Search in sources :

Example 36 with FreeSelectSqlBuilder

use of com.ctrip.platform.dal.dao.sqlbuilder.FreeSelectSqlBuilder in project dal by ctripcorp.

the class FreeSelectSqlBuilderTest method testBuildMySqlAtPage.

@Test
public void testBuildMySqlAtPage() throws SQLException {
    FreeSelectSqlBuilder test = new FreeSelectSqlBuilder(DatabaseCategory.MySql);
    test.setTemplate(template).setTemplate(template).append(template);
    assertEquals("template template template", test.build());
    test.atPage(10, 10);
    assertEquals("template template template limit 90, 10", test.build());
}
Also used : FreeSelectSqlBuilder(com.ctrip.platform.dal.dao.sqlbuilder.FreeSelectSqlBuilder) Test(org.junit.Test)

Example 37 with FreeSelectSqlBuilder

use of com.ctrip.platform.dal.dao.sqlbuilder.FreeSelectSqlBuilder in project dal by ctripcorp.

the class FreeSelectSqlBuilderTest method testBuildSqlServerTop.

@Test
public void testBuildSqlServerTop() throws SQLException {
    FreeSelectSqlBuilder test = createTest();
    test.setTemplate(template).setTemplate(template).append(template);
    assertEquals("template template template", test.build());
    test.top(10);
    assertEquals("template template template OFFSET 0 ROWS FETCH NEXT 10 ROWS ONLY", test.build());
}
Also used : FreeSelectSqlBuilder(com.ctrip.platform.dal.dao.sqlbuilder.FreeSelectSqlBuilder) Test(org.junit.Test)

Example 38 with FreeSelectSqlBuilder

use of com.ctrip.platform.dal.dao.sqlbuilder.FreeSelectSqlBuilder in project dal by ctripcorp.

the class PartialQueryQueryDaoTest method findFreeFirstSmaller.

// Result set is smaller than entity
public FreeEntityPartialPojo findFreeFirstSmaller(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.partialQuery("PeopleID", "Name", "CityID", "ProvinceID"));
}
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 39 with FreeSelectSqlBuilder

use of com.ctrip.platform.dal.dao.sqlbuilder.FreeSelectSqlBuilder in project dal by ctripcorp.

the class PartialQueryQueryDaoTest method findFreeFirstSame.

// Result set is same than entity
public FreeEntityPojo findFreeFirstSame(String name, List<Integer> cityIds, DalHints hints) throws SQLException {
    DalQueryDao queryDao = new DalQueryDao(DATA_BASE);
    DalDefaultJpaMapper<FreeEntityPojo> freeEntityPojoRowMapper = new DalDefaultJpaMapper<>(FreeEntityPojo.class);
    hints = DalHints.createIfAbsent(hints);
    FreeSelectSqlBuilder<FreeEntityPojo> 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 (FreeEntityPojo) 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 40 with FreeSelectSqlBuilder

use of com.ctrip.platform.dal.dao.sqlbuilder.FreeSelectSqlBuilder in project dal by ctripcorp.

the class PartialQueryQueryDaoTest method findFreeFirstMismatch.

// Result set is not same with entity
public FreeEntityMismatchPojo findFreeFirstMismatch(String name, List<Integer> cityIds, DalHints hints) throws SQLException {
    DalQueryDao queryDao = new DalQueryDao(DATA_BASE);
    DalDefaultJpaMapper<FreeEntityMismatchPojo> freeEntityPojoRowMapper = new DalDefaultJpaMapper<>(FreeEntityMismatchPojo.class);
    hints = DalHints.createIfAbsent(hints);
    FreeSelectSqlBuilder<FreeEntityMismatchPojo> 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 (FreeEntityMismatchPojo) 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)

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