jPersist is an extremely
powerful object-relational persistence API that is based on the
Active-Record and Data-Mapper patterns. jPersist wraps JDBC
functionality and can work with any relational database, and any
type of connection resource, including: java.sql.DriverManager,
JNDI, javax.sql.DataSource, and third party connection pooling
libraries (DBCP, C3PO, etc.).
Using jPersist is as simple
as:
public void
DatabaseExample(DatabaseManager dbm) throws
JPersistException
{
// Inserting contact with associations
Contact contact = new Contact("deisenhower", ...);
contact.getSupport().add(new Support("Request", ...));
contact.getSupport().add(new Support("Response", ...));
contact.getSupport().add(new Support("Request", ...));
contact.getOrders().add(new Order("Dwight D. Eisenhower Dollar",
...));
contact.getOrders().add(new Order("Susan B. Anthony Dollar",
...));
// Saving within an automatic transaction (covers all
relationships)
dbm.saveObject(contact);
// Load based on information contained in classes
contact = dbm.loadObject(Contact.class, "where :contactId like ?",
“tjef%”);
System.out.println("\ncontactId = " +
contact.getContactId());
// Load a collection of objects from the
database
Collection<Contact> c = dbm.loadObjects(new
Vector<Contact>(), Contact.class);
for (Contact contact2 : c)
System.out.println("contactId = " +
contact2.getContactId());
}
All in all, jPersist’s
sole reason for being is to provide simple trouble-free POJO
oriented
access to your database. With
jPersist and your POJOs, you should rarely have to
do anything more
than:
·
Define a POJO
(optionally extending jpersist.PersistentObject), which can be
extended by other POJOs (relational hierarchy via
joins).
·
Call one of
jpersist.DatabaseManager’s: loadObject(), saveObject(), and
deleteObject(), or one of jpersist.Database’s: saveObject(),
deleteObject(), and queryObject() with jpersist.Result’s
loadObject().
·
Group saves and
deletes in a transaction using jpersist.TransactionManager or use
jpersist.Database’s transaction oriented methods.
·
Group updates in
an update manager using jpersist.UpdateManager or use
jpersist.Database’s update and batch oriented
methods.
That’s not to say you
won’t have other JDBC needs, like calling stored procedures
or executing SQL statements, but with jPersist it’s all easy
to handle.