TitanManagement mgmt = null; try { mgmt = g.openManagement(); idx = mgmt.getGraphIndex(graphIndexName); for (PropertyKey pk : idx.getFieldKeys()) {
TitanManagement m2 = g2.openManagement(); assertEquals(secondValue.toString(), m2.get(path)); g2.close();
private static Vertex get(TitanGraph graph, String key, String value) { Iterator<Vertex> it = graph.getVertices(key, value).iterator(); Vertex vertex = null; if (it.hasNext()) { vertex = it.next(); } return vertex; } }
@Test public void testTitanFactoryBuilder() { String baseDir = Joiner.on(File.separator).join("target", "es", "titanfactory_jvmlocal_ext"); TitanFactory.Builder builder = TitanFactory.build(); builder.set("storage.backend", "inmemory"); builder.set("index." + INDEX_NAME + ".elasticsearch.interface", "NODE"); builder.set("index." + INDEX_NAME + ".elasticsearch.ext.node.data", "true"); builder.set("index." + INDEX_NAME + ".elasticsearch.ext.node.client", "false"); builder.set("index." + INDEX_NAME + ".elasticsearch.ext.node.local", "true"); builder.set("index." + INDEX_NAME + ".elasticsearch.ext.path.data", baseDir + File.separator + "data"); builder.set("index." + INDEX_NAME + ".elasticsearch.ext.path.work", baseDir + File.separator + "work"); builder.set("index." + INDEX_NAME + ".elasticsearch.ext.path.logs", baseDir + File.separator + "logs"); TitanGraph graph = builder.open(); // Must not throw an exception assertTrue(graph.isOpen()); graph.close(); }
private static void codeSnippets() throws Exception { TitanGraph g = TitanFactory.open("/tmp/titan"); g.createKeyIndex("name", Vertex.class); Vertex juno = g.addVertex(null); juno.setProperty("name", "juno"); juno = g.getVertices("name", "juno").iterator().next(); TransactionalGraph tx = g.newTransaction(); Thread[] threads = new Thread[10]; for (int i = 0; i < threads.length; i++) { //threads[i]=new Thread(new DoSomething(tx)); threads[i].start(); } for (int i = 0; i < threads.length; i++) threads[i].join(); tx.commit(); }
Vertex v = g.addVertex(i); g.commit(); TitanTransaction tx = g.newTransaction();
public static void load(final TitanGraph graph, String mixedIndexName, boolean uniqueNameCompositeIndex) { TitanManagement mgmt = graph.openManagement(); final PropertyKey name = mgmt.makePropertyKey("name").dataType(String.class).make(); TitanManagement.IndexBuilder nameIndexBuilder = mgmt.buildIndex("name", Vertex.class).addKey(name); TitanTransaction tx = graph.newTransaction();
/** * Initialise the handler using the graph passed as arguments. * * @param graph */ public TitanRDFHandler(TitanGraph graph, String indexes) { this.graph = new BatchGraph(graph); if (!graph.getIndexedKeys(Vertex.class).contains(VALUE)) { graph.createKeyIndex(VALUE, Vertex.class); } createTripleIndices(indexes, graph); namespaces = graph.addVertex(NAMESPACES_VERTEX_ID); }
@Override public Vertex createEntity( TypeMetadataSet<EntityTypeMetadata<TitanVertexMetadata>> types, Set<String> discriminators, Map<PrimitivePropertyMethodMetadata<TitanPropertyMetadata>, Object> exampleEntity) { Vertex vertex = titanGraph.addVertex(null); for (String discriminator : discriminators) { vertex.setProperty(TitanStoreSession.XO_DISCRIMINATORS_PROPERTY + discriminator, discriminator); } return vertex; }
@Override public Vertex getOrCreate(String value) { Integer intValue = Integer.valueOf(value); final Vertex v; if (titanGraph.query().has("nodeId", Compare.EQUAL, intValue).vertices().iterator().hasNext()) { v = (Vertex) titanGraph.query().has("nodeId", Compare.EQUAL, intValue).vertices().iterator().next(); } else { final long titanVertexId = TitanId.toVertexId(intValue); v = titanGraph.addVertex(titanVertexId); v.setProperty("nodeId", intValue); titanGraph.commit(); } return v; }
/** * Calls {@link TitanFactory#open(String)}, passing the Titan configuration file path * which must be the sole element in the {@code args} array, then calls * {@link #load(com.thinkaurelius.titan.core.TitanGraph)} on the opened graph, * then calls {@link com.thinkaurelius.titan.core.TitanGraph#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(com.thinkaurelius.titan.core.TitanGraph)}) when calling from * an enclosing application. * * @param args a singleton array containing a path to a Titan config properties file */ public static void main(String args[]) { if (null == args || 1 != args.length) { System.err.println("Usage: GraphOfTheGodsFactory <titan-config-file>"); System.exit(1); } TitanGraph g = TitanFactory.open(args[0]); load(g); g.close(); } }
@Override public void testGraphQueryForVertices() { TitanGraph g = (TitanGraph) graphTest.generateGraph(); if (g.getRelationType("age") == null) { TitanManagement mgmt = g.getManagementSystem(); mgmt.makePropertyKey("age").dataType(Integer.class).cardinality(Cardinality.SINGLE).make(); mgmt.commit(); } g.shutdown(); super.testGraphQueryForVertices(); }
@Override public AtlasGraphManagement getManagementSystem() { return new Titan0GraphManagement(this, getGraph().getManagementSystem()); }
@Override public void commit() { if (!active) { throw new XOException("There is no active transaction."); } active = false; titanGraph.commit(); }
@Override public void close() { logger.info("Shutting down eXtended Objects for Titan on Cassandra..."); titanGraph.shutdown(); titanGraph = null; } }
public void setGraph(TitanGraph graph) { Preconditions.checkArgument(graph!=null && graph.isOpen(),"Need to provide open graph"); this.graph = (StandardTitanGraph)graph; provided = true; }
public static void assertGraphOfTheGods(TitanGraph gotg) { assertEquals(12,Iterables.size(gotg.getVertices())); assertEquals(3,Iterables.size(gotg.getVertices("label","god"))); Vertex h = Iterables.getOnlyElement(gotg.getVertices("name","hercules")); assertEquals(30,h.getProperty("age")); assertEquals("demigod",((TitanVertex)h).getLabel()); assertEquals(5,Iterables.size(h.getEdges(Direction.BOTH))); gotg.commit(); }