GigaSpaces XAP 7.0 API

org.openspaces.persistency.hibernate
Class AbstractHibernateExternalDataSource

java.lang.Object
  extended by org.openspaces.persistency.hibernate.AbstractHibernateExternalDataSource
All Implemented Interfaces:
ManagedDataSource, ManagedDataSourceEntriesProvider
Direct Known Subclasses:
DefaultHibernateExternalDataSource, StatelessHibernateExternalDataSource

public abstract class AbstractHibernateExternalDataSource
extends Object
implements ManagedDataSource, ManagedDataSourceEntriesProvider

A base class for Hibernate based external data source implementations.

See the different setters for more information and the init(java.util.Properties).

Author:
kimchy

Field Summary
static String HIBERNATE_CFG_PROPERTY
           
protected  Log logger
           
 
Constructor Summary
AbstractHibernateExternalDataSource()
           
 
Method Summary
protected  DataIterator createInitialLoadIterator(DataIterator[] iterators)
          A helper method that creates the initial load itertaor using the ConcurrentMultiDataIterator with the provided setInitialLoadThreadPoolSize(int) thread pool size.
protected  int getFetchSize()
          Returns the fetch size that will be used when working with scrollable results.
protected  int getInitialLoadChunkSize()
          By default, the initial load process will chunk large tables and will iterate over the table (entity) per chunk (concurrently).
 String[] getInitialLoadEntries()
          Returns a list of entries that will be used to perform the ManagedDataSource.initialLoad() operation.
 String[] getManagedEntries()
          Returns all the entries this Hibernate data source will work with.
 org.hibernate.SessionFactory getSessionFactory()
          Returns the Hibernate session factory.
 void init(Properties properties)
          Initializes the hibernate data source.
protected  boolean isManagedEntry(String entityName)
          Returns if the given entity name is part of the getManagedEntries() list.
protected  boolean isPerformOrderById()
          When performing initial load, this flag indicates if the generated query will order to results by the id.
protected  boolean isUseScrollableResultSet()
          Controls if scrollable resultsets will be used with inital load operation.
 void setFetchSize(int fetchSize)
          Sets the fetch size that will be used when working with scrollable results.
 void setInitialLoadChunkSize(int initalLoadChunkSize)
          By default, the initial load process will chunk large tables and will iterate over the table (entity) per chunk (concurrently).
 void setInitialLoadEntries(String... initialLoadEntries)
          Sets a list of entries that will be used to perform the ManagedDataSource.initialLoad() operation.
 void setInitialLoadThreadPoolSize(int initialLoadThreadPoolSize)
          The initial load operation uses the ConcurrentMultiDataIterator.
 void setManagedEntries(String... entries)
          Sets all the entries this Hibernate data source will work with.
 void setPerformOrderById(boolean performOrderById)
          When performing initial load, this flag indicates if the generated query will order to results by the id.
 void setSessionFactory(org.hibernate.SessionFactory sessionFactory)
          Injects the Hibernate SessionFactory to be used with this external data source.
 void setUseScrollableResultSet(boolean useScrollableResultSet)
          Controls if scrollable resultsets will be used with inital load operation.
 void shutdown()
          Shuts down the data source.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected final Log logger

HIBERNATE_CFG_PROPERTY

public static final String HIBERNATE_CFG_PROPERTY
See Also:
Constant Field Values
Constructor Detail

AbstractHibernateExternalDataSource

public AbstractHibernateExternalDataSource()
Method Detail

setSessionFactory

public void setSessionFactory(org.hibernate.SessionFactory sessionFactory)
Injects the Hibernate SessionFactory to be used with this external data source.


getSessionFactory

public org.hibernate.SessionFactory getSessionFactory()
Returns the Hibernate session factory.


setManagedEntries

public void setManagedEntries(String... entries)
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 exception for the ManagedDataSource.initialLoad() operation.

Usually, there is no need to explicitly set this.


getManagedEntries

public String[] getManagedEntries()
Returns all the entries this Hibernate data source will work with. By default, will use Hiberante 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 exception for the ManagedDataSource.initialLoad() operation.

