public abstract class StorageContext extends AbstractContext
A context for persistent storage integrated with OSGi and
SecurityContext.
How the data is going to be stored (database, files) is implementation
dependent. But how the resources are structured (hierarchical, semantics)
is defined by the client implementing the StorageContext.Resource class.
class SemanticResource<T> extends SemanticEntity implements Resource<T> { ... } ... StorageContext ctx = StorageContext.enter(); // Enters the current storage service. try { // Stores resource. SemanticResource<Image> logoId = new SemanticResource<Image>( "http://purl.org/goodrelations/v1#Logo|MyCompany"); ctx.write(logoId, logoImg); // May raise SecurityException. ... // Retrieves resource. Image logoImg = ctx.read(logoId); // May raise SecurityException. } finally { ctx.exit(); }
Permission to read/write resource values may or not be granted at all
or only for particular resources. Sensitive data should always be
encrypted (e.g. using a SecuredStorageContext sub-class).
There is no limit in the size of the data being stored (except the actual
storage available). It is nonetheless recommended to split large data
set in smaller resources to allow for partial/concurrent retrieval.
| Modifier and Type | Class and Description |
|---|---|
static interface |
StorageContext.Resource<T>
A resource identifier.
|
| Modifier and Type | Field and Description |
|---|---|
static Configurable<File> |
FILE_STORAGE_LOCATION
Holds the default storage location for file based-implementations
(default
new File("storage")). |
| Modifier | Constructor and Description |
|---|---|
protected |
StorageContext()
Default constructor.
|
| Modifier and Type | Method and Description |
|---|---|
static StorageContext |
enter()
Enters and returns a storage context instance.
|
abstract <V extends Serializable> |
read(StorageContext.Resource<V> resource)
Reads the persistent value of the specified resource value.
|
abstract <V extends Serializable> |
write(StorageContext.Resource<V> resource,
V value)
Writes the persistent value of the specified resource.
|
current, current, enter, enterInner, exit, getOuter, inherit, innerpublic static final Configurable<File> FILE_STORAGE_LOCATION
new File("storage")).public static StorageContext enter()
public abstract <V extends Serializable> V read(StorageContext.Resource<V> resource) throws SecurityException
resource - the entity whose persistent value is returned.null if none.SecurityException - if the permission to read the resource
is not granted (new
Permission<Resource<V>>(Resource.class, "read", resource)).public abstract <V extends Serializable> void write(StorageContext.Resource<V> resource, V value) throws SecurityException
resource - the entity whose persistent value is stored.value - the persistent value.SecurityException - if the permission to write the resource
is not granted (new
Permission<Resource<V>>(Resource.class, "write", resource)).Copyright © 2017. All rights reserved.