8000 some crap · anderick/arangodb-java-driver@c33a4d9 · GitHub
[go: up one dir, main page]

Skip to content

Commit c33a4d9

Browse files
committed
some crap
1 parent 4452085 commit c33a4d9

File tree

6 files changed

+124
-2
lines changed

6 files changed

+124
-2
lines changed

src/main/java/com/arangodb/ArangoDriver.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
import com.arangodb.impl.ImplFactory;
6969
import com.arangodb.impl.InternalBatchDriverImpl;
7070
import com.arangodb.util.DumpHandler;
71+
import com.arangodb.util.MapBuilder;
7172
import com.arangodb.util.ResultSetUtils;
7273

7374
/**
@@ -2450,6 +2451,20 @@ public <T> EdgeEntity<T> graphUpdateEdge(
24502451
ifMatchRevision);
24512452
}
24522453

2454+
// Some methods not using the graph api
2455+
2456+
public <T> CursorEntity<T> graphGetEdges(String graphName, Class<T> clazz) throws ArangoException {
2457+
2458+
validateCollectionName(graphName);
2459+
String query = "return graph_edges(@graphName, null)";
2460+
Map<String, Object> bindVars = new MapBuilder().put("graphName", graphName).get();
2461+
2462+
CursorEntity<T> result = this.executeQuery(query, bindVars, clazz, true, 20);
2463+
2464+
return result;
2465+
2466+
}
2467+
24532468
// ***************************************
24542469
// *** end of graph **********************
24552470
// ***************************************

src/main/java/com/arangodb/InternalGraphDriver.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,16 @@
2121

2222
package com.arangodb;
2323

24+
import java.util.Collection;
2425
import java.util.List;
2526

27+
import com.arangodb.entity.CursorEntity;
2628
import com.arangodb.entity.DeletedEntity;
29+
import com.arangodb.entity.Direction;
2730
import com.arangodb.entity.DocumentEntity;
2831
import com.arangodb.entity.EdgeDefinitionEntity;
2932
import com.arangodb.entity.EdgeEntity;
33+
import com.arangodb.entity.FilterCondition;
3034
import com.arangodb.entity.GraphEntity;
3135
import com.arangodb.entity.GraphsEntity;
3236
import com.arangodb.impl.BaseDriverInterface;
@@ -434,4 +438,18 @@ <T> EdgeEntity<T> updateEdge(
434438
Boolean keepNull,
435439
Long rev,
436440
Long ifMatchRevision) throws ArangoException;
441+
442+
<T> CursorEntity<EdgeEntity<T>> getEdges(
443+
String database,
444+
String graphName,
445+
String vertexKey,
446+
Class<?> clazz,
447+
Integer batchSize,
448+
Integer limit,
449+
Boolean count,
450+
Direction direction,
451+
Collection<String> labels,
452+
ArangoDriver driver,
453+
FilterCondition... properties) throws ArangoException;
454+
437455
}

src/main/java/com/arangodb/impl/InternalGraphDriverImpl.java

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,25 @@
1717
package com.arangodb.impl;
1818

1919
import java.util.ArrayList;
20+
import java.util.Collection;
2021
import java.util.List;
22+
import java.util.Locale;
23+
import java.util.Map;
2124

2225
import org.apache.commons.collections4.CollectionUtils;
2326

2427
import com.arangodb.ArangoConfigure;
28+
import com.arangodb.ArangoDriver;
2529
import com.arangodb.ArangoException;
2630
import com.arangodb.InternalCursorDriver;
31+
import com.arangodb.entity.CursorEntity;
2732
import com.arangodb.entity.DeletedEntity;
33+
import com.arangodb.entity.Direction;
2834
import com.arangodb.entity.DocumentEntity;
2935
import com.arangodb.entity.EdgeDefinitionEntity;
3036
import com.arangodb.entity.EdgeEntity;
3137
import com.arangodb.entity.EntityFactory;
38+
import com.arangodb.entity.FilterCondition;
3239
import com.arangodb.entity.GraphEntity;
3340
import com.arangodb.entity.GraphGetCollectionsResultEntity;
3441
import com.arangodb.entity.GraphsEntity;
@@ -609,6 +616,45 @@ public <T> EdgeEntity<T> updateEdge(
609616

610617
}
611618

619+
@Override
620+
public <T> CursorEntity<EdgeEntity<T>> getEdges(
621+
String database,
622+
String graphName,
623+
String vertexKey,
624+
Class<?> clazz,
625+
Integer batchSize,
626+
Integer limit,
627+
Boolean count,
628+
Direction direction,
629+
Collection<String> labels,
630+
ArangoDriver driver,
631+
FilterCondition... properties) throws ArangoException {
632+
633+
validateCollectionName(graphName);
634+
635+
String getEdges = "var db = require('internal').db;\n" + "var graph = require('org/arangodb/general-graph');\n"
636+
+ "var g = graph._graph('" + graphName + "');\n" + "g._edges();";
637+
driver.executeScript(getEdges);
638+
639+
Map<String, Object> filter = new MapBuilder().put("direction", toLower(direction)).put("labels", labels)
640+
.put("properties", properties).get();
641+
642+
HttpResponseEntity res = httpManager.doPost(
643+
createEndpointUrl(
644+
baseUrl,
645+
database,
646+
"/_api/graph",
647+
StringUtils.encodeUrl(graphName),
648+
"edges",
649+
StringUtils.encodeUrl(vertexKey)),
650+
null,
651+
EntityFactory.toJsonString(new MapBuilder().put("batchSize", batchSize).put("limit", limit).put("count", count)
652+
.put("filter", filter).get()));
653+
654+
return createEntity(res, CursorEntity.class, EdgeEntity.class, clazz);
655+
656+
}
657+
612658
private String convertToString(EdgeDefinitionEntity edgeDefinition) {
613659
JsonObject rawEdgeDefinition = (JsonObject) EntityFactory.toJsonElement(
614660
new MapBuilder().put("edgeDefinition", edgeDefinition).get(),
@@ -617,4 +663,10 @@ private String convertToString(EdgeDefinitionEntity edgeDefinition) {
617663
return edgeDefinitionJson.toString();
618664
}
619665

666+
private String toLower(Enum<?> e) {
667+
if (e == null) {
668+
return null;
669+
}
670+
return e.name().toLowerCase(Locale.US);
671+
}
620672
}

src/test/java/com/arangodb/ArangoDriverGraphEdgesGetTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@
2020
import java.util.HashSet;
2121
import java.util.Set;
2222

23+
import org.junit.Test;
24+
25+
import com.arangodb.entity.CursorEntity;
2326
import com.arangodb.entity.EdgeEntity;
27+
import com.arangodb.entity.GraphEntity;
2428

2529
/**
2630
* @author tamtam180 - kirscheless at gmail.com
@@ -47,6 +51,18 @@ private Set<String> asSet(Object... objects) {
4751
}
4852
return set;
4953
}
54+
55+
@Test
56+
public void test_getEdges() throws ArangoException {
57+
58+
String graphName = "UnitTestGraph";
59+
60+
GraphEntity graph = this.createTestGraph();
61+
CursorEntity<EdgeEntity<?>> blub = driver.graphGetEdges(graph.getName(), null);
62+
blub = blub;
63+
64+
}
65+
5066
//
5167
// @Test
5268
// public void test_get_edges() throws ArangoException {

src/test/java/com/arangodb/ArangoTestSuite.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,6 @@
6868
ArangoDriverGraphEdgeGetTest.class,
6969
ArangoDriverGraphEdgeDeleteTest.class,
7070
ArangoDriverGraphEdgeReplaceTest.class,
71-
ArangoDriverGraphVertices1Test.class,
72-
ArangoDriverGraphVertices2Test.class,
7371
ArangoDriverThreadSafeTest.class,
7472
ArangoDriverReplicationTest.class,
7573
ArangoDriverReplicationTestScenario1.class

src/test/java/com/arangodb/BaseGraphTest.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.junit.Ignore;
2525

2626
import com.arangodb.entity.EdgeDefinitionEntity;
27+
import com.arangodb.entity.GraphEntity;
2728

2829
/**
2930
* @author tamtam180 - kirscheless at gmail.com
@@ -84,4 +85,26 @@ protected List<String> createOrphanCollections(int count) {
8485
return orphanCollections;
8586
}
8687

88+
protected GraphEntity createTestGraph() throws ArangoException {
89+
String createGraph = "var db = require('internal').db;\n"
90+
+ "var graphModule = require('org/arangodb/general-graph');\n"
91+
+ "graphModule._create('CountryGraph', [graphModule._relation('hasBorderWith', ['Country'], ['Country'])]);\n"
92+
+ "db.Country.save({'_key' : 'Germany'});\n" + "db.Country.save({'_key' : 'Austria'});\n"
93+
+ "db.Country.save({'_key' : 'Switzerland'});\n" + "db.Country.save({'_key' : 'Marocco'});\n"
94+
+ "db.Country.save({'_key' : 'Algeria'});\n" + "db.Country.save({'_key' : 'Tunesia'});\n"
95+
+ "db.Country.save({'_key' : 'Brasil'});\n" + "db.Country.save({'_key' : 'Argentina'});\n"
96+
+ "db.Country.save({'_key' : 'Uruguay'});\n" + "db.Country.save({'_key' : 'Australia'});\n"
97+
+ "db.hasBorderWith.save('Country/Germany', 'Country/Austria', {});\n"
98+
+ "db.hasBorderWith.save('Country/Germany', 'Country/Switzerland', {});\n"
99+
+ "db.hasBorderWith.save('Country/Switzerland', 'Country/Austria', {});\n"
100+
+ "db.hasBorderWith.save('Country/Marocco', 'Country/Algeria', {});\n"
101+
+ "db.hasBorderWith.save('Country/Algeria', 'Country/Tunesia', {});\n"
102+
+ "db.hasBorderWith.save('Country/Brasil', 'Country/Argentina', {});\n"
103+
+ "db.hasBorderWith.save('Country/Brasil', 'Country/Uruguay', {});\n"
104+
+ "db.hasBorderWith.save('Country/Argentina', 'Country/Uruguay', {});";
105+
106+
driver.executeScript(createGraph);
107+
108+
return driver.getGraph("CountryGraph");
109+
}
87110
}

0 commit comments

Comments
 (0)
0