use of java.sql.BatchUpdateException in project jdk8u_jdk by JetBrains.
the class BatchUpdateExceptionTests method test11.
/**
* Validate that if null is specified for the update count, it is returned
* as null
*/
@Test
public void test11() {
BatchUpdateException ex = new BatchUpdateException((int[]) null);
assertTrue(ex.getMessage() == null && ex.getSQLState() == null && ex.getErrorCode() == 0 && ex.getUpdateCounts() == null && ex.getLargeUpdateCounts() == null);
}
use of java.sql.BatchUpdateException in project spf4j by zolyfarkas.
the class ThrowablesTest method testChain2.
@Test
@SuppressFBWarnings("BC_UNCONFIRMED_CAST_OF_RETURN_VALUE")
public void testChain2() {
Throwable t = new RuntimeException("bla1", new BatchUpdateException("Sql bla", "ORA-500", 500, new int[] { 1, 2 }, new RuntimeException("la la")));
Throwable newRootCause = new TimeoutException("Booo");
Throwable result = Throwables.chain(t, newRootCause);
LOG.debug("Thowable string = {}", Throwables.toString(result));
Assert.assertArrayEquals(new int[] { 1, 2 }, ((BatchUpdateException) result.getCause()).getUpdateCounts());
Assert.assertEquals(newRootCause, com.google.common.base.Throwables.getRootCause(result));
Assert.assertEquals(4, com.google.common.base.Throwables.getCausalChain(result).size());
}
use of java.sql.BatchUpdateException in project pentaho-kettle by pentaho.
the class Database method insertFinished.
/**
* Close the prepared statement of the insert statement.
*
* @param ps The prepared statement to empty and close.
* @param batch true if you are using batch processing (typically true for this method)
* @param psBatchCounter The number of rows on the batch queue
* @throws KettleDatabaseException
* @deprecated use emptyAndCommit() instead (pass in the number of rows left in the batch)
*/
@Deprecated
public void insertFinished(PreparedStatement ps, boolean batch) throws KettleDatabaseException {
boolean isBatchUpdate = false;
try {
if (ps != null) {
if (!isAutoCommit()) {
// Execute the batch or just perform a commit.
if (batch && getDatabaseMetaData().supportsBatchUpdates()) {
// The problem with the batch counters is that you can't just
// execute the current batch.
// Certain databases have a problem if you execute the batch and if
// there are no statements in it.
// You can't just catch the exception either because you would have
// to roll back on certain databases before you can then continue to
// do anything.
// That leaves the task of keeping track of the number of rows up to
// our responsibility.
isBatchUpdate = true;
ps.executeBatch();
commit();
} else {
commit();
}
}
// Let's not forget to close the prepared statement.
//
ps.close();
}
} catch (BatchUpdateException ex) {
throw createKettleDatabaseBatchException("Error updating batch", ex);
} catch (SQLException ex) {
if (isBatchUpdate) {
throw createKettleDatabaseBatchException("Error updating batch", ex);
} else {
throw new KettleDatabaseException("Unable to commit connection after having inserted rows.", ex);
}
}
}
use of java.sql.BatchUpdateException in project pentaho-kettle by pentaho.
the class Database method insertRow.
/**
* Insert a row into the database using a prepared statement that has all values set.
*
* @param ps The prepared statement
* @param batch True if you want to use batch inserts (size = commit size)
* @param handleCommit True if you want to handle the commit here after the commit size (False e.g. in case the step
* handles this, see TableOutput)
* @return true if the rows are safe: if batch of rows was sent to the database OR if a commit was done.
* @throws KettleDatabaseException
*/
public boolean insertRow(PreparedStatement ps, boolean batch, boolean handleCommit) throws KettleDatabaseException {
String debug = "insertRow start";
boolean rowsAreSafe = false;
boolean isBatchUpdate = false;
try {
// Unique connections and Batch inserts don't mix when you want to roll
// back on certain databases.
// That's why we disable the batch insert in that case.
//
boolean useBatchInsert = getUseBatchInsert(batch);
//
if (!isAutoCommit()) {
if (useBatchInsert) {
debug = "insertRow add batch";
// Add the batch, but don't forget to run the batch
ps.addBatch();
} else {
debug = "insertRow exec update";
ps.executeUpdate();
}
} else {
ps.executeUpdate();
}
written++;
if (handleCommit) {
// TableOutput step)
if (!isAutoCommit() && (written % commitsize) == 0) {
if (useBatchInsert) {
isBatchUpdate = true;
debug = "insertRow executeBatch commit";
ps.executeBatch();
commit();
ps.clearBatch();
} else {
debug = "insertRow normal commit";
commit();
}
written = 0;
rowsAreSafe = true;
}
}
return rowsAreSafe;
} catch (BatchUpdateException ex) {
throw createKettleDatabaseBatchException("Error updating batch", ex);
} catch (SQLException ex) {
if (isBatchUpdate) {
throw createKettleDatabaseBatchException("Error updating batch", ex);
} else {
throw new KettleDatabaseException("Error inserting/updating row", ex);
}
} catch (Exception e) {
throw new KettleDatabaseException("Unexpected error inserting/updating row in part [" + debug + "]", e);
}
}
use of java.sql.BatchUpdateException in project pentaho-kettle by pentaho.
the class DatabaseTest method testCreateKettleDatabaseBatchExceptionConstructsExceptionList.
@Test
public void testCreateKettleDatabaseBatchExceptionConstructsExceptionList() {
BatchUpdateException root = new BatchUpdateException();
SQLException next = new SQLException();
SQLException next2 = new SQLException();
root.setNextException(next);
next.setNextException(next2);
List<Exception> exceptionList = Database.createKettleDatabaseBatchException("", root).getExceptionsList();
assertEquals(2, exceptionList.size());
assertEquals(next, exceptionList.get(0));
assertEquals(next2, exceptionList.get(1));
}
Aggregations