Class MongoDocumentStore
java.lang.Object
com.codename1.backend.document.MongoDocumentStore
- All Implemented Interfaces:
DocumentStore, Closeable, AutoCloseable
DocumentStore over MongoDB: the identifier is stored as _id, criteria
become a query filter, and sorting and paging run on the server.-
Constructor Summary
ConstructorsConstructorDescriptionMongoDocumentStore(MongoClient client, MongoDatabase database, boolean ownsClient) A store overdatabaseofclient(null for the database the connection string names);ownsClientcloses the client with it. -
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
-
MongoDocumentStore
A store overdatabaseofclient(null for the database the connection string names);ownsClientcloses the client with it.
-
-
Method Details
-
ensureCollection
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
-
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
-