The official ArangoDB Java Driver.
arangodb / arangodb-java-driver Goto Github PK
View Code? Open in Web Editor NEWThe official ArangoDB Java driver.
License: Apache License 2.0
The official ArangoDB Java driver.
License: Apache License 2.0
Arango v2.6, Driver v2.5.6
So, I'm just getting started with ArangoDB so it could be that I'm missing something or it seems like your documentation on the ArangoDB website may be out of date, but the tutorial suggests the following code to fetch an entity and its properties :
DocumentEntity<BaseDocument> myDocument = null;
BaseDocument myObject2 = null;
try {
myDocument = arangoDriver.getDocument(collectionName, "myKey", BaseDocument.class);
myObject2 = myDocument.getEntity();
System.out.println("Key: " + myObject2.getDocumentKey());
System.out.println("Attribute 'a': " + myObject2.getProperties().get("a"));
System.out.println("Attribute 'b': " + myObject2.getProperties().get("b"));
System.out.println("Attribute 'c': " + myObject2.getProperties().get("c"));
} catch (ArangoException e) {
System.out.println("Failed to get document. " + e.getMessage());
}
The readme for this project seems to show that you should use your own class rather than BaseDocument and count on the driver's deserialization, which seems ok, but I'd much rather have more fine grained control over my deserialization by accessing properties directly and handling nulls myself rather than getting back an object potentially chock full of null values for missing fields.
Is there some way to get BaseDocument to function as described in the code I pasted above? I've tried both like that and using the AQL and any time I use BaseDocument it returns an empty Map for properties. In any case, the tutorial should probably be updated because as a new user it's pretty frustrating when the "Java in 10 Minutes" tutorial leads to an hour of frustration because the code doesn't function as stated.
Hello,
Is there a way to use the driver non-blocking I/O way? Maybe through Reactive Streams or direct support of something like RxJava.
Team,
Can you please help me with any example usage of importDocuments in java.
Regards,
Sajeev
I would like to request for the following features to be implemented in the driver:
The above 2 will enable the driver to automatically connects to another coordinator when the coordinator it is connected to fails.
Even if you use a HA load balancer, when the primary load balancer fails and the secondary takes over with the same IP, the driver will require to reconnect to that IP address.
Just found that EdgeDefinitionsEntity.getEdgeDefinition(String collectionName) always returns null for me.
I think this is because of == string compare inside getEdgeDefinition method, it should be .equals there.
And also can you please help, how can I update edgeDefinition that already exists.
It would be great if we could add an api in align with "Exists" as mentioned in https://docs.arangodb.com/Documents/DocumentMethods.html
Is there any timeline on support for ArangoDB 2.6?
Regards,
Ben.
Hi,
Do you have plans to add support for classic begin -> commit/rollback transactions in additional to current db._executeTransaction(object) ?
In some cases the server will not reply with a json response; If thats the case the java driver seems to invoke the json driver anyways, which then in term throws an exception.
The resulting exception however doesn't contain any useful information about the real error itself.
Thus the javadriver should check the content type, and catch parser errors so it can give the user the actual error message.
It seems as if this line is missing the exception handling:
at com.arangodb.entity.EntityFactory.createEntity(EntityFactory.java:109)
originally posted in [email protected]
"
I'm trying to use the batch mode operations. I have a lot of documents to
make. So I want to batch them up in groups of 1,000. The code starts batch
mode. Loads 1,000 documents. It then calls the executeBatch() on the
driver. It then starts a new batch, startBatchMode(). The code processes
the next 956 records, and flushed the batch on close().
What I'm seeing is not batch(1,000) + batch (956). I'm getting batch(1,000)
"
Referring to https://github.com/arangodb/arangodb-java-driver
When there is no need to add orphanCollections, I code like this:
GraphEntity graph=driverDB.createGraph("test_Graph",edgeDefinitions,null,true);
But it throws a error:
om.arangodb.ArangoException: [1923] malformed edge definition
at com.arangodb.BaseArangoDriver.checkServerErrors(BaseArangoDriver.java:191)
at com.arangodb.BaseArangoDriver.createEntity(BaseArangoDriver.java:231)
at com.arangodb.BaseArangoDriver.createEntity(BaseArangoDriver.java:306)
at com.arangodb.impl.InternalGraphDriverImpl.createGraph(InternalGraphDriverImpl.java:86)
at com.arangodb.ArangoDriver.createGraph(ArangoDriver.java:3550)
at MyGraph.main(MyGraph.java:90)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
Any suggestion is greatly appreciated.
I was trying to implement the query cache for large queries.
When i check if the document cursor is cached or not, it shows true. But i see no performance improvements in the query time processing.
However using the same query from arangodb web interface shows high performance improvements.
Current implementation of driver.importDocuments
does not provide any means to customize it.
The following provisions should be present in the API:
onDuplicate
. In fact, to make it more genetic, we should have a Map
of query parameters in the API that can have any number of parameters.updateDocumentRaw
/import
API provides a flag details
which when used provides more info on the records that failed for any reason. Provide a way to fetch the details
object in the response along with the already present counts of documents.ArangoDB 3.0 apparently adds a new "persistent" index type.
This currently is not part of the provided Index Types in this driver.
I use the arango driver in a multithreaded environment and wanted to know if the CollectionEntry class is thread safe or not. I would like to instantiate it once as a public static final field.
"ArangoCollectionarangoDriver" can't be found in the arangodb-java-driver-3.0.3.
Any help is highly appreciated .
Hi,
Actually this library is using google-gson for managing JSON.
But what about Jackson? Some projects are already using Jackson instead of google.gson and have a complex configuration for serializing and deserializing data.
It could be very useful to let the user choose between Gson, Jackson or even another solution.
Is there any plan to add support to Jackson or another library?
Team,
Is there any way to do an upsert using the java driver.
Thanks & Regards,
Sajeev Ramakrishnan
Hi!
I am using arango java driver, version: 2.2.1. I have an Object with attribute name "code" and type String. When I select it from the database by id
new ArangoDriver().graphGetVertex(graphName, collectionName, id, CodeAttributeTest.class)
I got the following exception:
java.lang.IllegalStateException: Failed to execute CommandLineRunner
at org.springframework.boot.SpringApplication.runCommandLineRunners(SpringApplication.java:680)
at org.springframework.boot.SpringApplication.afterRefresh(SpringApplication.java:695)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:321)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:952)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:941)
at com.nebu.arangotest.ApplicationConfig.main(ApplicationConfig.java:26)
Caused by: java.lang.NumberFormatException: For input string: "alfaNumericCode"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:580)
at java.lang.Integer.parseInt(Integer.java:615)
at com.google.gson.JsonPrimitive.getAsInt(JsonPrimitive.java:260)
at com.arangodb.entity.EntityDeserializers.deserializeBaseParameter(EntityDeserializers.java:156)
at com.arangodb.entity.EntityDeserializers.access$000(EntityDeserializers.java:56)
at com.arangodb.entity.EntityDeserializers$DocumentEntityDeserializer.deserialize(EntityDeserializers.java:576)
at com.arangodb.entity.EntityDeserializers$DocumentEntityDeserializer.deserialize(EntityDeserializers.java:557)
at com.google.gson.TreeTypeAdapter.read(TreeTypeAdapter.java:58)
at com.google.gson.Gson.fromJson(Gson.java:805)
at com.google.gson.Gson.fromJson(Gson.java:870)
at com.google.gson.Gson$1.deserialize(Gson.java:127)
at com.arangodb.entity.EntityDeserializers$VertexEntityDeserializer.deserialize(EntityDeserializers.java:1704)
at com.arangodb.entity.EntityDeserializers$VertexEntityDeserializer.deserialize(EntityDeserializers.java:1691)
at com.google.gson.TreeTypeAdapter.read(TreeTypeAdapter.java:58)
at com.google.gson.Gson.fromJson(Gson.java:805)
at com.google.gson.Gson.fromJson(Gson.java:770)
at com.google.gson.Gson.fromJson(Gson.java:719)
at com.arangodb.entity.EntityFactory.createEntity(EntityFactory.java:115)
at com.arangodb.BaseArangoDriver.createEntityImpl(BaseArangoDriver.java:270)
at com.arangodb.BaseArangoDriver.createEntity(BaseArangoDriver.java:181)
at com.arangodb.BaseArangoDriver.createEntity(BaseArangoDriver.java:219)
at com.arangodb.impl.InternalGraphDriverImpl.getVertex(InternalGraphDriverImpl.java:371)
at com.arangodb.ArangoDriver.graphGetVertex(ArangoDriver.java:4090)
at com.nebu.arangotest.main.CodeTestMain.printWithSelectById(CodeTestMain.java:112)
at com.nebu.arangotest.main.CodeTestMain.run(CodeTestMain.java:126)
at org.springframework.boot.SpringApplication.runCommandLineRunners(SpringApplication.java:677)
However when I select it via
new ArangoDriver().executeQueryWithResultSet("For p in CollectionName FILTER p._key == @id RETURN p", parameters, CodeAttributeTest.class, true, 20)
I got back the right object without any exception.
Because now my ArangoDB version is 3.0.5 , can I add version group 3.0.5 to the dependency of pom.xml?
Any help is highly appreciated.
Can you please tell me how to remove or redirect debug logs of ArangoDB java driver?
Is this driver support command for execute Batch, Transaction, and Action?
Would you consider to create examples for that?
Thanks.
When I code like this:
CursorResult rs=arangoDriver.executeQueryWithResultSet(query,bindVars2,BaseDocument.class,true,20);
the color of "executeQueryWithResultSet" is red. And it throws a error below:
"
Error:(105, 41) java: 找不到符号
符号: 方法 executeQueryWithResultSet(java.lang.String,java.util.Map<java.lang.String,java.lang.Object>,java.lang.Class<com.arangodb.entity.BaseDocument>,boolean,int)
位置: 类型为com.arangodb.ArangoDriver的变量 arangoDriver
"
Any suggestion is appreciated greatly.
Why is that TransactionEntity.ReadWriteCollections is not a static class?
Because of that I can't setCollections.
As mentioned https://docs.arangodb.com/2.8/HttpAqlQueryCursor/AccessingCursors.html
, there is an options
flag which lets us control profile
for additional query profiling. Turns out it is enabled by default and I would like to turn it off.
Currently, there is no option to control this from AQL Query Options.
It should also be possible to fetch the extra.stats
parameter returned in the cursor output. It is only possible to access this when using driver.executeAqlQuery
via cursorResult.getEntity.getExtra
. However, it is not available via driver.executeDocumentQuery
.
Which one out of the both should be used and when?
In the doc, there is:
while (DocumentEntity documentEntity : documentCursor.asList()) {
MyObject obj = documentEntity.getEntity();
System.out.println(obj.getName());
}
please replace while
by for
Hi,
I added functions to get the raw JSON response with the results from the server:
https://github.com/miguel-porto/arangodb-java-driver
This is handy when the response is composed of JSON docs with different formats and you just want to pass it through without parsing.
Should I make a pull request?
Best,
Miguel
this is the code used for upsert with java-arango driver -
This is how it looks in arango. (1st line is commit/insert through shell and 2nd is through code).
Query run on shell : -
arangosh [test]> db._query("UPSERT {_key:'133_rohit'} INSERT {_key:'133_rohit',n
ame:'RB Bansal'} UPDATE {_key:'133_rohit',"name":"RaB Bansal"} IN firstColle
ction")
There is difference in observation when same query ran through java driver code and shell.
In case of java driver, it is ignoring the key sent by me and generating a key on its own. In case of shell, its respecting the _key supplied by me.
Hi,
I'm searching the method of beforeSave or afterUpdate, but found nothing.
The "before" or "after" same as triger in RDBMS.
Thanks.
Just by looking at the query execution API provided by the java driver, there is no easy way to tell which method is to be used to execute a standard AQL query:
Even if I do not consider the deprecated methods (not on the picture) and the methods for Edge query and Vertext Query, there is still a bit of confusion there.
This helps a little bit but still does not cover all the available options. Stuff like executeAqlQueryJSON
returning String
and executeAqlQueryRaw
returning a CursorRawResult
which includes JSON strings make the whole thing even worse.
So, my question are:
I'm saving and getting a BaseDocument
to be able to have a bag of dynamic properties. The problem is that if I put in any numeric type ( e.g. Integer
or Long
), the Java driver returns Double
. The value is properly stored in in the database as Long
.
The problem is the EntityDeserializers.deserializeJsonPrimitive(jsonPrimitive):668
, where any Number
is returned as Double
.
This is the code that reproduces this:
public class ArangoTest {
private ArangoDriver arangoDriver;
private String collection;
@Before
public void setup() {
Properties props = new Properties();
try {
InputStream propertiesStream = ArangoTest.class.getResourceAsStream("/arangodb.properties");
props.load(propertiesStream);
} catch (IOException e) {
throw new RuntimeException(e);
}
ArangoConfigure configure = new ArangoConfigure();
configure.setHost(props.getProperty("host"));
configure.setPort(Integer.valueOf(props.getProperty("port")));
configure.init();
// Create Driver (this instance is thread-safe)
arangoDriver = new ArangoDriver(configure);
try {
String database = "junit";
collection = "test";
if (!arangoDriver.getDatabases().getResult().contains(database)) {
arangoDriver.createDatabase(database);
}
arangoDriver.setDefaultDatabase(database);
if (arangoDriver.getCollection(collection) == null) {
arangoDriver.createCollection(collection);
}
} catch (ArangoException e) {
throw new RuntimeException(e);
}
}
@Test
public void test() {
Long inputValue = 1l;
Map<String, Object> data = new HashMap<>();
data.put("number", inputValue);
try {
DocumentEntity<BaseDocument> doc = arangoDriver.createDocument(collection, data);
DocumentEntity<BaseDocument> result = arangoDriver.getDocument(doc.getDocumentHandle(), BaseDocument.class);
Map<String, Object> fields = result.getEntity().getProperties();
System.out.println("Input value:"+inputValue+" type:"+(inputValue.getClass().getSimpleName()));
System.out.println("Output value:"+fields.get("number")+" type:"+(fields.get("number").getClass().getSimpleName()));
} catch (ArangoException e) {
throw new RuntimeException(e);
}
}
}
Please tell me how to implement query cache using Arango Java Driver.
Hello!
I'm currently working with CursorResult
and CursorRawResult
classes. Both of them implement the Iterable
interface, enabling us to iterate more than once over the result.
However, the iterator
method returns always the same iterator and thus the result can only be consumed once.
@Override
public Iterator<T> iterator() {
if (iter == null) {
iter = new CursorIterator();
}
return iter;
}
It makes perfectly sense that the result can only be consumed once, because the cursor of the DB is also moved with continueQuery
method. One could aggregate the results instead of overwriting it and always provide a new iterator. But the list can grow huge and there is also the asList
method.
Wouldn't it be more clear for the user if CursorResult
and CursorRawResult
would implement the Iterator
interface, indicating that it can only be consumed once?
And the asList
method returns only a complete list if no object is already consumed from the iterator. Should the asList
method be called asListRemaining
just like the forEachRemaining
of the Iterator
interface? Or completely remove this method to avoid confusing?
Enviroments:
ArangoDB (3.0.5)
Arangodb-java-driver-3.0.3
When I create a document with the code below:
ArangoConfigure configure = new ArangoConfigure();
ArangoDriver arangoDriver = new ArangoDriver(configure);
String collectionName="firstcollection";
try{
CollectionEntity myArangoCollection=arangoDriver.createCollection(collectionName);
}catch (Exception e){
System.out.println("Failed to collection"+ collectionName+";"+e.getMessage());
}
BaseDocument myObject=new BaseDocument();
myObject.setDocumentKey("myKey");
myObject.addAttribute("a","Foo");
myObject.addAttribute("b",42);
try {
arangoDriver.createDocument(collectionName,myObject);
System.out.println("Document created");
}catch (ArangoException e){
System.out.println("Field to create document."+e.getMessage());
}
It has a error:
Field to create document.[1210] cannot create document, unique constraint violated.
Any suggestion is appreciated greatly.
https://docs.arangodb.com/Aql/Operations.html
has many AqlQueryOptions such as keepNull
, mergeObjects
etc which is missing from AqlQueryOptions
When I add the following code to my pom.xml(the version of my arangodb is 3.0.5):
com.arangodb
arangodb-java-driver
3.0.3
and I use " mvn install" to get the dependency, it throws a error:
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project Save: Could not resolve dependencies f
or project com.huawei.arangodb.Save:Save:jar:1.0-SNAPSHOT: Failure to find com.a
rangodb:arangodb-java-driver:jar:3.0.3 in http://10.175.102.184:8081/nexus/conte
nt/groups/public/ was cached in the local repository, resolution will not be rea
ttempted until the update interval of big has elapsed or updates are forced -> [
Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e swit
ch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException
When I put arangodb-java-driver-3.0.3.jar into my local Maven libs, it still has this problem.
Any help is highly apprechiated.
I have this situation:
public class User {
private String email;
private String name;
private String surname;
private String username;
private String password;
/* getter and setter*/
}
/* ------- */
public T getByUniqueKey(String key, Object value) throws ArangoException {
String query = "FOR t IN " + getCollectionName() + " FILTER t." + key + " == @" + key + " RETURN t";
Map<String, Object> bindVars = new MapBuilder().put(key, value).get();
return getConnection().executeQuery(query,
bindVars, clazz, false, 0).getUniqueResult();
}
/* ------ */
After calling the getByUniqueKey method, I would do like update the User
object.
I cannot use the updateDocument
method because I do not have the _id field. In fact,
_id
and _key
fields are available only when call method that returns DocumentEntity<T>
or extends BaseDocument
class.
If extends BaseDocument
other fields like properties
are serialized and saved to DB.
I've used recently this object mapper where each class extends ArangoDbDocument
.
I could use this approach, however, would be redundant if the same class is used in a method that returns a DocumentEntity<T>
Any suggestions?
Once the graph is created it is not possible to change the edge collections. graph.setEdgeDefinitions(edgeDefinitions) has not effect (version 2.5.0)
Hi, I'm the author of c# driver. I see that java driver bring Vpack for serialization. Is it better for other drivers to port Vpack in their language and use it for serialization?
it's also missing javadocs for classDocumentEntity argument
Implement "ArangoDB Query Builder" like JavaScript node package module.
Could you confirm that driver does not support traversal API?
There is a slight bug in the method ArangoDriver.getAqlFunctions() which causes that only the functions in the system database will be retrieved.
getAqlFunctions() delegates to method InternalAqlFunctionsDriverImpl.getAqlFunctions(String) which builds the request to retrieve the functions. And here is the bug:
HttpResponseEntity res = httpManager.doGet(createEndpointUrl(null, API_AQLFUNCTION + appendix));
In order to use the propper database this should be:
HttpResponseEntity res = httpManager.doGet(createEndpointUrl(configure.getDefaultDatabase(), API_AQLFUNCTION + appendix));
Thanks
Ralf
Hi,
I think the issue #21 still exists for traversals. I tested the following code from version 2.7.4 up to 3.0.2 with ArangoDB version 3.0.5:
TraversalQueryOptions options = new TraversalQueryOptions();
options.setGraphName("GRAPHNAME");
options.setDirection(Direction.OUTBOUND);
options.setStartVertex("COL/123");
TraversalEntity<BaseDocument, BaseDocument> traversalEntity = arangoDb.getTraversal(options, BaseDocument.class, BaseDocument.class);
traversalEntity.getVertices().get(0).getEntity().getProperties().size(); // <--- this returns 0 for every entity
The TraversalEntity contains the correct vertices and edges, but the properties are missing.
Reading the startVertex with arangoDb.getDocument("COL/123", BaseDocument.class)
works fine (including the properties).
Thank you in advance!
I fail to understand how to get all results of a query without setting batchSize
parameter to a particular value, for example in:
arangoDriver.executeQuery(query, bindVars, clazz, calcCount, batchSize);
Is there a documentation for this, if so can please provide the link?
There us method to create edges directly in edge collection (version 2.5.0). Can only use corresponding graph method.
There is no replaceDocumentRaw
similar to createDocumentRaw
. This is needed when we want to send the raw JSON string when replacing a document.
Method createEdge takes graphName as a first argument - however this argument is in fact used as a databaseName during rest call URL construction.
see InternalEdgeDriverImpl line 54:
HttpResponseEntity response = httpManager.doPost(createEndpointUrl(graphName, "/_api/edge"), params, body);
However createEndpointUrl method takes following parameters:
protected String createEndpointUrl(String database, Object... paths) throws ArangoException
Property graphName is here used as a database name (first argument) in the createEndpointUrl method call and will be placed in the generated URL that should have this format:
http://server:port/_db/<database-name>/_api/edge
Currently following URL is generated:
http://server:port/_db/<graph-name>/_api/edge
which will always result in 404 and "database not found" error
Currently arangodb-java-driver uses httpclient 4.2.
httpclient 4.2 and 4.3 have different api structure, which will conflict when put both to a project's dependency.
My project has other library based on httpclient 4.3, and made me difficult to manage the dependency.
So I would suggest update arangodb-java-driver to httpclient 4.3.x, keeps up to date seems a good idea.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.