|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
public interface Storable<S extends Storable<S>>
A data access object in a Repository. User defined storables must
either extend or implement this interface via an interface or abstract
class. Abstract bean properties defined in the storable are persisted into
the repository. At least one property must be annotated as the PrimaryKey. At most one property may be annotated as being the Version property.
Storable instances are mutable, but they must be thread-safe. Although race conditions are possible if multiple threads are mutating the Storable, the Storable instance will not get into a corrupt state.
Alias,
Indexes,
Join,
Nullable,
PrimaryKey,
Version| Method Summary | |
|---|---|
S |
copy()
Returns an exact shallow copy of this object, including the state. |
void |
copyAllProperties(S target)
Copies all supported properties, skipping any that are uninitialized. |
void |
copyDirtyProperties(S target)
Copies all supported non-primary key properties which are dirty. |
void |
copyPrimaryKeyProperties(S target)
Copies all supported primary key properties, skipping any that are uninitialized. |
void |
copyUnequalProperties(S target)
Copies all supported non-primary key properties which are unequal, skipping any that are uninitialized. |
void |
copyVersionProperty(S target)
Copies the optional version property, unless it is uninitialized. |
void |
delete()
Deletes this object from the storage layer by its primary key, regardless of whether this object has actually been loaded or not. |
boolean |
equalPrimaryKeys(Object obj)
True if the supported properties which participate in the primary key are equal. |
boolean |
equalProperties(Object obj)
True if all supported properties for this object are equal. |
boolean |
equals(Object obj)
True if all properties and fields are equal, but ignoring the state. |
Object |
getPropertyValue(String propertyName)
Returns a Storable property value by name. |
boolean |
hasDirtyProperties()
Returns true if any non-primary key properties in this object are dirty. |
int |
hashCode()
|
void |
insert()
Inserts a new persistent value for this object. |
boolean |
isPropertyClean(String propertyName)
Returns true if the given property of this Storable is clean. |
boolean |
isPropertyDirty(String propertyName)
Returns true if the given property of this Storable has been set, but no load or store operation has been performed yet. |
boolean |
isPropertySupported(String propertyName)
Returns true if the given property exists and is supported. |
boolean |
isPropertyUninitialized(String propertyName)
Returns true if the given property of this Storable has never been loaded or set. |
void |
load()
Loads or reloads this object from the storage layer by a primary or alternate key. |
void |
markAllPropertiesClean()
Marks all properties as clean, including uninitialized properties. |
void |
markAllPropertiesDirty()
Marks all properties as dirty, including uninitialized properties. |
void |
markPropertiesClean()
Marks all dirty properties as clean. |
void |
markPropertiesDirty()
Marks all clean properties as dirty. |
S |
prepare()
Prepares a new object for loading, inserting, updating, or deleting. |
Map<String,Object> |
propertyMap()
Returns a fixed-size map view of this Storable's properties. |
void |
readFrom(InputStream in)
Restores property values and states as encoded by writeTo(java.io.OutputStream). |
void |
setPropertyValue(String propertyName,
Object value)
Sets a Storable property value by name. |
Class<S> |
storableType()
Returns the class or interface from which this storable was generated. |
String |
toString()
Returns a string for debugging purposes that contains all supported property names and values for this object. |
String |
toStringKeyOnly()
Returns a string for debugging purposes that contains supported key property names and values for this object. |
boolean |
tryDelete()
Deletes this object from the storage layer by its primary key, regardless of whether this object has actually been loaded or not. |
boolean |
tryInsert()
Inserts a new persistent value for this object. |
boolean |
tryLoad()
Loads or reloads this object from the storage layer by a primary or alternate key. |
boolean |
tryUpdate()
Updates the persistent value of this object, regardless of whether this object has actually been loaded or not. |
void |
update()
Updates the persistent value of this object, regardless of whether this object has actually been loaded or not. |
void |
writeTo(OutputStream out)
Serializes property values and states for temporary storage or for network transfer. |
| Method Detail |
|---|
void load()
throws FetchNoneException,
FetchException
If load is successful, altering the primary key is no longer allowed
unless a call to delete succeeds. Attempting to alter the primary key in
this state results in an IllegalStateException. Alternate keys
may always be modified, however.
Note: This method differs from tryLoad() only in that it
throws an exception if no matching record was found, instead of returning
false. This may indicate that the underlying record was deleted between
a load and reload. When a FetchNoneException is thrown, this object's
state will be the same as if the delete method was called on it.
FetchNoneException - if no matching record found
FetchException - if storage layer throws an exception
IllegalStateException - if the state of this instance suggests
that any primary keys are unspecified
boolean tryLoad()
throws FetchException
If load is successful, altering the primary key is no longer allowed
unless a call to delete succeeds. Attempting to alter the primary key in
this state results in an IllegalStateException. Alternate keys
may always be modified, however.
Note: This method differs from load() only in that it returns
false if no matching record was found, instead of throwing an exception.
This may indicate that the underlying record was deleted between a load
and reload. When false is returned, this object's state will be the same
as if the delete method was called on it.
FetchException - if storage layer throws an exception
IllegalStateException - if the state of this instance suggests
that any primary keys are unspecified
void insert()
throws PersistException
IllegalStateException. Alternate keys may always be modified, however.
Insert requires that all primary key properties be specified. If not,
an IllegalStateException is thrown. Also, repository
implementations usually require that properties which are not Nullable also be specified. Otherwise, a ConstraintException
may be thrown.
Note: This method differs from tryInsert() only in that it may
throw a UniqueConstraintException, instead of returning false.
UniqueConstraintException - if it is absolutely known that a key
of inserted object matches an existing one
ConstraintException - if any required properties are unspecified
PersistException - if storage layer throws an exception
IllegalStateException - if the state of this instance suggests
that any primary keys are unspecified
boolean tryInsert()
throws PersistException
IllegalStateException. Alternate keys may always be modified, however.
Insert requires that all primary key properties be specified. If not,
an IllegalStateException is thrown. Also, repository
implementations usually require that properties which are not Nullable also be specified. Otherwise, a ConstraintException
may be thrown.
Note: This method differs from insert() only in that it
returns false, instead of throwing a UniqueConstraintException.
ConstraintException - if any required properties are unspecified
PersistException - if storage layer throws an exception
IllegalStateException - if the state of this instance suggests
that any primary keys are unspecified
void update()
throws PersistException
IllegalStateException. Alternate keys may always be modified, however.
If this object has a version property defined, then
the update logic is a bit more strict. Updates of any storable require
that the primary keys be specified; if a version is present, the version
must be specified as well. If any of the primary key or version
properties are unspecified, an IllegalStateException will be
thrown; if they are fully specified and the version doesn't match the
current record, an OptimisticLockException is thrown.
Not all properties need to be set on this object when calling update. Setting a subset results in a partial update. After a successful update, all properties are set to the actual values in the storage layer. Put another way, the object is automatically reloaded after a successful update.
If PersistNoneException is thrown, this indicates that the underlying record was deleted. When this happens, this object's state will be the same as if the delete method was called on it.
PersistNoneException - if record is missing and no update occurred
PersistException - if storage layer throws an exception
OptimisticLockException - if a version property exists and the
optimistic lock failed
IllegalStateException - if the state of this instance suggests
that any primary keys are unspecified, or if a version property is unspecified
boolean tryUpdate()
throws PersistException
IllegalStateException. Alternate keys may always be modified, however.
If this object has a version property defined, then
the update logic is a bit more strict. Updates of any storable require
that the primary keys be specified; if a version is present, the version
must be specified as well. If any of the primary key or version
properties are unspecified, an IllegalStateException will be
thrown; if they are fully specified and the version doesn't match the
current record, an OptimisticLockException is thrown.
Not all properties need to be set on this object when calling update. Setting a subset results in a partial update. After a successful update, all properties are set to the actual values in the storage layer. Put another way, the object is automatically reloaded after a successful update.
A return value of false indicates that the underlying record was deleted. When this happens, this object's state will be the same as if the delete method was called on it.
PersistException - if storage layer throws an exception
OptimisticLockException - if a version property exists and the
optimistic lock failed
IllegalStateException - if the state of this instance suggests
that any primary keys are unspecified, or if a version property is unspecified
void delete()
throws PersistException
Note: This method differs from tryDelete() only in that it may
throw a PersistNoneException, instead of returning false.
PersistNoneException - if record is missing and nothing was
deleted
PersistException - if storage layer throws an exception
IllegalStateException - if the state of this instance suggests
that any primary keys are unspecified
boolean tryDelete()
throws PersistException
Note: This method differs from delete() only in that it
returns false, instead of throwing a PersistNoneException.
PersistException - if storage layer throws an exception
IllegalStateException - if the state of this instance suggests
that any primary keys are unspecifiedClass<S> storableType()
Design note: the name "getStorableType" is avoided, so as not to conflict with a user defined property of "storableType"
void copyAllProperties(S target)
independent properties in this
or the target are not copied.
target - storable on which to call set<property> methods
IllegalStateException - if any primary key properties of target
cannot be alteredvoid copyPrimaryKeyProperties(S target)
independent properties in this or the target are not copied.
target - storable on which to call set<property> methods
IllegalStateException - if any primary key properties of target
cannot be alteredvoid copyVersionProperty(S target)
independent properties in this
or the target are not copied.
target - storable on which to call set<property> methodvoid copyUnequalProperties(S target)
independent properties in this
or the target are not copied.
target - storable on which to call set<property> methodsvoid copyDirtyProperties(S target)
independent properties in this or the target are not
copied.
target - storable on which to call set<property> methodsboolean hasDirtyProperties()
void markPropertiesClean()
void markAllPropertiesClean()
void markPropertiesDirty()
void markAllPropertiesDirty()
boolean isPropertyUninitialized(String propertyName)
propertyName - name of property to interrogate
IllegalArgumentException - if property is unknown, is a join or is derivedboolean isPropertyDirty(String propertyName)
propertyName - name of property to interrogate
IllegalArgumentException - if property is unknown, is a join or is derivedboolean isPropertyClean(String propertyName)
propertyName - name of property to interrogate
IllegalArgumentException - if property is unknown, is a join or is derivedboolean isPropertySupported(String propertyName)
Independent property which is not supported by
the repository, then this method returns false.
propertyName - name of property to checkObject getPropertyValue(String propertyName)
propertyName - name of property to get value of
IllegalArgumentException - if property is unknown or if accessor
method declares throwing any checked exceptions
UnsupportedOperationException - if property is independent but unsupported
NullPointerException - if property name is null
void setPropertyValue(String propertyName,
Object value)
propertyName - name of property to set value tovalue - new value for property
IllegalArgumentException - if property is unknown, or if value is
unsupported due to a constraint, or if mutator method declares throwing
any checked exceptions
UnsupportedOperationException - if property is independent but unsupported
ClassCastException - if value is of wrong type
NullPointerException - if property name is null or if primitive
value is required but value is nullMap<String,Object> propertyMap()
S copy()
S prepare()
Storage.prepare()
void writeTo(OutputStream out)
throws IOException,
SupportException
readFrom(java.io.InputStream) to restore. Derived and join
properties are not serialized.
The encoding used by this method is much simpler than what is provided by standard object serialization. It does not encode class info or property names, which is why it is not suitable for long term storage.
IOException - if exception from stream
SupportException - if Storable cannot be serialized
void readFrom(InputStream in)
throws IOException,
SupportException
writeTo(java.io.OutputStream).
Derived properties are not directly modified, but all other properties
not restored are reset to their initial state.
IOException - if exception from stream
SupportException - if Storable cannot be serializedint hashCode()
hashCode in class Objectboolean equals(Object obj)
equals in class Objectobj - object to compare to for equalityboolean equalPrimaryKeys(Object obj)
independent
properties in this or the target are not compared.
obj - object to compare to for equalityboolean equalProperties(Object obj)
independent properties in this or the target are not
compared.
obj - object to compare to for equalityString toString()
independent properties are not included.
toString in class ObjectString toStringKeyOnly()
independent properties are not included.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||