com.arangodb.async.internal.ArangoCollectionAsyncImpl Maven / Gradle / Ivy
/*
* 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.async.internal;
import com.arangodb.async.ArangoCollectionAsync;
import com.arangodb.entity.*;
import com.arangodb.internal.InternalArangoCollection;
import com.arangodb.internal.util.DocumentUtil;
import com.arangodb.model.*;
import com.arangodb.util.RawData;
import java.util.Collection;
import java.util.Objects;
import java.util.concurrent.CompletableFuture;
import static com.arangodb.internal.serde.SerdeUtils.constructParametricType;
/**
* @author Mark Vollmary
* @author Michele Rastelli
*/
public class ArangoCollectionAsyncImpl
extends InternalArangoCollection
implements ArangoCollectionAsync {
ArangoCollectionAsyncImpl(final ArangoDatabaseAsyncImpl db, final String name) {
super(db, name);
}
@Override
public CompletableFuture> insertDocument(final Object value) {
return executor.execute(insertDocumentRequest(value, new DocumentCreateOptions()),
constructParametricType(DocumentCreateEntity.class, Void.class));
}
@Override
@SuppressWarnings("unchecked")
public CompletableFuture> insertDocument(
final T value,
final DocumentCreateOptions options) {
return insertDocument(value, options, (Class) value.getClass());
}
@Override
public CompletableFuture> insertDocument(T value, DocumentCreateOptions options,
Class type) {
return executor.execute(insertDocumentRequest(value, options),
constructParametricType(DocumentCreateEntity.class, type));
}
@Override
public CompletableFuture>> insertDocuments(RawData values) {
return executor
.execute(insertDocumentsRequest(values, new DocumentCreateOptions()),
insertDocumentsResponseDeserializer(Void.class));
}
@Override
@SuppressWarnings("unchecked")
public CompletableFuture>> insertDocuments(RawData values,
DocumentCreateOptions options) {
return executor
.execute(insertDocumentsRequest(values, options),
insertDocumentsResponseDeserializer((Class) values.getClass()));
}
@Override
public CompletableFuture>> insertDocuments(
final Collection> values) {
return executor
.execute(insertDocumentsRequest(values, new DocumentCreateOptions()),
insertDocumentsResponseDeserializer(Void.class));
}
@Override
@SuppressWarnings("unchecked")
public CompletableFuture>> insertDocuments(
final Collection values,
final DocumentCreateOptions options) {
return insertDocuments(values, options, (Class) getCollectionContentClass(values));
}
@Override
public CompletableFuture>> insertDocuments(Collection values,
DocumentCreateOptions options, Class type) {
return executor
.execute(insertDocumentsRequest(values, options), insertDocumentsResponseDeserializer(type));
}
@Override
public CompletableFuture importDocuments(final Collection> values) {
return importDocuments(values, new DocumentImportOptions());
}
@Override
public CompletableFuture importDocuments(
final Collection> values,
final DocumentImportOptions options) {
return executor.execute(importDocumentsRequest(values, options), DocumentImportEntity.class);
}
@Override
public CompletableFuture importDocuments(RawData values) {
return executor.execute(importDocumentsRequest(values, new DocumentImportOptions()),
DocumentImportEntity.class);
}
@Override
public CompletableFuture importDocuments(RawData values, DocumentImportOptions options) {
return executor.execute(importDocumentsRequest(values, options), DocumentImportEntity.class);
}
@Override
public CompletableFuture getDocument(final String key, final Class type) {
return getDocument(key, type, new DocumentReadOptions());
}
@Override
public CompletableFuture getDocument(
final String key,
final Class type,
final DocumentReadOptions options) {
DocumentUtil.validateDocumentKey(key);
return executor.execute(getDocumentRequest(key, options), getDocumentResponseDeserializer(type))
.exceptionally(ExceptionUtil.catchGetDocumentExceptions());
}
@Override
public CompletableFuture> getDocuments(
final Collection keys,
final Class type) {
return getDocuments(keys, type, new DocumentReadOptions());
}
@Override
public CompletableFuture> getDocuments(
final Collection keys,
final Class type,
final DocumentReadOptions options) {
return executor.execute(getDocumentsRequest(keys, options), getDocumentsResponseDeserializer(type));
}
@Override
public CompletableFuture> replaceDocument(final String key, final Object value) {
final DocumentReplaceOptions options = new DocumentReplaceOptions();
return executor.execute(replaceDocumentRequest(key, value, options),
constructParametricType(DocumentUpdateEntity.class, Void.class));
}
@Override
@SuppressWarnings("unchecked")
public CompletableFuture> replaceDocument(
final String key,
final T value,
final DocumentReplaceOptions options) {
return replaceDocument(key, value, options, (Class) value.getClass());
}
@Override
public CompletableFuture> replaceDocument(String key, T value,
DocumentReplaceOptions options,
Class type) {
return executor.execute(replaceDocumentRequest(key, value, options),
constructParametricType(DocumentUpdateEntity.class, type));
}
@Override
public CompletableFuture>> replaceDocuments(RawData values) {
return executor.execute(replaceDocumentsRequest(values, new DocumentReplaceOptions()),
replaceDocumentsResponseDeserializer(Void.class));
}
@Override
@SuppressWarnings("unchecked")
public CompletableFuture>> replaceDocuments(RawData values,
DocumentReplaceOptions options) {
return executor.execute(replaceDocumentsRequest(values, options),
replaceDocumentsResponseDeserializer((Class) values.getClass()));
}
@Override
public CompletableFuture>> replaceDocuments(
final Collection> values) {
return executor.execute(replaceDocumentsRequest(values, new DocumentReplaceOptions()),
replaceDocumentsResponseDeserializer(Void.class));
}
@Override
@SuppressWarnings("unchecked")
public CompletableFuture>> replaceDocuments(
final Collection values,
final DocumentReplaceOptions options) {
return replaceDocuments(values, options, (Class) getCollectionContentClass(values));
}
@Override
public CompletableFuture>> replaceDocuments(Collection values,
DocumentReplaceOptions options, Class type) {
return executor.execute(replaceDocumentsRequest(values, options), replaceDocumentsResponseDeserializer(type));
}
@Override
public CompletableFuture> updateDocument(final String key, final Object value) {
return updateDocument(key, value, new DocumentUpdateOptions(), Void.class);
}
@Override
@SuppressWarnings("unchecked")
public CompletableFuture> updateDocument(
final String key,
final T value,
final DocumentUpdateOptions options) {
return updateDocument(key, value, options, (Class) value.getClass());
}
@Override
public CompletableFuture> updateDocument(
final String key,
final Object value,
final DocumentUpdateOptions options,
final Class returnType) {
return executor.execute(updateDocumentRequest(key, value, options),
constructParametricType(DocumentUpdateEntity.class, returnType));
}
@Override
public CompletableFuture>> updateDocuments(RawData values) {
return executor
.execute(updateDocumentsRequest(values, new DocumentUpdateOptions()),
updateDocumentsResponseDeserializer(Void.class));
}
@Override
@SuppressWarnings("unchecked")
public CompletableFuture>> updateDocuments(RawData values,
DocumentUpdateOptions options) {
return executor
.execute(updateDocumentsRequest(values, options),
updateDocumentsResponseDeserializer((Class) values.getClass()));
}
@Override
public CompletableFuture>> updateDocuments(
final Collection> values) {
return updateDocuments(values, new DocumentUpdateOptions(), Void.class);
}
@Override
@SuppressWarnings("unchecked")
public CompletableFuture>> updateDocuments(
final Collection values,
final DocumentUpdateOptions options) {
return updateDocuments(values, options, (Class) getCollectionContentClass(values));
}
@Override
public CompletableFuture>> updateDocuments(
final Collection> values,
final DocumentUpdateOptions options,
final Class returnType) {
return executor
.execute(updateDocumentsRequest(values, options), updateDocumentsResponseDeserializer(returnType));
}
@Override
public CompletableFuture> deleteDocument(final String key) {
return deleteDocument(key, new DocumentDeleteOptions());
}
@Override
public CompletableFuture> deleteDocument(String key, DocumentDeleteOptions options) {
return deleteDocument(key, options, Void.class);
}
@Override
public CompletableFuture> deleteDocument(
final String key,
final DocumentDeleteOptions options,
final Class type) {
return executor.execute(deleteDocumentRequest(key, options),
constructParametricType(DocumentDeleteEntity.class, type));
}
@Override
public CompletableFuture>> deleteDocuments(RawData values) {
return executor.execute(deleteDocumentsRequest(values, new DocumentDeleteOptions()),
deleteDocumentsResponseDeserializer(Void.class));
}
@Override
@SuppressWarnings("unchecked")
public CompletableFuture>> deleteDocuments(RawData values,
DocumentDeleteOptions options) {
return executor.execute(deleteDocumentsRequest(values, options),
deleteDocumentsResponseDeserializer((Class) values.getClass()));
}
@Override
public CompletableFuture>> deleteDocuments(
final Collection> values) {
return deleteDocuments(values, new DocumentDeleteOptions(), Void.class);
}
@Override
@SuppressWarnings("unchecked")
public CompletableFuture>> deleteDocuments(Collection> values,
DocumentDeleteOptions options) {
return deleteDocuments(values, options, (Class) getCollectionContentClass(values));
}
@Override
public CompletableFuture>> deleteDocuments(
final Collection> values,
final DocumentDeleteOptions options,
final Class type) {
return executor.execute(deleteDocumentsRequest(values, options), deleteDocumentsResponseDeserializer(type));
}
@Override
public CompletableFuture documentExists(final String key) {
return documentExists(key, new DocumentExistsOptions());
}
@Override
public CompletableFuture documentExists(final String key, final DocumentExistsOptions options) {
return executor.execute(documentExistsRequest(key, options), response -> response)
.exceptionally(ExceptionUtil.catchGetDocumentExceptions())
.thenApply(Objects::nonNull);
}
@Override
public CompletableFuture getIndex(final String id) {
return executor.execute(getIndexRequest(id), IndexEntity.class);
}
@Override
public CompletableFuture getInvertedIndex(String id) {
return executor.execute(getIndexRequest(id), InvertedIndexEntity.class);
}
@Override
public CompletableFuture deleteIndex(final String id) {
return executor.execute(deleteIndexRequest(id), deleteIndexResponseDeserializer());
}
@Override
@Deprecated
public CompletableFuture ensureHashIndex(
final Iterable fields,
final HashIndexOptions options) {
return executor.execute(createHashIndexRequest(fields, options), IndexEntity.class);
}
@Override
@Deprecated
public CompletableFuture ensureSkiplistIndex(
final Iterable fields,
final SkiplistIndexOptions options) {
return executor.execute(createSkiplistIndexRequest(fields, options), IndexEntity.class);
}
@Override
public CompletableFuture ensurePersistentIndex(
final Iterable fields,
final PersistentIndexOptions options) {
return executor.execute(createPersistentIndexRequest(fields, options), IndexEntity.class);
}
@Override
public CompletableFuture ensureGeoIndex(final Iterable fields, final GeoIndexOptions options) {
return executor.execute(createGeoIndexRequest(fields, options), IndexEntity.class);
}
@Deprecated
@Override
public CompletableFuture ensureFulltextIndex(
final Iterable fields,
final FulltextIndexOptions options) {
return executor.execute(createFulltextIndexRequest(fields, options), IndexEntity.class);
}
@Override
public CompletableFuture ensureTtlIndex(Iterable fields, TtlIndexOptions options) {
return executor.execute(createTtlIndexRequest(fields, options), IndexEntity.class);
}
@Override
public CompletableFuture ensureZKDIndex(
final Iterable fields,
final ZKDIndexOptions options) {
return executor.execute(createZKDIndexRequest(fields, options), IndexEntity.class);
}
@Override
public CompletableFuture ensureInvertedIndex(InvertedIndexOptions options) {
return executor.execute(createInvertedIndexRequest(options), InvertedIndexEntity.class);
}
@Override
public CompletableFuture> getIndexes() {
return executor.execute(getIndexesRequest(), getIndexesResponseDeserializer());
}
@Override
public CompletableFuture> getInvertedIndexes() {
return executor.execute(getIndexesRequest(), getInvertedIndexesResponseDeserializer());
}
@Override
public CompletableFuture exists() {
return getInfo().thenApply(Objects::nonNull).exceptionally(Objects::isNull);
}
@Override
public CompletableFuture truncate() {
return truncate(null);
}
@Override
public CompletableFuture truncate(CollectionTruncateOptions options) {
return executor.execute(truncateRequest(options), CollectionEntity.class);
}
@Override
public CompletableFuture count() {
return count(null);
}
@Override
public CompletableFuture count(CollectionCountOptions options) {
return executor.execute(countRequest(options), CollectionPropertiesEntity.class);
}
@Override
public CompletableFuture create() {
return db().createCollection(name());
}
@Override
public CompletableFuture create(final CollectionCreateOptions options) {
return db().createCollection(name(), options);
}
@Override
public CompletableFuture drop() {
return executor.execute(dropRequest(null), Void.class);
}
@Override
public CompletableFuture drop(final boolean isSystem) {
return executor.execute(dropRequest(isSystem), Void.class);
}
@Override
public CompletableFuture getInfo() {
return executor.execute(getInfoRequest(), CollectionEntity.class);
}
@Override
public CompletableFuture getProperties() {
return executor.execute(getPropertiesRequest(), CollectionPropertiesEntity.class);
}
@Override
public CompletableFuture changeProperties(final CollectionPropertiesOptions options) {
return executor.execute(changePropertiesRequest(options), CollectionPropertiesEntity.class);
}
@Override
public CompletableFuture rename(final String newName) {
return executor.execute(renameRequest(newName), CollectionEntity.class);
}
@Override
public CompletableFuture getResponsibleShard(Object value) {
return executor.execute(responsibleShardRequest(value), ShardEntity.class);
}
@Override
public CompletableFuture getRevision() {
return executor.execute(getRevisionRequest(), CollectionRevisionEntity.class);
}
@Override
public CompletableFuture grantAccess(final String user, final Permissions permissions) {
return executor.execute(grantAccessRequest(user, permissions), Void.class);
}
@Override
public CompletableFuture revokeAccess(final String user) {
return executor.execute(grantAccessRequest(user, Permissions.NONE), Void.class);
}
@Override
public CompletableFuture resetAccess(final String user) {
return executor.execute(resetAccessRequest(user), Void.class);
}
@Override
public CompletableFuture getPermissions(final String user) {
return executor.execute(getPermissionsRequest(user), getPermissionsResponseDeserialzer());
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy