Search in sources :

Example 51 with ClientTestModel

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

Example 52 with ClientTestModel

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

the class DalTableDaoTestStub method testQueryFromWithWhereClauseEmpty.

/**
 * Test Query range of result with where clause when return empty collection
 * @throws SQLException
 */
@Test
public void testQueryFromWithWhereClauseEmpty() throws SQLException {
    String whereClause = "type=?";
    StatementParameters parameters = new StatementParameters();
    parameters.set(1, Types.SMALLINT, 10);
    List<ClientTestModel> models = dao.queryFrom(whereClause, parameters, new DalHints(), 0, 10);
    Assert.assertTrue(null != models);
    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 53 with ClientTestModel

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

the class DalDirectClientTestStub 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 54 with ClientTestModel

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

the class DalDirectClientTestStub method callTestWithoutParametersForSpWithoutOutParameter.

/**
 * Test call without parameters and has no resultsParameter
 * @throws SQLException
 */
@Test
public void callTestWithoutParametersForSpWithoutOutParameter() throws SQLException {
    String callSql = "{call " + SP_WITHOUT_OUT_PARAM + "(4, 12,1,'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(test.com.ctrip.platform.dal.dao.unitbase.ClientTestModel) StatementParameters(com.ctrip.platform.dal.dao.StatementParameters) Test(org.junit.Test)

Example 55 with ClientTestModel

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

the class DalDirectClientTestStub method callTestForSpWithIntermediateParameters.

/**
 * Test the call function with retrieveAllResultsFromSp parameters
 * @throws SQLException
 */
@Test
public void callTestForSpWithIntermediateParameters() throws SQLException {
    String callSql = "{call " + SP_WITH_INTERMEDIATE_RESULT + "(?,?,?,?)}";
    StatementParameters parameters = new StatementParameters();
    parameters.set("v_id", Types.INTEGER, 1);
    parameters.set("v_quantity", Types.INTEGER, 10);
    parameters.set("v_type", Types.SMALLINT, 3);
    parameters.registerInOut("v_address", Types.VARCHAR, "SZ INFO");
    DalHints hints = new DalHints().retrieveAllResultsFromSp();
    Map<String, ?> res = client.call(callSql, parameters, hints);
    System.out.println(res);
    Assert.assertTrue(null != res);
    if (diff.supportSpIntermediateResult)
        // mysql will return update count as well, while sqlserver will not return update count
        Assert.assertTrue(res.size() >= 5);
    else
        Assert.assertEquals(1, res.size());
    Assert.assertTrue(res.containsKey("v_address"));
    Assert.assertEquals("output", res.get("v_address"));
    Assert.assertEquals("output", parameters.get("v_address", ParameterDirection.InputOutput).getValue());
    List<ClientTestModel> models = this.queryModelsByIds(1);
    Assert.assertEquals(1, models.size());
    Assert.assertEquals("aaa", models.get(0).getAddress());
}
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