use of com.ctrip.platform.dal.dao.DalHints in project dal by ctripcorp.
the class DalDefaultJpaParserSqlServerTest method testBatch.
@Test
public void testBatch() throws SQLException {
ClientTestModel[] models = new ClientTestModel[ROW_COUNT];
for (int i = 0; i < ROW_COUNT; i++) {
ClientTestModel model = new ClientTestModel();
model.setQuantity(10 + 1 % 3);
model.setType(((Number) (1 % 3)).shortValue());
model.setAddress("CTRIP");
models[i] = model;
}
DalHints hints = new DalHints();
int[] res = dao.batchInsert(hints, Arrays.asList(models));
Assert.assertEquals(ROW_COUNT, res.length);
StatementParameters parameters = new StatementParameters();
List<ClientTestModel> db_models = dao.query("1=1", parameters, hints);
Assert.assertEquals(ROW_COUNT, db_models.size());
dao.delete(hints, db_models);
Assert.assertEquals(0, DalTestHelper.getCount(dao));
}
use of com.ctrip.platform.dal.dao.DalHints in project dal by ctripcorp.
the class BaseDalTabelDaoShardByTableTest method testCrossShardBatchInsertCallback.
@Test
public void testCrossShardBatchInsertCallback() {
try {
deleteAllShards();
ClientTestModel p = new ClientTestModel();
ClientTestModel[] pList = new ClientTestModel[6];
p = new ClientTestModel();
p.setId(1);
p.setAddress("aaa");
p.setTableIndex(0);
pList[0] = p;
p = new ClientTestModel();
p.setId(2);
p.setAddress("aaa");
p.setTableIndex(1);
pList[1] = p;
p = new ClientTestModel();
p.setId(3);
p.setAddress("aaa");
p.setTableIndex(2);
pList[2] = p;
p = new ClientTestModel();
p.setId(4);
p.setAddress("aaa");
p.setTableIndex(3);
pList[3] = p;
p = new ClientTestModel();
p.setId(5);
p.setAddress("aaa");
p.setTableIndex(4);
pList[4] = p;
p = new ClientTestModel();
p.setId(5);
p.setAddress("aaa");
p.setTableIndex(5);
pList[5] = p;
DalHints hints = intHints();
int[] res = dao.batchInsert(hints, Arrays.asList(pList));
assertIntArray(res, hints);
assertEquals(2, getCount(0));
assertEquals(2, getCount(1));
assertEquals(1, getCount(2));
assertEquals(1, getCount(3));
} catch (Exception e) {
fail();
}
}
use of com.ctrip.platform.dal.dao.DalHints in project dal by ctripcorp.
the class BaseDalTabelDaoShardByTableTest method testQueryByPkAsyncCallback.
@Test
public void testQueryByPkAsyncCallback() throws SQLException {
ClientTestModel model = null;
DalHints hints;
for (int i = 0; i < mod; i++) {
// By tabelShard
hints = new DalHints().asyncExecution();
if (i % 2 == 0)
model = dao.queryByPk(1, hints.inTableShard(String.valueOf(i)));
else
model = dao.queryByPk(1, hints.inTableShard(i));
model = assertModel(model, hints);
assertEquals(1, model.getId().intValue());
assertEquals(i, model.getTableIndex().intValue());
// By tableShardValue
hints = callbackHints();
if (i % 2 == 0)
model = dao.queryByPk(1, hints.setTableShardValue(String.valueOf(i)));
else
model = dao.queryByPk(1, hints.setTableShardValue(i));
model = assertModel(model, hints);
assertEquals(1, model.getId().intValue());
assertEquals(i, model.getTableIndex().intValue());
// By shardColValue
hints = new DalHints().asyncExecution();
if (i % 2 == 0)
model = dao.queryByPk(1, hints.setShardColValue("index", String.valueOf(i)));
else
model = dao.queryByPk(1, hints.setShardColValue("index", i));
model = assertModel(model, hints);
assertEquals(1, model.getId().intValue());
assertEquals(i, model.getTableIndex().intValue());
// By shardColValue
hints = callbackHints();
if (i % 2 == 0)
model = dao.queryByPk(1, hints.setShardColValue("tableIndex", String.valueOf(i)));
else
model = dao.queryByPk(1, hints.setShardColValue("tableIndex", i));
model = assertModel(model, hints);
assertEquals(1, model.getId().intValue());
assertEquals(i, model.getTableIndex().intValue());
}
}
use of com.ctrip.platform.dal.dao.DalHints in project dal by ctripcorp.
the class BaseDalTabelDaoShardByTableTest method testQueryWithWhereClauseAsymcCallback.
@Test
public void testQueryWithWhereClauseAsymcCallback() throws SQLException {
List<ClientTestModel> models = null;
DalHints hints;
for (int i = 0; i < mod; i++) {
String whereClause = "type=? and id=?";
StatementParameters parameters = new StatementParameters();
parameters.set(1, Types.SMALLINT, 1);
parameters.set(2, Types.INTEGER, 1);
// By tabelShard
hints = new DalHints().asyncExecution();
models = dao.query(whereClause, parameters, hints.inTableShard(i));
models = assertModels(models, hints);
assertEquals(1, models.size());
assertEquals("SH INFO", models.get(0).getAddress());
assertEquals(models.get(0).getTableIndex(), new Integer(i));
// By tableShardValue
hints = callbackHints();
models = dao.query(whereClause, parameters, hints.setTableShardValue(i));
models = assertModels(models, hints);
assertEquals(1, models.size());
assertEquals("SH INFO", models.get(0).getAddress());
assertEquals(models.get(0).getTableIndex(), new Integer(i));
// By shardColValue
hints = new DalHints().asyncExecution();
models = dao.query(whereClause, parameters, hints.setShardColValue("index", i));
models = assertModels(models, hints);
assertEquals(1, models.size());
assertEquals("SH INFO", models.get(0).getAddress());
assertEquals(models.get(0).getTableIndex(), new Integer(i));
// By shardColValue
hints = callbackHints();
models = dao.query(whereClause, parameters, hints.setShardColValue("tableIndex", i));
models = assertModels(models, hints);
assertEquals(1, models.size());
assertEquals("SH INFO", models.get(0).getAddress());
assertEquals(models.get(0).getTableIndex(), new Integer(i));
// By parameters
hints = new DalHints().asyncExecution();
whereClause += " and tableIndex=?";
parameters = new StatementParameters();
parameters.set(1, "type", Types.SMALLINT, 1);
parameters.set(2, "id", Types.SMALLINT, i + 1);
parameters.set(3, "tableIndex", Types.SMALLINT, i);
models = dao.query(whereClause, parameters, hints);
models = assertModels(models, hints);
assertEquals(1, models.size());
assertEquals("SH INFO", models.get(0).getAddress());
assertEquals(models.get(0).getTableIndex(), new Integer(i));
}
}
use of com.ctrip.platform.dal.dao.DalHints in project dal by ctripcorp.
the class MarkdownAndUpIntergration method testQuery.
private void testQuery(String logicName) throws SQLException {
DalClient client = DalClientFactory.getClient(logicName);
client.query("SELECT 1", new StatementParameters(), new DalHints(), new DalResultSetExtractor<Integer>() {
@Override
public Integer extract(ResultSet rs) throws SQLException {
return null;
}
});
}
Aggregations