Search in sources :

Example 11 with StandardJanusGraphTx

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();
}
Also used : StandardJanusGraphTx(org.janusgraph.graphdb.transaction.StandardJanusGraphTx) WriteConfiguration(org.janusgraph.diskstorage.configuration.WriteConfiguration) Test(org.junit.Test)

Example 12 with StandardJanusGraphTx

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));
}
Also used : StandardJanusGraphTx(org.janusgraph.graphdb.transaction.StandardJanusGraphTx) WriteConfiguration(org.janusgraph.diskstorage.configuration.WriteConfiguration) Test(org.junit.Test)

Example 13 with StandardJanusGraphTx

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);
}
Also used : StandardJanusGraphTx(org.janusgraph.graphdb.transaction.StandardJanusGraphTx)

Example 14 with StandardJanusGraphTx

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);
}
Also used : JanusGraphEdge(org.janusgraph.core.JanusGraphEdge) StandardJanusGraphTx(org.janusgraph.graphdb.transaction.StandardJanusGraphTx) JanusGraphVertex(org.janusgraph.core.JanusGraphVertex)

Example 15 with StandardJanusGraphTx

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();
}
Also used : VertexLongList(org.janusgraph.graphdb.query.vertex.VertexLongList) VertexArrayList(org.janusgraph.graphdb.query.vertex.VertexArrayList) JanusGraph(org.janusgraph.core.JanusGraph) StandardJanusGraphTx(org.janusgraph.graphdb.transaction.StandardJanusGraphTx) JanusGraphVertex(org.janusgraph.core.JanusGraphVertex) NoSuchElementException(java.util.NoSuchElementException) Test(org.junit.Test)

Aggregations

StandardJanusGraphTx (org.janusgraph.graphdb.transaction.StandardJanusGraphTx)17 Test (org.junit.Test)4 JanusGraphVertex (org.janusgraph.core.JanusGraphVertex)3 RelationType (org.janusgraph.core.RelationType)3 WriteConfiguration (org.janusgraph.diskstorage.configuration.WriteConfiguration)3 InternalRelationType (org.janusgraph.graphdb.internal.InternalRelationType)3 Instant (java.time.Instant)2 Map (java.util.Map)2 ExecutionException (java.util.concurrent.ExecutionException)2 Direction (org.apache.tinkerpop.gremlin.structure.Direction)2 JanusGraphTransaction (org.janusgraph.core.JanusGraphTransaction)2 StandardJanusGraph (org.janusgraph.graphdb.database.StandardJanusGraph)2 Preconditions (com.google.common.base.Preconditions)1 Predicate (com.google.common.base.Predicate)1 Predicates (com.google.common.base.Predicates)1 com.google.common.cache (com.google.common.cache)1 com.google.common.collect (com.google.common.collect)1 IOException (java.io.IOException)1 Duration (java.time.Duration)1 Collections (java.util.Collections)1