Search in sources :

Example 1 with StatementParameters

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

the class DalShardingHelperTest method testLocateTableShardId.

@Test
public void testLocateTableShardId() {
    //tableColumns=index,tableIndex;tableMod=4;separator=_;
    StatementParameters parameters = null;
    ;
    Map<String, Object> fields = null;
    try {
        // Preset
        assertEquals("0", DalShardingHelper.locateTableShardId("dao_test_sqlsvr_tableShard", new DalHints().inTableShard("0"), parameters, fields));
        // parameter
        parameters = new StatementParameters();
        parameters.set(1, "index", java.sql.Types.INTEGER, 1);
        assertEquals("1", DalShardingHelper.locateTableShardId("dao_test_sqlsvr_tableShard", new DalHints(), parameters, fields));
        //Fields
        parameters = null;
        fields = new HashMap<String, Object>();
        fields.put("index", 1);
        assertEquals("1", DalShardingHelper.locateTableShardId("dao_test_sqlsvr_tableShard", new DalHints(), parameters, fields));
    } catch (SQLException e) {
        e.printStackTrace();
        fail("Not yet implemented");
    }
    // Cannot locate
    try {
        // parameter
        parameters = new StatementParameters();
        parameters.set(1, "id", java.sql.Types.INTEGER, 1);
        fields = new HashMap<String, Object>();
        fields.put("ab", 1);
        assertEquals("1", DalShardingHelper.locateTableShardId("dao_test_sqlsvr_tableShard", new DalHints(), parameters, fields));
        fail();
    } catch (SQLException e) {
    }
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) SQLException(java.sql.SQLException) StatementParameters(com.ctrip.platform.dal.dao.StatementParameters) Test(org.junit.Test)

Example 2 with StatementParameters

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

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

the class DalColumnMapRowMapperTest method tearDownAfterClass.

@AfterClass
public static void tearDownAfterClass() throws Exception {
    DalHints hints = new DalHints();
    StatementParameters parameters = new StatementParameters();
    String[] sqls = new String[] { DROP_TABLE_SQL };
    for (int i = 0; i < sqls.length; i++) {
        client.update(sqls[i], parameters, hints);
    }
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) StatementParameters(com.ctrip.platform.dal.dao.StatementParameters) AfterClass(org.junit.AfterClass)

Example 4 with StatementParameters

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

the class DalColumnMapRowMapperTest method testDalColumnMapRowMapperEmpty.

@Test
public void testDalColumnMapRowMapperEmpty() {
    try {
        StatementParameters parameters = new StatementParameters();
        DalClient client = DalClientFactory.getClient(DATABASE_NAME);
        List<Map<String, Object>> result1 = client.query(sqlNoResult, parameters, new DalHints(), new DalRowMapperExtractor<Map<String, Object>>(new DalColumnMapRowMapper()));
        assertEquals(0, result1.size());
        DalQueryDao dao = new DalQueryDao(DATABASE_NAME);
        List<Map<String, Object>> result = dao.query(sqlNoResult, parameters, hints, new DalColumnMapRowMapper());
        assertEquals(0, result.size());
    } catch (Exception e) {
        fail();
    }
}
Also used : DalClient(com.ctrip.platform.dal.dao.DalClient) DalHints(com.ctrip.platform.dal.dao.DalHints) StatementParameters(com.ctrip.platform.dal.dao.StatementParameters) DalColumnMapRowMapper(com.ctrip.platform.dal.dao.helper.DalColumnMapRowMapper) DalQueryDao(com.ctrip.platform.dal.dao.DalQueryDao) Map(java.util.Map) SQLException(java.sql.SQLException) Test(org.junit.Test)

Example 5 with StatementParameters

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

the class DalColumnMapRowMapperTest method testDalColumnMapRowMapperOne.

@Test
public void testDalColumnMapRowMapperOne() {
    try {
        StatementParameters parameters = new StatementParameters();
        parameters.set(1, Types.INTEGER, 3);
        DalQueryDao dao = new DalQueryDao(DATABASE_NAME);
        List<Map<String, Object>> result = dao.query(sqlObject, parameters, hints, new DalColumnMapRowMapper());
        assertEquals(1, result.size());
    } catch (Exception e) {
        fail();
    }
}
Also used : StatementParameters(com.ctrip.platform.dal.dao.StatementParameters) DalColumnMapRowMapper(com.ctrip.platform.dal.dao.helper.DalColumnMapRowMapper) DalQueryDao(com.ctrip.platform.dal.dao.DalQueryDao) Map(java.util.Map) 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