T
- the type parameterpublic interface PersistentCollection<T> extends ChangeAware, MetadataAware
The interface Persistent collection.
NitriteCollection
,
ObjectRepository
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes the collection for further access.
|
void |
createIndex(java.lang.String field,
IndexOptions indexOptions)
Creates an index on
value , if not already exists. |
void |
drop()
Drops the collection and all of its indices.
|
void |
dropAllIndices()
Drops all indices from the collection.
|
void |
dropIndex(java.lang.String field)
Drops the index on a
field . |
T |
getById(NitriteId nitriteId)
Gets a single element from the collection by its id.
|
java.lang.String |
getName()
Returns the name of the
PersistentCollection . |
boolean |
hasIndex(java.lang.String field)
Checks if a value is already indexed or not.
|
WriteResult |
insert(T[] elements)
Inserts elements into this collection.
|
boolean |
isClosed()
Returns
true if the collection is closed; otherwise, false . |
boolean |
isDropped()
Returns
true if the collection is dropped; otherwise, false . |
boolean |
isIndexing(java.lang.String field)
Checks if indexing operation is currently ongoing for a
field . |
java.util.Collection<Index> |
listIndices()
Gets a set of all indices in the collection.
|
void |
rebuildIndex(java.lang.String field,
boolean async)
Rebuilds index on
field if it exists. |
WriteResult |
remove(T element)
Deletes the
element from the collection. |
long |
size()
Returns the size of the
PersistentCollection . |
WriteResult |
update(T element)
Updates
element in the collection. |
WriteResult |
update(T element,
boolean upsert)
Updates
element in the collection. |
deregister, register
getAttributes, setAttributes
void createIndex(java.lang.String field, IndexOptions indexOptions)
Creates an index on value
, if not already exists.
If indexOptions
is null
, it will use default options.
<p>
The default indexing option is -
<p>
- indexOptions.setAsync(false);
- indexOptions.setIndexType(IndexType.Unique);
<p>
|
field
- the value to be indexed.indexOptions
- index options.IndexingException
- if an index already exists on value
.IndexOptions
,
IndexType
void rebuildIndex(java.lang.String field, boolean async)
Rebuilds index on field
if it exists.
field
- the value to be indexed.async
- if set to true
, the indexing will run in background; otherwise, in foreground.IndexingException
- if the field
is not indexed.java.util.Collection<Index> listIndices()
Gets a set of all indices in the collection.
Index
boolean hasIndex(java.lang.String field)
Checks if a value is already indexed or not.
field
- the value to check.true
if the value
is indexed; otherwise, false
.boolean isIndexing(java.lang.String field)
Checks if indexing operation is currently ongoing for a field
.
field
- the value to check.true
if indexing is currently running; otherwise, false
.void dropIndex(java.lang.String field)
Drops the index on a field
.
field
- the index of the field
to drop.IndexingException
- if indexing is currently running on the field
.IndexingException
- if the field
is not indexed.void dropAllIndices()
Drops all indices from the collection.
IndexingException
- if indexing is running on any value.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 new NitriteId
and will add it to the '_id'
field.
<p>
If any of the value is already indexed in the collection, then after insertion the
index will also be updated.
<p>
This operations will notify all ChangeListener
instances registered to this collection with change type
ChangeType.INSERT .
|
elements
- an array of element for batch insertion.ValidationException
- if elements
is null
.InvalidIdException
- if the '_id' field’s value contains null
.InvalidIdException
- if the '_id' field’s value contains non comparable type, i.e. type that does not implement Comparable
.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).NitriteId
,
WriteResult
WriteResult update(T element)
Updates element
in the collection. Specified element
must have an id.
This operations will notify all ChangeListener
instances registered to this collection with change type
ChangeType.UPDATE .
|
element
- the element to update.ValidationException
- if the element
is null
.NotIdentifiableException
- if the element
does not have any id.WriteResult update(T element, boolean upsert)
Updates element
in the collection. Specified element
must have an id.
If the element
is not found in the collection, it will be inserted only if upsert
is set to true
.
This operations will notify all ChangeListener
instances registered to this collection with change type
ChangeType.UPDATE or ChangeType.INSERT .
|
element
- the element to update.upsert
- if set to true
, element
will be inserted if not found.ValidationException
- if the element
is null
.NotIdentifiableException
- if the element
does not have any id field.WriteResult remove(T element)
Deletes the element
from the collection. The element
must have an id.
This operations will notify all ChangeListener
instances registered to this collection with change type
ChangeType.REMOVE .
|
element
- the elementNotIdentifiableException
- if the element
does not
have any id field.T getById(NitriteId nitriteId)
Gets a single element from the collection by its id. If no element
is found, it will return null
.
nitriteId
- the nitrite idValidationException
- if nitriteId
is null
.void drop()
Drops the collection and all of its indices.
<p>
Any further access to a dropped collection would result into
a IllegalStateException
.
<p>
This operations will notify all ChangeListener
instances registered to this collection with change type
ChangeType.DROP .
|
boolean isDropped()
Returns true
if the collection is dropped; otherwise, false
.
boolean isClosed()
Returns true
if the collection is closed; otherwise, false
.
void close()
Closes the collection for further access. If a collection once closed
can only be opened via Nitrite.getCollection(String)
or
Nitrite.getRepository(Class)
operation.
<p>
Any access to a closed collection would result into a IllegalStateException
.
<p>
This operations will notify all ChangeListener
instances registered to this collection with change type
ChangeType.CLOSE .
|
java.lang.String getName()
Returns the name of the PersistentCollection
.
long size()
Returns the size of the PersistentCollection
.