Search in sources :

Example 96 with StatementParameters

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

the class DalQueryDaoTest method queryMultipleAllShards.

private List queryMultipleAllShards(DalHints hints) throws SQLException {
    StatementParameters parameters = new StatementParameters();
    parameters.set(1, Types.INTEGER, 1);
    MultipleSqlBuilder builder = new MultipleSqlBuilder();
    // TODO add all add method
    //mapper
    builder.addQuery(sqlList, new StatementParameters(), new ClientTestDalRowMapper());
    //merger
    builder.addQuery(sqlList, new StatementParameters(), new ClientTestDalRowMapper(), new DalListMerger<ClientTestModel>());
    //sorter
    builder.addQuery(sqlList, new StatementParameters(), ClientTestModel.class, new ClientTestModelComparator());
    //merger
    builder.addQuery(sqlListQuantity, new StatementParameters(), Integer.class, new DalListMerger<Integer>());
    //soter
    builder.addQuery(sqlObject, parameters, Integer.class, new InteregrComparator());
    //callback
    builder.addQuery(sqlNoResult, new StatementParameters(), new TestDalRowCallback3());
    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);
    builder.addQuery(sqlIdInParam, parameters, ClientTestModel.class);
    return dao.query(builder, hints.inAllShards());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) StatementParameters(com.ctrip.platform.dal.dao.StatementParameters) ArrayList(java.util.ArrayList) MultipleSqlBuilder(com.ctrip.platform.dal.dao.sqlbuilder.MultipleSqlBuilder)

Example 97 with StatementParameters

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

the class DalQueryDaoTest method testQueryFirstAllShardsFail.

@Test
public void testQueryFirstAllShardsFail() {
    try {
        DalHints hints = new DalHints();
        StatementParameters parameters = new StatementParameters();
        parameters.set(1, 1);
        ClientTestModel result = dao.queryFirst(sqlNoResult, parameters(), hints.inAllShards(), new ClientTestDalRowMapper());
        fail();
    } catch (Exception e) {
    }
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) StatementParameters(com.ctrip.platform.dal.dao.StatementParameters) SQLException(java.sql.SQLException) Test(org.junit.Test)

Example 98 with StatementParameters

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

the class DalQueryDaoTest method testQueryFirstAllShardsWithClassNullable.

@Test
public void testQueryFirstAllShardsWithClassNullable() {
    try {
        DalHints hints = new DalHints();
        StatementParameters parameters = new StatementParameters();
        Integer result = dao.queryFirstNullable(sqlNoResult, parameters, hints.inAllShards(), Integer.class);
        assertNull(result);
    } catch (Exception e) {
        fail();
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DalHints(com.ctrip.platform.dal.dao.DalHints) StatementParameters(com.ctrip.platform.dal.dao.StatementParameters) SQLException(java.sql.SQLException) Test(org.junit.Test)

Example 99 with StatementParameters

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

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

the class DalQueryDaoTest method testQueryForObjectAllShardsFailPartial.

@Test
public void testQueryForObjectAllShardsFailPartial() {
    try {
        DalHints hints = new DalHints();
        StatementParameters parameters = new StatementParameters();
        parameters.set(1, 1);
        ClientTestModel result = dao.queryForObject(sqlFirst, parameters, hints.inAllShards().partialQuery("quantity", "address"), new ClientTestDalRowMapper());
        fail();
    } catch (Exception e) {
    }
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) StatementParameters(com.ctrip.platform.dal.dao.StatementParameters) SQLException(java.sql.SQLException) Test(org.junit.Test)

Aggregations

StatementParameters (com.ctrip.platform.dal.dao.StatementParameters)276 DalHints (com.ctrip.platform.dal.dao.DalHints)245 Test (org.junit.Test)193 SQLException (java.sql.SQLException)97 ClientTestModel (test.com.ctrip.platform.dal.dao.unitbase.ClientTestModel)40 ArrayList (java.util.ArrayList)32 After (org.junit.After)17 DalTableDao (com.ctrip.platform.dal.dao.DalTableDao)16 DalDefaultJpaParser (com.ctrip.platform.dal.dao.helper.DalDefaultJpaParser)13 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)11 ResultSet (java.sql.ResultSet)10 DalClient (com.ctrip.platform.dal.dao.DalClient)9 BatchUpdateTask (com.ctrip.platform.dal.dao.task.BatchUpdateTask)8 DalQueryDao (com.ctrip.platform.dal.dao.DalQueryDao)7 DalResultSetExtractor (com.ctrip.platform.dal.dao.DalResultSetExtractor)7 Map (java.util.Map)7 AfterClass (org.junit.AfterClass)7 BeforeClass (org.junit.BeforeClass)7 DalCommand (com.ctrip.platform.dal.dao.DalCommand)6 HashSet (java.util.HashSet)6