Search in sources :

Example 26 with ClientTestModel

use of com.ctrip.platform.dal.dao.unitbase.ClientTestModel in project dal by ctripcorp.

the class DalDirectClientSqlServerTest method TSQLTestForSpWithOutParameter.

@Test
public void TSQLTestForSpWithOutParameter() throws SQLException {
    String callSql = "exec " + SP_WITH_OUT_PARAM + " @v_id=?, @count=?";
    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());
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) ClientTestModel(com.ctrip.platform.dal.dao.unitbase.ClientTestModel) StatementParameters(com.ctrip.platform.dal.dao.StatementParameters) Test(org.junit.Test)

Example 27 with ClientTestModel

use of com.ctrip.platform.dal.dao.unitbase.ClientTestModel in project dal by ctripcorp.

the class DalDirectClientSqlServerTest method testTSQLBatchCallWithParametersAndResultParameters.

@Test
public void testTSQLBatchCallWithParametersAndResultParameters() throws SQLException {
    String callSql = "exec " + SP_WITH_OUT_PARAM + " @v_id=?, @count=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());
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) ClientTestModel(com.ctrip.platform.dal.dao.unitbase.ClientTestModel) StatementParameters(com.ctrip.platform.dal.dao.StatementParameters) Test(org.junit.Test)

Example 28 with ClientTestModel

use of com.ctrip.platform.dal.dao.unitbase.ClientTestModel in project dal by ctripcorp.

the class DalTableDaoTestStub method testInsertMultipleAsList.

/**
 * Test Insert multiple entities one by one
 *
 * @throws SQLException
 */
@Test
public void testInsertMultipleAsList() 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.insert(new DalHints(), entities);
    assertEquals(new int[] { 1, 1, 1 }, res, 3, "address='CTRIP'");
}
Also used : ClientTestModel(com.ctrip.platform.dal.dao.unitbase.ClientTestModel) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 29 with ClientTestModel

use of com.ctrip.platform.dal.dao.unitbase.ClientTestModel in project dal by ctripcorp.

the class DalTableDaoTestStub method testBatchDelete.

/**
 * Test batch delete multiple entities
 *
 * @throws SQLException
 */
@Test
public void testBatchDelete() throws SQLException {
    List<ClientTestModel> entities = new ArrayList<ClientTestModel>();
    for (int i = 0; i < 3; i++) {
        ClientTestModel model = new ClientTestModel();
        model.setId(i + 1);
        entities.add(model);
    }
    int[] res = dao.batchDelete(new DalHints(), entities);
    assertEqualsBatch(new int[] { 1, 1, 1 }, res, 4 - 3);
}
Also used : ClientTestModel(com.ctrip.platform.dal.dao.unitbase.ClientTestModel) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 30 with ClientTestModel

use of com.ctrip.platform.dal.dao.unitbase.ClientTestModel in project dal by ctripcorp.

the class DalTableDaoTestStub method testInsertCheckForData.

/**
 * Test Insert with null or empty parameters
 *
 * @throws SQLException
 */
@Test
public void testInsertCheckForData() throws SQLException {
    ClientTestModel model = null;
    try {
        dao.insert(new DalHints(), model);
        Assert.fail();
    } catch (Exception e) {
    }
    List<ClientTestModel> models = null;
    try {
        dao.insert(new DalHints(), models);
        Assert.fail();
    } catch (Exception e) {
    }
    models = new ArrayList<>();
    int[] res = dao.insert(new DalHints(), models);
    Assert.assertEquals(0, res.length);
}
Also used : ClientTestModel(com.ctrip.platform.dal.dao.unitbase.ClientTestModel) SQLException(java.sql.SQLException) Test(org.junit.Test)

Aggregations

ClientTestModel (com.ctrip.platform.dal.dao.unitbase.ClientTestModel)57 Test (org.junit.Test)55 DalHints (com.ctrip.platform.dal.dao.DalHints)29 StatementParameters (com.ctrip.platform.dal.dao.StatementParameters)27 ArrayList (java.util.ArrayList)13 SQLException (java.sql.SQLException)9 SelectSqlBuilder (com.ctrip.platform.dal.dao.sqlbuilder.SelectSqlBuilder)5 DalClient (com.ctrip.platform.dal.dao.DalClient)3 DalCommand (com.ctrip.platform.dal.dao.DalCommand)3 ClientTestDalRowMapper (com.ctrip.platform.dal.dao.unitbase.ClientTestDalRowMapper)3 DalRowMapperExtractor (com.ctrip.platform.dal.dao.helper.DalRowMapperExtractor)2 DalCustomRowMapper (com.ctrip.platform.dal.dao.helper.DalCustomRowMapper)1 FreeSelectSqlBuilder (com.ctrip.platform.dal.dao.sqlbuilder.FreeSelectSqlBuilder)1 ResultSet (java.sql.ResultSet)1 Timestamp (java.sql.Timestamp)1 List (java.util.List)1 Map (java.util.Map)1