Backend API. Server-side code: this runs in a Codename One backend, not in the app on the device.

public interface DocumentStore

ExtendsAutoCloseable, Closeable

Known subtypesDynamoDocumentStore, MongoDocumentStore

The operations DocumentSession needs of a document database.

A document is a Map of strings, numbers, booleans, dates and byte arrays. Its key is held in the fields named by keyFields: one field, the partition key, or two, the partition key and then the sort key. A key value is a String or a Number, given as an array in the same order as keyFields.

Methods

public abstract void ensureCollection(String collection, String[] keyFields, boolean[] numericKeys) throws IOExceptionPrepares a collection keyed by keyFields, each a number where numericKeys says so and a string otherwise; an existing one is kept.
public abstract boolean insert(String collection, String[] keyFields, Map document) throws IOExceptionInserts a new document; returns false when one with the same key exists.
public abstract boolean replace(String collection, String[] keyFields, Map document, String versionField, Object expectedVersion) throws IOExceptionReplaces the document with the same key.
public abstract Map get(String collection, String[] keyFields, Object[] key) throws IOExceptionThe document with this key, or null.
public abstract boolean delete(String collection, String[] keyFields, Object[] key, String versionField, Object expectedVersion) throws IOExceptionDeletes the document with this key; returns whether there was one.
public abstract List find(String collection, String[] keyFields, List criteria, String sortField, boolean ascending, int offset, int limit) throws IOExceptionThe documents matching every criterion, ordered by sortField (null for the store’s order), skipping offset and returning at most limit (negative for no limit).
public abstract long count(String collection, String[] keyFields, List criteria) throws IOExceptionHow many documents match every criterion.
public abstract String newId()A new identifier for a document whose id is generated.
public abstract void close()Releases the store’s connections.

Method details

ensureCollection

public abstract void ensureCollection(String collection, String[] keyFields, boolean[] numericKeys) throws IOException
Prepares a collection keyed by keyFields, each a number where numericKeys says so and a string otherwise; an existing one is kept.

insert

public abstract boolean insert(String collection, String[] keyFields, Map document) throws IOException
Inserts a new document; returns false when one with the same key exists.

replace

public abstract boolean replace(String collection, String[] keyFields, Map document, String versionField, Object expectedVersion) throws IOException
Replaces the document with the same key. When versionField is not null it replaces only a document whose version is expectedVersion. Returns whether a document was replaced.

get

public abstract Map get(String collection, String[] keyFields, Object[] key) throws IOException
The document with this key, or null.

delete

public abstract boolean delete(String collection, String[] keyFields, Object[] key, String versionField, Object expectedVersion) throws IOException
Deletes the document with this key; returns whether there was one. A non-null versionField deletes only the version expectedVersion.

find

public abstract List find(String collection, String[] keyFields, List criteria, String sortField, boolean ascending, int offset, int limit) throws IOException
The documents matching every criterion, ordered by sortField (null for the store’s order), skipping offset and returning at most limit (negative for no limit).

count

public abstract long count(String collection, String[] keyFields, List criteria) throws IOException
How many documents match every criterion.

newId

public abstract String newId()
A new identifier for a document whose id is generated.

close

public abstract void close()
Releases the store’s connections.