Example usage for javax.sql.rowset.spi SyncProviderException SyncProviderException

List of usage examples for javax.sql.rowset.spi SyncProviderException SyncProviderException

Introduction

In this page you can find the example usage for javax.sql.rowset.spi SyncProviderException SyncProviderException.

Prototype

public SyncProviderException(SyncResolver syncResolver) 

Source Link

Document

Constructs a SyncProviderException object with the specified SyncResolver instance.

Usage

From source file:lasige.steeldb.jdbc.BFTRowSet.java

/**
 * Propagates all row update, insert, and delete changes to the
 * underlying data source backing this <code>CachedRowSetImpl</code>
 * object./*from w  w w .  j  a va  2  s  .c om*/
 * <P>
 * <b>Note</b>In the reference implementation an optimistic concurrency implementation
 * is provided as a sample implementation of a the <code>SyncProvider</code>
 * abstract class.
 * <P>
 * This method fails if any of the updates cannot be propagated back
 * to the data source.  When it fails, the caller can assume that
 * none of the updates are reflected in the data source.
 * When an exception is thrown, the current row
 * is set to the first "updated" row that resulted in an exception
 * unless the row that caused the exception is a "deleted" row.
 * In that case, when deleted rows are not shown, which is usually true,
 * the current row is not affected.
 * <P>
 * If no <code>SyncProvider</code> is configured, the reference implementation
 * leverages the <code>RIOptimisticProvider</code> available which provides the
 * default and reference synchronization capabilities for disconnected
 * <code>RowSets</code>.
 *
 * @throws SQLException if the cursor is on the insert row or the underlying
 *          reference synchronization provider fails to commit the updates
 *          to the datasource
 * @throws SyncProviderException if an internal error occurs within the
 *          <code>SyncProvider</code> instance during either during the
 *          process or at any time when the <code>SyncProvider</code>
 *          instance touches the data source.
 * @see #acceptChanges(java.sql.Connection)
 * @see javax.sql.RowSetWriter
 * @see javax.sql.rowset.spi.SyncProvider
 */
public void acceptChanges() throws SyncProviderException {
    if (onInsertRow == true) {
        throw new SyncProviderException(resBundle.handleGetObject("cachedrowsetimpl.invalidop").toString());
    }

    int saveCursorPos = cursorPos;
    boolean success = false;
    boolean conflict = false;

    try {
        if (rowSetWriter != null) {
            saveCursorPos = cursorPos;
            conflict = rowSetWriter.writeData((RowSetInternal) this);
            cursorPos = saveCursorPos;
        }

        if ((tXWriter) && this.COMMIT_ON_ACCEPT_CHANGES) {
            // do commit/rollback's here
            if (!conflict) {
                tWriter = (TransactionalWriter) rowSetWriter;
                tWriter.rollback();
                success = false;
            } else {
                tWriter = (TransactionalWriter) rowSetWriter;
                ((CachedRowSetWriter) tWriter).commit(this, updateOnInsert);
                success = true;
            }
        }

        if (success == true) {
            setOriginal();
        } else if (!(success) && !(this.COMMIT_ON_ACCEPT_CHANGES)) {
            throw new SyncProviderException(resBundle.handleGetObject("cachedrowsetimpl.accfailed").toString());
        }

    } catch (SyncProviderException spe) {
        throw spe;
    } catch (SQLException e) {
        e.printStackTrace();
        throw new SyncProviderException(e.getMessage());
    } catch (SecurityException e) {
        throw new SyncProviderException(e.getMessage());
    }
}

From source file:com.egt.core.db.xdp.RecursoCachedRowSet.java

/**
 * {@inheritDoc}//from  w w  w.j  av  a2  s  .  c  o m
 */
