Example usage for javax.sql.rowset.spi SyncResolver NO_ROW_CONFLICT

List of usage examples for javax.sql.rowset.spi SyncResolver NO_ROW_CONFLICT

Introduction

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

Prototype

int NO_ROW_CONFLICT

To view the source code for javax.sql.rowset.spi SyncResolver NO_ROW_CONFLICT.

Click Source Link

Document

Indicates that no conflict occurred while the RowSet object was attempting to update, delete or insert a row in the data source.

Usage

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

/**
 * {@inheritDoc}//  www  .  java2 s. c  om
 */
@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}/*  w ww  .  j  a  va  2s  .  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 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;
    }
}

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

private boolean esFilaValida(RowKey rowKey, boolean cursor) throws ExcepcionAplicacion {
    Bitacora.trace(this.getClass(), "esFilaValida", rowKey, String.valueOf(cursor));
    try {//from   w ww.j a  va 2 s. c  om
        long funcion = -1L;
        int status = SyncResolver.NO_ROW_CONFLICT;
        int tipoError = 3; /* OJO con la constante, 3 -> fila con uno o mas errores, todos conocidos */
        boolean ejecutada = false;
        boolean autorizada = false;
        String comando;
        String mensaje;
        if (cursor) {
            this.setCursorRow(rowKey); /* throws TableCursorVetoException */
        }
        if (this.getCachedRowSet().rowInserted()) { /* throws SQLException */
            funcion = this.getFuncionInsert();
            status = SyncResolver.INSERT_ROW_CONFLICT;
            ejecutada = true; /* this.isFuncionInsertEjecutada(); */
            autorizada = this.isFuncionInsertAutorizada();
        } else {
            if (this.getCachedRowSet().rowUpdated()) { /* throws SQLException */
                funcion = this.getFuncionUpdate();
                status = SyncResolver.UPDATE_ROW_CONFLICT;
                ejecutada = true; /* this.isFuncionUpdateEjecutada(); */
                autorizada = this.isFuncionUpdateAutorizada();
            }
        }
        boolean es = true;
        if (ejecutada) {
            this.filasProcesadasPorConfirmar++;
            if (autorizada) {
                es = this.esFilaValida(rowKey, funcion); /* check */
                if (es) {
                    Bitacora.trace(CBM2.CHECK_CHANGES_1, this.getEtiquetaRecurso(rowKey));
                } else {
                    comando = DBUtils.getTransactionLabel(status);
                    mensaje = tipoError + TLC.getBitacora().error(CBM2.CHECK_CHANGES_EXCEPTION_2, comando,
                            this.getEtiquetaRecurso(rowKey));
                    this.getFilasConflictivas().put(rowKey.getRowId(), mensaje);
                }
            } else {
                comando = DBUtils.getTransactionLabel(status);
                mensaje = tipoError + TLC.getBitacora().error(CBM2.CHECK_CHANGES_EXCEPTION_2, comando,
                        this.getEtiquetaRecurso(rowKey));
                this.getFilasConflictivas().put(rowKey.getRowId(), mensaje);
            }
        } else {
            Bitacora.trace(CBM2.CHECK_CHANGES_2, this.getEtiquetaRecurso(rowKey));
        }
        return es;
    } catch (IllegalArgumentException | SQLException | DataProviderException ex) {
        TLC.getBitacora().fatal(ex);
        throw new ExcepcionAplicacion(ex);
    }
}

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

private boolean esFilaValida(RowKey rowKey, boolean cursor) throws ExcepcionAplicacion {
    Bitacora.trace(getClass(), "esFilaValida", rowKey, String.valueOf(cursor));
    if (isNotRowAvailable(rowKey)) {
        return false;
    }//from  ww  w.  j  ava 2s .com
    try {
        long funcion = -1L;
        int status = SyncResolver.NO_ROW_CONFLICT;
        int tipoError = 3; /* OJO con la constante, 3 -> fila con uno o mas errores, todos conocidos */
        boolean ejecutada = false;
        boolean autorizada = false;
        String comando;
        String mensaje;
        if (cursor) {
            setCursorRow(rowKey); /* throws TableCursorVetoException */
        }
        if (getCachedRowSet().rowInserted()) { /* throws SQLException */
            funcion = getFuncionInsert();
            status = SyncResolver.INSERT_ROW_CONFLICT;
            ejecutada = true; /* isFuncionInsertEjecutada(); */
            autorizada = isFuncionInsertAutorizada();
        } else {
            if (getCachedRowSet().rowUpdated()) { /* throws SQLException */
                funcion = getFuncionUpdate();
                status = SyncResolver.UPDATE_ROW_CONFLICT;
                ejecutada = true; /* isFuncionUpdateEjecutada(); */
                autorizada = isFuncionUpdateAutorizada();
            }
        }
        boolean es = true;
        if (ejecutada) {
            filasProcesadasPorConfirmar++;
            if (autorizada) {
                es = esFilaValida(rowKey, funcion); /* check */
                if (es) {
                    Bitacora.trace(CBM.CHECK_CHANGES_1, getEtiquetaRecurso(rowKey));
                } else {
                    comando = DBUtils.getTransactionLabel(status);
                    mensaje = tipoError + TLC.getBitacora().error(CBM.CHECK_CHANGES_EXCEPTION_2, comando,
                            getEtiquetaRecurso(rowKey));
                    getFilasConflictivas().put(rowKey.getRowId(), mensaje);
                }
            } else {
                comando = DBUtils.getTransactionLabel(status);
                mensaje = tipoError + TLC.getBitacora().error(CBM.CHECK_CHANGES_EXCEPTION_2, comando,
                        getEtiquetaRecurso(rowKey));
                getFilasConflictivas().put(rowKey.getRowId(), mensaje);
            }
        } else {
            Bitacora.trace(CBM.CHECK_CHANGES_2, getEtiquetaRecurso(rowKey));
        }
        return es;
    } catch (IllegalArgumentException | SQLException | DataProviderException ex) {
        TLC.getBitacora().fatal(ex);
        throw new ExcepcionAplicacion(ex);
    }
}