Class AbstractNeo4JRelationshipRepositoyImpl<S>

  • Type Parameters:
    S - Type of class
    All Implemented Interfaces:
    Neo4jRepository<S,​Long>
    Direct Known Subclasses:
    ReflectiveNeo4JRelationshipRepositoryImpl

    public abstract class AbstractNeo4JRelationshipRepositoyImpl<S>
    extends AbstractNeo4JRepository<S,​Long>
    Quick notes about usage:
    • This class should handle pretty much all the default stuff
    • On a save all science.neo4j.nodes without an id will be saved (propagating to ALL science.neo4j.nodes through EVERY relationship!)
    • We are currently only capable of handling (source)-[DIRECTED]->(target) unidirectional relationships from S to T.
    • On a load the relationship + its source and target science.neo4j.nodes are loaded
    Since:
    1.0
    Author:
    Oliver Krauss
    • Constructor Detail

      • AbstractNeo4JRelationshipRepositoyImpl

        protected AbstractNeo4JRelationshipRepositoyImpl​(TransactionManager manager)
        empty constructor for child-implementations. If you use this one, you MUST call the init function
        Parameters:
        manager - used to handle transactions
      • AbstractNeo4JRelationshipRepositoyImpl

        protected AbstractNeo4JRelationshipRepositoyImpl​(TransactionManager manager,
                                                         String className)
    • Method Detail

      • init

        protected void init​(String className,
                            String labels)
      • cast

        protected abstract S cast​(org.neo4j.driver.Value relationship,
                                  org.neo4j.driver.Value source,
                                  org.neo4j.driver.Value target)
        Casts the result of the queryTyped into a relationship class
        Parameters:
        relationship - to be cast
        source - source node of relationship
        target - target node of relationship
        Returns:
        relationship object
      • setId

        protected abstract S setId​(S relationship,
                                   Long id)
        Helper method for setting the id when a node was stored to the database
        Parameters:
        relationship - to be assigned an id
        id - of the relationsip
        Returns:
        node with id
      • getId

        protected abstract Long getId​(S relationship)
        Helper method for finding the id of a node
        Parameters:
        relationship - to return the id from
        Returns:
        id of node or null
      • handleSourceAndTarget

        protected abstract <T extends S> T handleSourceAndTarget​(T node)
        Helper method that is responsible for storing source or target science.neo4j.nodes.
        Type Parameters:
        T - extension of S
        Parameters:
        node - to be saved
        Returns:
        node
      • handleSourceAndTarget

        protected abstract <T extends SCollection<T> handleSourceAndTarget​(Collection<T> nodes)
        Helper method that is responsible for storing all source or target science.neo4j.nodes in a multitude of relationships
        Type Parameters:
        T - extension of S
        Parameters:
        nodes - to be saved
        Returns:
        science.neo4j.nodes
      • objectify

        protected abstract Map<String,​Object> objectify​(S relationship)
        Turns all properties of a Relationship into something to be used by the queries
        Parameters:
        relationship - to be transformed
        Returns:
        a map containing the id, and another map that contains all properties
      • execute

        protected S execute​(String query,
                            org.neo4j.driver.Value parameters,
                            org.neo4j.driver.AccessMode accessMode)
        Helper function that simply executes a given queryTyped
        Parameters:
        query - to be run
        parameters - to be added to the queryTyped
        accessMode - of the query that should be executed
        Returns:
        result
      • executeAll

        protected Iterable<S> executeAll​(String query,
                                         org.neo4j.driver.Value parameters,
                                         org.neo4j.driver.AccessMode accessMode)
        Helper function that simply executes a given queryTyped
        Parameters:
        query - to be run
        parameters - to be added to the queryTyped
        accessMode - of the query that should be executed
        Returns:
        result
      • deleteAll

        public void deleteAll()
        Description copied from interface: Neo4jRepository
        Deletes all science.neo4j.nodes in neo4j that are of type S
      • findAll

        public Iterable<S> findAll()
        Description copied from interface: Neo4jRepository
        Returns all node in neo4j that are of type S
        Returns:
        iterator over all S
      • findById

        public S findById​(Long id)
        Description copied from interface: Neo4jRepository
        Returns the node with the given id, or null if no such node exists
        Parameters:
        id - id of node
        Returns:
        node or null
      • findSubtree

        public S findSubtree​(Long aLong)
        Description copied from interface: Neo4jRepository
        Returns the entire subtree of the node with the given id, or null if no such node exists
        Parameters:
        aLong - id of node
        Returns:
        node with children (infinite depth!) or null
      • findSubtree

        public S findSubtree​(Long aLong,
                             int depth)
        Description copied from interface: Neo4jRepository
        Returns the entire subtree of the node with the given id, or null if no such node exists
        Parameters:
        aLong - id of node
        depth - depth until the subtree will be loaded (-1 is infinite, 0 is node only)
        Returns:
        node with children up to depth or null
      • findSubtree

        public S findSubtree​(Long aLong,
                             int depth,
                             List<String> relationships)
        Description copied from interface: Neo4jRepository
        Returns the entire subtree of the node with the given id, or null if no such node exists
        Parameters:
        aLong - id of node
        depth - depth until the subtree will be loaded (-1 is infinite, 0 is node only)
        relationships - that will be loaded (all non mentioned will be omitted)
        Returns:
        node with children up to depth or null
      • save

        public <T extends S> T save​(T relationship)
        Description copied from interface: Neo4jRepository
        Stores the node in the database. If the node has an ID a merge is conducted, if the ID is empty a new node is always created
        Type Parameters:
        T - subtype of S
        Parameters:
        relationship - node to be stored
        Returns:
        node with ID
      • saveAll

        public <T extends SIterable<T> saveAll​(Iterable<T> relationships)
        Description copied from interface: Neo4jRepository
        Saves all given science.neo4j.nodes (create or update)
        Type Parameters:
        T - subtype of S
        Parameters:
        relationships - to be saved
        Returns:
        science.neo4j.nodes with id
      • findBy

        public S findBy​(String condition,
                        org.neo4j.driver.Value parameters)
        Description copied from class: AbstractNeo4JRepository
        Returns the first node that satisfies the given condition. The condition may access the node with "n" Example: findByCondition("n.name = $name", Values.parameters("name", "Dijkstra"))
        Specified by:
        findBy in class AbstractNeo4JRepository<S,​Long>
        Parameters:
        condition - any condition that would be after the "WHERE" in a cypher queryTyped
        parameters - all parameters defined in the condition (parameters optional)
        Returns:
        first node that satisifes condition with parameters
      • findAllBy

        public Iterable<S> findAllBy​(String condition,
                                     org.neo4j.driver.Value parameters)
        Description copied from class: AbstractNeo4JRepository
        Returns ALL science.neo4j.nodes that satisfies the given condition. The condition may access the node with "n" Example: findByCondition("n.name in $names", Values.parameters("names", Values.parameters("Dijkstra", "Knuth", "Turing")))
        Specified by:
        findAllBy in class AbstractNeo4JRepository<S,​Long>
        Parameters:
        condition - any condition that would be after the "WHERE" in a cypher queryTyped
        parameters - all parameters defined in the condition (parameters optional)
        Returns:
        first node that satisifes condition with parameters
      • query

        public S query​(String query,
                       org.neo4j.driver.Value parameters)
        Convenience function that allows calling any user defined queryTyped. Parameters should be defined as "$parametername" The value-list should be defined as Map of parametername (without the $) to value
        Parameters:
        query - to be run
        parameters - to be set
        Returns:
        node that matches the queryTyped
      • queryAll

        public Iterable<S> queryAll​(String query,
                                    org.neo4j.driver.Value parameters)
        Convenience function that allows calling any user defined queryTyped. Parameters should be defined as "$parametername" The value-list should be defined as Map of parametername (without the $) to value
        Parameters:
        query - to be run
        parameters - to be set
        Returns:
        node that matches the queryTyped