Search in sources :

Example 1 with DalRowCallback

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

Aggregations

DalHints (com.ctrip.platform.dal.dao.DalHints)1 DalRowCallback (com.ctrip.platform.dal.dao.DalRowCallback)1 StatementParameters (com.ctrip.platform.dal.dao.StatementParameters)1 ResultSet (java.sql.ResultSet)1 Test (org.junit.Test)1 ClientTestModel (test.com.ctrip.platform.dal.dao.unitbase.ClientTestModel)1