Simulate @CompassContext in JEE

@CompassContext is a great feature when using Spring. It allows for simplification when using Compass API within a transactional context (like Spring managed transactions). If your application uses a different managed environment, like JEE, the @CompassContext session injection can still be simulated.

If we take JEE environment as an example, usually the Compass instance would be registered under JNDI. In order to create a CompassSession that will simplify its usage under managed environment, all that needs to be done is:

compassSession = CompassSessionTransactionalProxy.newProxy(compass);

Where compassSession is probably a class level instance (since it does not make sense to proxy CompassSession each time). Note, it is perfectly fine for CompassSession to be a class level instance, and the proxy will take cate of creating ones correctly based on the transaction context.

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>