public class JPAStorageService extends AbstractStorageService
StorageService
that uses JPA to persist to a database.Constructor and Description |
---|
JPAStorageService(javax.persistence.EntityManagerFactory factory)
Creates a new JPA storage service.
|
Modifier and Type | Method and Description |
---|---|
boolean |
create(String context,
String key,
String value,
Long expiration)
Creates a new record in the store with an expiration.
|
boolean |
delete(String context,
String key)
Deletes an existing record from the store.
|
void |
deleteContext(String context)
Forcibly removes all records in a given context along with any
associated resources devoted to maintaining the context.
|
protected void |
deleteContextImpl(String context,
Long expiration)
Deletes every record with the supplied context.
|
protected boolean |
deleteImpl(Long version,
String context,
String key)
Deletes the record matching the supplied parameters.
|
boolean |
deleteWithVersion(long version,
String context,
String key)
Deletes an existing record from the store if it currently has a specified version.
|
protected void |
doDestroy() |
protected TimerTask |
getCleanupTask()
Returns a cleanup task function to schedule for background cleanup.
|
int |
getTransactionRetry()
Returns the number of times a transaction will be retried if a
RollbackException is encountered. |
StorageRecord |
read(String context,
String key)
Returns an existing record from the store, if one exists.
|
net.shibboleth.utilities.java.support.collection.Pair<Long,StorageRecord> |
read(String context,
String key,
long version)
Returns an existing record from the store, along with its version.
|
List<StorageRecord> |
readAll()
Returns all records from the store.
|
List<StorageRecord> |
readAll(String context)
Returns all records from the store for the supplied context.
|
List<String> |
readContexts()
Returns all contexts from the store.
|
protected net.shibboleth.utilities.java.support.collection.Pair<Long,StorageRecord> |
readImpl(String context,
String key,
Long version)
Reads the record matching the supplied parameters.
|
void |
reap(String context)
Manually trigger a cleanup of expired records.
|
void |
setTransactionRetry(int retry)
Sets the number of times a transaction will be retried.
|
boolean |
update(String context,
String key,
String value,
Long expiration)
Updates an existing record in the store.
|
void |
updateContextExpiration(String context,
Long expiration)
Updates the expiration time of all records in the context.
|
boolean |
updateExpiration(String context,
String key,
Long expiration)
Updates expiration of an existing record in the store.
|
protected Long |
updateImpl(Long version,
String context,
String key,
String value,
Long expiration)
Updates the record matching the supplied parameters.
|
Long |
updateWithVersion(long version,
String context,
String key,
String value,
Long expiration)
Updates an existing record in the store, if a version matches.
|
create, create, delete, deleteWithVersion, doInitialize, getCapabilities, getCleanupInterval, getCleanupTaskTimer, getContextSize, getKeySize, getValueSize, read, setCleanupInterval, setCleanupTaskTimer, setContextSize, setKeySize, setValueSize, update, update, updateExpiration, updateWithVersion, updateWithVersion
setId
getId
destroy, initialize, isDestroyed, isInitialized
public JPAStorageService(@Nonnull javax.persistence.EntityManagerFactory factory)
factory
- entity manager factorypublic int getTransactionRetry()
RollbackException
is encountered.public void setTransactionRetry(int retry)
retry
- number of transaction retriesprotected void doDestroy()
doDestroy
in class AbstractStorageService
public boolean create(@Nonnull @NotEmpty String context, @Nonnull @NotEmpty String key, @Nonnull @NotEmpty String value, @Nullable @Positive Long expiration) throws IOException
context
- a storage context labelkey
- a key unique to contextvalue
- value to storeexpiration
- expiration for record, or nullIOException
- if fatal errors occur in the insertion process@Nonnull @NonnullElements public List<StorageRecord> readAll() throws IOException
IOException
- if errors occur in the read process@Nonnull @NonnullElements public List<StorageRecord> readAll(@Nonnull @NotEmpty String context) throws IOException
context
- a storage context labelIOException
- if errors occur in the read process@Nonnull @NonnullElements public List<String> readContexts() throws IOException
IOException
- if errors occur in the read process@Nullable public StorageRecord read(@Nonnull @NotEmpty String context, @Nonnull @NotEmpty String key) throws IOException
context
- a storage context labelkey
- a key unique to contextIOException
- if errors occur in the read process@Nonnull public net.shibboleth.utilities.java.support.collection.Pair<Long,StorageRecord> read(@Nonnull @NotEmpty String context, @Nonnull @NotEmpty String key, @Positive long version) throws IOException
The first member of the pair returned will contain the version of the record in the store, or will be null if no record exists. The second member will contain the record read back. If null, the record either didn't exist (if the first member was also null) or the record was the same version as that supplied by the caller.
context
- a storage context labelkey
- a key unique to contextversion
- only return record if newer than supplied versionIOException
- if errors occur in the read process@Nonnull protected net.shibboleth.utilities.java.support.collection.Pair<Long,StorageRecord> readImpl(@Nonnull @NotEmpty String context, @Nonnull @NotEmpty String key, @Positive Long version) throws IOException
context
- to search forkey
- to search forversion
- to matchIOException
- if errors occur in the read processpublic boolean update(@Nonnull @NotEmpty String context, @Nonnull @NotEmpty String key, @Nonnull @NotEmpty String value, @Nullable @Positive Long expiration) throws IOException
context
- a storage context labelkey
- a key unique to contextvalue
- updated valueexpiration
- expiration for record, or nullIOException
- if errors occur in the update process@Nullable public Long updateWithVersion(@Positive long version, @Nonnull @NotEmpty String context, @Nonnull @NotEmpty String key, @Nonnull @NotEmpty String value, @Nullable @Positive Long expiration) throws IOException, VersionMismatchException
version
- only update if the current version matches this valuecontext
- a storage context labelkey
- a key unique to contextvalue
- updated valueexpiration
- expiration for record, or nullIOException
- if errors occur in the update processVersionMismatchException
- if the record has already been updated to a newer versionpublic boolean updateExpiration(@Nonnull @NotEmpty String context, @Nonnull @NotEmpty String key, @Nullable @Positive Long expiration) throws IOException
context
- a storage context labelkey
- a key unique to contextexpiration
- expiration for record, or nullIOException
- if errors occur in the update process@Nullable protected Long updateImpl(@Nullable Long version, @Nonnull @NotEmpty String context, @Nonnull @NotEmpty String key, @Nonnull @NotEmpty String value, @Nullable @Positive Long expiration) throws IOException, VersionMismatchException
version
- to checkcontext
- to search forkey
- to search forvalue
- to updateexpiration
- to updateIOException
- if errors occur in the update processVersionMismatchException
- if the record found contains a version that does not match the parameterpublic boolean deleteWithVersion(@Positive long version, @Nonnull @NotEmpty String context, @Nonnull @NotEmpty String key) throws IOException, VersionMismatchException
version
- record version to deletecontext
- a storage context labelkey
- a key unique to contextIOException
- if errors occur in the deletion processVersionMismatchException
- if the record has already been updated to a newer versionpublic boolean delete(@Nonnull @NotEmpty String context, @Nonnull @NotEmpty String key) throws IOException
context
- a storage context labelkey
- a key unique to contextIOException
- if errors occur in the deletion processprotected boolean deleteImpl(@Nullable @Positive Long version, @Nonnull @NotEmpty String context, @Nonnull @NotEmpty String key) throws IOException, VersionMismatchException
version
- to checkcontext
- to search forkey
- to search forIOException
- if errors occur in the delete processVersionMismatchException
- if the record found contains a version that does not match the parameterpublic void updateContextExpiration(@Nonnull @NotEmpty String context, @Nullable @Positive Long expiration) throws IOException
context
- a storage context labelexpiration
- a new expiration timestamp, or nullIOException
- if errors occur in the cleanup processpublic void deleteContext(@Nonnull @NotEmpty String context) throws IOException
context
- a storage context labelIOException
- if errors occur in the cleanup processpublic void reap(@Nonnull @NotEmpty String context) throws IOException
context
- a storage context labelIOException
- if errors occur in the cleanup processprotected void deleteContextImpl(@Nonnull @NotEmpty String context, @Nonnull Long expiration) throws IOException
context
- to deleteexpiration
- (optional) to require for deletionIOException
- if errors occur in the delete process@Nullable protected TimerTask getCleanupTask()
The default implementation does not supply one.
getCleanupTask
in class AbstractStorageService
Copyright © 2018. All rights reserved.