Interface PersistentCollection<T>
- Type Parameters:
T- the type of data stored in the collection.
- All Superinterfaces:
org.dizitart.no2.common.meta.AttributesAware,AutoCloseable,EventAware
- All Known Subinterfaces:
NitriteCollection,ObjectRepository<T>
- Since:
- 1.0
- Author:
- Anindya Chatterjee.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionvoidaddProcessor(Processor processor) Adds a data processor to this collection.voidclear()Removes all element from the collection.voidclose()Closes thisPersistentCollection.default voidcreateIndex(String... fields) Creates a unique index on thefields, if not already exists.voidcreateIndex(IndexOptions indexOptions, String... fields) Creates an index on thefields, if not already exists.voiddrop()Drops the collection and all of its indices.voidDrops all indices from the collection.voidDrops the index on thefields.NitriteStore<?>getStore()Returns theNitriteStoreinstance for this collection.booleanChecks if thefieldsis already indexed or not.Inserts elements into this collection.booleanReturnstrueif the collection is dropped; otherwise,false.booleanisIndexing(String... fields) Checks if indexing operation is currently ongoing for thefields.booleanisOpen()Returnstrueif the collection is open; otherwise,false.Gets a set of all indices in the collection.voidrebuildIndex(String... fields) Rebuilds index on thefieldsif it exists.Deletes theelementfrom the collection.longsize()Returns the size of thePersistentCollection.default WriteResultUpdates theelementin the collection.Updateselementin the collection.Methods inherited from interface org.dizitart.no2.common.meta.AttributesAware
getAttributes, setAttributesMethods inherited from interface org.dizitart.no2.collection.events.EventAware
subscribe, unsubscribe
-
Method Details
-
addProcessor
Adds a data processor to this collection.- Parameters:
processor- the processor
-
createIndex
Creates a unique index on thefields, if not already exists.- Parameters:
fields- the fields to be indexed.- Throws:
IndexingException- if an index already exists on the field.
-
createIndex
Creates an index on thefields, if not already exists. IfindexOptionsisnull, it will use default options.The default indexing option is -
indexOptions.setIndexType(IndexType.Unique);
NOTE:
- _id field is always indexed.
- Full-text indexing is not supported on _id value.
- Indexing on non-comparable value is not supported.
- Parameters:
indexOptions- index options.fields- the fields to be indexed.- Throws:
IndexingException- if an index already exists on the field.- See Also:
-
rebuildIndex
Rebuilds index on thefieldsif it exists.- Parameters:
fields- the fields to be indexed.- Throws:
IndexingException- if thefieldis not indexed.
-
listIndices
Collection<IndexDescriptor> listIndices()Gets a set of all indices in the collection.- Returns:
- a set of all indices.
- See Also:
-
hasIndex
Checks if thefieldsis already indexed or not.- Parameters:
fields- the fields to check.- Returns:
trueif thefieldis indexed; otherwise,false.
-
isIndexing
Checks if indexing operation is currently ongoing for thefields.- Parameters:
fields- the fields to check.- Returns:
trueif indexing is currently running; otherwise,false.
-
dropIndex
Drops the index on thefields.- Parameters:
fields- the index on thefieldsto drop.- Throws:
IndexingException- if indexing is currently running on thefields.IndexingException- if thefieldsare not indexed.
-
dropAllIndices
void dropAllIndices()Drops all indices from the collection.- Throws:
IndexingException- if indexing is running on any value.
-
insert
Inserts elements into this collection. If the element has an _id field, then the value will be used as an unique key to identify the element in the collection. If the element does not have any _id field, then nitrite will generate a newNitriteIdand will add it to the _id field.If any of the field is already indexed in the collection, then after insertion the index will also be updated.
NOTE: This operations will notify all
CollectionEventListenerinstances registered to this collection with change typeEventType.Insert.- Parameters:
elements- an array of element for batch insertion.- Returns:
- the result of the write operation.
- Throws:
ValidationException- if elements is null.InvalidIdException- if the _id field's value containsnull.InvalidIdException- if the _id field's value contains non comparable type, i.e. type that does not implementComparable.InvalidIdException- if the _id field contains value which is not of the same java type as of other element's _id field value in the collection.UniqueConstraintException- if the value of _id field clashes with the _id field of another element in the repository.UniqueConstraintException- if a value of the element is indexed and it violates the unique constraint in the collection(if any).- See Also:
-
update
Updates theelementin the collection. Specifiedelementmust have an id.NOTE: This operations will notify all
CollectionEventListenerinstances registered to this collection with change typeEventType.Update.- Parameters:
element- the element to update.- Returns:
- the result of the update operation.
- Throws:
ValidationException- if the element isnull.NotIdentifiableException- if the element does not have any id.
-
update
Updateselementin the collection. Specifiedelementmust have an id. If theelementis not found in the collection, it will be inserted only ifinsertIfAbsentis set totrue.NOTE: This operations will notify all
CollectionEventListenerinstances registered to this collection with change typeEventType.UpdateorEventType.Insert.- Parameters:
element- the element to update.insertIfAbsent- if set totrue,elementwill be inserted if not found.- Returns:
- the result of the update operation.
- Throws:
ValidationException- if theelementisnull.NotIdentifiableException- if theelementdoes not have any id field.
-
remove
Deletes theelementfrom the collection. Theelementmust have an id.NOTE: This operations will notify all
CollectionEventListenerinstances registered to this collection with change typeEventType.Remove.- Parameters:
element- the element- Returns:
- the result of the remove operation.
- Throws:
NotIdentifiableException- if theelementdoes not have any id field.
-
clear
void clear()Removes all element from the collection. -
drop
void drop()Drops the collection and all of its indices.Any further access to a dropped collection would result into an exception.
-
isDropped
boolean isDropped()Returnstrueif the collection is dropped; otherwise,false.- Returns:
- a boolean value indicating if the collection has been dropped or not.
-
isOpen
boolean isOpen()Returnstrueif the collection is open; otherwise,false.- Returns:
- a boolean value indicating if the collection has been closed or not.
-
size
long size()Returns the size of thePersistentCollection.- Returns:
- the size.
-
close
void close()Closes thisPersistentCollection.- Specified by:
closein interfaceAutoCloseable
-
getStore
NitriteStore<?> getStore()Returns theNitriteStoreinstance for this collection.- Returns:
- the
NitriteStoreinstance.
-