Search in sources :

Example 6 with DalTransactionManager

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

the class DalTransactionManagerTest method testGetConnection.

@Test
public void testGetConnection() {
    final DalHints hints = new DalHints();
    try {
        final DalTransactionManager test = new DalTransactionManager(getDalConnectionManager());
        assertFalse(DalTransactionManager.isInTransaction());
        ConnectionAction<?> action = new ConnectionAction<Object>() {

            public Object execute() throws Exception {
                Assert.assertNotNull(test.getConnection(hints, DalEventEnum.BATCH_CALL));
                return null;
            }
        };
        action.operation = DalEventEnum.EXECUTE;
        test.doInTransaction(action, hints);
    } catch (Exception e) {
        fail();
        e.printStackTrace();
    }
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) DalTransactionManager(com.ctrip.platform.dal.dao.client.DalTransactionManager) ConnectionAction(com.ctrip.platform.dal.dao.client.ConnectionAction) SQLException(java.sql.SQLException) Test(org.junit.Test)

Example 7 with DalTransactionManager

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

the class DalTransactionManagerTest method testGetCurrentDbMeta.

@Test
public void testGetCurrentDbMeta() {
    final DalHints hints = new DalHints();
    try {
        final DalTransactionManager test = new DalTransactionManager(getDalConnectionManager());
        assertFalse(DalTransactionManager.isInTransaction());
        ConnectionAction<?> action = new ConnectionAction<Object>() {

            public Object execute() throws Exception {
                assertNotNull(DalTransactionManager.getCurrentDbMeta());
                return null;
            }
        };
        action.operation = DalEventEnum.EXECUTE;
        test.doInTransaction(action, hints);
    } catch (Exception e) {
        fail();
        e.printStackTrace();
    }
    assertFalse(DalTransactionManager.isInTransaction());
    assertNull(DalTransactionManager.getCurrentDbMeta());
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) DalTransactionManager(com.ctrip.platform.dal.dao.client.DalTransactionManager) ConnectionAction(com.ctrip.platform.dal.dao.client.ConnectionAction) SQLException(java.sql.SQLException) Test(org.junit.Test)

Example 8 with DalTransactionManager

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

the class DalTransactionManagerTest method testDoInTransactionFail.

@Test
public void testDoInTransactionFail() {
    final DalHints hints = new DalHints();
    try {
        final DalTransactionManager test = new DalTransactionManager(getDalConnectionManager());
        assertFalse(DalTransactionManager.isInTransaction());
        ConnectionAction<?> action = new ConnectionAction<Object>() {

            public Object execute() throws Exception {
                throw new NullPointerException("test");
            }
        };
        action.operation = DalEventEnum.EXECUTE;
        test.doInTransaction(action, hints);
        fail();
    } catch (Exception e) {
        assertFalse(DalTransactionManager.isInTransaction());
        e.printStackTrace();
    }
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) DalTransactionManager(com.ctrip.platform.dal.dao.client.DalTransactionManager) ConnectionAction(com.ctrip.platform.dal.dao.client.ConnectionAction) SQLException(java.sql.SQLException) Test(org.junit.Test)

Example 9 with DalTransactionManager

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

the class DalTransactionManagerTest method testDoInTransaction.

@Test
public void testDoInTransaction() {
    final DalHints hints = new DalHints();
    try {
        final DalTransactionManager test = new DalTransactionManager(getDalConnectionManager());
        assertFalse(DalTransactionManager.isInTransaction());
        ConnectionAction<?> action = new ConnectionAction<Object>() {

            public Object execute() throws Exception {
                assertNotNull(DalTransactionManager.getCurrentDbMeta());
                return null;
            }
        };
        action.operation = DalEventEnum.EXECUTE;
        test.doInTransaction(action, hints);
    } catch (Exception e) {
        e.printStackTrace();
        fail();
    }
    assertFalse(DalTransactionManager.isInTransaction());
    assertNull(DalTransactionManager.getCurrentDbMeta());
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) DalTransactionManager(com.ctrip.platform.dal.dao.client.DalTransactionManager) ConnectionAction(com.ctrip.platform.dal.dao.client.ConnectionAction) SQLException(java.sql.SQLException) Test(org.junit.Test)

Example 10 with DalTransactionManager

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

the class ConnectionActionTest method testPopulateDbMetaInTransaction.

@Test
public void testPopulateDbMetaInTransaction() {
    TestConnectionAction test = new TestConnectionAction();
    try {
        DalTransactionManager tranManager = new DalTransactionManager(getDalConnectionManager());
        tranManager.doInTransaction(test, new DalHints());
        //			assertNotNull(test.entry.getDatabaseName());
        assertNotNull((test.entry).getDatabaseName());
    //assertNotNull(test.entry.getTag().get(LogEntry.TAG_USER_NAME)); be removed
    //assertNotNull(test.entry.getTag().get(LogEntry.TAG_SERVER_ADDRESS)); be removed
    } catch (Exception e) {
        e.printStackTrace();
        fail();
    }
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) DalTransactionManager(com.ctrip.platform.dal.dao.client.DalTransactionManager) Test(org.junit.Test)

Aggregations

DalHints (com.ctrip.platform.dal.dao.DalHints)12 DalTransactionManager (com.ctrip.platform.dal.dao.client.DalTransactionManager)12 Test (org.junit.Test)12 ConnectionAction (com.ctrip.platform.dal.dao.client.ConnectionAction)11 SQLException (java.sql.SQLException)11 DalTransactionListener (com.ctrip.platform.dal.dao.client.DalTransactionListener)4 DalClient (com.ctrip.platform.dal.dao.DalClient)1 DalCommand (com.ctrip.platform.dal.dao.DalCommand)1 StatementParameters (com.ctrip.platform.dal.dao.StatementParameters)1 ResultSet (java.sql.ResultSet)1