Package org.neo4j.ogm.metadata
Class ClassInfo
java.lang.Object
org.neo4j.ogm.metadata.ClassInfo
Maintains object to graph mapping details at the class (type) level
The ClassInfo object is used to maintain mappings from Java Types->Neo4j Labels
thereby allowing the correct labels to be applied to new nodes when they
are persisted.
The ClassInfo object also maintains a map of FieldInfo and MethodInfo objects
that maintain the appropriate information for mapping Java class attributes to Neo4j
node properties / paths (node)-[:relationship]->(node), via field or method
accessors respectively.
Given a type hierarchy, the ClassInfo object guarantees that for any type in that
hierarchy, the labels associated with that type will include the labels for
all its superclass and interface types as well. This is to avoid the need to iterate
through the ClassInfo hierarchy to recover label information.
- Author:
- Vince Bickers, Luanne Misquitta, Mark Angrish, Michael J. Simons, Torsten Kuhnhenne, Nicolas Labrot
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptioncandidateRelationshipFields
(String relationshipName, Relationship.Direction relationshipDirection, boolean strict) Finds all relationship fields with a specific name and direction from the ClassInfo's relationship fieldsboolean
static String
deriveSimpleName
(Class<?> clazz) boolean
findFields
(Class<?> fieldType) Find all FieldInfos for the specified ClassInfo whose type matches the supplied fieldTypefindFields
(String annotation) Find all FieldInfos for the specified ClassInfo which have the specified annotationfindIterableFields
(Class iteratedType) Finds all fields whose type is equivalent to Array<X> or assignable from Iterable<X> where X is the generic parameter type of the Array or IterablefindIterableFields
(Class<?> iteratedType, String relationshipType, Relationship.Direction relationshipDirection, boolean strict) Finds all fields whose type is equivalent to Array<X> or assignable from Iterable<X> where X is the generic parameter type of the Array or Iterable and the relationship type backing this iterable is "relationshipType"Return a FieldInfo for the EndNode of a RelationshipEntitygetFieldInfo
(String propertyName) Return a FieldInfo for the StartNode of a RelationshipEntityClass<?>
Get the underlying class represented by this ClassInfoint
hashCode()
boolean
boolean
boolean
Returns if the class as fields annotated with @Required annotationboolean
The identity field is a field annotated with @NodeId, or if none exists, a field of type Long called 'id'Class<? extends IdStrategy>
boolean
boolean
isEnum()
boolean
boolean
boolean
The label field is an optional field annotated with @Labels.name()
propertyField
(String propertyName) Finds the property field with a specific property name from the ClassInfo's property fields Note that this method does not allow for property names with differing case.propertyFieldByName
(String propertyName) Finds the property field with a specific field name from the ClassInfo's property fieldsA property field is any field annotated with @Property, or any field that can be mapped to a node property.readPrimaryIndexValueOf
(Object entity) Reads the value of the entity's primary index field if any.void
registerIdGenerationStrategy
(IdStrategy strategy) relationshipField
(String relationshipName) Finds the relationship field with a specific name from the ClassInfo's relationship fieldsrelationshipField
(String relationshipName, Relationship.Direction relationshipDirection, boolean strict) Finds the relationship field with a specific name and direction from the ClassInfo's relationship fieldsrelationshipFieldByName
(String fieldName) Finds the relationship field with a specific property name from the ClassInfo's relationship fieldsA relationship field is any field annotated with @Relationship, or any field that cannot be mapped to a node property.Retrieves the static labels that are applied to nodes in the database.toString()
-
Constructor Details
-
ClassInfo
-
-
Method Details
-
name
-
deriveSimpleName
-
directSuperclass
-
staticLabels
Retrieves the static labels that are applied to nodes in the database. If the class' instances are persisted by a relationship instead of a node then this method returns an empty collection.
Note that this method returns only the static labels. A node entity instance may declare additional labels managed at runtime by using the @Labels annotation on a collection field, therefore the full set of labels to be mapped to a node will be the static labels, in addition to any labels declared by the backing field of an
Labels
annotation.- Returns:
- A
Collection
of all the static labels that apply to the node or an empty list if there aren't any, nevernull
-
neo4jName
-
directSubclasses
-
allSubclasses
- Returns:
- A list of all implementing and extending subclasses.
- Since:
- 3.1.20
-
annotations
-
isInterface
public boolean isInterface() -
isEnum
public boolean isEnum() -
annotationsInfo
-
fieldsInfo
-
identityFieldOrNull
-
identityField
The identity field is a field annotated with @NodeId, or if none exists, a field of type Long called 'id'- Returns:
- A
FieldInfo
object representing the identity field nevernull
- Throws:
MappingException
- if no identity field can be found
-
hasIdentityField
public boolean hasIdentityField() -
labelFieldOrNull
The label field is an optional field annotated with @Labels.- Returns:
- A
FieldInfo
object representing the label field. Optionallynull
-
isRelationshipEntity
public boolean isRelationshipEntity() -
propertyFields
A property field is any field annotated with @Property, or any field that can be mapped to a node property. The identity field is not a property field.- Returns:
- A Collection of FieldInfo objects describing the classInfo's property fields
- Throws:
InvalidPropertyFieldException
- if the recognized property fields contain a field that is not actually persistable as property.
-
propertyField
Finds the property field with a specific property name from the ClassInfo's property fields Note that this method does not allow for property names with differing case. //TODO- Parameters:
propertyName
- the propertyName of the field to find- Returns:
- A FieldInfo object describing the required property field, or null if it doesn't exist.
- Throws:
InvalidPropertyFieldException
- if the recognized property fields contain a field that is not actually persistable as property.
-
propertyFieldByName
Finds the property field with a specific field name from the ClassInfo's property fields- Parameters:
propertyName
- the propertyName of the field to find- Returns:
- A FieldInfo object describing the required property field, or null if it doesn't exist.
-
relationshipFields
A relationship field is any field annotated with @Relationship, or any field that cannot be mapped to a node property. The identity field is not a relationship field.- Returns:
- A Collection of FieldInfo objects describing the classInfo's relationship fields
-
relationshipField
Finds the relationship field with a specific name from the ClassInfo's relationship fields- Parameters:
relationshipName
- the relationshipName of the field to find- Returns:
- A FieldInfo object describing the required relationship field, or null if it doesn't exist.
-
relationshipField
public FieldInfo relationshipField(String relationshipName, Relationship.Direction relationshipDirection, boolean strict) Finds the relationship field with a specific name and direction from the ClassInfo's relationship fields- Parameters:
relationshipName
- the relationshipName of the field to findrelationshipDirection
- the direction of the relationship represented by a stringstrict
- if true, does not infer relationship type but looks for it in the @Relationship annotation. Null if missing. If false, infers relationship type from FieldInfo- Returns:
- A FieldInfo object describing the required relationship field, or null if it doesn't exist.
-
candidateRelationshipFields
public Set<FieldInfo> candidateRelationshipFields(String relationshipName, Relationship.Direction relationshipDirection, boolean strict) Finds all relationship fields with a specific name and direction from the ClassInfo's relationship fields- Parameters:
relationshipName
- the relationshipName of the field to findrelationshipDirection
- the direction of the relationshipstrict
- if true, does not infer relationship type but looks for it in the @Relationship annotation. Null if missing. If false, infers relationship type from FieldInfo- Returns:
- Set of FieldInfo objects describing the required relationship field, or empty set if it doesn't exist.
-
relationshipFieldByName
Finds the relationship field with a specific property name from the ClassInfo's relationship fields- Parameters:
fieldName
- the name of the field- Returns:
- A FieldInfo object describing the required relationship field, or null if it doesn't exist.
-
getField
-
findFields
Find all FieldInfos for the specified ClassInfo whose type matches the supplied fieldType -
findFields
Find all FieldInfos for the specified ClassInfo which have the specified annotation -
findIterableFields
-
findIterableFields
Finds all fields whose type is equivalent to Array<X> or assignable from Iterable<X> where X is the generic parameter type of the Array or Iterable- Parameters:
iteratedType
- the type of iterable- Returns:
List
ofMethodInfo
, nevernull
-
findIterableFields
public List<FieldInfo> findIterableFields(Class<?> iteratedType, String relationshipType, Relationship.Direction relationshipDirection, boolean strict) Finds all fields whose type is equivalent to Array<X> or assignable from Iterable<X> where X is the generic parameter type of the Array or Iterable and the relationship type backing this iterable is "relationshipType"- Parameters:
iteratedType
- the type of iterablerelationshipType
- the relationship typerelationshipDirection
- the relationship directionstrict
- if true, does not infer relationship type but looks for it in the @Relationship annotation. Null if missing. If false, infers relationship type from FieldInfo- Returns:
List
ofMethodInfo
, nevernull
-
isTransient
public boolean isTransient() -
isAbstract
public boolean isAbstract() -
getUnderlyingClass
Get the underlying class represented by this ClassInfo- Returns:
- the underlying class or null if it cannot be determined
-
containsIndexes
public boolean containsIndexes()- Returns:
- If this class contains any fields/properties annotated with @Index.
-
getIndexFields
- Returns:
- The
FieldInfo
s representing the Indexed fields in this class.
-
-
hasPrimaryIndexField
public boolean hasPrimaryIndexField() -
idStrategy
-
idStrategyClass
-
registerIdGenerationStrategy
-
postLoadMethodOrNull
-
getFieldInfo
-
getEndNodeReader
Return a FieldInfo for the EndNode of a RelationshipEntity- Returns:
- a FieldInfo for the field annotated as the EndNode, or none if not found
-
getStartNodeReader
Return a FieldInfo for the StartNode of a RelationshipEntity- Returns:
- a FieldInfo for the field annotated as the StartNode, or none if not found
-
hasRequiredFields
public boolean hasRequiredFields()Returns if the class as fields annotated with @Required annotation -
requiredFields
-
hasVersionField
public boolean hasVersionField() -
getVersionField
-
readPrimaryIndexValueOf
Reads the value of the entity's primary index field if any.- Parameters:
entity
-- Returns:
-
getPrimaryIndexOrIdReader
-
toString
-
equals
-
hashCode
public int hashCode()
-