public abstract class Persistable extends java.lang.Object implements IsPersistable
Persistable
class as the super class of data objects to be persisted in some data store.
The data store could be a client's Local Storage or the ASSISTments server database.
Persistable
maintains a Persistence Key that uniquely represents an instance of persistable data.
The Persistence Key is in the following format:
@<class type>/<uid>
where:
<class type>
-- The superclass' name as a fully qualified name. For example:
org.assisments.core.domain.Assignment
.
The class name can be obtained by calling
.getClass().getName()
on a superclass' instance.
<uid>
-- A unique ID.
Modifier | Constructor and Description |
---|---|
protected |
Persistable(java.lang.String classType,
java.lang.String uid)
Constructor
This is the preferred constructor and should be used whenever possible - most certainly in server code.
|
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
createKey(java.lang.String classType)
For the specified class, returns a key for use in retrieving the corresponding persistable data.
|
static java.lang.String |
createKey(java.lang.String classType,
java.lang.String uid)
For the specified class type and UID, returns a key for use in retrieving the corresponding persistable data.
|
boolean |
equals(java.lang.Object obj)
Determines whether another object contains the same data values as the current
Persistable instance. |
static java.lang.String |
extractType(java.lang.String key)
Returns the class type from a Persistence Key.
|
static java.lang.String |
extractUID(java.lang.String key)
Returns the unique identifier from a Persistence Key.
|
java.lang.String |
getKey()
Returns a key representing this persistable object in the following format:
@<class type>/<uid>
|
java.lang.String |
getShortKey()
Alias for
HasUID.getUID() |
static java.lang.String |
getShortKey(java.lang.String persistenceKey)
Returns the unique identifier from a Persistence Key.
|
java.lang.String |
getType()
Returns, as a fully specified class name, the class type needed to store this persistable object.
|
java.lang.String |
getUID()
Returns the database UID for this persistable object.
|
ValidatorUtilities |
getValidatorUtilities() |
void |
setValidatorUtilities(ValidatorUtilities vu) |
java.lang.String |
toString()
Returns a string representation of this object.
|
void |
validate()
Check this object's data for inconsistencies
Subclasses must (by informal contract) implement this method!
|
static void |
validateKey(java.lang.String key)
Validates a Persistence Key's format.
|
protected Persistable(java.lang.String classType, java.lang.String uid)
public java.lang.String getUID()
HasUID
public java.lang.String getShortKey()
HasUID
HasUID.getUID()
getShortKey
in interface HasUID
public java.lang.String getType()
getType
in interface IsPersistable
setType(String)
public java.lang.String getKey()
@<class type>/<uid>
getKey
in interface IsPersistable
getType()
,
org.assistments.domain.content.tutor.persistence.HasUID#getUID()
public static java.lang.String createKey(java.lang.String classType)
classType
- fully specified class nameUIDGeneratorGWTImpl.generateDefaultUID()
,
createKey(String, String)
public static java.lang.String createKey(java.lang.String classType, java.lang.String uid)
classType
- fully specified class nameuid
- Unique Identifier@<class type>/<uid>
public static java.lang.String extractType(java.lang.String key)
key
- The persistence keyjava.lang.IllegalArgumentException
- if key is improperly formatted.public static java.lang.String extractUID(java.lang.String key)
key
- The persistence keypublic static java.lang.String getShortKey(java.lang.String persistenceKey)
extractUID(String)
.persistenceKey
- The persistence keyextractUID(String)
public static void validateKey(java.lang.String key) throws java.lang.IllegalArgumentException
key
- Persistence key to validatejava.lang.IllegalArgumentException
- If the key is not in the expected format.public void validate() throws ValidationException
SelfValidating
validate
in interface SelfValidating
ValidationException
- if the data is invalidpublic boolean equals(java.lang.Object obj)
Persistable
instance.
Equality is determined if all member fields, are identical. Please note that class type and UID compares are case sensitive.
equals
in class java.lang.Object
true if all fields are identical; otherwise false
public java.lang.String toString()
toString
in interface IsPersistable
toString
in class java.lang.Object
public void setValidatorUtilities(ValidatorUtilities vu)
setValidatorUtilities
in interface IsPersistable
public ValidatorUtilities getValidatorUtilities()
getValidatorUtilities
in interface IsPersistable