|Mr Persister ORM|
|Who is using Mr Persister?|
Mr Persister 4.0.0 has been cleaned up and released as Butterfly Persistence 5.0.0. All further development will take place in Butterfly Persistence. Butterfly Persistence is not drop-in compatible with Mr Persister. The two API's have different base package names. Therefore it is possible to use both API's in your application at the same time. This can be handy during a transition from Mr Persister to Butterfly Persistence. Just create a PersistenceManager from each API, and pass the same DataSource instance to them. That should work. The old code will use the com.jenkov.mrpersister.PersistenceManager, and the new code will use the com.jenkov.db.PersistenceManager.
Mr. Persister aims at providing a simple yet complete relational persistence API. The implemented/planned features includes easier JDBC operations via JDBC templates (Spring style), automatic connection / transaction handling, object relational mapping, dynamic reports, connection pooling, caching, replication, debugging and more. The API has been under constant development since the first release in august 2004.
Mr. Persister's features include:
|JDBC Support / Utilities|
|Simplifies trivial JDBC tasks.|
|Interleave custom JDBC with Mr. Persister operations.|
|Automatic connection and transaction management
(via connection and transaction scoping).
|Connection Pooling (coming soon)|
|Object Relational Mapping (ORM)|
|Read objects of any size in just 3-5 lines of code.|
|Automatic, annotation based and manual (programmatic) mapping of objects to database tables and queries.|
|SQL as query language.|
|Automatic connection and transaction management
(via DAO commands).
|Automatic SQL generation for most trivial tasks.|
|Batch updates of multiple objects.|
|Compound primary key support.|
|Partial object reading and writing.|
|Read ResultSet's into Map's for easy display in web pages etc.|
|Ease of Use|
|No config files required.|
|No new query language (just plain SQL)|
|Fully Pluggable Design.|
|Stability, Maturity & Performance|
|Less than 5% overhead compared to JDBC (Much less than Hibernate)|
|Well Tested. 313 unit tests were executed against each supported database.|
|First stable release was august 2004.|
Read objects of any size in just 3-5 lines of code.
In most cases Mr. Persister just takes 3 to 5 lines of code to read or write an object, or a list of objects. Create a PersistenceManager (line 1), create an IDaos or IGenericDao instance (line 2), and read / write your object(s). See the examples for code examples.
Automatic and manual mapping of objects to database tables.
Mr. Persister can guess most trivial object-to-database-table mappings at runtime. In the cases in which the mapping between object and table isn't trivial you can specify a custom object mapping programmatically. You can also mix Mr. Persisters auto-mapping with custom mapping, so you only need to fill in what Mr. Persiste can't guess.
No config files required.
No configuration files are required. Mr. Persister guesses most object-to-database-table mappings itself. For the mappings that cannot be guessed, mapping is done programmatically in your code.
SQL as query language.
Mr. Persister uses plain SQL as the query language. If your database understands it, so does Mr. Persister. No proprietary query language.
Automatic connection and transaction management.
Automatic connection handling means that if you pass a DataSource to Mr. Persister the API will open and close connections automatically, without you needing to worry about it. If you just pass Mr. Persister a connection Mr. Persister can close it for you automatically when you are done. Automatic transaction handling means that Mr. Persister will commit your transaction for you automatically. If an exception is thrown during the transaction the transaction is rolled back for you automatically, before the exception is rethrown.
Automatic connection and transaction management is achieved via DAO commands. You pass a DAO command to Mr. Persister for execution. Mr. Persister will obtain a connection and if executing in a transaction call connection.setAutoCommit(false) on the connection. Then Mr. Persister will execute the DAO command. After execution the transaction, if any, will be committed and the connection closed. If an exception (any Throwable) is thrown from the DAO command during execution the transaction, if any, will be rolled back, and the exception wrapped and rethrown. You can also use automatic connection and transaction handling even if you pass a connection to Mr. Persister manually. Mr. Persister will commit/rollback and close the connection for you.
Automatic SQL generation for most trivial tasks.
Mr. Persister can generate SQL for object-database trivial tasks like insert, update, delete, and read-by-primary-key operations .
Batch updates of multiple objects.
Mr. Persister makes it easy to insert, update or delete multiple objects using batch updates. It takes just the usual 3 lines of code. See the examples for code examples.
Compound primary key support.
From v. 2.9.0 Mr. Persister has support for compound primary keys.
Partial object reading and writing.
Even if all of an objects fields are mapped to columns in a database table, you don't have to read all the database columns into an object when reading it. In your SQL, just select the columns you want filled into the object. The rest of the objects fields are left untouched. For partial writing you will have to specify a custom object mapping that only maps the fields to write, to the database table.
It is possible to futher filter the ResultSet using IReadFilter's before reading the records into objects. That way you can filter out unwanted objects that are otherwise hard to filter out in SQL. For instance, depending on whether another object was read earlier in the ResultSet etc. Read filters can also skip ahead in the ResultSet, for instance down to the 100th record, before object reading starts. Read filters can also stop the object reading, for instance after record 101-110 has been read from the ResultSet. This is useful for "page reading".
Simplifies trivial JDBC tasks.
Even if you don't have to read objects, but just need to run an SQL update on a set of records, Mr. Persister can help you. Mr. Persister can fill in the parameters into the PreparedStatement for you, so you don't have to be bothered with the opening and closing of PreparedStatements. Mr. Persister can also help you iterate ResultSets and close them for you. See the examples for code examples.
Interleave custom JDBC with Mr. Persister operations.
You can always execute custom JDBC operations on the connection used by Mr. Persister. That way you can interleave custom JDBC operations with tasks carried out by Mr. Persister.
Fully Pluggable Design.
The components that carry out the Mr. Persister operations are separated by their function, and collected into a coherent persistence configuration. You can always exchange the Mr. Persister default implementations in the persistence configuration with your own, custom implementations. You can also override any auto-generated object mappings, or auto-generated SQL. Just manipulate the caches, and you are done.
We are currently evaluating Mr. Persisters performance on difference databases, and compared to other ORM's. You can keep up with the results under performance.
The early tests show that Mr. Persister is more than twice as fast as Hibernate for simple insert and delete operations, both API's used ontop of HSQLDB. By twice as fast we mean that twice as many inserts and deletes could be carried out with Mr. Persister in the same time. More detailed tests and measurements will be added throughout the year.
Mr. Persister's overhead seems to be less than 5% compared to pure JDBC persistence with an HSQLDB server. Hibernates out-of-the-box overhead seems to be around 110% compared to pure JDBC persistence with an HSQLDB server.
See the examples of how easy Mr. Persister is to use, if you are not convinced.