use of test.com.ctrip.platform.dal.dao.unitbase.ClientTestModel in project dal by ctripcorp.
the class DalTableDaoTestStub method testBatchInsert.
/**
* Test Batch Insert multiple entities
* @throws SQLException
*/
@Test
public void testBatchInsert() throws SQLException {
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);
}
int[] res = dao.batchInsert(new DalHints(), entities);
assertEqualsBatchInsert(new int[] { 1, 1, 1 }, res, 7);
}
use of test.com.ctrip.platform.dal.dao.unitbase.ClientTestModel in project dal by ctripcorp.
the class DalTableDaoTestStub method testQueryTopWithWhereClause.
/**
* Test Query the top rows with where clause
* @throws SQLException
*/
@Test
public void testQueryTopWithWhereClause() throws SQLException {
String whereClause = "type=?";
StatementParameters parameters = new StatementParameters();
parameters.set(1, Types.SMALLINT, 1);
List<ClientTestModel> models = dao.queryTop(whereClause, parameters, new DalHints(), 2);
Assert.assertTrue(null != models);
Assert.assertEquals(2, models.size());
}
use of test.com.ctrip.platform.dal.dao.unitbase.ClientTestModel in project dal by ctripcorp.
the class DalDirectClientSqlServerTest method testBatchCallWithParametersAndResultParameters.
/**
* Test batch call with parameters and has ResultParameters
* @throws SQLException
*/
@Test
public void testBatchCallWithParametersAndResultParameters() throws SQLException {
String callSql = "{call " + SP_WITH_OUT_PARAM + "(?,NULL)}";
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 DalDirectClientSqlServerTest method queryModelsByIds.
/**
* Get the models all in dal_client_test by specified IDs
*
* @param ids
* @return The list of ClientTestModel
*/
private List<ClientTestModel> queryModelsByIds(int... ids) {
List<ClientTestModel> models = new ArrayList<ClientTestModel>();
String querySql = "";
if (null != ids && ids.length > 0) {
Integer[] idds = new Integer[ids.length];
for (int i = 0; i < idds.length; i++) {
idds[i] = ids[i];
}
querySql = "SELECT * FROM %s WHERE id in(%s)";
String inClause = StringUtils.join(idds, ",");
querySql = String.format(querySql, TABLE_NAME, inClause);
} else {
querySql = "SELECT * FROM " + TABLE_NAME;
}
StatementParameters parameters = new StatementParameters();
DalHints hints = new DalHints();
try {
models = client.query(querySql, parameters, hints, new DalRowMapperExtractor<ClientTestModel>(mapper));
} catch (SQLException e) {
e.printStackTrace();
}
return models;
}
use of test.com.ctrip.platform.dal.dao.unitbase.ClientTestModel in project dal by ctripcorp.
the class DalDirectClientTestStub method callTestWithParametersForSpWithoutOutParameter.
/**
* Test call with parameters but has no resultsParameter
* @throws SQLException
*/
@Test
public void callTestWithParametersForSpWithoutOutParameter() throws SQLException {
String callSql = "{call " + SP_WITHOUT_OUT_PARAM + "(?,?,?,?)}";
StatementParameters parameters = new StatementParameters();
parameters.set("v_id", Types.INTEGER, 4);
parameters.set("v_quantity", Types.INTEGER, 10);
parameters.set("v_type", Types.SMALLINT, 3);
parameters.set("v_address", Types.VARCHAR, "SZ INFO");
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());
}
Aggregations