Interface DocumentStore

All Superinterfaces:
AutoCloseable, Closeable
All Known Implementing Classes:
DynamoDocumentStore, MongoDocumentStore

public interface DocumentStore extends Closeable

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.

  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Releases the store's connections.
    long
    count(String collection, String[] keyFields, List criteria)
    How many documents match every criterion.
    boolean
    delete(String collection, String[] keyFields, Object[] key, String versionField, Object expectedVersion)
    Deletes the document with this key; returns whether there was one.
    void
    ensureCollection(String collection, String[] keyFields, boolean[] numericKeys)
    Prepares a collection keyed by keyFields, each a number where numericKeys says so and a string otherwise; an existing one is kept.
    find(String collection, String[] keyFields, List criteria, String sortField, boolean ascending, int offset, int limit)
    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).
    get(String collection, String[] keyFields, Object[] key)
    The document with this key, or null.
    boolean
    insert(String collection, String[] keyFields, Map document)
    Inserts a new document; returns false when one with the same key exists.
    A new identifier for a document whose id is generated.
    boolean
    replace(String collection, String[] keyFields, Map document, String versionField, Object expectedVersion)
    Replaces the document with the same key.
  • Method Details

    • ensureCollection

      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.
      Throws:
      IOException
    • insert

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

      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.
      Throws:
      IOException
    • get

      Map get(String collection, String[] keyFields, Object[] key) throws IOException
      The document with this key, or null.
      Throws:
      IOException
    • delete

      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.
      Throws:
      IOException
    • find

      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).
      Throws:
      IOException
    • count

      long count(String collection, String[] keyFields, List criteria) throws IOException
      How many documents match every criterion.
      Throws:
      IOException
    • newId

      String newId()
      A new identifier for a document whose id is generated.
    • close

      void close()
      Releases the store's connections.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable