Search in sources :

Example 6 with ClientTestModel

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

the class DalDirectClientTestStub method updateTestWithParameters.

/**
 * Test the update function with parameters
 *
 * @throws SQLException
 */
@Test
public void updateTestWithParameters() throws SQLException {
    String updateSql = String.format("UPDATE %s SET address=? WHERE id=?", TABLE_NAME);
    StatementParameters parameters = new StatementParameters();
    parameters.set(1, Types.VARCHAR, "BJ INFO");
    parameters.set(2, Types.INTEGER, 1);
    DalHints hints = new DalHints();
    int count = client.update(updateSql, parameters, hints);
    assertEquals(1, count, 2, "address='BJ INFO'");
    List<ClientTestModel> po_models = this.queryModelsByIds(1);
    Assert.assertTrue(null != po_models);
    Assert.assertEquals(1, po_models.size());
    Assert.assertEquals("BJ INFO", po_models.get(0).getAddress());
}
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 7 with ClientTestModel

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

the class DalQueryDaoTestStub method testQueryForObjectSuccess.

/**
 * Test query for object success
 * @throws SQLException
 */
@Test
public void testQueryForObjectSuccess() throws SQLException {
    String sql = "SELECT * FROM " + TABLE_NAME + " WHERE id = 1";
    StatementParameters param = new StatementParameters();
    DalHints hints = new DalHints();
    ClientTestModel model = client.queryForObject(sql, param, hints, mapper);
    Assert.assertEquals(1, model.getId().intValue());
    FreeSelectSqlBuilder<List<Map<String, Object>>> builder = new FreeSelectSqlBuilder<>();
    builder.append("select count(*) as c1, 111 as c2");
    builder.mapWith(new DalCustomRowMapper("c1", "c2"));
    builder.with(new StatementParameters());
    List<Map<String, Object>> l = client.query(builder, hints);
}
Also used : FreeSelectSqlBuilder(com.ctrip.platform.dal.dao.sqlbuilder.FreeSelectSqlBuilder) ClientTestModel(com.ctrip.platform.dal.dao.unitbase.ClientTestModel) DalCustomRowMapper(com.ctrip.platform.dal.dao.helper.DalCustomRowMapper) List(java.util.List) Map(java.util.Map) Test(org.junit.Test)

Example 8 with ClientTestModel

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

the class DalQueryDaoTestStub method testQueryForObjectNullableSuccess.

/**
 * Test query for object success
 * @throws SQLException
 */
@Test
public void testQueryForObjectNullableSuccess() throws SQLException {
    String sql = "SELECT * FROM " + TABLE_NAME + " WHERE id = 1";
    StatementParameters param = new StatementParameters();
    DalHints hints = new DalHints();
    ClientTestModel model = client.queryForObjectNullable(sql, param, hints, mapper);
    Assert.assertNotNull(model);
    Assert.assertEquals(1, model.getId().intValue());
    sql = "SELECT * FROM " + TABLE_NAME + " WHERE id = -1";
    Assert.assertNull(client.queryForObjectNullable(sql, param, hints, mapper));
}
Also used : ClientTestModel(com.ctrip.platform.dal.dao.unitbase.ClientTestModel) Test(org.junit.Test)

Example 9 with ClientTestModel

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

the class DalQueryDaoTestStub method testQueryFirstSuccess.

/**
 * Test query for first success
 * @throws SQLException
 */
@Test
public void testQueryFirstSuccess() throws SQLException {
    String sql = "SELECT * FROM " + TABLE_NAME + " WHERE id = 1";
    StatementParameters param = new StatementParameters();
    DalHints hints = new DalHints();
    ClientTestModel model = client.queryFirst(sql, param, hints, mapper);
    Assert.assertEquals(1, model.getId().intValue());
}
Also used : ClientTestModel(com.ctrip.platform.dal.dao.unitbase.ClientTestModel) Test(org.junit.Test)

Example 10 with ClientTestModel

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

the class DalQueryDaoTestStub method testQueryWithCallback.

/**
 * Test the query function with callback
 * @throws SQLException
 */
@Test
public void testQueryWithCallback() throws SQLException {
    String sql = "SELECT * FROM " + TABLE_NAME + " WHERE id = 1";
    final ClientTestModel model = new ClientTestModel();
    DalRowCallback callback = new DalRowCallback() {

        @Override
        public void process(ResultSet rs) throws SQLException {
            model.setId(rs.getInt(1));
            model.setQuantity(rs.getInt(2));
            model.setType(rs.getShort(3));
            model.setAddress(rs.getString(4));
            model.setLastChanged(rs.getTimestamp(5));
        }
    };
    StatementParameters param = new StatementParameters();
    DalHints hints = new DalHints();
    client.query(sql, param, hints, callback);
    Assert.assertEquals(1, model.getId().intValue());
}
Also used : ClientTestModel(com.ctrip.platform.dal.dao.unitbase.ClientTestModel) ResultSet(java.sql.ResultSet) 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