public class JPAStorageService extends AbstractStorageService implements StorageCapabilitiesEx
StorageService that uses JPA to persist to a database.| Modifier and Type | Field and Description |
|---|---|
private EntityManagerFactory |
entityManagerFactory
Entity manager factory.
|
private Logger |
log
Class logger.
|
private int |
transactionRetry
Number of times to retry a transaction if it rolls back.
|
| Constructor and Description |
|---|
JPAStorageService(EntityManagerFactory factory)
Creates a new JPA storage service.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
create(String context,
String key,
String value,
Long expiration) |
boolean |
delete(String context,
String key) |
void |
deleteContext(String context) |
protected void |
deleteContextImpl(String context,
Long expiration)
Deletes every record with the supplied context.
|
protected void |
deleteImpl(Long expiration)
Deletes every record with an expiration before the supplied expiration.
|
protected boolean |
deleteImpl(Long version,
String context,
String key)
Deletes the record matching the supplied parameters.
|
boolean |
deleteWithVersion(long version,
String context,
String key) |
protected void |
doDestroy() |
private <T> List<T> |
executeNamedQuery(EntityManager manager,
String query,
Map<String,Object> params,
Class<T> clazz,
LockModeType lockMode)
Executes the supplied named query.
|
protected TimerTask |
getCleanupTask() |
int |
getTransactionRetry()
Returns the number of times a transaction will be retried if a
RollbackException is encountered. |
boolean |
isClustered() |
boolean |
isServerSide() |
StorageRecord |
read(String context,
String key) |
net.shibboleth.utilities.java.support.collection.Pair<Long,StorageRecord> |
read(String context,
String key,
long 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) |
void |
setTransactionRetry(int retry)
Sets the number of times a transaction will be retried.
|
boolean |
update(String context,
String key,
String value,
Long expiration) |
void |
updateContextExpiration(String context,
Long expiration) |
boolean |
updateExpiration(String context,
String key,
Long expiration) |
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) |
create, create, delete, deleteWithVersion, doInitialize, getCapabilities, getCleanupInterval, getCleanupTaskTimer, getContextSize, getKeySize, getValueSize, read, setCleanupInterval, setCleanupTaskTimer, setContextSize, setKeySize, setValueSize, update, update, updateExpiration, updateWithVersion, updateWithVersionsetIdgetIddestroy, initialize, isDestroyed, isInitializedclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetContextSize, getKeySize, getValueSize@Nonnull private final EntityManagerFactory entityManagerFactory
@NonNegative private int transactionRetry
public JPAStorageService(@Nonnull EntityManagerFactory factory)
factory - entity manager factorypublic int getTransactionRetry()
RollbackException is encountered.public void setTransactionRetry(int retry)
retry - number of transaction retriespublic boolean isServerSide()
isServerSide in interface StorageCapabilitiesExpublic boolean isClustered()
isClustered in interface StorageCapabilitiesExprotected void doDestroy()
doDestroy in class AbstractStorageServicepublic boolean create(@Nonnull@NotEmpty String context, @Nonnull@NotEmpty String key, @Nonnull@NotEmpty String value, @Nullable@Positive Long expiration) throws IOException
create in interface StorageServiceIOException@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
read in interface StorageServiceIOException@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
read in interface StorageServiceIOException@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
update in interface StorageServiceIOException@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
updateWithVersion in interface StorageServiceIOExceptionVersionMismatchExceptionpublic boolean updateExpiration(@Nonnull@NotEmpty String context, @Nonnull@NotEmpty String key, @Nullable@Positive Long expiration) throws IOException
updateExpiration in interface StorageServiceIOException@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
deleteWithVersion in interface StorageServiceIOExceptionVersionMismatchExceptionpublic boolean delete(@Nonnull@NotEmpty String context, @Nonnull@NotEmpty String key) throws IOException
delete in interface StorageServiceIOExceptionprotected 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
updateContextExpiration in interface StorageServiceIOExceptionpublic void deleteContext(@Nonnull@NotEmpty String context) throws IOException
deleteContext in interface StorageServiceIOExceptionpublic void reap(@Nonnull@NotEmpty String context) throws IOException
reap in interface StorageServiceIOExceptionprotected 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 processprotected void deleteImpl(@Nonnull Long expiration) throws IOException
expiration - of records to deleteIOException - if errors occur in the cleanup processprivate <T> List<T> executeNamedQuery(@Nonnull EntityManager manager, @Nonnull@NotEmpty String query, @Nonnull Map<String,Object> params, @Nonnull Class<T> clazz, @Nonnull LockModeType lockMode) throws IOException
T - type of entity to returnmanager - to execute the queryquery - to executeparams - parameters for the queryclazz - type of entity to returnlockMode - of the transactionIOException - if an error occurs executing the query@Nullable protected TimerTask getCleanupTask()
getCleanupTask in class AbstractStorageServiceCopyright © 1999–2016 Shibboleth Consortium. All rights reserved.