All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.arangodb.ArangoCollection Maven / Gradle / Ivy

There is a newer version: 7.8.0
Show newest version
/*
 * DISCLAIMER
 *
 * Copyright 2016 ArangoDB GmbH, Cologne, Germany
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * Copyright holder is ArangoDB GmbH, Cologne, Germany
 */

package com.arangodb;

import com.arangodb.entity.*;
import com.arangodb.model.*;
import com.arangodb.util.RawData;

import javax.annotation.concurrent.ThreadSafe;
import java.util.Collection;

/**
 * Interface for operations on ArangoDB collection level.
 *
 * @author Mark Vollmary
 * @author Heiko Kernbach
 * @author Michele Rastelli
 * @see Collection API Documentation
 * @see Documents API Documentation
 */
@ThreadSafe
public interface ArangoCollection extends ArangoSerdeAccessor {

    /**
     * The the handler of the database the collection is within
     *
     * @return database handler
     */
    ArangoDatabase db();

    /**
     * The name of the collection
     *
     * @return collection name
     */
    String name();

    /**
     * Creates a new document from the given document, unless there is already a document with the _key given. If no
     * _key is given, a new unique _key is generated automatically.
     *
     * @param value A representation of a single document (POJO or {@link com.arangodb.util.RawData}
     * @return information about the document
     * @see API
     * Documentation
     */
    DocumentCreateEntity insertDocument(Object value);

    /**
     * Creates a new document from the given document, unless there is already a document with the _key given. If no
     * _key is given, a new unique _key is generated automatically.
     *
     * @param value   A representation of a single document (POJO or {@link com.arangodb.util.RawData})
     * @param options Additional options
     * @return information about the document
     * @see API
     * Documentation
     */
     DocumentCreateEntity insertDocument(T value, DocumentCreateOptions options);

    /**
     * Creates a new document from the given document, unless there is already a document with the _key given. If no
     * _key is given, a new unique _key is generated automatically.
     *
     * @param value   A representation of a single document (POJO or {@link com.arangodb.util.RawData})
     * @param options Additional options
     * @param type    Deserialization target type for the returned documents.
     * @return information about the document
     * @see API
     * Documentation
     */
     DocumentCreateEntity insertDocument(T value, DocumentCreateOptions options, Class type);

    /**
     * Creates new documents from the given documents, unless there is already a document with the _key given. If no
     * _key is given, a new unique _key is generated automatically.
     *
     * @param values Raw data representing a collection of documents
     * @return information about the documents
     * @see API
     * Documentation
     */
    MultiDocumentEntity> insertDocuments(RawData values);

    /**
     * Creates new documents from the given documents, unless there is already a document with the _key given. If no
     * _key is given, a new unique _key is generated automatically.
     *
     * @param values  Raw data representing a collection of documents
     * @param options Additional options
     * @return information about the documents
     * @see API
     * Documentation
     */
    MultiDocumentEntity> insertDocuments(
            RawData values, DocumentCreateOptions options);

    /**
     * Creates new documents from the given documents, unless there is already a document with the _key given. If no
     * _key is given, a new unique _key is generated automatically.
     *
     * @param values A List of documents
     * @return information about the documents
     * @see API
     * Documentation
     */
    MultiDocumentEntity> insertDocuments(Collection values);

    /**
     * Creates new documents from the given documents, unless there is already a document with the _key given. If no
     * _key is given, a new unique _key is generated automatically.
     *
     * @param values  A List of documents (POJO or {@link com.arangodb.util.RawData})
     * @param options Additional options
     * @return information about the documents
     * @see API
     * Documentation
     */
    MultiDocumentEntity> insertDocuments(
            Collection values, DocumentCreateOptions options);

