Cumulus4j API
(1.2.0-SNAPSHOT)

org.cumulus4j.store.model
Class FieldMeta

java.lang.Object
  extended by org.cumulus4j.store.model.FieldMeta
All Implemented Interfaces:
DetachCallback, StoreCallback
Direct Known Subclasses:
EmbeddedFieldMeta

public class FieldMeta
extends Object
implements DetachCallback, StoreCallback

Persistent meta-data for a field of a persistence-capable class. Since class- and field-names are very long we reference them indirectly via the long-identifiers of ClassMeta and FieldMeta, e.g. in the relation IndexEntry.fieldMeta.

Author:
Marco หงุ่ยตระกูล-Schulze - marco at nightlabs dot de

Nested Class Summary
protected static class FieldMeta.NamedQueries
           
 
Field Summary
protected static ThreadLocal<Set<FieldMeta>> attachedFieldMetasInPostDetachThreadLocal
           
protected static String UNIQUE_SCOPE_FIELD_META
           
 
Constructor Summary
protected FieldMeta()
          Internal constructor.
protected FieldMeta(ClassMeta classMeta, FieldMeta ownerFieldMeta, String fieldName, FieldMetaRole role)
          Internal constructor.
  FieldMeta(ClassMeta classMeta, String fieldName)
          Create a FieldMeta referencing a real field.
  FieldMeta(FieldMeta ownerFieldMeta, FieldMetaRole role)
          Create a FieldMeta referencing a part of a field.
 
Method Summary
 void addSubFieldMeta(FieldMeta subFieldMeta)
           
 boolean equals(Object obj)
           
 ClassMeta getClassMeta()
          Get the ClassMeta to which this FieldMeta belongs.
 int getDataNucleusAbsoluteFieldNumber()
          Get the non-persistent field-number in DataNucleus' meta-data.
 int getDataNucleusAbsoluteFieldNumber(ExecutionContext executionContext)
           
 AbstractMemberMetaData getDataNucleusMemberMetaData(ExecutionContext executionContext)
           
 EmbeddedClassMeta getEmbeddedClassMeta()
           
 long getFieldID()
           
 String getFieldName()
          Get the simple field name (no class prefix) of the field referenced by this meta-data-instance.
 Class<?> getFieldOrElementType(ExecutionContext executionContext)
           
 ClassMeta getFieldOrElementTypeClassMeta(ExecutionContext executionContext)
           
 AbstractClassMetaData getFieldOrElementTypeDataNucleusClassMetaData(ExecutionContext executionContext)
           
 FieldMeta getMappedByFieldMeta(ExecutionContext executionContext)
           Get the FieldMeta of the opposite end of the mapped-by-relation.
 FieldMeta getOwnerFieldMeta()
          Get the primary FieldMeta, to which this sub-FieldMeta belongs or null, if this FieldMeta is primary.
protected  PersistenceManager getPersistenceManager()
          Get the PersistenceManager assigned to this.
 FieldMetaRole getRole()
          Get the role of the (sub-)field.
protected  Map<FieldMetaRole,FieldMeta> getRole2SubFieldMeta()
           
 FieldMeta getSubFieldMeta(FieldMetaRole role)
          Get a sub-field of this field or null, if no such sub-field exists.
 Collection<FieldMeta> getSubFieldMetas()
          Get all sub-fields' meta-data of this field.
protected  String getUniqueScope()
           
 int hashCode()
           
 void jdoPostDetach(Object o)
           
 void jdoPreDetach()
           
 void jdoPreStore()
           
 void removeAllSubFieldMetasExcept(FieldMetaRole... roles)
           
 void removeSubFieldMeta(FieldMeta subFieldMeta)
           
protected  void setClassMeta(ClassMeta classMeta)
           
 void setDataNucleusAbsoluteFieldNumber(int dataNucleusAbsoluteFieldNumber)
           
 void setEmbeddedClassMeta(EmbeddedClassMeta embeddedClassMeta)
           
protected  void setOwnerFieldMeta(FieldMeta ownerFieldMeta)
           
protected  void setUniqueScope(String uniqueScope)
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

UNIQUE_SCOPE_FIELD_META

protected static final String UNIQUE_SCOPE_FIELD_META
See Also:
Constant Field Values

attachedFieldMetasInPostDetachThreadLocal

protected static final ThreadLocal<Set<FieldMeta>> attachedFieldMetasInPostDetachThreadLocal
Constructor Detail

FieldMeta

protected FieldMeta()
Internal constructor. This exists only for JDO and should not be used by application code!


FieldMeta

public FieldMeta(ClassMeta classMeta,
                 String fieldName)
Create a FieldMeta referencing a real field.

Parameters:
classMeta - the class to which this field belongs.
fieldName - the field's name.
See Also:
FieldMeta(FieldMeta, FieldMetaRole)

FieldMeta

public FieldMeta(FieldMeta ownerFieldMeta,
                 FieldMetaRole role)
Create a FieldMeta referencing a part of a field. This is necessary to index keys and values of a Map field (i.e. 2 separate indexes for one field) as well as Collection-elements and similar.

Parameters:
ownerFieldMeta - the FieldMeta of the real field (to which the part belongs).
role - the role (aka type) of the sub-field (aka part).
See Also:
FieldMeta(ClassMeta, String)

FieldMeta

