Search in sources :

Example 41 with DalHints

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

the class DalColumnMapRowMapperTest method testDalColumnMapRowMapperEmpty.

@Test
public void testDalColumnMapRowMapperEmpty() {
    try {
        StatementParameters parameters = new StatementParameters();
        DalClient client = DalClientFactory.getClient(DATABASE_NAME);
        List<Map<String, Object>> result1 = client.query(sqlNoResult, parameters, new DalHints(), new DalRowMapperExtractor<Map<String, Object>>(new DalColumnMapRowMapper()));
        assertEquals(0, result1.size());
        DalQueryDao dao = new DalQueryDao(DATABASE_NAME);
        List<Map<String, Object>> result = dao.query(sqlNoResult, parameters, hints, new DalColumnMapRowMapper());
        assertEquals(0, result.size());
    } catch (Exception e) {
        fail();
    }
}
Also used : DalClient(com.ctrip.platform.dal.dao.DalClient) DalHints(com.ctrip.platform.dal.dao.DalHints) StatementParameters(com.ctrip.platform.dal.dao.StatementParameters) DalColumnMapRowMapper(com.ctrip.platform.dal.dao.helper.DalColumnMapRowMapper) DalQueryDao(com.ctrip.platform.dal.dao.DalQueryDao) Map(java.util.Map) SQLException(java.sql.SQLException) Test(org.junit.Test)

Example 42 with DalHints

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

the class MySqlHelperTest method tearDownAfterClass.

@AfterClass
public static void tearDownAfterClass() throws Exception {
    DalHints hints = new DalHints();
    String[] sqls = new String[] { DROP_TABLE_SQL_MYSQL_TPL };
    clientMySql.batchUpdate(sqls, hints);
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) AfterClass(org.junit.AfterClass)

Example 43 with DalHints

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

the class MySqlHelperTest method replaceTest.

@Test
public void replaceTest() throws SQLException {
    int count = 3;
    List<Person> persons = new ArrayList<>();
    for (int i = 1; i <= count; i++) {
        Person pojo1 = new Person();
        pojo1.setID(i);
        pojo1.setName("forest" + i);
        pojo1.setBirth(new Timestamp(System.currentTimeMillis()));
        persons.add(pojo1);
    }
    client.delete(hints, persons);
    KeyHolder holder = new KeyHolder();
    helper.replace(holder, hints, persons);
    List<Map<String, Object>> generateKeys = holder.getKeyList();
    assertTrue(generateKeys.size() == 3);
    assertTrue(generateKeys.get(0).containsKey("GENERATED_KEY"));
    persons.get(1).setName("jack1");
    helper.replace(holder, new DalHints(), persons);
    Person rep = client.queryByPk(2, hints);
    assertTrue(rep.getName().equals("jack1"));
    client.delete(hints, persons);
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) ArrayList(java.util.ArrayList) KeyHolder(com.ctrip.platform.dal.dao.KeyHolder) Timestamp(java.sql.Timestamp) Map(java.util.Map) Test(org.junit.Test)

Example 44 with DalHints

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

the class ShardColModShardStrategyTest method testLocateDbShardByShardValue.

@Test
public void testLocateDbShardByShardValue() throws Exception {
    DalConfigure configure = DalConfigureFactory.load();
    ShardColModShardStrategy strategy = new ShardColModShardStrategy();
    Map<String, String> settings = new HashMap<String, String>();
    settings.put(ShardColModShardStrategy.COLUMNS, "id,id1");
    settings.put(ShardColModShardStrategy.MOD, "2");
    settings.put(ShardColModShardStrategy.TABLE_COLUMNS, "index,index1");
    settings.put(ShardColModShardStrategy.TABLE_MOD, "4");
    strategy.initialize(settings);
    assertEquals("0", strategy.locateDbShard(configure, logicDbName, new DalHints().setShardValue(0)));
    assertEquals("1", strategy.locateDbShard(configure, logicDbName, new DalHints().setShardValue(1)));
    assertEquals("0", strategy.locateDbShard(configure, logicDbName, new DalHints().setShardValue(2)));
    assertEquals("1", strategy.locateDbShard(configure, logicDbName, new DalHints().setShardValue(3)));
    assertEquals("0", strategy.locateDbShard(configure, logicDbName, new DalHints().setShardValue(100000000000L)));
    assertEquals("1", strategy.locateDbShard(configure, logicDbName, new DalHints().setShardValue(100000000001L)));
    assertEquals("0", strategy.locateDbShard(configure, logicDbName, new DalHints().setShardValue(100000000002L)));
    assertEquals("1", strategy.locateDbShard(configure, logicDbName, new DalHints().setShardValue(100000000003L)));
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) DalConfigure(com.ctrip.platform.dal.dao.configure.DalConfigure) HashMap(java.util.HashMap) ShardColModShardStrategy(com.ctrip.platform.dal.dao.strategy.ShardColModShardStrategy) Test(org.junit.Test)

Example 45 with DalHints

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

the class DalTabelDaoShardByTableSqlSvrTest method tearDown.

@After
public void tearDown() throws Exception {
    String sql = "DELETE FROM " + TABLE_NAME;
    StatementParameters parameters = new StatementParameters();
    DalHints hints = new DalHints();
    sql = "DELETE FROM " + TABLE_NAME;
    parameters = new StatementParameters();
    hints = new DalHints();
    try {
        for (int i = 0; i < mod; i++) {
            clientSqlSvr.update(sql + "_" + i, parameters, hints);
        }
    } catch (SQLException e) {
        e.printStackTrace();
    }
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) SQLException(java.sql.SQLException) StatementParameters(com.ctrip.platform.dal.dao.StatementParameters) After(org.junit.After)

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