    /**
     * Creates new documents from the given documents, unless there is already a document with the _key given. If no
     * _key is given, a new unique _key is generated automatically.
     *
     * @param values  A List of documents (POJO or {@link com.arangodb.util.RawData})
     * @param options Additional options
     * @param type    Deserialization target type for the returned documents.
     * @return information about the documents
     * @see API
     * Documentation
     */
     MultiDocumentEntity> insertDocuments(
            Collection values, DocumentCreateOptions options, Class type);

    /**
     * Bulk imports the given values into the collection.
     *
     * @param values A List of documents (POJO or {@link com.arangodb.util.RawData})
     * @return information about the import
     */
    DocumentImportEntity importDocuments(Collection values);

    /**
     * Bulk imports the given values into the collection.
     *
     * @param values  A List of documents (POJO or {@link com.arangodb.util.RawData})
     * @param options Additional options, can be null
     * @return information about the import
     */
    DocumentImportEntity importDocuments(Collection values, DocumentImportOptions options);

    /**
     * Bulk imports the given values into the collection.
     *
     * @param values Raw data representing a collection of documents
     * @return information about the import
     */
    DocumentImportEntity importDocuments(RawData values);

    /**
     * Bulk imports the given values into the collection.
     *
     * @param values  Raw data representing a collection of documents
     * @param options Additional options, can be null
     * @return information about the import
     */
    DocumentImportEntity importDocuments(RawData values, DocumentImportOptions options);

    /**
     * Retrieves the document with the given {@code key} from the collection.
     *
     * @param key  The key of the document
     * @param type The type of the document (POJO or {@link com.arangodb.util.RawData})
     * @return the document identified by the key
     * @see API
     * Documentation
     */
     T getDocument(String key, Class type);

    /**
     * Retrieves the document with the given {@code key} from the collection.
     *
     * @param key     The key of the document
     * @param type    The type of the document (POJO or {@link com.arangodb.util.RawData})
     * @param options Additional options, can be null
     * @return the document identified by the key
     * @see API
     * Documentation
     */
     T getDocument(String key, Class type, DocumentReadOptions options);

    /**
     * Retrieves multiple documents with the given {@code _key} from the collection.
     *
     * @param keys The keys of the documents
     * @param type The type of the documents (POJO or {@link com.arangodb.util.RawData})
     * @return the documents and possible errors
     */
     MultiDocumentEntity getDocuments(Collection keys, Class type);

    /**
     * Retrieves multiple documents with the given {@code _key} from the collection.
     *
     * @param keys    The keys of the documents
     * @param type    The type of the documents (POJO or {@link com.arangodb.util.RawData})
     * @param options Additional options, can be null
     * @return the documents and possible errors
     */
     MultiDocumentEntity getDocuments(Collection keys, Class type, DocumentReadOptions options);

    /**
     * Replaces the document with {@code key} with the one in the body, provided there is such a document and no
     * precondition is violated
     *
     * @param key   The key of the document
     * @param value A representation of a single document (POJO or {@link com.arangodb.util.RawData})
     * @return information about the document
     * @see
     * API
     * Documentation
     */
    DocumentUpdateEntity replaceDocument(String key, Object value);

    /**
     * Replaces the document with {@code key} with the one in the body, provided there is such a document and no
     * precondition is violated
     *
     * @param key     The key of the document
     * @param value   A representation of a single document (POJO or {@link com.arangodb.util.RawData})
     * @param options Additional options
     * @return information about the document
     * @see
     * API
     * Documentation
     */
     DocumentUpdateEntity replaceDocument(String key, T value, DocumentReplaceOptions options);

    /**
     * Replaces the document with {@code key} with the one in the body, provided there is such a document and no
     * precondition is violated
     *
     * @param key     The key of the document
     * @param value   A representation of a single document (POJO or {@link com.arangodb.util.RawData})
     * @param options Additional options
     * @param type    Deserialization target type for the returned documents.
     * @return information about the document
     * @see
     * API
     * Documentation
     */
     DocumentUpdateEntity replaceDocument(String key, T value, DocumentReplaceOptions options, Class type);

