Package com.j_spaces.sadapter.datasource
Class DataStorage<T>
java.lang.Object
com.j_spaces.sadapter.datasource.DataStorage<T>
- All Implemented Interfaces:
BulkDataPersister,DataPersister<T>,DataProvider<T>,ManagedDataSource<T>,SQLDataProvider<T>
public class DataStorage<T>
extends Object
implements DataProvider<T>, SQLDataProvider<T>, DataPersister<T>, BulkDataPersister, ManagedDataSource<T>
Data Storage is a delegator over user defined data source-interface implementation.
Operations defined by each interface are delegated to the implementation - only if it exists.
DataStorage supports both space API and the JCache API
- Since:
- 6.0
- Version:
- 1.0
- Author:
- anna
-
Field Summary
Fields inherited from interface com.gigaspaces.datasource.ManagedDataSource
NUMBER_OF_PARTITIONS, STATIC_PARTITION_NUMBER -
Constructor Summary
ConstructorsConstructorDescriptionDataStorage(Object store) DataStorage instantiation of cache and space data interfaces implementation, -
Method Summary
Modifier and TypeMethodDescriptionvoidexecuteBulk(List<BulkItem> bulk) Execute given bulk of operations.
EachBulkItemcontains one of the following operation -
WRITE - given object should be inserted to the data store,
UPDATE - given object should be updated in the data store,
REMOVE - given object should be deleted from the data store
If the implementation uses transactions,
all the bulk operations must be executed in one transaction.voidinit(Properties configuration) Initialize and configure the data source using given properties.
Called when space is started.
The properties are loaded from a file that can be defined in the space schema or as a property named:
space-config.ExternalDataSource.properties-file partitionId and number of partitions are also in the Properties - can be read with STATIC_PARTITION_NUMBER and NUMBER_OF_PARTITIONSCreates and returns an iterator over all the entries that should be loaded into space.booleanbooleanbooleanbooleanbooleanReturns true is the underlying data source doesn't support data changesbooleanCreate an iterator over all objects that match the givenSQLQuery.Create an iterator over all objects that match the given template.
Note: null value can be passed - in case of a null template or at initial space load.Read one object that matches the given template.voidRemove the given object from the data storevoidsetManagedDataSource(ManagedDataSource<T> managedDataSource) Override the internal managed data source Method is synchronized to force the thread to flush its memoryvoidsetSQLDataProvider(SQLDataProvider<T> sqlDataProvider) Override the internal sql data provider Method is synchronized to force the thread to flush its memoryvoidshutdown()Close the data source and clean any used resources.
Called before space shutdown.voidUpdate the given object in the data storevoidWrite given new object to the data storevoidwriteBatch(List<T> objects) Write given new objects to the data store.
If the implementation uses transactions,
all the objects must be written in one transaction.
-
Constructor Details
-
DataStorage
DataStorage instantiation of cache and space data interfaces implementation,- Parameters:
store- The data source instance
-
-
Method Details
-
isDataProvider
public boolean isDataProvider()- Returns:
trueif DataStorage implementsDataProvider;falseotherwise.
-
isDataPersister
public boolean isDataPersister()- Returns:
trueif DataStorage implementsDataPersister;falseotherwise.
-
isSQLDataProvider
public boolean isSQLDataProvider()- Returns:
trueif DataStorage implements SQLDataProvider;falseotherwise.
-
isBulkDataPersister
public boolean isBulkDataPersister()- Returns:
trueif DataStorage implementsBulkDataPersister;falseotherwise.
-
isManagedDataSource
public boolean isManagedDataSource()- Returns:
trueif DataStorage implementsManagedDataSource;falseotherwise.
-
read
Description copied from interface:DataProviderRead one object that matches the given template.
Used by the space for read templates with UID.- Specified by:
readin interfaceDataProvider<T>- Returns:
- matched object or null
- Throws:
DataSourceException
-
iterator
Description copied from interface:DataProviderCreate an iterator over all objects that match the given template.
Note: null value can be passed - in case of a null template or at initial space load. IfSQLDataProviderinterface is also implemented - the space will useSQLDataProvider.iterator instead.- Specified by:
iteratorin interfaceDataProvider<T>- Returns:
- a
DataIteratoror null if no data was found that match the given template - Throws:
DataSourceException
-
iterator
Description copied from interface:SQLDataProviderCreate an iterator over all objects that match the given
SQLQuery. 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);- Specified by:
iteratorin interfaceSQLDataProvider<T>- Returns:
- a
DataIteratoror null if no data was found that match the given template - Throws:
DataSourceException
-
remove
Description copied from interface:DataPersisterRemove the given object from the data store- Specified by:
removein interfaceDataPersister<T>- Throws:
DataSourceException
-
update
Description copied from interface:DataPersisterUpdate the given object in the data store- Specified by:
updatein interfaceDataPersister<T>- Throws:
DataSourceException
-
write
Description copied from interface:DataPersisterWrite given new object to the data store- Specified by:
writein interfaceDataPersister<T>- Throws:
DataSourceException
-
writeBatch
Description copied from interface:DataPersisterWrite given new objects to the data store.
If the implementation uses transactions,
all the objects must be written in one transaction.- Specified by:
writeBatchin interfaceDataPersister<T>- Throws:
DataSourceException
-
executeBulk
Description copied from interface:BulkDataPersisterExecute given bulk of operations.
EachBulkItemcontains one of the following operation -
WRITE - given object should be inserted to the data store,
UPDATE - given object should be updated in the data store,
REMOVE - given object should be deleted from the data store
If the implementation uses transactions,
all the bulk operations must be executed in one transaction.- Specified by:
executeBulkin interfaceBulkDataPersister- Parameters:
bulk- list of data object and the operation to apply on that object- Throws:
DataSourceException- when the data store fails to persist the given list of objects
-
init
Description copied from interface:ManagedDataSourceInitialize and configure the data source using given properties.
Called when space is started.
The properties are loaded from a file that can be defined in the space schema or as a property named:
space-config.ExternalDataSource.properties-file partitionId and number of partitions are also in the Properties - can be read with STATIC_PARTITION_NUMBER and NUMBER_OF_PARTITIONS- Specified by:
initin interfaceManagedDataSource<T>- Parameters:
configuration- - contains user defined param and Partition data- Throws:
DataSourceException
-
shutdown
Description copied from interface:ManagedDataSourceClose the data source and clean any used resources.
Called before space shutdown.- Specified by:
shutdownin interfaceManagedDataSource<T>- Throws:
DataSourceException
-
isReadOnly
public boolean isReadOnly()Returns true is the underlying data source doesn't support data changes- Returns:
- true if Data Storage is read elsy, esle return false
-
initialLoad
Description copied from interface:ManagedDataSourceCreates and returns an iterator over all the entries that should be loaded into space.- Specified by:
initialLoadin interfaceManagedDataSource<T>- Returns:
- a
DataIteratoror null if no data should be loaded into space - Throws:
DataSourceException
-
setSQLDataProvider
Override the internal sql data provider Method is synchronized to force the thread to flush its memory -
setManagedDataSource
Override the internal managed data source Method is synchronized to force the thread to flush its memory
-