Interface NitriteCollection
-
- All Superinterfaces:
org.dizitart.no2.common.meta.AttributesAware
,AutoCloseable
,EventAware
,PersistentCollection<Document>
public interface NitriteCollection extends PersistentCollection<Document>
Represents a named document collection stored in Nitrite database. It persists documents into the database. Each document is associated with a uniqueNitriteId
in a collection.A nitrite collection supports indexing. Every nitrite collection is also observable. It means, any change in a collection can be listened back via registering a
Create a collectionCollectionEventListener
.Nitrite db = Nitrite.builder() .openOrCreate("user", "password"); NitriteCollection collection = db.getCollection("products");
- Since:
- 1.0
- Author:
- Anindya Chatterjee
- See Also:
EventAware
,Document
,NitriteId
,CollectionEventListener
,EventBus
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default DocumentCursor
find()
Returns a cursor to all documents in the collection.default DocumentCursor
find(FindOptions findOptions)
Returns a customized cursor to all documents in the collection.default DocumentCursor
find(Filter filter)
Applies a filter on the collection and returns a cursor to the selected documents.DocumentCursor
find(Filter filter, FindOptions findOptions)
Applies a filter on the collection and returns a customized cursor to the selected documents.Document
getById(NitriteId nitriteId)
Gets a single element from the collection by its id.String
getName()
Returns the name of theNitriteCollection
.default WriteResult
insert(Document document, Document... documents)
Inserts documents into a collection.default WriteResult
remove(Filter filter)
Removes matching elements from the collection.WriteResult
remove(Filter filter, boolean justOne)
Removes document from a collection.default WriteResult
update(Filter filter, Document update)
Update documents in the collection.WriteResult
update(Filter filter, Document update, UpdateOptions updateOptions)
Updates document in the collection.-
Methods inherited from interface org.dizitart.no2.common.meta.AttributesAware
getAttributes, setAttributes
-
Methods inherited from interface org.dizitart.no2.collection.events.EventAware
subscribe, unsubscribe
-
Methods inherited from interface org.dizitart.no2.common.PersistentCollection
addProcessor, clear, close, createIndex, createIndex, drop, dropAllIndices, dropIndex, getStore, hasIndex, insert, isDropped, isIndexing, isOpen, listIndices, rebuildIndex, remove, size, update, update
-
-
-
-
Method Detail
-
insert
default WriteResult insert(Document document, Document... documents)
Inserts documents into a collection. If the document contains aNitriteId
in its_id
field, then it will be used as a unique key to identify the document in the collection. If the document does not contain anyNitriteId
, then a newNitriteId
will be generated and inserted into the document.If any of the field is already indexed in the collection, then after insertion the index will also be updated.
NOTE: These operations will notify all
CollectionEventListener
instances registered to this collection with change typeEventType.Insert
.- Parameters:
document
- the document to insertdocuments
- other documents to insert in a batch.- Returns:
- the result of write operation.
- Throws:
ValidationException
- ifdocument
isnull
.InvalidIdException
- if the_id
value contains non-comparable type, i.e. type that does not implementComparable
.UniqueConstraintException
- if the value of_id
value clashes with the id of another document in the collection.UniqueConstraintException
- if a field of the document is indexed, and it violates the unique constraint in the collection(if any).- See Also:
NitriteId
,WriteResult
-
update
default WriteResult update(Filter filter, Document update)
Update documents in the collection.If the
filter
isnull
, it will update all documents in the collection.NOTE: This operations will notify all
CollectionEventListener
instances registered to this collection with change typeEventType.Update
.- Parameters:
filter
- the filter to apply to select documents from the collection.update
- the modifications to apply.- Returns:
- the result of the update operation.
- Throws:
ValidationException
- if theupdate
document isnull
.
-
update
WriteResult update(Filter filter, Document update, UpdateOptions updateOptions)
Updates document in the collection. Update operation can be customized with the help ofupdateOptions
.If the
filter
isnull
, it will update all documents in the collection unlessjustOnce
is set totrue
inupdateOptions
.NOTE: This operations will notify all
CollectionEventListener
instances registered to this collection with change typeEventType.Update
orEventType.Insert
.- Parameters:
filter
- the filter to apply to select documents from the collection.update
- the modifications to apply.updateOptions
- the update options to customize the operation.- Returns:
- the result of the update operation.
- Throws:
ValidationException
- if theupdate
document isnull
.ValidationException
- ifupdateOptions
isnull
.- See Also:
UpdateOptions
-
remove
default WriteResult remove(Filter filter)
Removes matching elements from the collection.If the
filter
isnull
, it will remove all objects from the collection.NOTE: This operations will notify all
CollectionEventListener
instances registered to this collection with change typeEventType.Remove
.- Parameters:
filter
- the filter to apply to select elements from collection.- Returns:
- the result of the remove operation.
-
remove
WriteResult remove(Filter filter, boolean justOne)
Removes document from a collection. Remove operation can be customized byremoveOptions
.If the
filter
isnull
, it will remove all documents in the collection unlessjustOnce
is set totrue
inremoveOptions
.NOTE: This operations will notify all
CollectionEventListener
instances registered to this collection with change typeEventType.Remove
.- Parameters:
filter
- the filter to apply to select documents from collection.justOne
- indicates if only one element will be removed or all of them.- Returns:
- the result of the remove operation.
-
find
default DocumentCursor find()
Returns a cursor to all documents in the collection.- Returns:
- a cursor to all documents in the collection.
-
find
default DocumentCursor find(Filter filter)
Applies a filter on the collection and returns a cursor to the selected documents.See
Filter
for all available filters.NOTE: If there is an index on the value specified in the filter, this operation will take advantage of the index.
- Parameters:
filter
- the filter to apply to select documents from collection.- Returns:
- a cursor to all selected documents.
- Throws:
ValidationException
- iffilter
is null.- See Also:
Filter
,DocumentCursor.project(Document)
-
find
default DocumentCursor find(FindOptions findOptions)
Returns a customized cursor to all documents in the collection.- Parameters:
findOptions
- specifies pagination, sort options for the cursor.- Returns:
- a cursor to all selected documents.
- See Also:
SortOrder
-
find
DocumentCursor find(Filter filter, FindOptions findOptions)
Applies a filter on the collection and returns a customized cursor to the selected documents.NOTE: If there is an index on the value specified in the filter, this operation will take advantage of the index.
- Parameters:
filter
- the filter to apply to select documents from collection.findOptions
- specifies pagination, sort options for the cursor.- Returns:
- a cursor to all selected documents.
-
getById
Document getById(NitriteId nitriteId)
Gets a single element from the collection by its id. If no element is found, it will returnnull
.- Parameters:
nitriteId
- the nitrite id- Returns:
- the unique document associated with the nitrite id.
- Throws:
ValidationException
- if `nitriteId` isnull
.
-
getName
String getName()
Returns the name of theNitriteCollection
.- Returns:
- the name.
-
-