Class JPADataDescriptor

All Implemented Interfaces:
DataDescriptor, DataDescriptorWithDomain<JPADataDescriptor>

JPA DataDescriptor

The JPA DataDescriptor is a data descriptor that stores data in an SQL database and reads data from that database using the standard JPA layer. The JBStrap framework uses the EclipseLink 2.6.2 JPA implementation. The JPA DataDescriptor also accesses the database using this implementation and reads data from the DataDescriptor.

To use the DataDescriptor, you need an entity class (dataClass) that describes the data structure and type for the JPA layer. In the DataDescriptor, those columns are included that are defined in the entity class. If there is a column in the DataDescriptor that is not included in the entity, data in such a column are not saved to the database; when reading the record, the value of such columns is null.

Since:
4.0
Author:
JBStrap
See Also:
  • Constructor Details

    • JPADataDescriptor

      public JPADataDescriptor(String name, String domainClass)
      Creates a JPA DataDescriptor with the specified name, assigned to the entity class.
      Parameters:
      name - Unique JPA DataDescriptor name
      domainClass - Full name of the entity class associated with the DataDescriptor
      Throws:
      NullPointerException - Thrown if the name of the DataDescriptor or the associated dataClass is specified as null
  • Method Details

    • find

      public List<Record> find(SQLTransaction transaction, Client client, Criteria criteria, List<Order> orders, int startRow, int endRow) throws FindException, DataAccessException
      Initiates a query by using the DataDescriptor.
      Specified by:
      find in class BaseDataDescriptor<JPADataDescriptor,SQLTransaction>
      Parameters:
      transaction - Transaction object used to initiated the query If null is specified, does not use a transaction (it takes place outside of a transaction).
      client - Client instance initiating the query If null is specified, user access to the data (whether the user has the rights to read data) is not checked.
      startRow - The index of the first row
      endRow - The index of the last row
      criteria - Criteria instance used as a filter criterion If null is specified, the query fetches all records from the database without filtering.
      orders - A list containing Order objects used to the order the query results If null or an empty list is passed, the query results are not ordered.
      Returns:
      A list of Record instances returned by the query
      Throws:
      FindException - Occurs if an error was encountered during the query
      DataAccessException - Occurs if the user in the specified client has no access to read the data
    • countData

      public long countData(SQLTransaction transaction, Client client, Criteria criteria) throws RowCountException, DataAccessException
      Gets the number of records in the database.
      Specified by:
      countData in class BaseDataDescriptor<JPADataDescriptor,SQLTransaction>
      Parameters:
      transaction - Transaction object used to initiated the query If null is specified, does not use a transaction (it takes place outside of a transaction).
      client - Client instance initiating the query If null is specified, user access to the data (whether the user has the rights to read data) is not checked.
      criteria - Criteria instance used as a filter criterion If null is specified, the query fetches all records from the database without filtering.
      Returns:
      The number of records corresponding to the specified criteria If no records correspond to the specified criteria, the method returns 0.
      Throws:
      RowCountException - Occurs if an error was encountered during the execution of the SQL instruction that does the counting.
      DataAccessException - Occurs if the logged in user has no read access to the DataDescriptor
    • save

      public List<Record> save(SQLTransaction transaction, Client client, List<Record> records) throws SaveException, DataAccessException
      Initiates a save operation using a DataDescriptor.
      Use the method to save one or more records to the database using the DataDescriptor.
      Specified by:
      save in class BaseDataDescriptor<JPADataDescriptor,SQLTransaction>
      Parameters:
      transaction - Transaction object used to initiated the query If null is specified, does not use a transaction (it takes place outside of a transaction).
      client - Client instance initiating the query If null is specified, user access (and whether the user has rights to update the data) to the data is not checked.
      records - A list of records to be saved
      Returns:
      The saved record
      Throws:
      SaveException - Occurs if an error was encountered during the save.
      DataAccessException - Occurs if the user on the specified client has no permission to save the record to the DataDescriptor.
    • remove

      public List<Record> remove(SQLTransaction transaction, Client client, List<Record> records) throws RemoveException, DataAccessException
      Initiates a delete operation by using a DataDescriptor.
      Use the method to delete one or more records from the database using a DataDescriptor.
      Specified by:
      remove in class BaseDataDescriptor<JPADataDescriptor,SQLTransaction>
      Parameters:
      transaction - Transaction object used to initiated the query If null is specified, does not use a transaction (it takes place outside of a transaction).
      client - Client instance initiating the query If null is specified, user access (and whether the user has rights to update the data) to the data is not checked.
      records - A list of records to be deleted
      Throws:
      RemoveException - Occurs if an error was encountered during the removal process
      DataAccessException - Occurs if the user on the specified client has no access to write the data of the DataDescriptor.
    • findById

      public Record findById(SQLTransaction transaction, Client client, Object... id) throws FindException, DataAccessException
      Fetches a record from the database using the record’s unique ID.
      Specified by:
      findById in class BaseDataDescriptor<JPADataDescriptor,SQLTransaction>
      Parameters:
      transaction - Transaction object used to initiated the query If null is specified, does not use a transaction (it takes place outside of a transaction).
      client - Client instance initiating the query If null is specified, user access to the data (whether the user has the rights to read data) is not checked.
      id - Record ID
      Throws:
      FindException - Occurs if an error was encountered during the query
      DataAccessException - Occurs if the user in the specified client has no access to query the data.
    • openTransaction

      public SQLTransaction openTransaction()
      Initiates a transaction with the DataDescriptor type.
      Specified by:
      openTransaction in interface DataDescriptor
      Specified by:
      openTransaction in class BaseDataDescriptor<JPADataDescriptor,SQLTransaction>
      Returns:
      Transaction object