com.gisgraphy.dao.spring
Class HibernateExtensionPostProcessor

java.lang.Object
  extended by com.gisgraphy.dao.spring.HibernateExtensionPostProcessor
All Implemented Interfaces:
org.springframework.beans.factory.config.BeanFactoryPostProcessor

public class HibernateExtensionPostProcessor
extends java.lang.Object
implements org.springframework.beans.factory.config.BeanFactoryPostProcessor

Adds Hibernate persistent class definitions to an existing Spring Session Factory bean, possibly defined within a separate Spring configuration file in a seprate jar file. By using this extension factory developers can add persistent classes to an AppFuse application without modifying any of the existing AppFuse Spring configuration or jar distribution files.

As an example consider the following Spring bean configuration:

 <bean class="com.gisgraphy.dao.spring.HibernateExtensionPostProcessor">
     <property name="mappingResources">
         <list>
             <value>com/gisgraphy/model/Foo.hbm.xml</value>
         </list>
     </property>
     <property name="annotatedClasses">
         <list>
             <value>com.gisgraphy.model.Bar</value>
         </list>
     </property>
 </bean>
 

The snippet will add two persistent classes to an existing Session Factory bean called "sessionFactory". Note that the extension can handle both annotated classes and the more traditional .hbm.xml files. Assuming that these persistent classes are packaged in a jar called extension.jar which contains the Spring configuration file applicationContext-dao.xml at the root level, then the standard AppFuse configuration will automatically pick up the new Spring configuration file and the new persistent classes will be added to the list already defined for the session factory bean configured within the standard appfuse-hibernate.jar file. And all this without needing to touch the original AppFuse configuration files!

Author:
Michael Horwitz

Constructor Summary
HibernateExtensionPostProcessor()
           
 
Method Summary
 void postProcessBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory configurableListableBeanFactory)
          Adds the annotated classes and the mapping resources to the existing Session Factory configuration.
 void setAnnotatedClasses(java.util.List annotatedClasses)
          The list of annotated classes to add to the session factory.
 void setConfigLocations(java.util.List configLocations)
          The list of configuration locations (i.e. classpath:hibernate.cfg.xml) to add to the session factory
 void setHibernateProperties(java.util.Properties hibernateProperties)
          Hibernate properties to add to the session factory.
 void setMappingResources(java.util.List mappingResources)
          Set the list of mapping resources (.hbm.xml files) to be added to the session factory.
 void setSessionFactoryBeanName(java.lang.String sessionFactoryBeanName)
          Set the name of the SessionFactory bean.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HibernateExtensionPostProcessor

public HibernateExtensionPostProcessor()
Method Detail

postProcessBeanFactory

public void postProcessBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory configurableListableBeanFactory)
Adds the annotated classes and the mapping resources to the existing Session Factory configuration.

Specified by:
postProcessBeanFactory in interface org.springframework.beans.factory.config.BeanFactoryPostProcessor
Parameters:
configurableListableBeanFactory - the good ol' bean factory

setSessionFactoryBeanName

public void setSessionFactoryBeanName(java.lang.String sessionFactoryBeanName)
Set the name of the SessionFactory bean. By default this post processor looks for a bean of name "sessionFactory"

Parameters:
sessionFactoryBeanName - The name of the session factory bean.

setMappingResources

public void setMappingResources(java.util.List mappingResources)
Set the list of mapping resources (.hbm.xml files) to be added to the session factory.

Parameters:
mappingResources - The list of mapping resources.

setAnnotatedClasses

public void setAnnotatedClasses(java.util.List annotatedClasses)
The list of annotated classes to add to the session factory.

Parameters:
annotatedClasses - The list of annotated classes that need to be added.

setConfigLocations

public void setConfigLocations(java.util.List configLocations)
The list of configuration locations (i.e. classpath:hibernate.cfg.xml) to add to the session factory

Parameters:
configLocations - The list of configuration locations that need to be added.

setHibernateProperties

public void setHibernateProperties(java.util.Properties hibernateProperties)
Hibernate properties to add to the session factory.

Parameters:
hibernateProperties - The list of additional properties.


Copyright © 2010. All Rights Reserved.