Torque
Well I’m working on a new project and I thought I would test out the Jakarta project Torque for persistence layer. The setup was pretty easy although it took me a little longer to figure out how to configure it with Resin and db pooling.
You use XML to define your objects like so:
< table name="author" description="Author Table">
< column
name=”author_id”
required=”true”
primaryKey=”true”
type=”INTEGER”
description=”Author Id”/>
< column
name=”first_name”
required=”true”
type=”VARCHAR”
size=”128″
description=”First Name”/>
< column
name=”last_name”
required=”true”
type=”VARCHAR”
size=”128″
description=”Last Name”/>
< /table>
Once you setup your schema the coding is easy peasy:
INSERT
Book book = new Book();
book.setTitle(title);
book.setISBN(isbn);
book.save();
SELECT
Criteria crit = new Criteria();
crit.add(BookPeer.title, “Thinking in Java”);
List list = BookPeer.doSelect(crit);
There are ant tasks defined for creating the database, generating the tables, pre-populating tables, and generating your source code. It has transactional support, object and method caching, and a variety of methods of db pooling built in. It also can perform cascading deletes.
Another cool thing is that you can create criteria to use SQL joins to get an object and its foreign key objects thereby elimating multiple selects for an object.
Pretty cool. I’m anxious to see how it performs under a load.