Class InMemoryDataDescriptor

All Implemented Interfaces:
DataDescriptor

public class InMemoryDataDescriptor extends BaseDataDescriptor<InMemoryDataDescriptor,NoTransaction>

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
  • Constructor Details

    • InMemoryDataDescriptor

      public InMemoryDataDescriptor(String name)
      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 is null
  • Method Details

    • setGlobal

      public InMemoryDataDescriptor setGlobal(boolean global)
      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 a true 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 class BaseDataDescriptor<InMemoryDataDescriptor,NoTransaction>
      Parameters:
      transaction - Transaction object used to initiated the query If If null is specified, the query 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 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(NoTransaction transaction, Client client, Criteria criteria) throws RowCountException
      Gets the number of records in the database.
      Specified by:
      countData in class BaseDataDescriptor<InMemoryDataDescriptor,NoTransaction>
      Parameters:
      transaction - Transaction object used to initiated the query If If null is specified, the query 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 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(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 class BaseDataDescriptor<InMemoryDataDescriptor,NoTransaction>
      Parameters:
      transaction - Transaction object used to initiated the query If If null is specified, the query 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 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 class BaseDataDescriptor<InMemoryDataDescriptor,NoTransaction>
      Parameters:
      transaction - Transaction object used to initiated the query If If null is specified, the query 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 update 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(NoTransaction transaction, Client client, Object... id)
      Fetches a record from the database using the record’s unique ID.
      Specified by:
      findById in class BaseDataDescriptor<InMemoryDataDescriptor,NoTransaction>
      Parameters:
      transaction - Transaction object used to initiated the query If If null is specified, the query 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 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 NoTransaction openTransaction()
      As the DataDescriptor does not support transaction handling, the method returns null.
      Specified by:
      openTransaction in interface DataDescriptor
      Specified by:
      openTransaction in class BaseDataDescriptor<InMemoryDataDescriptor,NoTransaction>
      Returns:
      Transaction object
    • copy

      public InMemoryDataDescriptor copy()
      Creates a copy of the DataDescriptor
      Specified by:
      copy in interface DataDescriptor
      Overrides:
      copy in class BaseDataDescriptor<InMemoryDataDescriptor,NoTransaction>
      Returns:
      A new DataDescriptor, that is a perfect copy of the DataDescriptor