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) {
}
}
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);
}
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);
}
}
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();
}
}
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();
}
}
Aggregations