use of com.ctrip.platform.dal.dao.StatementParameters in project dal by ctripcorp.
the class BaseDalTableDaoShardByDbTest method testBatchUpdateMultipleCallback.
public void testBatchUpdateMultipleCallback() throws SQLException {
DalHints hints = new DalHints();
List<ClientTestModel> entities = new ArrayList<>();
for (int i = 0; i < 3; i++) {
ClientTestModel model = new ClientTestModel();
model.setId(i + 1);
model.setAddress("CTRIP");
entities.add(model);
}
int[] ress;
try {
ress = dao.batchUpdate(hints, entities);
fail();
} catch (Exception e) {
}
// By fields same shard
// holder = createKeyHolder();
entities.get(0).setTableIndex(0);
entities.get(0).setAddress("1234");
entities.get(1).setTableIndex(0);
entities.get(1).setAddress("1234");
entities.get(2).setTableIndex(0);
entities.get(2).setAddress("1234");
IntCallback callback = new IntCallback();
hints = new DalHints().callbackWith(callback);
ress = dao.batchUpdate(hints, entities);
assertNull(ress);
ress = callback.getIntArray();
assertResEquals(3, ress);
List<ClientTestModel> result = dao.query("1=1", new StatementParameters(), new DalHints().inShard(0));
for (ClientTestModel m : result) assertEquals("1234", m.getAddress());
}
use of com.ctrip.platform.dal.dao.StatementParameters in project dal by ctripcorp.
the class AbstractSqlBuilder method buildParameters.
/**
* 获取StatementParameters
* @return
*/
public StatementParameters buildParameters() {
parameters = new StatementParameters();
index = 1;
for (FieldEntry entry : selectOrUpdataFieldEntrys) {
parameters.add(new StatementParameter(index++, entry.getSqlType(), entry.getParamValue()).setSensitive(entry.isSensitive()).setName(entry.getFieldName()).setInParam(entry.isInParam()));
}
for (FieldEntry entry : whereFieldEntrys) {
parameters.add(new StatementParameter(index++, entry.getSqlType(), entry.getParamValue()).setSensitive(entry.isSensitive()).setName(entry.getFieldName()).setInParam(entry.isInParam()));
}
return this.parameters;
}
use of com.ctrip.platform.dal.dao.StatementParameters in project dal by ctripcorp.
the class InsertSqlBuilder method buildParameters.
public StatementParameters buildParameters() {
StatementParameters parameters = new StatementParameters();
int index = 1;
for (FieldEntry entry : fieldEntrys) {
if (entry.isSensitive())
parameters.setSensitive(index++, entry.getFieldName(), entry.getSqlType(), entry.getParamValue());
else
parameters.set(index++, entry.getFieldName(), entry.getSqlType(), entry.getParamValue());
}
return parameters;
}
use of com.ctrip.platform.dal.dao.StatementParameters in project dal by ctripcorp.
the class DalSqlTaskRequest method createTasks.
@Override
public Map<String, Callable<T>> createTasks() throws SQLException {
Map<String, Callable<T>> tasks = new HashMap<>();
if (parametersByShard == null) {
// Create by given shards
for (String shard : shards) {
tasks.put(shard, create(parameters.duplicate(), hints.clone().inShard(shard)));
}
} else {
// Create by sharded values
for (Map.Entry<String, ?> shard : parametersByShard.entrySet()) {
StatementParameters tempParameters = parameters.duplicateWith(hints.getShardBy(), (List) shard.getValue());
tasks.put(shard.getKey(), create(tempParameters, hints.clone().inShard(shard.getKey())));
}
}
return tasks;
}
use of com.ctrip.platform.dal.dao.StatementParameters in project dal by ctripcorp.
the class StatementParametersTest method testDuplicate.
@Test
public void testDuplicate() {
StatementParameters test = new StatementParameters();
test.set(1, "name1", Types.INTEGER, 1);
test.set(2, "name2", Types.INTEGER, 2);
StatementParameters test2 = test.duplicateWith("name1", 2);
StatementParameters test3 = test.duplicateWith("name1", 3);
assertEquals(2, test.size());
assertEquals(2, test2.size());
assertEquals(2, test3.size());
assertEquals(1, test.get(0).getValue());
assertEquals(2, test.get(1).getValue());
assertEquals(2, test2.get(0).getValue());
assertEquals(2, test2.get(1).getValue());
assertEquals(3, test3.get(0).getValue());
assertEquals(2, test3.get(1).getValue());
}
Aggregations