use of com.ctrip.platform.dal.dao.unitbase.ClientTestModel in project dal by ctripcorp.
the class DalDirectClientTestStub method queryTestWithoutParameters.
/**
* Test the basic query function without parameters
*
* @throws SQLException
*/
@Test
public void queryTestWithoutParameters() 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 com.ctrip.platform.dal.dao.unitbase.ClientTestModel in project dal by ctripcorp.
the class DalDirectClientTestStub method batchUpdateTestWithRollback.
@Test
public void batchUpdateTestWithRollback() throws SQLException {
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, models.size());
}
use of com.ctrip.platform.dal.dao.unitbase.ClientTestModel in project dal by ctripcorp.
the class DalDirectClientTestStub method callTestWithoutParametersForSpWithoutOutParameter.
/**
* Test call without parameters and has no resultsParameter
* @throws SQLException
*/
@Test
public void callTestWithoutParametersForSpWithoutOutParameter() throws SQLException {
String callSql = "{call " + SP_WITHOUT_OUT_PARAM + "(4, 12,1,'SZ INFO')}";
StatementParameters parameters = new StatementParameters();
DalHints hints = new DalHints();
Map<String, ?> res = client.call(callSql, parameters, hints);
Assert.assertTrue(null != res);
Assert.assertEquals(0, res.size());
List<ClientTestModel> models = this.queryModelsByIds();
Assert.assertEquals(4, models.size());
}
use of 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 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());
}
Aggregations