Class Neo4jTemplate

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
  • Constructor Details

  • Method Details

    • count

      public long count(Class<?> domainType)
      Description copied from interface: Neo4jOperations
      Counts the number of entities of a given type.
      Specified by:
      count in interface Neo4jOperations
      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: Neo4jOperations
      Counts the number of entities of a given type.
      Specified by:
      count in interface Neo4jOperations
      Parameters:
      statement - the Cypher Statement that returns the count.
      Returns:
      the number of instances stored in the database. Guaranteed to be not null.
    • count

      public long count(org.neo4j.cypherdsl.core.Statement statement, Map<String,Object> parameters)
      Description copied from interface: Neo4jOperations
      Counts the number of entities of a given type.
      Specified by:
      count in interface Neo4jOperations
      Parameters:
      statement - the Cypher Statement that returns the count.
      parameters - Map of parameters. Must not be null.
      Returns:
      the number of instances stored in the database. Guaranteed to be not null.
    • count

      public long count(String cypherQuery)
      Description copied from interface: Neo4jOperations
      Counts the number of entities of a given type.
      Specified by:
      count in interface Neo4jOperations
      Parameters:
      cypherQuery - the Cypher query that returns the count.
      Returns:
      the number of instances stored in the database. Guaranteed to be not null.
    • count

      public long count(String cypherQuery, Map<String,Object> parameters)
      Description copied from interface: Neo4jOperations
      Counts the number of entities of a given type.
      Specified by:
      count in interface Neo4jOperations
      Parameters:
      cypherQuery - the Cypher query that returns the count.
      parameters - Map of parameters. Must not be null.
      Returns:
      the number of instances stored in the database. Guaranteed to be not null.
    • findAll

      public <T> List<T> findAll(Class<T> domainType)
      Description copied from interface: Neo4jOperations
      Load all entities of a given type.
      Specified by:
      findAll in interface Neo4jOperations
      Type Parameters:
      T - the type of the entities. Must not be null.
      Parameters:
      domainType - the type of the entities. Must not be null.
      Returns:
      Guaranteed to be not null.
    • findAll

      public <T> List<T> findAll(org.neo4j.cypherdsl.core.Statement statement, Class<T> domainType)
      Description copied from interface: Neo4jOperations
      Load all entities of a given type by executing given statement.
      Specified by:
      findAll in interface Neo4jOperations
      Type Parameters:
      T - the type of the entities. Must not be null.
      Parameters:
      statement - Cypher Statement. Must not be null.
      domainType - the type of the entities. Must not be null.
      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: Neo4jOperations
      Load all entities of a given type by executing given statement with parameters.
      Specified by:
      findAll in interface Neo4jOperations
      Type Parameters:
      T - the type of the entities. Must not be null.
      Parameters:
      statement - Cypher Statement. Must not be null.
      parameters - Map of parameters. Must not be null.
      domainType - the type of the entities. Must not be null.
      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: Neo4jOperations
      Load one entity of a given type by executing given statement with parameters.
      Specified by:
      findOne in interface Neo4jOperations
      Type Parameters:
      T - the type of the entities. Must not be null.
      Parameters:
      statement - Cypher Statement. Must not be null.
      parameters - Map of parameters. Must not be null.
      domainType - the type of the entities. Must not be null.
      Returns:
      Guaranteed to be not null.
    • findAll

      public <T> List<T> findAll(String cypherQuery, Class<T> domainType)
      Description copied from interface: Neo4jOperations
      Load all entities of a given type by executing given statement.
      Specified by:
      findAll in interface Neo4jOperations
      Type Parameters:
      T - the type of the entities. Must not be null.
      Parameters:
      cypherQuery - Cypher query string. Must not be null.
      domainType - the type of the entities. Must not be null.
      Returns:
      Guaranteed to be not null.
    • findAll

      public <T> List<T> findAll(String cypherQuery, Map<String,Object> parameters, Class<T> domainType)
      Description copied from interface: Neo4jOperations
      Load all entities of a given type by executing given statement with parameters.
      Specified by:
      findAll in interface Neo4jOperations
      Type Parameters:
      T - the type of the entities. Must not be null.
      Parameters:
      cypherQuery - Cypher query string. Must not be null.
      parameters - Map of parameters. Must not be null.
      domainType - the type of the entities. Must not be null.
      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: Neo4jOperations
      Load one entity of a given type by executing given statement with parameters.
      Specified by:
      findOne in interface Neo4jOperations
      Type Parameters:
      T - the type of the entities. Must not be null.
      Parameters:
      cypherQuery - Cypher query string. Must not be null.
      parameters - Map of parameters. Must not be null.
      domainType - the type of the entities. Must not be null.
      Returns:
      Guaranteed to be not null.
    • find

      public <T> FluentFindOperation.ExecutableFind<T> find(Class<T> domainType)
      Description copied from interface: FluentFindOperation
      Start creating a find operation for the given domainType.
      Specified by:
      find in interface FluentFindOperation
      Parameters:
      domainType - must not be null.
      Returns:
      new instance of FluentFindOperation.ExecutableFind.
    • existsById

      public <T> boolean existsById(Object id, Class<T> domainType)
      Description copied from interface: Neo4jOperations
      Check if an entity for a given id exists in the database.
      Specified by:
      existsById in interface Neo4jOperations
      Type Parameters:
      T - the type of the entity.
      Parameters:
      id - the id of the entity to check. Must not be null.
      domainType - the type of the entity. Must not be null.
      Returns:
      If entity exists in the database, true, otherwise false.
    • findById

      public <T> Optional<T> findById(Object id, Class<T> domainType)
      Description copied from interface: Neo4jOperations
      Load an entity from the database.
      Specified by:
      findById in interface Neo4jOperations
      Type Parameters:
      T - the type of the entity.
      Parameters:
      id - the id of the entity to load. Must not be null.
      domainType - the type of the entity. Must not be null.
      Returns:
      the loaded entity. Might return an empty optional.
    • findAllById

      public <T> List<T> findAllById(Iterable<?> ids, Class<T> domainType)
      Description copied from interface: Neo4jOperations
      Load all entities of a given type that are identified by the given ids.
      Specified by:
      findAllById in interface Neo4jOperations
      Type Parameters:
      T - the type of the entities. Must not be null.
      Parameters:
      ids - of the entities identifying the entities to load. Must not be null.
      domainType - the type of the entities. Must not be null.
      Returns:
      Guaranteed to be not null.
    • save

      public <T> T save(T instance)
      Description copied from interface: Neo4jOperations
      Saves an instance of an entity, including all the related entities of the entity.
      Specified by:
      save in interface Neo4jOperations
      Type Parameters:
      T - the type of the entity.
      Parameters:
      instance - the entity to be saved. Must not be null.
      Returns:
      the saved instance.
    • saveAs

      public <T> T saveAs(T instance, BiPredicate<PropertyPath,Neo4jPersistentProperty> includeProperty)
      Description copied from interface: Neo4jOperations
      Saves 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:
      saveAs in interface Neo4jOperations
      Type Parameters:
      T - the type of the entity.
      Parameters:
      instance - the entity to be saved. Must not be null.
      includeProperty - A predicate to determine the properties to save.
      Returns:
      the saved instance.
    • saveAs

      public <T, R> R saveAs(T instance, Class<R> resultType)
      Description copied from interface: Neo4jOperations
      Saves an instance of an entity, including the properties and relationship defined by the projected resultType.
      Specified by:
      saveAs in interface Neo4jOperations
      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 be null.
      Returns:
      the saved, projected instance.
    • saveAll

      public <T> List<T> saveAll(Iterable<T> instances)
      Description copied from interface: Neo4jOperations
      Saves several instances of an entity, including all the related entities of the entity.
      Specified by:
      saveAll in interface Neo4jOperations
      Type Parameters:
      T - the type of the entity.
      Parameters:
      instances - the instances to be saved. Must not be null.
      Returns:
      the saved instances.
    • saveAllAs

      public <T> List<T> saveAllAs(Iterable<T> instances, BiPredicate<PropertyPath,Neo4jPersistentProperty> includeProperty)
      Description copied from interface: Neo4jOperations
      Saves 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:
      saveAllAs in interface Neo4jOperations
      Type Parameters:
      T - the type of the entity.
      Parameters:
      instances - the instances to be saved. Must not be null.
      includeProperty - A predicate to determine the properties to save.
      Returns:
      the saved instances.
    • saveAllAs

      public <T, R> List<R> saveAllAs(Iterable<T> instances, Class<R> resultType)
      Description copied from interface: Neo4jOperations
      Saves an instance of an entity, including the properties and relationship defined by the project resultType.
      Specified by:
      saveAllAs in interface Neo4jOperations
      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 be null.
      Returns:
      the saved, projected instance.
    • deleteById

      public <T> void deleteById(Object id, Class<T> domainType)
      Description copied from interface: Neo4jOperations
      Deletes a single entity including all entities related to that entity.
      Specified by:
      deleteById in interface Neo4jOperations
      Type Parameters:
      T - the type of the entity.
      Parameters:
      id - the id of the entity to be deleted. Must not be null.
      domainType - the type of the entity
    • deleteByIdWithVersion

      public <T> void deleteByIdWithVersion(Object id, Class<T> domainType, Neo4jPersistentProperty versionProperty, Object versionValue)
      Specified by:
      deleteByIdWithVersion in interface Neo4jOperations
    • deleteAllById

      public <T> void deleteAllById(Iterable<?> ids, Class<T> domainType)
      Description copied from interface: Neo4jOperations
      Deletes all entities with one of the given ids, including all entities related to that entity.
      Specified by:
      deleteAllById in interface Neo4jOperations
      Type Parameters:
      T - the type of the entity.
      Parameters:
      ids - the ids of the entities to be deleted. Must not be null.
      domainType - the type of the entity
    • deleteAll

      public void deleteAll(Class<?> domainType)
      Description copied from interface: Neo4jOperations
      Delete all entities of a given type.
      Specified by:
      deleteAll in interface Neo4jOperations
      Parameters:
      domainType - type of the entities to be deleted. Must not be null.
    • setBeanClassLoader

      public void setBeanClassLoader(ClassLoader beanClassLoader)
      Specified by:
      setBeanClassLoader in interface BeanClassLoaderAware
    • setBeanFactory

      public void setBeanFactory(BeanFactory beanFactory) throws BeansException
      Specified by:
      setBeanFactory in interface BeanFactoryAware
      Throws:
      BeansException
    • setCypherRenderer

      public void setCypherRenderer(org.neo4j.cypherdsl.core.renderer.Renderer rendererFromCdiConfiguration)
    • setTransactionManager

      public void setTransactionManager(@Nullable PlatformTransactionManager transactionManager)
    • toExecutableQuery

      public <T> Neo4jOperations.ExecutableQuery<T> toExecutableQuery(Class<T> domainType, QueryFragmentsAndParameters queryFragmentsAndParameters)
      Description copied from interface: Neo4jOperations
      Create an executable query based on query fragment.
      Specified by:
      toExecutableQuery in interface Neo4jOperations
      Type Parameters:
      T - The type of the objects returned by this query.
      Parameters:
      domainType - domain class the executable query should return
      queryFragmentsAndParameters - fragments and parameters to construct the query from
      Returns:
      An executable query
    • toExecutableQuery

      public <T> Neo4jOperations.ExecutableQuery<T> toExecutableQuery(PreparedQuery<T> preparedQuery)
      Description copied from interface: Neo4jOperations
      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.
      Specified by:
      toExecutableQuery in interface Neo4jOperations
      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

      public <T> FluentSaveOperation.ExecutableSave<T> save(Class<T> domainType)
      Description copied from interface: FluentSaveOperation
      Start creating a save operation for the given domainType.
      Specified by:
      save in interface FluentSaveOperation
      Parameters:
      domainType - must not be null.
      Returns:
      new instance of FluentSaveOperation.ExecutableSave.