use of com.ctrip.platform.dal.dao.StatementParameters in project dal by ctripcorp.
the class BatchUpdateTaskTestStub method testNotUpdatableVersion.
@Test
public void testNotUpdatableVersion() throws SQLException {
BatchUpdateTask<NonUpdatableVersionModel> test = new BatchUpdateTask<>();
DalParser<NonUpdatableVersionModel> parser = new DalDefaultJpaParser<>(NonUpdatableVersionModel.class, getDbName());
test.initialize(parser);
DalTableDao<NonUpdatableVersionModel> dao = new DalTableDao<>(parser);
DalHints hints = new DalHints();
List<NonUpdatableVersionModel> pojos = dao.query("1=1", new StatementParameters(), new DalHints());
for (NonUpdatableVersionModel model : pojos) {
model.setAddress("1122334455");
}
int[] result = execute(test, hints, pojos);
assertArrayEquals(new int[] { 1, 1, 1 }, result);
pojos = dao.query("1=1", new StatementParameters(), new DalHints());
for (NonUpdatableVersionModel model : pojos) assertEquals("1122334455", model.getAddress());
}
use of com.ctrip.platform.dal.dao.StatementParameters in project dal by ctripcorp.
the class DalSqlTaskRequestTest method testCreateTasksByInParameters.
@Test
public void testCreateTasksByInParameters() {
DalSqlTaskRequest<Integer> test = null;
try {
// Shard by in parameter
DalHints hints = new DalHints();
hints.shardBy("index");
StatementParameters p = new StatementParameters();
p.set(1, 1);
List<Integer> l = new ArrayList<>();
l.add(1);
l.add(2);
l.add(3);
l.add(4);
p.setInParameter(2, "index", Types.INTEGER, l);
p.set(3, 1);
test = new DalSqlTaskRequest<>("dao_test_sqlsvr_dbShard", new TestSqlBuilder("select * from tablea where id = ? and id in (?) and id = ?", p), hints, new TestSqlTask(1), new ResultMerger.IntSummary());
Map<String, Callable<Integer>> tasks = test.createTasks();
int i = 0;
for (Callable<Integer> task : tasks.values()) {
i += task.call().intValue();
}
assertEquals(2, i);
} catch (Exception e) {
fail();
}
assertNotNull(test.getMerger());
}
use of com.ctrip.platform.dal.dao.StatementParameters in project dal by ctripcorp.
the class BatchUpdateTaskTestStub method testDaoExcludeColumns.
@Test
public void testDaoExcludeColumns() throws SQLException {
DalTableDao<UpdatableIntVersionModel> dao = new DalTableDao<>(UpdatableIntVersionModel.class, getDbName());
DalHints hints = new DalHints().exclude("dbIndex");
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 DalStatementCreator method createCallableStatement.
public CallableStatement createCallableStatement(Connection conn, String sql, StatementParameters[] parametersList, DalHints hints) throws Exception {
CallableStatement statement = conn.prepareCall(sql);
applyHints(statement, hints);
for (StatementParameters parameters : parametersList) {
setParameter(statement, parameters);
statement.addBatch();
}
return statement;
}
use of com.ctrip.platform.dal.dao.StatementParameters in project dal by ctripcorp.
the class DalStatementCreator method createPreparedStatement.
public PreparedStatement createPreparedStatement(Connection conn, String sql, StatementParameters[] parametersList, DalHints hints) throws Exception {
PreparedStatement statement = conn.prepareStatement(sql, getResultSetType(hints), getResultSetConcurrency(hints));
applyHints(statement, hints);
for (StatementParameters parameters : parametersList) {
setParameter(statement, parameters);
statement.addBatch();
}
return statement;
}
Aggregations