    /**
     * Replaces multiple documents in the specified collection with the ones in the values, the replaced documents are
     * specified by the _key attributes in the documents in values.
     *
     * @param values Raw data representing a collection of documents
     * @return information about the documents
     * @see
     * API
     * Documentation
     */
    MultiDocumentEntity> replaceDocuments(RawData values);

    /**
     * Replaces multiple documents in the specified collection with the ones in the values, the replaced documents are
     * specified by the _key attributes in the documents in values.
     *
     * @param values  Raw data representing a collection of documents
     * @param options Additional options
     * @return information about the documents
     * @see
     * API
     * Documentation
     */
    MultiDocumentEntity> replaceDocuments(
            RawData values, DocumentReplaceOptions options);

    /**
     * Replaces multiple documents in the specified collection with the ones in the values, the replaced documents are
     * specified by the _key attributes in the documents in values.
     *
     * @param values A List of documents (POJO or {@link com.arangodb.util.RawData})
     * @return information about the documents
     * @see
     * API
     * Documentation
     */
    MultiDocumentEntity> replaceDocuments(Collection values);

    /**
     * Replaces multiple documents in the specified collection with the ones in the values, the replaced documents are
     * specified by the _key attributes in the documents in values.
     *
     * @param values  A List of documents (POJO or {@link com.arangodb.util.RawData})
     * @param options Additional options
     * @return information about the documents
     * @see
     * API
     * Documentation
     */
    MultiDocumentEntity> replaceDocuments(
            Collection values, DocumentReplaceOptions options);

    /**
     * Replaces multiple documents in the specified collection with the ones in the values, the replaced documents are
     * specified by the _key attributes in the documents in values.
     *
     * @param values  A List of documents (POJO or {@link com.arangodb.util.RawData})
     * @param options Additional options
     * @param type    Deserialization target type for the returned documents.
     * @return information about the documents
     * @see
     * API
     * Documentation
     */
     MultiDocumentEntity> replaceDocuments(
            Collection values, DocumentReplaceOptions options, Class type);

    /**
     * Partially updates the document identified by document-key. The value must contain a document with the attributes
     * to patch (the patch document). All attributes from the patch document will be added to the existing document if
     * they do not yet exist, and overwritten in the existing document if they do exist there.
     *
     * @param key   The key of the document
     * @param value A representation of a single document (POJO or {@link com.arangodb.util.RawData})
     * @return information about the document
     * @see API
     * Documentation
     */
    DocumentUpdateEntity updateDocument(String key, Object value);

    /**
     * Partially updates the document identified by document-key. The value must contain a document with the attributes
     * to patch (the patch document). All attributes from the patch document will be added to the existing document if
     * they do not yet exist, and overwritten in the existing document if they do exist there.
     *
     * @param key     The key of the document
     * @param value   A representation of a single document (POJO or {@link com.arangodb.util.RawData})
     * @param options Additional options
     * @return information about the document
     * @see API
     * Documentation
     */
     DocumentUpdateEntity updateDocument(String key, T value, DocumentUpdateOptions options);

    /**
     * Partially updates the document identified by document-key. The value must contain a document with the attributes
     * to patch (the patch document). All attributes from the patch document will be added to the existing document if
     * they do not yet exist, and overwritten in the existing document if they do exist there.
     *
     * @param key        The key of the document
     * @param value      A representation of a single document (POJO or {@link com.arangodb.util.RawData})
     * @param options    Additional options
     * @param returnType Type of the returned newDocument and/or oldDocument
     * @return information about the document
     * @see API
     * Documentation
     */
     DocumentUpdateEntity updateDocument(String key, Object value, DocumentUpdateOptions options,
                                               Class returnType);

