public class SharedIteratorSQLDataProviderDecorator<T> extends Object implements SQLDataProvider<T>, ISharedDataIteratorSourceStateChangedListener<T>
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.NUMBER_OF_PARTITIONS, STATIC_PARTITION_NUMBER
Constructor and Description |
---|
SharedIteratorSQLDataProviderDecorator(SQLDataProvider<T> sqlDataProvider,
long timeToLive)
Create a new instance
|
Modifier and Type | Method and Description |
---|---|
void |
init(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_PARTITIONS |
DataIterator<T> |
initialLoad()
Creates and returns an iterator over all the entries that should be loaded into
space. |
DataIterator<T> |
iterator(SQLQuery<T> query)
Create an iterator over all objects that match the given
SQLQuery . |
void |
onClosed(SharedDataIteratorSource<T> sender)
Triggered when the iterator source is closed
|
void |
onExpired(SharedDataIteratorSource<T> sender)
Triggered when the iterator source is expired
|
void |
shutdown()
Close the data source and clean any used resources.
Called before space shutdown. |
public SharedIteratorSQLDataProviderDecorator(SQLDataProvider<T> sqlDataProvider, long timeToLive)
sqlDataProvider
- provider to decoratetimeToLive
- liveness time of a created mediators, once this time expired this
mediator will not be used for new iterator creationspublic 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 init(Properties prop) throws DataSourceException
ManagedDataSource
init
in interface ManagedDataSource<T>
prop
- - contains user defined param and Partition dataDataSourceException
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 shutdown() throws DataSourceException
ManagedDataSource
shutdown
in interface ManagedDataSource<T>
DataSourceException
public void onClosed(SharedDataIteratorSource<T> sender)
ISharedDataIteratorSourceStateChangedListener
onClosed
in interface ISharedDataIteratorSourceStateChangedListener<T>
sender
- shared data iterator source that triggered the eventpublic void onExpired(SharedDataIteratorSource<T> sender)
ISharedDataIteratorSourceStateChangedListener
onExpired
in interface ISharedDataIteratorSourceStateChangedListener<T>
sender
- shared data iterator source that triggered the eventCopyright © GigaSpaces.