use of test.com.ctrip.platform.dal.dao.unitbase.ClientTestModel in project dal by ctripcorp.
the class DalDirectClientTestStub method updateTestWithParameters.
/**
* Test the update function with parameters
*
* @throws SQLException
*/
@Test
public void updateTestWithParameters() throws SQLException {
String updateSql = String.format("UPDATE %s SET address=? WHERE id=?", TABLE_NAME);
StatementParameters parameters = new StatementParameters();
parameters.set(1, Types.VARCHAR, "BJ INFO");
parameters.set(2, Types.INTEGER, 1);
DalHints hints = new DalHints();
int count = client.update(updateSql, parameters, hints);
assertEquals(1, count, 2, "address='BJ INFO'");
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 callTestForSpWithOutParameter.
/**
* Test the call function with out parameters
* @throws SQLException
*/
@Test
public void callTestForSpWithOutParameter() throws SQLException {
String callSql = diff.category == DatabaseCategory.SqlServer ? "{call " + SP_WITH_OUT_PARAM + "(?,?)}" : "call " + SP_WITH_OUT_PARAM + "(?,?)";
StatementParameters parameters = new StatementParameters();
parameters.set("v_id", Types.INTEGER, 1);
parameters.registerOut("count", Types.INTEGER);
DalHints hints = new DalHints();
Map<String, ?> res = client.call(callSql, parameters, hints);
Assert.assertTrue(null != res);
Assert.assertEquals(1, res.size());
Assert.assertEquals(2, ((Number) res.get("count")).intValue());
List<ClientTestModel> models = this.queryModelsByIds(1);
Assert.assertEquals(0, models.size());
List<ClientTestModel> models_d = this.queryModelsByIds();
Assert.assertEquals(2, models_d.size());
}
use of test.com.ctrip.platform.dal.dao.unitbase.ClientTestModel in project dal by ctripcorp.
the class DalDirectClientTestStub method batchCallTestForSpWithOutParameter.
/**
* Test batch call with parameters and has ResultParameters
* @throws SQLException
*/
@Test
public void batchCallTestForSpWithOutParameter() throws SQLException {
// Oracle do not support out parameter for batch store procedure update
if (!diff.supportBatchSpWithOutParameter)
return;
String callSql = "{call " + SP_WITH_OUT_PARAM + "(?,?)}";
StatementParameters[] parametersList = new StatementParameters[3];
for (int i = 0; i < 3; i++) {
StatementParameters parameters = new StatementParameters();
parameters.set("v_id", Types.INTEGER, i + 1);
parameters.registerOut("count", Types.INTEGER);
parametersList[i] = parameters;
}
DalHints hints = new DalHints();
int[] res = client.batchCall(callSql, parametersList, hints);
Assert.assertEquals(3, res.length);
List<ClientTestModel> models = this.queryModelsByIds(1, 2, 3);
Assert.assertEquals(0, models.size());
}
use of test.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 test.com.ctrip.platform.dal.dao.unitbase.ClientTestModel in project dal by ctripcorp.
the class DalDirectClientTestStub method batchCallTestWithParametersForSpWithoutOutParameter.
/**
* Test batch call with parameters but has no ResultParameters
* @throws SQLException
*/
@Test
public void batchCallTestWithParametersForSpWithoutOutParameter() throws SQLException {
String callSql = "{call " + SP_WITHOUT_OUT_PARAM + "(?,?,?,?)}";
StatementParameters[] parametersList = new StatementParameters[7];
DalHints hints = new DalHints();
for (int i = 0; i < 7; i++) {
StatementParameters parameters = new StatementParameters();
parameters.set("v_id", Types.INTEGER, null);
parameters.set("v_quantity", Types.INTEGER, 10 + i);
parameters.set("v_type", Types.SMALLINT, 3);
parameters.set("v_address", Types.VARCHAR, "SZ INFO" + "_" + i);
parametersList[i] = parameters;
}
int[] res = client.batchCall(callSql, parametersList, hints);
Assert.assertEquals(7, res.length);
List<ClientTestModel> models = this.queryModelsByIds();
Assert.assertEquals(10, models.size());
}
Aggregations