Class ClassInfo

java.lang.Object
org.neo4j.ogm.metadata.ClassInfo

public class ClassInfo extends Object
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 Details

    • ClassInfo

      public ClassInfo(Class<?> cls, org.neo4j.ogm.driver.TypeSystem typeSystem)
  • Method Details

    • name

      public String name()
    • deriveSimpleName

      public static String deriveSimpleName(Class<?> clazz)
    • directSuperclass

      public ClassInfo directSuperclass()
    • staticLabels

      public Collection<String> 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, never null
    • neo4jName

      public String neo4jName()
    • directSubclasses

      public List<ClassInfo> directSubclasses()
    • allSubclasses

      public Collection<ClassInfo> allSubclasses()
      Returns:
      A list of all implementing and extending subclasses.
      Since:
      3.1.20
    • annotations

      public Collection<AnnotationInfo> annotations()
    • isInterface

      public boolean isInterface()
    • isEnum

      public boolean isEnum()
    • annotationsInfo

      public AnnotationsInfo annotationsInfo()
    • fieldsInfo

      public FieldsInfo fieldsInfo()
    • identityFieldOrNull

      public FieldInfo identityFieldOrNull()
    • identityField

      public FieldInfo 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 never null
      Throws:
      MappingException - if no identity field can be found
    • hasIdentityField

      public boolean hasIdentityField()
    • labelFieldOrNull

      public FieldInfo labelFieldOrNull()
      The label field is an optional field annotated with @Labels.
      Returns:
      A FieldInfo object representing the label field. Optionally null
    • dynamicLabelsFrom

      public Collection<String> dynamicLabelsFrom(org.neo4j.ogm.model.Node nodeModel)
    • isRelationshipEntity

      public boolean isRelationshipEntity()
    • propertyFields

      public Collection<FieldInfo> 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

      public FieldInfo 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. //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

      public FieldInfo propertyFieldByName(String propertyName)
      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

      public Collection<FieldInfo> 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

      public FieldInfo relationshipField(String relationshipName)
      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 find
      relationshipDirection - the direction of the relationship represented by a string
      strict - 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 find
      relationshipDirection - the direction of the relationship
      strict - 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

      public FieldInfo relationshipFieldByName(String fieldName)
      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

      public Field getField(FieldInfo fieldInfo)
    • findFields

      public List<FieldInfo> findFields(Class<?> fieldType)
      Find all FieldInfos for the specified ClassInfo whose type matches the supplied fieldType
      Parameters:
      fieldType - The field type to look for
      Returns:
      A List of FieldInfo objects that are of the given type, never null
    • findFields

      public List<FieldInfo> findFields(String annotation)
      Find all FieldInfos for the specified ClassInfo which have the specified annotation
      Parameters:
      annotation - The annotation
      Returns:
      A List of FieldInfo objects that are of the given type, never null
    • findIterableFields

      public List<FieldInfo> findIterableFields()
      Retrieves a List of FieldInfo representing all of the fields that can be iterated over using a "foreach" loop.
      Returns:
      List of FieldInfo
    • findIterableFields

      public List<FieldInfo> findIterableFields(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 Iterable
      Parameters:
      iteratedType - the type of iterable
      Returns:
      List of MethodInfo, never null
    • 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 iterable
      relationshipType - the relationship type
      relationshipDirection - the relationship direction
      strict - 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 of MethodInfo, never null
    • isTransient

      public boolean isTransient()
    • isAbstract

      public boolean isAbstract()
    • getUnderlyingClass

      public Class<?> 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

      public Collection<FieldInfo> getIndexFields()
      Returns:
      The FieldInfos representing the Indexed fields in this class.
    • primaryIndexField

      public FieldInfo primaryIndexField()
    • hasPrimaryIndexField

      public boolean hasPrimaryIndexField()
    • idStrategy

      public IdStrategy idStrategy()
    • idStrategyClass

      public Class<? extends IdStrategy> idStrategyClass()
    • registerIdGenerationStrategy

      public void registerIdGenerationStrategy(IdStrategy strategy)
    • postLoadMethodOrNull

      public MethodInfo postLoadMethodOrNull()
    • getFieldInfo

      public FieldInfo getFieldInfo(String propertyName)
    • getEndNodeReader

      public FieldInfo 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

      public FieldInfo 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

      public Collection<FieldInfo> requiredFields()
    • hasVersionField

      public boolean hasVersionField()
    • getVersionField

      public FieldInfo getVersionField()
    • readPrimaryIndexValueOf

      public Object readPrimaryIndexValueOf(Object entity)
      Reads the value of the entity's primary index field if any.
      Parameters:
      entity -
      Returns:
    • getPrimaryIndexOrIdReader

      public Function<Object,Optional<Object>> getPrimaryIndexOrIdReader()
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object