Search in sources :

Example 1 with TypeDefinitionDescription

use of org.janusgraph.graphdb.types.TypeDefinitionDescription in project janusgraph by JanusGraph.

the class ManagementSystem method addSchemaEdge.

private JanusGraphEdge addSchemaEdge(JanusGraphVertex out, JanusGraphVertex in, TypeDefinitionCategory def, Object modifier) {
    assert def.isEdge();
    JanusGraphEdge edge = transaction.addEdge(out, in, BaseLabel.SchemaDefinitionEdge);
    TypeDefinitionDescription desc = new TypeDefinitionDescription(def, modifier);
    edge.property(BaseKey.SchemaDefinitionDesc.name(), desc);
    return edge;
}
Also used : JanusGraphEdge(org.janusgraph.core.JanusGraphEdge) TypeDefinitionDescription(org.janusgraph.graphdb.types.TypeDefinitionDescription)

Example 2 with TypeDefinitionDescription

use of org.janusgraph.graphdb.types.TypeDefinitionDescription in project janusgraph by JanusGraph.

the class ManagementSystem method updateConnectionEdgeConstraints.

private void updateConnectionEdgeConstraints(JanusGraphSchemaVertex edgeLabel, String oldName, String newName) {
    if (!(edgeLabel instanceof EdgeLabel))
        return;
    ((EdgeLabel) edgeLabel).mappedConnections().stream().peek(s -> schemaCache.expireSchemaElement(s.getOutgoingVertexLabel().longId())).map(Connection::getConnectionEdge).forEach(edge -> {
        TypeDefinitionDescription desc = new TypeDefinitionDescription(TypeDefinitionCategory.CONNECTION_EDGE, newName);
        edge.property(BaseKey.SchemaDefinitionDesc.name(), desc);
    });
}
Also used : TypeDefinitionDescription(org.janusgraph.graphdb.types.TypeDefinitionDescription) EdgeLabel(org.janusgraph.core.EdgeLabel)

Example 3 with TypeDefinitionDescription

use of org.janusgraph.graphdb.types.TypeDefinitionDescription in project janusgraph by JanusGraph.

the class JanusGraphSchemaVertex method getDefinition.

@Override
public TypeDefinitionMap getDefinition() {
    TypeDefinitionMap def = definition;
    if (def == null) {
        def = new TypeDefinitionMap();
        Iterable<JanusGraphVertexProperty> ps;
        if (isLoaded()) {
            StandardJanusGraphTx tx = tx();
            ps = (Iterable) RelationConstructor.readRelation(this, tx.getGraph().getSchemaCache().getSchemaRelations(longId(), BaseKey.SchemaDefinitionProperty, Direction.OUT), tx);
        } else {
            ps = query().type(BaseKey.SchemaDefinitionProperty).properties();
        }
        for (JanusGraphVertexProperty property : ps) {
            TypeDefinitionDescription desc = property.valueOrNull(BaseKey.SchemaDefinitionDesc);
            Preconditions.checkArgument(desc != null && desc.getCategory().isProperty());
            def.setValue(desc.getCategory(), property.value());
        }
        assert def.size() > 0;
        definition = def;
    }
    assert def != null;
    return def;
}
Also used : StandardJanusGraphTx(org.janusgraph.graphdb.transaction.StandardJanusGraphTx) TypeDefinitionDescription(org.janusgraph.graphdb.types.TypeDefinitionDescription) TypeDefinitionMap(org.janusgraph.graphdb.types.TypeDefinitionMap) JanusGraphVertexProperty(org.janusgraph.core.JanusGraphVertexProperty)

Example 4 with TypeDefinitionDescription

use of org.janusgraph.graphdb.types.TypeDefinitionDescription in project janusgraph by JanusGraph.

the class ManagementSystem method setStatusEdges.

private void setStatusEdges(JanusGraphSchemaVertex vertex, SchemaStatus status, Set<PropertyKeyVertex> keys) {
    Preconditions.checkArgument(vertex.asIndexType().isMixedIndex());
    for (JanusGraphEdge 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 : JanusGraphEdge(org.janusgraph.core.JanusGraphEdge) TypeDefinitionDescription(org.janusgraph.graphdb.types.TypeDefinitionDescription) Parameter(org.janusgraph.core.schema.Parameter) PropertyKeyVertex(org.janusgraph.graphdb.types.vertices.PropertyKeyVertex)

Example 5 with TypeDefinitionDescription

use of org.janusgraph.graphdb.types.TypeDefinitionDescription in project janusgraph by JanusGraph.

the class ManagementSystem method setStatusVertex.

private void setStatusVertex(JanusGraphSchemaVertex vertex, SchemaStatus status) {
    Preconditions.checkArgument(vertex instanceof RelationTypeVertex || vertex.asIndexType().isCompositeIndex());
    // Delete current status
    for (JanusGraphVertexProperty p : vertex.query().types(BaseKey.SchemaDefinitionProperty).properties()) {
        if (p.<TypeDefinitionDescription>valueOrNull(BaseKey.SchemaDefinitionDesc).getCategory() == TypeDefinitionCategory.STATUS) {
            if (p.value().equals(status))
                return;
            else
                p.remove();
        }
    }
    // Add new status
    JanusGraphVertexProperty p = transaction.addProperty(vertex, BaseKey.SchemaDefinitionProperty, status);
    p.property(BaseKey.SchemaDefinitionDesc.name(), TypeDefinitionDescription.of(TypeDefinitionCategory.STATUS));
}
Also used : TypeDefinitionDescription(org.janusgraph.graphdb.types.TypeDefinitionDescription) JanusGraphVertexProperty(org.janusgraph.core.JanusGraphVertexProperty) RelationTypeVertex(org.janusgraph.graphdb.types.vertices.RelationTypeVertex)

Aggregations

TypeDefinitionDescription (org.janusgraph.graphdb.types.TypeDefinitionDescription)8 JanusGraphEdge (org.janusgraph.core.JanusGraphEdge)4 JanusGraphVertexProperty (org.janusgraph.core.JanusGraphVertexProperty)2 StandardJanusGraphTx (org.janusgraph.graphdb.transaction.StandardJanusGraphTx)2 TypeDefinitionCategory (org.janusgraph.graphdb.types.TypeDefinitionCategory)2 ImmutableListMultimap (com.google.common.collect.ImmutableListMultimap)1 EdgeLabel (org.janusgraph.core.EdgeLabel)1 JanusGraphVertex (org.janusgraph.core.JanusGraphVertex)1 Parameter (org.janusgraph.core.schema.Parameter)1 TypeDefinitionMap (org.janusgraph.graphdb.types.TypeDefinitionMap)1 PropertyKeyVertex (org.janusgraph.graphdb.types.vertices.PropertyKeyVertex)1 RelationTypeVertex (org.janusgraph.graphdb.types.vertices.RelationTypeVertex)1