Search in sources :

Example 1 with StandardEdge

use of com.thinkaurelius.titan.graphdb.relations.StandardEdge in project titan by thinkaurelius.

the class StandardTitanTx method addEdge.

public TitanEdge addEdge(TitanVertex outVertex, TitanVertex inVertex, EdgeLabel label) {
    verifyWriteAccess(outVertex, inVertex);
    outVertex = ((InternalVertex) outVertex).it();
    inVertex = ((InternalVertex) inVertex).it();
    Preconditions.checkNotNull(label);
    Multiplicity multiplicity = label.multiplicity();
    TransactionLock uniqueLock = getUniquenessLock(outVertex, (InternalRelationType) label, inVertex);
    uniqueLock.lock(LOCK_TIMEOUT);
    try {
        //Check uniqueness
        if (config.hasVerifyUniqueness()) {
            if (multiplicity == Multiplicity.SIMPLE) {
                if (!Iterables.isEmpty(query(outVertex).type(label).direction(Direction.OUT).adjacent(inVertex).edges()))
                    throw new SchemaViolationException("An edge with the given label already exists between the pair of vertices and the label [%s] is simple", label.name());
            }
            if (multiplicity.isUnique(Direction.OUT)) {
                if (!Iterables.isEmpty(query(outVertex).type(label).direction(Direction.OUT).edges()))
                    throw new SchemaViolationException("An edge with the given label already exists on the out-vertex and the label [%s] is out-unique", label.name());
            }
            if (multiplicity.isUnique(Direction.IN)) {
                if (!Iterables.isEmpty(query(inVertex).type(label).direction(Direction.IN).edges()))
                    throw new SchemaViolationException("An edge with the given label already exists on the in-vertex and the label [%s] is in-unique", label.name());
            }
        }
        StandardEdge edge = new StandardEdge(IDManager.getTemporaryRelationID(temporaryIds.nextID()), label, (InternalVertex) outVertex, (InternalVertex) inVertex, ElementLifeCycle.New);
        if (config.hasAssignIDsImmediately())
            graph.assignID(edge);
        connectRelation(edge);
        return edge;
    } finally {
        uniqueLock.unlock();
    }
}
Also used : StandardEdge(com.thinkaurelius.titan.graphdb.relations.StandardEdge)

Example 2 with StandardEdge

use of com.thinkaurelius.titan.graphdb.relations.StandardEdge in project titan by thinkaurelius.

the class TitanGraphPerformanceMemoryTest method elementCreationPerformance.

@Test
public void elementCreationPerformance() {
    TitanLabel connect = makeSimpleEdgeLabel("connect");
    int noNodes = 20000;
    TitanVertex[] nodes = new TitanVertex[noNodes];
    PerformanceTest p = new PerformanceTest(true);
    for (int i = 0; i < noNodes; i++) {
        nodes[i] = tx.addVertex();
    }
    p.end();
    System.out.println("Time per node in (ns): " + (p.getNanoTime() / noNodes));
    p = new PerformanceTest(true);
    for (int i = 0; i < noNodes; i++) {
        new StandardEdge(i + 1, connect, (InternalVertex) nodes[i], (InternalVertex) nodes[(i + 1) % noNodes], ElementLifeCycle.New);
    }
    p.end();
    System.out.println("Time per edge in (ns): " + (p.getNanoTime() / noNodes));
    p = new PerformanceTest(true);
    for (int i = 0; i < noNodes; i++) {
        nodes[i].addEdge(connect, nodes[(i + 1) % noNodes]);
    }
    p.end();
    System.out.println("Time per edge creation+connection in (ns): " + (p.getNanoTime() / noNodes));
    tx.rollback();
    tx = null;
}
Also used : TitanVertex(com.thinkaurelius.titan.core.TitanVertex) TitanLabel(com.thinkaurelius.titan.core.TitanLabel) PerformanceTest(com.thinkaurelius.titan.testutil.PerformanceTest) StandardEdge(com.thinkaurelius.titan.graphdb.relations.StandardEdge) Test(org.junit.Test) PerformanceTest(com.thinkaurelius.titan.testutil.PerformanceTest)

Example 3 with StandardEdge

use of com.thinkaurelius.titan.graphdb.relations.StandardEdge in project titan by thinkaurelius.

the class StandardTitanTx method addEdge.

@Override
public TitanEdge addEdge(TitanVertex outVertex, TitanVertex inVertex, TitanLabel label) {
    verifyWriteAccess(outVertex, inVertex);
    outVertex = ((InternalVertex) outVertex).it();
    inVertex = ((InternalVertex) inVertex).it();
    Preconditions.checkNotNull(label);
    Lock uniqueLock = FakeLock.INSTANCE;
    if (config.hasVerifyUniqueness() && (label.isUnique(Direction.OUT) || label.isUnique(Direction.IN)))
        uniqueLock = getUniquenessLock(outVertex, label, inVertex);
    uniqueLock.lock();
    try {
        // Check uniqueness
        if (config.hasVerifyUniqueness()) {
            if (label.isUnique(Direction.OUT)) {
                Preconditions.checkArgument(Iterables.isEmpty(query(outVertex).includeHidden().type(label).direction(Direction.OUT).titanEdges()), "An edge with the given type already exists on the out-vertex and the label [%s] is out-unique", label.getName());
            }
            if (label.isUnique(Direction.IN)) {
                Preconditions.checkArgument(Iterables.isEmpty(query(inVertex).includeHidden().type(label).direction(Direction.IN).titanEdges()), "An edge with the given type already exists on the in-vertex and the label [%s] is in-unique", label.getName());
            }
        }
        StandardEdge edge = new StandardEdge(temporaryID.decrementAndGet(), label, (InternalVertex) outVertex, (InternalVertex) inVertex, ElementLifeCycle.New);
        if (config.hasAssignIDsImmediately())
            graph.assignID(edge);
        connectRelation(edge);
        return edge;
    } finally {
        uniqueLock.unlock();
    }
}
Also used : StandardEdge(com.thinkaurelius.titan.graphdb.relations.StandardEdge) FakeLock(com.thinkaurelius.titan.graphdb.util.FakeLock) ReentrantLock(java.util.concurrent.locks.ReentrantLock) Lock(java.util.concurrent.locks.Lock)

Aggregations

StandardEdge (com.thinkaurelius.titan.graphdb.relations.StandardEdge)3 TitanLabel (com.thinkaurelius.titan.core.TitanLabel)1 TitanVertex (com.thinkaurelius.titan.core.TitanVertex)1 FakeLock (com.thinkaurelius.titan.graphdb.util.FakeLock)1 PerformanceTest (com.thinkaurelius.titan.testutil.PerformanceTest)1 Lock (java.util.concurrent.locks.Lock)1 ReentrantLock (java.util.concurrent.locks.ReentrantLock)1 Test (org.junit.Test)1