    /**
     * Partially updates documents, the documents to update are specified by the _key attributes in the objects on
     * values. Vales must contain a list of document updates with the attributes to patch (the patch documents). All
     * attributes from the patch documents will be added to the existing documents if they do not yet exist, and
     * overwritten in the existing documents if they do exist there.
     *
     * @param values Raw data representing a collection of documents
     * @return information about the documents
     * @see
     * API
     * Documentation
     */
    MultiDocumentEntity> updateDocuments(RawData values);

    /**
     * Partially updates documents, the documents to update are specified by the _key attributes in the objects on
     * values. Vales must contain a list of document updates with the attributes to patch (the patch documents). All
     * attributes from the patch documents will be added to the existing documents if they do not yet exist, and
     * overwritten in the existing documents if they do exist there.
     *
     * @param values  Raw data representing a collection of documents
     * @param options Additional options
     * @return information about the documents
     * @see
     * API
     * Documentation
     */
    MultiDocumentEntity> updateDocuments(
            RawData values, DocumentUpdateOptions options);

    /**
     * Partially updates documents, the documents to update are specified by the _key attributes in the objects on
     * values. Vales must contain a list of document updates with the attributes to patch (the patch documents). All
     * attributes from the patch documents will be added to the existing documents if they do not yet exist, and
     * overwritten in the existing documents if they do exist there.
     *
     * @param values A list of documents (POJO or {@link com.arangodb.util.RawData})
     * @return information about the documents
     * @see
     * API
     * Documentation
     */
    MultiDocumentEntity> updateDocuments(Collection values);

    /**
     * Partially updates documents, the documents to update are specified by the _key attributes in the objects on
     * values. Vales must contain a list of document updates with the attributes to patch (the patch documents). All
     * attributes from the patch documents will be added to the existing documents if they do not yet exist, and
     * overwritten in the existing documents if they do exist there.
     *
     * @param values  A list of documents (POJO or {@link com.arangodb.util.RawData})
     * @param options Additional options
     * @return information about the documents
     * @see
     * API
     * Documentation
     */
    MultiDocumentEntity> updateDocuments(
            Collection values, DocumentUpdateOptions options);

    /**
     * Partially updates documents, the documents to update are specified by the _key attributes in the objects on
     * values. Vales must contain a list of document updates with the attributes to patch (the patch documents). All
     * attributes from the patch documents will be added to the existing documents if they do not yet exist, and
     * overwritten in the existing documents if they do exist there.
     *
     * @param values     A list of documents (POJO or {@link com.arangodb.util.RawData})
     * @param options    Additional options
     * @param returnType Type of the returned newDocument and/or oldDocument
     * @return information about the documents
     * @see
     * API
     * Documentation
     */
     MultiDocumentEntity> updateDocuments(
            Collection values, DocumentUpdateOptions options, Class returnType);

    /**
     * Deletes the document with the given {@code key} from the collection.
     *
     * @param key The key of the document
     * @return information about the document
     * @see
     * API
     * Documentation
     */
    DocumentDeleteEntity deleteDocument(String key);

    /**
     * Deletes the document with the given {@code key} from the collection.
     *
     * @param key     The key of the document
     * @param options Additional options
     * @return information about the document
     * @see
     * API
     * Documentation
     */
    DocumentDeleteEntity deleteDocument(String key, DocumentDeleteOptions options);

    /**
     * Deletes the document with the given {@code key} from the collection.
     *
     * @param key     The key of the document
     * @param type    Deserialization target type for the returned documents.
     * @param options Additional options
     * @return information about the document
     * @see
     * API
     * Documentation
     */
     DocumentDeleteEntity deleteDocument(String key, DocumentDeleteOptions options, Class type);

    /**
     * Deletes multiple documents from the collection.
     *
     * @param values Raw data representing the keys of the documents or the documents themselves
     * @return information about the documents
     * @see API
     * Documentation
     */
    MultiDocumentEntity> deleteDocuments(RawData values);

