public class DataStorage<T> extends Object implements DataProvider<T>, SQLDataProvider<T>, DataPersister<T>, BulkDataPersister, ManagedDataSource<T>
Operations defined by each interface are delegated to the implementation - only if it exists.
DataStorage
supports both space API and the JCache API
NUMBER_OF_PARTITIONS, STATIC_PARTITION_NUMBER
Constructor and Description |
---|
DataStorage(Object store)
DataStorage instantiation of cache and space data interfaces implementation,
|
Modifier and Type | Method and Description |
---|---|
void |
executeBulk(List<BulkItem> bulk)
Execute given bulk of operations.
Each BulkItem contains 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. |
void |
init(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_PARTITIONS |
DataIterator<T> |
initialLoad()
Creates and returns an iterator over all the entries that should be loaded into
space. |
boolean |
isBulkDataPersister() |
boolean |
isDataPersister() |
boolean |
isDataProvider() |
boolean |
isManagedDataSource() |
boolean |
isReadOnly()
Returns true is the underlying data source doesn't support data changes
|
boolean |
isSQLDataProvider() |
DataIterator<T> |
iterator(SQLQuery<T> query)
Create an iterator over all objects that match the given
SQLQuery . |
DataIterator<T> |
iterator(T template)
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. |
T |
read(T template)
Read one object that matches the given template.
|
void |
remove(T object)
Remove the given object from the data store
|
void |
setManagedDataSource(ManagedDataSource<T> managedDataSource)
Override the internal managed data source Method is synchronized to force the thread to flush
its memory
|
void |
setSQLDataProvider(SQLDataProvider<T> sqlDataProvider)
Override the internal sql data provider Method is synchronized to force the thread to flush
its memory
|
void |
shutdown()
Close the data source and clean any used resources.
Called before space shutdown. |
void |
update(T object)
Update the given object in the data store
|
void |
write(T object)
Write given new object to the data store
|
void |
writeBatch(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. |
public DataStorage(Object store)
store
- The data source instancepublic boolean isDataProvider()
true
if DataStorage implements DataProvider
; false
otherwise.public boolean isDataPersister()
true
if DataStorage implements DataPersister
; false
otherwise.public boolean isSQLDataProvider()
true
if DataStorage implements SQLDataProvider; false
otherwise.public boolean isBulkDataPersister()
true
if DataStorage implements BulkDataPersister
;
false
otherwise.public boolean isManagedDataSource()
true
if DataStorage implements ManagedDataSource
;
false
otherwise.public T read(T template) throws DataSourceException
DataProvider
read
in interface DataProvider<T>
DataSourceException
public DataIterator<T> iterator(T template) throws DataSourceException
DataProvider
SQLDataProvider
interface is also implemented - the space will use SQLDataProvider
.iterator instead.iterator
in interface DataProvider<T>
DataIterator
or null if no data was found that match the given templateDataSourceException
public DataIterator<T> iterator(SQLQuery<T> query) throws DataSourceException
SQLDataProvider
Create an iterator over all objects that match the givenSQLQuery
. SQLQuery contains a string representation of SQL 'where' clause. The format matches thePreparedStatement
format(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<T>
DataIterator
or null if no data was found that match the given templateDataSourceException
public void remove(T object) throws DataSourceException
DataPersister
remove
in interface DataPersister<T>
DataSourceException
public void update(T object) throws DataSourceException
DataPersister
update
in interface DataPersister<T>
DataSourceException
public void write(T object) throws DataSourceException
DataPersister
write
in interface DataPersister<T>
DataSourceException
public void writeBatch(List<T> objects) throws DataSourceException
DataPersister
writeBatch
in interface DataPersister<T>
DataSourceException
public void executeBulk(List<BulkItem> bulk) throws DataSourceException
BulkDataPersister
BulkItem
contains one of the following
operation -executeBulk
in interface BulkDataPersister
bulk
- list of data object and the operation to apply on that objectDataSourceException
- when the data store fails to persist the given list of objectspublic void init(Properties configuration) throws DataSourceException
ManagedDataSource
init
in interface ManagedDataSource<T>
configuration
- - contains user defined param and Partition dataDataSourceException
public void shutdown() throws DataSourceException
ManagedDataSource
shutdown
in interface ManagedDataSource<T>
DataSourceException
public boolean isReadOnly()
public DataIterator<T> initialLoad() throws DataSourceException
ManagedDataSource
Creates and returns an iterator over all the entries that should be loaded into
space.
initialLoad
in interface ManagedDataSource<T>
DataIterator
or null if no data should be loaded into spaceDataSourceException
public void setSQLDataProvider(SQLDataProvider<T> sqlDataProvider)
public void setManagedDataSource(ManagedDataSource<T> managedDataSource)
Copyright © GigaSpaces.