Skip to content

Commit

Permalink
graph example, initial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
erneestoc committed Mar 23, 2018
0 parents commit 78908ff
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
build/
.idea/
out/
graph.iml
.gradle/
23 changes: 23 additions & 0 deletions build.gradle
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'
}
48 changes: 48 additions & 0 deletions src/java/com/example/example.java
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();
}
}
9 changes: 9 additions & 0 deletions src/test/com/example/ExampleTest.java
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() {

}
}

0 comments on commit 78908ff

Please sign in to comment.