Query for data within a Partition

Partitions are used to divide large data sets to provide quicker access and increase capability to distribute data among logical parts.

You can download the code for this example here:

OnyxDevTools/onyx-database-samples/partition.

  1. Create a PhoneNumber and CallLog entity.

    For this example we have a Phone that makes calls and logs the metadata regarding the call. We would like to make the storage of these call logs more robust so we can run some analytical queries to determine what calls were monitored by the NSA for each zip code.

    Notes:
    Make an entity partitioned by adding the @Partition annotation to the attribute that is used to differentiate the partition.
    Each entity maintains its own partition. Entire object graphs are not stored in a partition.
    If the partition attribute value is null, the data will be stored in a default partition.
  2. Populate test data in different partitions.

    Call logs are stored in partitions for area codes 555 and 123.

    Notes:
    Each partition is stored in a separate physical storage.
    An entities primary key or identifier is not unique among different partitions. In other words, you can have the same identifier for entities in different partitions.
    The partition should be pre-determined. What me mean by that is the partition cannot be defined by runtime listeners. It must be defined prior to persisting the entity(s).
  3. Create a query to find NSA monitored calls
    Notes:
    The partition parameter is set on the Query object to query the partition with value 555.
    The isNSAListening field is populated so this query should be highly optimized.
    Query results indicate only 1 CallLog was recorded by the NSA.
  4. Partition Find By ID