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;
}
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);
}
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());
}
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;
}
Aggregations