Search in sources :

Example 31 with TitanGraphIndex

use of com.thinkaurelius.titan.core.schema.TitanGraphIndex in project titan by thinkaurelius.

the class ManagementSystem method setTypeModifier.

private void setTypeModifier(final TitanSchemaElement element, final ModifierType modifierType, final Object value) {
    Preconditions.checkArgument(element != null, "null schema element");
    TypeDefinitionCategory cat = modifierType.getCategory();
    if (cat.hasDataType() && null != value) {
        Preconditions.checkArgument(cat.getDataType().equals(value.getClass()), "modifier value is not of expected type " + cat.getDataType());
    }
    TitanSchemaVertex typeVertex;
    if (element instanceof TitanSchemaVertex) {
        typeVertex = (TitanSchemaVertex) element;
    } else if (element instanceof TitanGraphIndex) {
        IndexType index = ((TitanGraphIndexWrapper) element).getBaseIndex();
        assert index instanceof IndexTypeWrapper;
        SchemaSource base = ((IndexTypeWrapper) index).getSchemaBase();
        typeVertex = (TitanSchemaVertex) base;
    } else
        throw new IllegalArgumentException("Invalid schema element: " + element);
    // remove any pre-existing value for the modifier, or return if an identical value has already been set
    for (TitanEdge e : typeVertex.getEdges(TypeDefinitionCategory.TYPE_MODIFIER, Direction.OUT)) {
        TitanSchemaVertex v = (TitanSchemaVertex) e.vertex(Direction.IN);
        TypeDefinitionMap def = v.getDefinition();
        Object existingValue = def.getValue(modifierType.getCategory());
        if (null != existingValue) {
            if (existingValue.equals(value)) {
                //Already has the right value, don't need to do anything
                return;
            } else {
                e.remove();
                v.remove();
            }
        }
    }
    if (null != value) {
        TypeDefinitionMap def = new TypeDefinitionMap();
        def.setValue(cat, value);
        TitanSchemaVertex cVertex = transaction.makeSchemaVertex(TitanSchemaCategory.TYPE_MODIFIER, null, def);
        addSchemaEdge(typeVertex, cVertex, TypeDefinitionCategory.TYPE_MODIFIER, null);
    }
    updateSchemaVertex(typeVertex);
    updatedTypes.add(typeVertex);
}
Also used : TypeDefinitionCategory(com.thinkaurelius.titan.graphdb.types.TypeDefinitionCategory) IndexTypeWrapper(com.thinkaurelius.titan.graphdb.types.indextype.IndexTypeWrapper) TitanSchemaVertex(com.thinkaurelius.titan.graphdb.types.vertices.TitanSchemaVertex) IndexType(com.thinkaurelius.titan.graphdb.types.IndexType) MixedIndexType(com.thinkaurelius.titan.graphdb.types.MixedIndexType) CompositeIndexType(com.thinkaurelius.titan.graphdb.types.CompositeIndexType) TitanGraphIndex(com.thinkaurelius.titan.core.schema.TitanGraphIndex) SchemaSource(com.thinkaurelius.titan.graphdb.types.SchemaSource) TypeDefinitionMap(com.thinkaurelius.titan.graphdb.types.TypeDefinitionMap) TitanEdge(com.thinkaurelius.titan.core.TitanEdge)

Aggregations

TitanGraphIndex (com.thinkaurelius.titan.core.schema.TitanGraphIndex)31 PropertyKey (com.thinkaurelius.titan.core.PropertyKey)20 Test (org.junit.Test)16 TitanVertex (com.thinkaurelius.titan.core.TitanVertex)13 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)10 VertexLabel (com.thinkaurelius.titan.core.VertexLabel)8 RelationTypeIndex (com.thinkaurelius.titan.core.schema.RelationTypeIndex)7 TitanManagement (com.thinkaurelius.titan.core.schema.TitanManagement)7 BaseVertexLabel (com.thinkaurelius.titan.graphdb.types.system.BaseVertexLabel)6 EdgeLabel (com.thinkaurelius.titan.core.EdgeLabel)5 CompositeIndexType (com.thinkaurelius.titan.graphdb.types.CompositeIndexType)4 TitanSchemaVertex (com.thinkaurelius.titan.graphdb.types.vertices.TitanSchemaVertex)4 TitanTransaction (com.thinkaurelius.titan.core.TitanTransaction)3 ScanMetrics (com.thinkaurelius.titan.diskstorage.keycolumnvalue.scan.ScanMetrics)3 IndexType (com.thinkaurelius.titan.graphdb.types.IndexType)3 MixedIndexType (com.thinkaurelius.titan.graphdb.types.MixedIndexType)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 RelationType (com.thinkaurelius.titan.core.RelationType)2 TitanEdge (com.thinkaurelius.titan.core.TitanEdge)2 TitanException (com.thinkaurelius.titan.core.TitanException)2