Search in sources :

Example 1 with TypeDefinitionMap

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

the class JanusGraphHadoopSetupImpl method getTypeInspector.

@Override
public TypeInspector getTypeInspector() {
    // Pre-load schema
    for (JanusGraphSchemaCategory sc : JanusGraphSchemaCategory.values()) {
        for (JanusGraphVertex k : QueryUtil.getVertices(tx, BaseKey.SchemaCategory, sc)) {
            assert k instanceof JanusGraphSchemaVertex;
            JanusGraphSchemaVertex s = (JanusGraphSchemaVertex) k;
            if (sc.hasName()) {
                String name = s.name();
                Preconditions.checkNotNull(name);
            }
            TypeDefinitionMap dm = s.getDefinition();
            Preconditions.checkNotNull(dm);
            s.getRelated(TypeDefinitionCategory.TYPE_MODIFIER, Direction.OUT);
            s.getRelated(TypeDefinitionCategory.TYPE_MODIFIER, Direction.IN);
        }
    }
    return tx;
}
Also used : JanusGraphVertex(org.janusgraph.core.JanusGraphVertex) JanusGraphSchemaVertex(org.janusgraph.graphdb.types.vertices.JanusGraphSchemaVertex) JanusGraphSchemaCategory(org.janusgraph.graphdb.internal.JanusGraphSchemaCategory) TypeDefinitionMap(org.janusgraph.graphdb.types.TypeDefinitionMap)

Example 2 with TypeDefinitionMap

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

the class ManagementSystem method setTypeModifier.

private void setTypeModifier(final JanusGraphSchemaElement 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());
    }
    JanusGraphSchemaVertex typeVertex;
    if (element instanceof JanusGraphSchemaVertex) {
        typeVertex = (JanusGraphSchemaVertex) element;
    } else if (element instanceof JanusGraphIndex) {
        IndexType index = ((JanusGraphIndexWrapper) element).getBaseIndex();
        assert index instanceof IndexTypeWrapper;
        SchemaSource base = ((IndexTypeWrapper) index).getSchemaBase();
        typeVertex = (JanusGraphSchemaVertex) 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 (JanusGraphEdge e : typeVertex.getEdges(TypeDefinitionCategory.TYPE_MODIFIER, Direction.OUT)) {
        JanusGraphSchemaVertex v = (JanusGraphSchemaVertex) 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);
        JanusGraphSchemaVertex cVertex = transaction.makeSchemaVertex(JanusGraphSchemaCategory.TYPE_MODIFIER, null, def);
        addSchemaEdge(typeVertex, cVertex, TypeDefinitionCategory.TYPE_MODIFIER, null);
    }
    updateSchemaVertex(typeVertex);
    updatedTypes.add(typeVertex);
}
Also used : TypeDefinitionCategory(org.janusgraph.graphdb.types.TypeDefinitionCategory) IndexTypeWrapper(org.janusgraph.graphdb.types.indextype.IndexTypeWrapper) JanusGraphEdge(org.janusgraph.core.JanusGraphEdge) JanusGraphSchemaVertex(org.janusgraph.graphdb.types.vertices.JanusGraphSchemaVertex) JanusGraphIndex(org.janusgraph.core.schema.JanusGraphIndex) IndexType(org.janusgraph.graphdb.types.IndexType) CompositeIndexType(org.janusgraph.graphdb.types.CompositeIndexType) MixedIndexType(org.janusgraph.graphdb.types.MixedIndexType) SchemaSource(org.janusgraph.graphdb.types.SchemaSource) TypeDefinitionMap(org.janusgraph.graphdb.types.TypeDefinitionMap)

Example 3 with TypeDefinitionMap

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

the class ManagementSystem method createMixedIndex.

private JanusGraphIndex createMixedIndex(String indexName, ElementCategory elementCategory, JanusGraphSchemaType constraint, String backingIndex) {
    Preconditions.checkArgument(graph.getIndexSerializer().containsIndex(backingIndex), "Unknown external index backend: %s", backingIndex);
    checkIndexName(indexName);
    TypeDefinitionMap def = new TypeDefinitionMap();
    def.setValue(TypeDefinitionCategory.INTERNAL_INDEX, false);
    def.setValue(TypeDefinitionCategory.ELEMENT_CATEGORY, elementCategory);
    def.setValue(TypeDefinitionCategory.BACKING_INDEX, backingIndex);
    def.setValue(TypeDefinitionCategory.INDEXSTORE_NAME, indexName);
    def.setValue(TypeDefinitionCategory.INDEX_CARDINALITY, Cardinality.LIST);
    def.setValue(TypeDefinitionCategory.STATUS, SchemaStatus.ENABLED);
    JanusGraphSchemaVertex indexVertex = transaction.makeSchemaVertex(JanusGraphSchemaCategory.GRAPHINDEX, indexName, def);
    Preconditions.checkArgument(constraint == null || (elementCategory.isValidConstraint(constraint) && constraint instanceof JanusGraphSchemaVertex));
    if (constraint != null) {
        addSchemaEdge(indexVertex, (JanusGraphSchemaVertex) constraint, TypeDefinitionCategory.INDEX_SCHEMA_CONSTRAINT, null);
    }
    updateSchemaVertex(indexVertex);
    return new JanusGraphIndexWrapper(indexVertex.asIndexType());
}
Also used : JanusGraphSchemaVertex(org.janusgraph.graphdb.types.vertices.JanusGraphSchemaVertex) TypeDefinitionMap(org.janusgraph.graphdb.types.TypeDefinitionMap)

