OverviewGigaSpaces comes with a built in implementation of Space Persistency APIs for Hibernate. This implementation is an extension of the SpaceDataSource and SpaceSynchronizationEndpoint classes. The implementation allows a custom objects persistency using Hibernate mappings. There are two available implementations: Default Hibernate Space Persistency ImplementationDefaultHibernateSpaceDataSource and DefaultHibernateSpaceSynchronizationEndpoint based on Hibernate Session. Stateless Hibernate Space Persistency ImplementationStatelessHibernateSpaceDataSource and StatelessHibernateSpaceSynchronizationEndpoint based on Hiberante StatelessSession. This implementation is faster than the Default Hibernate Space Persistency Implementation, but it does not have first level cache, as well as does not perform any cascading operations (both in read operations as well as dirty operations). The Hibernate Space Persistency Implementation is used both with the Synchronous and the Asynchronous Persistency modes. ConfigurationSee below example for Hibernate Space Persistency 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="hibernateSpaceDataSource" class="org.openspaces.persistency.hibernate.DefaultHibernateSpaceDataSourceFactoryBean"> <property name="sessionFactory" ref="sessionFactory"/> <property name="initialLoadChunkSize" value="2000"/> </bean> <bean id="hibernateSpaceSpaceSynchronizationEndpoint" class="org.openspaces.persistency.hibernate.DefaultHibernateSpaceSynchronizationEndpointFactoryBean"> <property name="sessionFactory" ref="sessionFactory"/> </bean> <os-core:space id="space" url="/./space" schema="persistent" space-data-source="hibernateSpaceDataSource" space-sync-endpoint="hibernateSpaceSynchronizationEndpoint" /> <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="hibernateSpaceDataSource" class="org.openspaces.persistency.hibernate.DefaultHibernateSpaceDataSourceFactoryBean"> <property name="sessionFactory" ref="sessionFactory"/> <property name="initialLoadChunkSize" value="2000"/> </bean> <bean id="hibernateSpaceSpaceSynchronizationEndpoint" class="org.openspaces.persistency.hibernate.DefaultHibernateSpaceSynchronizationEndpointFactoryBean"> <property name="sessionFactory" ref="sessionFactory"/> </bean> <bean id="space" class="org.openspaces.core.space.UrlSpaceFactoryBean"> <property name="url" value="/./space" /> <property name="scheam" value="persistent" /> <property name="spaceDataSource" ref="hibernateSpaceDataSource" /> <property name="spaceSynchronizationEndpoint" ref="hibernateSpaceSynchronizationEndpoint" /> <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>
Here is an example for a Space Domain class with its Hibernate decorations. See the @SpaceId and the @SpaceRouting used to include the Space Class meta Data.
See the POJO Metadata for details about these decorations. package com.mycompany.app.common; import com.gigaspaces.annotation.pojo.SpaceClass; import com.gigaspaces.annotation.pojo.SpaceId; import com.gigaspaces.annotation.pojo.SpaceRouting; import javax.persistence.Entity; import javax.persistence.Table; import javax.persistence.Id; @Entity @Table(name="DATA") @SpaceClass public class Data { @Id private String id; private Long type; // need no arg constr public Data() {} @SpaceId(autoGenerate=false) public String getId() {return id;} public void setId(String id) {this.id = id;} @SpaceRouting public Long getType() {return type;} public void setType(Long type) {this.type = type;} ... } }
PropertiesThe Hibernate Space Persistency implementation includes the following properties:
See example below: <bean id="hibernateSpaceDataSource" class="org.openspaces.persistency.hibernate.DefaultHibernateSpaceDataSourceFactoryBean"> <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 |