Interface PersistentCollection<T>

    • 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 the fields, 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 the fields, if not already exists. If indexOptions is null, 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 the fields if it exists.
        Parameters:
        fields - the fields to be indexed.
        Throws:
        IndexingException - if the field is not indexed.
      • hasIndex

        boolean hasIndex​(String... fields)
        Checks if the fields is already indexed or not.
        Parameters:
        fields - the fields to check.
        Returns:
        true if the field is indexed; otherwise, false.
      • isIndexing

        boolean isIndexing​(String... fields)
        Checks if indexing operation is currently ongoing for the fields.
        Parameters:
        fields - the fields to check.
        Returns:
        true if indexing is currently running; otherwise, false.
      • dropIndex

        void dropIndex​(String... fields)
        Drops the index on the fields.
        Parameters:
        fields - the index on the fields to drop.
        Throws:
        IndexingException - if indexing is currently running on the fields.
        IndexingException - if the fields are 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 new NitriteId and 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 CollectionEventListener instances registered to this collection with change type EventType.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 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).
        See Also:
        NitriteId, WriteResult
      • update

        default WriteResult update​(T element)
        Updates the element in the collection. Specified element must have an id.

        NOTE: This operations will notify all CollectionEventListener instances registered to this collection with change type EventType.Update.

        Parameters:
        element - the element to update.
        Returns:
        the result of the update operation.
        Throws:
        ValidationException - if the element is null.
        NotIdentifiableException - if the element does not have any id.
      • update

        WriteResult update​(T element,
                           boolean insertIfAbsent)
        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 insertIfAbsent is set to true.

        NOTE: This operations will notify all CollectionEventListener instances registered to this collection with change type EventType.Update or EventType.Insert.

        Parameters:
        element - the element to update.
        insertIfAbsent - if set to true, element will be inserted if not found.
        Returns:
        the result of the update operation.
        Throws:
        ValidationException - if the element is null.
        NotIdentifiableException - if the element does not have any id field.
      • remove

        WriteResult remove​(T element)
        Deletes the element from the collection. The element must have an id.

        NOTE: This operations will notify all CollectionEventListener instances registered to this collection with change type EventType.Remove.

        Parameters:
        element - the element
        Returns:
        the result of the remove operation.
        Throws:
        NotIdentifiableException - if the element does 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()
        Returns true if the collection is dropped; otherwise, false.
        Returns:
        a boolean value indicating if the collection has been dropped or not.
      • isOpen

        boolean isOpen()
        Returns true if the collection is open; otherwise, false.
        Returns:
        a boolean value indicating if the collection has been closed or not.