Example 4 with TypeDefinitionMap

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

the class ManagementSystem method createCompositeIndex.

private JanusGraphIndex createCompositeIndex(String indexName, ElementCategory elementCategory, boolean unique, JanusGraphSchemaType constraint, PropertyKey... keys) {
    checkIndexName(indexName);
    Preconditions.checkArgument(keys != null && keys.length > 0, "Need to provide keys to index [%s]", indexName);
    Preconditions.checkArgument(!unique || elementCategory == ElementCategory.VERTEX, "Unique indexes can only be created on vertices [%s]", indexName);
    boolean allSingleKeys = true;
    boolean oneNewKey = false;
    for (PropertyKey key : keys) {
        Preconditions.checkArgument(key != null && key instanceof PropertyKeyVertex, "Need to provide valid keys: %s", key);
        if (key.cardinality() != Cardinality.SINGLE)
            allSingleKeys = false;
        if (key.isNew())
            oneNewKey = true;
        else
            updatedTypes.add((PropertyKeyVertex) key);
    }
    Cardinality indexCardinality;
    if (unique)
        indexCardinality = Cardinality.SINGLE;
    else
        indexCardinality = (allSingleKeys ? Cardinality.SET : Cardinality.LIST);
    TypeDefinitionMap def = new TypeDefinitionMap();
    def.setValue(TypeDefinitionCategory.INTERNAL_INDEX, true);
    def.setValue(TypeDefinitionCategory.ELEMENT_CATEGORY, elementCategory);
    def.setValue(TypeDefinitionCategory.BACKING_INDEX, Token.INTERNAL_INDEX_NAME);
    def.setValue(TypeDefinitionCategory.INDEXSTORE_NAME, indexName);
    def.setValue(TypeDefinitionCategory.INDEX_CARDINALITY, indexCardinality);
    def.setValue(TypeDefinitionCategory.STATUS, oneNewKey ? SchemaStatus.ENABLED : SchemaStatus.INSTALLED);
    JanusGraphSchemaVertex indexVertex = transaction.makeSchemaVertex(JanusGraphSchemaCategory.GRAPHINDEX, indexName, def);
    for (int i = 0; i < keys.length; i++) {
        Parameter[] paras = { ParameterType.INDEX_POSITION.getParameter(i) };
        addSchemaEdge(indexVertex, keys[i], TypeDefinitionCategory.INDEX_FIELD, paras);
    }
    Preconditions.checkArgument(constraint == null || (elementCategory.isValidConstraint(constraint) && constraint instanceof JanusGraphSchemaVertex));
    if (constraint != null) {
        addSchemaEdge(indexVertex, (JanusGraphSchemaVertex) constraint, TypeDefinitionCategory.INDEX_SCHEMA_CONSTRAINT, null);
    }
    updateSchemaVertex(indexVertex);
    JanusGraphIndexWrapper index = new JanusGraphIndexWrapper(indexVertex.asIndexType());
    if (!oneNewKey)
        updateIndex(index, SchemaAction.REGISTER_INDEX);
    return index;
}
Also used : Cardinality(org.janusgraph.core.Cardinality) JanusGraphSchemaVertex(org.janusgraph.graphdb.types.vertices.JanusGraphSchemaVertex) Parameter(org.janusgraph.core.schema.Parameter) PropertyKeyVertex(org.janusgraph.graphdb.types.vertices.PropertyKeyVertex) TypeDefinitionMap(org.janusgraph.graphdb.types.TypeDefinitionMap) PropertyKey(org.janusgraph.core.PropertyKey)

Aggregations

TypeDefinitionMap (org.janusgraph.graphdb.types.TypeDefinitionMap)4 JanusGraphSchemaVertex (org.janusgraph.graphdb.types.vertices.JanusGraphSchemaVertex)4 Cardinality (org.janusgraph.core.Cardinality)1 JanusGraphEdge (org.janusgraph.core.JanusGraphEdge)1 JanusGraphVertex (org.janusgraph.core.JanusGraphVertex)1 PropertyKey (org.janusgraph.core.PropertyKey)1 JanusGraphIndex (org.janusgraph.core.schema.JanusGraphIndex)1 Parameter (org.janusgraph.core.schema.Parameter)1 JanusGraphSchemaCategory (org.janusgraph.graphdb.internal.JanusGraphSchemaCategory)1 CompositeIndexType (org.janusgraph.graphdb.types.CompositeIndexType)1 IndexType (org.janusgraph.graphdb.types.IndexType)1 MixedIndexType (org.janusgraph.graphdb.types.MixedIndexType)1 SchemaSource (org.janusgraph.graphdb.types.SchemaSource)1 TypeDefinitionCategory (org.janusgraph.graphdb.types.TypeDefinitionCategory)1 IndexTypeWrapper (org.janusgraph.graphdb.types.indextype.IndexTypeWrapper)1 PropertyKeyVertex (org.janusgraph.graphdb.types.vertices.PropertyKeyVertex)1