当前位置: 首页>>代码示例>>Java>>正文


Java BatchUpdateException.getUpdateCounts方法代码示例

本文整理汇总了Java中java.sql.BatchUpdateException.getUpdateCounts方法的典型用法代码示例。如果您正苦于以下问题:Java BatchUpdateException.getUpdateCounts方法的具体用法?Java BatchUpdateException.getUpdateCounts怎么用?Java BatchUpdateException.getUpdateCounts使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.sql.BatchUpdateException的用法示例。


在下文中一共展示了BatchUpdateException.getUpdateCounts方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testExecuteBatch06

import java.sql.BatchUpdateException; //导入方法依赖的package包/类
private void testExecuteBatch06() throws SQLException {
    trace("testExecuteBatch06");
    boolean batchExceptionFlag = false;
    // Insert a row which is already Present
    String sInsCoffee = COFFEE_INSERT1;
    String sDelCoffee = COFFEE_DELETE1;
    stat.addBatch(sInsCoffee);
    stat.addBatch(sInsCoffee);
    stat.addBatch(sDelCoffee);
    try {
        stat.executeBatch();
    } catch (BatchUpdateException b) {
        batchExceptionFlag = true;
        for (int uc : b.getUpdateCounts()) {
            trace("Update counts:" + uc);
        }
    }
    if (batchExceptionFlag) {
        trace("executeBatch insert duplicate; correct");
    } else {
        fail("executeBatch");
    }
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:24,代码来源:TestBatchUpdates.java

示例2: assertBatchExecuteError

import java.sql.BatchUpdateException; //导入方法依赖的package包/类
/**
 * helper method to evaluate negative tests where we expect a
 * batchExecuteException to be returned.
 * @exception SQLException     Thrown if the expected error occurs
 *                             We expect a BatchUpdateException, and
 *                             verify it is so.
 *
 * @param expectedError The sqlstate to look for.
 * @param stmt The Statement that contains the Batch to
 *                             be executed.
 * @param expectedUpdateCount The expectedUpdateCount array.
 */
protected void assertBatchExecuteError(
    String expectedError,
    Statement stmt,
    int[] expectedUpdateCount)
throws SQLException
{
    int[] updateCount;
    try {
        updateCount = stmt.executeBatch();
        fail("Expected batchExecute to fail");
    } catch (BatchUpdateException bue) {
        assertSQLState(expectedError, bue);
        updateCount = bue.getUpdateCounts();
        assertBatchUpdateCounts(expectedUpdateCount, updateCount);
    }
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:29,代码来源:BatchUpdateTest.java

示例3: testErrorAmidstBatch

import java.sql.BatchUpdateException; //导入方法依赖的package包/类
/**
 * @throws SQLException if failed.
 */
public void testErrorAmidstBatch() throws SQLException {
    formBatch(1, 2);
    formBatch(3, 1); // Duplicate key

    BatchUpdateException reason = (BatchUpdateException)
        GridTestUtils.assertThrows(log, new Callable<Object>() {
            @Override public Object call() throws Exception {
                return prepStmt.executeBatch();
            }
        },
        BatchUpdateException.class,
        "Failed to INSERT some keys because they are already in cache");

    // Check update counts in the exception.
    int[] counts = reason.getUpdateCounts();

    assertNotNull(counts);

    assertEquals(1, counts.length);
    assertEquals(2, counts[0]);
}
 
开发者ID:apache,项目名称:ignite,代码行数:25,代码来源:JdbcInsertStatementSelfTest.java

示例4: Exception

import java.sql.BatchUpdateException; //导入方法依赖的package包/类
/**
 * @tests {@link java.sql.BatchUpdateException#BatchUpdateException(String, int[], Throwable)}
 * 
 * @since 1.6
 */
public void testBatchUpdateExceptionLString$ILThrowable() {
    Throwable cause = new Exception("MYTHROWABLE");
    int[] updateCounts = new int[] { 1, 2, 3 };
    BatchUpdateException batchUpdateException = new BatchUpdateException(
            "MYTESTSTRING1", "MYTESTSTRING2", updateCounts, cause);
    assertNotNull(batchUpdateException);
    assertEquals("MYTESTSTRING2", batchUpdateException.getSQLState());
    assertEquals("MYTESTSTRING1", batchUpdateException.getMessage());
    assertEquals(0, batchUpdateException.getErrorCode());
    int[] result = batchUpdateException.getUpdateCounts();
    for (int i = 0; i < updateCounts.length; i++) {
        assertEquals(updateCounts[i], result[i]);
    }
    assertEquals(cause, batchUpdateException.getCause());
}
 
开发者ID:shannah,项目名称:cn1,代码行数:21,代码来源:BatchUpdateExceptionTest.java

示例5: raiseBatchUpdateException

import java.sql.BatchUpdateException; //导入方法依赖的package包/类
/**
 * Throws an {@link AndesBatchUpdateException} with specified
 * information. and rollback the tried batch operation.
 * 
 * @param dataList
 *            data objects will was used for batch operation.
 * @param connection
 *            SQL connection used.
 * @param bue
 *            the original SQL batch update exception.
 * @param task
 *            the string indicating the task tried out (in failed batch
 *            update operation)
 * @throws AndesBatchUpdateException
 *             the error.
 */
public <T> void raiseBatchUpdateException(List<T> dataList, Connection connection,
                                          BatchUpdateException bue,
                                          String task) throws AndesBatchUpdateException {

    int[] updateCountsOfFailedBatch = bue.getUpdateCounts();
    List<T> failed = new ArrayList<T>();
    List<T> succeded = new ArrayList<T>();

    for (int i = 0; i < updateCountsOfFailedBatch.length; i++) {
        T msgPart = dataList.get(i);
        if (Statement.EXECUTE_FAILED == updateCountsOfFailedBatch[i]) {
            failed.add(msgPart);
        } else {
            succeded.add(msgPart);
        }
    }

    rollback(connection, task); // try to rollback the batch operation.

    AndesBatchUpdateException insertEx =
                                         new AndesBatchUpdateException(task + " failed", bue.getSQLState(),
                                                                       bue, failed, succeded);
    throw insertEx;
}
 
开发者ID:wso2,项目名称:andes,代码行数:41,代码来源:RDBMSStoreUtils.java

示例6: assertBatchExecuteError

import java.sql.BatchUpdateException; //导入方法依赖的package包/类
/** 
 * helper method to evaluate negative tests where we expect a 
 * batchExecuteException to be returned.
 * @exception SQLException     Thrown if the expected error occurs
 *                             We expect a BatchUpdateException, and
 *                             verify it is so.
 *
 * @param expectedError The sqlstate to look for.
 * @param stmt The Statement that contains the Batch to
 *                             be executed.
 * @param expectedUpdateCount The expectedUpdateCount array.
 */
protected void assertBatchExecuteError( 
    String expectedError,
    Statement stmt,
    int[] expectedUpdateCount) 
throws SQLException 
{
    int[] updateCount;    
    try {
        updateCount = stmt.executeBatch();
        fail("Expected batchExecute to fail");
    } catch (BatchUpdateException bue) {
        assertSQLState(expectedError, bue);
        updateCount = bue.getUpdateCounts();
        assertBatchUpdateCounts(expectedUpdateCount, updateCount);
    } 
}
 
开发者ID:splicemachine,项目名称:spliceengine,代码行数:29,代码来源:BatchUpdateTest.java

示例7: testBatchException

import java.sql.BatchUpdateException; //导入方法依赖的package包/类
/**
 * @throws SQLException If failed.
 */
public void testBatchException() throws SQLException {
    final int BATCH_SIZE = 7;

    final int FAILED_IDX = 5;

    for (int idx = 0, i = 0; i < FAILED_IDX; ++i, idx += i) {
        stmt.addBatch("insert into Person (_key, id, firstName, lastName, age) values "
            + generateValues(idx, i + 1));
    }

    stmt.addBatch("select * from Person");

    stmt.addBatch("insert into Person (_key, id, firstName, lastName, age) values "
        + generateValues(100, 7));

    try {
        stmt.executeBatch();

        fail("BatchUpdateException must be thrown");
    } catch(BatchUpdateException e) {
        int [] updCnts = e.getUpdateCounts();

        assertEquals("Invalid update counts size", BATCH_SIZE, updCnts.length);

        for (int i = 0; i < BATCH_SIZE; ++i)
            assertEquals("Invalid update count", i != FAILED_IDX ? i + 1 : Statement.EXECUTE_FAILED,
                updCnts[i]);

        if (!e.getMessage().contains("Given statement type does not match that declared by JDBC driver")) {
            log.error("Invalid exception: ", e);

            fail();
        }

        assertEquals("Invalid SQL state.", SqlStateCode.PARSING_EXCEPTION, e.getSQLState());
        assertEquals("Invalid error code.", IgniteQueryErrorCode.STMT_TYPE_MISMATCH, e.getErrorCode());
    }
}
 
开发者ID:apache,项目名称:ignite,代码行数:42,代码来源:JdbcThinBatchSelfTest.java

示例8: testBatchParseException

import java.sql.BatchUpdateException; //导入方法依赖的package包/类
/**
 * @throws SQLException If failed.
 */
public void testBatchParseException() throws SQLException {
    final int BATCH_SIZE = 7;

    final int FAILED_IDX = 5;

    for (int idx = 0, i = 0; i < FAILED_IDX; ++i, idx += i) {
        stmt.addBatch("insert into Person (_key, id, firstName, lastName, age) values "
            + generateValues(idx, i + 1));
    }

    stmt.addBatch("insert into Person (_key, id, firstName, lastName, age) values (4444, 'fail', 1, 1, 1)");

    stmt.addBatch("insert into Person (_key, id, firstName, lastName, age) values "
        + generateValues(100, 7));

    try {
        stmt.executeBatch();

        fail("BatchUpdateException must be thrown");
    } catch(BatchUpdateException e) {
        int [] updCnts = e.getUpdateCounts();

        assertEquals("Invalid update counts size", BATCH_SIZE, updCnts.length);

        for (int i = 0; i < BATCH_SIZE; ++i)
            assertEquals("Invalid update count: " + i, i != FAILED_IDX ? i + 1 : Statement.EXECUTE_FAILED,
                updCnts[i]);

        if (!e.getMessage().contains("Value conversion failed")) {
            log.error("Invalid exception: ", e);

            fail();
        }

        assertEquals("Invalid SQL state.", SqlStateCode.CONVERSION_FAILED, e.getSQLState());
        assertEquals("Invalid error code.", IgniteQueryErrorCode.CONVERSION_FAILED, e.getErrorCode());
    }
}
 
开发者ID:apache,项目名称:ignite,代码行数:42,代码来源:JdbcThinBatchSelfTest.java

示例9: testBatchMergeParseException

import java.sql.BatchUpdateException; //导入方法依赖的package包/类
/**
 * @throws SQLException If failed.
 */
public void testBatchMergeParseException() throws SQLException {
    final int BATCH_SIZE = 7;

    final int FAILED_IDX = 5;

    for (int idx = 0, i = 0; i < FAILED_IDX; ++i, idx += i) {
        stmt.addBatch("merge into Person (_key, id, firstName, lastName, age) values "
            + generateValues(idx, i + 1));
    }

    stmt.addBatch("merge into Person (_key, id, firstName, lastName, age) values (4444, 'FAIL', 1, 1, 1)");

    stmt.addBatch("merge into Person (_key, id, firstName, lastName, age) values "
        + generateValues(100, 7));

    try {
        stmt.executeBatch();

        fail("BatchUpdateException must be thrown");
    } catch(BatchUpdateException e) {
        int [] updCnts = e.getUpdateCounts();

        assertEquals("Invalid update counts size", BATCH_SIZE, updCnts.length);

        for (int i = 0; i < BATCH_SIZE; ++i)
            assertEquals("Invalid update count: " + i, i != FAILED_IDX ? i + 1 : Statement.EXECUTE_FAILED,
                updCnts[i]);

        if (!e.getMessage().contains("Value conversion failed")) {
            log.error("Invalid exception: ", e);

            fail();
        }

        assertEquals("Invalid SQL state.", SqlStateCode.CONVERSION_FAILED, e.getSQLState());
        assertEquals("Invalid error code.", IgniteQueryErrorCode.CONVERSION_FAILED, e.getErrorCode());
    }
}
 
开发者ID:apache,项目名称:ignite,代码行数:42,代码来源:JdbcThinBatchSelfTest.java

示例10: testHeterogeneousBatchException

import java.sql.BatchUpdateException; //导入方法依赖的package包/类
/**
 * @throws SQLException If failed.
 */
public void testHeterogeneousBatchException() throws SQLException {
    stmt.addBatch("insert into Person (_key, id, firstName, lastName, age) values ('p0', 0, 'Name0', 'Lastname0', 10)");
    stmt.addBatch("insert into Person (_key, id, firstName, lastName, age) values ('p1', 1, 'Name1', 'Lastname1', 20), ('p2', 2, 'Name2', 'Lastname2', 30)");
    stmt.addBatch("merge into Person (_key, id, firstName, lastName, age) values ('p3', 3, 'Name3', 'Lastname3', 40)");
    stmt.addBatch("update Person set id = 'FAIL' where age >= 30"); // Fail.
    stmt.addBatch("merge into Person (_key, id, firstName, lastName, age) values ('p0', 2, 'Name2', 'Lastname2', 50)");
    stmt.addBatch("delete from Person where FAIL <= 40"); // Fail.

    try {
        stmt.executeBatch();

        fail("BatchUpdateException must be thrown");
    } catch(BatchUpdateException e) {
        int[] updCnts = e.getUpdateCounts();

        if (!e.getMessage().contains("Value conversion failed")) {
            log.error("Invalid exception: ", e);

            fail();
        }

        assertEquals("Invalid update counts size", 6, updCnts.length);
        assertArrayEquals("Invalid update count",
            new int[] {1, 2, 1, Statement.EXECUTE_FAILED, 1, Statement.EXECUTE_FAILED}, updCnts);
    }
}
 
开发者ID:apache,项目名称:ignite,代码行数:30,代码来源:JdbcThinBatchSelfTest.java

示例11: testErrorAmidstBatch

import java.sql.BatchUpdateException; //导入方法依赖的package包/类
/**
 * @throws SQLException If failed.
 */
public void testErrorAmidstBatch() throws SQLException {
    BatchUpdateException reason = (BatchUpdateException)
        GridTestUtils.assertThrows(log,
        new Callable<Object>() {
            @Override public Object call() throws Exception {
                try (Statement stmt = conn.createStatement()) {
                    stmt.addBatch("INSERT INTO Person(_key, id, firstName, lastName, age, data) " +
                        "VALUES ('p1', 0, 'J', 'W', 250, RAWTOHEX('W'))");

                    stmt.addBatch("UPDATE Person SET id = 3, firstName = 'Mike', lastName = 'Green', " +
                        "age = 40, data = RAWTOHEX('Green') WHERE _key = 'p3'");

                    stmt.addBatch("SELECT id FROM Person WHERE _key = 'p1'");

                    return stmt.executeBatch();
                }
            }
        },
        BatchUpdateException.class,
        "Given statement type does not match that declared by JDBC driver");

    // Check update counts in the exception.
    int[] counts = reason.getUpdateCounts();

    assertEquals(2, counts.length);
    assertEquals(1, counts[0]);
    assertEquals(0, counts[1]);
}
 
开发者ID:apache,项目名称:ignite,代码行数:32,代码来源:JdbcStatementBatchingSelfTest.java

示例12: assertDeserialized

import java.sql.BatchUpdateException; //导入方法依赖的package包/类
public void assertDeserialized(Serializable initial,
        Serializable deserialized) {

    // do common checks for all throwable objects
    SerializationTest.THROWABLE_COMPARATOR.assertDeserialized(initial,
            deserialized);

    BatchUpdateException initThr = (BatchUpdateException) initial;
    BatchUpdateException dserThr = (BatchUpdateException) deserialized;

    // verify updateCounts
    int[] initUpdateCounts = initThr.getUpdateCounts();
    int[] dserUpdateCounts = dserThr.getUpdateCounts();
    assertTrue(Arrays.equals(initUpdateCounts, dserUpdateCounts));
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:16,代码来源:BatchUpdateExceptionTest.java

示例13: testContinueBatch01

import java.sql.BatchUpdateException; //导入方法依赖的package包/类
private void testContinueBatch01() throws SQLException {
    trace("testContinueBatch01");
    int[] batchUpdates = { 0, 0, 0 };
    int buCountLen = 0;
    try {
        String sPrepStmt = COFFEE_UPDATE_SET;
        trace("Prepared Statement String:" + sPrepStmt);
        prep = conn.prepareStatement(sPrepStmt);
        // Now add a legal update to the batch
        prep.setInt(1, 1);
        prep.setString(2, "Continue-1");
        prep.setString(3, "COFFEE-1");
        prep.addBatch();
        // Now add an illegal update to the batch by
        // forcing a unique constraint violation
        // Try changing the key_id of row 3 to 1.
        prep.setInt(1, 1);
        prep.setString(2, "Invalid");
        prep.setString(3, "COFFEE-3");
        prep.addBatch();
        // Now add a second legal update to the batch
        // which will be processed ONLY if the driver supports
        // continued batch processing according to 6.2.2.3
        // of the J2EE platform spec.
        prep.setInt(1, 2);
        prep.setString(2, "Continue-2");
        prep.setString(3, "COFFEE-2");
        prep.addBatch();
        // The executeBatch() method will result in a
        // BatchUpdateException
        prep.executeBatch();
    } catch (BatchUpdateException b) {
        trace("expected BatchUpdateException");
        batchUpdates = b.getUpdateCounts();
        buCountLen = batchUpdates.length;
    }
    if (buCountLen == 1) {
        trace("no continued updates - OK");
        return;
    } else if (buCountLen == 3) {
        trace("Driver supports continued updates.");
        // Check to see if the third row from the batch was added
        String query = COFFEE_SELECT_CONTINUED;
        trace("Query is: " + query);
        ResultSet rs = stat.executeQuery(query);
        rs.next();
        int count = rs.getInt(1);
        rs.close();
        stat.close();
        trace("Count val is: " + count);
        // make sure that we have the correct error code for
        // the failed update.
        if (!(batchUpdates[1] == -3 && count == 1)) {
            fail("insert failed");
        }
    }
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:58,代码来源:TestBatchUpdates.java

示例14: hibernateData

import java.sql.BatchUpdateException; //导入方法依赖的package包/类
/**
 * Hibernate data.
 *
 * @param article
 *            the article
 * @param session
 *            the session
 * @return true, if successful
 */
public synchronized boolean hibernateData(final NewsArticle article, final Session session) {
	Transaction tx = null;

	HibernateHelper.logger.debug("hibernateData: " + article.getArticleId());

	final Location location = null;
	final String gender = null;
	try {
		tx = session.beginTransaction();
		tx.begin();

		final UsenetUser poster = this.createUsenetUser(article, session, location, gender);

		final Message message = this.createMessage(article, null, poster);

		this.storeNewsgroups(article.getNewsgroupsList(), message, session);

		tx.commit();

	}
	catch (Exception e) {
		if (e instanceof GenericJDBCException) {
			e = (Exception) e.getCause();
		}
		if (e instanceof BatchUpdateException) {
			final BatchUpdateException buex = (BatchUpdateException) e;
			System.err.println("Contents of BatchUpdateException:");
			System.err.println(" Update counts: ");
			final int[] updateCounts = buex.getUpdateCounts();
			for (int i = 0; i < updateCounts.length; i++) {
				System.err.println("  Statement " + i + ":" + updateCounts[i]);
			}
			System.err.println(" Message: " + buex.getMessage());
			System.err.println(" SQLSTATE: " + buex.getSQLState());
			System.err.println(" Error code: " + buex.getErrorCode());
			System.err.println(" Article: " + article);

			SQLException ex = buex.getNextException();
			while (ex != null) {
				System.err.println("SQL exception:");
				System.err.println(" Message: " + ex.getMessage());
				System.err.println(" SQLSTATE: " + ex.getSQLState());
				System.err.println(" Error code: " + ex.getErrorCode());
				System.err.println(" Error code: " + ex.getErrorCode());

				ex = ex.getNextException();
			}

		}
		HibernateHelper.logger.error("Failed to store message", e);
		e.printStackTrace();
		if (tx != null) {
			try {
				tx.rollback();
			}
			catch (final HibernateException e1) {
				e1.printStackTrace();
				return false;
			}
		}
	}
	return true;
}
 
开发者ID:leonarduk,项目名称:unison,代码行数:73,代码来源:HibernateHelper.java

示例15: testBatchKeyDuplicatesException

import java.sql.BatchUpdateException; //导入方法依赖的package包/类
/**
 * @throws SQLException If failed.
 */
public void testBatchKeyDuplicatesException() throws SQLException {
    final int BATCH_SIZE = 7;

    final int FAILED_IDX = 5;

    int idx = 0;

    for (int i = 0; i < FAILED_IDX; ++i, idx += i) {
        stmt.addBatch("insert into Person (_key, id, firstName, lastName, age) values "
            + generateValues(idx, i + 1));
    }

    stmt.addBatch("insert into Person (_key, id, firstName, lastName, age) values ('p0', 0, 'Name0', 'Lastname0', 20)");

    stmt.addBatch("insert into Person (_key, id, firstName, lastName, age) values "
        + generateValues(++idx, 7));

    try {
        stmt.executeBatch();

        fail("BatchUpdateException must be thrown");
    } catch(BatchUpdateException e) {
        int [] updCnts = e.getUpdateCounts();

        assertEquals("Invalid update counts size", BATCH_SIZE, updCnts.length);

        for (int i = 0; i < BATCH_SIZE; ++i)
            assertEquals("Invalid update count: " + i, i != FAILED_IDX ? i + 1 : Statement.EXECUTE_FAILED,
                updCnts[i]);

        if (!e.getMessage().contains("Failed to INSERT some keys because they are already in cache [keys=[p0]")) {
            log.error("Invalid exception: ", e);

            fail();
        }

        assertEquals("Invalid SQL state.", SqlStateCode.CONSTRAINT_VIOLATION, e.getSQLState());
        assertEquals("Invalid error code.", IgniteQueryErrorCode.DUPLICATE_KEY, e.getErrorCode());
    }
}
 
开发者ID:apache,项目名称:ignite,代码行数:44,代码来源:JdbcThinBatchSelfTest.java


注:本文中的java.sql.BatchUpdateException.getUpdateCounts方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。