本文整理汇总了Java中com.thinkaurelius.titan.core.TitanVertex.id方法的典型用法代码示例。如果您正苦于以下问题:Java TitanVertex.id方法的具体用法?Java TitanVertex.id怎么用?Java TitanVertex.id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.thinkaurelius.titan.core.TitanVertex
的用法示例。
在下文中一共展示了TitanVertex.id方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testVertexTTLWithCompositeIndex
import com.thinkaurelius.titan.core.TitanVertex; //导入方法依赖的package包/类
@Test
public void testVertexTTLWithCompositeIndex() throws Exception {
if (!features.hasCellTTL()) {
return;
}
PropertyKey name = mgmt.makePropertyKey("name").dataType(String.class).make();
PropertyKey time = mgmt.makePropertyKey("time").dataType(Long.class).make();
TitanGraphIndex index1 = mgmt.buildIndex("index1", Vertex.class).addKey(name).buildCompositeIndex();
TitanGraphIndex index2 = mgmt.buildIndex("index2", Vertex.class).addKey(name).addKey(time).buildCompositeIndex();
VertexLabel label1 = mgmt.makeVertexLabel("event").setStatic().make();
mgmt.setTTL(label1, Duration.ofSeconds(1));
assertEquals(Duration.ZERO, mgmt.getTTL(name));
assertEquals(Duration.ZERO, mgmt.getTTL(time));
assertEquals(Duration.ofSeconds(1), mgmt.getTTL(label1));
mgmt.commit();
TitanVertex v1 = tx.addVertex(T.label, "event", "name", "some event", "time", System.currentTimeMillis());
tx.commit();
Object id = v1.id();
v1 = getV(graph, id);
assertNotNull(v1);
assertNotEmpty(graph.query().has("name", "some event").vertices());
Thread.sleep(1001);
graph.tx().rollback();
v1 = getV(graph, id);
assertNull(v1);
assertEmpty(graph.query().has("name", "some event").vertices());
}
示例2: testVertexTTLImplicitKey
import com.thinkaurelius.titan.core.TitanVertex; //导入方法依赖的package包/类
@Test
public void testVertexTTLImplicitKey() throws Exception {
Duration d;
if (!features.hasCellTTL()) {
return;
}
clopen(option(GraphDatabaseConfiguration.STORE_META_TTL, "edgestore"), true);
int ttl1 = 1;
VertexLabel label1 = mgmt.makeVertexLabel("event").setStatic().make();
mgmt.setTTL(label1, Duration.ofSeconds(ttl1));
assertEquals(Duration.ofSeconds(ttl1), mgmt.getTTL(label1));
mgmt.commit();
TitanVertex v1 = tx.addVertex("event");
TitanVertex v2 = tx.addVertex();
tx.commit();
/* TODO: this fails
d = v1.getProperty("~ttl");
assertEquals(1, d);
d = v2.getProperty("~ttl");
assertEquals(0, d);
*/
Object v1id = v1.id();
Object v2id = v2.id();
v1 = getV(graph, v1id);
v2 = getV(graph, v2id);
d = v1.value("~ttl");
assertEquals(Duration.ofSeconds(1), d);
d = v2.value("~ttl");
assertEquals(Duration.ZERO, d);
}
示例3: testPropertyTTLTiming
import com.thinkaurelius.titan.core.TitanVertex; //导入方法依赖的package包/类
@Category({BrittleTests.class})
@Test
public void testPropertyTTLTiming() throws Exception {
if (!features.hasCellTTL()) {
return;
}
PropertyKey name = mgmt.makePropertyKey("name").dataType(String.class).make();
PropertyKey place = mgmt.makePropertyKey("place").dataType(String.class).make();
mgmt.setTTL(name, Duration.ofSeconds(42));
mgmt.setTTL(place, Duration.ofSeconds(1));
TitanGraphIndex index1 = mgmt.buildIndex("index1", Vertex.class).addKey(name).buildCompositeIndex();
TitanGraphIndex index2 = mgmt.buildIndex("index2", Vertex.class).addKey(name).addKey(place).buildCompositeIndex();
VertexLabel label1 = mgmt.makeVertexLabel("event").setStatic().make();
mgmt.setTTL(label1, Duration.ofSeconds(2));
assertEquals(Duration.ofSeconds(42), mgmt.getTTL(name));
assertEquals(Duration.ofSeconds(1), mgmt.getTTL(place));
assertEquals(Duration.ofSeconds(2), mgmt.getTTL(label1));
mgmt.commit();
TitanVertex v1 = tx.addVertex(T.label, "event", "name", "some event", "place", "somewhere");
tx.commit();
Object id = v1.id();
v1 = getV(graph, id);
assertNotNull(v1);
assertNotEmpty(graph.query().has("name", "some event").has("place", "somewhere").vertices());
assertNotEmpty(graph.query().has("name", "some event").vertices());
Thread.sleep(1001);
graph.tx().rollback();
// short-lived property expires first
v1 = getV(graph, id);
assertNotNull(v1);
assertEmpty(graph.query().has("name", "some event").has("place", "somewhere").vertices());
assertNotEmpty(graph.query().has("name", "some event").vertices());
Thread.sleep(1001);
graph.tx().rollback();
// vertex expires before defined TTL of the long-lived property
assertEmpty(graph.query().has("name", "some event").has("place", "somewhere").vertices());
assertEmpty(graph.query().has("name", "some event").vertices());
v1 = getV(graph, id);
assertNull(v1);
}
示例4: testVertexTTLWithMixedIndices
import com.thinkaurelius.titan.core.TitanVertex; //导入方法依赖的package包/类
@Test
public void testVertexTTLWithMixedIndices() throws Exception {
if (!features.hasCellTTL() || !indexFeatures.supportsDocumentTTL()) {
return;
}
PropertyKey name = makeKey("name", String.class);
PropertyKey time = makeKey("time", Long.class);
PropertyKey text = makeKey("text", String.class);
VertexLabel event = mgmt.makeVertexLabel("event").setStatic().make();
final int eventTTLSeconds = (int) TestGraphConfigs.getTTL(TimeUnit.SECONDS);
mgmt.setTTL(event, Duration.ofSeconds(eventTTLSeconds));
mgmt.buildIndex("index1", Vertex.class).
addKey(name, getStringMapping()).addKey(time).buildMixedIndex(INDEX);
mgmt.buildIndex("index2", Vertex.class).indexOnly(event).
addKey(text, getTextMapping()).buildMixedIndex(INDEX);
assertEquals(Duration.ZERO, mgmt.getTTL(name));
assertEquals(Duration.ZERO, mgmt.getTTL(time));
assertEquals(Duration.ofSeconds(eventTTLSeconds), mgmt.getTTL(event));
finishSchema();
TitanVertex v1 = tx.addVertex("event");
v1.property(VertexProperty.Cardinality.single, "name", "first event");
v1.property(VertexProperty.Cardinality.single, "text", "this text will help to identify the first event");
long time1 = System.currentTimeMillis();
v1.property(VertexProperty.Cardinality.single, "time", time1);
TitanVertex v2 = tx.addVertex("event");
v2.property(VertexProperty.Cardinality.single, "name", "second event");
v2.property(VertexProperty.Cardinality.single, "text", "this text won't match");
long time2 = time1 + 1;
v2.property(VertexProperty.Cardinality.single, "time", time2);
evaluateQuery(tx.query().has("name", "first event").orderBy("time", decr),
ElementCategory.VERTEX, 1, new boolean[]{true, true}, tx.getPropertyKey("time"), Order.DESC, "index1");
evaluateQuery(tx.query().has("text", Text.CONTAINS, "help").has(LABEL_NAME, "event"),
ElementCategory.VERTEX, 1, new boolean[]{true, true}, "index2");
clopen();
Object v1Id = v1.id();
Object v2Id = v2.id();
evaluateQuery(tx.query().has("name", "first event").orderBy("time", decr),
ElementCategory.VERTEX, 1, new boolean[]{true, true}, tx.getPropertyKey("time"), Order.DESC, "index1");
evaluateQuery(tx.query().has("text", Text.CONTAINS, "help").has(LABEL_NAME, "event"),
ElementCategory.VERTEX, 1, new boolean[]{true, true}, "index2");
v1 = getV(tx, v1Id);
v2 = getV(tx, v1Id);
assertNotNull(v1);
assertNotNull(v2);
Thread.sleep(TimeUnit.MILLISECONDS.convert((long) Math.ceil(eventTTLSeconds * 1.25), TimeUnit.SECONDS));
clopen();
Thread.sleep(TimeUnit.MILLISECONDS.convert((long) Math.ceil(eventTTLSeconds * 1.25), TimeUnit.SECONDS));
evaluateQuery(tx.query().has("text", Text.CONTAINS, "help").has(LABEL_NAME, "event"),
ElementCategory.VERTEX, 0, new boolean[]{true, true}, "index2");
evaluateQuery(tx.query().has("name", "first event").orderBy("time", decr),
ElementCategory.VERTEX, 0, new boolean[]{true, true}, tx.getPropertyKey("time"), Order.DESC, "index1");
v1 = getV(tx, v1Id);
v2 = getV(tx, v2Id);
assertNull(v1);
assertNull(v2);
}
示例5: testNestedWrites
import com.thinkaurelius.titan.core.TitanVertex; //导入方法依赖的package包/类
private void testNestedWrites(String initialValue, String updatedValue) throws BackendException {
// This method touches a single vertex with multiple transactions,
// leading to deadlock under BDB and cascading test failures. Check for
// the hasTxIsolation() store feature, which is currently true for BDB
// but false for HBase/Cassandra. This is kind of a hack; a more robust
// approach might implement different methods/assertions depending on
// whether the store is capable of deadlocking or detecting conflicting
// writes and aborting a transaction.
Backend b = null;
try {
b = graph.getConfiguration().getBackend();
if (b.getStoreFeatures().hasTxIsolation()) {
log.info("Skipping " + getClass().getSimpleName() + "." + methodName.getMethodName());
return;
}
} finally {
if (null != b)
b.close();
}
final String propName = "foo";
// Write schema and one vertex
PropertyKey prop = makeKey(propName, String.class);
createExternalVertexIndex(prop, INDEX);
finishSchema();
TitanVertex v = graph.addVertex();
if (null != initialValue)
v.property(VertexProperty.Cardinality.single, propName, initialValue);
graph.tx().commit();
Object id = v.id();
// Open two transactions and modify the same vertex
TitanTransaction vertexDeleter = graph.newTransaction();
TitanTransaction propDeleter = graph.newTransaction();
getV(vertexDeleter, id).remove();
if (null == updatedValue)
getV(propDeleter, id).property(propName).remove();
else
getV(propDeleter, id).property(VertexProperty.Cardinality.single, propName, updatedValue);
vertexDeleter.commit();
propDeleter.commit();
// The vertex must not exist after deletion
graph.tx().rollback();
assertEquals(null, getV(graph, id));
assertEmpty(graph.query().has(propName).vertices());
if (null != updatedValue)
assertEmpty(graph.query().has(propName, updatedValue).vertices());
graph.tx().rollback();
}