Class ClassInformation


  • public class ClassInformation
    extends Object
    ClassInformation handles the metadata for the ReflectiveNeo4JNodeRepositoryImpl It contains info on the id, fields and relationships that should be modelled in the database
    Since:
    1.0
    Author:
    Oliver Krauss
    • Method Detail

      • constructClassInformation

        protected static ClassInformation constructClassInformation​(ParameterizedType targetClass,
                                                                    String relationshipName)
        Constructs the Class information from a given class including the GENERIC TYPES. TODO #22: Currently this is only used for MapRelationship, we may be able to support generics in general.
        Parameters:
        targetClass - Parameterized fieldClass of class.
        relationshipName - name of relationship, as this becomes part of the class identity.
        Returns:
        Class information of targetClass
      • constructClassInformation

        public static ClassInformation constructClassInformation​(Class clazz)
        Constructs the Class Information from a given class. It will fail if the class does not contain a valid ID field A Valid ID Field is either named "id" or contains the Id Annotation
        Parameters:
        clazz - Class to be analized
        Returns:
        ClassInformation for Neo4J DB transformation
      • constructClassInformation

        public static ClassInformation constructClassInformation​(Class clazz,
                                                                 boolean namespaceaware)
        Constructs the Class Information from a given class. It will fail if the class does not contain a valid ID field A Valid ID Field is either named "id" or contains the Id Annotation
        Parameters:
        clazz - Class to be analized
        namespaceaware - -> if it is constructed with or without namespacing, per default it is not
        Returns:
        ClassInformation for Neo4J DB transformation
      • cast

        protected Object cast​(org.neo4j.driver.types.Relationship value,
                              org.neo4j.driver.types.Node source,
                              org.neo4j.driver.types.Node target,
                              Map<Long,​Object> castNodes)
      • cast

        protected Object cast​(org.neo4j.driver.types.Node value,
                              List<org.neo4j.driver.types.Relationship> relationships,
                              List<org.neo4j.driver.types.Node> children,
                              Map<Long,​Object> nodes)
      • cast

        protected Object cast​(Long id,
                              Map<String,​Object> value,
                              List<org.neo4j.driver.types.Relationship> relationships,
                              List<org.neo4j.driver.types.Node> children,
                              Map<Long,​Object> nodes)
        Casts a database node or relationship into a java object
        Parameters:
        id - java object will be asigned to
        value - map of values contained in the node
        relationships - relationships in the subtree
        children - nodes not yet cast in the subtree
        nodes - nodes already cast in the subtree
        Returns:
        cast result
      • objectifyProperties

        public Map<String,​Object> objectifyProperties​(Object node)
        turns the object into a map of fields->values
        Parameters:
        node - to be turned into a map
        Returns:
        map of all fields
      • getAlternativeNamespaceFields

        public Map<String,​Object> getAlternativeNamespaceFields​(Object node)
        Provides a map of fields that alternative namespaces used in the given node. If the system doesn't consider namespaces, or no alternative namespaces exist yet NULL is returned
        Parameters:
        node - for which namepsace fields should be retrieved
        Returns:
        Map with all alternative fields or null Please note that the return map can also contain maps!

        Warning: This is NOT READ ONLY. Changes WILL be stored in the DB.

      • getLabels

        public List<String> getLabels​(Object node)
        Returns the database labels from the given node
        Parameters:
        node - to be checked
        Returns:
        database labels or the labels the node will receive when stored into the db.

        Warning: this is READ ONLY. No changes will be stored in the DB.

      • getAlternativeRelationshipsInNamespaces

        public Map<String,​Pair<org.neo4j.driver.types.Node,​org.neo4j.driver.types.Relationship>> getAlternativeRelationshipsInNamespaces​(Object node)
        Provides a map of relationships that alternative namespaces used in the given node. If the system doesn't consider namespaces, or no alternative namespaces exist yet NULL is returned
        Parameters:
        node - for which relationships should be retrieved
        Returns:
        Map with all alternative relationships or null (The pair contains <TARGETNODE, RELATIONSHIP>) Please note that the return map can also contain maps!

        Warning: this is READ ONLY. No changes will be stored in the DB.

      • getClazz

        public Class getClazz()
      • getName

        public String getName()
      • getLabels

        public String getLabels()
      • getNamespace

        public String getNamespace()
      • getNsName

        public String getNsName()
      • getNsLabels

        public String getNsLabels()
      • isNamespaceaware

        public boolean isNamespaceaware()
        gets value of field namespaceaware
        Returns:
        value of field namespaceaware
        See Also:
        namespaceaware
      • castToClass

        public static <T> T castToClass​(Object o,
                                        Class<T> c)
        Casts a Neo4J database object to the required class
        Type Parameters:
        T - Type = class given as c
        Parameters:
        o - object to be cast
        c - class to cast to
        Returns:
        object now of class c
      • getExtensions

        public Map<String,​Object> getExtensions​(Object node)
        Returns all extensions provided in the object
        Parameters:
        node - object where extensions should be accessed
        Returns:
        all extensions (map can be modified!)
      • getExtension

        public Object getExtension​(Object node,
                                   String name)
        Returns the extension of name or null if it doesnt exist
        Parameters:
        node - object that the extension should be loaded out of
        name - of extension that should be returned
        Returns:
        extension or null (object CAN NOT be modified)
      • setExtension

        public void setExtension​(Object node,
                                 String name,
                                 Object extension)
        Adds the extension of name to the object o. Warning: If the extension already exists it will be overwritten!
        Parameters:
        node - object that the extension should be added to
        name - name of extension to be set
        extension - to be added (can only be primitive!)
      • setExtensionSafe

        public boolean setExtensionSafe​(Object node,
                                        String name,
                                        Object extension)
        Adds the extension of name to the object o. Will only write extension if it does NOT exist
        Parameters:
        node - object that the extension should be added to
        name - name of extension to be set
        extension - to be added (can only be primitive!)
        Returns:
        true if write was successful, false if the extension already existed