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)
properties are used to initialize the node.
|
org.neo4j.graphdb.Node |
createNode(Map<String,Object> properties,
Collection<String> labels)
properties are used to initialize the node.
|
<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
|
<T> T |
findUniqueEntity(Class<T> entityClass,
String propertyName,
Object value)
Returns the unique entity of type entityClass (if it exists) otherwise returns null.
|
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)
Deprecated.
|
<S extends org.neo4j.graphdb.PropertyContainer,T> |
getIndex(Class<T> type,
String indexName,
IndexType indexType)
Deprecated.
|
<S extends org.neo4j.graphdb.PropertyContainer> |
getIndex(Neo4jPersistentProperty property,
Class<?> instanceType) |
<S extends org.neo4j.graphdb.PropertyContainer> |
getIndex(String name)
Deprecated.
|
<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,
Collection<String> labels)
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.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 |
isLabelBased() |
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.
|
org.neo4j.graphdb.Node |
merge(String label,
String key,
Object value,
Map<String,Object> properties,
Collection<String> labels)
creates the node uniquely or returns an existing node with the same label-key-value combination.
|
<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> CypherQueryEngine |
queryEngineFor()
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 Neo4jOperations
@Deprecated public <S extends org.neo4j.graphdb.PropertyContainer,T> org.neo4j.graphdb.index.Index<S> getIndex(Class<T> type)
@Deprecated public <S extends org.neo4j.graphdb.PropertyContainer> org.neo4j.graphdb.index.Index<S> getIndex(String name)
@Deprecated public <S extends org.neo4j.graphdb.PropertyContainer,T> org.neo4j.graphdb.index.Index<S> getIndex(Class<T> type, String indexName, IndexType indexType)
public <T> T findUniqueEntity(Class<T> entityClass, String propertyName, Object value)
T
- the entityentityClass
- Entity classpropertyName
- Name of uniquely indexed propertyvalue
- value of property to findpublic boolean transactionIsRunning()
public <T> T findOne(long id, Class<T> entityClass)
Neo4jOperations
findOne
in interface Neo4jOperations
public <T> EndResult<T> findAll(Class<T> entityClass)
Neo4jOperations
findAll
in interface Neo4jOperations
public <T> long count(Class<T> entityClass)
Neo4jOperations
count
in interface Neo4jOperations
public <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)
Neo4jOperations
load
in interface Neo4jOperations
public <T> T projectTo(Object entity, Class<T> targetType)
Neo4jOperations
projectTo
in interface Neo4jOperations
public <T> T projectTo(Object entity, Class<T> targetType, MappingPolicy mappingPolicy)
public <S extends org.neo4j.graphdb.PropertyContainer> S getPersistentState(Object entity)
getPersistentState
in interface Neo4jOperations
public <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)
Neo4jOperations
delete
in interface Neo4jOperations
public org.neo4j.graphdb.Node createNode()
GraphDatabaseService
createNode
in interface Neo4jOperations
public org.neo4j.graphdb.Node createNode(Map<String,Object> properties)
createNode
in interface Neo4jOperations
properties
- the properties that should be initially set on the nodepublic org.neo4j.graphdb.Node createNode(Map<String,Object> properties, Collection<String> labels)
createNode
in interface Neo4jOperations
public org.neo4j.graphdb.Node getOrCreateNode(String index, String key, Object value, Map<String,Object> properties, Collection<String> labels)
getOrCreateNode
in interface Neo4jOperations
public org.neo4j.graphdb.Node merge(String label, String key, Object value, Map<String,Object> properties, Collection<String> labels)
merge
in interface Neo4jOperations
public <T> T createNodeAs(Class<T> target, Map<String,Object> properties)
Neo4jOperations
createNodeAs
in interface Neo4jOperations
target
- 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 boolean isLabelBased()
public <T> T save(T entity)
Neo4jOperations
save
in interface Neo4jOperations
public <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)
Neo4jOperations
getRelationshipBetween
in interface Neo4jOperations
public <R> Iterable<R> getRelationshipsBetween(Object start, Object end, Class<R> relationshipEntityClass, String relationshipType)
Neo4jOperations
getRelationshipsBetween
in interface Neo4jOperations
public org.neo4j.graphdb.Relationship getRelationshipBetween(Object start, Object end, String relationshipType)
Neo4jOperations
getRelationshipBetween
in interface Neo4jOperations
public void deleteRelationshipBetween(Object start, Object end, String type)
Neo4jOperations
deleteRelationshipBetween
in interface Neo4jOperations
public <R> R createRelationshipBetween(Object start, Object end, Class<R> relationshipEntityClass, String relationshipType, boolean allowDuplicates)
Neo4jOperations
createRelationshipBetween
in interface Neo4jOperations
public org.neo4j.graphdb.Relationship createRelationshipBetween(org.neo4j.graphdb.Node startNode, org.neo4j.graphdb.Node endNode, String relationshipType, Map<String,Object> properties)
Neo4jOperations
createRelationshipBetween
in interface Neo4jOperations
public 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)
Neo4jOperations
getOrCreateRelationship
in interface Neo4jOperations
public DataAccessException translateExceptionIfPossible(Exception ex)
public <T> T exec(GraphCallback<T> callback)
Neo4jOperations
exec
in interface Neo4jOperations
T
- return typecallback
- for executing graph operations NON-transactionally, not nullpublic org.neo4j.graphdb.Node getNode(long id)
Neo4jOperations
getNode
in interface Neo4jOperations
id
- node idpublic org.neo4j.graphdb.Relationship getRelationship(long id)
Neo4jOperations
getRelationship
in interface Neo4jOperations
id
- relationship idpublic <T extends org.neo4j.graphdb.PropertyContainer> T index(String indexName, T element, String field, Object value)
Neo4jOperations
index
in interface Neo4jOperations
T
- 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)
Neo4jOperations
fetch
in interface Neo4jOperations
public MappingPolicy getMappingPolicy(Class<?> targetType)
getMappingPolicy
in interface Neo4jOperations
public <T> Result<T> convert(Iterable<T> iterable)
Neo4jOperations
convert
in interface Neo4jOperations
public <T> T convert(Object value, Class<T> type)
Neo4jOperations
convert
in interface Neo4jOperations
public ResultConverter getDefaultConverter()
getDefaultConverter
in interface Neo4jOperations
public <T> CypherQueryEngine queryEngineFor()
Neo4jOperations
queryEngineFor
in interface Neo4jOperations
public Result<Map<String,Object>> query(String statement, Map<String,Object> params)
Neo4jOperations
query
in interface Neo4jOperations
public Result<org.neo4j.graphdb.Path> traverse(Object start, org.neo4j.graphdb.traversal.TraversalDescription traversal)
Neo4jOperations
traverse
in interface Neo4jOperations
public <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)
Neo4jOperations
traverse
in interface Neo4jOperations
public <T extends org.neo4j.graphdb.PropertyContainer> Result<T> lookup(String indexName, String field, Object value)
Neo4jOperations
lookup
in interface Neo4jOperations
public <T extends org.neo4j.graphdb.PropertyContainer> Result<T> lookup(Class<?> indexedType, String propertyName, Object value)
Neo4jOperations
lookup
in interface Neo4jOperations
public <T extends org.neo4j.graphdb.PropertyContainer> org.neo4j.graphdb.index.Index<T> getIndex(String indexName, Class<?> indexedType)
Neo4jOperations
getIndex
in interface Neo4jOperations
indexName
- 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)
Neo4jOperations
getIndex
in interface Neo4jOperations
public Neo4jPersistentProperty getPersistentProperty(Class<?> type, String propertyName)
public <T extends org.neo4j.graphdb.PropertyContainer> Result<T> lookup(String indexName, Object query)
Neo4jOperations
lookup
in interface Neo4jOperations
public org.neo4j.graphdb.traversal.TraversalDescription traversalDescription()
traversalDescription
in interface Neo4jOperations
public 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 Neo4jOperations
public 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 Neo4jOperations
public org.neo4j.graphdb.Node createUniqueNode(Object entity)
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException
setApplicationContext
in interface ApplicationContextAware
BeansException
Copyright © 2011-2014-2014 Pivotal. All Rights Reserved.