Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Announcements

Tip: Looking for answers? Try searching our database.

Mr. Persister 2.0.1 Released in beta (ORM API).

Jakob Jenkov   06 Aug 2004 17:59 GMTPage rating:


Jenkov Development has released v. 2.0.1 of the Mr. Persister ORM API.

Mr. Persister is a small, fast, and  simple open source
Java object relational mapping API.
You can download it from it's project page here:

http://www.jenkov.dk/projects/mrpersister/mrpersister.jsp

Mr. Persister's main features and differences from other ORM API's are:

*) SQL as Query Language.
  That means you don't have to learn a new query language in order to use
  Mr. Persister. If your database understands your SQL, so does Mr.
Persister.

  In addition to SQL Mr. Persister is capable of reading objects from
  JDBC's ResultSet, Statement, and PreparedStatement instances too.

*) Mapping to SQL Queries
  When reading Mr. Persister just iterates through the columns
  of the ResultSet and checks if they are mapped to a setter method on
  the object. Therefore the columns in the ResultSet don't have to exist
  in any table. As long as they exist in the ResultSet Mr. Persister can
  read objects from it. This makes it easy to map objects to complex
  joins, or aggregate functions like "select sum (...) from ... group by
...."

*) Automatic Mapping
  Mr. Persister is capable of guessing most trivial mappings between
classes
  and tables, and between getters / setters and columns. This way you save
  the work of creating manual mapping files.

  You can also create manual mappings easily programmatically. Or you can
  use mixed mapping where you have Mr. Persister generate an automatic
  mapping that you modify before it's used.

*) Mr. Persister can generate SQL for some trivial operations like
readByPrimaryKey,
  insert, update, delete, deleteByPrimaryKey.
  This SQL is generated at
  request time (lazy evaluation) and cached for later use, so there is
  no startup SQL generation time penalty.

*) Mr. Persister supports batch updates (insert, update, delete, and
deleteByPrimaryKey)

*) Mr. Persister uses reflection to move data between the JDBC components
and
  the objects.

*) Mr. Persister supports JDBC transactions. You can easily interleave your
own
  JDBC code with Mr. Persister method calls inside the same transaction.

*) Small. 97 kb binary jar file.

*) Fast. < 5% overhead on reads from MySQL.

*) Released under the Apache License.

Using Mr. Persister can be done in just 3 simple steps:

1) Download the binary jar file.

2) Include the binary jar file on your classpath

3) Subclass com.jenkov.mrpersister.AbstractDao (with you DAO class, not the
POJO's)

The AbstractDao works as a facade to the Mr. Persister components and has a
lot
of protected methods your DAO subclass can make use of when implementing
your
own read and write methods. Below is an example of a simple DAO class that
uses
Mr. Persister and automatic mapping:

public class EmployeeDao extends AbstractDao{

   protected Connection getConnection() throws PersistenceException {
       //you need to override this method. It's used by the AbstractDAO
methods.
   }

   public Employee readEmployee(String employeeId) throws
PersistenceException{
       return (Employee) readByPrimaryKey(Employee.class, employeeId);
   }

   public List readAllEmployees() throws PersistenceException{
       return readList(Employee.class, "select * from employees");
   }

   public int insertEmployee(Employee employee) throws PersistenceException
{
       return insert(Employee.class, employee);
   }

   public int updateEmployee(Employee employee) throws PersistenceException
{
       return update(Employee.class, employee);
   }

   public int deleteEmployee(Employee employee) throws PersistenceException
{
       return delete(Employee.class, employee);
   }

   public int[] insertEmployees(List employees) throws PersistenceException
{
       return insertBatch(Employee.class, employees);
   }

   public int[] updateEmployees(List employees) throws PersistenceException
{
       return updateBatch(Employee.class, employees);
   }

   public int[] deleteEmployees(List employees) throws PersistenceException
{
       return deleteBatch(Employee.class, employees);
   }

}

Check it out. ORM won't get much easier than this, we believe.


Rate this page
Poor Excellent    

Comments

No comments at this time. Why not be the first?

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Post new comment
Rate this page



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.