Package science.aist.neo4j.repository
Class AbstractNeo4JRelationshipRepositoyImpl<S>
- java.lang.Object
-
- science.aist.neo4j.repository.AbstractNeo4JRepository<S,Long>
-
- science.aist.neo4j.repository.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 Summary
Constructors Modifier Constructor Description protected
AbstractNeo4JRelationshipRepositoyImpl(TransactionManager manager)
empty constructor for child-implementations.protected
AbstractNeo4JRelationshipRepositoyImpl(TransactionManager manager, String className)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description 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 classvoid
deleteAll()
Deletes all science.neo4j.nodes in neo4j that are of type Sprotected S
execute(String query, org.neo4j.driver.Value parameters, org.neo4j.driver.AccessMode accessMode)
Helper function that simply executes a given queryTypedprotected Iterable<S>
executeAll(String query, org.neo4j.driver.Value parameters, org.neo4j.driver.AccessMode accessMode)
Helper function that simply executes a given queryTypedIterable<S>
findAll()
Returns all node in neo4j that are of type SIterable<S>
findAllBy(String condition, org.neo4j.driver.Value parameters)
Returns ALL science.neo4j.nodes that satisfies the given condition.S
findBy(String condition, org.neo4j.driver.Value parameters)
Returns the first node that satisfies the given condition.S
findById(Long id)
Returns the node with the given id, or null if no such node existsS
findSubtree(Long aLong)
Returns the entire subtree of the node with the given id, or null if no such node existsS
findSubtree(Long aLong, int depth)
Returns the entire subtree of the node with the given id, or null if no such node existsS
findSubtree(Long aLong, int depth, List<String> relationships)
Returns the entire subtree of the node with the given id, or null if no such node existsprotected abstract Long
getId(S relationship)
Helper method for finding the id of a nodeprotected abstract <T extends S>
Collection<T>handleSourceAndTarget(Collection<T> nodes)
Helper method that is responsible for storing all source or target science.neo4j.nodes in a multitude of relationshipsprotected abstract <T extends S>
ThandleSourceAndTarget(T node)
Helper method that is responsible for storing source or target science.neo4j.nodes.protected void
init(String className, String labels)
protected abstract Map<String,Object>
objectify(S relationship)
Turns all properties of a Relationship into something to be used by the queriesS
query(String query, org.neo4j.driver.Value parameters)
Convenience function that allows calling any user defined queryTyped.Iterable<S>
queryAll(String query, org.neo4j.driver.Value parameters)
Convenience function that allows calling any user defined queryTyped.<T extends S>
Tsave(T relationship)
Stores the node in the database.<T extends S>
Iterable<T>saveAll(Iterable<T> relationships)
Saves all given science.neo4j.nodes (create or update)protected abstract S
setId(S relationship, Long id)
Helper method for setting the id when a node was stored to the database-
Methods inherited from class science.aist.neo4j.repository.AbstractNeo4JRepository
buildParameters, buildWhere, findAllBy, findAllBy, findBy, findBy, getProvidedRepository, getTransactionManager, provideRepository
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface science.aist.neo4j.Neo4jRepository
findAllAsStream
-
-
-
-
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
-
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 castsource
- source node of relationshiptarget
- 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 idid
- 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 S> Collection<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 runparameters
- to be added to the queryTypedaccessMode
- 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 runparameters
- to be added to the queryTypedaccessMode
- 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 nodedepth
- 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 nodedepth
- 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 S> Iterable<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 classAbstractNeo4JRepository<S,Long>
- Parameters:
condition
- any condition that would be after the "WHERE" in a cypher queryTypedparameters
- 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 classAbstractNeo4JRepository<S,Long>
- Parameters:
condition
- any condition that would be after the "WHERE" in a cypher queryTypedparameters
- 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 runparameters
- 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 runparameters
- to be set- Returns:
- node that matches the queryTyped
-
-