use of com.ctrip.platform.dal.dao.sqlbuilder.FreeSelectSqlBuilder in project dal by ctripcorp.
the class PartialQueryQueryDaoTest method findFreeFirstBigger.
// Result set is bigger than entity
public FreeEntityPartialPojo findFreeFirstBigger(String name, List<Integer> cityIds, DalHints hints) throws SQLException {
DalQueryDao queryDao = new DalQueryDao(DATA_BASE);
DalDefaultJpaMapper<FreeEntityPartialPojo> freeEntityPojoRowMapper = new DalDefaultJpaMapper<>(FreeEntityPartialPojo.class);
hints = DalHints.createIfAbsent(hints);
FreeSelectSqlBuilder<FreeEntityPartialPojo> builder = new FreeSelectSqlBuilder<>(dbCategory);
builder.setTemplate("SELECT * FROM Person WHERE name LIKE ? and CityId in (?) ORDER BY name");
StatementParameters parameters = new StatementParameters();
int i = 1;
parameters.setSensitive(i++, "name", Types.VARCHAR, name);
i = parameters.setSensitiveInParameter(i, "cityIds", Types.INTEGER, cityIds);
builder.mapWith(freeEntityPojoRowMapper).requireFirst().nullable();
return (FreeEntityPartialPojo) queryDao.query(builder, parameters, hints);
}
use of com.ctrip.platform.dal.dao.sqlbuilder.FreeSelectSqlBuilder in project dal by ctripcorp.
the class DalQueryDaoTest method queryListForInParamBuilder.
// Test in parameters
private List<Short> queryListForInParamBuilder(DalHints hints) throws SQLException {
StatementParameters parameters = new StatementParameters();
List<Integer> inParam = new ArrayList<>();
inParam.add(0);
inParam.add(1);
inParam.add(2);
inParam.add(3);
inParam.add(4);
parameters.setInParameter(1, "type", Types.INTEGER, inParam);
FreeSelectSqlBuilder<List<Short>> builder = new FreeSelectSqlBuilder<>(dbCategory);
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 testBuildSqlServerAtPage.
@Test
public void testBuildSqlServerAtPage() throws SQLException {
FreeSelectSqlBuilder test = createTest();
test.setTemplate(template).setTemplate(template).append(template);
assertEquals("template template template", test.build());
test.atPage(10, 10);
assertEquals("template template template OFFSET 90 ROWS FETCH NEXT 10 ROWS ONLY", test.build());
}
use of com.ctrip.platform.dal.dao.sqlbuilder.FreeSelectSqlBuilder in project dal by ctripcorp.
the class FreeSelectSqlBuilderTest method testBuildMeltdownAtEnd.
@Test
public void testBuildMeltdownAtEnd() throws SQLException {
FreeSelectSqlBuilder test = createTest();
test.where(text(template), AND, expression(template).ignoreNull(null)).groupBy(template);
assertEquals("WHERE template GROUP BY [template]", test.build());
test = createTest();
test.where(text(template)).and().appendExpression(template).ignoreNull(null).groupBy(template);
assertEquals("WHERE template GROUP BY [template]", test.build());
}
use of com.ctrip.platform.dal.dao.sqlbuilder.FreeSelectSqlBuilder in project dal by ctripcorp.
the class FreeSelectSqlBuilderTest method testBuildMySqlRange.
@Test
public void testBuildMySqlRange() throws SQLException {
FreeSelectSqlBuilder test = new FreeSelectSqlBuilder(DatabaseCategory.MySql);
test.setTemplate(template).setTemplate(template).append(template);
assertEquals("template template template", test.build());
test.range(10, 10);
assertEquals("template template template limit 10, 10", test.build());
}
Aggregations