Search in sources :

Example 21 with ClientTestModel

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());
}
Also used : ClientTestModel(com.ctrip.platform.dal.dao.unitbase.ClientTestModel) Test(org.junit.Test)

Example 22 with ClientTestModel

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);
}
Also used : ClientTestModel(com.ctrip.platform.dal.dao.unitbase.ClientTestModel) Test(org.junit.Test)

Example 23 with ClientTestModel

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);
}
Also used : ClientTestModel(com.ctrip.platform.dal.dao.unitbase.ClientTestModel) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 24 with ClientTestModel

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());
}
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 25 with ClientTestModel

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());
}
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)

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