Search in sources :

Example 1 with FreeSelectSqlBuilder

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);
}
Also used : FreeSelectSqlBuilder(com.ctrip.platform.dal.dao.sqlbuilder.FreeSelectSqlBuilder) StatementParameters(com.ctrip.platform.dal.dao.StatementParameters) DalDefaultJpaMapper(com.ctrip.platform.dal.dao.helper.DalDefaultJpaMapper) DalQueryDao(com.ctrip.platform.dal.dao.DalQueryDao)

Example 2 with FreeSelectSqlBuilder

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"));
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) FreeSelectSqlBuilder(com.ctrip.platform.dal.dao.sqlbuilder.FreeSelectSqlBuilder) ShortRowMapper(com.ctrip.platform.dal.dao.helper.ShortRowMapper) StatementParameters(com.ctrip.platform.dal.dao.StatementParameters) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 3 with FreeSelectSqlBuilder

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());
}
Also used : FreeSelectSqlBuilder(com.ctrip.platform.dal.dao.sqlbuilder.FreeSelectSqlBuilder) Test(org.junit.Test)

Example 4 with FreeSelectSqlBuilder

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());
}
Also used : FreeSelectSqlBuilder(com.ctrip.platform.dal.dao.sqlbuilder.FreeSelectSqlBuilder) Test(org.junit.Test)

Example 5 with FreeSelectSqlBuilder

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());
}
Also used : FreeSelectSqlBuilder(com.ctrip.platform.dal.dao.sqlbuilder.FreeSelectSqlBuilder) Test(org.junit.Test)

Aggregations

FreeSelectSqlBuilder (com.ctrip.platform.dal.dao.sqlbuilder.FreeSelectSqlBuilder)61 StatementParameters (com.ctrip.platform.dal.dao.StatementParameters)44 DalHints (com.ctrip.platform.dal.dao.DalHints)38 List (java.util.List)38 ArrayList (java.util.ArrayList)22 Test (org.junit.Test)17 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)10 DalQueryDao (com.ctrip.platform.dal.dao.DalQueryDao)6 ShortRowMapper (com.ctrip.platform.dal.dao.helper.ShortRowMapper)6 DalDefaultJpaMapper (com.ctrip.platform.dal.dao.helper.DalDefaultJpaMapper)4 DatabaseSet (com.ctrip.platform.dal.daogen.entity.DatabaseSet)3 GenTaskByFreeSql (com.ctrip.platform.dal.daogen.entity.GenTaskByFreeSql)3 GenTaskBySqlBuilder (com.ctrip.platform.dal.daogen.entity.GenTaskBySqlBuilder)3 DalCustomRowMapper (com.ctrip.platform.dal.dao.helper.DalCustomRowMapper)2 FreeUpdateSqlBuilder (com.ctrip.platform.dal.dao.sqlbuilder.FreeUpdateSqlBuilder)2 DatabaseSetEntry (com.ctrip.platform.dal.daogen.entity.DatabaseSetEntry)2 GenTaskByTableViewSp (com.ctrip.platform.dal.daogen.entity.GenTaskByTableViewSp)2 Project (com.ctrip.platform.dal.daogen.entity.Project)2 Map (java.util.Map)2 ClientTestModel (com.ctrip.platform.dal.dao.unitbase.ClientTestModel)1