Interface DocumentStore
- All Superinterfaces:
AutoCloseable, Closeable
- All Known Implementing Classes:
DynamoDocumentStore, 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.
-
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Releases the store's connections.longHow many documents match every criterion.booleandelete(String collection, String[] keyFields, Object[] key, String versionField, Object expectedVersion) Deletes the document with this key; returns whether there was one.voidensureCollection(String collection, String[] keyFields, boolean[] numericKeys) Prepares a collection keyed bykeyFields, each a number wherenumericKeyssays 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 bysortField(null for the store's order), skippingoffsetand returning at mostlimit(negative for no limit).The document with this key, or null.booleanInserts a new document; returns false when one with the same key exists.newId()A new identifier for a document whose id is generated.booleanreplace(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 bykeyFields, each a number wherenumericKeyssays so and a string otherwise; an existing one is kept.- Throws:
IOException
-
insert
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. WhenversionFieldis not null it replaces only a document whose version isexpectedVersion. Returns whether a document was replaced.- Throws:
IOException
-
get
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-nullversionFielddeletes only the versionexpectedVersion.- 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 bysortField(null for the store's order), skippingoffsetand returning at mostlimit(negative for no limit).- Throws:
IOException
-
count
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:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-