Class InMemoryDataDescriptor
- All Implemented Interfaces:
DataDescriptor
In-Memory DataDescriptor
The InMemory is a special DataDescriptor that does not persist data in a file or a database. The saved data are stored in the server’s memory. If the DataDescriptor class is destroyed, the associated data are also lost.
There are two basic ways of working of an In-Memory DataDescriptor. By default, they locally store data, that is, every instance stores data values separately, without interfering each other. Use this concept to temporarily store data on a page.
If you switch the DataDescriptor to global mode using the setGlobal(boolean)
method,
the DataDescriptor stores data globally, meaning that data values will be the same in every DataDescriptor instance. If you delete a record
from an instance, it disappears from all instances. Use this concept to cache data on application level.
- Since:
- 4.0
- Author:
- JBStrap
-
Field Summary
Fields inherited from class com.jbstrap.core.meta.BaseDataDescriptor
access, columns, domainClass, name
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptioncopy()
Creates a copy of the DataDescriptorlong
countData
(NoTransaction transaction, Client client, Criteria criteria) Gets the number of records in the database.find
(NoTransaction transaction, Client client, Criteria criteria, List<Order> orders, int startRow, int endRow) Initiates a query by using the DataDescriptor.findById
(NoTransaction transaction, Client client, Object... id) Fetches a record from the database using the record’s unique ID.boolean
isGlobal()
Checks if the DataDescriptor is global.As the DataDescriptor does not support transaction handling, the method returnsnull
.remove
(NoTransaction 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
(NoTransaction 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.setGlobal
(boolean global) Sets if the DataDescriptor should use global or local data storage.Methods inherited from class com.jbstrap.core.meta.BaseDataDescriptor
addColumn, addColumns, addParam, 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
-
Constructor Details
-
InMemoryDataDescriptor
Creates an In-Memory DataDescriptor.- Parameters:
name
- DataDescriptor name You can specify any name for the DataDescriptor. The name must be unique within the application.- Throws:
NullPointerException
- Thrown if the specified DataDescriptor name isnull
-
-
Method Details
-
setGlobal
Sets if the DataDescriptor should use global or local data storage. By default, the DataDescriptor works locally, it only stores data in the specified instance. If you set it to global, the same data values are contained in every instance. If you save a new record to one of the instances, the new record is also there in every instance.- Parameters:
global
- If you set atrue
value, the DataDescriptor works globally, otherwise it works locally- Returns:
- In-Memory DataDescriptor instance
-
isGlobal
public boolean isGlobal()Checks if the DataDescriptor is global.- Returns:
- If
true
is specified, the DataDescriptor works globally, otherwise it works locally
-
find
public List<Record> find(NoTransaction transaction, Client client, Criteria criteria, List<Order> orders, int startRow, int endRow) throws FindException Initiates a query by using the DataDescriptor.- Specified by:
find
in classBaseDataDescriptor<InMemoryDataDescriptor,
NoTransaction> - Parameters:
transaction
- Transaction object used to initiated the query If Ifnull
is specified, the query 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 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(NoTransaction transaction, Client client, Criteria criteria) throws RowCountException Gets the number of records in the database.- Specified by:
countData
in classBaseDataDescriptor<InMemoryDataDescriptor,
NoTransaction> - Parameters:
transaction
- Transaction object used to initiated the query If Ifnull
is specified, the query 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 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(NoTransaction transaction, Client client, List<Record> records) throws SaveException 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<InMemoryDataDescriptor,
NoTransaction> - Parameters:
transaction
- Transaction object used to initiated the query If Ifnull
is specified, the query 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 update 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(NoTransaction transaction, Client client, List<Record> records) throws RemoveException 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<InMemoryDataDescriptor,
NoTransaction> - Parameters:
transaction
- Transaction object used to initiated the query If Ifnull
is specified, the query 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 update 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
Fetches a record from the database using the record’s unique ID.- Specified by:
findById
in classBaseDataDescriptor<InMemoryDataDescriptor,
NoTransaction> - Parameters:
transaction
- Transaction object used to initiated the query If Ifnull
is specified, the query 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 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
As the DataDescriptor does not support transaction handling, the method returnsnull
.- Specified by:
openTransaction
in interfaceDataDescriptor
- Specified by:
openTransaction
in classBaseDataDescriptor<InMemoryDataDescriptor,
NoTransaction> - Returns:
- Transaction object
-
copy
Creates a copy of the DataDescriptor- Specified by:
copy
in interfaceDataDescriptor
- Overrides:
copy
in classBaseDataDescriptor<InMemoryDataDescriptor,
NoTransaction> - Returns:
- A new DataDescriptor, that is a perfect copy of the DataDescriptor
-