-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 78908ff
Showing
4 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
build/ | ||
.idea/ | ||
out/ | ||
graph.iml | ||
.gradle/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
apply plugin: 'java' | ||
|
||
sourceSets { | ||
main { | ||
java { | ||
srcDirs = ['src/java'] | ||
} | ||
} | ||
|
||
} | ||
|
||
repositories { | ||
jcenter() | ||
} | ||
|
||
dependencies { | ||
implementation 'org.janusgraph:janusgraph-core:0.2.0' | ||
implementation 'org.janusgraph:janusgraph-berkeleyje:0.2.0' | ||
implementation 'org.slf4j:slf4j-api:1.7.5' | ||
implementation 'org.slf4j:slf4j-log4j12:1.7.5' | ||
|
||
testImplementation 'junit:junit:4.12' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.example; | ||
|
||
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; | ||
import org.apache.tinkerpop.gremlin.structure.Vertex; | ||
import org.janusgraph.core.Cardinality; | ||
import org.janusgraph.core.JanusGraph; | ||
import org.janusgraph.core.JanusGraphFactory; | ||
import org.janusgraph.core.PropertyKey; | ||
import org.janusgraph.core.schema.JanusGraphManagement; | ||
|
||
|
||
class Example { | ||
public static void main(String[] args) { | ||
JanusGraph graph = getGraph(); | ||
buildIndexFor(graph); | ||
|
||
graph.addVertex("name", "ernesto", "email", "[email protected]"); | ||
|
||
GraphTraversal<Vertex, Vertex> traversal = graph | ||
.traversal() | ||
.V() | ||
.has("email", "[email protected]"); | ||
|
||
Vertex v = traversal.next(); | ||
|
||
System.out.print("Hola " + v.property("name").value()); | ||
} | ||
|
||
private static final JanusGraph getGraph() { | ||
return JanusGraphFactory.build().set("storage.backend", "inmemory").open(); | ||
} | ||
|
||
private static final void buildIndexFor(JanusGraph graph) { | ||
JanusGraphManagement mgmt = graph.openManagement(); | ||
|
||
PropertyKey emailKey = mgmt.makePropertyKey("email") | ||
.dataType(String.class) | ||
.cardinality(Cardinality.SINGLE) | ||
.make(); | ||
|
||
mgmt.buildIndex("byEmailUnique", Vertex.class) | ||
.addKey(emailKey) | ||
.unique() | ||
.buildCompositeIndex(); | ||
|
||
mgmt.commit(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.example; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class ExampleTest { | ||
@Test | ||
public void loadGraphTest() { | ||
|
||
} | ||
} |