Class DynamoDocumentStore
java.lang.Object
com.codename1.backend.document.DynamoDocumentStore
- All Implemented Interfaces:
DocumentStore, Closeable, AutoCloseable
DocumentStore over DynamoDB: one table per collection, named
tablePrefix + collection, keyed by the partition key and, for a two-column
key, the sort key.
A lookup by the whole key is a GetItem. A query with an equality on the
partition key is a Query over that partition, with at most one comparison
on the sort key in the key condition and the other comparisons as a filter.
Anything else is a Scan with the comparisons as a filter expression.
LIKE, ordering and paging are applied in memory afterwards. Dates are
stored as epoch milliseconds, the form DynamoDB's TTL and numeric
comparisons expect.
-
Constructor Summary
ConstructorsConstructorDescriptionDynamoDocumentStore(DynamoDb db, String tablePrefix) A store overdb, with every table name prefixed bytablePrefix(which may be empty) so environments can share an account. -
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.
-
Constructor Details
-
DynamoDocumentStore
-
-
Method Details
-
ensureCollection
public void ensureCollection(String collection, String[] keyFields, boolean[] numericKeys) throws IOException Description copied from interface:DocumentStorePrepares a collection keyed bykeyFields, each a number wherenumericKeyssays so and a string otherwise; an existing one is kept.- Specified by:
ensureCollectionin interfaceDocumentStore- Throws:
IOException
-
insert
Description copied from interface:DocumentStoreInserts a new document; returns false when one with the same key exists.- Specified by:
insertin interfaceDocumentStore- Throws:
IOException
-
replace
public boolean replace(String collection, String[] keyFields, Map document, String versionField, Object expectedVersion) throws IOException Description copied from interface:DocumentStoreReplaces the document with the same key. WhenversionFieldis not null it replaces only a document whose version isexpectedVersion. Returns whether a document was replaced.- Specified by:
replacein interfaceDocumentStore- Throws:
IOException
-
get
Description copied from interface:DocumentStoreThe document with this key, or null.- Specified by:
getin interfaceDocumentStore- Throws:
IOException
-
delete
public boolean delete(String collection, String[] keyFields, Object[] key, String versionField, Object expectedVersion) throws IOException Description copied from interface:DocumentStoreDeletes the document with this key; returns whether there was one. A non-nullversionFielddeletes only the versionexpectedVersion.- Specified by:
deletein interfaceDocumentStore- Throws:
IOException
-
find
public List find(String collection, String[] keyFields, List criteria, String sortField, boolean ascending, int offset, int limit) throws IOException Description copied from interface:DocumentStoreThe documents matching every criterion, ordered bysortField(null for the store's order), skippingoffsetand returning at mostlimit(negative for no limit).- Specified by:
findin interfaceDocumentStore- Throws:
IOException
-
count
Description copied from interface:DocumentStoreHow many documents match every criterion.- Specified by:
countin interfaceDocumentStore- Throws:
IOException
-
newId
Description copied from interface:DocumentStoreA new identifier for a document whose id is generated.- Specified by:
newIdin interfaceDocumentStore
-
close
public void close()Description copied from interface:DocumentStoreReleases the store's connections.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceDocumentStore
-