Search in sources :

Example 16 with ClientTestModel

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

the class DalTableDaoTestStub method testBatchInsert.

/**
 * Test Batch Insert multiple entities
 * @throws SQLException
 */
@Test
public void testBatchInsert() 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.batchInsert(new DalHints(), entities);
    assertEqualsBatchInsert(new int[] { 1, 1, 1 }, res, 7);
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) ClientTestModel(test.com.ctrip.platform.dal.dao.unitbase.ClientTestModel) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 17 with ClientTestModel

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

the class DalTableDaoTestStub method testQueryTopWithWhereClause.

/**
 * Test Query the top rows with where clause
 * @throws SQLException
 */
@Test
public void testQueryTopWithWhereClause() throws SQLException {
    String whereClause = "type=?";
    StatementParameters parameters = new StatementParameters();
    parameters.set(1, Types.SMALLINT, 1);
    List<ClientTestModel> models = dao.queryTop(whereClause, parameters, new DalHints(), 2);
    Assert.assertTrue(null != models);
    Assert.assertEquals(2, models.size());
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) ClientTestModel(test.com.ctrip.platform.dal.dao.unitbase.ClientTestModel) StatementParameters(com.ctrip.platform.dal.dao.StatementParameters) Test(org.junit.Test)

Example 18 with ClientTestModel

use of test.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(test.com.ctrip.platform.dal.dao.unitbase.ClientTestModel) StatementParameters(com.ctrip.platform.dal.dao.StatementParameters) Test(org.junit.Test)

Example 19 with ClientTestModel

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

the class DalDirectClientSqlServerTest 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;
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) ClientTestModel(test.com.ctrip.platform.dal.dao.unitbase.ClientTestModel) SQLException(java.sql.SQLException) StatementParameters(com.ctrip.platform.dal.dao.StatementParameters) ArrayList(java.util.ArrayList) DalRowMapperExtractor(com.ctrip.platform.dal.dao.helper.DalRowMapperExtractor)

Example 20 with ClientTestModel

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

the class DalDirectClientTestStub method callTestWithParametersForSpWithoutOutParameter.

/**
 * Test call with parameters but has no resultsParameter
 * @throws SQLException
 */
@Test
public void callTestWithParametersForSpWithoutOutParameter() throws SQLException {
    String callSql = "{call " + SP_WITHOUT_OUT_PARAM + "(?,?,?,?)}";
    StatementParameters parameters = new StatementParameters();
    parameters.set("v_id", Types.INTEGER, 4);
    parameters.set("v_quantity", Types.INTEGER, 10);
    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());
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) ClientTestModel(test.com.ctrip.platform.dal.dao.unitbase.ClientTestModel) StatementParameters(com.ctrip.platform.dal.dao.StatementParameters) Test(org.junit.Test)

Aggregations

DalHints (com.ctrip.platform.dal.dao.DalHints)61 ClientTestModel (test.com.ctrip.platform.dal.dao.unitbase.ClientTestModel)61 Test (org.junit.Test)59 StatementParameters (com.ctrip.platform.dal.dao.StatementParameters)40 ArrayList (java.util.ArrayList)13 SQLException (java.sql.SQLException)9 DalClient (com.ctrip.platform.dal.dao.DalClient)3 DalCommand (com.ctrip.platform.dal.dao.DalCommand)3 SelectSqlBuilder (com.ctrip.platform.dal.dao.sqlbuilder.SelectSqlBuilder)3 ClientTestDalRowMapper (test.com.ctrip.platform.dal.dao.unitbase.ClientTestDalRowMapper)3 KeyHolder (com.ctrip.platform.dal.dao.KeyHolder)2 DalRowMapperExtractor (com.ctrip.platform.dal.dao.helper.DalRowMapperExtractor)2 DalRowCallback (com.ctrip.platform.dal.dao.DalRowCallback)1 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