public interface PersistingElement extends Comparable<PersistingElement>, Serializable
SimpleStore.
To make a class persisting, do not implement this interface, but rather declare the annotation Persisting.Persisting| Modifier and Type | Field and Description |
|---|---|
static Class<?>[] |
PossiblePropertyTypes
The list of possible types for simple properties (including keys).
|
static long |
serialVersionUID |
| Modifier and Type | Method and Description |
|---|---|
void |
activate(String... families)
Retrieves information from the store and put it into this persisting element.
|
void |
activateColumnFamily(String name)
Activates a given column family (does not activate included persisting elements).
|
void |
activateColumnFamily(String name,
Object from,
Object to)
Activates a given column family (does not activate included persisting elements).
|
void |
activateColumnFamilyIfNotAlready(String name)
Activates a given column family (does not activate included persisting elements) in case it was not done before (with any possible activation method).
|
void |
activateColumnFamilyIfNotAlready(String name,
long lastActivationTimeoutMs)
Activates a given column family (does not activate included persisting elements) in case it was not done before (with any possible activation method).
|
void |
activateColumnFamilyIfNotAlready(String name,
long lastActivationTimeoutMs,
Object from,
Object to)
Activates a given column family (does not activate included persisting elements) in case it was not done before (with any possible activation method).
|
void |
activateColumnFamilyIfNotAlready(String name,
Object from,
Object to)
Activates a given column family (does not activate included persisting elements) in case it was not done before (with any possible activation method).
|
void |
activateIfNotAlready(long lastActivationTimeoutMs,
String... families)
Retrieves information that have not been activated yet from the store and put it into this persisting element.
|
void |
activateIfNotAlready(String... families)
Retrieves information that have not been activated yet from the store and put it into this persisting element.
|
void |
addPersistingElementListener(PersistingElementListener listener)
Adds a listener to this persisting element.
|
int |
compareTo(PersistingElement rhs)
If instanciated classes are different, class names are compared, in the other case, the result of
getIdentifier() are compared. |
void |
delete()
Deletes rows representing this persisting element in the store.
|
void |
deleteNoCache()
Deletes rows representing this persisting element in the store.
|
boolean |
equals(Object rhs)
To be equal, two persisting elements must implement the same class and have the same identifier, no matter they have same values for properties and column families.
|
boolean |
exists()
Checks whether the row representing this persisting element is known to exist in the store avoiding as much as possible to query the data store.
|
boolean |
existsInStore()
Checks whether the row representing this persisting element exists in the store.
|
void |
flush()
Flushes any outgoing request pending on a
write-retention store. |
PersistingElement |
getCachedVersion()
If an element with the same id as this element exists in the cache, returns the element from the cache, otherwise returns this element which will be placed in the cache.
|
Collection<ColumnFamily<?>> |
getColumnFamilies()
The list of all
ColumnFamily held by this persisting element. |
ColumnFamily<?> |
getColumnFamily(Object collection)
The the
ColumnFamily held by this persisting element corresponding to the object stored by the object as a column family. |
ColumnFamily<?> |
getColumnFamily(String columnFamilyName)
The the
ColumnFamily held by this persisting element with the given name. |
String |
getFullIdentifier()
Same result as
getIdentifier(), but postfixed with the name of the class instanciated by this persisting element. |
String |
getIdentifier()
The identifier for this persisting element.
|
List<Field> |
getKeys()
The list of keys for this persisting element.
|
com.googlecode.n_orm.PropertyManagement.PropertyFamily |
getPropertiesColumnFamily()
The
ColumnFamily used to store properties. |
Store |
getStore()
The store used for this persisting element.
|
String |
getTable()
The table used to store this persisting element as declared by the
Persisting.table() annotation. |
boolean |
hasChanged()
Checks whether this persisting has changed since its last activation.
|
int |
hashCode()
The hash code for
getIdentifier(). |
void |
removePersistingElementListener(PersistingElementListener listener)
Removes a listener to this persisting element.
|
void |
setStore(Store store)
Sets the store used for this persisting element.
|
void |
store()
Stores the object into the data store designated by
getStore(). |
void |
storeNoCache()
Store this persisting element as
store() but ignoring any write cache. |
static final long serialVersionUID
static final Class<?>[] PossiblePropertyTypes
Store getStore()
void setStore(Store store) throws IllegalStateException
store - the store to be usedIllegalStateException - in case this persisting element already has a storePersistingString getTable()
Persisting.table() annotation.
If the persisting element inherits another persisting element, only the table for the instanciated class is shown.List<Field> getKeys()
Key.
The result is sorted in the order declared by Key.order().com.googlecode.n_orm.PropertyManagement.PropertyFamily getPropertiesColumnFamily()
ColumnFamily used to store properties.
A property is a non static, non final, non transient field whose type is one of PossiblePropertyTypes plus persisting elements plus classes with only key properties and no column family, plus arrays of such types.
Keys are also readable from this family.
The values stored in this column families are the last activated.activate(String...)Collection<ColumnFamily<?>> getColumnFamilies()
ColumnFamily held by this persisting element.ColumnFamily<?> getColumnFamily(String columnFamilyName) throws UnknownColumnFamily
ColumnFamily held by this persisting element with the given name.
The name is the name of the property for the column family, i.e. the non static, non final , non transient Map or Set field.UnknownColumnFamilyColumnFamily.getName()ColumnFamily<?> getColumnFamily(Object collection) throws UnknownColumnFamily
ColumnFamily held by this persisting element corresponding to the object stored by the object as a column family.
Typical use is myPe.getColumnFamily(myPe.myCf)collection - the value for the property stored as a column family.UnknownColumnFamilyString getIdentifier()
KeyManagement.KEY_SEPARATOR.
Moreover, the identifier ends with KeyManagement.KEY_END_SEPARATOR.IllegalStateException - in case all keys have not been setConversionTools.convertToString(Object)String getFullIdentifier()
getIdentifier(), but postfixed with the name of the class instanciated by this persisting element.Object.getClass()boolean hasChanged()
store() will not trigger any data store request.activate(String...)void store()
throws DatabaseNotReachedException
getStore().
All non static final or transient fields will be stored into the datastore.
All keys have to be set before invoking this operation
This object is stored as a row in table designated by getTable() using the key computed from getIdentifier().
Properties are stored in a column family whose name is given by PropertyManagement.PROPERTY_COLUMNFAMILY_NAME.
Column families are stored using their own name (see getColumnFamily(String)), that is the name of the Map or Set fields.
Properties and column families which have not changed since last activation of this element are not sent to the store as they are supposed to be already stored.
In case this persisting element inherits another persisting element class, a row with the full identifier is created in the tables for the ancestor class (see Persisting.table()).
Properties and column families are not stored in those rows unless stated by the Persisting.storeAlsoInSuperClasses() annotation in the actual class of this persisting element.
To choose a store, you need to supply in the classpath a properties file depending on the nature of the data store you want to use.
This property file is to be found in the class path. For a persisting element of a class in package foo.bar, the property file is searched as foo/bar/store.propetries in the complete classpath (in the declared order), then as foo/store.properties, and then directly store.properties.
To know how to define the properties file, please refer to your data store supplier. An (naive) example is the Memory data store.
WARNING: any column family change would raise a ConcurrentModificationException during this period in case application is multi-threaded and this element is explicitly shared by threads.
In the latter case, the store is retried at most 0.5s per problematic column family.
Simplest solution is to search this element in each thread using StorageManagement.getElement(Class, String).
A cleaner mean to solve this issue store calls should be performed within a synchronized section on this or on changed column family:
synchronized(element.myFamily) { //or merely synchronized(element)
element.myFamily.add(something);
}
Another way to avoid such problem is to use an instance of ColumnFamily as a column family (but then this cannot be serialized):
@Persisting class Foo {
...
public java.util.Map <BarK,BarV > element = new MapColumnFamily();
}
DatabaseNotReachedException - in case the store cannot store this persisting object (e.g. cannot connect to database)getIdentifier(),
SimpleStorevoid storeNoCache()
throws DatabaseNotReachedException
store() but ignoring any write cache.
Actually, in case this element has a write cache, request is still sent to the cache, but then flushed immediately so that previous requests regarding this element are merged and sent.DatabaseNotReachedExceptionvoid delete()
throws DatabaseNotReachedException
DatabaseNotReachedExceptionstore()void deleteNoCache()
throws DatabaseNotReachedException
DatabaseNotReachedExceptionstore()PersistingElement getCachedVersion()
exists(), activateIfNotAlready(String...), activateColumnFamilyIfNotAlready(String), or activateColumnFamilyIfNotAlready(String, Object, Object).
@Persisting public class Element {
@Key private String key;
@Key publi Element(String key) {
this.key = key;
}
}
Element elt = new Element("key").getCachedVersion();Cacheboolean exists()
throws DatabaseNotReachedException
exists() or existsInStore() returned true.
A persisting element is said not to exist if it has never been stored, if it has been unsuccessfully activated (i.e. the data store didn't return any information about the element), or if a previous invocation of exists() or existsInStore() returned false.
In other situations, the data store is queried using existsInStore().DatabaseNotReachedExceptiongetCachedVersion()boolean existsInStore()
throws DatabaseNotReachedException
DatabaseNotReachedExceptionstore()void activate(String... families) throws DatabaseNotReachedException
ImplicitActivation are also activated.
Use activateIfNotAlready(String...) in case you want to avoid re-activating already activated elements of this persisting elements.families - names of the families to activate even if they are not annotated with ImplicitActivation (see getColumnFamily(String))IllegalArgumentException - in case a given column family does not existsDatabaseNotReachedExceptionvoid activateIfNotAlready(String... families) throws DatabaseNotReachedException
activateColumnFamily(String, Object, Object)) will not be activated.
This means that if a constraint were passed at a previous activation time, it will be preserved.families - names of the families to activate even if they are not annotated with ImplicitActivation (see getColumnFamily(String))IllegalArgumentException - in case a given column family does not existsDatabaseNotReachedExceptiongetCachedVersion()void activateIfNotAlready(long lastActivationTimeoutMs,
String... families)
throws DatabaseNotReachedException
activateColumnFamily(String, Object, Object)) will not be activated.
This means that if a constraint were passed at a previous activation time, it will be preserved.families - names of the families to activate even if they are not annotated with ImplicitActivation (see getColumnFamily(String))lastActivationTimeoutMs - the maximum duration (in ms) at which last actual activation was performed. E.g. if last activation happened at 12:00 and method is called at 12:10 while this parameter is set to 3600000 (1 min), activation will happen anyway ; if parameter is set to 40000000, activation will not be performedIllegalArgumentException - in case a given column family does not existsDatabaseNotReachedExceptiongetCachedVersion()void activateColumnFamily(String name) throws UnknownColumnFamily, DatabaseNotReachedException
name - name of the column familyUnknownColumnFamily - in case this column family does not existDatabaseNotReachedExceptiongetColumnFamily(String)void activateColumnFamily(String name, Object from, Object to) throws UnknownColumnFamily, DatabaseNotReachedException
name - name of the column familyfrom - the minimal (inclusive) value for the activation (a key for a Map column family or a value for a Set column family)to - the maximal (inclusive) value for the activation (a key for a Map column family or a value for a Set column family)UnknownColumnFamily - in case this column family does not existDatabaseNotReachedExceptiongetColumnFamily(String)void activateColumnFamilyIfNotAlready(String name) throws UnknownColumnFamily, DatabaseNotReachedException
activateColumnFamily(String, Object, Object) or activateColumnFamilyIfNotAlready(String, Object, Object).name - name of the column familyUnknownColumnFamily - in case this column family does not existDatabaseNotReachedExceptiongetColumnFamily(String),
getCachedVersion()void activateColumnFamilyIfNotAlready(String name, long lastActivationTimeoutMs) throws UnknownColumnFamily, DatabaseNotReachedException
activateColumnFamily(String, Object, Object) or activateColumnFamilyIfNotAlready(String, Object, Object).lastActivationTimeoutMs - the maximum duration (in ms) at which last actual activation was performed. E.g. if last activation happened at 12:00 and method is called at 12:10 while this parameter is set to 3600000 (1 min), activation will happen anyway ; if parameter is set to 40000000, activation will not be performedname - name of the column familyUnknownColumnFamily - in case this column family does not existDatabaseNotReachedExceptiongetColumnFamily(String),
getCachedVersion()void activateColumnFamilyIfNotAlready(String name, Object from, Object to) throws UnknownColumnFamily, DatabaseNotReachedException
activateColumnFamily(String, Object, Object) or activateColumnFamilyIfNotAlready(String, Object, Object).name - name of the column familyfrom - the minimal (inclusive) value for the activation (a key for a Map column family or a value for a Set column family)to - the maximal (inclusive) value for the activation (a key for a Map column family or a value for a Set column family)UnknownColumnFamily - in case this column family does not existDatabaseNotReachedExceptiongetColumnFamily(String),
getCachedVersion()void activateColumnFamilyIfNotAlready(String name, long lastActivationTimeoutMs, Object from, Object to) throws UnknownColumnFamily, DatabaseNotReachedException
activateColumnFamily(String, Object, Object) or activateColumnFamilyIfNotAlready(String, Object, Object).lastActivationTimeoutMs - the maximum duration (in ms) at which last actual activation was performed. E.g. if last activation happened at 12:00 and method is called at 12:10 while this parameter is set to 3600000 (1 min), activation will happen anyway ; if parameter is set to 40000000, activation will not be performedname - name of the column familyfrom - the minimal (inclusive) value for the activation (a key for a Map column family or a value for a Set column family)to - the maximal (inclusive) value for the activation (a key for a Map column family or a value for a Set column family)UnknownColumnFamily - in case this column family does not existDatabaseNotReachedExceptiongetColumnFamily(String),
getCachedVersion()void flush()
write-retention store.boolean equals(Object rhs)
equals in class ObjectObject.equals(Object)int hashCode()
getIdentifier().
This method make possible to use persisting elements in Hashtables, HashMaps or HashSets.hashCode in class ObjectObject.hashCode()int compareTo(PersistingElement rhs)
getIdentifier() are compared.
This method make possible to use persisting elements in TreeMaps or TreeSets.compareTo in interface Comparable<PersistingElement>Comparable.compareTo(Object)void addPersistingElementListener(PersistingElementListener listener)
void removePersistingElementListener(PersistingElementListener listener)
Copyright © 2016. All Rights Reserved.