Interface JKObjectDataAccess

All Known Subinterfaces:
JKNoSqlDataAccess
All Known Implementing Classes:
JKMongoDataAccess, JKObjectDataAccessImpl, JKObjectDataAccessInMemory

public interface JKObjectDataAccess
This interface provides methods that help with data access operations on objects.
Version:
1.0
Author:
Dr. Jalal H. Kiswani
  • Method Summary

    Modifier and Type
    Method
    Description
    <T> T
    clone(T model)
    This method creates a detached copy of the provided object.
    void
    closeTransaction(boolean commit)
    This method closes the current data storage transaction.
    <T> T
    delete(Class<T> type, Object id)
    This method deletes an object from the data storage using its identifier (ID).
    <T> T
    delete(T object)
    This method deletes an object from the data storage.
    <T> void
    detach(T model)
    This method remove the given object from the persistence context, causing managed object to become detached.
    <T> List<T>
    executeQuery(Class<T> clas, String queryString, Object... paramters)
    This method executes a query to retrieve a list of objects of the specified class.
    default <T> T
    executeSingleOutputQuery(Class<T> clas, String query, Object... params)
    This method executes a data storage query that is expected to return a single result and returns that result.
    <T> T
    find(Class<T> clas, Object id)
    This method finds an object from the data storage using its identifier (ID).
    <T> List<T>
    findByFieldName(Class<T> clas, String fieldName, Object value)
    This method retrieves a list of objects of the specified class based on a specific field's value.
    <T> T
    findOneByFieldName(Class<T> clas, String fieldName, Object fieldValue)
    This method retrieves a single object of the specified class from the data storage based on a field name and its value.
    <T> List<T>
    getList(Class<T> clas)
    This method retrieves a list of objects of the provided class type from the data storage.
    <T> List<T>
    getList(Class<T> clas, Map<String,Object> paramters)
    This method retrieves a list of objects of the specified class based on the provided parameters.
    <T> List<T>
    This method retrieves a list of objects of a specified class type and caches the result.
    default String
    This method retrieves the tenant identifier (ID).
    <T> T
    insert(T object)
    This method inserts the provided object into the data storage.
    <T> T
    insertOrUpdate(T object)
    This method inserts a new object into the data storage if it doesn't exist, or updates an existing object.
    void
    setMaxResults(int maxResults)
    This method sets the max results shown from any executed query.
    void
    This method starts the transaction for data storage operations.
    <T> T
    update(T object)
    This method updates an existing object in the data storage.
  • Method Details

    • insert

      <T> T insert(T object)
      This method inserts the provided object into the data storage.
      Type Parameters:
      T - Specifies the type of the object.
      Parameters:
      object - Specifies the object to be inserted
      Returns:
      the inserted object.
    • update

      <T> T update(T object)
      This method updates an existing object in the data storage.
      Type Parameters:
      T - Specifies the type of the object.
      Parameters:
      object - Specifies the object to update.
      Returns:
      the updated object.
    • delete

      <T> T delete(T object)
      This method deletes an object from the data storage.
      Type Parameters:
      T - Specifies the type of the object.
      Parameters:
      object - Specifies the object to delete.
      Returns:
      the deleted object.
    • delete

      <T> T delete(Class<T> type, Object id)
      This method deletes an object from the data storage using its identifier (ID).
      Type Parameters:
      T - Specifies the type of the object.
      Parameters:
      type - Specifies the class type of the object.
      id - Specifies the object identifier (ID)
      Returns:
      the deleted object.
    • find

      <T> T find(Class<T> clas, Object id)
      This method finds an object from the data storage using its identifier (ID).
      Type Parameters:
      T - Specifies the type of the object.
      Parameters:
      clas - Specifies the class type of the object.
      id - Specifies the identifier (ID) of the object to find.
      Returns:
      the found object, or null if not found.
    • getList

      <T> List<T> getList(Class<T> clas)
      This method retrieves a list of objects of the provided class type from the data storage.
      Type Parameters:
      T - Specifies the type of the object.
      Parameters:
      clas - Specifies the class type of the objects.
      Returns:
      a list of objects from data storage that are of the provided class type.
    • getList

      <T> List<T> getList(Class<T> clas, Map<String,Object> paramters)
      This method retrieves a list of objects of the specified class based on the provided parameters.
      Type Parameters:
      T - Specifies the type of objects to retrieve.
      Parameters:
      clas - Specifies the class of objects to retrieve.
      paramters - Specifies a map of parameters or criteria for filtering the objects.
      Returns:
      a list of objects matching the specified class and criteria.
    • executeQuery

      <T> List<T> executeQuery(Class<T> clas, String queryString, Object... paramters)
      This method executes a query to retrieve a list of objects of the specified class.
      Type Parameters:
      T - Specifies the type of objects to retrieve.
      Parameters:
      clas - Specifies the class of objects to retrieve.
      queryString - Specifies the query string to execute.
      paramters - Specifies the optional parameters to bind to the query.
      Returns:
      a list of objects matching the specified class and query criteria.
    • findByFieldName

      <T> List<T> findByFieldName(Class<T> clas, String fieldName, Object value)
      This method retrieves a list of objects of the specified class based on a specific field's value.
      Type Parameters:
      T - Specifies the type of objects to retrieve.
      Parameters:
      clas - Specifies the class of objects to retrieve.
      fieldName - Specifies the name of the field to search by.
      value - Specifies the value to search for within the specified field.
      Returns:
      a list of objects matching the specified class and field value criteria.
    • insertOrUpdate

      <T> T insertOrUpdate(T object)
      This method inserts a new object into the data storage if it doesn't exist, or updates an existing object.
      Type Parameters:
      T - Specifies the type of the object to insert or update.
      Parameters:
      object - Specifies the object to insert or update in the data storage.
      Returns:
      the inserted or updated object.
    • findOneByFieldName

      <T> T findOneByFieldName(Class<T> clas, String fieldName, Object fieldValue)
      This method retrieves a single object of the specified class from the data storage based on a field name and its value.
      Type Parameters:
      T - Specifies the type of object to retrieve.
      Parameters:
      clas - Specifies the class of the object to retrieve.
      fieldName - Specifies the name of the field to use as a filter.
      fieldValue - Specifies the value to match in the specified field.
      Returns:
      the retrieved object, or null if no matching object is found.
    • setMaxResults

      void setMaxResults(int maxResults)
      This method sets the max results shown from any executed query.
      Parameters:
      maxResults - Specifies the new max results shown from any executed query.
    • detach

      <T> void detach(T model)
      This method remove the given object from the persistence context, causing managed object to become detached.
      Type Parameters:
      T - Specifies the type of the object to detach.
      Parameters:
      model - Specifies the object to detach from the persistence context.
    • clone

      <T> T clone(T model)
      This method creates a detached copy of the provided object.
      Type Parameters:
      T - Specifies the type of the object to clone.
      Parameters:
      model - Specifies the object to create a detached copy of.
      Returns:
      a detached copy of the input object.
    • startTransaction

      void startTransaction()
      This method starts the transaction for data storage operations.
    • closeTransaction

      void closeTransaction(boolean commit)
      This method closes the current data storage transaction.
      Parameters:
      commit - Indicates whether to commit (true) the transaction or to roll it back (false).
    • executeSingleOutputQuery

      default <T> T executeSingleOutputQuery(Class<T> clas, String query, Object... params)
      This method executes a data storage query that is expected to return a single result and returns that result.
      Type Parameters:
      T - Specifies the type of the expected result.
      Parameters:
      clas - Specifies the class type of the expected result.
      query - Specifies the SQL query to execute.
      params - Specifies the optional parameters to bind to the query.
      Returns:
      the single result of the specified class type.
    • getListAndCache

      <T> List<T> getListAndCache(Class<T> clas)
      This method retrieves a list of objects of a specified class type and caches the result.
      Type Parameters:
      T - Specifies the type of the object.
      Parameters:
      clas - Specifies the class type of the objects to retrieve.
      Returns:
      a list of objects of the specified class type.
    • getTenantId

      default String getTenantId()
      This method retrieves the tenant identifier (ID).
      Returns:
      the tenant identifier (ID).