List of usage examples for javax.sql.rowset.spi SyncResolver INSERT_ROW_CONFLICT
int INSERT_ROW_CONFLICT
To view the source code for javax.sql.rowset.spi SyncResolver INSERT_ROW_CONFLICT.
Click Source Link
RowSet
object was attempting to insert a row into the data source. From source file:com.egt.core.db.util.DBUtils.java
public static String getTransactionLabel(int status) { String value;/*from w ww. j a v a2s . c om*/ switch (status) { case SyncResolver.INSERT_ROW_CONFLICT: value = DBC.COMANDO_INSERT; break; case SyncResolver.UPDATE_ROW_CONFLICT: value = DBC.COMANDO_UPDATE; break; case SyncResolver.DELETE_ROW_CONFLICT: value = DBC.COMANDO_DELETE; break; default: value = DBC.COMANDO_COMMIT; break; } return value; }
From source file:ips1ap101.lib.core.db.util.DBUtils.java
public static String getTransactionLabel(int status) { String value;/*from ww w . ja v a 2 s . co m*/ switch (status) { case SyncResolver.INSERT_ROW_CONFLICT: value = BundleWebui.getString("database.insert.command"); break; case SyncResolver.UPDATE_ROW_CONFLICT: value = BundleWebui.getString("database.update.command"); break; case SyncResolver.DELETE_ROW_CONFLICT: value = BundleWebui.getString("database.delete.command"); break; default: value = BundleWebui.getString("database.commit.command"); break; } return value; }
From source file:com.oracle.tutorial.jdbc.CachedRowSetSample.java
public void testPaging() throws SQLException, MalformedURLException { CachedRowSet crs = null;//from w w w . j a v a2 s .c om this.con.setAutoCommit(false); try { crs = new CachedRowSetImpl(); crs.setUsername(settings.userName); crs.setPassword(settings.password); if (this.dbms.equals("mysql")) { crs.setUrl(settings.urlString + "?relaxAutoCommit=true"); } else { crs.setUrl(settings.urlString); } crs.setCommand("select * from MERCH_INVENTORY"); // Setting the page size to 4, such that we // get the data in chunks of 4 rows @ a time. crs.setPageSize(100); // Now get the first set of data crs.execute(); crs.addRowSetListener(new ExampleRowSetListener()); // Keep on getting data in chunks until done. int i = 1; do { System.out.println("Page number: " + i); while (crs.next()) { System.out.println("Found item " + crs.getInt("ITEM_ID") + ": " + crs.getString("ITEM_NAME")); if (crs.getInt("ITEM_ID") == 1235) { int currentQuantity = crs.getInt("QUAN") + 1; System.out.println("Updating quantity to " + currentQuantity); crs.updateInt("QUAN", currentQuantity + 1); crs.updateRow(); // Syncing the row back to the DB crs.acceptChanges(con); } } // End of inner while i++; } while (crs.nextPage()); // End of outer while // Inserting a new row // Doing a previous page to come back to the last page // as we ll be after the last page. int newItemId = 123456; if (this.doesItemIdExist(newItemId)) { System.out.println("Item ID " + newItemId + " already exists"); } else { crs.previousPage(); crs.moveToInsertRow(); crs.updateInt("ITEM_ID", newItemId); crs.updateString("ITEM_NAME", "TableCloth"); crs.updateInt("SUP_ID", 927); crs.updateInt("QUAN", 14); Calendar timeStamp; timeStamp = new GregorianCalendar(); timeStamp.set(2006, 4, 1); crs.updateTimestamp("DATE_VAL", new Timestamp(timeStamp.getTimeInMillis())); crs.insertRow(); crs.moveToCurrentRow(); // Syncing the new row back to the database. System.out.println("About to add a new row..."); crs.acceptChanges(con); System.out.println("Added a row..."); this.viewTable(con); } } catch (SyncProviderException spe) { SyncResolver resolver = spe.getSyncResolver(); Object crsValue; // value in the RowSet object Object resolverValue; // value in the SyncResolver object Object resolvedValue; // value to be persisted while (resolver.nextConflict()) { if (resolver.getStatus() == SyncResolver.INSERT_ROW_CONFLICT) { int row = resolver.getRow(); crs.absolute(row); int colCount = crs.getMetaData().getColumnCount(); for (int j = 1; j <= colCount; j++) { if (resolver.getConflictValue(j) != null) { crsValue = crs.getObject(j); resolverValue = resolver.getConflictValue(j); // Compare crsValue and resolverValue to determine // which should be the resolved value (the value to persist) // // This example choses the value in the RowSet object, // crsValue, to persist., resolvedValue = crsValue; resolver.setResolvedValue(j, resolvedValue); } } } } } catch (SQLException sqle) { JDBCTutorialUtilities.printSQLException(sqle); } finally { if (crs != null) crs.close(); this.con.setAutoCommit(true); } }
From source file:ips1ap101.lib.core.db.xdp.RecursoCachedRowSetDataProvider.java
public RowKey appendRow(long funcion) throws DataProviderException { Bitacora.trace(getClass(), "appendRow", funcion); try {//w w w .j a v a 2 s .c om if (isFuncionUpdateEjecutada() || isFuncionDeleteEjecutada()) { throw new ExcepcionAplicacion(TLC.getBitacora().error(CBM.INSERT_ROW_EXCEPTION_4)); } setFuncionInsert(funcion); /* throws ExcepcionAplicacion */ if (esPermitidoAgregar()) { setComandoSelectVersion(); /* throws ExcepcionAplicacion */ RowKey rowKey = super.appendRow(); /* throws DataProviderException */ setFuncionInsertEjecutada(true); getFilasProcesadas().put(rowKey.getRowId(), rowKey); posAppendRow(rowKey, funcion); /* fire afterAppendRow event? */ setAppendedRowVersion(rowKey); setFilaEscogida(rowKey); return rowKey; } String message = getBeforeAppendingProcedureDefaultErrorMessage(); if (message != null) { TLC.getBitacora().error(message); } String transaction = DBUtils.getTransactionLabel(SyncResolver.INSERT_ROW_CONFLICT); TLC.getBitacora().error(CBM.FUNCION_NO_DISPONIBLE, transaction, ""); return null; } catch (ExcepcionAplicacion ex) { throw new DataProviderException(ex); } catch (DataProviderException ex) { TLC.getBitacora().fatal(ex); throw ex; } }
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 {/* w w w . j a v a 2 s. co m*/ 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; }// w w w . ja v a2 s . c om 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); } }