Errai 3.0.1-SNAPSHOT

org.jboss.errai.jpa.client.local.backend
Class WebStorageBackend

java.lang.Object
  extended by org.jboss.errai.jpa.client.local.backend.WebStorageBackend
All Implemented Interfaces:
StorageBackend

public class WebStorageBackend
extends Object
implements StorageBackend

The storage backend for HTML WebStorage, a storage facility supported by most browsers for at least 2.5 million characters of data, (5 megabytes of Unicode text).

This backend supports namespacing, which is a way of dividing up the storage into any number of non-overlapping buckets. For any two namespaces A and B (A != B), the storage backend for namespace A will never see, modify, or otherwise or interfere with anything stored in the storage backend for namespace B.

Author:
Jonathan Fuerth

Field Summary
static StorageBackendFactory FACTORY
           
 
Constructor Summary
WebStorageBackend(ErraiEntityManager erraiEntityManager)
          Creates a WebStorageBackend that works with entities in the default storage namespace.
WebStorageBackend(ErraiEntityManager erraiEntityManager, String namespace)
          Creates a WebStorageBackend that works with entities in the given storage namespace.
 
Method Summary
<X,Y> boolean
contains(Key<X,Y> key)
          Tests if this backend contains data for the given key.
<X> X
get(Key<X,?> requestedKey)
          Retrieves the value most recently stored in this backend under the given key, reconnecting referenced objects by calling back up into the owning EntityManager.
<X> List<X>
getAll(ErraiIdentifiableType<X> type, EntityJsonMatcher matcher)
          Returns all entities of the given type (and its subtypes) whose JSON representations are accepted by the given matcher.
<X> boolean
isModified(Key<X,?> key, X value)
          Checks if the value currently associated with key in this backend datastore is identical to the given one.
<X> void
put(Key<X,?> key, X value)
          Stores the given Errai-Marshalling-Capable value under the given key.
<X> void
remove(Key<X,?> key)
          Removes the key and its associated value (if any) from this storage backend.
 void removeAll()
          Removes all data from this storage backend.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FACTORY

public static final StorageBackendFactory FACTORY
Constructor Detail

WebStorageBackend

public WebStorageBackend(ErraiEntityManager erraiEntityManager)
Creates a WebStorageBackend that works with entities in the default storage namespace.

Parameters:
erraiEntityManager - the ErraiEntityManager this storage backend will be used with (it is used for resolving entity references).

WebStorageBackend

public WebStorageBackend(ErraiEntityManager erraiEntityManager,
                         String namespace)
Creates a WebStorageBackend that works with entities in the given storage namespace.

Parameters:
erraiEntityManager - the ErraiEntityManager this storage backend will be used with (it is used for resolving entity references).
namespace - The namespace to operate within. Must not be null.
Method Detail

removeAll

public void removeAll()
Description copied from interface: StorageBackend
Removes all data from this storage backend.

Specified by:
removeAll in interface StorageBackend

put

public <X> void put(Key<X,?> key,
                    X value)
Description copied from interface: StorageBackend
Stores the given Errai-Marshalling-Capable value under the given key. A pre-existing value under the same key (if any) is silently replaced by the new one.

Specified by:
put in interface StorageBackend
Type Parameters:
X - The entity's Java type
Parameters:
key - The identity of the entry in the storage backend. Null is not permitted.
value - The value to store. Must be marshallable using Errai Marshalling. Null is not permitted; use StorageBackend.remove(Key) to remove an entity from this data store.

get

public <X> X get(Key<X,?> requestedKey)
Description copied from interface: StorageBackend
Retrieves the value most recently stored in this backend under the given key, reconnecting referenced objects by calling back up into the owning EntityManager.

Note that this operation is not a good method for testing if the backend contains a given object, because of the potentially wide-reaching side effects caused by recursively resolving the entity references in the object being retrieved. To test if the backend contains an object for a particular key, use StorageBackend.contains(Key).

Specified by:
get in interface StorageBackend
Type Parameters:
X - The entity's Java type
Parameters:
requestedKey - The identity of the object to be retrieved. The actual entity returned may be a subtype of the type specified in the key. Null is not permitted.
Returns:
The retrieved object, reconstituted from its backend (serialized) representation, including references to other objects. Return value is null if there is no value presently associated with key.

getAll

public <X> List<X> getAll(ErraiIdentifiableType<X> type,
                          EntityJsonMatcher matcher)
Description copied from interface: StorageBackend
Returns all entities of the given type (and its subtypes) whose JSON representations are accepted by the given matcher.

Specified by:
getAll in interface StorageBackend
Parameters:
type - The type of entities to retrieve
matcher - The matcher that decides which entity instances will be retrieved.
Returns:
all matching entities of the given type.

contains

public <X,Y> boolean contains(Key<X,Y> key)
Description copied from interface: StorageBackend
Tests if this backend contains data for the given key. As with StorageBackend.get(Key), subtypes are taken into account. If this backend contains an entity with the same ID as the given key and the same type or a subtype of the type specified in the key, this method will return true.

Specified by:
contains in interface StorageBackend
Parameters:
key - The identity of the object to be tested for. Null is not permitted.
Returns:
True if the backend contains the entity instance associated with the given key, and false otherwise.

remove

public <X> void remove(Key<X,?> key)
Description copied from interface: StorageBackend
Removes the key and its associated value (if any) from this storage backend. If the key is not present in this backend, this method returns normally and has no effect.

Specified by:
remove in interface StorageBackend
Type Parameters:
X - The entity's Java type
Parameters:
key - The identity of the object to be removed. Null is not permitted.

isModified

public <X> boolean isModified(Key<X,?> key,
                              X value)
Description copied from interface: StorageBackend
Checks if the value currently associated with key in this backend datastore is identical to the given one. For the purposes of this method, two values are considered identical if their serialized representation is the same. This method does not check for equality using the equals() method of value.

Specified by:
isModified in interface StorageBackend
Type Parameters:
X - The entity's Java type
Parameters:
key - The identity of the object to be removed. Null is not permitted.
value - The value to check. Must be marshallable using Errai Marshalling.

Errai 3.0.1-SNAPSHOT

Copyright © 2013-2014 JBoss, a division of Red Hat. All Rights Reserved.