use of test.com.ctrip.platform.dal.dao.unitbase.ClientTestModel in project dal by ctripcorp.
the class DalDirectClientTestStub method updateTestWithoutParameters.
/**
* Test the update function without parameters
*
* @throws SQLException
*/
@Test
public void updateTestWithoutParameters() throws SQLException {
String updateSql = String.format("UPDATE %s SET address=%s WHERE id=%s", TABLE_NAME, "'BJ INFO'", 1);
StatementParameters parameters = new StatementParameters();
DalHints hints = new DalHints();
int count = client.update(updateSql, parameters, hints);
assertEquals(1, count, 3);
List<ClientTestModel> po_models = this.queryModelsByIds(1);
Assert.assertTrue(null != po_models);
Assert.assertEquals(1, po_models.size());
Assert.assertEquals("BJ INFO", po_models.get(0).getAddress());
}
use of test.com.ctrip.platform.dal.dao.unitbase.ClientTestModel in project dal by ctripcorp.
the class DalDirectClientTestStub method executeTestWithMultipleCommandsAllSuccessed.
/**
* Test execute multiple commands and all successes.
* @throws SQLException
*/
@Test
public void executeTestWithMultipleCommandsAllSuccessed() throws SQLException {
final DalHints hints = new DalHints();
List<DalCommand> commands = new ArrayList<DalCommand>();
commands.add(new DalCommand() {
@Override
public boolean execute(DalClient client) throws SQLException {
String sql = "DELETE FROM " + TABLE_NAME + " WHERE id = 1";
StatementParameters parameters = new StatementParameters();
client.update(sql, parameters, hints);
return true;
}
});
commands.add(new DalCommand() {
@Override
public boolean execute(DalClient client) throws SQLException {
String sql = "DELETE FROM " + TABLE_NAME + " WHERE id = 2";
StatementParameters parameters = new StatementParameters();
client.update(sql, parameters, hints);
return true;
}
});
commands.add(new DalCommand() {
@Override
public boolean execute(DalClient client) throws SQLException {
String sql = "DELETE FROM " + TABLE_NAME + " WHERE id = 3";
StatementParameters parameters = new StatementParameters();
client.update(sql, parameters, hints);
return true;
}
});
client.execute(commands, hints);
List<ClientTestModel> models = this.queryModelsByIds();
Assert.assertEquals(0, models.size());
}
use of test.com.ctrip.platform.dal.dao.unitbase.ClientTestModel in project dal by ctripcorp.
the class DalDirectClientTestStub method queryTestWithFetchSizeLimit.
/**
* Test the basic query function with maxRows limit
*
* @throws SQLException
*/
@Test
public void queryTestWithFetchSizeLimit() throws SQLException {
String querySql = "SELECT * FROM " + TABLE_NAME;
StatementParameters parameters = new StatementParameters();
ClientTestDalRowMapper mapper = new ClientTestDalRowMapper();
DalHints hints = new DalHints();
// Set fetch size limit
hints.set(DalHintEnum.maxRows, 1);
List<ClientTestModel> res = client.query(querySql, parameters, hints, new DalRowMapperExtractor<ClientTestModel>(mapper));
Assert.assertTrue(null != res);
Assert.assertEquals(1, res.size());
}
use of test.com.ctrip.platform.dal.dao.unitbase.ClientTestModel in project dal by ctripcorp.
the class DalDirectClientTestStub method callTestForSpWithInOutParameters.
/**
* Test the call function with in-out parameters
* @throws SQLException
*/
@Test
public void callTestForSpWithInOutParameters() throws SQLException {
String callSql = "{call " + SP_WITH_IN_OUT_PARAM + "(?,?,?,?)}";
StatementParameters parameters = new StatementParameters();
parameters.set("v_id", Types.INTEGER, 1);
parameters.set("v_quantity", Types.INTEGER, 10);
parameters.set("v_type", Types.SMALLINT, 3);
parameters.registerInOut("v_address", Types.VARCHAR, "SZ INFO");
DalHints hints = new DalHints();
Map<String, ?> res = client.call(callSql, parameters, hints);
Assert.assertTrue(null != res);
Assert.assertEquals(1, res.size());
Assert.assertTrue(res.containsKey("v_address"));
Assert.assertEquals("output", parameters.get("v_address", ParameterDirection.InputOutput).getValue());
List<ClientTestModel> models = this.queryModelsByIds(1);
Assert.assertEquals(1, models.size());
Assert.assertEquals("SZ INFO", models.get(0).getAddress());
}
use of test.com.ctrip.platform.dal.dao.unitbase.ClientTestModel in project dal by ctripcorp.
the class DalDirectClientTestStub method batchUpdateTestWithParametersNotAllSuccessed.
/**
* Test the batch update function with parameters not all success.
*
* @throws SQLException
*/
@Test
public void batchUpdateTestWithParametersNotAllSuccessed() throws SQLException {
String sql = "DELETE FROM " + TABLE_NAME + " WHERE id = ?";
StatementParameters[] parameterList = new StatementParameters[2];
parameterList[0] = new StatementParameters();
parameterList[0].set(1, Types.INTEGER, 1);
parameterList[1] = new StatementParameters();
parameterList[1].set(1, Types.INTEGER, 100);
DalHints hints = new DalHints();
int[] counts = client.batchUpdate(sql, parameterList, hints);
Assert.assertEquals(2, counts.length);
assertEqualsBatch(new int[] { 1, 0 }, counts, 3 - 1);
List<ClientTestModel> models = this.queryModelsByIds();
Assert.assertEquals(2, models.size());
}
Aggregations