use of com.ctrip.platform.dal.dao.StatementParameters in project dal by ctripcorp.
the class BaseDalTableDaoShardByDbTableTest method testQueryTopWithWhereClauseFailed.
private void testQueryTopWithWhereClauseFailed(DalHints hints) throws SQLException {
String whereClause = "type=?";
StatementParameters parameters = new StatementParameters();
parameters.set(1, Types.SMALLINT, 10);
List<ClientTestModel> models;
try {
hints = copy(hints);
models = dao.queryTop(whereClause, parameters, hints, 2);
models = assertModels(models, hints);
Assert.fail();
} catch (Exception e) {
}
models = dao.queryTop(whereClause, parameters, new DalHints().inTableShard(1).inShard(0), 2);
Assert.assertTrue(null != models);
Assert.assertEquals(0, models.size());
}
use of com.ctrip.platform.dal.dao.StatementParameters in project dal by ctripcorp.
the class BaseDalTableDaoShardByDbTableTest method testQueryWithWhereClause.
/**
* Query by Entity with where clause
* @throws SQLException
*/
private void testQueryWithWhereClause(int shardId, DalHints oldhints) throws SQLException {
DalHints hints;
List<ClientTestModel> models = null;
for (int i = 0; i < tableMod; i++) {
String whereClause = "type=? and id=?";
StatementParameters parameters = new StatementParameters();
parameters.set(1, Types.SMALLINT, 1);
parameters.set(2, Types.INTEGER, 1);
// By tabelShard
hints = copy(oldhints);
models = dao.query(whereClause, parameters, hints.inTableShard(i));
models = assertModels(models, hints);
assertQueryWithWhereClause(shardId, models, i);
// By tableShardValue
hints = copy(oldhints);
models = dao.query(whereClause, parameters, hints.setTableShardValue(i));
models = assertModels(models, hints);
assertQueryWithWhereClause(shardId, models, i);
// By shardColValue
hints = copy(oldhints);
models = dao.query(whereClause, parameters, hints.setShardColValue("table", i));
models = assertModels(models, hints);
assertQueryWithWhereClause(shardId, models, i);
// By shardColValue
hints = copy(oldhints);
models = dao.query(whereClause, parameters, hints.setShardColValue("tableIndex", i));
models = assertModels(models, hints);
assertQueryWithWhereClause(shardId, models, i);
// By parameters
whereClause += " and tableIndex=? and dbIndex=?";
parameters = new StatementParameters();
parameters.set(1, "type", Types.SMALLINT, 1);
parameters.set(2, "id", Types.SMALLINT, i + 1);
parameters.set(3, "tableIndex", Types.SMALLINT, i);
parameters.set(4, "dbIndex", Types.SMALLINT, shardId);
hints = copy(oldhints);
models = dao.query(whereClause, parameters, hints);
models = assertModels(models, hints);
assertQueryWithWhereClause(shardId, models, i);
}
}
use of com.ctrip.platform.dal.dao.StatementParameters in project dal by ctripcorp.
the class BaseDalTableDaoShardByDbTableTest method testDeleteWithWhereClauseFail.
/**
* Test delete entities with where clause and parameters
* @throws SQLException
*/
@Test
public void testDeleteWithWhereClauseFail() throws SQLException {
String whereClause = "type=?";
StatementParameters parameters = new StatementParameters();
parameters.set(1, Types.SMALLINT, 1);
int res;
try {
DalHints hints = new DalHints();
res = dao.delete(whereClause, parameters, hints);
Assert.fail();
} catch (Exception e) {
}
//Async
try {
DalHints hints = asyncHints();
res = dao.delete(whereClause, parameters, hints);
res = assertInt(res, hints);
Assert.fail();
} catch (Exception e) {
}
//Callback
try {
DalHints hints = intHints();
res = dao.delete(whereClause, parameters, hints);
res = assertInt(res, hints);
Assert.fail();
} catch (Exception e) {
}
}
use of com.ctrip.platform.dal.dao.StatementParameters in project dal by ctripcorp.
the class DalConcurrentMysqlTest method testQueryById.
@Test
public void testQueryById() throws SQLException {
int maxId = random.nextInt(INSERT_COUNT);
List<ClientTestModel> models = dao.query("Id > " + generateIds.get(maxId).intValue(), new StatementParameters(), new DalHints());
System.out.println(models.size());
}
use of com.ctrip.platform.dal.dao.StatementParameters in project dal by ctripcorp.
the class DalConcurrentMysqlTest method testUpdate.
@Test
public void testUpdate() throws SQLException {
int id = random.nextInt(INSERT_COUNT);
String updateSql = "UPDATE " + TABLE_NAME + " SET address = ? WHERE id = ?";
StatementParameters param = new StatementParameters();
if (id % 2 == 0)
param.set(1, Types.VARCHAR, "BJ-" + id);
else
param.set(1, Types.VARCHAR, "SH-" + id);
param.set(2, Types.INTEGER, id);
int count = dao.update(updateSql, param, new DalHints());
System.out.println("update souccess: " + id);
Assert.assertEquals(1, count);
}
Aggregations