Search in sources :

Example 1 with ThrowExceptionDalCommand

use of com.ctrip.platform.dal.dao.client.DalCommand.ThrowExceptionDalCommand in project dal by ctripcorp.

the class DalCommandTest method testBatchOperationThrowExceptionInDalCommand.

// Two layer transaction with exception which should throws actual exception
@Test
public void testBatchOperationThrowExceptionInDalCommand() throws Exception {
    DalClient client = DalClientFactory.getClient(dbName);
    try {
        client.execute(new ThrowExceptionDalCommand(), new DalHints());
        Assert.fail();
    } catch (Throwable e) {
        System.out.println(e.getMessage());
        Assert.assertTrue(e instanceof BatchUpdateException);
        Assert.assertTrue(e.getMessage().equals("Data truncation: Data too long for column 'Name' at row 1"));
        Assert.assertTrue(isCurrentTransactionNull());
    }
}
Also used : DalClient(com.ctrip.platform.dal.dao.DalClient) DalHints(com.ctrip.platform.dal.dao.DalHints) ThrowExceptionDalCommand(com.ctrip.platform.dal.dao.client.DalCommand.ThrowExceptionDalCommand) BatchUpdateException(java.sql.BatchUpdateException) Test(org.junit.Test)

Aggregations

DalClient (com.ctrip.platform.dal.dao.DalClient)1 DalHints (com.ctrip.platform.dal.dao.DalHints)1 ThrowExceptionDalCommand (com.ctrip.platform.dal.dao.client.DalCommand.ThrowExceptionDalCommand)1 BatchUpdateException (java.sql.BatchUpdateException)1 Test (org.junit.Test)1