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>
public interface PersistentCollection<T> extends EventAware, org.dizitart.no2.common.meta.AttributesAware, AutoCloseable
A persistent collection interface that provides methods to manage and manipulate data in a Nitrite database.- Since:
- 1.0
- Author:
- Anindya Chatterjee.
- See Also:
NitriteCollection,ObjectRepository
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description voidaddProcessor(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.voiddropAllIndices()Drops all indices from the collection.voiddropIndex(String... fields)Drops the index on thefields.NitriteStore<?>getStore()Returns theNitriteStoreinstance for this collection.booleanhasIndex(String... fields)Checks if thefieldsis already indexed or not.WriteResultinsert(T[] elements)Inserts elements into this collection.booleanisDropped()Returnstrueif 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.Collection<IndexDescriptor>listIndices()Gets a set of all indices in the collection.voidrebuildIndex(String... fields)Rebuilds index on thefieldsif it exists.WriteResultremove(T element)Deletes theelementfrom the collection.longsize()Returns the size of thePersistentCollection.default WriteResultupdate(T element)Updates theelementin the collection.WriteResultupdate(T element, boolean insertIfAbsent)Updateselementin 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
-
-
-
-
Method Detail
-
addProcessor
void addProcessor(Processor processor)
Adds a data processor to this collection.- Parameters:
processor- the processor
-
createIndex
default void createIndex(String... fields)
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
void createIndex(IndexOptions indexOptions, String... fields)
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:
IndexOptions,IndexType
-
rebuildIndex
void rebuildIndex(String... fields)
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:
IndexDescriptor
-
hasIndex
boolean hasIndex(String... fields)
Checks if thefieldsis already indexed or not.- Parameters:
fields- the fields to check.- Returns:
trueif thefieldis indexed; otherwise,false.
-
isIndexing
boolean isIndexing(String... fields)
Checks if indexing operation is currently ongoing for thefields.- Parameters:
fields- the fields to check.- Returns:
trueif indexing is currently running; otherwise,false.
-
dropIndex
void dropIndex(String... fields)
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
WriteResult insert(T[] elements)
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:
NitriteId,WriteResult
-
update
default WriteResult update(T element)
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
WriteResult update(T element, boolean insertIfAbsent)
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
WriteResult remove(T element)
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.
-
-