use of org.apache.commons.dbutils.handlers.MapListHandler in project notes by KevinBlandy.
the class Demo method demo.
/**
* ���н�����ķ�װ��ʾ
*/
public static void demo(String param) throws Exception {
String sql = "select * from user,class where user.cid=class.cid and user.password=?";
// ִ�в�ѯ,���صĵ���һ��map����
List<Map<String, Object>> list = qr.query(sql, new MapListHandler(), param);
// ��������,����������
List<User> userlist = new ArrayList<User>();
for (int x = 0; x < list.size(); x++) {
// �ѵ���mapȡ��
Map<String, Object> map = list.get(x);
// ��������
User u = new User();
// ��������
Class c = new Class();
// ��װ����
BeanUtils.populate(u, map);
// ��װ����
BeanUtils.populate(c, map);
// ������ϵ,��ʵҲ���ǰ����c�ŵ���u������
u.setC(c);
// �����յĶ�����õ�����,���Է��ظ�service��
userlist.add(u);
}
for (int x = 0; x < userlist.size(); x++) {
User u = userlist.get(x);
System.out.println(u.toString());
System.out.println(u.getC().toString());
}
}
use of org.apache.commons.dbutils.handlers.MapListHandler in project tutorials by eugenp.
the class DbUtilsUnitTest method givenResultHandler_whenExecutingQuery_thenExpectedList.
@Test
public void givenResultHandler_whenExecutingQuery_thenExpectedList() throws SQLException {
MapListHandler beanListHandler = new MapListHandler();
QueryRunner runner = new QueryRunner();
List<Map<String, Object>> list = runner.query(connection, "SELECT * FROM employee", beanListHandler);
assertEquals(list.size(), 5);
assertEquals(list.get(0).get("firstname"), "John");
assertEquals(list.get(4).get("firstname"), "Christian");
}
use of org.apache.commons.dbutils.handlers.MapListHandler in project jSqlBox by drinkjava2.
the class DynamicCompileEngineTest method doTest.
@Test
public void doTest() throws IllegalAccessException, InstantiationException {
MapListHandler handler = null;
String fullName = "com.foo.bar.DynaClass";
Class<?> clazz = null;
for (// Test class cached
int i = 0; // Test class cached
i < 100000; // Test class cached
i++) clazz = DynamicCompileEngine.instance.javaCodeToClass(fullName, javaSrc);
Object instance = DynamicCompileEngine.instance.javaCodeToNewInstance(fullName, javaSrc);
System.out.println(instance.toString());
Assert.assertEquals(instance.toString(), "Test Dynamic Compile");
}
use of org.apache.commons.dbutils.handlers.MapListHandler in project jSqlBox by drinkjava2.
the class HandlersTest method testMyAroundSqlHandler.
@Test
public void testMyAroundSqlHandler() throws SQLException {
List<Map<String, Object>> result2 = ctx.nQuery(new Wrap(new MapListHandler(), new MyAroundSqlHandler()), "select u.* from DemoUser u where u.age>?", 0);
Assert.assertTrue(result2.size() == 99);
}
use of org.apache.commons.dbutils.handlers.MapListHandler in project jSqlBox by drinkjava2.
the class HandlersTest method testPrintSqlHandler.
@Test
public void testPrintSqlHandler() throws SQLException {
List<Map<String, Object>> result = ctx.nQuery(new MapListHandler(), "select u.* from DemoUser u where u.age>?", 0);
Assert.assertTrue(result.size() == 99);
List<Map<String, Object>> result2 = ctx.nQuery(new Wrap(new MapListHandler(), new PrintSqlHandler()), "select u.* from DemoUser u where u.age>?", 0);
Assert.assertTrue(result2.size() == 99);
}
Aggregations