    /**
     * Deletes multiple documents from the collection.
     *
     * @param values  Raw data representing the keys of the documents or the documents themselves
     * @param options Additional options
     * @return information about the documents
     * @see API
     * Documentation
     */
    MultiDocumentEntity> deleteDocuments(
            RawData values, DocumentDeleteOptions options);

    /**
     * Deletes multiple documents from the collection.
     *
     * @param values The keys of the documents or the documents themselves
     * @return information about the documents
     * @see API
     * Documentation
     */
    MultiDocumentEntity> deleteDocuments(Collection values);

    /**
     * Deletes multiple documents from the collection.
     *
     * @param values  The keys of the documents or the documents themselves
     * @param options Additional options
     * @return information about the documents
     * @see API
     * Documentation
     */
    MultiDocumentEntity> deleteDocuments(
            Collection values, DocumentDeleteOptions options);

    /**
     * Deletes multiple documents from the collection.
     *
     * @param values  The keys of the documents or the documents themselves
     * @param type    Deserialization target type for the returned documents.
     * @param options Additional options
     * @return information about the documents
     * @see API
     * Documentation
     */
     MultiDocumentEntity> deleteDocuments(
            Collection values, DocumentDeleteOptions options, Class type);

    /**
     * Checks if the document exists by reading a single document head
     *
     * @param key The key of the document
     * @return true if the document was found, otherwise false
     * @see API
     * Documentation
     */
    Boolean documentExists(String key);

    /**
     * Checks if the document exists by reading a single document head
     *
     * @param key     The key of the document
     * @param options Additional options, can be null
     * @return true if the document was found, otherwise false
     * @see API
     * Documentation
     */
    Boolean documentExists(String key, DocumentExistsOptions options);

