Search in sources :

Example 86 with BatchUpdateException

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;
}
Also used : JdbcEntryDatum(org.apache.gobblin.converter.jdbc.JdbcEntryDatum) JdbcEntryData(org.apache.gobblin.converter.jdbc.JdbcEntryData) BatchUpdateException(java.sql.BatchUpdateException)

Example 87 with BatchUpdateException

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);
    }
}
Also used : IReferenceableAttribute(com.agiletec.plugins.jacms.aps.system.services.content.model.extraAttribute.IReferenceableAttribute) PreparedStatement(java.sql.PreparedStatement) CmsAttributeReference(com.agiletec.plugins.jacms.aps.system.services.content.model.CmsAttributeReference) AttributeInterface(com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface) EntityAttributeIterator(com.agiletec.aps.system.common.util.EntityAttributeIterator) BatchUpdateException(java.sql.BatchUpdateException)

Example 88 with BatchUpdateException

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);
    }
}
Also used : PreparedStatement(java.sql.PreparedStatement) BatchUpdateException(java.sql.BatchUpdateException)

Example 89 with BatchUpdateException

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");
    }
}
Also used : Statement(java.sql.Statement) CallableStatement(java.sql.CallableStatement) PreparedStatement(java.sql.PreparedStatement) BatchUpdateException(java.sql.BatchUpdateException)

Example 90 with BatchUpdateException

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"));
}
Also used : IgniteException(org.apache.ignite.IgniteException) Callable(java.util.concurrent.Callable) BatchUpdateException(java.sql.BatchUpdateException) Test(org.junit.Test)

Aggregations

BatchUpdateException (java.sql.BatchUpdateException)103 SQLException (java.sql.SQLException)39 PreparedStatement (java.sql.PreparedStatement)33 Statement (java.sql.Statement)22 ArrayList (java.util.ArrayList)19 Test (org.junit.Test)19 Connection (java.sql.Connection)17 Test (org.testng.annotations.Test)17 BaseTest (util.BaseTest)17 SerializedBatchUpdateException (util.SerializedBatchUpdateException)17 ResultSet (java.sql.ResultSet)13 List (java.util.List)12 CallableStatement (java.sql.CallableStatement)8 HashSet (java.util.HashSet)8 IgniteSQLException (org.apache.ignite.internal.processors.query.IgniteSQLException)7 HashMap (java.util.HashMap)6 Map (java.util.Map)5 CustomChangeException (liquibase.exception.CustomChangeException)5 DatabaseException (liquibase.exception.DatabaseException)5 SetupException (liquibase.exception.SetupException)5