use of com.ctrip.platform.dal.dao.unitbase.ClientTestModel in project dal by ctripcorp.
the class DalDirectClientTestStub method callTestForSpWithIntermediateParameters.
/**
* Test the call function with retrieveAllResultsFromSp parameters
* @throws SQLException
*/
@Test
public void callTestForSpWithIntermediateParameters() throws SQLException {
String callSql = "{call " + SP_WITH_INTERMEDIATE_RESULT + "(?,?,?,?)}";
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().retrieveAllResultsFromSp();
Map<String, ?> res = client.call(callSql, parameters, hints);
System.out.println(res);
Assert.assertTrue(null != res);
if (diff.supportSpIntermediateResult)
// mysql will return update count as well, while sqlserver will not return update count
Assert.assertTrue(res.size() >= 5);
else
Assert.assertEquals(1, res.size());
Assert.assertTrue(res.containsKey("v_address"));
Assert.assertEquals("output", res.get("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("aaa", models.get(0).getAddress());
}
use of 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 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());
}
use of com.ctrip.platform.dal.dao.unitbase.ClientTestModel in project dal by ctripcorp.
the class DalTableDaoTestStub method testCombinedInsert.
/**
* Test Insert multiple entities with one SQL Statement
*
* @throws SQLException
*/
@Test
public void testCombinedInsert() throws SQLException {
if (!diff.supportInsertValues)
return;
List<ClientTestModel> entities = new ArrayList<ClientTestModel>();
for (int i = 0; i < 3; i++) {
ClientTestModel model = new ClientTestModel();
model.setQuantity(10 + 1 % 3);
model.setType(((Number) (1 % 3)).shortValue());
model.setAddress("CTRIP");
entities.add(model);
}
KeyHolder holder = diff.supportGetGeneratedKeys ? new KeyHolder() : null;
DalHints hints = new DalHints();
int res = dao.combinedInsert(hints, holder, entities);
assertEquals(3, res, 4 + 3);
if (diff.supportGetGeneratedKeys) {
Assert.assertEquals(3, holder.size());
Assert.assertTrue(holder.getKeyList().get(0).containsKey("GENERATED_KEY"));
}
}
use of com.ctrip.platform.dal.dao.unitbase.ClientTestModel in project dal by ctripcorp.
the class DalTableDaoTestStub method testUpdateMultiple.
/**
* Test update multiple entities with primary key
*
* @throws SQLException
*/
@Test
public void testUpdateMultiple() throws SQLException {
DalHints hints = new DalHints();
List<ClientTestModel> models = new ArrayList<>();
for (int i = 0; i < 3; i++) {
ClientTestModel model = new ClientTestModel();
model.setId(i + 1);
model.setAddress("CTRIP");
models.add(model);
}
int[] res = dao.update(hints, models);
assertEquals(new int[] { 1, 1, 1 }, res, 3, "address='CTRIP'");
ClientTestModel model = dao.queryByPk(1, hints);
Assert.assertTrue(null != model);
Assert.assertEquals("CTRIP", model.getAddress());
}
Aggregations