use of com.ctrip.platform.dal.dao.DalQueryDao 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.DalQueryDao 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.DalQueryDao 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();
}
}
use of com.ctrip.platform.dal.dao.DalQueryDao in project dal by ctripcorp.
the class DalWatcherTest method testQueryObjectWhenShutdown.
@Test
public void testQueryObjectWhenShutdown() throws Exception {
final DalQueryDao client = new DalQueryDao(DATABASE_NAME);
Runnable shutdown = new Runnable() {
public void run() {
while (true) {
DalClientFactory.shutdownFactory();
}
}
};
Runnable query = new Runnable() {
public void run() {
while (true) {
String sql = "SELECT quantity FROM " + TABLE_NAME;
StatementParameters param = new StatementParameters();
DalHints hints = new DalHints();
try {
System.out.println("query");
client.queryFrom(sql, param, hints, Integer.class, 0, 10);
} catch (SQLException e) {
e.printStackTrace();
System.exit(1);
}
}
}
};
new Thread(shutdown).start();
new Thread(query).start();
;
int i = 100;
while (i-- > 0) {
System.out.println("waiting");
Thread.sleep(1 * 10000);
}
}
use of com.ctrip.platform.dal.dao.DalQueryDao in project dal by ctripcorp.
the class BaseTransactionAnnoClass method testQueryFail.
private void testQueryFail(String db) {
try {
new DalQueryDao(db).query(query, new StatementParameters(), new DalHints(), Integer.class);
fail();
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
Aggregations