Search in sources :

Example 1 with TypeDefinitionCategory

use of org.janusgraph.graphdb.types.TypeDefinitionCategory 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 2 with TypeDefinitionCategory

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

the class TypeDefinitionDescriptionSerializer method read.

@Override
public TypeDefinitionDescription read(ScanBuffer buffer) {
    TypeDefinitionCategory defCategory = serializer.readObjectNotNull(buffer, TypeDefinitionCategory.class);
    Object modifier = serializer.readClassAndObject(buffer);
    return new TypeDefinitionDescription(defCategory, modifier);
}
Also used : TypeDefinitionCategory(org.janusgraph.graphdb.types.TypeDefinitionCategory) TypeDefinitionDescription(org.janusgraph.graphdb.types.TypeDefinitionDescription)

Aggregations

TypeDefinitionCategory (org.janusgraph.graphdb.types.TypeDefinitionCategory)2 JanusGraphEdge (org.janusgraph.core.JanusGraphEdge)1 JanusGraphIndex (org.janusgraph.core.schema.JanusGraphIndex)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 TypeDefinitionDescription (org.janusgraph.graphdb.types.TypeDefinitionDescription)1 TypeDefinitionMap (org.janusgraph.graphdb.types.TypeDefinitionMap)1 IndexTypeWrapper (org.janusgraph.graphdb.types.indextype.IndexTypeWrapper)1 JanusGraphSchemaVertex (org.janusgraph.graphdb.types.vertices.JanusGraphSchemaVertex)1