public class Neo4jTemplate extends Object implements Neo4jOperations, ApplicationEventPublisherAware
Neo4jOperations. Indeed, framework users are encouraged
to favour coding against the Neo4jOperations interface rather than the Neo4jTemplate directly, as the
interface API will be more consistent over time and enhanced proxy objects of the interface may actually be created by Spring
for auto-wiring instead of this template.
Note that this class also implements ApplicationEventPublisherAware and will publish events before data manipulation
operations - specifically delete and save.
DataAccessException if any underlying Exception is
thrown. Since DataAccessException is a runtime exception, this is not documented at the method level.| Constructor and Description |
|---|
Neo4jTemplate(org.neo4j.ogm.session.Session session)
Constructs a new
Neo4jTemplate based on the given Neo4j OGM Session. |
| Modifier and Type | Method and Description |
|---|---|
void |
clear()
Removes all mapping information from the current session
|
long |
count(Class<?> entityClass)
Provides the instance count for the given node entity type.
|
void |
delete(Object entity)
Removes the given node or relationship entity from the graph.
|
<T> void |
deleteAll(Class<T> type)
Removes all nodes or relationship entities of a specific type from the graph.
|
org.neo4j.ogm.model.QueryStatistics |
execute(String jsonStatements)
Issue a single Cypher update operation (such as a CREATE, MERGE or DELETE statement).
|
org.neo4j.ogm.model.QueryStatistics |
execute(String cypher,
Map<String,Object> parameters)
Allows a cypher statement with a modification statement to be executed.
|
<T> T |
load(Class<T> type,
Long id)
Loads an entity of type T that matches the specified ID to the default depth.
|
<T> T |
load(Class<T> type,
Long id,
int depth)
Loads an entity of type T that matches the specified ID to the given depth.
|
<T> Collection<T> |
loadAll(Class<T> type)
Retrieves all the entities of the given class in the database hydrated to the default depth.
|
<T> Collection<T> |
loadAll(Class<T> type,
Collection<Long> ids) |
<T> Collection<T> |
loadAll(Class<T> type,
Collection<Long> ids,
int depth)
Reloads all of the entities which match IDs in the given
Collection to the specified depth. |
<T> Collection<T> |
loadAll(Class<T> type,
Collection<Long> ids,
org.neo4j.ogm.cypher.query.SortOrder sortOrder,
int depth)
Reloads all of the entities in the given
Collection to the specified depth, sorted by the sprcified SortOrder Of course, this will
only work for persistent objects (i.e., those with a non-null @GraphId field). |
<T> Collection<T> |
loadAll(Class<T> type,
int depth)
Retrieves all the entities of the given class in the database hydrated to the specified depth.
|
<T> Collection<T> |
loadAll(Class<T> type,
org.neo4j.ogm.cypher.query.SortOrder sortOrder,
int depth)
Retrieves all the entities of the given class in the database hydrated to the specified depth, with Sorting.
|
<T> Collection<T> |
loadAll(Class<T> type,
org.neo4j.ogm.cypher.query.SortOrder sortOrder,
org.neo4j.ogm.cypher.query.Pagination pagination,
int depth)
Retrieves all the entities of the given class in the database hydrated to the specified depth, with Sorting and Pagination.
|
<T> Collection<T> |
loadAll(Collection<T> objects) |
<T> Collection<T> |
loadAll(Collection<T> objects,
int depth)
Reloads all of the entities in the given
Collection to the specified depth. |
<T> Collection<T> |
loadAllByProperties(Class<T> type,
org.neo4j.ogm.cypher.Filters parameters)
Retrieves all the entities of the specified type that contain a properties matching the ones supplied with given name and value.
|
<T> Collection<T> |
loadAllByProperties(Class<T> type,
org.neo4j.ogm.cypher.Filters parameters,
int depth)
Retrieves all the entities of the specified type that contain a properties matching the ones supplied with given name and value.
|
<T> Collection<T> |
loadAllByProperty(Class<T> type,
String name,
Object value)
Retrieves all the entities of the specified type that contain a property matching the given name with the given value.
|
<T> Collection<T> |
loadAllByProperty(Class<T> type,
String name,
Object value,
int depth)
Retrieves all the entities of the specified type that contain a property matching the given name with the given value.
|
<T> T |
loadByProperties(Class<T> type,
org.neo4j.ogm.cypher.Filters parameters)
Retrieves the entity of the specified type that contains properties matching the ones supplied with given name and value.
|
<T> T |
loadByProperties(Class<T> type,
org.neo4j.ogm.cypher.Filters parameters,
int depth)
Retrieves the entity of the specified type that contains properties matching the ones supplied with given name and value.
|
<T> T |
loadByProperty(Class<T> type,
String propertyName,
Object propertyValue)
Retrieves the entity of the specified type that contains a property matching the given name with the given value.
|
<T> T |
loadByProperty(Class<T> type,
String propertyName,
Object propertyValue,
int depth)
Retrieves the entity of the specified type that contains a property matching the given name with the given value.
|
<T> T |
loadByPropertyOrNull(Class<T> type,
String propertyName,
Object propertyValue) |
void |
purgeSession() |
org.neo4j.ogm.model.Result |
query(String cypher,
Map<String,?> parameters)
|
org.neo4j.ogm.model.Result |
query(String cypher,
Map<String,?> parameters,
boolean readOnly)
Given a cypher statement this method will return a
Query object containing a collection of Map's which represent Neo4j
objects as properties, along with query statistics if applicable. |
<T> T |
queryForObject(Class<T> objectType,
String cypher,
Map<String,?> parameters)
Runs the specified Cypher query with the given parameters against the underlying Neo4j database and returns the result
marshalled as an object of the requested type.
|
<T> Iterable<T> |
queryForObjects(Class<T> objectType,
String cypher,
Map<String,?> parameters)
Runs the specified Cypher query with the given parameters against the underlying Neo4j database and returns the result
marshalled as a group of objects of the requested type.
|
<T> T |
save(T entity)
Saves the specified entity in the graph database.
|
<T> T |
save(T entity,
int depth)
Saves the specified entity in the graph database to a custom depth.
|
void |
setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) |
@Autowired public Neo4jTemplate(org.neo4j.ogm.session.Session session)
Neo4jTemplate based on the given Neo4j OGM Session.session - The Neo4j OGM session upon which to base the templatepublic void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher)
setApplicationEventPublisher in interface ApplicationEventPublisherAwarepublic <T> T load(Class<T> type, Long id)
Neo4jOperationsload in interface Neo4jOperationstype - The type of entity to loadid - The ID of the node or relationship to matchnull if no match is foundpublic <T> T load(Class<T> type, Long id, int depth)
Neo4jOperationsload in interface Neo4jOperationstype - The type of entity to loadid - The ID of the node or relationship to matchdepth - The maximum number of relationships away from the identified object to follow when loading related entities.
A value of 0 just loads the object's properties and no related entities. A value of -1 implies no depth limit.null if no match is foundpublic <T> Collection<T> loadAll(Class<T> type, Collection<Long> ids)
public <T> Collection<T> loadAll(Class<T> type, Collection<Long> ids, int depth)
Neo4jOperationsCollection to the specified depth. Of course, this will
only work for persistent objects (i.e., those with a non-null @GraphId field).loadAll in interface Neo4jOperationstype - The type of entity to return.ids - The IDs of objects to re-hydratedepth - The depth to which the objects should be hydratedCollection of entities matching those in the given collection hydrated to the given depthpublic <T> Collection<T> loadAll(Class<T> type)
Neo4jOperationsloadAll in interface Neo4jOperationstype - The type of entity to return.Collection containing all instances of the given type in the database or an empty collection if none
are found, never nullpublic <T> Collection<T> loadAll(Class<T> type, int depth)
Neo4jOperationsloadAll in interface Neo4jOperationstype - The type of entity to return.depth - The maximum number of relationships away from each loaded object to follow when loading related entities.
A value of 0 just loads the object's properties and no related entities. A value of -1 implies no depth limit.Collection containing all instances of the given type in the database or an empty collection if none
are found, never nullpublic <T> Collection<T> loadAll(Class<T> type, org.neo4j.ogm.cypher.query.SortOrder sortOrder, int depth)
Neo4jOperationsloadAll in interface Neo4jOperationstype - The type of entity to return.sortOrder - The SortOrder to be applieddepth - The maximum number of relationships away from each loaded object to follow when loading related entities.
A value of 0 just loads the object's properties and no related entities. A value of -1 implies no depth limit.Collection containing all instances of the given type in the database or an empty collection if none
are found, never nullpublic <T> Collection<T> loadAll(Class<T> type, org.neo4j.ogm.cypher.query.SortOrder sortOrder, org.neo4j.ogm.cypher.query.Pagination pagination, int depth)
Neo4jOperationsloadAll in interface Neo4jOperationstype - The type of entity to return.sortOrder - The SortOrder to be appliedpagination - The Pagination to be applieddepth - The maximum number of relationships away from each loaded object to follow when loading related entities.
A value of 0 just loads the object's properties and no related entities. A value of -1 implies no depth limit.Collection containing all instances of the given type in the database or an empty collection if none
are found, never nullpublic <T> Collection<T> loadAll(Collection<T> objects)
public <T> Collection<T> loadAll(Collection<T> objects, int depth)
Neo4jOperationsCollection to the specified depth. Of course, this will
only work for persistent objects (i.e., those with a non-null @GraphId field).loadAll in interface Neo4jOperationsobjects - The objects to re-hydratedepth - The depth to which the objects should be hydratedCollection of entities matching those in the given collection hydrated to the given depthpublic <T> Collection<T> loadAll(Class<T> type, Collection<Long> ids, org.neo4j.ogm.cypher.query.SortOrder sortOrder, int depth)
Neo4jOperationsCollection to the specified depth, sorted by the sprcified SortOrder Of course, this will
only work for persistent objects (i.e., those with a non-null @GraphId field).loadAll in interface Neo4jOperationsids - The IDs of objects to re-hydratesortOrder - The SortOrder to be useddepth - The depth to which the objects should be hydratedCollection of entities matching those in the given collection hydrated to the given depthpublic <T> T loadByProperty(Class<T> type, String propertyName, Object propertyValue)
Neo4jOperationsNeo4jOperations.loadAllByProperty(Class, String, Object) instead.loadByProperty in interface Neo4jOperationstype - The type of entity to loadpropertyName - The name of the property on the entity against which to match the given valuepropertyValue - The value of the named property against which to match entitiesnullpublic <T> T loadByProperty(Class<T> type, String propertyName, Object propertyValue, int depth)
Neo4jOperationsNeo4jOperations.loadAllByProperty(Class, String, Object) instead.loadByProperty in interface Neo4jOperationstype - The type of entity to loadpropertyName - The name of the property on the entity against which to match the given valuepropertyValue - The value of the named property against which to match entitiesdepth - The maximum number of relationships away from each loaded object to follow when loading related entities.
A value of 0 just loads the object's properties and no related entities. A value of -1 implies no depth limit.nullpublic <T> T loadByPropertyOrNull(Class<T> type, String propertyName, Object propertyValue)
public <T> Collection<T> loadAllByProperty(Class<T> type, String name, Object value)
Neo4jOperationsloadAllByProperty in interface Neo4jOperationstype - The type of entity to loadname - The name of the property on the entity against which to match the given valuevalue - The value of the named property against which to match entitiesCollection containing all the entities that match the given property or an empty Collection if
there aren't any matches, never nullpublic <T> T loadByProperties(Class<T> type, org.neo4j.ogm.cypher.Filters parameters)
Neo4jOperationsNeo4jOperations.loadAllByProperty(Class, String, Object) instead.loadByProperties in interface Neo4jOperationstype - The type of entity to loadparameters - The parameters to filter bynullpublic <T> T loadByProperties(Class<T> type, org.neo4j.ogm.cypher.Filters parameters, int depth)
Neo4jOperationsNeo4jOperations.loadAllByProperty(Class, String, Object) instead.loadByProperties in interface Neo4jOperationstype - The type of entity to loadparameters - The parameters to filter bydepth - The maximum number of relationships away from each loaded object to follow when loading related entities.
A value of 0 just loads the object's properties and no related entities. A value of -1 implies no depth limit.nullpublic <T> Collection<T> loadAllByProperties(Class<T> type, org.neo4j.ogm.cypher.Filters parameters)
Neo4jOperationsloadAllByProperties in interface Neo4jOperationstype - The type of entity to loadparameters - The parameters to filter byCollection containing all the entities that match the given properties or an empty Collection if
there aren't any matches, never nullpublic <T> Collection<T> loadAllByProperties(Class<T> type, org.neo4j.ogm.cypher.Filters parameters, int depth)
Neo4jOperationsloadAllByProperties in interface Neo4jOperationstype - The type of entity to loadparameters - The parameters to filter bydepth - The maximum number of relationships away from each loaded object to follow when loading related entities.
A value of 0 just loads the object's properties and no related entities. A value of -1 implies no depth limit.Collection containing all the entities that match the given properties or an empty Collection if
there aren't any matches, never nullpublic <T> Collection<T> loadAllByProperty(Class<T> type, String name, Object value, int depth)
Neo4jOperationsloadAllByProperty in interface Neo4jOperationstype - The type of entity to loadname - The name of the property on the entity against which to match the given valuevalue - The value of the named property against which to match entitiesdepth - The maximum number of relationships away from each loaded object to follow when loading related entities.
A value of 0 just loads the object's properties and no related entities. A value of -1 implies no depth limit.Collection containing all the entities that match the given property or an empty Collection if
there aren't any matches, never nullpublic void delete(Object entity)
Neo4jOperationsdelete in interface Neo4jOperationsentity - The entity to deletepublic void clear()
Neo4jOperationsclear in interface Neo4jOperationspublic <T> void deleteAll(Class<T> type)
Neo4jOperationsdeleteAll in interface Neo4jOperationstype - the type of entity to deletepublic org.neo4j.ogm.model.QueryStatistics execute(String jsonStatements)
Neo4jOperationsexecute in interface Neo4jOperationsjsonStatements - The Cypher query to executeQueryStatistics representing statistics about graph modifications as a result of the cypher execution.public org.neo4j.ogm.model.QueryStatistics execute(String cypher, Map<String,Object> parameters)
Neo4jOperationsParameters may be scalars or domain objects themselves.
execute in interface Neo4jOperationscypher - The parametrisable cypher to execute.parameters - Any parameters to attach to the cypher. These may be domain objects or scalars. Note that
if a complex domain object is provided only the properties of that object will be set.
If relationships of a provided object also need to be set then the cypher should reflect this
and further domain object parameters provided.QueryStatistics representing statistics about graph modifications as a result of the cypher execution.public void purgeSession()
public <T> T save(T entity)
Neo4jOperationssave in interface Neo4jOperationsentity - The entity to savepublic <T> T save(T entity,
int depth)
Neo4jOperationssave in interface Neo4jOperationsentity - The entity to savedepth - The maximum number of relationships away from the entity to follow when saving related entities.
A value of 0 just saves the object's properties and no related entities. A value of -1 implies no depth limit.public org.neo4j.ogm.model.Result query(String cypher, Map<String,?> parameters)
Neo4jOperationsIterable of Maps.
Each of the resultant maps corresponds to a "row" in the result set and the key set in each map contains all the names
contained in the RETURN clause of the given query.
query in interface Neo4jOperationscypher - The Cypher query to executeparameters - The parameter to merge into the cypher query or an empty Map if the given query isn't parameterisedQuery containing an Iterable map representing query results and QueryStatistics if applicable.public <T> Iterable<T> queryForObjects(Class<T> objectType, String cypher, Map<String,?> parameters)
Neo4jOperationsqueryForObjects in interface Neo4jOperationsobjectType - The Class denoting the type of entity to returncypher - The Cypher query to executeparameters - The parameter to merge into the Cypher query or an empty Map if the query's not parameterisedIterable over the entities found by executing the query or an empty Iterable if nothing
is found by the query, never nullpublic org.neo4j.ogm.model.Result query(String cypher, Map<String,?> parameters, boolean readOnly)
Neo4jOperationsQuery object containing a collection of Map's which represent Neo4j
objects as properties, along with query statistics if applicable.
Each element of the query result is a map which you can access by the name of the returned field
TODO: Are we going to use the neo4jOperations conversion method to cast the value object to its proper class?query in interface Neo4jOperationscypher - The parametrisable cypher to execute.parameters - Any parameters to attach to the cypher.readOnly - true if the query is readOnly, false otherwiseQuery of Iterables with each entry representing a neo4j object's properties.public <T> T queryForObject(Class<T> objectType, String cypher, Map<String,?> parameters)
Neo4jOperationsqueryForObject in interface Neo4jOperationsobjectType - The Class denoting the type of entity to returncypher - The Cypher query to executeparameters - The parameter to merge into the Cypher query or an empty Map if the query's not parameterisednull if nothing is
found by the querypublic long count(Class<?> entityClass)
Neo4jOperationscount in interface Neo4jOperationsentityClass - The Class representing the type of node entity to countCopyright © 2011–2017 Pivotal Software, Inc.. All rights reserved.