use of org.janusgraph.graphdb.types.SchemaSource 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 %s", 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);
}
use of org.janusgraph.graphdb.types.SchemaSource in project janusgraph by JanusGraph.
the class RelationTypeVertex method getKeyIndexes.
public Iterable<IndexType> getKeyIndexes() {
List<IndexType> result = indexes;
if (result == null) {
ImmutableList.Builder<IndexType> b = ImmutableList.builder();
for (Entry entry : getRelated(TypeDefinitionCategory.INDEX_FIELD, Direction.IN)) {
SchemaSource index = entry.getSchemaType();
b.add(index.asIndexType());
}
result = b.build();
indexes = result;
}
assert result != null;
return result;
}
Aggregations