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());
}
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);
}
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));
}
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());
}
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());
}
Aggregations