protected FieldMeta(ClassMeta classMeta,
                    FieldMeta ownerFieldMeta,
                    String fieldName,
                    FieldMetaRole role)
Internal constructor. This exists only for easier implementation of the other constructors and should not be used by application code!

Method Detail

getFieldID

public long getFieldID()

getUniqueScope

protected String getUniqueScope()

setUniqueScope

protected void setUniqueScope(String uniqueScope)

getClassMeta

public ClassMeta getClassMeta()
Get the ClassMeta to which this FieldMeta belongs. Every FieldMeta belongs to exactly one ClassMeta just like a field is declared in exactly one Java class. Note, that a FieldMeta might belong to another FieldMeta in order to reference sub-field-properties, e.g. a Map's key. In this case, the direct property classMeta is null, but this method still returns the correct ClassMeta by resolving it indirectly via the ownerFieldMeta.

Returns:
the ClassMeta to which this instance of FieldMeta belongs.

setClassMeta

protected void setClassMeta(ClassMeta classMeta)

getOwnerFieldMeta

public FieldMeta getOwnerFieldMeta()
Get the primary FieldMeta, to which this sub-FieldMeta belongs or null, if this FieldMeta is primary.

Returns:
the owning primary field-meta or null.

setOwnerFieldMeta

protected void setOwnerFieldMeta(FieldMeta ownerFieldMeta)

getFieldName

public String getFieldName()
Get the simple field name (no class prefix) of the field referenced by this meta-data-instance.

Returns:
the simple field name.

getRole

public FieldMetaRole getRole()
Get the role of the (sub-)field. If this is not a sub-field, but a primary field (i.e. directly meaning a real field of the class referenced by classMeta) it will be FieldMetaRole.primary, hence this method never returns null.

Returns:
the role of this FieldMeta; never null.

getPersistenceManager

protected PersistenceManager getPersistenceManager()
Get the PersistenceManager assigned to this. If there is none, this method checks, if this is new. If this was persisted before, it must have one or an IllegalStateException is thrown.

Returns:
the PersistenceManager assigned to this or null.

getRole2SubFieldMeta

protected Map<FieldMetaRole,FieldMeta> getRole2SubFieldMeta()

getEmbeddedClassMeta

public EmbeddedClassMeta getEmbeddedClassMeta()

setEmbeddedClassMeta

public void setEmbeddedClassMeta(EmbeddedClassMeta embeddedClassMeta)

getDataNucleusAbsoluteFieldNumber

public int getDataNucleusAbsoluteFieldNumber(ExecutionContext executionContext)

getDataNucleusAbsoluteFieldNumber

public int getDataNucleusAbsoluteFieldNumber()
Get the non-persistent field-number in DataNucleus' meta-data. This is only a usable value, if this FieldMeta was obtained via Cumulus4jStoreManager#getClassMeta(org.datanucleus.store.ExecutionContext, Class); otherwise it is -1.

Returns:
the non-persistent field-number in DataNucleus' meta-data or -1.

setDataNucleusAbsoluteFieldNumber

public void setDataNucleusAbsoluteFieldNumber(int dataNucleusAbsoluteFieldNumber)

getSubFieldMeta

public FieldMeta getSubFieldMeta(FieldMetaRole role)
Get a sub-field of this field or null, if no such sub-field exists.

Parameters:
role - the role of the sub-field. Must not be null.
Returns:
the sub-FieldMeta or null.

getSubFieldMetas

public Collection<FieldMeta> getSubFieldMetas()
Get all sub-fields' meta-data of this field. If there are no sub-fields, this is an empty collection.

Returns:
all sub-FieldMetas of this field; never null.

addSubFieldMeta

public void addSubFieldMeta(FieldMeta subFieldMeta)

removeSubFieldMeta

public void removeSubFieldMeta(FieldMeta subFieldMeta)

removeAllSubFieldMetasExcept

public void removeAllSubFieldMetasExcept(FieldMetaRole... roles)

getFieldOrElementTypeClassMeta

public ClassMeta getFieldOrElementTypeClassMeta(ExecutionContext executionContext)

getFieldOrElementTypeDataNucleusClassMetaData

public AbstractClassMetaData getFieldOrElementTypeDataNucleusClassMetaData(ExecutionContext executionContext)

getFieldOrElementType

public Class<?> getFieldOrElementType(ExecutionContext executionContext)

getMappedByFieldMeta

public FieldMeta getMappedByFieldMeta(ExecutionContext executionContext)

Get the FieldMeta of the opposite end of the mapped-by-relation. If this is not a mapped-by field, this method returns null.

Though, it returns always the mapped-by opposite side, the semantics of this method still depend on the role of this FieldMeta:

Returns:
the FieldMeta of the other end of the mapped-by-relation.

jdoPreDetach

public void jdoPreDetach()
Specified by:
jdoPreDetach in interface DetachCallback

jdoPostDetach

public void jdoPostDetach(Object o)
Specified by:
jdoPostDetach in interface DetachCallback

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

toString

public String toString()
Overrides:
toString in class Object

getDataNucleusMemberMetaData

public AbstractMemberMetaData getDataNucleusMemberMetaData(ExecutionContext executionContext)

jdoPreStore

public void jdoPreStore()
Specified by:
jdoPreStore in interface StoreCallback

Cumulus4j API
(1.2.0-SNAPSHOT)

Copyright © 2013 NightLabs Consulting GmbH. All Rights Reserved.