use of test.com.ctrip.platform.dal.dao.unitbase.ClientTestModel in project dal by ctripcorp.
the class DalTableDaoTestStub method testInsertSingle.
/**
* Test Insert multiple entities one by one
* @throws SQLException
*/
@Test
public void testInsertSingle() throws SQLException {
ClientTestModel model = new ClientTestModel();
model.setQuantity(10 + 1 % 3);
model.setType(((Number) (1 % 3)).shortValue());
model.setAddress("CTRIP");
int res = dao.insert(new DalHints(), model);
assertEquals(1, res, 4 + 1);
}
use of test.com.ctrip.platform.dal.dao.unitbase.ClientTestModel in project dal by ctripcorp.
the class DalTableDaoTestStub method testQueryFromWithWhereClauseEmpty.
/**
* Test Query range of result with where clause when return empty collection
* @throws SQLException
*/
@Test
public void testQueryFromWithWhereClauseEmpty() throws SQLException {
String whereClause = "type=?";
StatementParameters parameters = new StatementParameters();
parameters.set(1, Types.SMALLINT, 10);
List<ClientTestModel> models = dao.queryFrom(whereClause, parameters, new DalHints(), 0, 10);
Assert.assertTrue(null != models);
Assert.assertEquals(0, models.size());
}
use of test.com.ctrip.platform.dal.dao.unitbase.ClientTestModel in project dal by ctripcorp.
the class DalDirectClientTestStub 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 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 test.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());
}
Aggregations