Date: 2004-09-15T07:19:46
   Editor: JimmiDyson <[EMAIL PROTECTED]>
   Wiki: Jakarta HiveMind Wiki
   Page: HibernateSupport
   URL: http://wiki.apache.org/jakarta-hivemind/HibernateSupport

   no comment

New Page:

= Feature Enhancment Description =

-- JimmiDyson [[DateTime(2004-09-15T14:19:45Z)]]

Hibernate is one of the most widely used O/R persistence APIs used today. Its 
only common sense to provide services to support this software.

Session (as Hibernate calls a DB connection) management is a cross-cutting 
concern, as is transaction management, so !HiveMind can be utilised effectively 
to remove the need to write your own code for this.

= Proposed Solution =

Using Session proxy and !SessionFactory proxy services, a connection to the 
database can be established simply by retrieving the Session proxy from the 
Registry. The Session proxy can be written to support any model, and by 
implementing the correct interfaces, automatic closure of the session can be 
achieved when using the threaded (recommended) or pooled models. The 
!SessionFactory service would be a singleton, although multiple implementations 
of the !SessionFactoryProxy could be declared. This would enable the developer 
using the Hibernate services to open database connections to different 
databases, running on different servers.

The !SessionFactoryProxyFactory (horrible name...) would take as an optional 
parameter the path to a Hibernate config file. This would allow for multiple 
singleton !SessionFactoryProxies to be declared, referencing different 
databases.

The !SessionProxyFactory would require the appropriate !SessionFactoryProxy to 
be set-serviced in the construct element.

The hivemodule.xml would contain the following:

{{{<service-point id="HibernateExceptionCoordinator" 
interface="org.apache.hivemind.hibernate.HibernateExceptionCoordinator">
        Used to coordinate propogation of Hibernate exceptions.
        <create-instance 
class="org.apache.hivemind.hibernate.impl.HibernateExceptionCoordinatorImpl" 
model="primitive"/>
</service-point>
<service-point id="SessionFactoryProxyFactory" 
interface="org.apache.hivemind.ServiceImplementationFactory">
        Core service implementation factory that constructs dynamic proxies to 
Hibernate SessionFactory factories.
        <parameters-schema>
                <element name="construct">
                        Specifies parameters needed to construct the 
SessionFactory Proxy.    
                        <attribute name="config-file" required="false">
                                The path to the hibernate config file.
                        </attribute>
                        <conversion 
class="org.apache.hivemind.hibernate.impl.SessionFactoryProxyParameters">
                                <map attribute="config-file" 
property="configFile"/>
                        </conversion>
                </element>
        </parameters-schema>
        <invoke-factory service-id="hivemind.BuilderFactory">
                <construct 
class="org.apache.hivemind.hibernate.impl.SessionFactoryProxyFactory">
                        <set-service property="classFactory" 
service-id="hivemind.ClassFactory"/>
                        <set-service property="coordinator" 
service-id="HibernateExceptionCoordinator"/>
                </construct>
        </invoke-factory>
</service-point>
<service-point id="SessionFactoryProxy" 
interface="net.sf.hibernate.SessionFactory">
        This is the actual session factory proxy service.
        <invoke-factory service-id="SessionFactoryProxyFactory" 
model="singleton"/>
</service-point>
<service-point id="SessionProxyFactory" 
interface="org.apache.hivemind.ServiceImplementationFactory">
        Core service implementation factory that constructs dynamic proxies to 
Hibernate Session factories.
        <invoke-factory service-id="hivemind.BuilderFactory">
                <construct 
class="org.apache.hivemind.hibernate.impl.SessionProxyFactory">
                        <set-service property="classFactory" 
service-id="hivemind.ClassFactory"/>
                        <set-service property="coordinator" 
service-id="HibernateExceptionCoordinator"/>
                        <set-service property="sessionFactory" 
service-id="SessionFactoryProxy"/>
                </construct>
        </invoke-factory>
</service-point>
<service-point id="SessionProxy" interface="net.sf.hibernate.Session">
        This is the actual session proxy service.
        <invoke-factory service-id="SessionProxyFactory" model="threaded"/>
</service-point>}}}

This would then be used to get the database Session (already opened) just like 
getting any other service:

{{{Session s = (Session) reg.getService("SessionProxy",Session.class);}}}

Need to think more about the !TransactionInterceptor - any ideas would be very 
welcome. 

Another solution to the Hibernate support is to use the !ThreadLocalStorage and 
a singleton !SessionSource to hold the Session for the thread. This could limit 
the end-developer to just one Session per thread, which is fine in most 
situations, but doesn't give the flexibility that should be given by using the 
Hibernate - !HiveMind combination.

= Discussion =


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to