Saturday, April 2, 2011
We've made some excellent refinements and added some new features:
The most notable refinement is that the PersistenceProviderFactory has been renamed to ModelExposerFactory which is extended within your application to become the single object reponsible for producing ModelExposer's when required.
Previously ModelExposers were produced by the ExpojoServletContextListener which unfortunately tied the use of exPOJO to web based applications. Now that ModelExposer's are produced by a separate ModelExposerFactory that is independent of the servlet API exPOJO can be used equally well in web app and traditional Java applications.
Even within web based development there is often the need for background threads running as part of the web app or running as services outside of a servlet container and this recent refinement of the exPOJO design makes it possible to implement exPOJO in both the web app and supporting services using common source code.
Simple Wrapping of method within a transaction context
The basic pattern for using the ModelExposer is as follows:
// Either find a ModelExposer associated with the current context or create
// a new one each time - the choice is yours. The context could be a HTTP
// session or anything you want it to be.
modelExposer = context.getModelExposer();
if ( modelExposer == null )
modelExposer = ModelExposerFactory().get().createModelExposer();
// Inject (attach) the ModelExposer to this thread so that within any
// methods executed by this thread the model exposer is instantly
// accessible without requiring direct injection of individual
// objects via ModelExposer.get()
// Get the PersistenceProvider and begin a transaction
PersistenceProvider pp = modelExposer.getPp();
// Typically call a method to perform work like servicing a HTTP request or
// executing an iteration of a periodic background task
// do something with your model - load objects, navigate along
// relationships etc., populating UI components: pages, forms, fields etc.,
// example of code that may be executed within a method that does the work:
// UI elements, model objects etc., all have access to the repositories and
// services and the methods of the PersistenceProvider by simply calling the
// convenience methods eg.,
// User user = UserRepository.get().findUser(username);
// Order order = OrderService.get().createOrder(customer);
// Commit the transaction
catch (Exception e)
// rollback if required etc.,
// Detach from this thread - as threads are pooled in a servlet container we must
// not leave the model exposer attached to any particular thread after it
// has finished servicing the current http request
In exPOJO 1.x what tended to happen was that this familiar pattern ended up being implemented in multiple places throughout the code. In 2.x a new method in ModelExposer makes it simple to wrap code in such a pattern without having to repeatedly write implementations of the whole pattern. The implementation within ModelExposer can simply be reused, wrapping any doWork() style method that you require. The doWork() style method in ModelExposer is actually called execute() and it supports the passing of parameters if required.
Friday, May 30, 2008
exPOJO is a super lightweight framework that provides:
- dependency injection in Java (no XML - say goodbye to Spring forever!) using the easy to use ModelExposer class.
- high productivity persistence using the 'exposed POJO model pattern' to access your objects via Hibernate or JDO.
- an ORM wrapper that helps you to build code that is portable across different ORMs.
Version 1.3.2 adds an exceptionally useful 'auto query resource clean up' class donated by Guido Anzuoni from Object Magic: http://www.objectmagic.org. Using this class to encapsulate returned query collection result you don't need to explicitly clean up the query resources associated with those results. Guido's class 'automagically' cleans up the resources when it is garbage collected. This is great for users of the OpenPersistenceManagerInView pattern. Currently Guido's class works with JDO only.
Version 1.3.2 also adds a new flushChanges method which is great when you need to establish an extremely complex object graph with cyclic references. ORMs occassionally generate FK constraints with such object graphs and the only workaround is to perform piecemeal database commits. The new flushChanges method can be called at various steps during construction of a complex object graph to perform piecemeal database commits, upon return from flushChanges the exPOJO transaction depth is restored to its previous value saving the developer from having to save/restore the transaction depth explicitly.
Saturday, September 15, 2007
It now makes dependency injection even easier to use. Simply configure the ExpojoServletFilter in your web.xml and voila!! Too easy.
For the lovers of the highly productive "exposed POJO domain model" pattern you will find the latest version of POJO irresistable.
Read more and download here.
Saturday, July 14, 2007
The exposed model was implemented using exPOJOs JPOX/JDO wrapper (a Hibernate wrapper is also available) as their transparent persistence solution. JPOX was chosen because it provides virtually 100% transparent persistence at the domain model level and has a significant performance edge due to its ability to perform build time byte code enhancement instead of relying on much slower run time reflection to do its job. The domain model objects are all pure POJOs without any need for annotations or the need to add extra methods to enable the underlying ORM to function correctly.
All domain models are designed and maintained using the light weight, high productivity, Javelin Modeler/Coder which automatically generates all necessary JPOX meta data files based on the information available in Javelin's UML style class diagrams (Hibernate meta data generation is also supported in Javelin)
If you want to try out persisting your POJOs without the massive learning curve or XML configuration nightmare required by Spring et al then you should give exPOJO a try.