Support and Documentation

Field types

Dari stores data as a Map<String,Object> as the object's State, using the formats described below.

Note

Class types (Boolean, Integer, Double, etc.) default to null. Primitive types default to a value. For example, a boolean field defaults to false. Therefore, primitives consume more memory than uninitialized object types.

String

The following field types are stored as a String: enumerations, URL, UUID, URI.

Number

The following field types are stored as an implementation of a Number type: Integer/int, Double/double, Long/long, Float/float, Short/short, Byte/byte.

Boolean

The following field types are stored as Boolean: Boolean/boolean.

Date

Dates are represented as java.util.Date objects in memory. In the database, dates are stored in epoch time, for example, 1490673600000.

StorageItem

StorageItems are Dari's implementation for uploading, processing, and delivering files. This class provides abstraction functions for easily representing files as JSON objects. For example, the following snippet describes a file residing on local storage.

{
  "file":{
    "storage":"Local file storage",
    "path":"/Users/birdArtist/drawings/woodchuck.png",
    "contentType":"image/png",
    "metadata":null
  }
}

For a detailed explanation of StorageItems and working with files, see File storage.

Locale

Use java.util.Locale for storing Locale data. The value gets stored as text, for example:

{
  "locale":"en-US"
}
Record

Any Dari object that extends Record can be persisted in the database in JSON format. The following example illustrates a simple activity object.

{
  "activityDate": 1492833600000,
  "activityType": "Download RFP response",
  "_id": "0000015a-dc72-dcb9-af7b-fdfac06c0000",
  "_type": "0000015a-7bb5-d284-addf-7ff7e7c00000"
}

Each persisted object has a unique _id (ID) and an associated _type (type identifier).

Records can be nested, either by reference or embedded. For details, see Relationships.

Location

Locations are stored as Dari Location objects. The Location class is a container for a two-dimensional space, defined by latitude and longitude values. A Location object cannot be saved as a database record, but can be embedded in a Record-derived object. For example, the following JSON example represents a City object, which derives from Record. City references a Location object.

{
  "name":"Seattle",
  "location":{
    "x":47.608013,
    "y":-122.335167
  },
  "_id":"0000015a-f87a-dc82-ab7b-ff7e42050000",
  "_type":"0000015a-f857-d85a-a7de-fe570fa70000"
}
Region

Regions are stored as Dari Region objects. The Region class is a container for a three-dimensional circular space based on a spherical or Cartesian coordinate system. A Region object cannot be saved as a database record, but can be embedded in a Record-derived object. For example, the following JSON example represents a Watershed object, which derives from Record. Watershed references a list of watersources, consisting of three Region objects.

{
  "name": "Puget Sound",
  "watersources": [{
    "polygons": [
      [
        [
          [
            138.92975190516853, 73.02111110999999
          ],
          [138.92975190516853, 23.02111111],
          [105.48691475483149, 23.02111111],
          [105.48691475483149, 73.02111110999999],
          [138.92975190516853, 73.02111110999999]
        ]
      ]
    ],
    "circles": null,
    "x": 48.02111111,
    "y": 122.20833333,
    "radius": 25.0
  }, {
    "polygons": [
      [
        [
          [139.11691099660493, 72.61666667],
          [139.11691099660493, 22.61666667],
          [105.41253344339506, 22.61666667],
          [105.41253344339506, 72.61666667],
          [139.11691099660493, 72.61666667]
        ]
      ]
    ],
    "circles": null,
    "x": 47.61666667,
    "y": 122.26472222,
    "radius": 25.0
  }, {
    "polygons": [
      [
        [
          [139.71832470428922, 72.10861111],
          [139.71832470428922, 22.10861111],
          [105.68778641571079, 22.10861111],
          [105.68778641571079, 72.10861111],
          [139.71832470428922, 72.10861111]
        ]
      ]
    ],
    "circles": null,
    "x": 47.10861111,
    "y": 122.70305556,
    "radius": 25.0
  }],
  "_id": "0000015a-fb23-d820-a37b-fb73772e0000",
  "_type": "0000015a-fb09-d55a-a75a-fb5dffc00000"
}

Collections (List or Set)

Collections are stored as a multiple of any of the above field types. Set prevents duplicates and order is not guaranteed. List allows duplicates and order is guaranteed.

Collections are automatically handled by Dari. No extra tables or information are needed. For example, the Person class need only reference a list of Activity objects:

import com.psddev.dari.db.Record;

public classActivity extends Record {

    @IndexedprivateStringactivityType;
    privateDateactivityDate;
    
    /* Getters and setters */
}
import com.psddev.dari.db.Record;

public class Person extends Record {

    private String firstName;

    @Indexed private String lastName;
    private List<Activity> activities;

    /* Getters and setters */
}

Note

Indexes on collections are also supported. However, performance should be considered when adding indexes to collections. Each item in a collection results in an additional row that is written to the underlying database index tables when using an SQL database back end.

Also, be careful that your collections do not grow unbounded. Large collections can slow down retrieval of data since Dari retrieves collection data even if you do not need it.