use of test.com.ctrip.platform.dal.dao.unitbase.ClientTestModel in project dal by ctripcorp.
the class DalDirectClientTestStub method quryTestWithoutParameters.
/**
* Test the basic query function without parameters
*
* @throws SQLException
*/
@Test
public void quryTestWithoutParameters() throws SQLException {
String querySql = "SELECT * FROM " + TABLE_NAME;
StatementParameters parameters = new StatementParameters();
ClientTestDalRowMapper mapper = new ClientTestDalRowMapper();
DalHints hints = new DalHints();
List<ClientTestModel> res = client.query(querySql, parameters, hints, new DalRowMapperExtractor<ClientTestModel>(mapper));
Assert.assertTrue(null != res && res.size() == 3);
ClientTestModel model = res.get(0);
Assert.assertTrue(model.getQuantity() == 10 && model.getType() == 1 && model.getAddress().equals("SH INFO"));
}
use of test.com.ctrip.platform.dal.dao.unitbase.ClientTestModel in project dal by ctripcorp.
the class DalDirectClientTestStub method executeTestWithOneCommand.
/**
* Test execute command function
* @throws SQLException
*/
@Test
public void executeTestWithOneCommand() throws SQLException {
final DalHints hints = new DalHints();
DalCommand command = new DalCommand() {
@Override
public boolean execute(DalClient client) throws SQLException {
String sql = "DELETE FROM " + TABLE_NAME + " WHERE id = 1";
StatementParameters parameters = new StatementParameters();
return client.update(sql, parameters, hints) == 1;
}
};
client.execute(command, hints);
List<ClientTestModel> models = this.queryModelsByIds(1);
Assert.assertEquals(0, models.size());
}
use of test.com.ctrip.platform.dal.dao.unitbase.ClientTestModel in project dal by ctripcorp.
the class DalDirectClientTestStub method updateTestWithDelete.
/**
* Test the update function with delete SQL statement
*
* @throws SQLException
*/
@Test
public void updateTestWithDelete() throws SQLException {
String deleteSql = String.format("DELETE FROM %s WHERE id=?", TABLE_NAME);
StatementParameters parameters = new StatementParameters();
parameters.set(1, Types.INTEGER, 1);
DalHints hints = new DalHints();
int count = client.update(deleteSql, parameters, hints);
assertEquals(1, count, 2);
List<ClientTestModel> po_models = this.queryModelsByIds(1);
Assert.assertTrue(null != po_models);
Assert.assertEquals(0, po_models.size());
}
use of test.com.ctrip.platform.dal.dao.unitbase.ClientTestModel in project dal by ctripcorp.
the class DalDirectClientTestStub method batchUpdateTestWithParametersAllSuccessed.
/**
* Test the batch update function with parameters all success.
*
* @throws SQLException
*/
@Test
public void batchUpdateTestWithParametersAllSuccessed() throws SQLException {
String sql = "INSERT INTO " + TABLE_NAME + "(quantity,type,address,last_changed) VALUES(?, ?, ?,?)";
StatementParameters[] parameterList = new StatementParameters[2];
parameterList[0] = new StatementParameters();
parameterList[0].set(1, Types.INTEGER, 11);
parameterList[0].set(2, Types.SMALLINT, 2);
parameterList[0].set(3, Types.VARCHAR, "SZ INFO");
parameterList[0].set(4, Types.TIMESTAMP, new Timestamp(System.currentTimeMillis()));
parameterList[1] = new StatementParameters();
parameterList[1].set(1, Types.INTEGER, 11);
parameterList[1].set(2, Types.SMALLINT, 2);
parameterList[1].set(3, Types.VARCHAR, "HK INFO");
parameterList[1].set(4, Types.TIMESTAMP, new Timestamp(System.currentTimeMillis()));
DalHints hints = new DalHints();
int[] counts = client.batchUpdate(sql, parameterList, hints);
assertEqualsBatchInsert(new int[] { 1, 1 }, counts, 3 + 2);
List<ClientTestModel> models = this.queryModelsByIds();
Assert.assertEquals(5, models.size());
}
use of test.com.ctrip.platform.dal.dao.unitbase.ClientTestModel in project dal by ctripcorp.
the class DalDirectClientTestStub method executeTestWithMultipleCommandsNotAllSuccessed.
/**
* Test execute multiple commands and not all successes.
* If one failed, the after commands will be dropped.
* @throws SQLException
*/
@Test
public void executeTestWithMultipleCommandsNotAllSuccessed() 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 false;
}
});
commands.add(new DalCommand() {
@Override
public boolean execute(DalClient client) throws SQLException {
String sql = "DELETE FROM " + TABLE_NAME + " WHERE id = 100";
StatementParameters parameters = new StatementParameters();
return client.update(sql, parameters, hints) == 1;
}
});
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();
return client.update(sql, parameters, hints) == 1;
}
});
client.execute(commands, hints);
List<ClientTestModel> models = this.queryModelsByIds();
Assert.assertEquals(2, models.size());
}
Aggregations