I've been doing the exact same thing ... creating wrappers around Kodo JDO.
Our JDO logic was already encapsulated in a couple of classes, which I
easily turned into HiveMind services.
I created a new HiveMind service, JDOTransactionManager. It's job is
to provide a KodoPersistenceManager to the other services.
The code in the other services have a JDOTransactionManager injected
in, and can get the persistence manager by invoking
getPersistenceManager() on it.
Note: my original take was to create a projection of the
JDOTransactionManager's persisteceManager property as a seperate
service, using the hivemind.lib.ServicePropertyFactory.
Unfortunately, HIVEMIND-76 got in the way.
Anyway, the JDOTransactionManager ensures that a transaction is begun
when it is activated (typically, the first time the PM is accessed).
It also commits any outstanding transacton at the end of the request
cycle.
I put together a TransactionInterceptor that can selectively
commitAndResume after certain operations (those that update the
database). It also forces the transaction to rollback only if an
unchecked exception is thrown.
The JDOTransactionManager gets its PM's from a
KodoPersistenceManagerSource, which is a wrapper around
PersistenceManagerFactory.
So, my solution is very similar to yours.
I think, in terms of parameterizing this better, it will be a case of
when Knut and/or Harish adds Groovy scripting support for creating
module descriptors. A little Groovy script could do wonders there!
On Tue, 9 Nov 2004 16:07:58 +1100, Tom Davies <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I've just started playing with creating my first HiveMind services, to
> create JDO persistence managers and what I have ended up with is shown
> below.
>
> My questions are:
>
> 1. I'd like to avoid the pattern where my service implementation looks like:
>
> FooImpl(...)
> {
> create a Foo using a third-party factory
> }
>
> Foo get()
> {
> return the Foo
> }
>
> I'd rather have a service who's type is Foo, but Foo may be a concrete
> type (e.g. I'd like a properties service, but Properties is concrete)
> or may be a third-party interface which needs a bit of code to
> instantiate (i.e. more than just passing some parameters to a
> constructor) -- PersistenceManagerFactory is an example of this.
>
> Can I get rid of the 'get()' above?
>
> 2. Can I parameterise services? In this example I need three services
> for each data source. It would be nice if I could declare the
> PersistenceManagerFactory and PersistenceManager services once, and
> have the declarations of the various PM services pass them parameters.
>
> Or maybe I don't need todo these things -- I'm still getting to grips
> with the HiveMind philosophy.
>
> Thanks,
> Tom
>
> <?xml version="1.0"?>
> <module id="au.com.ids.hivemind" version="1.0.0">
> <!-- create a persistence manager factory using the properties
> file name passed to the constructor -->
> <service-point
> id="PersistenceManagerFactory"
>
> interface="au.com.ids.services.PersistenceManagerFactoryService">
> <invoke-factory>
> <construct
> class="au.com.ids.services.impls.PersistenceManagerFactoryServiceImpl">
> <string>kodo.properties</string>
> </construct>
> </invoke-factory>
> </service-point>
>
> <!-- create a persistence manager using the PM factory service above.
> Implement Discardable to close the PM appropriately -->
> <service-point id="PersistenceManager"
> interface="au.com.ids.services.PersistenceManagerService">
> <invoke-factory model="threaded">
> <construct
> class="au.com.ids.services.impls.PersistenceManagerServiceImpl">
> <service>PersistenceManagerFactory</service>
> </construct>
> </invoke-factory>
> </service-point>
>
> <!-- make the persistence manager easier to get by exposing the
> 'persistenceManager'
> property of the PM service above as a service in its own right -->
> <service-point id="PM" interface="javax.jdo.PersistenceManager">
> <invoke-factory
> service-id="hivemind.lib.ServicePropertyFactory">
> <construct service-id="PersistenceManager"
> property="persistenceManager"/>
> </invoke-factory>
> </service-point>
>
> </module>
>
> public class PersistenceManagerServiceImpl implements
> PersistenceManagerService, Discardable {
> public void threadDidDiscardService() {
> _pm.close();
> _pm = null;
> }
>
> private PersistenceManager _pm;
>
> public PersistenceManagerServiceImpl(
> PersistenceManagerFactoryService pmFactoryService) {
> _pm = pmFactoryService.get().getPersistenceManager();
> }
>
> public PersistenceManager getPersistenceManager() {
> return _pm;
> }
> }
>
> public class PersistenceManagerFactoryServiceImpl implements
> PersistenceManagerFactoryService {
>
> private PersistenceManagerFactory pmf = null;
>
> public PersistenceManagerFactoryServiceImpl(String propertiesFile) {
> Properties props = new Properties();
> InputStream propertyRes = Persistence.class.getClassLoader()
> .getResourceAsStream(propertiesFile);
> try {
> props.load(propertyRes);
> } catch (IOException ioe) {
> throw new RuntimeException("error loading properties '"
> + propertiesFile + "'", ioe);
> }
> pmf = JDOHelper.getPersistenceManagerFactory(props);
> }
>
> public PersistenceManagerFactory get() {
> return pmf;
> }
> }
>
> --
> [EMAIL PROTECTED]
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
--
Howard M. Lewis Ship
Independent J2EE / Open-Source Java Consultant
Creator, Jakarta Tapestry
Creator, Jakarta HiveMind
http://howardlewisship.com
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]