@Test public void testOrForceIndexPartialIndex() throws Exception { JanusGraph customGraph = null; try { customGraph = this.getForceIndexGraph(); final JanusGraphManagement management = customGraph.openManagement(); final PropertyKey stringProperty = management.makePropertyKey("name").dataType(String.class).cardinality(Cardinality.SINGLE).make(); management.makePropertyKey("age").dataType(Integer.class).cardinality(Cardinality.SINGLE).make(); management.buildIndex("oridx", Vertex.class).addKey(stringProperty, getStringMapping()).buildMixedIndex(INDEX); management.commit(); customGraph.tx().commit(); final GraphTraversalSource g = customGraph.traversal(); g.addV().property("name", "Hiro").property("age", 2).next(); g.addV().property("name", "Totoro").property("age", 1).next(); customGraph.tx().commit(); g.V().or(__.has("name", "Totoro"),__.has("age", 2)).hasNext(); fail("should fail"); } catch (final JanusGraphException e){ assertTrue(e.getMessage().contains("Could not find a suitable index to answer graph query and graph scans are disabled")); } finally { if (customGraph != null) { JanusGraphFactory.close(customGraph); } } }
/** * Calls {@link JanusGraphFactory#open(String)}, passing the JanusGraph configuration file path * which must be the sole element in the {@code args} array, then calls * {@link #load(org.janusgraph.core.JanusGraph)} on the opened graph, * then calls {@link org.janusgraph.core.JanusGraph#close()} * and returns. * <p> * This method may call {@link System#exit(int)} if it encounters an error, such as * failure to parse its arguments. Only use this method when executing main from * a command line. Use one of the other methods on this class ({@link #create(String)} * or {@link #load(org.janusgraph.core.JanusGraph)}) when calling from * an enclosing application. * * @param args a singleton array containing a path to a JanusGraph config properties file */ public static void main(String args[]) { if (null == args || 1 != args.length) { System.err.println("Usage: GraphOfTheGodsFactory <janusgraph-config-file>"); System.exit(1); } JanusGraph g = JanusGraphFactory.open(args[0]); load(g); g.close(); } }
/** * Drop graph database, deleting all data in storage and indexing backends. Graph can be open or closed (will be * closed as part of the drop operation). The graph is also removed from the {@link JanusGraphManager} * graph reference tracker, if there. * * <p><b>WARNING: This is an irreversible operation that will delete all graph and index data.</b></p> * @param graph JanusGraph graph database. Can be open or closed. * @throws BackendException If an error occurs during deletion */ public static void drop(JanusGraph graph) throws BackendException { Preconditions.checkNotNull(graph); Preconditions.checkArgument(graph instanceof StandardJanusGraph,"Invalid graph instance detected: %s",graph.getClass()); final StandardJanusGraph g = (StandardJanusGraph) graph; final JanusGraphManager jgm = JanusGraphManagerUtility.getInstance(); if (jgm != null) { jgm.removeGraph(g.getGraphName()); } if (graph.isOpen()) { graph.close(); } final GraphDatabaseConfiguration config = g.getConfiguration(); final Backend backend = config.getBackend(); try { backend.clearStorage(); } finally { IOUtils.closeQuietly(backend); } }
public static void assertGraphOfTheGods(JanusGraph graphOfTheGods) { assertCount(12, graphOfTheGods.query().vertices()); assertCount(3, graphOfTheGods.query().has(LABEL_NAME, "god").vertices()); final JanusGraphVertex h = getOnlyVertex(graphOfTheGods.query().has("name", "hercules")); assertEquals(30, h.<Integer>value("age").intValue()); assertEquals("demigod", h.label()); assertCount(5, h.query().direction(Direction.BOTH).edges()); graphOfTheGods.tx().commit(); }
JanusGraphManagement m2 = g2.openManagement(); assertEquals(secondValue.toString(), m2.get(path)); g2.close();
private static Vertex get(final JanusGraph graph, final String key, final String value) { final GraphTraversalSource g = graph.traversal(); final Iterator<Vertex> it = g.V().has(key, value); if (it.hasNext()) { return it.next(); } return null; } }
JanusGraphManagement management = null; try { management = g.openManagement(); idx = management.getGraphIndex(graphIndexName); for (PropertyKey pk : idx.getFieldKeys()) {
@Override public Transaction newTransaction() { return context.getGraph().tx(); }
@Test public void testOrForceIndexUniqueMixedIndex() throws Exception { JanusGraph customGraph = null; try { customGraph = this.getForceIndexGraph(); final JanusGraphManagement management = customGraph.openManagement(); final PropertyKey nameProperty = management.makePropertyKey("name").dataType(String.class).cardinality(Cardinality.SINGLE).make(); final PropertyKey ageProperty = management.makePropertyKey("age").dataType(Integer.class).cardinality(Cardinality.SINGLE).make(); final PropertyKey lengthProperty = management.makePropertyKey("length").dataType(Integer.class).cardinality(Cardinality.SINGLE).make(); management.buildIndex("oridx", Vertex.class).addKey(nameProperty, getStringMapping()).addKey(ageProperty).addKey(lengthProperty).buildMixedIndex(INDEX); management.commit(); customGraph.tx().commit(); testOr(customGraph); } finally { if (customGraph != null) { JanusGraphFactory.close(customGraph); } } }
public void setGraph(JanusGraph graph) { Preconditions.checkArgument(graph!=null && graph.isOpen(),"Need to provide open graph"); this.graph = (StandardJanusGraph)graph; provided = true; }
JanusGraphManagement management = graph.openManagement(); final PropertyKey name = management.makePropertyKey("name").dataType(String.class).make(); JanusGraphManagement.IndexBuilder nameIndexBuilder = management.buildIndex("name", Vertex.class).addKey(name); JanusGraphTransaction tx = graph.newTransaction();
@Override public String writeSingle(String key) throws Exception { if (useJanusgraphTransaction) { graph.addVertex(T.label, VERTEX_LABEL_LEVEL_1, PROP_CUSTOM_ID_KEY, key, PROP_METADATA_KEY, dataGenerator.getRandomValue()); //Automatically opens a new transaction graph.tx().commit(); } else { traversalSource.getGraph().addVertex(T.label, VERTEX_LABEL_LEVEL_1, PROP_CUSTOM_ID_KEY, key, PROP_METADATA_KEY, dataGenerator.getRandomValue()); traversalSource.getGraph().tx().commit(); } return OK; }
@Override public void run() { final long start = System.currentTimeMillis(); final Vertex vertex = graph.addVertex(); vertex.property(COMIC_BOOK, comicBook); REGISTRY.counter(COUNTER_GET + COMIC_BOOK).inc(); final long end = System.currentTimeMillis(); final long time = end - start; REGISTRY.timer(TIMER_CREATE + COMIC_BOOK).update(time, TimeUnit.MILLISECONDS); } }
JanusGraphTransaction tx1 = graph.newTransaction(); JanusGraphTransaction tx2 = graph.newTransaction(); job.run(tx1); job.run(tx2);
@Override public Iterable<AtlasVertex<AtlasJanusVertex, AtlasJanusEdge>> getVertices() { Iterator<Vertex> vertices = getGraph().vertices(); return wrapVertices(vertices); }
@Override public void init(DataGenerator dataGenerator) throws Exception { this.graph = graphBuilder.open(); this.traversalSource = graph.traversal(); this.dataGenerator = dataGenerator; createSchema(graph); logger.info("Initing JanusGraph Plugin CQL"); }
private static void removeGraphFromCache(final JanusGraph graph) { final JanusGraphManager jgm = JanusGraphManagerUtility.getInstance(); Preconditions.checkState(jgm != null, JANUS_GRAPH_MANAGER_EXPECTED_STATE_MSG); jgm.removeGraph(((StandardJanusGraph) graph).getGraphName()); final ManagementSystem mgmt = (ManagementSystem) graph.openManagement(); mgmt.evictGraphFromCache(); mgmt.commit(); }