Specified by:
getManagedEntries in interface ManagedDataSourceEntriesProvider

isManagedEntry

protected boolean isManagedEntry(String entityName)
Returns if the given entity name is part of the getManagedEntries() list.


setFetchSize

public void setFetchSize(int fetchSize)
Sets the fetch size that will be used when working with scrollable results. Defaults to 100.

See Also:
Criteria.setFetchSize(int)

getFetchSize

protected int getFetchSize()
Returns the fetch size that will be used when working with scrollable results. Defaults to 100.

See Also:
Criteria.setFetchSize(int)

setPerformOrderById

public void setPerformOrderById(boolean performOrderById)
When performing initial load, this flag indicates if the generated query will order to results by the id. By default set to true as it most times results in better initial load performance.


isPerformOrderById

protected boolean isPerformOrderById()
When performing initial load, this flag indicates if the generated query will order to results by the id. By default set to true as it most times results in better initial load performance.


setInitialLoadEntries

public void setInitialLoadEntries(String... 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.

Note, sometimes an explicit list should be provided. For example, if we have a class A and class B, and A has a relationship to B which is not component. If in the space, we only wish to have A, and have B just as a field in A (and not as an Entry), then we need to explciitly set the list just to A. By default, if we won't set it, it will result in two entries existing in the Space, A and B, with A having a field of B as well.


getInitialLoadEntries

public String[] getInitialLoadEntries()
Returns a list of entries that will be used to perform the ManagedDataSource.initialLoad() operation. By default, will try and build a sensible list basde on Hiberante meta data.

Note, sometimes an explicit list should be provided. For example, if we have a class A and class B, and A has a relationship to B which is not component. If in the space, we only wish to have A, and have B just as a field in A (and not as an Entry), then we need to explicitly set the list just to A. By default, if we won't set it, it will result in two entries existing in the Space, A and B, with A having a field of B as well.


setInitialLoadThreadPoolSize

public void setInitialLoadThreadPoolSize(int initialLoadThreadPoolSize)
The initial load operation uses the ConcurrentMultiDataIterator. This property allows to control the thread pool size of the concurrent multi data iterator. Defaults to 10.

Note, this usually will map one to one to the number of open connections / cursors against the database.


setInitialLoadChunkSize

public void setInitialLoadChunkSize(int initalLoadChunkSize)
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. By default, set to 100,000. Batching can be disabled by setting -1.


getInitialLoadChunkSize

protected int getInitialLoadChunkSize()
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. By default, set to 100,000. Batching can be disabled by setting -1.


isUseScrollableResultSet

protected boolean isUseScrollableResultSet()
Controls if scrollable resultsets will be used with inital load operation. Defaults to true.


setUseScrollableResultSet

public void setUseScrollableResultSet(boolean useScrollableResultSet)
Controls if scrollable resultsets will be used with inital load operation. Defaults to true.


init

public void init(Properties properties)
          throws DataSourceException
Initializes the hibernate data source. Called by the Space.

If the session factory was not injected using setSessionFactory(org.hibernate.SessionFactory), will try can create it from the Properties file expecting to find a property called hibernate-config-file with the location of the Hibernate config file.

Initializes the setManagedEntries(String[]) if they were not set explicitly by iterating over all the mapped classes in Hibernate and adding them.

Also initalizes the setInitialLoadEntries(String[]) if not set explicitly.

Specified by:
init in interface ManagedDataSource
Parameters:
properties - - contains user defined param and Partition data
Throws:
DataSourceException

shutdown

public void shutdown()
              throws DataSourceException
Shuts down the data source. If the session factory was created by this data source, will close it.

Specified by:
shutdown in interface ManagedDataSource
Throws:
DataSourceException

createInitialLoadIterator

protected DataIterator createInitialLoadIterator(DataIterator[] iterators)
A helper method that creates the initial load itertaor using the ConcurrentMultiDataIterator with the provided setInitialLoadThreadPoolSize(int) thread pool size.


GigaSpaces XAP 7.0 API

Copyright © GigaSpaces.