java.lang.Object
org.springframework.data.neo4j.core.Neo4jTemplate
- All Implemented Interfaces:
Aware,BeanClassLoaderAware,BeanFactoryAware,FluentFindOperation,FluentNeo4jOperations,FluentSaveOperation,Neo4jOperations
@API(status=STABLE,
since="6.0")
public final class Neo4jTemplate
extends Object
implements Neo4jOperations, FluentNeo4jOperations, BeanClassLoaderAware, BeanFactoryAware
- Since:
- 6.0
- Author:
- Michael J. Simons, Philipp T��lle, Gerrit Meier, Corey Beres
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.springframework.data.neo4j.core.FluentFindOperation
FluentFindOperation.ExecutableFind<T>, FluentFindOperation.FindWithProjection<T>, FluentFindOperation.FindWithQuery<T>, FluentFindOperation.TerminatingFind<T>, FluentFindOperation.TerminatingFindWithoutQuery<T>Nested classes/interfaces inherited from interface org.springframework.data.neo4j.core.FluentSaveOperation
FluentSaveOperation.ExecutableSave<DT>Nested classes/interfaces inherited from interface org.springframework.data.neo4j.core.Neo4jOperations
Neo4jOperations.ExecutableQuery<T> -
Constructor Summary
ConstructorsConstructorDescriptionNeo4jTemplate(Neo4jClient neo4jClient) Neo4jTemplate(Neo4jClient neo4jClient, Neo4jMappingContext neo4jMappingContext) Neo4jTemplate(Neo4jClient neo4jClient, Neo4jMappingContext neo4jMappingContext, EntityCallbacks entityCallbacks) Neo4jTemplate(Neo4jClient neo4jClient, Neo4jMappingContext neo4jMappingContext, EntityCallbacks entityCallbacks, PlatformTransactionManager platformTransactionManager) Neo4jTemplate(Neo4jClient neo4jClient, Neo4jMappingContext neo4jMappingContext, PlatformTransactionManager transactionManager) -
Method Summary
Modifier and TypeMethodDescriptionlongCounts the number of entities of a given type.longCounts the number of entities of a given type.longCounts the number of entities of a given type.longcount(org.neo4j.cypherdsl.core.Statement statement) Counts the number of entities of a given type.longCounts the number of entities of a given type.voidDelete all entities of a given type.<T> voiddeleteAllById(Iterable<?> ids, Class<T> domainType) Deletes all entities with one of the given ids, including all entities related to that entity.<T> voiddeleteById(Object id, Class<T> domainType) Deletes a single entity including all entities related to that entity.<T> voiddeleteByIdWithVersion(Object id, Class<T> domainType, Neo4jPersistentProperty versionProperty, Object versionValue) <T> booleanexistsById(Object id, Class<T> domainType) Check if an entity for a given id exists in the database.Start creating a find operation for the given domainType.<T> List<T>Load all entities of a given type.<T> List<T>Load all entities of a given type by executing given statement.<T> List<T>Load all entities of a given type by executing given statement with parameters.<T> List<T>Load all entities of a given type by executing given statement.<T> List<T>findAll(org.neo4j.cypherdsl.core.Statement statement, Map<String, Object> parameters, Class<T> domainType) Load all entities of a given type by executing given statement with parameters.<T> List<T>findAllById(Iterable<?> ids, Class<T> domainType) Load all entities of a given type that are identified by the given ids.<T> Optional<T>Load an entity from the database.<T> Optional<T>Load one entity of a given type by executing given statement with parameters.<T> Optional<T>findOne(org.neo4j.cypherdsl.core.Statement statement, Map<String, Object> parameters, Class<T> domainType) Load one entity of a given type by executing given statement with parameters.Start creating a save operation for the given domainType.<T> Tsave(T instance) Saves an instance of an entity, including all the related entities of the entity.<T> List<T>Saves several instances of an entity, including all the related entities of the entity.<T,R> List<R> Saves an instance of an entity, including the properties and relationship defined by the projectresultType.<T> List<T>saveAllAs(Iterable<T> instances, BiPredicate<PropertyPath, Neo4jPersistentProperty> includeProperty) Saves several instances of an entity, using the provided predicate to shape the stored graph.<T,R> R Saves an instance of an entity, including the properties and relationship defined by the projectedresultType.<T> TsaveAs(T instance, BiPredicate<PropertyPath, Neo4jPersistentProperty> includeProperty) Saves an instance of an entity, using the provided predicate to shape the stored graph.voidsetBeanClassLoader(ClassLoader beanClassLoader) voidsetBeanFactory(BeanFactory beanFactory) voidsetCypherRenderer(org.neo4j.cypherdsl.core.renderer.Renderer rendererFromCdiConfiguration) voidsetTransactionManager(PlatformTransactionManager transactionManager) toExecutableQuery(Class<T> domainType, QueryFragmentsAndParameters queryFragmentsAndParameters) Create an executable query based on query fragment.toExecutableQuery(PreparedQuery<T> preparedQuery) Takes a prepared query, containing all the information about the cypher template to be used, needed parameters and an optional mapping function, and turns it into an executable query.
-
Constructor Details
-
Neo4jTemplate
-
Neo4jTemplate
-
Neo4jTemplate
public Neo4jTemplate(Neo4jClient neo4jClient, Neo4jMappingContext neo4jMappingContext, PlatformTransactionManager transactionManager) -
Neo4jTemplate
public Neo4jTemplate(Neo4jClient neo4jClient, Neo4jMappingContext neo4jMappingContext, EntityCallbacks entityCallbacks) -
Neo4jTemplate
public Neo4jTemplate(Neo4jClient neo4jClient, Neo4jMappingContext neo4jMappingContext, EntityCallbacks entityCallbacks, @Nullable PlatformTransactionManager platformTransactionManager)
-
-
Method Details
-
count
Description copied from interface:Neo4jOperationsCounts the number of entities of a given type.- Specified by:
countin interfaceNeo4jOperations- Parameters:
domainType- the type of the entities to be counted.- Returns:
- the number of instances stored in the database. Guaranteed to be not
null.
-
count
public long count(org.neo4j.cypherdsl.core.Statement statement) Description copied from interface:Neo4jOperationsCounts the number of entities of a given type.- Specified by:
countin interfaceNeo4jOperations- Parameters:
statement- the CypherStatementthat returns the count.- Returns:
- the number of instances stored in the database. Guaranteed to be not
null.
-
count
Description copied from interface:Neo4jOperationsCounts the number of entities of a given type.- Specified by:
countin interfaceNeo4jOperations- Parameters:
statement- the CypherStatementthat returns the count.parameters- Map of parameters. Must not benull.- Returns:
- the number of instances stored in the database. Guaranteed to be not
null.
-
count
Description copied from interface:Neo4jOperationsCounts the number of entities of a given type.- Specified by:
countin interfaceNeo4jOperations- Parameters:
cypherQuery- the Cypher query that returns the count.- Returns:
- the number of instances stored in the database. Guaranteed to be not
null.
-
count
Description copied from interface:Neo4jOperationsCounts the number of entities of a given type.- Specified by:
countin interfaceNeo4jOperations- Parameters:
cypherQuery- the Cypher query that returns the count.parameters- Map of parameters. Must not benull.- Returns:
- the number of instances stored in the database. Guaranteed to be not
null.
-
findAll
Description copied from interface:Neo4jOperationsLoad all entities of a given type.- Specified by:
findAllin interfaceNeo4jOperations- Type Parameters:
T- the type of the entities. Must not benull.- Parameters:
domainType- the type of the entities. Must not benull.- Returns:
- Guaranteed to be not
null.
-
findAll
Description copied from interface:Neo4jOperationsLoad all entities of a given type by executing given statement.- Specified by:
findAllin interfaceNeo4jOperations- Type Parameters:
T- the type of the entities. Must not benull.- Parameters:
statement- CypherStatement. Must not benull.domainType- the type of the entities. Must not benull.- Returns:
- Guaranteed to be not
null.
-
findAll
public <T> List<T> findAll(org.neo4j.cypherdsl.core.Statement statement, Map<String, Object> parameters, Class<T> domainType) Description copied from interface:Neo4jOperationsLoad all entities of a given type by executing given statement with parameters.- Specified by:
findAllin interfaceNeo4jOperations- Type Parameters:
T- the type of the entities. Must not benull.- Parameters:
statement- CypherStatement. Must not benull.parameters- Map of parameters. Must not benull.domainType- the type of the entities. Must not benull.- Returns:
- Guaranteed to be not
null.
-
findOne
public <T> Optional<T> findOne(org.neo4j.cypherdsl.core.Statement statement, Map<String, Object> parameters, Class<T> domainType) Description copied from interface:Neo4jOperationsLoad one entity of a given type by executing given statement with parameters.- Specified by:
findOnein interfaceNeo4jOperations- Type Parameters:
T- the type of the entities. Must not benull.- Parameters:
statement- CypherStatement. Must not benull.parameters- Map of parameters. Must not benull.domainType- the type of the entities. Must not benull.- Returns:
- Guaranteed to be not
null.
-
findAll
Description copied from interface:Neo4jOperationsLoad all entities of a given type by executing given statement.- Specified by:
findAllin interfaceNeo4jOperations- Type Parameters:
T- the type of the entities. Must not benull.- Parameters:
cypherQuery- Cypher query string. Must not benull.domainType- the type of the entities. Must not benull.- Returns:
- Guaranteed to be not
null.
-
findAll
Description copied from interface:Neo4jOperationsLoad all entities of a given type by executing given statement with parameters.- Specified by:
findAllin interfaceNeo4jOperations- Type Parameters:
T- the type of the entities. Must not benull.- Parameters:
cypherQuery- Cypher query string. Must not benull.parameters- Map of parameters. Must not benull.domainType- the type of the entities. Must not benull.- Returns:
- Guaranteed to be not
null.
-
findOne
public <T> Optional<T> findOne(String cypherQuery, Map<String, Object> parameters, Class<T> domainType) Description copied from interface:Neo4jOperationsLoad one entity of a given type by executing given statement with parameters.- Specified by:
findOnein interfaceNeo4jOperations- Type Parameters:
T- the type of the entities. Must not benull.- Parameters:
cypherQuery- Cypher query string. Must not benull.parameters- Map of parameters. Must not benull.domainType- the type of the entities. Must not benull.- Returns:
- Guaranteed to be not
null.
-
find
Description copied from interface:FluentFindOperationStart creating a find operation for the given domainType.- Specified by:
findin interfaceFluentFindOperation- Parameters:
domainType- must not be null.- Returns:
- new instance of
FluentFindOperation.ExecutableFind.
-
existsById
Description copied from interface:Neo4jOperationsCheck if an entity for a given id exists in the database.- Specified by:
existsByIdin interfaceNeo4jOperations- Type Parameters:
T- the type of the entity.- Parameters:
id- the id of the entity to check. Must not benull.domainType- the type of the entity. Must not benull.- Returns:
- If entity exists in the database, true, otherwise false.
-
findById
Description copied from interface:Neo4jOperationsLoad an entity from the database.- Specified by:
findByIdin interfaceNeo4jOperations- Type Parameters:
T- the type of the entity.- Parameters:
id- the id of the entity to load. Must not benull.domainType- the type of the entity. Must not benull.- Returns:
- the loaded entity. Might return an empty optional.
-
findAllById
Description copied from interface:Neo4jOperationsLoad all entities of a given type that are identified by the given ids.- Specified by:
findAllByIdin interfaceNeo4jOperations- Type Parameters:
T- the type of the entities. Must not benull.- Parameters:
ids- of the entities identifying the entities to load. Must not benull.domainType- the type of the entities. Must not benull.- Returns:
- Guaranteed to be not
null.
-
save
public <T> T save(T instance) Description copied from interface:Neo4jOperationsSaves an instance of an entity, including all the related entities of the entity.- Specified by:
savein interfaceNeo4jOperations- Type Parameters:
T- the type of the entity.- Parameters:
instance- the entity to be saved. Must not benull.- Returns:
- the saved instance.
-
saveAs
Description copied from interface:Neo4jOperationsSaves an instance of an entity, using the provided predicate to shape the stored graph. One can think of the predicate as a dynamic projection. If you want to save or update properties of associations (aka related nodes), you must include the association property as well (meaning the predicate must return true for that property, too).Be careful when reusing the returned instance for further persistence operations, as it will most likely not be fully hydrated and without using a static or dynamic projection, you will most likely cause data loss.
- Specified by:
saveAsin interfaceNeo4jOperations- Type Parameters:
T- the type of the entity.- Parameters:
instance- the entity to be saved. Must not benull.includeProperty- A predicate to determine the properties to save.- Returns:
- the saved instance.
-
saveAs
Description copied from interface:Neo4jOperationsSaves an instance of an entity, including the properties and relationship defined by the projectedresultType.- Specified by:
saveAsin interfaceNeo4jOperations- Type Parameters:
T- the type of the entity.R- the type of the projection to be used during save.- Parameters:
instance- the entity to be saved. Must not benull.- Returns:
- the saved, projected instance.
-
saveAll
Description copied from interface:Neo4jOperationsSaves several instances of an entity, including all the related entities of the entity.- Specified by:
saveAllin interfaceNeo4jOperations- Type Parameters:
T- the type of the entity.- Parameters:
instances- the instances to be saved. Must not benull.- Returns:
- the saved instances.
-
saveAllAs
public <T> List<T> saveAllAs(Iterable<T> instances, BiPredicate<PropertyPath, Neo4jPersistentProperty> includeProperty) Description copied from interface:Neo4jOperationsSaves several instances of an entity, using the provided predicate to shape the stored graph. One can think of the predicate as a dynamic projection. If you want to save or update properties of associations (aka related nodes), you must include the association property as well (meaning the predicate must return true for that property, too).Be careful when reusing the returned instances for further persistence operations, as they will most likely not be fully hydrated and without using a static or dynamic projection, you will most likely cause data loss.
- Specified by:
saveAllAsin interfaceNeo4jOperations- Type Parameters:
T- the type of the entity.- Parameters:
instances- the instances to be saved. Must not benull.includeProperty- A predicate to determine the properties to save.- Returns:
- the saved instances.
-
saveAllAs
Description copied from interface:Neo4jOperationsSaves an instance of an entity, including the properties and relationship defined by the projectresultType.- Specified by:
saveAllAsin interfaceNeo4jOperations- Type Parameters:
T- the type of the entity.R- the type of the projection to be used during save.- Parameters:
instances- the instances to be saved. Must not benull.- Returns:
- the saved, projected instance.
-
deleteById
Description copied from interface:Neo4jOperationsDeletes a single entity including all entities related to that entity.- Specified by:
deleteByIdin interfaceNeo4jOperations- Type Parameters:
T- the type of the entity.- Parameters:
id- the id of the entity to be deleted. Must not benull.domainType- the type of the entity
-
deleteByIdWithVersion
public <T> void deleteByIdWithVersion(Object id, Class<T> domainType, Neo4jPersistentProperty versionProperty, Object versionValue) - Specified by:
deleteByIdWithVersionin interfaceNeo4jOperations
-
deleteAllById
Description copied from interface:Neo4jOperationsDeletes all entities with one of the given ids, including all entities related to that entity.- Specified by:
deleteAllByIdin interfaceNeo4jOperations- Type Parameters:
T- the type of the entity.- Parameters:
ids- the ids of the entities to be deleted. Must not benull.domainType- the type of the entity
-
deleteAll
Description copied from interface:Neo4jOperationsDelete all entities of a given type.- Specified by:
deleteAllin interfaceNeo4jOperations- Parameters:
domainType- type of the entities to be deleted. Must not benull.
-
setBeanClassLoader
- Specified by:
setBeanClassLoaderin interfaceBeanClassLoaderAware
-
setBeanFactory
- Specified by:
setBeanFactoryin interfaceBeanFactoryAware- Throws:
BeansException
-
setCypherRenderer
public void setCypherRenderer(org.neo4j.cypherdsl.core.renderer.Renderer rendererFromCdiConfiguration) -
setTransactionManager
-
toExecutableQuery
public <T> Neo4jOperations.ExecutableQuery<T> toExecutableQuery(Class<T> domainType, QueryFragmentsAndParameters queryFragmentsAndParameters) Description copied from interface:Neo4jOperationsCreate an executable query based on query fragment.- Specified by:
toExecutableQueryin interfaceNeo4jOperations- Type Parameters:
T- The type of the objects returned by this query.- Parameters:
domainType- domain class the executable query should returnqueryFragmentsAndParameters- fragments and parameters to construct the query from- Returns:
- An executable query
-
toExecutableQuery
Description copied from interface:Neo4jOperationsTakes a prepared query, containing all the information about the cypher template to be used, needed parameters and an optional mapping function, and turns it into an executable query.- Specified by:
toExecutableQueryin interfaceNeo4jOperations- Type Parameters:
T- The type of the objects returned by this query.- Parameters:
preparedQuery- prepared query that should get converted to an executable query- Returns:
- An executable query
-
save
Description copied from interface:FluentSaveOperationStart creating a save operation for the given domainType.- Specified by:
savein interfaceFluentSaveOperation- Parameters:
domainType- must not be null.- Returns:
- new instance of
FluentSaveOperation.ExecutableSave.
-