Search in sources :

Example 56 with ClientTestModel

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

the class DalDirectClientSqlServerTest method execTestWithParametersForSpWithoutOutParameter.

@Test
public void execTestWithParametersForSpWithoutOutParameter() throws SQLException {
    String callSql = "exec " + SP_WITHOUT_OUT_PARAM + " @v_id=?, @v_quantity=?, @v_type=?, @v_address=?";
    // set disordered parameter by name
    StatementParameters parameters = new StatementParameters();
    parameters.set("v_quantity", Types.INTEGER, 10);
    parameters.set("v_id", Types.INTEGER, 4);
    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());
    // set disordered parameter by index and name
    StatementParameters parameters2 = new StatementParameters();
    int index = 1;
    parameters2.set(index++, "v_quantity", Types.INTEGER, 10);
    parameters2.set(index++, "v_id", Types.INTEGER, 4);
    parameters2.set(index++, "v_type", Types.SMALLINT, 3);
    parameters2.set(index++, "v_address", Types.VARCHAR, "SZ INFO");
    try {
        client.call(callSql, parameters2, new DalHints());
    } catch (Exception e) {
        Assert.assertTrue(e.getMessage().contains("doesn't match with the index"));
    }
    // set disordered parameter by index
    StatementParameters parameters3 = new StatementParameters();
    index = 1;
    parameters3.set(index++, Types.VARCHAR, "SZ INFO");
    parameters3.set(index++, Types.INTEGER, 10);
    parameters3.set(index++, Types.INTEGER, 4);
    parameters3.set(index++, Types.SMALLINT, 3);
    try {
        client.call(callSql, parameters3, new DalHints());
    } catch (Exception e) {
        Assert.assertTrue(e.getMessage().contains("Error converting data type varchar to int"));
    }
    // set ordered parameter by index
    StatementParameters parameters4 = new StatementParameters();
    index = 1;
    parameters4.set(index++, Types.INTEGER, 5);
    parameters4.set(index++, Types.INTEGER, 10);
    parameters4.set(index++, Types.SMALLINT, 3);
    parameters4.set(index++, Types.VARCHAR, "SZ INFO");
    try {
        client.call(callSql, parameters4, new DalHints());
    } catch (Exception e) {
        Assert.fail();
    }
    Assert.assertTrue(null != res);
    Assert.assertEquals(0, res.size());
    models = this.queryModelsByIds();
    Assert.assertEquals(5, models.size());
    // set ordered parameter by index and name
    StatementParameters parameters5 = new StatementParameters();
    index = 1;
    parameters5.set(index++, "v_id", Types.INTEGER, 6);
    parameters5.set(index++, "v_quantity", Types.INTEGER, 10);
    parameters5.set(index++, "v_type", Types.SMALLINT, 3);
    parameters5.set(index++, "v_address", Types.VARCHAR, "SZ INFO");
    try {
        client.call(callSql, parameters5, new DalHints());
    } catch (Exception e) {
        Assert.fail();
    }
    Assert.assertTrue(null != res);
    Assert.assertEquals(0, res.size());
    models = this.queryModelsByIds();
    Assert.assertEquals(6, 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) SQLException(java.sql.SQLException) Test(org.junit.Test)

Example 57 with ClientTestModel

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

the class DalDirectClientSqlServerTest method execTestWithoutParametersForSpWithoutOutParameter.

@Test
public void execTestWithoutParametersForSpWithoutOutParameter() throws SQLException {
    String callSql = "exec " + SP_WITHOUT_OUT_PARAM + " @v_id=4, @v_quantity=12, @v_type=1, @v_address='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());
}
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