com.arangodb.internal.InternalArangoCollection 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.internal;
import com.arangodb.ArangoDBException;
import com.arangodb.DbName;
import com.arangodb.entity.*;
import com.arangodb.internal.ArangoExecutor.ResponseDeserializer;
import com.arangodb.internal.util.DocumentUtil;
import com.arangodb.internal.util.RequestUtils;
import com.arangodb.model.*;
import com.arangodb.util.RawData;
import com.arangodb.shaded.fasterxml.jackson.databind.JsonNode;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Collection;
import static com.arangodb.internal.serde.SerdeUtils.constructParametricType;
/**
* @author Mark Vollmary
* @author Michele Rastelli
*/
public abstract class InternalArangoCollection, D extends InternalArangoDatabase,
E extends ArangoExecutor>
extends ArangoExecuteable {
protected static final String PATH_API_COLLECTION = "/_api/collection";
private static final String COLLECTION = "collection";
private static final String PATH_API_DOCUMENT = "/_api/document";
private static final String PATH_API_INDEX = "/_api/index";
private static final String PATH_API_IMPORT = "/_api/import";
private static final String PATH_API_USER = "/_api/user";
private static final String MERGE_OBJECTS = "mergeObjects";
private static final String KEEP_NULL = "keepNull";
private static final String IGNORE_REVS = "ignoreRevs";
private static final String RETURN_NEW = "returnNew";
private static final String RETURN_OLD = "returnOld";
private static final String OVERWRITE = "overwrite";
private static final String OVERWRITE_MODE = "overwriteMode";
private static final String SILENT = "silent";
private static final String TRANSACTION_ID = "x-arango-trx-id";
private final D db;
protected volatile String name;
protected InternalArangoCollection(final D db, final String name) {
super(db.executor, db.serde);
this.db = db;
this.name = name;
}
public D db() {
return db;
}
public String name() {
return name;
}
protected InternalRequest insertDocumentRequest(final T value, final DocumentCreateOptions options) {
final InternalRequest request = createInsertDocumentRequest(options);
request.setBody(getSerde().serializeUserData(value));
return request;
}
protected InternalRequest insertDocumentsRequest(final RawData values, final DocumentCreateOptions options) {
InternalRequest request = createInsertDocumentRequest(options);
request.setBody(getSerde().serialize(values));
return request;
}
protected InternalRequest insertDocumentsRequest(final Collection values, final DocumentCreateOptions options) {
InternalRequest request = createInsertDocumentRequest(options);
request.setBody(getSerde().serializeCollectionUserData(values));
return request;
}
private InternalRequest createInsertDocumentRequest(final DocumentCreateOptions options) {
final DocumentCreateOptions params = (options != null ? options : new DocumentCreateOptions());
final InternalRequest request = request(db.dbName(), RequestType.POST, PATH_API_DOCUMENT, name);
request.putQueryParam(ArangoRequestParam.WAIT_FOR_SYNC, params.getWaitForSync());
request.putQueryParam(RETURN_NEW, params.getReturnNew());
request.putQueryParam(RETURN_OLD, params.getReturnOld());
request.putQueryParam(SILENT, params.getSilent());
request.putQueryParam(OVERWRITE_MODE, params.getOverwriteMode() != null ?
params.getOverwriteMode().getValue() : null);
request.putQueryParam(MERGE_OBJECTS, params.getMergeObjects());
request.putQueryParam(KEEP_NULL, params.getKeepNull());
request.putHeaderParam(TRANSACTION_ID, params.getStreamTransactionId());
return request;
}
protected ResponseDeserializer>> insertDocumentsResponseDeserializer(Class userDataClass) {
return response -> {
final MultiDocumentEntity> multiDocument = new MultiDocumentEntity<>();
final Collection> docs = new ArrayList<>();
final Collection errors = new ArrayList<>();
final Collection
© 2015 - 2025 Weber Informatics LLC | Privacy Policy