Search in sources :

Example 1 with Wrap

use of com.github.drinkjava2.jdbpro.handler.Wrap in project jSqlBox by drinkjava2.

the class HandlersTest method testSimpleCacheHandler.

@Test
public void testSimpleCacheHandler() {
    for (int i = 0; i < 10; i++) {
        // warm up
        ctx.nQuery(new Wrap(new EntityListHandler(DemoUser.class), new SimpleCacheHandler()), "select u.** from DemoUser u where u.age>?", 0);
        ctx.nQuery(new Wrap(new EntityListHandler(DemoUser.class)), "select u.** from DemoUser u where u.age>?", 0);
    }
    long start = System.currentTimeMillis();
    for (int i = 0; i < 1000; i++) {
        List<DemoUser> result = ctx.nQuery(new Wrap(new EntityListHandler(DemoUser.class), new SimpleCacheHandler()), "select u.** from DemoUser u where u.age>?", 0);
        Assert.assertTrue(result.size() == 99);
    }
    long end = System.currentTimeMillis();
    String timeused = "" + (end - start) / 1000 + "." + (end - start) % 1000;
    System.out.println(String.format("%28s: %6s s", "With Cache", timeused));
    start = System.currentTimeMillis();
    for (int i = 0; i < 1000; i++) {
        List<DemoUser> result = ctx.nQuery(new Wrap(new EntityListHandler(DemoUser.class)), "select u.** from DemoUser u where u.age>?", 0);
        Assert.assertTrue(result.size() == 99);
    }
    end = System.currentTimeMillis();
    timeused = "" + (end - start) / 1000 + "." + (end - start) % 1000;
    System.out.println(String.format("%28s: %6s s", "No Cache", timeused));
}
Also used : Wrap(com.github.drinkjava2.jdbpro.handler.Wrap) SimpleCacheHandler(com.github.drinkjava2.jdbpro.handler.SimpleCacheHandler) EntityListHandler(com.github.drinkjava2.jsqlbox.handler.EntityListHandler) Test(org.junit.Test)

Example 2 with Wrap

use of com.github.drinkjava2.jdbpro.handler.Wrap 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 3 with Wrap

use of com.github.drinkjava2.jdbpro.handler.Wrap in project jSqlBox by drinkjava2.

the class HandlersTest method testPaginHandler.

@Test
public void testPaginHandler() {
    List<Map<String, Object>> result = ctx.nQuery(new Wrap(new EntitySqlMapListHandler(DemoUser.class), new PaginHandler(2, 5)), "select u.** from DemoUser u where u.age>?", 0);
    Assert.assertTrue(result.size() == 5);
    List<DemoUser> users = ctx.nQuery(new Wrap(new EntityListHandler(DemoUser.class), new PaginHandler(2, 5)), "select u.** from DemoUser u where u.age>?", 0);
    Assert.assertTrue(users.size() == 5);
}
Also used : PaginHandler(com.github.drinkjava2.jsqlbox.handler.PaginHandler) Wrap(com.github.drinkjava2.jdbpro.handler.Wrap) EntityListHandler(com.github.drinkjava2.jsqlbox.handler.EntityListHandler) Map(java.util.Map) EntitySqlMapListHandler(com.github.drinkjava2.jsqlbox.handler.EntitySqlMapListHandler) Test(org.junit.Test)

Example 4 with Wrap

use of com.github.drinkjava2.jdbpro.handler.Wrap 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)

Example 5 with Wrap

use of com.github.drinkjava2.jdbpro.handler.Wrap in project jSqlBox by drinkjava2.

the class HandlersTest method testHandlers.

@Test
public void testHandlers() {
    List<DemoUser> result = ctx.nQuery(new Wrap(PrintSqlHandler.class, new EntityListHandler(DemoUser.class), new PaginHandler(1, 5), PrintSqlHandler.class), "select u.** from DemoUser u where u.age>?", 0);
    Assert.assertTrue(result.size() == 5);
}
Also used : PaginHandler(com.github.drinkjava2.jsqlbox.handler.PaginHandler) Wrap(com.github.drinkjava2.jdbpro.handler.Wrap) EntityListHandler(com.github.drinkjava2.jsqlbox.handler.EntityListHandler) PrintSqlHandler(com.github.drinkjava2.jdbpro.handler.PrintSqlHandler) Test(org.junit.Test)

Aggregations

Wrap (com.github.drinkjava2.jdbpro.handler.Wrap)5 Test (org.junit.Test)5 EntityListHandler (com.github.drinkjava2.jsqlbox.handler.EntityListHandler)3 EntitySqlMapListHandler (com.github.drinkjava2.jsqlbox.handler.EntitySqlMapListHandler)3 Map (java.util.Map)3 PrintSqlHandler (com.github.drinkjava2.jdbpro.handler.PrintSqlHandler)2 PaginHandler (com.github.drinkjava2.jsqlbox.handler.PaginHandler)2 MapListHandler (org.apache.commons.dbutils.handlers.MapListHandler)2 SimpleCacheHandler (com.github.drinkjava2.jdbpro.handler.SimpleCacheHandler)1