@Override
public void acceptChanges() throws SyncProviderException {
    try {
        this.getFilasConflictivas().clear();
        super.acceptChanges();
    } catch (SyncProviderException spe) {
        SyncResolver resolver = spe.getSyncResolver();
        if (resolver != null && resolver instanceof SyncResolverX) {
            boolean showDeleted = this.tryToGetShowDeleted();
            boolean sinDuplicados = TLC.getBitacora().isSinDuplicados();
            int conflictos = 0;
            int row;
            int status = SyncResolver.NO_ROW_CONFLICT;
            String transaction = DBUtils.getTransactionLabel(status);
            SQLException sqlException;
            int errorCode;
            String message;
            String localizedMessage;
            String sqlState;
            String heading;
            String clave = CBM2.COMMIT_CHANGES_UNKNOWN_EXCEPTION;
            int tipoError; /* OJO con la constante, 1 -> fila con un error desconocido */
            String mensaje;
            String prefijo = Global.PREFIJO_ETIQUETA_ID_RECURSO;
            try {
                this.tryToSetShowDeleted(true);
                TLC.getBitacora().setSinDuplicados(true);
                while (resolver.nextConflict()) {
                    conflictos++;
                    row = resolver.getRow();
                    status = resolver.getStatus();
                    transaction = DBUtils.getTransactionLabel(status);
                    sqlException = ((SyncResolverX) resolver).getSQLException();
                    errorCode = sqlException.getErrorCode();
                    message = sqlException.getMessage();
                    localizedMessage = StringUtils.substringBefore(sqlException.getLocalizedMessage(),
                            " Where: ");
                    sqlState = sqlException.getSQLState();
                    heading = "Row:" + row + ", Status:" + status + ", Code:" + errorCode + ", State:"
                            + sqlState;
                    Bitacora.trace(heading + message);
                    if (TLC.getInterpreteSql().isCommandIgnoredException(sqlException)) {
                        clave = CBM2.COMMIT_CHANGES_COMMAND_IGNORED_EXCEPTION;
                        tipoError = 0; /* OJO con la constante, 0 -> fila "ignorada" (no se sabe si tiene o no errores) */
                        mensaje = tipoError + Bitacora.getTextoMensaje(clave, transaction, prefijo + row);
                        TLC.getBitacora().error(CBM2.COMMIT_CHANGES_COMMAND_IGNORED);
                        if (status == SyncResolver.DELETE_ROW_CONFLICT) {
                            this.tryToSetShowDeleted(false);
                        }
                    } else {
                        String columna = TLC.getInterpreteSql()
                                .getNotNullConstraintViolationColumn(sqlException);
                        if (StringUtils.isNotBlank(columna)) {
                            clave = CBM2.DATABASE_NOT_NULL_CONSTRAINT_VIOLATION;
                            tipoError = 2; /* OJO con la constante, 2 -> fila con un error conocido */
                            mensaje = tipoError
                                    + TLC.getBitacora().error(clave, transaction, prefijo + row, columna);
                        } else {
                            clave = DBUtils.getConstraintMessageKey(message, status);
                            if (clave == null) {
                                clave = CBM2.COMMIT_CHANGES_UNKNOWN_EXCEPTION;
                                tipoError = 1; /* OJO con la constante, 1 -> fila con un error desconocido */
                                mensaje = tipoError + TLC.getBitacora().error(clave, transaction, prefijo + row,
                                        localizedMessage);
                            } else {
                                tipoError = 2; /* OJO con la constante, 2 -> fila con un error conocido */
                                mensaje = tipoError
                                        + TLC.getBitacora().error(clave, transaction, prefijo + row);
                            }
                        }
                    }
                    this.getFilasConflictivas().put(String.valueOf(row - 1), mensaje);
                    //                      if (status == SyncResolver.DELETE_ROW_CONFLICT)
                    //                          if (this.absolute(row))
                    //                              if (this.rowDeleted()) // RETORNA FALSO!
                    //                                  this.undoDelete();
                }
                if (conflictos == 0) { /* esto parece un BUG, y pasa cuando se elimina la ultima fila y showDeleted==false */
                    TLC.getBitacora().error(clave, transaction, "", spe.getLocalizedMessage());
                }
            } catch (SQLException ex) {
                TLC.getBitacora().fatal(ex);
            } finally {
                this.tryToSetShowDeleted(showDeleted);
                TLC.getBitacora().setSinDuplicados(sinDuplicados);
                throw new SyncProviderException(this.getSyncProviderExceptionString(spe));
            }
        }
        throw spe;
    }
}

From source file:ips1ap101.lib.core.db.xdp.RecursoCachedRowSet.java

/**
 * {@inheritDoc}//from  w ww .j av a  2  s  .co  m
 */
