Interface PersistenceService

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      abstract void persist(@NotNull() Object entity) Persists a single entity to the store.
      abstract void persist(@NotNull() List<out Object> entities) Persists multiple entities in the persistence context in a single transaction.
      abstract <T> T merge(@NotNull() T entity) Merges a single entity in the persistence context in a transaction.
      abstract <T> List<T> merge(@NotNull() List<T> entities) Merges multiple entities in the persistence context in a single transaction.
      abstract void remove(@NotNull() Object entity) Removes a single entity from the persistence context in a transaction.
      abstract void remove(@NotNull() List<out Object> entities) Removes multiple entities from the persistence context in a single transaction.
      abstract <T> T find(@NotNull() Class<T> entityClass, @NotNull() Object primaryKey) Finds a single entity in the persistence context of the specified entity type [T] and with the specified primaryKey.
      abstract <T> List<T> find(@NotNull() Class<T> entityClass, @NotNull() List<out Object> primaryKeys) Finds multiple entities of the same type with different primary keys in a single transaction.
      abstract <T> PagedQuery<T> findAll(@NotNull() Class<T> entityClass) Creates a PagedQuery to find all entities of the same type from the persistence context in a single transaction.
      abstract <T> ParameterizedQuery<T> query(@NotNull() String queryName, @NotNull() Class<T> entityClass) Creates a ParameterizedQuery to support a named query to return a list of entities of the given type in a single transaction.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

    • Method Detail

      • persist

        @Suspendable() abstract void persist(@NotNull() Object entity)

        Persists a single entity to the store.

        Parameters:
        entity - The entity to persist.
      • persist

        @Suspendable() abstract void persist(@NotNull() List<out Object> entities)

        Persists multiple entities in the persistence context in a single transaction.

        Parameters:
        entities - List of entities to be persisted.
      • merge

        @Suspendable()@Nullable() abstract <T> T merge(@NotNull() T entity)

        Merges a single entity in the persistence context in a transaction.

        Parameters:
        entity - The entity to merge.
      • merge

        @Suspendable()@NotNull() abstract <T> List<T> merge(@NotNull() List<T> entities)

        Merges multiple entities in the persistence context in a single transaction.

        Parameters:
        entities - List of entities to be merged.
      • remove

        @Suspendable() abstract void remove(@NotNull() Object entity)

        Removes a single entity from the persistence context in a transaction.

        Parameters:
        entity - The entity to remove.
      • remove

        @Suspendable() abstract void remove(@NotNull() List<out Object> entities)

        Removes multiple entities from the persistence context in a single transaction.

        Parameters:
        entities - List of entities to be removed.
      • find

        @Suspendable()@Nullable() abstract <T> T find(@NotNull() Class<T> entityClass, @NotNull() Object primaryKey)

        Finds a single entity in the persistence context of the specified entity type [T] and with the specified primaryKey.

        Parameters:
        entityClass - The type of entity to find.
        primaryKey - The primary key of the entity to find.
      • find

        @Suspendable()@NotNull() abstract <T> List<T> find(@NotNull() Class<T> entityClass, @NotNull() List<out Object> primaryKeys)

        Finds multiple entities of the same type with different primary keys in a single transaction.

        Parameters:
        entityClass - The type of the entities to find.
        primaryKeys - List of primary keys to find with the given entityClass type.
      • findAll

        @Suspendable()@NotNull() abstract <T> PagedQuery<T> findAll(@NotNull() Class<T> entityClass)

        Creates a PagedQuery to find all entities of the same type from the persistence context in a single transaction.

        Parameters:
        entityClass - The type of the entities to find.
      • query

        @Suspendable()@NotNull() abstract <T> ParameterizedQuery<T> query(@NotNull() String queryName, @NotNull() Class<T> entityClass)

        Creates a ParameterizedQuery to support a named query to return a list of entities of the given type in a single transaction. Casts result set to the specified type [T].

        Example usage:

        • Kotlin:
          
          // For JPA Entity:
          
          
          
          = "DOGS")
          = "find_by_name_and_age", query = "SELECT d FROM Dog d WHERE d.name = :name AND d.age <= :maxAge")
          class Dog {
              
              private val id: UUID? = null
          
              = "DOG_NAME", length = 50, nullable = false, unique = false)
              private val name: String? = null
          
              = "DOG_AGE")
              private val age: Int? = null // getters and setters
              // ...
          }
          
          // Create a named query that returns pages of up to 100 records
          val pagedQuery = persistenceService
              .query("find_by_name_and_age", Dog::class.java)
              .setParameter("name", "Felix")
              .setParameter("maxAge", 5)
              .setLimit(100)
              .setOffset(0)
          
          // Execute the query and return a ResultSet
          val resultSet = pagedQuery.execute()
          
          processResultsWithApplicationLogic(resultSet.results)
          
          while (resultSet.hasNext()) {
              val results = resultSet.next()
              processResultsWithApplicationLogic(results)
          }
          
        • Java:
          
          // For JPA Entity:
          
          
          = "DOGS")
          = "find_by_name_and_age", query = "SELECT d FROM Dog d WHERE d.name = :name AND d.age <= :maxAge")
          class Dog {
              
              private UUID id;
              = "DOG_NAME", length = 50, nullable = false, unique = false)
              private String name;
              = "DOG_AGE")
              private Integer age;
          
              // getters and setters
               ...
          }
          
          // Create a named query that returns pages of up to 100 records
          ParameterizedQuery<Dog> pagedQuery = persistenceService
                  .query("find_by_name_and_age", Dog.class)
                  .setParameter("name", "Felix")
                  .setParameter("maxAge", 5)
                  .setLimit(100)
                  .setOffset(0);
          
          // Execute the query and return a ResultSet
          ResultSet<Dog> resultSet = pagedQuery.execute();
          
          processResultsWithApplicationLogic(resultSet.getResults());
          
          while (resultSet.hasNext()) {
              List<Integer> results = resultSet.next();
              processResultsWithApplicationLogic(results);
          }
          
        Parameters:
        queryName - The name of the named query registered in the persistence context.
        entityClass - The type of the entities to find.