public class Neo4jTemplate extends Object implements Neo4jOperations, ApplicationContextAware
GraphDatabaseService, the used
TypeRepresentationStrategy, entity instantiators for nodes and relationships as well as a spring conversion service.
It delegates the appropriate methods to those services. The services are not intended to be accessible from outside.| Modifier | Constructor and Description |
|---|---|
protected |
Neo4jTemplate() |
|
Neo4jTemplate(GraphDatabase graphDatabase) |
|
Neo4jTemplate(GraphDatabase graphDatabase,
PlatformTransactionManager transactionManager) |
|
Neo4jTemplate(org.neo4j.graphdb.GraphDatabaseService graphDatabaseService) |
|
Neo4jTemplate(Infrastructure infrastructure) |
| Modifier and Type | Method and Description |
|---|---|
<T> Result<T> |
convert(Iterable<T> iterable)
Converts the Iterable into a Result object for uniform handling.
|
<T> T |
convert(Object value,
Class<T> type)
Converts a single object according to the configured ResultConverter of the Neo4j-Template.
|
<T> long |
count(Class<T> entityClass)
Provies the instance count a given entity type using the typerepresentation strategy configured for this template.
|
<S extends org.neo4j.graphdb.PropertyContainer,T> |
createEntityFromState(S state,
Class<T> type,
MappingPolicy mappingPolicy) |
<S extends org.neo4j.graphdb.PropertyContainer,T> |
createEntityFromStoredType(S state,
MappingPolicy mappingPolicy) |
org.neo4j.graphdb.Node |
createNode()
Delegates to
GraphDatabaseService |
org.neo4j.graphdb.Node |
createNode(Map<String,Object> properties)
creates the node uniquely or returns an existing node with the same index-key-value combination.
|
<T> T |
createNodeAs(Class<T> target,
Map<String,Object> properties)
Creates a node mapped by the given entity class
|
org.neo4j.graphdb.Relationship |
createRelationshipBetween(org.neo4j.graphdb.Node startNode,
org.neo4j.graphdb.Node endNode,
String relationshipType,
Map<String,Object> properties)
Creates a relationship with the given initial properties.
|
<R> R |
createRelationshipBetween(Object start,
Object end,
Class<R> relationshipEntityClass,
String relationshipType,
boolean allowDuplicates)
Creates a single relationship entity between two node entities with the given relationship type projected to the provided
relationship entity class.
|
org.neo4j.graphdb.Node |
createUniqueNode(Object entity) |
void |
delete(Object entity)
Removes the given node or relationship entity or node or relationship from the graph, the entity is first removed
from all indexes and then deleted.
|
void |
deleteRelationshipBetween(Object start,
Object end,
String type)
Removes the relationship of this type between the two node entities
|
<T> T |
exec(GraphCallback<T> callback)
Executes the callback in a NON-transactional context.
|
<T> T |
fetch(T value)
fully loades the single entity or collection thereof which has been loaded lazily (i.e. just with the id but w/o values)
|
<T> EndResult<T> |
findAll(Class<T> entityClass)
Provides all instances of a given entity type using the typerepresentation strategy configured for this template.
|
<T> T |
findOne(long id,
Class<T> entityClass)
Retrieves a node or relationship and returns it mapped to the appropriate type
|
ConversionService |
getConversionService() |
ResultConverter |
getDefaultConverter() |
EntityStateHandler |
getEntityStateHandler() |
<T> StoredEntityType |
getEntityType(Class<T> target) |
GraphDatabase |
getGraphDatabase() |
org.neo4j.graphdb.GraphDatabaseService |
getGraphDatabaseService() |
<T extends org.neo4j.graphdb.PropertyContainer> |
getIndex(Class<?> indexedType,
String propertyName)
The index determined by the property of the indexed type is returned, so all the customization
via @Indexed annotations is taken into consideration.
|
<S extends org.neo4j.graphdb.PropertyContainer,T> |
getIndex(Class<T> type) |
<S extends org.neo4j.graphdb.PropertyContainer,T> |
getIndex(Class<T> type,
String indexName,
IndexType indexType) |
<S extends org.neo4j.graphdb.PropertyContainer> |
getIndex(Neo4jPersistentProperty property,
Class<?> instanceType) |
<S extends org.neo4j.graphdb.PropertyContainer> |
getIndex(String name) |
<T extends org.neo4j.graphdb.PropertyContainer> |
getIndex(String indexName,
Class<?> indexedType)
Retrieves an existing index for the given class and/or name
|
String |
getIndexKey(Neo4jPersistentProperty property) |
Infrastructure |
getInfrastructure() |
MappingPolicy |
getMappingPolicy(Class<?> targetType) |
MappingPolicy |
getMappingPolicy(Object entity) |
org.neo4j.graphdb.Node |
getNode(long id)
Delegates to the GraphDatabase
|
org.neo4j.graphdb.Node |
getOrCreateNode(String index,
String key,
Object value,
Map<String,Object> properties)
creates the node uniquely or returns an existing node with the same index-key-value combination.
|
org.neo4j.graphdb.Relationship |
getOrCreateRelationship(String indexName,
String key,
Object value,
org.neo4j.graphdb.Node startNode,
org.neo4j.graphdb.Node endNode,
String type,
Map<String,Object> properties)
Creates the relationship uniquely, uses the given index,key,value to achieve that.
|
Neo4jPersistentProperty |
getPersistentProperty(Class<?> type,
String propertyName) |
<S extends org.neo4j.graphdb.PropertyContainer> |
getPersistentState(Object entity)
just sets the persistent state (i.e.
|
org.neo4j.graphdb.Node |
getReferenceNode()
Returns the reference node.
|
org.neo4j.graphdb.Relationship |
getRelationship(long id)
Delegates to the GraphDatabase
|
<R> R |
getRelationshipBetween(Object start,
Object end,
Class<R> relationshipEntityClass,
String relationshipType)
Retrieves a single relationship entity between two node entities with the given relationship type projected to the provided
relationship entity class
|
org.neo4j.graphdb.Relationship |
getRelationshipBetween(Object start,
Object end,
String relationshipType)
Retrieves a single relationship entity between two node entities.
|
<R> Iterable<R> |
getRelationshipsBetween(Object start,
Object end,
Class<R> relationshipEntityClass,
String relationshipType)
Retrieves all relationship entities between two node entities with the given relationship type projected to the provided
relationship entity class
|
StoredEntityType |
getStoredEntityType(Object entity) |
Class |
getStoredJavaType(Object entity) |
javax.validation.Validator |
getValidator() |
<T extends org.neo4j.graphdb.PropertyContainer> |
index(String indexName,
T element,
String field,
Object value)
Indexes the given field and value for the element.
|
boolean |
isManaged(Object entity) |
boolean |
isNodeEntity(Class<?> targetType) |
boolean |
isRelationshipEntity(Class<?> targetType) |
<S extends org.neo4j.graphdb.PropertyContainer,T> |
load(S state,
Class<T> type)
loades the provided node or relationship to be used as an entity of the given type
|
<T extends org.neo4j.graphdb.PropertyContainer> |
lookup(Class<?> indexedType,
String propertyName,
Object value)
The value or query-object is looked up in the index indicated by the property of the indexed type, so all the customization
via @Indexed annotations is taken into consideration.
|
<T extends org.neo4j.graphdb.PropertyContainer> |
lookup(String indexName,
Object query)
The query is executed on the index returning the IndexHits wrapped in a Result to be converted
into Paths or Entities.
|
<T extends org.neo4j.graphdb.PropertyContainer> |
lookup(String indexName,
String field,
Object value)
The value is looked up in the Neo4j index returning the IndexHits wrapped in a Result to be converted
into Paths or Entities.
|
<S extends org.neo4j.graphdb.PropertyContainer,T> |
postEntityCreation(S node,
Class<T> entityClass)
Deprecated.
|
<T> T |
projectTo(Object entity,
Class<T> targetType)
Projects a node or relationship entity to a different type.
|
<T> T |
projectTo(Object entity,
Class<T> targetType,
MappingPolicy mappingPolicy) |
Result<Map<String,Object>> |
query(String statement,
Map<String,Object> params)
Runs the given cypher statement and packages the result in a Result, simple conversions via the
registered converter-factories are already executed via this method.
|
Object |
query(String statement,
Map<String,Object> params,
TypeInformation<?> typeInformation) |
<T> QueryEngine<T> |
queryEngineFor(QueryType type)
Provides a cypher query engine set up with a default entity converter.
|
<T> GraphRepository<T> |
repositoryFor(Class<T> clazz) |
<T> T |
save(T entity)
Stores the given entity in the graph, if the entity is already attached to the graph, the node is updated, otherwise
a new node is created.
|
<T> T |
save(T entity,
org.neo4j.graphdb.RelationshipType annotationProvidedRelationshipType) |
void |
setApplicationContext(ApplicationContext applicationContext) |
<S extends org.neo4j.graphdb.PropertyContainer,T> |
setPersistentState(T entity,
S state) |
boolean |
transactionIsRunning() |
DataAccessException |
translateExceptionIfPossible(Exception ex) |
org.neo4j.graphdb.traversal.TraversalDescription |
traversalDescription() |
Result<org.neo4j.graphdb.Path> |
traverse(org.neo4j.graphdb.Node startNode,
org.neo4j.graphdb.traversal.TraversalDescription traversal)
Traverses the graph starting at the given node with the provided traversal description.
|
<T> Iterable<T> |
traverse(Object entity,
Class<?> targetType,
org.neo4j.graphdb.traversal.TraversalDescription traversalDescription) |
Result<org.neo4j.graphdb.Path> |
traverse(Object start,
org.neo4j.graphdb.traversal.TraversalDescription traversal)
Traverses the graph starting at the given node entity with the provided traversal description.
|
protected Neo4jTemplate()
public Neo4jTemplate(GraphDatabase graphDatabase, PlatformTransactionManager transactionManager)
graphDatabase - the neo4j graph databasetransactionManager - if passed in, will be used to create implicit transactions whenever neededpublic Neo4jTemplate(GraphDatabase graphDatabase)
public Neo4jTemplate(org.neo4j.graphdb.GraphDatabaseService graphDatabaseService)
public Neo4jTemplate(Infrastructure infrastructure)
public <T> GraphRepository<T> repositoryFor(Class<T> clazz)
repositoryFor in interface Neo4jOperationspublic <S extends org.neo4j.graphdb.PropertyContainer,T> org.neo4j.graphdb.index.Index<S> getIndex(Class<T> type)
public <S extends org.neo4j.graphdb.PropertyContainer> org.neo4j.graphdb.index.Index<S> getIndex(String name)
public <S extends org.neo4j.graphdb.PropertyContainer,T> org.neo4j.graphdb.index.Index<S> getIndex(Class<T> type, String indexName, IndexType indexType)
public boolean transactionIsRunning()
public <T> T findOne(long id,
Class<T> entityClass)
Neo4jOperationsfindOne in interface Neo4jOperationspublic <T> EndResult<T> findAll(Class<T> entityClass)
Neo4jOperationsfindAll in interface Neo4jOperationspublic <T> long count(Class<T> entityClass)
Neo4jOperationscount in interface Neo4jOperationspublic <S extends org.neo4j.graphdb.PropertyContainer,T> T createEntityFromStoredType(S state,
MappingPolicy mappingPolicy)
public <S extends org.neo4j.graphdb.PropertyContainer,T> T createEntityFromState(S state,
Class<T> type,
MappingPolicy mappingPolicy)
public <S extends org.neo4j.graphdb.PropertyContainer,T> T load(S state,
Class<T> type)
Neo4jOperationsload in interface Neo4jOperationspublic <T> T projectTo(Object entity, Class<T> targetType)
Neo4jOperationsprojectTo in interface Neo4jOperationspublic <T> T projectTo(Object entity, Class<T> targetType, MappingPolicy mappingPolicy)
public <S extends org.neo4j.graphdb.PropertyContainer> S getPersistentState(Object entity)
getPersistentState in interface Neo4jOperationspublic <S extends org.neo4j.graphdb.PropertyContainer,T> T setPersistentState(T entity,
S state)
@Deprecated public <S extends org.neo4j.graphdb.PropertyContainer,T> void postEntityCreation(S node, Class<T> entityClass)
public void delete(Object entity)
Neo4jOperationsdelete in interface Neo4jOperationspublic org.neo4j.graphdb.Node createNode()
GraphDatabaseServicecreateNode in interface Neo4jOperationspublic org.neo4j.graphdb.Node createNode(Map<String,Object> properties)
createNode in interface Neo4jOperationsproperties - the properties that should be initially set on the nodepublic org.neo4j.graphdb.Node getOrCreateNode(String index, String key, Object value, Map<String,Object> properties)
getOrCreateNode in interface Neo4jOperationspublic <T> T createNodeAs(Class<T> target, Map<String,Object> properties)
Neo4jOperationscreateNodeAs in interface Neo4jOperationstarget - mapped entity class or Node.classproperties - the properties that should be initially set on the nodepublic <T> StoredEntityType getEntityType(Class<T> target)
public boolean isNodeEntity(Class<?> targetType)
public boolean isRelationshipEntity(Class<?> targetType)
public <T> T save(T entity)
Neo4jOperationssave in interface Neo4jOperationspublic <T> T save(T entity,
org.neo4j.graphdb.RelationshipType annotationProvidedRelationshipType)
public boolean isManaged(Object entity)
public Object query(String statement, Map<String,Object> params, TypeInformation<?> typeInformation)
public <R> R getRelationshipBetween(Object start, Object end, Class<R> relationshipEntityClass, String relationshipType)
Neo4jOperationsgetRelationshipBetween in interface Neo4jOperationspublic <R> Iterable<R> getRelationshipsBetween(Object start, Object end, Class<R> relationshipEntityClass, String relationshipType)
Neo4jOperationsgetRelationshipsBetween in interface Neo4jOperationspublic org.neo4j.graphdb.Relationship getRelationshipBetween(Object start, Object end, String relationshipType)
Neo4jOperationsgetRelationshipBetween in interface Neo4jOperationspublic void deleteRelationshipBetween(Object start, Object end, String type)
Neo4jOperationsdeleteRelationshipBetween in interface Neo4jOperationspublic <R> R createRelationshipBetween(Object start, Object end, Class<R> relationshipEntityClass, String relationshipType, boolean allowDuplicates)
Neo4jOperationscreateRelationshipBetween in interface Neo4jOperationspublic org.neo4j.graphdb.Relationship createRelationshipBetween(org.neo4j.graphdb.Node startNode,
org.neo4j.graphdb.Node endNode,
String relationshipType,
Map<String,Object> properties)
Neo4jOperationscreateRelationshipBetween in interface Neo4jOperationspublic org.neo4j.graphdb.Relationship getOrCreateRelationship(String indexName, String key, Object value, org.neo4j.graphdb.Node startNode, org.neo4j.graphdb.Node endNode, String type, Map<String,Object> properties)
Neo4jOperationsgetOrCreateRelationship in interface Neo4jOperationspublic DataAccessException translateExceptionIfPossible(Exception ex)
public <T> T exec(GraphCallback<T> callback)
Neo4jOperationsexec in interface Neo4jOperationsT - return typecallback - for executing graph operations NON-transactionally, not nullpublic org.neo4j.graphdb.Node getReferenceNode()
Neo4jOperationsgetReferenceNode in interface Neo4jOperationspublic org.neo4j.graphdb.Node getNode(long id)
Neo4jOperationsgetNode in interface Neo4jOperationsid - node idpublic org.neo4j.graphdb.Relationship getRelationship(long id)
Neo4jOperationsgetRelationship in interface Neo4jOperationsid - relationship idpublic <T extends org.neo4j.graphdb.PropertyContainer> T index(String indexName, T element, String field, Object value)
Neo4jOperationsindex in interface Neo4jOperationsT - the provided element typeindexName - Name of the index, will be checked against existing indexes according to the given element
assumes a "node" node index or "relationship" relationship index for a null valueelement - node or relationship to indexfield - field to indexvalue - value to indexpublic <T> T fetch(T value)
Neo4jOperationsfetch in interface Neo4jOperationspublic MappingPolicy getMappingPolicy(Class<?> targetType)
getMappingPolicy in interface Neo4jOperationspublic <T> Result<T> convert(Iterable<T> iterable)
Neo4jOperationsconvert in interface Neo4jOperationspublic <T> T convert(Object value, Class<T> type)
Neo4jOperationsconvert in interface Neo4jOperationspublic ResultConverter getDefaultConverter()
getDefaultConverter in interface Neo4jOperationspublic <T> QueryEngine<T> queryEngineFor(QueryType type)
Neo4jOperationsqueryEngineFor in interface Neo4jOperationspublic Result<Map<String,Object>> query(String statement, Map<String,Object> params)
Neo4jOperationsquery in interface Neo4jOperationspublic Result<org.neo4j.graphdb.Path> traverse(Object start, org.neo4j.graphdb.traversal.TraversalDescription traversal)
Neo4jOperationstraverse in interface Neo4jOperationspublic <T> Iterable<T> traverse(Object entity, Class<?> targetType, org.neo4j.graphdb.traversal.TraversalDescription traversalDescription)
public Result<org.neo4j.graphdb.Path> traverse(org.neo4j.graphdb.Node startNode, org.neo4j.graphdb.traversal.TraversalDescription traversal)
Neo4jOperationstraverse in interface Neo4jOperationspublic <T extends org.neo4j.graphdb.PropertyContainer> Result<T> lookup(String indexName, String field, Object value)
Neo4jOperationslookup in interface Neo4jOperationspublic <T extends org.neo4j.graphdb.PropertyContainer> Result<T> lookup(Class<?> indexedType, String propertyName, Object value)
Neo4jOperationslookup in interface Neo4jOperationspublic <T extends org.neo4j.graphdb.PropertyContainer> org.neo4j.graphdb.index.Index<T> getIndex(String indexName, Class<?> indexedType)
Neo4jOperationsgetIndex in interface Neo4jOperationsindexName - might be nullindexedType - entity class, might be nullpublic <T extends org.neo4j.graphdb.PropertyContainer> org.neo4j.graphdb.index.Index<T> getIndex(Class<?> indexedType, String propertyName)
Neo4jOperationsgetIndex in interface Neo4jOperationspublic Neo4jPersistentProperty getPersistentProperty(Class<?> type, String propertyName)
public <T extends org.neo4j.graphdb.PropertyContainer> Result<T> lookup(String indexName, Object query)
Neo4jOperationslookup in interface Neo4jOperationspublic org.neo4j.graphdb.traversal.TraversalDescription traversalDescription()
traversalDescription in interface Neo4jOperationspublic EntityStateHandler getEntityStateHandler()
public ConversionService getConversionService()
public javax.validation.Validator getValidator()
public org.neo4j.graphdb.GraphDatabaseService getGraphDatabaseService()
public Infrastructure getInfrastructure()
public GraphDatabase getGraphDatabase()
getGraphDatabase in interface Neo4jOperationspublic String getIndexKey(Neo4jPersistentProperty property)
public <S extends org.neo4j.graphdb.PropertyContainer> org.neo4j.graphdb.index.Index<S> getIndex(Neo4jPersistentProperty property, Class<?> instanceType)
public MappingPolicy getMappingPolicy(Object entity)
public StoredEntityType getStoredEntityType(Object entity)
public Class getStoredJavaType(Object entity)
getStoredJavaType in interface Neo4jOperationspublic org.neo4j.graphdb.Node createUniqueNode(Object entity)
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException
setApplicationContext in interface ApplicationContextAwareBeansExceptionCopyright © 2011-2013-2013 Pivotal. All Rights Reserved.