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:
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).
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:
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.
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 Support - Advanced 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
privateString id;
privateLong type;
// need no arg constr
public Data() {}
@SpaceId(autoGenerate=false)
publicString getId() {return id;}
public void setId(String id) {this.id = id;}
@SpaceRouting
publicLong getType() {return type;}
public void setType(Long type) {this.type = type;}
...
}
}
When mapping a Collection Data types or any other variable size field make sure the relevant database table column has a sufficient size that can accommodate the largest collection/variable size field you may have within your space object.
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
The initialLoadChunkSize property allows you to have multiple threads loading data from the same table into the space - each thread loading different rows from the same table. Having the initialLoadChunkSize as 100,000 will break a 1 million rows table into ten chunks. All the chunks, from all the tables, are processes by the amount of initialLoadThreadPoolSize configured.
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
Tuning the fetchSize, initialLoadChunkSize, initialLoadThreadPoolSize and performOrderById will allow you to control the initial load time. In addition, the StatelessHibernateExternalDataSource should give you better performance on startup.