Interface Neo4jOperations

All Known Implementing Classes:
Neo4jTemplate

@API(status=STABLE, since="6.0") public interface Neo4jOperations
Specifies operations one can perform on a database, based on an Domain Type.
Since:
6.0
Author:
Michael J. Simons
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static interface 
    An interface for controlling query execution.
  • Method Summary

    Modifier and Type
    Method
    Description
    long
    count(Class<?> domainType)
    Counts the number of entities of a given type.
    long
    count(String cypherQuery)
    Counts the number of entities of a given type.
    long
    count(String cypherQuery, Map<String,Object> parameters)
    Counts the number of entities of a given type.
    long
    count(org.neo4j.cypherdsl.core.Statement statement)
    Counts the number of entities of a given type.
    long
    count(org.neo4j.cypherdsl.core.Statement statement, Map<String,Object> parameters)
    Counts the number of entities of a given type.
    void
    deleteAll(Class<?> domainType)
    Delete all entities of a given type.
    <T> void
    deleteAllById(Iterable<?> ids, Class<T> domainType)
    Deletes all entities with one of the given ids, including all entities related to that entity.
    <T> void
    deleteById(Object id, Class<T> domainType)
    Deletes a single entity including all entities related to that entity.
    <T> void
    deleteByIdWithVersion(Object id, Class<T> domainType, Neo4jPersistentProperty versionProperty, Object versionValue)
     
    <T> boolean
    existsById(Object id, Class<T> domainType)
    Check if an entity for a given id exists in the database.
    <T> List<T>
    findAll(Class<T> domainType)
    Load all entities of a given type.
    <T> List<T>
    findAll(String cypherQuery, Class<T> domainType)
    Load all entities of a given type by executing given statement.
    <T> List<T>
    findAll(String cypherQuery, Map<String,Object> parameters, Class<T> domainType)
    Load all entities of a given type by executing given statement with parameters.
    <T> List<T>
    findAll(org.neo4j.cypherdsl.core.Statement statement, Class<T> domainType)
    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>
    findById(Object id, Class<T> domainType)
    Load an entity from the database.
    <T> Optional<T>
    findOne(String cypherQuery, Map<String,Object> parameters, Class<T> domainType)
    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.
    <T> T
    save(T instance)
    Saves an instance of an entity, including all the related entities of the entity.
    <T> List<T>
    saveAll(Iterable<T> instances)
    Saves several instances of an entity, including all the related entities of the entity.
    default <T, R> List<R>
    saveAllAs(Iterable<T> instances, Class<R> resultType)
    Saves an instance of an entity, including the properties and relationship defined by the project resultType.
    default <T> List<T>
    Saves several instances of an entity, using the provided predicate to shape the stored graph.
    default <T, R> R
    saveAs(T instance, Class<R> resultType)
    Saves an instance of an entity, including the properties and relationship defined by the projected resultType.
    default <T> T
    saveAs(T instance, BiPredicate<PropertyPath,Neo4jPersistentProperty> includeProperty)
    Saves an instance of an entity, using the provided predicate to shape the stored graph.
    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.
  • Method Details

    • count

      long count(Class<?> domainType)
      Counts the number of entities of a given type.
      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

      long count(org.neo4j.cypherdsl.core.Statement statement)
      Counts the number of entities of a given type.
      Parameters:
      statement - the Cypher Statement that returns the count.
      Returns:
      the number of instances stored in the database. Guaranteed to be not null.
    • count

      long count(org.neo4j.cypherdsl.core.Statement statement, Map<String,Object> parameters)
      Counts the number of entities of a given type.
      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

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

      long count(String cypherQuery, Map<String,Object> parameters)
      Counts the number of entities of a given type.
      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

      <T> List<T> findAll(Class<T> domainType)
      Load all entities of a given type.
      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

      <T> List<T> findAll(org.neo4j.cypherdsl.core.Statement statement, Class<T> domainType)
      Load all entities of a given type by executing given statement.
      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

      <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.
      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

      <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.
      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

      <T> List<T> findAll(String cypherQuery, Class<T> domainType)
      Load all entities of a given type by executing given statement.
      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

      <T> List<T> findAll(String cypherQuery, Map<String,Object> parameters, Class<T> domainType)
      Load all entities of a given type by executing given statement with parameters.
      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

      <T> Optional<T> findOne(String cypherQuery, Map<String,Object> parameters, Class<T> domainType)
      Load one entity of a given type by executing given statement with parameters.
      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.
    • findById

      <T> Optional<T> findById(Object id, Class<T> domainType)
      Load an entity from the database.
      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

      <T> List<T> findAllById(Iterable<?> ids, Class<T> domainType)
      Load all entities of a given type that are identified by the given ids.
      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.
    • existsById

      <T> boolean existsById(Object id, Class<T> domainType)
      Check if an entity for a given id exists in the database.
      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.
    • save

      <T> T save(T instance)
      Saves an instance of an entity, including all the related entities of the entity.
      Type Parameters:
      T - the type of the entity.
      Parameters:
      instance - the entity to be saved. Must not be null.
      Returns:
      the saved instance.
    • saveAs

      default <T> T saveAs(T instance, BiPredicate<PropertyPath,Neo4jPersistentProperty> includeProperty)
      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.

      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.
      Since:
      6.3
    • saveAs

      default <T, R> R saveAs(T instance, Class<R> resultType)
      Saves an instance of an entity, including the properties and relationship defined by the projected resultType.
      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.
      Since:
      6.1
    • saveAll

      <T> List<T> saveAll(Iterable<T> instances)
      Saves several instances of an entity, including all the related entities of the entity.
      Type Parameters:
      T - the type of the entity.
      Parameters:
      instances - the instances to be saved. Must not be null.
      Returns:
      the saved instances.
    • saveAllAs

      default <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. 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.

      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.
      Since:
      6.3
    • saveAllAs

      default <T, R> List<R> saveAllAs(Iterable<T> instances, Class<R> resultType)
      Saves an instance of an entity, including the properties and relationship defined by the project resultType.
      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.
      Since:
      6.1
    • deleteById

      <T> void deleteById(Object id, Class<T> domainType)
      Deletes a single entity including all entities related to that entity.
      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

      <T> void deleteByIdWithVersion(Object id, Class<T> domainType, Neo4jPersistentProperty versionProperty, @Nullable Object versionValue)
    • deleteAllById

      <T> void deleteAllById(Iterable<?> ids, Class<T> domainType)
      Deletes all entities with one of the given ids, including all entities related to that entity.
      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

      void deleteAll(Class<?> domainType)
      Delete all entities of a given type.
      Parameters:
      domainType - type of the entities to be deleted. Must not be null.
    • toExecutableQuery

      <T> Neo4jOperations.ExecutableQuery<T> 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.
      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
    • toExecutableQuery

      <T> Neo4jOperations.ExecutableQuery<T> toExecutableQuery(Class<T> domainType, QueryFragmentsAndParameters queryFragmentsAndParameters)
      Create an executable query based on query fragment.
      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