use of com.ctrip.platform.dal.dao.unitbase.ClientTestModel in project dal by ctripcorp.
the class DalTableDaoTestStub method testUpdatePlain.
/**
* Test plain update with SQL
*
* @throws SQLException
*/
@Test
public void testUpdatePlain() throws SQLException {
String sql = "UPDATE " + TABLE_NAME + " SET address = 'CTRIP' WHERE id = 1";
StatementParameters parameters = new StatementParameters();
DalHints hints = new DalHints();
int res = dao.update(sql, parameters, hints);
assertEquals(1, res, 1, "address = 'CTRIP'");
ClientTestModel model = dao.queryByPk(1, hints);
Assert.assertTrue(null != model);
Assert.assertEquals("CTRIP", model.getAddress());
}
use of 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 com.ctrip.platform.dal.dao.unitbase.ClientTestModel in project dal by ctripcorp.
the class DalTableDaoTestStub method testInsertMultipleAsListWithContinueOnErrorHints.
/**
* Test Test Insert multiple entities one by one with continueOnError hints
*
* @throws SQLException
*/
@Test
public void testInsertMultipleAsListWithContinueOnErrorHints() 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());
if (i == 1) {
model.setAddress("CTRIPCTRIPCTRIPCTRIPCTRIPCTRIPCTRIP" + "CTRIPCTRIPCTRIPCTRIPCTRIPCTRIPCTRIPCTRIPCTRIP" + "CTRIPCTRIPCTRIPCTRIP");
} else {
model.setAddress("CTRIP");
}
entities.add(model);
}
DalHints hints = new DalHints(DalHintEnum.continueOnError);
int[] res = dao.insert(hints, entities);
assertEquals(new int[] { 1, 0, 1 }, res, 4 + 2);
}
use of 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 com.ctrip.platform.dal.dao.unitbase.ClientTestModel in project dal by ctripcorp.
the class DalDirectClientSqlServerTest method batchExecTestWithParametersForSpWithoutOutParameter.
@Test
public void batchExecTestWithParametersForSpWithoutOutParameter() throws SQLException {
String callSql = "exec " + SP_WITHOUT_OUT_PARAM + " @v_id=?, @v_quantity=?, @v_type=?, @v_address=?";
// set parameter by name
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());
// set parameter by index
StatementParameters[] parametersList2 = new StatementParameters[7];
for (int i = 0; i < 7; i++) {
StatementParameters parameters = new StatementParameters();
int index = 1;
parameters.set(index++, Types.INTEGER, null);
parameters.set(index++, Types.INTEGER, 10 + i);
parameters.set(index++, Types.SMALLINT, 3);
parameters.set(index++, Types.VARCHAR, "SZ INFO" + "_" + i);
parametersList2[i] = parameters;
}
res = client.batchCall(callSql, parametersList, hints);
Assert.assertEquals(7, res.length);
models = this.queryModelsByIds();
Assert.assertEquals(17, models.size());
// set parameter by index and name
StatementParameters[] parametersList3 = new StatementParameters[7];
for (int i = 0; i < 7; i++) {
StatementParameters parameters = new StatementParameters();
int index = 1;
parameters.set(index++, "v_id", Types.INTEGER, null);
parameters.set(index++, "v_quantity", Types.INTEGER, 10 + i);
parameters.set(index++, "v_type", Types.SMALLINT, 3);
parameters.set(index++, "v_address", Types.VARCHAR, "SZ INFO" + "_" + i);
parametersList3[i] = parameters;
}
res = client.batchCall(callSql, parametersList, hints);
Assert.assertEquals(7, res.length);
models = this.queryModelsByIds();
Assert.assertEquals(24, models.size());
}
Aggregations