use of org.janusgraph.graphdb.transaction.StandardJanusGraphTx in project janusgraph by JanusGraph.
the class CassandraGraphTest method testCustomConfigUsedByTx.
@Test
public void testCustomConfigUsedByTx() {
close();
WriteConfiguration wc = getConfiguration();
wc.set(ConfigElement.getPath(CASSANDRA_READ_CONSISTENCY), "ALL");
wc.set(ConfigElement.getPath(CASSANDRA_WRITE_CONSISTENCY), "ALL");
graph = (StandardJanusGraph) JanusGraphFactory.open(wc);
StandardJanusGraphTx tx = (StandardJanusGraphTx) graph.buildTransaction().customOption(ConfigElement.getPath(CASSANDRA_READ_CONSISTENCY), "ONE").customOption(ConfigElement.getPath(CASSANDRA_WRITE_CONSISTENCY), "TWO").start();
assertEquals("ONE", tx.getTxHandle().getBaseTransactionConfig().getCustomOptions().get(AbstractCassandraStoreManager.CASSANDRA_READ_CONSISTENCY));
assertEquals("TWO", tx.getTxHandle().getBaseTransactionConfig().getCustomOptions().get(AbstractCassandraStoreManager.CASSANDRA_WRITE_CONSISTENCY));
tx.rollback();
}
use of org.janusgraph.graphdb.transaction.StandardJanusGraphTx in project janusgraph by JanusGraph.
the class CassandraGraphTest method testGraphConfigUsedByThreadBoundTx.
@Test
public void testGraphConfigUsedByThreadBoundTx() {
close();
WriteConfiguration wc = getConfiguration();
wc.set(ConfigElement.getPath(CASSANDRA_READ_CONSISTENCY), "ALL");
wc.set(ConfigElement.getPath(CASSANDRA_WRITE_CONSISTENCY), "LOCAL_QUORUM");
graph = (StandardJanusGraph) JanusGraphFactory.open(wc);
StandardJanusGraphTx tx = (StandardJanusGraphTx) graph.getCurrentThreadTx();
assertEquals("ALL", tx.getTxHandle().getBaseTransactionConfig().getCustomOptions().get(AbstractCassandraStoreManager.CASSANDRA_READ_CONSISTENCY));
assertEquals("LOCAL_QUORUM", tx.getTxHandle().getBaseTransactionConfig().getCustomOptions().get(AbstractCassandraStoreManager.CASSANDRA_WRITE_CONSISTENCY));
}
use of org.janusgraph.graphdb.transaction.StandardJanusGraphTx in project janusgraph by JanusGraph.
the class JanusGraphSchemaVertex method name.
@Override
public String name() {
if (name == null) {
JanusGraphVertexProperty<String> p;
if (isLoaded()) {
StandardJanusGraphTx tx = tx();
p = (JanusGraphVertexProperty) Iterables.getOnlyElement(RelationConstructor.readRelation(this, tx.getGraph().getSchemaCache().getSchemaRelations(longId(), BaseKey.SchemaName, Direction.OUT), tx), null);
} else {
p = Iterables.getOnlyElement(query().type(BaseKey.SchemaName).properties(), null);
}
Preconditions.checkState(p != null, "Could not find type for id: %s", longId());
name = p.value();
}
assert name != null;
return JanusGraphSchemaCategory.getName(name);
}
use of org.janusgraph.graphdb.transaction.StandardJanusGraphTx in project janusgraph by JanusGraph.
the class JanusGraphSchemaVertex method getRelated.
@Override
public Iterable<Entry> getRelated(TypeDefinitionCategory def, Direction dir) {
assert dir == Direction.OUT || dir == Direction.IN;
ListMultimap<TypeDefinitionCategory, Entry> relations = dir == Direction.OUT ? outRelations : inRelations;
if (relations == null) {
ImmutableListMultimap.Builder<TypeDefinitionCategory, Entry> b = ImmutableListMultimap.builder();
Iterable<JanusGraphEdge> edges;
if (isLoaded()) {
StandardJanusGraphTx tx = tx();
edges = (Iterable) RelationConstructor.readRelation(this, tx.getGraph().getSchemaCache().getSchemaRelations(longId(), BaseLabel.SchemaDefinitionEdge, dir), tx);
} else {
edges = query().type(BaseLabel.SchemaDefinitionEdge).direction(dir).edges();
}
for (JanusGraphEdge edge : edges) {
JanusGraphVertex oth = edge.vertex(dir.opposite());
assert oth instanceof JanusGraphSchemaVertex;
TypeDefinitionDescription desc = edge.valueOrNull(BaseKey.SchemaDefinitionDesc);
Object modifier = null;
if (desc.getCategory().hasDataType()) {
assert desc.getModifier() != null && desc.getModifier().getClass().equals(desc.getCategory().getDataType());
modifier = desc.getModifier();
}
b.put(desc.getCategory(), new Entry((JanusGraphSchemaVertex) oth, modifier));
}
relations = b.build();
if (dir == Direction.OUT)
outRelations = relations;
else
inRelations = relations;
}
assert relations != null;
return relations.get(def);
}
use of org.janusgraph.graphdb.transaction.StandardJanusGraphTx in project janusgraph by JanusGraph.
the class VertexListTest method testLists.
@Test
public void testLists() {
int num = 13;
JanusGraph g = JanusGraphFactory.open("inmemory");
StandardJanusGraphTx tx = (StandardJanusGraphTx) g.newTransaction();
VertexLongList vll = new VertexLongList(tx);
VertexArrayList val = new VertexArrayList(tx);
for (int i = 0; i < num; i++) {
JanusGraphVertex 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<JanusGraphVertex> iterable : new Iterable[] { val, vll }) {
Iterator<JanusGraphVertex> iterator = iterable.iterator();
JanusGraphVertex previous = null;
for (int i = 0; i < num; i++) {
JanusGraphVertex next = iterator.next();
if (previous != null)
assertTrue(previous.longId() < next.longId());
previous = next;
}
try {
iterator.next();
fail();
} catch (NoSuchElementException ignored) {
}
}
tx.commit();
g.close();
}
Aggregations