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();
}
}
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);
}
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);
}
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)));
}
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();
}
}
Aggregations