    /**
     * Fetches information about the index with the given {@code id} and returns it.
     * 
* Note: inverted indexes are not returned by this method. Use * {@link ArangoCollection#getInvertedIndex(String)} instead. * * @param id The index-handle * @return information about the index * @see * API Documentation */ IndexEntity getIndex(String id); /** * Fetches information about the inverted index with the given {@code id} and returns it. * * @param id The index-handle * @return information about the index * @see API Documentation * @since ArangoDB 3.10 */ InvertedIndexEntity getInvertedIndex(String id); /** * Deletes the index with the given {@code id} from the collection. * * @param id The index-handle * @return the id of the index * @see * API Documentation */ String deleteIndex(String id); /** * Creates a persistent index for the collection, if it does not already exist. * * @param fields A list of attribute paths * @param options Additional options, can be null * @return information about the index * @see API * Documentation */ IndexEntity ensurePersistentIndex(Iterable fields, PersistentIndexOptions options); /** * Creates a geo-spatial index for the collection, if it does not already exist. * * @param fields A list of attribute paths * @param options Additional options, can be null * @return information about the index * @see API * Documentation */ IndexEntity ensureGeoIndex(Iterable fields, GeoIndexOptions options); /** * Creates a fulltext index for the collection, if it does not already exist. * * @param fields A list of attribute paths * @param options Additional options, can be null * @return information about the index * @see API * Documentation * @deprecated since ArangoDB 3.10, use ArangoSearch or Inverted indexes instead. */ @Deprecated IndexEntity ensureFulltextIndex(Iterable fields, FulltextIndexOptions options); /** * Creates a ttl index for the collection, if it does not already exist. * * @param fields A list of attribute paths * @param options Additional options, can be null * @return information about the index * @see API * Documentation */ IndexEntity ensureTtlIndex(Iterable fields, TtlIndexOptions options); /** * Creates a ZKD multi-dimensional index for the collection, if it does not already exist. * Note that zkd indexes are an experimental feature in ArangoDB 3.9. * * @param fields A list of attribute paths * @param options Additional options, can be null * @return information about the index * @see API Documentation * @since ArangoDB 3.9 */ IndexEntity ensureZKDIndex(Iterable fields, ZKDIndexOptions options); /** * Creates an inverted index for the collection, if it does not already exist. * * @param options index creation options * @return information about the index * @see API Documentation * @since ArangoDB 3.10 */ InvertedIndexEntity ensureInvertedIndex(InvertedIndexOptions options); /** * Fetches a list of all indexes on this collection. *
* Note: inverted indexes are not returned by this method. Use * {@link ArangoCollection#getInvertedIndexes()} instead. * * @return information about the indexes * @see API * Documentation */ Collection getIndexes(); /** * Fetches a list of all inverted indexes on this collection. * * @return information about the indexes * @see API * Documentation * @since ArangoDB 3.10 */ Collection getInvertedIndexes(); /** * Checks whether the collection exists * * @return true if the collection exists, otherwise false */ boolean exists(); /** * Removes all documents from the collection, but leaves the indexes intact * * @return information about the collection * @see API * Documentation */ CollectionEntity truncate(); /** * Removes all documents from the collection, but leaves the indexes intact * * @param options * @return information about the collection * @see API * Documentation * @since ArangoDB 3.5.0 */ CollectionEntity truncate(CollectionTruncateOptions options); /** * Counts the documents in a collection * * @return information about the collection, including the number of documents * @see API * Documentation */ CollectionPropertiesEntity count(); /** * Counts the documents in a collection * * @param options * @return information about the collection, including the number of documents * @see API * Documentation * @since ArangoDB 3.5.0 */ CollectionPropertiesEntity count(CollectionCountOptions options); /** * Creates a collection for this collection's name, then returns collection information from the server. * * @return information about the collection * @see API * Documentation */ CollectionEntity create(); /** * Creates a collection with the given {@code options} for this collection's name, then returns collection * information from the server. * * @param options Additional options, can be null * @return information about the collection * @see API * Documentation */ CollectionEntity create(CollectionCreateOptions options); /** * Deletes the collection from the database. * * @see API * Documentation */ void drop(); /** * Deletes the collection from the database. * * @param isSystem Whether or not the collection to drop is a system collection. This parameter must be set to * true in * order to drop a system collection. * @see API * Documentation * @since ArangoDB 3.1.0 */ void drop(boolean isSystem); /** * Returns information about the collection * * @return information about the collection * @see API * Documentation */ CollectionEntity getInfo(); /** * Reads the properties of the specified collection * * @return properties of the collection * @see API * Documentation */ CollectionPropertiesEntity getProperties(); /** * Changes the properties of the collection * * @param options Additional options, can be null * @return properties of the collection * @see API * Documentation */ CollectionPropertiesEntity changeProperties(CollectionPropertiesOptions options); /** * Renames the collection * * @param newName The new name * @return information about the collection * @see API * Documentation */ CollectionEntity rename(String newName); /** * Returns the responsible shard for the document. * Please note that this API is only meaningful and available on a cluster coordinator. * * @param value A projection of the document containing at least the shard key (_key or a custom attribute) for * which the responsible shard should be determined * @return information about the responsible shard * @see * * API Documentation * @since ArangoDB 3.5.0 */ ShardEntity getResponsibleShard(final Object value); /** * Retrieve the collections revision * * @return information about the collection, including the collections revision * @see * API * Documentation */ CollectionRevisionEntity getRevision(); /** * Grants or revoke access to the collection for user user. You need permission to the _system database in order to * execute this call. * * @param user The name of the user * @param permissions The permissions the user grant * @see API * Documentation */ void grantAccess(String user, Permissions permissions); /** * Revokes access to the collection for user user. You need permission to the _system database in order to execute * this call. * * @param user The name of the user * @see API * Documentation */ void revokeAccess(String user); /** * Clear the collection access level, revert back to the default access level. * * @param user The name of the user * @see API * Documentation * @since ArangoDB 3.2.0 */ void resetAccess(String user); /** * Get the collection access level * * @param user The name of the user * @return permissions of the user * @see * * API Documentation * @since ArangoDB 3.2.0 */ Permissions getPermissions(String user); }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy