use of java.sql.BatchUpdateException in project incubator-gobblin by apache.
the class TeradataBufferedInserter method insertBatch.
@Override
protected boolean insertBatch(PreparedStatement pstmt) throws SQLException {
for (JdbcEntryData pendingEntry : TeradataBufferedInserter.this.pendingInserts) {
int i = 1;
for (JdbcEntryDatum datum : pendingEntry) {
Object value = datum.getVal();
if (value != null) {
pstmt.setObject(i, value);
} else {
// Column type is needed for null value insertion
pstmt.setNull(i, columnPosSqlTypes.get(i));
}
i++;
}
pstmt.addBatch();
pstmt.clearParameters();
}
if (LOG.isDebugEnabled()) {
LOG.debug("Executing SQL " + pstmt);
}
int[] execStatus = pstmt.executeBatch();
// Check status explicitly if driver continues batch insertion upon failure
for (int status : execStatus) {
if (status == Statement.EXECUTE_FAILED) {
throw new BatchUpdateException("Batch insert failed.", execStatus);
}
}
return true;
}
use of java.sql.BatchUpdateException in project entando-core by entando.
the class ContentDAO method addContentRelationsRecord.
/**
* Add a record in the table 'contentrelations' for every resource, page,
* other content, role and category associated to the given content).
*
* @param content
* The current content.
* @param conn
* The connection to the database.
* @throws ApsSystemException
* when connection error are detected.
*/
protected void addContentRelationsRecord(Content content, Connection conn) throws ApsSystemException {
PreparedStatement stat = null;
try {
stat = conn.prepareStatement(ADD_CONTENT_REL_RECORD);
this.addCategoryRelationsRecord(content, true, stat);
this.addGroupRelationsRecord(content, stat);
EntityAttributeIterator attributeIter = new EntityAttributeIterator(content);
while (attributeIter.hasNext()) {
AttributeInterface currAttribute = (AttributeInterface) attributeIter.next();
if (currAttribute instanceof IReferenceableAttribute) {
IReferenceableAttribute cmsAttribute = (IReferenceableAttribute) currAttribute;
List<CmsAttributeReference> refs = cmsAttribute.getReferences(this.getLangManager().getLangs());
for (int i = 0; i < refs.size(); i++) {
CmsAttributeReference ref = refs.get(i);
stat.setString(1, content.getId());
stat.setString(2, ref.getRefPage());
stat.setString(3, ref.getRefContent());
stat.setString(4, ref.getRefResource());
stat.setString(5, null);
stat.setString(6, null);
stat.addBatch();
stat.clearParameters();
}
}
}
stat.executeBatch();
} catch (BatchUpdateException e) {
_logger.error("Error saving record into contentrelations {}", content.getId(), e.getNextException());
throw new RuntimeException("Error saving record into contentrelations " + content.getId(), e.getNextException());
} catch (Throwable t) {
_logger.error("Error saving record into contentrelations {}", content.getId(), t);
throw new RuntimeException("Error saving record into contentrelations " + content.getId(), t);
} finally {
closeDaoResources(null, stat);
}
}
use of java.sql.BatchUpdateException in project entando-core by entando.
the class ContentDAO method addWorkContentRelationsRecord.
protected void addWorkContentRelationsRecord(Content content, Connection conn) throws ApsSystemException {
PreparedStatement stat = null;
try {
stat = conn.prepareStatement(ADD_WORK_CONTENT_REL_RECORD);
this.addCategoryRelationsRecord(content, false, stat);
stat.executeBatch();
} catch (BatchUpdateException e) {
_logger.error("Error saving record into workcontentrelations {}", content.getId(), e.getNextException());
throw new RuntimeException("Error saving record into workcontentrelations " + content.getId(), e);
} catch (Throwable t) {
_logger.error("Error saving record into workcontentrelations {}", content.getId(), t);
throw new RuntimeException("Error saving record into workcontentrelations " + content.getId(), t);
} finally {
closeDaoResources(null, stat);
}
}
use of java.sql.BatchUpdateException in project jdbc-shards by wplatform.
the class BatchUpdatesTestCase method testExecuteBatch07.
private void testExecuteBatch07() throws SQLException {
trace("testExecuteBatch07");
boolean batchExceptionFlag = false;
String selectCoffee = COFFEE_SELECT1;
trace("selectCoffee = " + selectCoffee);
Statement stmt = conn.createStatement();
stmt.addBatch(selectCoffee);
try {
int[] updateCount = stmt.executeBatch();
trace("updateCount Length : " + updateCount.length);
} catch (BatchUpdateException be) {
batchExceptionFlag = true;
}
if (batchExceptionFlag) {
trace("executeBatch select");
} else {
fail("executeBatch");
}
}
use of java.sql.BatchUpdateException in project ignite by apache.
the class JdbcThinTransactionsAbstractComplexSelfTest method testBatchDmlStatementsIntermediateFailure.
/**
*/
@Test
public void testBatchDmlStatementsIntermediateFailure() throws SQLException {
insertPerson(6, "John", "Doe", 2, 2);
IgniteException e = (IgniteException) GridTestUtils.assertThrows(null, new Callable<Object>() {
@Override
public Object call() throws Exception {
doBatchedInsert();
return null;
}
}, IgniteException.class, "Duplicate key during INSERT [key=KeyCacheObjectImpl " + "[part=6, val=6, hasValBytes=true]]");
assertTrue(e.getCause() instanceof BatchUpdateException);
assertEquals(IgniteQueryErrorCode.DUPLICATE_KEY, ((BatchUpdateException) e.getCause()).getErrorCode());
assertTrue(e.getCause().getMessage().contains("Duplicate key during INSERT [key=KeyCacheObjectImpl " + "[part=6, val=6, hasValBytes=true]]"));
// First we insert id 7, then 6. Still, 7 is not in the cache as long as the whole batch has failed inside tx.
assertEquals(Collections.emptyList(), execute("SELECT * FROM \"Person\".Person where id > 6 order by id"));
}
Aggregations