Search in sources :

Example 16 with DalQueryDao

use of com.ctrip.platform.dal.dao.DalQueryDao 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);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) FreeSelectSqlBuilder(com.ctrip.platform.dal.dao.sqlbuilder.FreeSelectSqlBuilder) DalHints(com.ctrip.platform.dal.dao.DalHints) StatementParameters(com.ctrip.platform.dal.dao.StatementParameters) ArrayList(java.util.ArrayList) List(java.util.List) DalQueryDao(com.ctrip.platform.dal.dao.DalQueryDao) Test(org.junit.Test)

Example 17 with DalQueryDao

use of com.ctrip.platform.dal.dao.DalQueryDao 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);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) FreeSelectSqlBuilder(com.ctrip.platform.dal.dao.sqlbuilder.FreeSelectSqlBuilder) DalHints(com.ctrip.platform.dal.dao.DalHints) StatementParameters(com.ctrip.platform.dal.dao.StatementParameters) ArrayList(java.util.ArrayList) List(java.util.List) DalQueryDao(com.ctrip.platform.dal.dao.DalQueryDao) Test(org.junit.Test)

Example 18 with DalQueryDao

use of com.ctrip.platform.dal.dao.DalQueryDao 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 19 with DalQueryDao

use of com.ctrip.platform.dal.dao.DalQueryDao 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 20 with DalQueryDao

use of com.ctrip.platform.dal.dao.DalQueryDao 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

DalQueryDao (com.ctrip.platform.dal.dao.DalQueryDao)20 StatementParameters (com.ctrip.platform.dal.dao.StatementParameters)19 DalHints (com.ctrip.platform.dal.dao.DalHints)13 Test (org.junit.Test)9 SQLException (java.sql.SQLException)7 FreeSelectSqlBuilder (com.ctrip.platform.dal.dao.sqlbuilder.FreeSelectSqlBuilder)6 DalDefaultJpaMapper (com.ctrip.platform.dal.dao.helper.DalDefaultJpaMapper)4 DalColumnMapRowMapper (com.ctrip.platform.dal.dao.helper.DalColumnMapRowMapper)3 Map (java.util.Map)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 DalClient (com.ctrip.platform.dal.dao.DalClient)1 HashMap (java.util.HashMap)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 BeforeClass (org.junit.BeforeClass)1