Search in sources :

Example 31 with DalHints

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

the class DalQueryDaoTestStub method testQueryWithClazz.

@Test
public void testQueryWithClazz() throws SQLException {
    String sql = "SELECT quantity FROM " + TABLE_NAME;
    StatementParameters param = new StatementParameters();
    DalHints hints = new DalHints();
    List<Integer> models = client.query(sql, param, hints, Integer.class);
    Assert.assertEquals(ROW_COUNT, models.size());
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) StatementParameters(com.ctrip.platform.dal.dao.StatementParameters) Test(org.junit.Test)

Example 32 with DalHints

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

the class DalTransactionManagerTest method testRegister.

@Test
public void testRegister() {
    final DalHints hints = new DalHints();
    final DalTransactionListener testListener = new DalTransactionListener() {

        @Override
        public void beforeCommit() {
        }

        @Override
        public void beforeRollback() {
        }

        @Override
        public void afterCommit() {
        }

        @Override
        public void afterRollback() {
        }
    };
    try {
        final DalTransactionManager test = new DalTransactionManager(getDalConnectionManager());
        DalTransactionManager.register(testListener);
        fail();
    } catch (Exception e) {
    }
    try {
        final DalTransactionManager test = new DalTransactionManager(getDalConnectionManager());
        ConnectionAction<?> action = new ConnectionAction<Object>() {

            public Object execute() throws Exception {
                DalTransactionManager.register(testListener);
                return null;
            }
        };
        action.operation = DalEventEnum.EXECUTE;
        test.doInTransaction(action, hints);
    } catch (Exception e) {
        e.printStackTrace();
        fail();
    }
}
Also used : DalTransactionListener(com.ctrip.platform.dal.dao.client.DalTransactionListener) 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 33 with DalHints

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

the class PartialQueryQueryDaoTest method testAllowPartial.

@Test
public void testAllowPartial() throws Exception {
    // Test value here
    String name = "Test";
    List<Integer> cityIds = new ArrayList<>();
    cityIds.add(1);
    cityIds.add(2);
    cityIds.add(3);
    DalHints hints = new DalHints();
    FreeEntityMismatchPojo ret;
    try {
        hints = new DalHints();
        ret = findFreeFirstMismatch(name, cityIds, hints.inShard(1));
        fail();
    } catch (DalException e) {
        Assert.assertEquals(ErrorCode.ResultMappingError.getCode(), e.getErrorCode());
    }
    hints = new DalHints().allowPartial();
    ret = findFreeFirstMismatch(name, cityIds, hints.inShard(1));
    assertNotNull(ret);
    hints = new DalHints().allowPartial();
    ret = findFreeFirstMismatch(name, cityIds, hints.inAllShards());
    assertNotNull(ret);
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) DalException(com.ctrip.platform.dal.exceptions.DalException) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 34 with DalHints

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

the class DalTransactionManagerTest method testIsInTransaction.

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

            public Object execute() throws Exception {
                Assert.assertTrue(DalTransactionManager.isInTransaction());
                return null;
            }
        };
        action.operation = DalEventEnum.EXECUTE;
        test.doInTransaction(action, new DalHints());
    } 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 35 with DalHints

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

the class DalTransactionManagerTest method testClearCurrentTransaction.

@Test
public void testClearCurrentTransaction() {
    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)

Aggregations

DalHints (com.ctrip.platform.dal.dao.DalHints)772 Test (org.junit.Test)532 StatementParameters (com.ctrip.platform.dal.dao.StatementParameters)317 SQLException (java.sql.SQLException)298 ArrayList (java.util.ArrayList)132 ClientTestModel (test.com.ctrip.platform.dal.dao.unitbase.ClientTestModel)61 List (java.util.List)48 KeyHolder (com.ctrip.platform.dal.dao.KeyHolder)45 FreeSelectSqlBuilder (com.ctrip.platform.dal.dao.sqlbuilder.FreeSelectSqlBuilder)39 Future (java.util.concurrent.Future)32 DalTableDao (com.ctrip.platform.dal.dao.DalTableDao)29 SelectionContext (com.ctrip.platform.dal.dao.configure.SelectionContext)27 DalDefaultJpaParser (com.ctrip.platform.dal.dao.helper.DalDefaultJpaParser)27 DataBase (com.ctrip.platform.dal.dao.configure.DataBase)26 BeforeClass (org.junit.BeforeClass)26 AfterClass (org.junit.AfterClass)25 HashMap (java.util.HashMap)23 FreeUpdateSqlBuilder (com.ctrip.platform.dal.dao.sqlbuilder.FreeUpdateSqlBuilder)20 DalClient (com.ctrip.platform.dal.dao.DalClient)18 BatchUpdateTask (com.ctrip.platform.dal.dao.task.BatchUpdateTask)18