com.arangodb.impl.InternalSimpleDriverImpl Maven / Gradle / Ivy
/*
* Copyright (C) 2012 tamtam180
*
* 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.
*/
package com.arangodb.impl;
import java.util.Map;
import com.arangodb.ArangoConfigure;
import com.arangodb.ArangoException;
import com.arangodb.CursorResultSet;
import com.arangodb.InternalCursorDriver;
import com.arangodb.entity.CursorEntity;
import com.arangodb.entity.DocumentEntity;
import com.arangodb.entity.DocumentResultEntity;
import com.arangodb.entity.EntityFactory;
import com.arangodb.entity.ScalarExampleEntity;
import com.arangodb.entity.SimpleByResultEntity;
import com.arangodb.http.HttpManager;
import com.arangodb.http.HttpResponseEntity;
import com.arangodb.util.MapBuilder;
/**
* @author tamtam180 - kirscheless at gmail.com
*
*/
public class InternalSimpleDriverImpl extends BaseArangoDriverWithCursorImpl implements com.arangodb.InternalSimpleDriver {
InternalSimpleDriverImpl(ArangoConfigure configure,
InternalCursorDriver cursorDriver, HttpManager httpManager) {
super(configure , cursorDriver, httpManager);
}
// ----- all --------------------
private CursorEntity _executeSimpleAll(
String database,
String collectionName, int skip, int limit,
Class>... clazz) throws ArangoException {
validateCollectionName(collectionName);
HttpResponseEntity res = httpManager.doPut(
createEndpointUrl(baseUrl, database, "/_api/simple/all"),
null,
EntityFactory.toJsonString(
new MapBuilder()
.put("collection", collectionName)
.put("skip", skip > 0 ? skip : null)
.put("limit", limit > 0 ? limit : null)
.get())
);
return createEntity(res, CursorEntity.class, clazz);
}
@Override
public CursorEntity executeSimpleAll(
String database,
String collectionName, int skip, int limit,
Class> clazz) throws ArangoException {
CursorEntity entity = _executeSimpleAll(database, collectionName, skip, limit, clazz);
return entity;
//return EntityFactory.createResult(entity, clazz);
}
@Override
public CursorResultSet executeSimpleAllWithResultSet(
String database,
String collectionName, int skip, int limit,
Class> clazz) throws ArangoException {
CursorEntity entity = executeSimpleAll(database, collectionName, skip, limit, clazz);
CursorResultSet rs = new CursorResultSet(database, cursorDriver, entity, clazz);
return rs;
}
@Override
public CursorEntity> executeSimpleAllWithDocument(
String database,
String collectionName, int skip, int limit,
Class> clazz) throws ArangoException {
CursorEntity> entity = _executeSimpleAll(database, collectionName, skip, limit, DocumentEntity.class, clazz);
//return EntityFactory.createDocumentResult(entity, clazz);
return entity;
}
@Override
public CursorResultSet> executeSimpleAllWithDocumentResultSet(
String database,
String collectionName, int skip, int limit,
Class> clazz) throws ArangoException {
CursorEntity> entity = executeSimpleAllWithDocument(database, collectionName, skip, limit, clazz);
CursorResultSet> rs = new CursorResultSet>(database, cursorDriver, entity, DocumentEntity.class, clazz);
return rs;
}
// ----- example --------------------
private CursorEntity _executeSimpleByExample(
String database,
String collectionName,
Map example,
int skip, int limit,
Class>... clazz
) throws ArangoException {
validateCollectionName(collectionName);
HttpResponseEntity res = httpManager.doPut(
createEndpointUrl(baseUrl, database, "/_api/simple/by-example"),
null,
EntityFactory.toJsonString(
new MapBuilder()
.put("collection", collectionName)
.put("example", example)
.put("skip", skip > 0 ? skip : null)
.put("limit", limit > 0 ? limit : null)
.get())
);
return createEntity(res, CursorEntity.class, clazz);
}
@Override
public CursorEntity executeSimpleByExample(
String database,
String collectionName,
Map example,
int skip, int limit,
Class> clazz
) throws ArangoException {
CursorEntity entity = _executeSimpleByExample(database, collectionName, example, skip, limit, clazz);
return entity;
}
@Override
public CursorResultSet executeSimpleByExampleWithResultSet(
String database,
String collectionName, Map example,
int skip, int limit,
Class> clazz
) throws ArangoException {
CursorEntity entity = executeSimpleByExample(database, collectionName, example, skip, limit, clazz);
CursorResultSet rs = new CursorResultSet(database, cursorDriver, entity, clazz);
return rs;
}
@Override
public CursorEntity> executeSimpleByExampleWithDocument(
String database,
String collectionName,
Map example,
int skip, int limit,
Class> clazz
) throws ArangoException {
CursorEntity> entity = _executeSimpleByExample(database, collectionName, example, skip, limit, DocumentEntity.class, clazz);
return entity;
//return EntityFactory.createDocumentResult(entity, clazz);
}
@Override
public CursorResultSet> executeSimpleByExampleWithDocumentResultSet(
String database,
String collectionName, Map example,
int skip, int limit,
Class> clazz
) throws ArangoException {
CursorEntity> entity = executeSimpleByExampleWithDocument(database, collectionName, example, skip, limit, clazz);
CursorResultSet> rs = new CursorResultSet>(database, cursorDriver, entity, DocumentEntity.class, clazz);
return rs;
}
// ----- first --------------------
@Override
public ScalarExampleEntity executeSimpleFirstExample(
String database,
String collectionName,
Map example,
Class> clazz
) throws ArangoException {
validateCollectionName(collectionName);
HttpResponseEntity res = httpManager.doPut(
createEndpointUrl(baseUrl, database, "/_api/simple/first-example"),
null,
EntityFactory.toJsonString(
new MapBuilder()
.put("collection", collectionName)
.put("example", example)
.get())
);
ScalarExampleEntity entity = createEntity(res, ScalarExampleEntity.class, clazz);
return entity;
//return EntityFactory.createScalarExampleEntity(entity, clazz);
}
// ----- any --------------------
@Override
public ScalarExampleEntity executeSimpleAny(
String database,
String collectionName,
Class> clazz
) throws ArangoException {
validateCollectionName(collectionName);
HttpResponseEntity res = httpManager.doPut(
createEndpointUrl(baseUrl, database, "/_api/simple/any"),
null,
EntityFactory.toJsonString(
new MapBuilder()
.put("collection", collectionName)
.get())
);
ScalarExampleEntity entity = createEntity(res, ScalarExampleEntity.class, clazz);
return entity;
//return EntityFactory.createScalarExampleEntity(entity, clazz);
}
// ----- range --------------------
private CursorEntity _executeSimpleRange(
String database,
String collectionName,
String attribute,
Object left, Object right, Boolean closed,
int skip, int limit,
Class>... clazz
) throws ArangoException {
validateCollectionName(collectionName);
HttpResponseEntity res = httpManager.doPut(
createEndpointUrl(baseUrl, database, "/_api/simple/range"),
null,
EntityFactory.toJsonString(
new MapBuilder()
.put("collection", collectionName)
.put("attribute", attribute)
.put("left", left)
.put("right", right)
.put("closed", closed)
.put("skip", skip > 0 ? skip : null)
.put("limit", limit > 0 ? limit : null)
.get())
);
return createEntity(res, CursorEntity.class, clazz);
}
@Override
public CursorEntity executeSimpleRange(
String database,
String collectionName,
String attribute,
Object left, Object right, Boolean closed,
int skip, int limit,
Class> clazz
) throws ArangoException {
CursorEntity entity = _executeSimpleRange(database, collectionName, attribute, left, right, closed, skip, limit, clazz);
//return EntityFactory.createResult(entity, clazz);
return entity;
}
@Override
public CursorResultSet executeSimpleRangeWithResultSet(
String database,
String collectionName,
String attribute,
Object left, Object right, Boolean closed,
int skip, int limit,
Class> clazz
) throws ArangoException {
CursorEntity entity = executeSimpleRange(database, collectionName, attribute, left, right, closed, skip, limit, clazz);
CursorResultSet rs = new CursorResultSet(database, cursorDriver, entity, clazz);
return rs;
}
@Override
public CursorEntity> executeSimpleRangeWithDocument(
String database,
String collectionName,
String attribute,
Object left, Object right, Boolean closed,
int skip, int limit,
Class> clazz
) throws ArangoException {
CursorEntity> entity = _executeSimpleRange(database, collectionName, attribute, left, right, closed, skip, limit, DocumentEntity.class, clazz);
return entity;
}
@Override
public CursorResultSet> executeSimpleRangeWithDocumentResultSet(
String database,
String collectionName,
String attribute,
Object left, Object right, Boolean closed,
int skip, int limit,
Class> clazz
) throws ArangoException {
CursorEntity> entity = executeSimpleRangeWithDocument(database, collectionName, attribute, left, right, closed, skip, limit, clazz);
CursorResultSet> rs = new CursorResultSet>(database, cursorDriver, entity, DocumentEntity.class, clazz);
return rs;
}
// ----- remove-by-example --------------------
@Override
public SimpleByResultEntity executeSimpleRemoveByExample(
String database,
String collectionName,
Map example,
Boolean waitForSync,
Integer limit) throws ArangoException {
validateCollectionName(collectionName);
HttpResponseEntity res = httpManager.doPut(
createEndpointUrl(baseUrl, database, "/_api/simple/remove-by-example"),
null,
EntityFactory.toJsonString(
new MapBuilder()
.put("collection", collectionName)
.put("example", example)
.put("waitForSync", waitForSync)
.put("limit", limit != null && limit.intValue() > 0 ? limit : null)
.get())
);
SimpleByResultEntity entity = createEntity(res, SimpleByResultEntity.class);
return entity;
}
// ----- replace-by-example --------------------
@Override
public SimpleByResultEntity executeSimpleReplaceByExample(
String database,
String collectionName,
Map example,
Map newValue,
Boolean waitForSync,
Integer limit) throws ArangoException {
validateCollectionName(collectionName);
HttpResponseEntity res = httpManager.doPut(
createEndpointUrl(baseUrl, database, "/_api/simple/replace-by-example"),
null,
EntityFactory.toJsonString(
new MapBuilder()
.put("collection", collectionName)
.put("example", example)
.put("newValue", newValue)
.put("waitForSync", waitForSync)
.put("limit", limit != null && limit.intValue() > 0 ? limit : null)
.get())
);
SimpleByResultEntity entity = createEntity(res, SimpleByResultEntity.class);
return entity;
}
// ----- update-by-example --------------------
@Override
public SimpleByResultEntity executeSimpleUpdateByExample(
String database,
String collectionName,
Map example,
Map newValue,
Boolean keepNull,
Boolean waitForSync,
Integer limit) throws ArangoException {
validateCollectionName(collectionName);
HttpResponseEntity res = httpManager.doPut(
createEndpointUrl(baseUrl, database, "/_api/simple/update-by-example"),
null,
EntityFactory.toJsonString(
new MapBuilder()
.put("collection", collectionName)
.put("example", example)
.put("newValue", newValue)
.put("keepNull", keepNull)
.put("waitForSync", waitForSync)
.put("limit", limit != null && limit.intValue() > 0 ? limit : null)
.get(),
keepNull != null && !keepNull
)
);
SimpleByResultEntity entity = createEntity(res, SimpleByResultEntity.class);
return entity;
}
// ----- Fulltext --------------------
private CursorEntity _executeSimpleFulltext(
String database,
String collectionName,
String attribute, String query,
int skip, int limit,
String index,
Class>... clazz
) throws ArangoException {
validateCollectionName(collectionName);
HttpResponseEntity res = httpManager.doPut(
createEndpointUrl(baseUrl, database, "/_api/simple/fulltext"),
null,
EntityFactory.toJsonString(
new MapBuilder()
.put("collection", collectionName)
.put("attribute", attribute)
.put("query", query)
.put("skip", skip > 0 ? skip : null)
.put("limit", limit > 0 ? limit : null)
.put("index", index)
.get())
);
return createEntity(res, CursorEntity.class, clazz);
}
@Override
public CursorEntity executeSimpleFulltext(
String database,
String collectionName,
String attribute, String query,
int skip, int limit,
String index,
Class> clazz
) throws ArangoException {
CursorEntity entity = _executeSimpleFulltext(database, collectionName, attribute, query, skip, limit, index, clazz);
//return EntityFactory.createResult(entity, clazz);
return entity;
}
@Override
public CursorResultSet executeSimpleFulltextWithResultSet(
String database,
String collectionName,
String attribute, String query,
int skip, int limit,
String index,
Class> clazz
) throws ArangoException {
CursorEntity entity = executeSimpleFulltext(database, collectionName, attribute, query, skip, limit, index, clazz);
CursorResultSet rs = new CursorResultSet(database, cursorDriver, entity, clazz);
return rs;
}
@Override
public CursorEntity> executeSimpleFulltextWithDocument(
String database,
String collectionName,
String attribute, String query,
int skip, int limit,
String index,
Class> clazz
) throws ArangoException {
CursorEntity> entity = _executeSimpleFulltext(database, collectionName, attribute, query, skip, limit, index, DocumentEntity.class, clazz);
//return EntityFactory.createDocumentResult(entity, clazz);
return entity;
}
@Override
public CursorResultSet> executeSimpleFulltextWithDocumentResultSet(
String database,
String collectionName,
String attribute, String query,
int skip, int limit,
String index,
Class> clazz
) throws ArangoException {
CursorEntity> entity = executeSimpleFulltextWithDocument(database, collectionName, attribute, query, skip, limit, index, clazz);
CursorResultSet> rs = new CursorResultSet>(database, cursorDriver, entity, DocumentEntity.class, clazz);
return rs;
}
// ----- // Fulltext --------------------
// ----- first --------------------
@Override
public DocumentResultEntity executeSimpleFirst(
String database,
String collectionName,
Integer count,
Class> clazz) throws ArangoException {
validateCollectionName(collectionName);
HttpResponseEntity res = httpManager.doPut(
createEndpointUrl(baseUrl, database, "/_api/simple/first"),
null,
EntityFactory.toJsonString(
new MapBuilder()
.put("collection", collectionName)
.put("count", count)
.get())
);
return createEntity(res, DocumentResultEntity.class, clazz);
}
// ----- last --------------------
@Override
public DocumentResultEntity executeSimpleLast(
String database,
String collectionName,
Integer count,
Class> clazz) throws ArangoException {
validateCollectionName(collectionName);
HttpResponseEntity res = httpManager.doPut(
createEndpointUrl(baseUrl, database, "/_api/simple/last"),
null,
EntityFactory.toJsonString(
new MapBuilder()
.put("collection", collectionName)
.put("count", count)
.get())
);
return createEntity(res, DocumentResultEntity.class, clazz);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy