Package org.datanucleus.cache
Class CachedPC
- java.lang.Object
-
- org.datanucleus.cache.CachedPC
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Comparable<CachedPC>
public class CachedPC extends java.lang.Object implements java.io.Serializable, java.lang.Comparable<CachedPC>
An object that is stored in the Level2 Cache keyed by the identity of the persistable object. Comprises a map of the field values keyed by the absolute field number in the class, the loaded fields array, and the version of the object that is represented with these values.- Where the field is a relation field (PC, Map, Collection, array) we store the id of any referenced persistable object. This is used when regenerating the object, and recreating its relations. Note that the "id" is the DatastoreId or SingleFieldId etc where applicable otherwise is CachedId (ensuring that the class of the related object is stored).
- Where the field contains an embedded/serialised persistable object, we store a nested CachedPC object representing that object (since it doesn't exist in its own right).
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classCachedPC.CachedId
-
Field Summary
Fields Modifier and Type Field Description private java.lang.ClassclsClass of the object being cached.private java.util.Map<java.lang.Integer,java.lang.Object>fieldValuesValues for the fields, keyed by the absolute field number.private java.lang.ObjectidIdentity of the object being cached.private boolean[]loadedFieldsThe loaded fields array.private static longserialVersionUIDprivate java.lang.ObjectversionVersion of the cached object (if any) - Long, Timestamp etc.
-
Constructor Summary
Constructors Constructor Description CachedPC(java.lang.Class cls, boolean[] loadedFields, java.lang.Object vers, java.lang.Object id)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intcompareTo(CachedPC other)CachedPCgetCopy()java.lang.ObjectgetFieldValue(java.lang.Integer fieldNumber)java.lang.ObjectgetId()int[]getLoadedFieldNumbers()boolean[]getLoadedFields()Accessor for the loaded fields of this object.java.lang.ClassgetObjectClass()java.lang.ObjectgetVersion()voidsetFieldValue(java.lang.Integer fieldNumber, java.lang.Object value)voidsetLoadedField(int fieldNumber, boolean loaded)voidsetVersion(java.lang.Object ver)java.lang.StringtoString()Method to return a sting form of the cached object.java.lang.StringtoString(java.lang.String indent, boolean debug)Method to return a string form of the cached object.
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
cls
private java.lang.Class cls
Class of the object being cached.
-
id
private java.lang.Object id
Identity of the object being cached. This is to allow recreation of the object when using uniqueKey lookup. This will be null if embedded/serialised.
-
fieldValues
private java.util.Map<java.lang.Integer,java.lang.Object> fieldValues
Values for the fields, keyed by the absolute field number.
-
version
private java.lang.Object version
Version of the cached object (if any) - Long, Timestamp etc.
-
loadedFields
private boolean[] loadedFields
The loaded fields array. TODO Note that this could be interpreted from the keys of fieldValues.
-
-
Method Detail
-
getObjectClass
public java.lang.Class getObjectClass()
-
getId
public java.lang.Object getId()
-
setFieldValue
public void setFieldValue(java.lang.Integer fieldNumber, java.lang.Object value)
-
getFieldValue
public java.lang.Object getFieldValue(java.lang.Integer fieldNumber)
-
setVersion
public void setVersion(java.lang.Object ver)
-
getVersion
public java.lang.Object getVersion()
-
getLoadedFields
public boolean[] getLoadedFields()
Accessor for the loaded fields of this object. Use setLoadedField() if you want to update a flag.- Returns:
- The loaded fields flags
-
getLoadedFieldNumbers
public int[] getLoadedFieldNumbers()
-
setLoadedField
public void setLoadedField(int fieldNumber, boolean loaded)
-
getCopy
public CachedPC getCopy()
-
compareTo
public int compareTo(CachedPC other)
- Specified by:
compareToin interfacejava.lang.Comparable<CachedPC>
-
toString
public java.lang.String toString()
Method to return a sting form of the cached object. Returns something likeCachedPC : cls=mydomain.MyClass version=1 loadedFlags=[YY]
- Overrides:
toStringin classjava.lang.Object- Returns:
- The string form
-
toString
public java.lang.String toString(java.lang.String indent, boolean debug)Method to return a string form of the cached object. Returns something likeCachedPC : cls=mydomain.MyClass version=1 loadedFlags=[YY] numValues=2 field=0 value=101 type=class java.lang.Long field=1 value=Home type=class java.lang.Stringwhen debug is enabled, and omits the "field=..." parts when not using debug.- Parameters:
indent- Indent for this CachedPCdebug- Whether to include the field values in the return- Returns:
- The string form
-
-