use of 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 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 com.ctrip.platform.dal.dao.unitbase.ClientTestModel in project dal by ctripcorp.
the class DalDirectClientTestStub method batchUpdateTestWithoutRollback.
// The SQL server does not support auto commit for batch update
@Test
public void batchUpdateTestWithoutRollback() throws SQLException {
if (diff.category == DatabaseCategory.SqlServer)
return;
String[] sqls = new String[] { "DELETE FROM " + TABLE_NAME + " WHERE ID = 1", "DELETE FROM " + TABLE_NAME + " WHERE _ID = 2", "DELETE FROM " + TABLE_NAME + " WHERE ID = 3" };
DalHints hints = new DalHints();
hints.set(DalHintEnum.forceAutoCommit);
try {
client.batchUpdate(sqls, hints);
Assert.fail();
} catch (Exception e) {
}
List<ClientTestModel> models = this.queryModelsByIds();
Assert.assertEquals(3 - 1, models.size());
}
use of 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());
}
use of 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());
}
Aggregations