@Override public long getID(int pos) { return vertices.get(pos).getLongId(); }
private void verifyVerticesRetrieval(long[] vids, Map<Long,TitanVertex> vs) { for (int i = 0; i < vids.length; i++) { assertTrue(vs.containsKey(vids[i])); assertEquals(vids[i],vs.get(vids[i]).getLongId()); } }
/** * Converts a Titan vertex id of a given vertex to the user provided id as the inverse mapping of {@link #toVertexId(long)}. * * @param v Vertex * @return original user provided id */ public static final long fromVertexID(TitanVertex v) { Preconditions.checkArgument(v.hasId(), "Invalid vertex provided: %s", v); return fromVertexId(v.getLongId()); }
/** * Utility method used to convert the list of vertices into a list of vertex ids (assuming all vertices have ids) * * @param vertices * @return */ private static final LongArrayList toLongList(List<TitanVertex> vertices) { LongArrayList result = new LongArrayList(vertices.size()); for (TitanVertex n : vertices) { result.add(n.getLongId()); } return result; }
public boolean isPartitionedVertex(TitanVertex vertex) { return vertex.hasId() && idInspector.isPartitionedVertex(vertex.getLongId()); }
public InternalVertex getOtherPartitionVertex(TitanVertex partitionedVertex, long otherPartition) { Preconditions.checkArgument(isPartitionedVertex(partitionedVertex)); return getExistingVertex(idManager.getPartitionedVertexId(partitionedVertex.getLongId(), otherPartition)); }
@Override public void run() { while (true) { // Make or break relType between two (possibly same) random nodes // TitanVertex source = tx.getVertex(idProp, RandomGenerator.randomInt(0, nodeCount)); // TitanVertex sink = tx.getVertex(idProp, RandomGenerator.randomInt(0, nodeCount)); TitanVertex source = Iterables.getOnlyElement(tx.getVertices(idProp, 0)); TitanVertex sink = Iterables.getOnlyElement(tx.getVertices(idProp, 1)); for (TitanEdge r : source.getTitanEdges(Direction.OUT, relType)) { if (r.getVertex(Direction.IN).getLongId() == sink.getLongId()) { r.remove(); continue; } } source.addEdge(relType, sink); if (Thread.interrupted()) break; } }
@Override protected void doRun() throws Exception { TitanVertex n = Iterables.getOnlyElement(tx.getVertices(id, nodeid)); for (int i = 0; i < nodeTraversalCount; i++) { assertEquals("On vertex: " + n.getLongId(), expectedEdges, Iterables.size(n.getTitanEdges(Direction.BOTH, relTypeToTraverse))); for (TitanEdge r : n.getTitanEdges(Direction.OUT, relTypeToTraverse)) { n = r.getVertex(Direction.IN); } } } }
public InternalVertex[] getAllRepresentatives(TitanVertex partitionedVertex, boolean restrict2Partitions) { Preconditions.checkArgument(isPartitionedVertex(partitionedVertex)); long[] ids; if (!restrict2Partitions || !config.hasRestrictedPartitions()) { ids = idManager.getPartitionedVertexRepresentatives(partitionedVertex.getLongId()); } else { int[] restrictedParititions = config.getRestrictedPartitions(); ids = new long[restrictedParititions.length]; for (int i=0;i<ids.length;i++) { ids[i]=idManager.getPartitionedVertexId(partitionedVertex.getLongId(),restrictedParititions[i]); } } Preconditions.checkArgument(ids.length>0); InternalVertex[] vertices = new InternalVertex[ids.length]; for (int i=0;i<ids.length;i++) vertices[i]=getExistingVertex(ids[i]); return vertices; }
public static int getPartitionID(TitanVertex vertex, IDManager idManager) { long p = idManager.getPartitionId(vertex.getLongId()); assertTrue(p>=0 && p<idManager.getPartitionBound() && p<Integer.MAX_VALUE); return (int)p; }
private void verifyWriteAccess(TitanVertex... vertices) { if (config.isReadOnly()) throw new UnsupportedOperationException("Cannot create new entities in read-only transaction"); for (TitanVertex v : vertices) { if (v.hasId() && idInspector.isUnmodifiableVertex(v.getLongId()) && !v.isNew()) throw new SchemaViolationException("Cannot modify unmodifiable vertex: "+v); } verifyAccess(vertices); }
@Override public Long retrieveSchemaByName(String typeName) { // Get a consistent tx Configuration customTxOptions = backend.getStoreFeatures().getKeyConsistentTxConfig(); StandardTitanTx consistentTx = null; try { consistentTx = StandardTitanGraph.this.newTransaction(new StandardTransactionBuilder(getConfiguration(), StandardTitanGraph.this, customTxOptions).setGroupName(GraphDatabaseConfiguration.METRICS_SCHEMA_PREFIX_DEFAULT)); consistentTx.getTxHandle().disableCache(); TitanVertex v = Iterables.getOnlyElement(consistentTx.getVertices(BaseKey.SchemaName, typeName), null); return v!=null?v.getLongId():null; } finally { TXUtils.rollbackQuietly(consistentTx); } }
public void executeMultiQuery(final Collection<InternalVertex> vertices, final SliceQuery sq) { LongArrayList vids = new LongArrayList(vertices.size()); for (InternalVertex v : vertices) { if (!v.isNew() && v.hasId() && (v instanceof CacheVertex) && !v.hasLoadedRelations(sq)) vids.add(v.getLongId()); } if (!vids.isEmpty()) { List<EntryList> results = graph.edgeMultiQuery(vids, sq, txHandle); int pos = 0; for (TitanVertex v : vertices) { if (pos<vids.size() && vids.get(pos) == v.getLongId()) { final EntryList vresults = results.get(pos); ((CacheVertex) v).loadRelations(sq, new Retriever<SliceQuery, EntryList>() { @Override public EntryList get(SliceQuery query) { return vresults; } }); pos++; } } } }
@Test public void testPropertyIndexPersistence() { final String propName = "favorite_color"; final String sharedValue = "blue"; tx.makePropertyKey(propName).dataType(String.class).make(); TitanVertex alice = tx.addVertex(); TitanVertex bob = tx.addVertex(); alice.addProperty(propName, sharedValue); clopen(); alice = tx.getVertex(alice.getLongId()); bob = tx.getVertex(bob.getLongId()); assertEquals(sharedValue, alice.getProperty(propName)); assertEquals(null, bob.getProperty(propName)); alice.removeProperty(propName); bob.addProperty(propName, sharedValue); clopen(); }
/** * Very simple graph operation to ensure minimal functionality and cleanup */ @Test public void testBasic() { PropertyKey uid = makeVertexIndexedUniqueKey("name",String.class); finishSchema(); TitanVertex n1 = tx.addVertex(); uid = tx.getPropertyKey("name"); n1.addProperty(uid.getName(), "abcd"); clopen(); long nid = n1.getLongId(); uid = tx.getPropertyKey("name"); assertTrue(tx.containsVertex(nid)); assertTrue(tx.containsVertex(uid.getLongId())); assertFalse(tx.containsVertex(nid + 64)); uid = tx.getPropertyKey(uid.getName()); n1 = tx.getVertex(nid); assertEquals(n1,Iterables.getOnlyElement(tx.getVertices(uid, "abcd"))); assertEquals(1, Iterables.size(n1.query().relations())); assertTrue(n1.getProperty(uid).equals("abcd")); assertEquals(1,Iterables.size(tx.getVertices())); close(); TitanCleanup.clear(graph); open(config); assertTrue(Iterables.isEmpty(tx.getVertices())); }
assertEquals(1,v.query().labels("knows").direction(BOTH).has("$titanid",eid.getRelationId()).count()); assertEquals(0,v.query().labels("knows").direction(BOTH).has("$titanid",110111).count()); assertEquals(1,v.query().has("$adjacent",u.getLongId()).count()); assertEquals(1,v.query().has("$adjacent",(int)u.getLongId()).count()); try {