Search in sources :

Example 1 with MapListHandler

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());
    }
}
Also used : MapListHandler(org.apache.commons.dbutils.handlers.MapListHandler) ArrayList(java.util.ArrayList) Map(java.util.Map)

Example 2 with MapListHandler

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");
}
Also used : MapListHandler(org.apache.commons.dbutils.handlers.MapListHandler) Map(java.util.Map) QueryRunner(org.apache.commons.dbutils.QueryRunner) AsyncQueryRunner(org.apache.commons.dbutils.AsyncQueryRunner) Test(org.junit.Test)

Example 3 with MapListHandler

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");
}
Also used : MapListHandler(org.apache.commons.dbutils.handlers.MapListHandler) Test(org.junit.Test)

Example 4 with MapListHandler

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);
}
Also used : MapListHandler(org.apache.commons.dbutils.handlers.MapListHandler) EntitySqlMapListHandler(com.github.drinkjava2.jsqlbox.handler.EntitySqlMapListHandler) Wrap(com.github.drinkjava2.jdbpro.handler.Wrap) Map(java.util.Map) Test(org.junit.Test)

Example 5 with MapListHandler

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);
}
Also used : MapListHandler(org.apache.commons.dbutils.handlers.MapListHandler) EntitySqlMapListHandler(com.github.drinkjava2.jsqlbox.handler.EntitySqlMapListHandler) Wrap(com.github.drinkjava2.jdbpro.handler.Wrap) PrintSqlHandler(com.github.drinkjava2.jdbpro.handler.PrintSqlHandler) Map(java.util.Map) Test(org.junit.Test)

Aggregations

MapListHandler (org.apache.commons.dbutils.handlers.MapListHandler)6 Map (java.util.Map)5 Test (org.junit.Test)5 Wrap (com.github.drinkjava2.jdbpro.handler.Wrap)2 EntitySqlMapListHandler (com.github.drinkjava2.jsqlbox.handler.EntitySqlMapListHandler)2 PrintSqlHandler (com.github.drinkjava2.jdbpro.handler.PrintSqlHandler)1 SqlBoxContext (com.github.drinkjava2.jsqlbox.SqlBoxContext)1 HikariDataSource (com.zaxxer.hikari.HikariDataSource)1 ArrayList (java.util.ArrayList)1 AsyncQueryRunner (org.apache.commons.dbutils.AsyncQueryRunner)1 QueryRunner (org.apache.commons.dbutils.QueryRunner)1