import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import com.datastax.driver.dse.DseCluster;
import com.datastax.driver.dse.DseSession;
import com.datastax.driver.dse.graph.GraphOptions;
import com.datastax.driver.dse.graph.SimpleGraphStatement;
import com.datastax.dse.graph.api.DseGraph;
public class DseTest {
public static void main(String args[]) {
DseSession session = DseCluster
.builder()
.addContactPoint("127.0.0.1")
.withGraphOptions(new GraphOptions().setGraphName("test"))
.build()
.connect();
session.executeGraph(new SimpleGraphStatement("system.graph('test').ifNotExists().create()").setSystemQuery());
session.executeGraph("schema.config().option('graph.schema_mode').set('Production')");
session.executeGraph("schema.propertyKey('id').Int().single().ifNotExists().create()");
session.executeGraph("schema.vertexLabel('label').properties('id').ifNotExists().create()");
session.executeGraph("schema.vertexLabel('label').index('label_by_id').materialized().by('id').ifNotExists().add()");
GraphTraversalSource source = DseGraph.traversal(session);
if (source.V().has("label", "id", 1).count().next() == 0) {
source.addV("label").property("id", 1).iterate();
}
try {
GraphTraversal<Vertex, Vertex> traversal = source.V().has("label", "id", 1);
Object unused = traversal.asAdmin().clone().count().next();
Vertex vertex = traversal.range(0, 1).next(); // returns same Long value as above
}
catch (Exception e) {
// java.lang.ClassCastException: java.lang.Long cannot be cast to org.apache.tinkerpop.gremlin.structure.Vertex
System.out.println(e.toString());
}
try {
GraphTraversal<Vertex, Vertex> traversal = source.V().has("label", "id", 1);
Object unused = traversal.asAdmin().clone().valueMap().next();
traversal.property("id", 2).iterate(); // fails with no detail in exception
}
catch (Exception e) {
// com.datastax.driver.core.exceptions.InvalidQueryException:
System.out.println(e.toString());
}
}
}