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

    Constructors
    Constructor
    Description
    DataStorage instantiation of cache and space data interfaces implementation,
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    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
    Creates and returns an iterator over all the entries that should be loaded into space.
    boolean
     
    boolean
     
    boolean
     
    boolean
     
    boolean
    Returns true is the underlying data source doesn't support data changes
    boolean
     
    Create an iterator over all objects that match the given SQLQuery.
    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.
    read(T template)
    Read one object that matches the given template.
    void
    remove(T object)
    Remove the given object from the data store
    void
    Override the internal managed data source Method is synchronized to force the thread to flush its memory
    void
    Override the internal sql data provider Method is synchronized to force the thread to flush its memory
    void
    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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • DataStorage

      public DataStorage(Object store)
      DataStorage instantiation of cache and space data interfaces implementation,
      Parameters:
      store - The data source instance
  • Method Details

    • isDataProvider

      public boolean isDataProvider()
      Returns:
      true if DataStorage implements DataProvider; false otherwise.
    • isDataPersister

      public boolean isDataPersister()
      Returns:
      true if DataStorage implements DataPersister; false otherwise.
    • isSQLDataProvider

      public boolean isSQLDataProvider()
      Returns:
      true if DataStorage implements SQLDataProvider; false otherwise.
    • isBulkDataPersister

      public boolean isBulkDataPersister()
      Returns:
      true if DataStorage implements BulkDataPersister; false otherwise.
    • isManagedDataSource

      public boolean isManagedDataSource()
      Returns:
      true if DataStorage implements ManagedDataSource; false otherwise.
    • read

      public T read(T template) throws DataSourceException
      Description copied from interface: DataProvider
      Read one object that matches the given template.
      Used by the space for read templates with UID.
      Specified by:
      read in interface DataProvider<T>
      Returns:
      matched object or null
      Throws:
      DataSourceException
    • iterator

      public DataIterator<T> iterator(T template) throws DataSourceException
      Description copied from interface: DataProvider
      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. If SQLDataProvider interface is also implemented - the space will use SQLDataProvider.iterator instead.
      Specified by:
      iterator in interface DataProvider<T>
      Returns:
      a DataIterator or null if no data was found that match the given template
      Throws:
      DataSourceException
    • iterator

      public DataIterator<T> iterator(SQLQuery<T> query) throws DataSourceException
      Description copied from interface: SQLDataProvider
       Create an iterator over all objects that match the given SQLQuery.
       SQLQuery contains a string representation of SQL 'where' clause.
       The format matches the PreparedStatement format(field1 = ? and field2 > ? and ....).
       The prepared values are accessible by SQLQuery.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:
      iterator in interface SQLDataProvider<T>
      Returns:
      a DataIterator or null if no data was found that match the given template
      Throws:
      DataSourceException
    • remove

      public void remove(T object) throws DataSourceException
      Description copied from interface: DataPersister
      Remove the given object from the data store
      Specified by:
      remove in interface DataPersister<T>
      Throws:
      DataSourceException
    • update

      public void update(T object) throws DataSourceException
      Description copied from interface: DataPersister
      Update the given object in the data store
      Specified by:
      update in interface DataPersister<T>
      Throws:
      DataSourceException
    • write

      public void write(T object) throws DataSourceException
      Description copied from interface: DataPersister
      Write given new object to the data store
      Specified by:
      write in interface DataPersister<T>
      Throws:
      DataSourceException
    • writeBatch

      public void writeBatch(List<T> objects) throws DataSourceException
      Description copied from interface: DataPersister
      Write given new objects to the data store.

      If the implementation uses transactions,
      all the objects must be written in one transaction.
      Specified by:
      writeBatch in interface DataPersister<T>
      Throws:
      DataSourceException
    • executeBulk

      public void executeBulk(List<BulkItem> bulk) throws DataSourceException
      Description copied from interface: BulkDataPersister
      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.
      Specified by:
      executeBulk in interface BulkDataPersister
      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

      public void init(Properties configuration) throws DataSourceException
      Description copied from interface: ManagedDataSource
      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
      Specified by:
      init in interface ManagedDataSource<T>
      Parameters:
      configuration - - contains user defined param and Partition data
      Throws:
      DataSourceException
    • shutdown

      public void shutdown() throws DataSourceException
      Description copied from interface: ManagedDataSource
      Close the data source and clean any used resources.
      Called before space shutdown.
      Specified by:
      shutdown in interface ManagedDataSource<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

      public DataIterator<T> initialLoad() throws DataSourceException
      Description copied from interface: ManagedDataSource
      Creates and returns an iterator over all the entries that should be loaded into space.
      Specified by:
      initialLoad in interface ManagedDataSource<T>
      Returns:
      a DataIterator or null if no data should be loaded into space
      Throws:
      DataSourceException
    • setSQLDataProvider

      public void setSQLDataProvider(SQLDataProvider<T> sqlDataProvider)
      Override the internal sql data provider Method is synchronized to force the thread to flush its memory
    • setManagedDataSource

      public void setManagedDataSource(ManagedDataSource<T> managedDataSource)
      Override the internal managed data source Method is synchronized to force the thread to flush its memory