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:
-
Field Summary
Fields inherited from class com.jbstrap.core.meta.BaseDataDescriptor
access, columns, domainClass, name
-
Constructor Summary
ConstructorDescriptionJPADataDescriptor
(String name, String domainClass) Creates a JPA DataDescriptor with the specified name, assigned to the entity class. -
Method Summary
Modifier and TypeMethodDescriptionlong
countData
(SQLTransaction transaction, Client client, Criteria criteria) Gets the number of records in the database.find
(SQLTransaction transaction, Client client, Criteria criteria, List<Order> orders, int startRow, int endRow) Initiates a query by using the DataDescriptor.findById
(SQLTransaction transaction, Client client, Object... id) Fetches a record from the database using the record’s unique ID.Initiates a transaction with the DataDescriptor type.remove
(SQLTransaction transaction, Client client, List<Record> records) Initiates a delete operation by using a DataDescriptor.
Use the method to delete one or more records from the database using a DataDescriptor.save
(SQLTransaction transaction, Client client, List<Record> records) Initiates a save operation using a DataDescriptor.
Use the method to save one or more records to the database using the DataDescriptor.Methods inherited from class com.jbstrap.core.meta.BaseDataDescriptor
addColumn, addColumns, addParam, copy, countData, countData, fetchData, fetchData, fetchData, fetchData, fetchData, fetchData, find, find, find, find, find, find, find, find, find, find, find, find, findById, findById, getAccess, getColumn, getColumns, getDefaultFilterCriteria, getName, getParam, getPrimaryKeyName, getPrimaryKeyNames, getRead, getWrite, isFilterable, remove, remove, remove, remove, remove, remove, remove, remove, remove, save, save, save, save, save, save, save, save, save, setAccess, setDefaultFilterCriteria, setParam, setRead, setWrite, sortColumn
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.jbstrap.core.meta.DataDescriptorWithDomain
getDomainClass, getDomainClassName
-
Constructor Details
-
JPADataDescriptor
Creates a JPA DataDescriptor with the specified name, assigned to the entity class.- Parameters:
name
- Unique JPA DataDescriptor namedomainClass
- 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 asnull
-
-
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 classBaseDataDescriptor<JPADataDescriptor,
SQLTransaction> - Parameters:
transaction
- Transaction object used to initiated the query Ifnull
is specified, does not use a transaction (it takes place outside of a transaction).client
- Client instance initiating the query Ifnull
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 rowendRow
- The index of the last rowcriteria
-Criteria
instance used as a filter criterion Ifnull
is specified, the query fetches all records from the database without filtering.orders
- A list containingOrder
objects used to the order the query results Ifnull
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 queryDataAccessException
- 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 classBaseDataDescriptor<JPADataDescriptor,
SQLTransaction> - Parameters:
transaction
- Transaction object used to initiated the query Ifnull
is specified, does not use a transaction (it takes place outside of a transaction).client
- Client instance initiating the query Ifnull
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 Ifnull
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 classBaseDataDescriptor<JPADataDescriptor,
SQLTransaction> - Parameters:
transaction
- Transaction object used to initiated the query Ifnull
is specified, does not use a transaction (it takes place outside of a transaction).client
- Client instance initiating the query Ifnull
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 classBaseDataDescriptor<JPADataDescriptor,
SQLTransaction> - Parameters:
transaction
- Transaction object used to initiated the query Ifnull
is specified, does not use a transaction (it takes place outside of a transaction).client
- Client instance initiating the query Ifnull
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 processDataAccessException
- 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 classBaseDataDescriptor<JPADataDescriptor,
SQLTransaction> - Parameters:
transaction
- Transaction object used to initiated the query Ifnull
is specified, does not use a transaction (it takes place outside of a transaction).client
- Client instance initiating the query Ifnull
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 queryDataAccessException
- Occurs if the user in the specified client has no access to query the data.
-
openTransaction
Initiates a transaction with the DataDescriptor type.- Specified by:
openTransaction
in interfaceDataDescriptor
- Specified by:
openTransaction
in classBaseDataDescriptor<JPADataDescriptor,
SQLTransaction> - Returns:
- Transaction object
-