Search in sources :

Example 11 with TitanEdge

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

the class AllEdgesIterator method findNext.

private Edge findNext() {
    TitanEdge rel = null;
    while (rel == null) {
        if (currentEdges.hasNext()) {
            rel = (TitanEdge) currentEdges.next();
            if (vertices != null && !vertices.contains(rel.vertex(Direction.IN)))
                rel = null;
        } else {
            if (vertexIter.hasNext()) {
                Vertex nextVertex = vertexIter.next();
                currentEdges = nextVertex.edges(Direction.OUT);
            } else
                break;
        }
    }
    return rel;
}
Also used : Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) TitanEdge(com.thinkaurelius.titan.core.TitanEdge)

Example 12 with TitanEdge

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

the class ManagementSystem method setStatusEdges.

private void setStatusEdges(TitanSchemaVertex vertex, SchemaStatus status, Set<PropertyKeyVertex> keys) {
    Preconditions.checkArgument(vertex.asIndexType().isMixedIndex());
    for (TitanEdge edge : vertex.getEdges(TypeDefinitionCategory.INDEX_FIELD, Direction.OUT)) {
        //Only address edges with matching keys
        if (!keys.contains(edge.vertex(Direction.IN)))
            continue;
        TypeDefinitionDescription desc = edge.valueOrNull(BaseKey.SchemaDefinitionDesc);
        assert desc.getCategory() == TypeDefinitionCategory.INDEX_FIELD;
        Parameter[] parameters = (Parameter[]) desc.getModifier();
        assert parameters[parameters.length - 1].key().equals(ParameterType.STATUS.getName());
        if (parameters[parameters.length - 1].value().equals(status))
            continue;
        Parameter[] paraCopy = Arrays.copyOf(parameters, parameters.length);
        paraCopy[parameters.length - 1] = ParameterType.STATUS.getParameter(status);
        edge.remove();
        addSchemaEdge(vertex, edge.vertex(Direction.IN), TypeDefinitionCategory.INDEX_FIELD, paraCopy);
    }
    for (PropertyKeyVertex prop : keys) prop.resetCache();
}
Also used : TypeDefinitionDescription(com.thinkaurelius.titan.graphdb.types.TypeDefinitionDescription) Parameter(com.thinkaurelius.titan.core.schema.Parameter) PropertyKeyVertex(com.thinkaurelius.titan.graphdb.types.vertices.PropertyKeyVertex) TitanEdge(com.thinkaurelius.titan.core.TitanEdge)

Example 13 with TitanEdge

use of com.thinkaurelius.titan.core.TitanEdge 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)

Example 14 with TitanEdge

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

the class EdgeSerializerTest method testValueOrdering.

@Test
public void testValueOrdering() {
    StandardTitanGraph graph = (StandardTitanGraph) StorageSetup.getInMemoryGraph();
    TitanManagement mgmt = graph.openManagement();
    EdgeLabel father = mgmt.makeEdgeLabel("father").multiplicity(Multiplicity.MANY2ONE).make();
    for (int i = 1; i <= 5; i++) mgmt.makePropertyKey("key" + i).dataType(Integer.class).make();
    mgmt.commit();
    TitanVertex v1 = graph.addVertex(), v2 = graph.addVertex();
    TitanEdge e1 = v1.addEdge("father", v2);
    for (int i = 1; i <= 5; i++) e1.property("key" + i, i);
    graph.tx().commit();
    e1.remove();
    graph.tx().commit();
}
Also used : TitanVertex(com.thinkaurelius.titan.core.TitanVertex) StandardTitanGraph(com.thinkaurelius.titan.graphdb.database.StandardTitanGraph) EdgeLabel(com.thinkaurelius.titan.core.EdgeLabel) TitanManagement(com.thinkaurelius.titan.core.schema.TitanManagement) TitanEdge(com.thinkaurelius.titan.core.TitanEdge) Test(org.junit.Test)

Aggregations

TitanEdge (com.thinkaurelius.titan.core.TitanEdge)14 TitanVertex (com.thinkaurelius.titan.core.TitanVertex)9 PropertyKey (com.thinkaurelius.titan.core.PropertyKey)8 Test (org.junit.Test)7 EdgeLabel (com.thinkaurelius.titan.core.EdgeLabel)5 TitanVertexProperty (com.thinkaurelius.titan.core.TitanVertexProperty)5 Edge (org.apache.tinkerpop.gremlin.structure.Edge)5 TitanTransaction (com.thinkaurelius.titan.core.TitanTransaction)4 VertexProperty (org.apache.tinkerpop.gremlin.structure.VertexProperty)4 VertexList (com.thinkaurelius.titan.core.VertexList)3 StandardEdgeLabelMaker (com.thinkaurelius.titan.graphdb.types.StandardEdgeLabelMaker)3 SchemaViolationException (com.thinkaurelius.titan.core.SchemaViolationException)2 TypeDefinitionDescription (com.thinkaurelius.titan.graphdb.types.TypeDefinitionDescription)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 ImmutableList (com.google.common.collect.ImmutableList)1 VertexLabel (com.thinkaurelius.titan.core.VertexLabel)1 Change (com.thinkaurelius.titan.core.log.Change)1 ChangeProcessor (com.thinkaurelius.titan.core.log.ChangeProcessor)1 ChangeState (com.thinkaurelius.titan.core.log.ChangeState)1 LogProcessorFramework (com.thinkaurelius.titan.core.log.LogProcessorFramework)1