| 
 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.gigaspaces.datasource.hibernate.HibernateDataSource
public class HibernateDataSource
HibernateDataSource is a full Hibernate implementation of space external data source. Changing data - when space data is written/taken/removed/updated HibernateDataSource is responsible to perform the relevant changes at the external database. HibernateDataSource delegates these changes into external database via Hibernate 3.0 ORM. Reading data - when the space is queried about specific data and it is not found in the space HibernateDataSource is called to load the data from the database.DataProvideris used for data read.DataPersisteris used for write/update/remove Bulk operations - in case of transactions and replication will invoke theBulkDataPersistermethods for persisting data. Complex queries against the space -SQLQueryandExternalEntrymatching will invoke theSQLDataProvidermethods. See theDataProvider,DataPersister,SQLDataProviderandBulkDataPersisterfor full description of the methods mapping between the Space API and theHibernateDataSourcemethods.
Configuration To use theHibernateDataSourcethe space schema XML configuration file should include the following. <space-config> <persistent> <enabled>true</enabled> <StorageAdapterClass>com.gigaspaces.datasource.DataAdapter</StorageAdapterClass> </persistent> <external-data-source> <data-source-class>com.gigaspaces.datasource.hibernate.HibernateDataSource</data-source-class> <data-class>java.lang.Object</data-class> <supports-inheritance>true</supports-inheritance> <supports-version>false</supports-version> <usage>read-write</usage> </external-data-source> <engine> <cache_policy>0</cache_policy> </engine> </space-config> You may also use the following space properties: space-config.persistent.enabled=true<.b> space-config.persistent.StorageAdapterClass=com.j_spaces.sadapter.datasource.DataAdapter space-config.engine.cache_policy=0 space-config.external-data-source.data-source-class=com.gigaspaces.datasource.hibernate.HibernateDataSource space-config.external-data-source.init-properties-file=hibernate.properties When using theHibernateDataSourcethe space-config.external-data-source.init-properties the content of this file will be passed on init to theHibernateDataSource. You must use space-config.engine.cache_policy=0 (LRU policy) to activate the external datasource implementation. It is recommended to configure also the following to control the space memory usage and the eviction behavior: space-config.engine.memory_usage.enabled=true space-config.engine.memory_usage.high_watermark_percentage=95 space-config.engine.memory_usage.write_only_block_percentage=85 space-config.engine.memory_usage.write_only_check_percentage=76 space-config.engine.memory_usage.low_watermark_percentage=75 space-config.engine.memory_usage.eviction_batch_size=500
| Constructor Summary | |
|---|---|
| HibernateDataSource() | |
| Method Summary | |
|---|---|
|  int | count(Object template)Count number of object in the data source that match given template. | 
|  int | count(SQLQuery<Object> query)Count number of objects in the data source that match given query | 
|  void | executeBulk(List<BulkItem> bulk)This method is called in the following scenarios: 1. | 
|  void | init(Properties properties)Initialize and configure the data source using given properties. | 
|  DataIterator<Object> | initialLoad()
 Creates and returns an iterator over all the entries that should be loaded into space. | 
|  DataIterator<Object> | iterator(Object template)Create an iterator over all objects that match the given template. | 
|  DataIterator<Object> | iterator(SQLQuery<Object> query)Create an iterator over all objects that match the given SQLQuery. | 
|  Object | read(Object template)Read one object that matches the given template. | 
|  void | remove(Object object)Remove the given object from the data store | 
|  void | removeBatch(List<Object> objects)Remove given objects from the data store. | 
|  void | setDataClass(Class dataClass) | 
|  void | setSessionFactory(org.hibernate.SessionFactory _sessionFactory)Injects a Hibernate session factory into the data source to be used | 
|  void | shutdown()Close the data source and clean any used resources. | 
|  void | update(Object object)Update the given object in the data store | 
|  void | updateBatch(List<Object> objects)Update given objects in the data store. | 
|  void | write(Object object)Write given new object to the data store | 
|  void | writeBatch(List<Object> objects)Write given new objects to the data store. | 
| Methods inherited from class java.lang.Object | 
|---|
| equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait | 
| Constructor Detail | 
|---|
public HibernateDataSource()
| Method Detail | 
|---|
public void init(Properties properties)
          throws DataSourceException
ManagedDataSource
init in interface ManagedDataSource<Object>properties - - contains user defined param and Partition data
DataSourceExceptionpublic void setSessionFactory(org.hibernate.SessionFactory _sessionFactory)
public void setDataClass(Class dataClass)
public void shutdown()
              throws DataSourceException
ManagedDataSource
shutdown in interface ManagedDataSource<Object>DataSourceException
public Object read(Object template)
            throws DataSourceException
DataProvider
read in interface DataProvider<Object>DataSourceException
public void remove(Object object)
            throws DataSourceException
DataPersister
remove in interface DataPersister<Object>DataSourceException
public void update(Object object)
            throws DataSourceException
DataPersister
update in interface DataPersister<Object>DataSourceException
public void write(Object object)
           throws DataSourceException
DataPersister
write in interface DataPersister<Object>DataSourceException
public void writeBatch(List<Object> objects)
                throws DataSourceException
DataPersister
writeBatch in interface DataPersister<Object>DataSourceException
public void removeBatch(List<Object> objects)
                 throws DataSourceException
DataPersister
removeBatch in interface DataPersister<Object>DataSourceException
public void updateBatch(List<Object> objects)
                 throws DataSourceException
DataPersister
updateBatch in interface DataPersister<Object>DataSourceException
public void executeBulk(List<BulkItem> bulk)
                 throws DataSourceException
 1. Transaction commit 
 2. Asynchronize persistency mode This method can throw DataSourceException.
 This exception will be delivered to the client application wrapped by
 com.j_spaces.javax.cache.CacheException
executeBulk in interface BulkDataPersisterbulk - This bulkSet contains set of BulkItem
DataSourceException
public int count(Object template)
          throws DataSourceException
DataProvider
count in interface DataProvider<Object>DataSourceException
public DataIterator<Object> iterator(Object template)
                              throws DataSourceException
DataProvider
iterator in interface DataProvider<Object>DataIterator or null if no data was found that match the given template
DataSourceException
public int count(SQLQuery<Object> query)
          throws DataSourceException
SQLDataProvider
count in interface SQLDataProvider<Object>DataSourceException
public DataIterator<Object> iterator(SQLQuery<Object> query)
                              throws DataSourceException
SQLDataProviderCreate an iterator over all objects that match the givenSQLQuery. SQLQuery contains a string representation of SQL 'where' clause. The format matches thePreparedStatementformat(field1 = ? and field2 > ? and ....). The prepared values are accessible bySQLQuery.getPreparedValues() method Example implementation with SQL PreparedStatement:PreparedStatement st = con.prepareStatement(query.getSelectAllQuery()); int index = 0; if(query.hasPreparedValues()) { for(Iterator iter = query.getPreparedValues().iterator();iter.hasNext()) { st.setObject(++index,iter.next()); } } ResultSet rs = st.executeQuery(); return new ResultSetIterator(rs);
iterator in interface SQLDataProvider<Object>DataIterator or null if no data was found that match the given template
DataSourceExceptionResultSetIterator
public DataIterator<Object> initialLoad()
                                 throws DataSourceException
ManagedDataSource
 Creates and returns an iterator over all the entries that should be loaded into space.
 
 
initialLoad in interface ManagedDataSource<Object>DataIterator or null if no data should be loaded into space
DataSourceException| 
 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||