public class JdbcStringBasedStore extends Object implements org.infinispan.persistence.spi.AdvancedLoadWriteStore
AdvancedCacheLoader
implementation that stores the entries in a database. In contrast to the
JdbcBinaryStore
, this cache store will store each entry within a row
in the table (rather than grouping multiple entries into an row). This assures a finer grained granularity for all
operation, and better performance. In order to be able to store non-string keys, it relies on an Key2StringMapper
.
Note that only the keys are stored as strings, the values are still saved as binary data. Using a character
data type for the value column will result in unmarshalling errors.
The actual storage table is defined through configuration JdbcStringBasedStoreConfiguration
. The table can
be
created/dropped on-the-fly, at deployment time. For more details consult javadoc for JdbcStringBasedStoreConfiguration
.
It is recommended to use JdbcStringBasedStore
} over
JdbcBinaryStore
} whenever it is possible, as is has a better performance.
One scenario in which this is not possible to use it though, is when you can't write an Key2StringMapper
} to map the
keys to to string objects (e.g. when you don't have control over the types of the keys, for whatever reason).
Preload.In order to support preload functionality the store needs to read the string keys from the database and transform them
into the corresponding key objects. Key2StringMapper
only supports
key to string transformation(one way); in order to be able to use preload one needs to specify an
TwoWayKey2StringMapper
, which extends Key2StringMapper
and
allows bidirectional transformation.
Rehashing. When a node leaves/joins, Infinispan moves around persistent state as part of rehashing process.
For this it needs access to the underlaying key objects, so if distribution is used, the mapper needs to be an
TwoWayKey2StringMapper
otherwise the cache won't start (same constraint as with preloading).Key2StringMapper
,
DefaultTwoWayKey2StringMapper
Constructor and Description |
---|
JdbcStringBasedStore() |
Modifier and Type | Method and Description |
---|---|
void |
clear() |
boolean |
contains(Object key) |
boolean |
delete(Object key) |
ConnectionFactory |
getConnectionFactory() |
TableManager |
getTableManager() |
void |
init(org.infinispan.persistence.spi.InitializationContext ctx) |
void |
initializeConnectionFactory(ConnectionFactory connectionFactory)
Keeps a reference to the connection factory for further use.
|
boolean |
isDistributed() |
org.infinispan.marshall.core.MarshalledEntry |
load(Object key) |
void |
process(org.infinispan.filter.KeyFilter filter,
org.infinispan.persistence.spi.AdvancedCacheLoader.CacheLoaderTask task,
Executor executor,
boolean fetchValue,
boolean fetchMetadata) |
void |
purge(Executor executor,
org.infinispan.persistence.spi.AdvancedCacheWriter.PurgeListener task) |
int |
size() |
void |
start() |
void |
stop() |
boolean |
supportsKey(Class<?> keyType) |
void |
write(org.infinispan.marshall.core.MarshalledEntry entry) |
public void init(org.infinispan.persistence.spi.InitializationContext ctx)
init
in interface org.infinispan.persistence.spi.CacheLoader
init
in interface org.infinispan.persistence.spi.CacheWriter
public void start()
start
in interface org.infinispan.commons.api.Lifecycle
public void stop()
stop
in interface org.infinispan.commons.api.Lifecycle
public void write(org.infinispan.marshall.core.MarshalledEntry entry)
write
in interface org.infinispan.persistence.spi.CacheWriter
public org.infinispan.marshall.core.MarshalledEntry load(Object key)
load
in interface org.infinispan.persistence.spi.CacheLoader
public boolean delete(Object key)
delete
in interface org.infinispan.persistence.spi.CacheWriter
public void clear() throws org.infinispan.persistence.spi.PersistenceException
clear
in interface org.infinispan.persistence.spi.AdvancedCacheWriter
org.infinispan.persistence.spi.PersistenceException
public void purge(Executor executor, org.infinispan.persistence.spi.AdvancedCacheWriter.PurgeListener task)
purge
in interface org.infinispan.persistence.spi.AdvancedCacheWriter
public boolean contains(Object key)
contains
in interface org.infinispan.persistence.spi.CacheLoader
public void process(org.infinispan.filter.KeyFilter filter, org.infinispan.persistence.spi.AdvancedCacheLoader.CacheLoaderTask task, Executor executor, boolean fetchValue, boolean fetchMetadata)
process
in interface org.infinispan.persistence.spi.AdvancedCacheLoader
public int size()
size
in interface org.infinispan.persistence.spi.AdvancedCacheLoader
public boolean supportsKey(Class<?> keyType)
public void initializeConnectionFactory(ConnectionFactory connectionFactory) throws org.infinispan.persistence.spi.PersistenceException
TableManager
that needs connections. This method should be called when you don't
want the store to manage the connection factory, perhaps because it is using an shared connection factory: see
JdbcMixedStore
for such an example of this.org.infinispan.persistence.spi.PersistenceException
public ConnectionFactory getConnectionFactory()
public TableManager getTableManager()
public boolean isDistributed()
Copyright © 2018 JBoss, a division of Red Hat. All rights reserved.