Postgres

The primary target database for @DbArray is Postgres as single dimension array. In time, we could also map this to Oracle nested tables but at this stage that will be done on demand (you can ask and sponsor the development effort etc).

Fallback

For non-Postgres the fallback is to simply store the data in JSON form in VARCHAR (ala @DbJson).

Example: uuid[]

@DbArray
List<UUID> uids = new ArrayList<UUID>();

The example above will map to a database column type uuid[].

Example: integer[]

@DbArray
List<Long> someIds = new ArrayList<Long>();

The example above will map to a database column type integer[].

Example: varchar[]

@DbArray
List<String> phoneNumbers = new ArrayList<String>();

The example above will map to a database column type varchar[].

Fallback varchar length

The length attribute is used with non-Postgres databases and defines the size of the varchar column used in the fallback case.

// fallback to varchar(300) for non-Postgres databases
@DbArray(length = 300)
List<String> phNums = new ArrayList<String>();

Expressions

Ebean "Query Beans" and ExpressionList have 4 expressions added to handle the common ARRAY expressions we want to execute.

The following examples use a phNums property that maps to array of varchar.

contains()

List<Contact> contacts = Contact.find
    .where()
    .phNums.contains("2314")
    .findList();

contains() uses the @> contains operator and results in the following predicate:

where t0.ph_nums @> array[?]; --bind(2314)

notContains()

List<Contact> contacts = Contact.find
    .where()
    .phNums.notContains("2314")
    .findList();

notContains() uses the @> contains operator and results in the following predicate:

where not (t0.ph_nums @> array[?]); --bind(2314)

isEmpty()

List<Contact> contacts = Contact.find
    .where()
    .phNums.isEmpty()
    .findList();

isEmpty() uses the cardinality function and results in the following predicate:

where coalesce(cardinality(t0.ph_nums),0) = 0

isNotEmpty()

List<Contact> contacts = Contact.find
    .where()
    .phNums.isNotEmpty()
    .findList();

isNotEmpty() uses the cardinality function and results in the following predicate:

where coalesce(cardinality(t0.ph_nums),0) <> 0