use of com.ctrip.platform.dal.dao.sqlbuilder.FreeSelectSqlBuilder in project dal by ctripcorp.
the class DalQueryDaoTest method testQueryListAllShardsBuilder.
@Test
public void testQueryListAllShardsBuilder() throws SQLException {
String address = null;
Integer id = 1;
FreeSelectSqlBuilder<List<ClientTestModel>> query = new FreeSelectSqlBuilder<>();
query.selectAll().from(TABLE_NAME).where(like("address ").ignoreNull(address), AND, equal("id").ignoreNull(id));
query.mapWith(ClientTestModel.class);
DalQueryDao dao = new DalQueryDao(logicDbName);
StatementParameters parameters = new StatementParameters();
parameters.set(1, 1);
List<ClientTestModel> l = dao.query(query, parameters, new DalHints().inAllShards());
Assert.assertTrue(l.size() > 0);
}
use of com.ctrip.platform.dal.dao.sqlbuilder.FreeSelectSqlBuilder in project dal by ctripcorp.
the class DalQueryDaoTest method testQueryListAllShardsBuilderWhen.
@Test
public void testQueryListAllShardsBuilderWhen() throws SQLException {
String address = null;
Integer id = 1;
FreeSelectSqlBuilder<List<ClientTestModel>> query = new FreeSelectSqlBuilder<>();
query.selectAll().from(TABLE_NAME).where(like("address ").when(address != null), AND, equal("id").when(id != null));
query.mapWith(ClientTestModel.class);
DalQueryDao dao = new DalQueryDao(logicDbName);
StatementParameters parameters = new StatementParameters();
parameters.set(1, 1);
List<ClientTestModel> l = dao.query(query, parameters, new DalHints().inAllShards());
Assert.assertTrue(l.size() > 0);
}
use of com.ctrip.platform.dal.dao.sqlbuilder.FreeSelectSqlBuilder in project dal by ctripcorp.
the class DalQueryDaoTest method queryListForInParamBuilderNew1.
// Test in parameters
private List<Short> queryListForInParamBuilderNew1(DalHints hints) throws SQLException {
StatementParameters parameters = new StatementParameters();
FreeSelectSqlBuilder<List<Short>> builder = new FreeSelectSqlBuilder<>();
builder.with(parameters);
List<Integer> inParam = new ArrayList<>();
inParam.add(0);
inParam.add(1);
inParam.add(2);
inParam.add(3);
inParam.add(4);
builder.selectAll().from(TABLE_NAME).where(in("type", inParam, Types.INTEGER));
builder.mapWith(new ShortRowMapper());
return dao.query(builder, parameters, hints.shardBy("type"));
}
use of com.ctrip.platform.dal.dao.sqlbuilder.FreeSelectSqlBuilder in project dal by ctripcorp.
the class DalQueryDaoTest method queryListForInParamBuilderNew.
// Test in parameters
private List<Short> queryListForInParamBuilderNew(DalHints hints) throws SQLException {
StatementParameters parameters = new StatementParameters();
FreeSelectSqlBuilder<List<Short>> builder = new FreeSelectSqlBuilder<>(dbCategory);
builder.with(parameters);
List<Integer> inParam = new ArrayList<>();
inParam.add(0);
inParam.add(1);
inParam.add(2);
inParam.add(3);
inParam.add(4);
builder.setIn("type", inParam, Types.INTEGER);
builder.setTemplate(sqlInParam);
builder.mapWith(new ShortRowMapper());
return dao.query(builder, parameters, hints.shardBy("type"));
}
use of com.ctrip.platform.dal.dao.sqlbuilder.FreeSelectSqlBuilder in project dal by ctripcorp.
the class FreeSelectSqlBuilderTest method testBuildSqlServerRange.
@Test
public void testBuildSqlServerRange() throws SQLException {
FreeSelectSqlBuilder test = createTest();
test.setTemplate(template).setTemplate(template).append(template);
assertEquals("template template template", test.build());
test.range(10, 10);
assertEquals("template template template OFFSET 10 ROWS FETCH NEXT 10 ROWS ONLY", test.build());
}
Aggregations