@Override
public void acceptChanges() throws SyncProviderException {
    try {
        this.getFilasConflictivas().clear();
        super.acceptChanges();
    } catch (SyncProviderException spe) {
        SyncResolver resolver = spe.getSyncResolver();
        if (resolver != null && resolver instanceof SyncResolverX) {
            boolean showDeleted = this.tryToGetShowDeleted();
            boolean sinDuplicados = TLC.getBitacora().isSinDuplicados();
            int conflictos = 0;
            int row;
            int status = SyncResolver.NO_ROW_CONFLICT;
            String transaction = DBUtils.getTransactionLabel(status);
            SQLException sqlException;
            int errorCode;
            String message;
            String localizedMessage;
            String sqlState;
            String clave = CBM.COMMIT_CHANGES_UNKNOWN_EXCEPTION;
            int tipoError; /* OJO con la constante, 1 -> fila con un error desconocido */
            String mensaje;
            String prefijo = Global.PREFIJO_ETIQUETA_ID_RECURSO;
            try {
                this.tryToSetShowDeleted(true);
                TLC.getBitacora().setSinDuplicados(true);
                while (resolver.nextConflict()) {
                    conflictos++;
                    row = resolver.getRow();
                    status = resolver.getStatus();
                    transaction = DBUtils.getTransactionLabel(status);
                    sqlException = ((SyncResolverX) resolver).getSQLException();
                    errorCode = sqlException.getErrorCode();
                    message = sqlException.getMessage();
                    localizedMessage = DBUtils.getProperErrorMessage(sqlException.getLocalizedMessage());
                    sqlState = sqlException.getSQLState();
                    Bitacora.trace("SQLException Message = " + message);
                    Bitacora.trace("SQLException Localized Message = " + localizedMessage);
                    Bitacora.trace("SQLException Row = " + row + ", Status = " + status + ", Code = "
                            + errorCode + ", State = " + sqlState);
                    if (TLC.getInterpreteSql().isCommandIgnoredException(sqlException)) {
                        clave = CBM.COMMIT_CHANGES_COMMAND_IGNORED_EXCEPTION;
                        tipoError = 0; /* OJO con la constante, 0 -> fila "ignorada" (no se sabe si tiene o no errores) */
                        mensaje = tipoError + Bitacora.getTextoMensaje(clave, transaction, prefijo + row);
                        TLC.getBitacora().error(CBM.COMMIT_CHANGES_COMMAND_IGNORED);
                        if (status == SyncResolver.DELETE_ROW_CONFLICT) {
                            this.tryToSetShowDeleted(false);
                        }
                    } else {
                        String columna = TLC.getInterpreteSql()
                                .getNotNullConstraintViolationColumn(sqlException);
                        if (StringUtils.isNotBlank(columna)) {
                            clave = CBM.DATABASE_NOT_NULL_CONSTRAINT_VIOLATION;
                            tipoError = 2; /* OJO con la constante, 2 -> fila con un error conocido */
                            mensaje = tipoError
                                    + TLC.getBitacora().error(clave, transaction, prefijo + row, columna);
                        } else {
                            clave = DBUtils.getConstraintMessageKey(message, status);
                            if (clave == null) {
                                clave = CBM.COMMIT_CHANGES_UNKNOWN_EXCEPTION;
                                tipoError = 1; /* OJO con la constante, 1 -> fila con un error desconocido */
                                mensaje = tipoError + TLC.getBitacora().error(clave, transaction, prefijo + row,
                                        localizedMessage);
                            } else {
                                tipoError = 2; /* OJO con la constante, 2 -> fila con un error conocido */
                                mensaje = tipoError
                                        + TLC.getBitacora().error(clave, transaction, prefijo + row);
                            }
                        }
                    }
                    this.getFilasConflictivas().put(String.valueOf(row - 1), mensaje);
                    //                      if (status == SyncResolver.DELETE_ROW_CONFLICT)
                    //                          if (this.absolute(row))
                    //                              if (this.rowDeleted()) // RETORNA FALSO!
                    //                                  this.undoDelete();
                }
                if (conflictos == 0) { /* esto parece un BUG, y pasa cuando se elimina la ultima fila y showDeleted==false */
                    TLC.getBitacora().error(clave, transaction, "", spe.getLocalizedMessage());
                }
            } catch (SQLException ex) {
                TLC.getBitacora().fatal(ex);
            } finally {
                this.tryToSetShowDeleted(showDeleted);
                TLC.getBitacora().setSinDuplicados(sinDuplicados);
                throw new SyncProviderException(this.getSyncProviderExceptionString(spe));
            }
        }
        throw spe;
    }
}