Search in sources :

Example 56 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 57 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 58 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 59 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)

Example 60 with StatementParameters

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

the class DalQueryDaoTest method queryListForInParamOld.

// Test in parameters
private List<Short> queryListForInParamOld(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);
    String sql = SQLParser.parse(sqlInParam, inParam);
    return dao.query(sql, parameters, hints.inAllShards(), new ShortRowMapper());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ShortRowMapper(com.ctrip.platform.dal.dao.helper.ShortRowMapper) StatementParameters(com.ctrip.platform.dal.dao.StatementParameters) ArrayList(java.util.ArrayList)

Aggregations

StatementParameters (com.ctrip.platform.dal.dao.StatementParameters)360 DalHints (com.ctrip.platform.dal.dao.DalHints)317 Test (org.junit.Test)209 SQLException (java.sql.SQLException)102 ArrayList (java.util.ArrayList)51 FreeSelectSqlBuilder (com.ctrip.platform.dal.dao.sqlbuilder.FreeSelectSqlBuilder)40 ClientTestModel (test.com.ctrip.platform.dal.dao.unitbase.ClientTestModel)40 List (java.util.List)29 FreeUpdateSqlBuilder (com.ctrip.platform.dal.dao.sqlbuilder.FreeUpdateSqlBuilder)20 DalQueryDao (com.ctrip.platform.dal.dao.DalQueryDao)19 DalTableDao (com.ctrip.platform.dal.dao.DalTableDao)17 After (org.junit.After)17 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)15 DalDefaultJpaParser (com.ctrip.platform.dal.dao.helper.DalDefaultJpaParser)14 ResultSet (java.sql.ResultSet)10 DalClient (com.ctrip.platform.dal.dao.DalClient)9 AfterClass (org.junit.AfterClass)9 BeforeClass (org.junit.BeforeClass)9 AbstractFreeSqlBuilder (com.ctrip.platform.dal.dao.sqlbuilder.AbstractFreeSqlBuilder)8 Map (java.util.Map)8