Class DocumentSession
java.lang.Object
com.codename1.backend.document.DocumentSession
- All Implemented Interfaces:
Closeable, AutoCloseable
Persists @Entity classes in a DocumentStore: one document per entity,
one collection per entity table, each field under its column name.
DocumentSession s = DocumentSession.current();
s.persist(order);
List<Order> open = s.query(Order.class).eq("status", "OPEN").orderBy("placed", false).list();
What the SQL session does that this one does not is listed in the package description: relationships, numeric generated ids, identifiers of more than two columns, an identity map and multi-call transactions.
-
Constructor Summary
ConstructorsConstructorDescriptionDocumentSession(DocumentStore store) A session overstore; closing the session closes the store. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes this and releases what it holds.voidcreateCollections(Class... types) Creates the collection (or table) for each entity type, if missing.static DocumentSessioncurrent()The session of the calling thread's server, opened fromcn1.document.urlthe first time it is asked for and closed when the server stops.<T> TThe entity with this id, or null.getStore()The store this session writes to.<T> Tmerge(T entity) Replaces the stored document ofentity.static DocumentSessionA session fromcn1.document.url: amongodb://connection string, ordynamodb://REGION, optionally with?endpoint=URL(DynamoDB Local) and&prefix=for the table names.static DocumentSessionA session from a document store URL; seeopen(Config).<T> Tpersist(T entity) Insertsentity.<T> DocumentQuery<T> A query over the entities oftype.<T> booleanremove(T entity)
-
Constructor Details
-
DocumentSession
A session overstore; closing the session closes the store. Opened inside a server, it keeps each@Searchableentity's search index in step with every write that succeeds.
-
-
Method Details
-
current
The session of the calling thread's server, opened fromcn1.document.urlthe first time it is asked for and closed when the server stops.- Throws:
IOException
-
open
A session fromcn1.document.url: amongodb://connection string, ordynamodb://REGION, optionally with?endpoint=URL(DynamoDB Local) and&prefix=for the table names. Without the key,cn1.mongodb.uriand the Spring MongoDB properties are used.- Throws:
IOException
-
open
A session from a document store URL; seeopen(Config).- Throws:
IOException
-
getStore
The store this session writes to. -
createCollections
Creates the collection (or table) for each entity type, if missing.- Throws:
IOException
-
persist
Insertsentity. A null generated text id is assigned first; the entity returned carries it (a new instance for an immutable entity).- Throws:
IOException
-
merge
Replaces the stored document ofentity. With a@Versionfield the write succeeds only if the stored version is the entity's, and the version is incremented; otherwiseOptimisticLockExceptionis thrown.- Throws:
IOException
-
find
The entity with this id, or null.- Throws:
IOException
-
remove
Deletesentity, honouring its@Versionlikemerge(Object). Returns false if there was nothing to delete and the entity has no version.- Throws:
IOException
-
query
A query over the entities oftype. -
close
public void close()Description copied from interface:CloseableCloses this and releases what it holds. Closing it again has no effect.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-