Summary: The default Hibernate implementation of the External Data Source.

Overview

GigaSpaces comes with a built in implementation of External Data Source, called the HibernateExternalDataSource. The HibernateExternalDataSource is a Hibernate implementation of the External Data Source interfaces. It allows a custom objects persistency using Hibernate mappings.

The HibernateExternalDataSource has 2 implemenations:

  • DefaultHibernateExternalDataSource - Based on Hibernate Session.
  • StatelessHibernateExternalDataSource - based on Hiberante StatelessSession. This implemenation is faster than the DefaultHibernateExternalDataSource, but it does not have first level cache, as well as does not performe any cascading operations (both in read operations as well as dirty operations).

The HibernateExternalDataSource used both with the Synchronous and the ASynchronous persistency modes.

Configuration

See below example for HibernateExternalDataSource that is configured having a Space connected to a central data source using Hibernate configuration files decorating the Space Classes:

Namespace
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
    <property name="driverClassName" value="org.hsqldb.jdbcDriver"/>
    <property name="url" value="jdbc:hsqldb:hsql://localhost:9001"/>
    <property name="username" value="sa"/>
    <property name="password" value=""/>
</bean>

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="dataSource" ref="dataSource"/>
    <property name="mappingResources">
        <list>
            <value>Person.hbm.xml</value>
        </list>
    </property>
    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect">org.hibernate.dialect.HSQLDialect</prop>
            <prop key="hibernate.cache.provider_class">org.hibernate.cache.NoCacheProvider</prop>
            <prop key="hibernate.cache.use_second_level_cache">false</prop>
            <prop key="hibernate.cache.use_query_cache">false</prop>
            <prop key="hibernate.hbm2ddl.auto">update</prop>
            <prop key="hibernate.jdbc.batch_size">50</prop>            
        </props>
    </property>
</bean>

<bean id="hibernateDataSource" class="org.openspaces.persistency.hibernate.DefaultHibernateExternalDataSource">
    <property name="sessionFactory" ref="sessionFactory"/>
    <property name="initialLoadChunkSize" value="2000"/>
</bean>

<os-core:space id="space" url="/./space" schema="persistent" external-data-source="hibernateDataSource">
    <os-core:properties>
        <props>
            <prop key="cluster-config.cache-loader.external-data-source">true</prop>
            <prop key="cluster-config.cache-loader.central-data-source">true</prop>
        </props>
    </os-core:properties>
</os-core:space>

Plain XML
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
    <property name="driverClassName" value="org.hsqldb.jdbcDriver"/>
    <property name="url" value="jdbc:hsqldb:hsql://localhost:9001"/>
    <property name="username" value="sa"/>
    <property name="password" value=""/>
</bean>

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="dataSource" ref="dataSource"/>
    <property name="mappingResources">
        <list>
            <value>Person.hbm.xml</value>
        </list>
    </property>
    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect">org.hibernate.dialect.HSQLDialect</prop>
            <prop key="hibernate.cache.provider_class">org.hibernate.cache.NoCacheProvider</prop>
            <prop key="hibernate.cache.use_second_level_cache">false</prop>
            <prop key="hibernate.cache.use_query_cache">false</prop>
            <prop key="hibernate.hbm2ddl.auto">update</prop>
            <prop key="hibernate.jdbc.batch_size">50</prop>
        </props>
    </property>
</bean>

<bean id="hibernateDataSource" class="org.openspaces.persistency.hibernate.HibernateExternalDataSource">
    <property name="sessionFactory" ref="sessionFactory"/>
    <property name="initialLoadChunkSize" value="2000"/>
</bean>

<bean id="space" class="org.openspaces.core.space.UrlSpaceFactoryBean">
    <property name="url" value="/./space" />
    <property name="scheam" value="persistent" />
    <property name="externalDataSource" ref="hibernateDataSource" />
    <property name="properties">
        <props>
            <prop key="cluster-config.cache-loader.external-data-source">true</prop>
            <prop key="cluster-config.cache-loader.central-data-source">true</prop>
        </props>
    </property>
</bean>

When using annotations to decorate the Space Classes the sessionFactory would have the following:

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
    <property name="dataSource" ref="dataSource"/>
    <property name="annotatedClasses">
        <list>
            <value>com.mycompany.app.common.Data</value>
        </list>
    </property>
    <property name="hibernateProperties">
        <props>
			....
        </props>
    </property>
</bean>

The external-data-source element within the persistent schema allows for further configuration of the external data source. The values can be injected using the properties tag within the Space tag using the "xpath" notation.

Properties

The Hibernate External Data Source includes the following properties:

Property Description Default
fetchSize Sets the fetch size that will be used when working with scrollable results. 100
initialLoadChunkSize By default, the initial load process will chunk large tables and will iterate over the table (entity) per chunk (concurrently). This setting allows to control the chunk size to split the table by. Batching can be disabled by setting -1 100,000
initialLoadEntries Sets a list of entries that will be used to perform the ManagedDataSource.initialLoad() operation. By default, will try and build a sensible list based on Hibernate meta data.
managedEntries Sets all the entries this Hibernate data source will work with. By default, will use Hibernate meta data API in order to get the list of all the given entities it handles. This list is used to filter out entities when performing all data source operations except for the ManagedDataSource.initialLoad() operation. Usually, there is no need to explicitly set this.  
sessionFactory Injects the Hibernate SessionFactory to be used with this external data source.  
initialLoadThreadPoolSize The initial load operation uses the ConcurrentMultiDataIterator. This property allows to control the thread pool size of the concurrent multi data iterator.Note, this usually will map one to one to the number of open connections / cursors against the database. 10
performOrderById When performing initial load, this flag indicates if the generated query will order to results by the id. true (as it most times results in better initial load performance).
useScrollableResultSet Controls if scrollable resultsets will be used with inital load operation. true
useMerge If set to true, will use Hibernate merge to perform the create/update, and will merge before calling delete. This might be required for complex mappings (depends on Hibernate) at the expense of slower performance. Available only for the DefaultHibernateExternalDataSource false

See example below:

<bean id="hibernateDataSource" class="org.openspaces.persistency.hibernate.HibernateExternalDataSource">
	<property name="sessionFactory" ref="sessionFactory"/>
	<property name="fetchSize" value="100"/>
	<property name="initialLoadChunkSize" value="2000"/>
	<property name="initialLoadEntries" value="myClass1,myClass2"/>
	<property name="managedEntries" value="myClass1,myClass2"/>
	<property name="initialLoadThreadPoolSize" value="10"/>
	<property name="performOrderById" value="true"/>
	<property name="useScrollableResultSet" value="true"/>
	<property name="useMerge" value="true"/>
</bean>
GigaSpaces.com - Legal Notice - 3rd Party Licenses - Site Map - API Docs - Forum - Downloads - Blog - White Papers - Contact Tech Writing - Gen. by Atlassian Confluence