use of com.ctrip.platform.dal.dao.StatementParameters in project dal by ctripcorp.
the class BaseDalTabelDaoShardByTableTest method testDeleteWithWhereClauseAsyncCallback.
@Test
public void testDeleteWithWhereClauseAsyncCallback() throws SQLException {
DalHints hints;
String whereClause = "type=?";
StatementParameters parameters = new StatementParameters();
parameters.set(1, Types.SMALLINT, 1);
int res;
try {
hints = asyncHints();
res = dao.delete(whereClause, parameters, hints);
res = assertInt(res, hints);
fail();
} catch (Exception e) {
}
// By tabelShard
hints = asyncHints();
res = dao.delete(whereClause, parameters, hints.inTableShard(0));
res = assertInt(res, hints);
assertEquals(0, dao.query(whereClause, parameters, new DalHints().inTableShard(0)).size());
// By tableShardValue
assertEquals(2, getCount(1));
hints = intHints();
res = dao.delete(whereClause, parameters, hints.setTableShardValue(1));
res = assertInt(res, hints);
assertEquals(0, dao.query(whereClause, parameters, new DalHints().setTableShardValue(1)).size());
// By shardColValue
assertEquals(3, getCount(2));
hints = asyncHints();
res = dao.delete(whereClause, parameters, hints.setShardColValue("index", 2));
res = assertInt(res, hints);
assertEquals(0, dao.query(whereClause, parameters, new DalHints().setShardColValue("index", 2)).size());
// By shardColValue
assertEquals(4, getCount(3));
hints = intHints();
res = dao.delete(whereClause, parameters, hints.setShardColValue("tableIndex", 3));
res = assertInt(res, hints);
assertEquals(0, dao.query(whereClause, parameters, new DalHints().setShardColValue("tableIndex", 3)).size());
}
use of com.ctrip.platform.dal.dao.StatementParameters in project dal by ctripcorp.
the class BaseDalTabelDaoShardByTableTest method deleteAllShards.
private void deleteAllShards() throws SQLException {
for (int i = 0; i < mod; i++) {
int j = 1;
dao.delete("1=1", new StatementParameters(), new DalHints().inTableShard(i));
}
}
use of com.ctrip.platform.dal.dao.StatementParameters in project dal by ctripcorp.
the class BatchUpdateTaskTestStub method testDaoIncludeExcludeColumns.
@Test
public void testDaoIncludeExcludeColumns() throws SQLException {
DalTableDao<UpdatableIntVersionModel> dao = new DalTableDao<>(UpdatableIntVersionModel.class, getDbName());
DalHints hints = new DalHints().exclude("dbIndex").include("quantity", "dbIndex", "address");
List<UpdatableIntVersionModel> pojos = dao.query("1=1", new StatementParameters(), new DalHints());
for (UpdatableIntVersionModel model : pojos) {
model.setQuantity(500);
model.setDbIndex(100);
model.setAddress("1122334455");
}
int[] result = dao.batchUpdate(hints, pojos);
assertArrayEquals(new int[] { 1, 1, 1 }, result);
pojos = dao.query("1=1", new StatementParameters(), new DalHints());
for (UpdatableIntVersionModel model : pojos) {
assertEquals("1122334455", model.getAddress());
assertEquals(500, model.getQuantity().intValue());
assertEquals(0, model.getDbIndex().intValue());
}
}
use of com.ctrip.platform.dal.dao.StatementParameters in project dal by ctripcorp.
the class InsertSqlBuilderTest method testBuildSqlsvr.
@Test
public void testBuildSqlsvr() throws SQLException {
InsertSqlBuilder isb = new InsertSqlBuilder().from("table").setDatabaseCategory(DatabaseCategory.SqlServer);
isb.set("f1", 1, Types.INTEGER);
isb.setSensitive("f2", "abc", Types.VARBINARY);
assertEquals("INSERT INTO [table] ([f1], [f2]) VALUES(?, ?)", isb.build());
assertEquals("INSERT INTO [table_0] ([f1], [f2]) VALUES(?, ?)", isb.build("_0"));
StatementParameters p = isb.buildParameters();
assertEquals(2, p.size());
}
use of com.ctrip.platform.dal.dao.StatementParameters in project dal by ctripcorp.
the class InsertSqlBuilderTest method testBuildMySql.
@Test
public void testBuildMySql() throws SQLException {
InsertSqlBuilder isb = new InsertSqlBuilder().from("table").setDatabaseCategory(DatabaseCategory.MySql);
isb.set("f1", 1, Types.INTEGER);
isb.setSensitive("f2", "abc", Types.VARBINARY);
assertEquals("INSERT INTO `table` (`f1`, `f2`) VALUES(?, ?)", isb.build());
assertEquals("INSERT INTO `table_0` (`f1`, `f2`) VALUES(?, ?)", isb.build("_0"));
StatementParameters p = isb.buildParameters();
assertEquals(2, p.size());
}
Aggregations