The Ollin Framework


I have recently discovered a simple Java database framework called “Ollin“. It can be found when searching jdbc fluent api on Google. It has a couple of transaction handling and ORM features, the way many other frameworks do this. But one specific functionality I found particularly interesting:

ValuedRowVisitor<Integer> rowCounter =
dbSession.createQuery("select * from app.employee")
         .forEachRow(new ValuedRowVisitor<Integer>() {
            private int counter;

            public Integer getValue() {
              return counter;
            }

            public void visit(ResultSetRow row) throws SQLException {
              counter++;
            }
         });
System.out.println("Count of rows: " + rowCounter.getValue());

In this example, you can pass an anonymous type implementing a RowVisitor base interface to a “closure-style” foreach method. Victor Herrera, the creator of Ollin designed this specifically for a use case he had where large amounts of rows (or records) needed to be processed and memory was getting low. This use case is already covered in jOOQ when using the ResultQuery.fetchLazy() method, and then iterate over the resulting Cursor. But the idea of “injecting” a custom handler seemed appealing to me, so with Victor’s permission, I have implemented a similar construct for jOOQ 1.6.4 with #728.

In jOOQ, the magic word is “fetch”, and as discussed recently, there is now the possibility of fetching things into custom types using ResultQuery.fetchInto(Class<?>). So why not also fetch results into custom “targets” like this:

create.selectFrom(T_BOOK)
      .orderBy(TBook.ID)
      .fetchInto(new RecordTarget<TBookRecord>() {
        @Override
        public void next(TBookRecord record) {
          // Do stuff
        }
      });

I’m thrilled to find good open source ideas on the web. I’m always open to new ideas and this Ollin Framework made my day, today :-)

See the framework here: http://code.google.com/p/ollin/

Tags: , , , ,

5 responses to “The Ollin Framework”

  1. Manfred Schäfer says :

    Maybe i’m wrong, but isn’t that the common usage of springs jdbctemplate?

    • lukaseder says :

      Spring’s JdbcTemplate knows the concept of a RowMapper or RowCallbackHandler and other types. All of those types are based on plain JDBC ResultSet’s. In fact, Ollin doesn’t do much more than that, so you’re right.

    • Victor Herrera says :

      Yes, it could seem like what Spring JDBC does. But Spring doesn’t abstract the concept of Row. Maybe this doesn’t matter in functionality but I like to develop in a more-OO style.

      The main feature (and difference with Spring) of Ollin is that is based in the Visitor pattern. So the functionality is in the implementation of the RowVisitor. There is just one class and one method to execute the query (useful for simple cases).

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 2,084 other followers

%d bloggers like this: