Class SharedIteratorSQLDataProviderDecorator<T>
java.lang.Object
com.gigaspaces.datasource.concurrentaccess.SharedIteratorSQLDataProviderDecorator<T>
- All Implemented Interfaces:
ISharedDataIteratorSourceStateChangedListener<T>,ManagedDataSource<T>,SQLDataProvider<T>
public class SharedIteratorSQLDataProviderDecorator<T>
extends Object
implements SQLDataProvider<T>, ISharedDataIteratorSourceStateChangedListener<T>
Decorates a
SQLDataProvider with additional property, concurrent request for an iterator
which is based on the same query will only open one underlying iterator against the decorates
provider, this iterator will be shared amont the concurrent requests as if each of them has its
own iterator. the purpose is to reduce the load on the data source.- Since:
- 7.0
- Author:
- eitany
-
Field Summary
Fields inherited from interface com.gigaspaces.datasource.ManagedDataSource
NUMBER_OF_PARTITIONS, STATIC_PARTITION_NUMBER -
Constructor Summary
ConstructorsConstructorDescriptionSharedIteratorSQLDataProviderDecorator(SQLDataProvider<T> sqlDataProvider, long timeToLive) Create a new instance -
Method Summary
Modifier and TypeMethodDescriptionvoidinit(Properties prop) 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.Create an iterator over all objects that match the givenSQLQuery.voidonClosed(SharedDataIteratorSource<T> sender) Triggered when the iterator source is closedvoidonExpired(SharedDataIteratorSource<T> sender) Triggered when the iterator source is expiredvoidshutdown()Close the data source and clean any used resources.
Called before space shutdown.
-
Constructor Details
-
SharedIteratorSQLDataProviderDecorator
Create a new instance- Parameters:
sqlDataProvider- provider to decoratetimeToLive- liveness time of a created mediators, once this time expired this mediator will not be used for new iterator creations
-
-
Method Details
-
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
-
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:
prop- - contains user defined param and Partition data- Throws:
DataSourceException
-
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
-
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
-