本文整理汇总了Java中com.thinkaurelius.titan.core.TitanGraph.newTransaction方法的典型用法代码示例。如果您正苦于以下问题:Java TitanGraph.newTransaction方法的具体用法?Java TitanGraph.newTransaction怎么用?Java TitanGraph.newTransaction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.thinkaurelius.titan.core.TitanGraph
的用法示例。
在下文中一共展示了TitanGraph.newTransaction方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: codeSnippets
import com.thinkaurelius.titan.core.TitanGraph; //导入方法依赖的package包/类
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();
}
示例2: generateData
import com.thinkaurelius.titan.core.TitanGraph; //导入方法依赖的package包/类
/**
* Generate a scale-free graph using parameters specified in the
* {@link Schema} object provided to this instance's constructor. The types
* must already exist. The types can be created by either calling
* {@link #generateTypesAndData(TitanGraph)} instead of this method or by
* calling {@link Schema#makeTypes(TitanGraph)} before calling this method.
*
* @param g A graph with types predefined. If it already contains vertices
* or relations, they may be overwritten.
*/
public void generateData(TitanGraph g) {
// Generate vertices
for (long i = uidCounter; i < schema.getVertexCount() + INITIAL_VERTEX_UID - 1; i++) {
Vertex v = g.addVertex(i);
// DistributionGenerator doesn't currently support VertexAnnotator
vertexAnnotator.annotate(v, null);
}
// Generate edges
for (int i = 0; i < schema.getEdgeLabels(); i++) {
DistributionGenerator gen = new DistributionGenerator(schema.getEdgeLabelName(i), edgeAnnotator);
gen.setOutDistribution(new PowerLawDistribution(GAMMA));
gen.setInDistribution(new PowerLawDistribution(GAMMA));
gen.generate(g, schema.getEdgeCount());
}
g.commit();
TitanTransaction tx = g.newTransaction();
// Add a vertex that has an out edge to every other vertex
Vertex hiOutDeg = tx.addVertex(Schema.SUPERNODE_UID);
String label = schema.getSupernodeOutLabel();
PropertyKey uidKey = tx.getPropertyKey(Schema.UID_PROP);
hiOutDeg.setProperty(Schema.UID_PROP, Schema.SUPERNODE_UID);
String pKey = schema.getSortKeyForLabel(label);
for (long i = INITIAL_VERTEX_UID; i < schema.getVertexCount(); i++) {
Vertex in = Iterables.getOnlyElement(tx.getVertices(uidKey, i));
Edge e = hiOutDeg.addEdge(label, in);
e.setProperty(pKey, (int) i);
}
tx.commit();
}
示例3: testLists
import com.thinkaurelius.titan.core.TitanGraph; //导入方法依赖的package包/类
@Test
public void testLists() {
int num = 13;
TitanGraph g = TitanFactory.open("inmemory");
StandardTitanTx tx = (StandardTitanTx) g.newTransaction();
VertexLongList vll = new VertexLongList(tx);
VertexArrayList val = new VertexArrayList(tx);
for (int i=0; i<num; i++) {
TitanVertex v = tx.addVertex();
vll.add(v);
val.add(v);
}
assertEquals(num, Iterables.size(vll));
assertEquals(num, Iterables.size(val));
vll.sort();
val.sort();
assertTrue(vll.isSorted());
assertTrue(val.isSorted());
for (Iterable<TitanVertex> iterable : new Iterable[]{val,vll}) {
Iterator<TitanVertex> iter = iterable.iterator();
TitanVertex previous = null;
for (int i = 0; i < num; i++) {
TitanVertex next = iter.next();
if (previous!=null) assertTrue(previous.longId()<next.longId());
previous = next;
}
try {
iter.next();
fail();
} catch (NoSuchElementException ex) {
}
}
tx.commit();
g.close();
}
示例4: testLists
import com.thinkaurelius.titan.core.TitanGraph; //导入方法依赖的package包/类
@Test
public void testLists() {
int num = 13;
TitanGraph g = TitanFactory.open("inmemory");
StandardTitanTx tx = (StandardTitanTx) g.newTransaction();
VertexLongList vll = new VertexLongList(tx);
VertexArrayList val = new VertexArrayList(tx);
for (int i=0; i<num; i++) {
TitanVertex v = tx.addVertex();
vll.add(v);
val.add(v);
}
assertEquals(num, Iterables.size(vll));
assertEquals(num, Iterables.size(val));
vll.sort();
val.sort();
assertTrue(vll.isSorted());
assertTrue(val.isSorted());
for (Iterable<TitanVertex> iterable : new Iterable[]{val,vll}) {
Iterator<TitanVertex> iter = iterable.iterator();
TitanVertex previous = null;
for (int i = 0; i < num; i++) {
TitanVertex next = iter.next();
if (previous!=null) assertTrue(previous.getLongId()<next.getLongId());
previous = next;
}
try {
iter.next();
fail();
} catch (NoSuchElementException ex) {
}
}
tx.commit();
g.shutdown();
}