Search in sources :

Example 6 with RelationType

use of com.thinkaurelius.titan.core.RelationType in project titan by thinkaurelius.

the class RelationIdentifier method findRelation.

TitanRelation findRelation(TitanTransaction tx) {
    TitanVertex v = ((StandardTitanTx) tx).getInternalVertex(outVertexId);
    if (v == null || v.isRemoved())
        return null;
    TitanVertex typeVertex = tx.getVertex(typeId);
    if (typeVertex == null)
        return null;
    if (!(typeVertex instanceof RelationType))
        throw new IllegalArgumentException("Invalid RelationIdentifier: typeID does not reference a type");
    RelationType type = (RelationType) typeVertex;
    Iterable<? extends TitanRelation> rels;
    if (((RelationType) typeVertex).isEdgeLabel()) {
        Direction dir = Direction.OUT;
        TitanVertex other = ((StandardTitanTx) tx).getInternalVertex(inVertexId);
        if (other == null || other.isRemoved())
            return null;
        if (((StandardTitanTx) tx).isPartitionedVertex(v) && !((StandardTitanTx) tx).isPartitionedVertex(other)) {
            //Swap for likely better performance
            TitanVertex tmp = other;
            other = v;
            v = tmp;
            dir = Direction.IN;
        }
        rels = ((VertexCentricQueryBuilder) v.query()).noPartitionRestriction().types((EdgeLabel) type).direction(dir).adjacent(other).edges();
    } else {
        rels = ((VertexCentricQueryBuilder) v.query()).noPartitionRestriction().types((PropertyKey) type).properties();
    }
    for (TitanRelation r : rels) {
        //Find current or previous relation
        if (r.longId() == relationId || ((r instanceof StandardRelation) && ((StandardRelation) r).getPreviousID() == relationId))
            return r;
    }
    return null;
}
Also used : TitanVertex(com.thinkaurelius.titan.core.TitanVertex) RelationType(com.thinkaurelius.titan.core.RelationType) StandardTitanTx(com.thinkaurelius.titan.graphdb.transaction.StandardTitanTx) Direction(org.apache.tinkerpop.gremlin.structure.Direction) TitanRelation(com.thinkaurelius.titan.core.TitanRelation)

Example 7 with RelationType

use of com.thinkaurelius.titan.core.RelationType in project titan by thinkaurelius.

the class AbstractIndexManagementIT method testRemoveRelationIndex.

@Test
public void testRemoveRelationIndex() throws InterruptedException, BackendException, ExecutionException {
    tx.commit();
    mgmt.commit();
    // Load the "Graph of the Gods" sample data
    GraphOfTheGodsFactory.loadWithoutMixedIndex(graph, true);
    // Disable the "battlesByTime" index
    TitanManagement m = graph.openManagement();
    RelationType battled = m.getRelationType("battled");
    RelationTypeIndex battlesByTime = m.getRelationIndex(battled, "battlesByTime");
    m.updateIndex(battlesByTime, SchemaAction.DISABLE_INDEX);
    m.commit();
    graph.tx().commit();
    // Block until the SchemaStatus transitions to DISABLED
    assertTrue(ManagementSystem.awaitRelationIndexStatus(graph, "battlesByTime", "battled").status(SchemaStatus.DISABLED).call().getSucceeded());
    // Remove index
    MapReduceIndexManagement mri = new MapReduceIndexManagement(graph);
    m = graph.openManagement();
    battled = m.getRelationType("battled");
    battlesByTime = m.getRelationIndex(battled, "battlesByTime");
    ScanMetrics metrics = mri.updateIndex(battlesByTime, SchemaAction.REMOVE_INDEX).get();
    assertEquals(6, metrics.getCustom(IndexRemoveJob.DELETED_RECORDS_COUNT));
}
Also used : RelationType(com.thinkaurelius.titan.core.RelationType) ScanMetrics(com.thinkaurelius.titan.diskstorage.keycolumnvalue.scan.ScanMetrics) TitanManagement(com.thinkaurelius.titan.core.schema.TitanManagement) RelationTypeIndex(com.thinkaurelius.titan.core.schema.RelationTypeIndex) Test(org.junit.Test) TitanGraphBaseTest(com.thinkaurelius.titan.graphdb.TitanGraphBaseTest)

Aggregations

RelationType (com.thinkaurelius.titan.core.RelationType)7 InternalRelationType (com.thinkaurelius.titan.graphdb.internal.InternalRelationType)5 StandardTitanTx (com.thinkaurelius.titan.graphdb.transaction.StandardTitanTx)3 RelationTypeIndex (com.thinkaurelius.titan.core.schema.RelationTypeIndex)2 TitanGraphIndex (com.thinkaurelius.titan.core.schema.TitanGraphIndex)2 MixedIndexType (com.thinkaurelius.titan.graphdb.types.MixedIndexType)2 TitanSchemaVertex (com.thinkaurelius.titan.graphdb.types.vertices.TitanSchemaVertex)2 EdgeLabel (com.thinkaurelius.titan.core.EdgeLabel)1 PropertyKey (com.thinkaurelius.titan.core.PropertyKey)1 TitanElement (com.thinkaurelius.titan.core.TitanElement)1 TitanException (com.thinkaurelius.titan.core.TitanException)1 TitanRelation (com.thinkaurelius.titan.core.TitanRelation)1 TitanVertex (com.thinkaurelius.titan.core.TitanVertex)1 VertexLabel (com.thinkaurelius.titan.core.VertexLabel)1 TitanManagement (com.thinkaurelius.titan.core.schema.TitanManagement)1 IndexTransaction (com.thinkaurelius.titan.diskstorage.indexing.IndexTransaction)1 ScanMetrics (com.thinkaurelius.titan.diskstorage.keycolumnvalue.scan.ScanMetrics)1 TitanGraphBaseTest (com.thinkaurelius.titan.graphdb.TitanGraphBaseTest)1 TransactionLogHeader (com.thinkaurelius.titan.graphdb.database.log.TransactionLogHeader)1 InternalRelation (com.thinkaurelius.titan.graphdb.internal.InternalRelation)1