use of org.janusgraph.core.RelationType in project janusgraph by JanusGraph.
the class PredicateCondition method evaluate.
@Override
public boolean evaluate(E element) {
RelationType type;
if (key instanceof String) {
type = ((InternalElement) element).tx().getRelationType((String) key);
if (type == null)
return satisfiesCondition(null);
} else {
type = (RelationType) key;
}
Preconditions.checkNotNull(type);
if (type.isPropertyKey()) {
Iterator<Object> iterator = ElementHelper.getValues(element, (PropertyKey) type).iterator();
if (iterator.hasNext()) {
while (iterator.hasNext()) {
if (satisfiesCondition(iterator.next()))
return true;
}
return false;
}
return satisfiesCondition(null);
} else {
assert ((InternalRelationType) type).multiplicity().isUnique(Direction.OUT);
return satisfiesCondition(element.value(type.name()));
}
}
use of org.janusgraph.core.RelationType in project janusgraph by JanusGraph.
the class ManagementSystem method setConsistency.
/**
* Sets the consistency level for those schema elements that support it (types and internal indexes)
* <p>
* Note, that it is possible to have a race condition here if two threads simultaneously try to change the
* consistency level. However, this is resolved when the consistency level is being read by taking the
* first one and deleting all existing attached consistency levels upon modification.
*
* @param element
* @param consistency
*/
@Override
public void setConsistency(JanusGraphSchemaElement element, ConsistencyModifier consistency) {
if (element instanceof RelationType) {
RelationTypeVertex rv = (RelationTypeVertex) element;
Preconditions.checkArgument(consistency != ConsistencyModifier.FORK || !rv.multiplicity().isConstrained(), "Cannot apply FORK consistency mode to constraint relation type: %s", rv.name());
} else if (element instanceof JanusGraphIndex) {
IndexType index = ((JanusGraphIndexWrapper) element).getBaseIndex();
if (index.isMixedIndex())
throw new IllegalArgumentException("Cannot change consistency on mixed index: " + element);
} else
throw new IllegalArgumentException("Cannot change consistency of schema element: " + element);
setTypeModifier(element, ModifierType.CONSISTENCY, consistency);
}
use of org.janusgraph.core.RelationType in project janusgraph by JanusGraph.
the class ManagementSystem method printIndexes.
private String printIndexes(boolean calledDirectly) {
StringBuilder sb = new StringBuilder();
String pattern = "%-30s | %-11s | %-9s | %-14s | %-10s %10s |%n";
String relationPattern = "%-30s | %-11s | %-9s | %-14s | %-8s | %10s |%n";
Iterable<JanusGraphIndex> vertexIndexes = getGraphIndexes(Vertex.class);
Iterable<JanusGraphIndex> edgeIndexes = getGraphIndexes(Edge.class);
Iterable<RelationType> relationTypes = getRelationTypes(RelationType.class);
LinkedList<RelationTypeIndex> relationIndexes = new LinkedList<>();
for (RelationType rt : relationTypes) {
Iterable<RelationTypeIndex> rti = getRelationIndexes(rt);
rti.forEach(relationIndexes::add);
}
if (calledDirectly) {
sb.append(FIRSTDASH);
} else {
sb.append(DASHBREAK);
}
sb.append(String.format(pattern, "Graph Index (Vertex)", "Type", "Unique", "Backing", "Key:", "Status"));
sb.append(DASHBREAK);
sb.append(iterateIndexes(pattern, vertexIndexes));
sb.append(DASHBREAK);
sb.append(String.format(pattern, "Graph Index (Edge)", "Type", "Unique", "Backing", "Key:", "Status"));
sb.append(DASHBREAK);
sb.append(iterateIndexes(pattern, edgeIndexes));
sb.append(DASHBREAK);
sb.append(String.format(relationPattern, "Relation Index (VCI)", "Type", "Direction", "Sort Key", "Order", "Status"));
sb.append(DASHBREAK);
for (RelationTypeIndex ri : relationIndexes) {
sb.append(String.format(relationPattern, ri.name(), ri.getType(), ri.getDirection(), ri.getSortKey()[0], ri.getSortOrder(), ri.getIndexStatus().name()));
}
if (!relationIndexes.isEmpty()) {
sb.append(DASHBREAK);
}
return sb.toString();
}
use of org.janusgraph.core.RelationType in project janusgraph by JanusGraph.
the class ManagementSystem method changeName.
@Override
public void changeName(JanusGraphSchemaElement element, String newName) {
Preconditions.checkArgument(StringUtils.isNotBlank(newName), "Invalid name: %s", newName);
JanusGraphSchemaVertex schemaVertex = getSchemaVertex(element);
String oldName = schemaVertex.name();
if (oldName.equals(newName))
return;
JanusGraphSchemaCategory schemaCategory = schemaVertex.valueOrNull(BaseKey.SchemaCategory);
Preconditions.checkArgument(schemaCategory.hasName(), "Invalid schema element: %s", element);
if (schemaVertex instanceof RelationType) {
InternalRelationType relType = (InternalRelationType) schemaVertex;
if (relType.getBaseType() != null) {
newName = composeRelationTypeIndexName(relType.getBaseType(), newName);
} else
assert !(element instanceof RelationTypeIndex);
JanusGraphSchemaCategory cat = relType.isEdgeLabel() ? JanusGraphSchemaCategory.EDGELABEL : JanusGraphSchemaCategory.PROPERTYKEY;
SystemTypeManager.throwIfSystemName(cat, newName);
} else if (element instanceof VertexLabel) {
SystemTypeManager.throwIfSystemName(JanusGraphSchemaCategory.VERTEXLABEL, newName);
} else if (element instanceof JanusGraphIndex) {
checkIndexName(newName);
}
transaction.addProperty(schemaVertex, BaseKey.SchemaName, schemaCategory.getSchemaName(newName));
updateConnectionEdgeConstraints(schemaVertex, oldName, newName);
updateSchemaVertex(schemaVertex);
schemaVertex.resetCache();
updatedTypes.add(schemaVertex);
}
use of org.janusgraph.core.RelationType in project janusgraph by JanusGraph.
the class ManagementSystem method buildRelationTypeIndex.
private RelationTypeIndex buildRelationTypeIndex(RelationType type, String name, Direction direction, Order sortOrder, PropertyKey... sortKeys) {
Preconditions.checkArgument(type != null && direction != null && sortOrder != null && sortKeys != null);
Preconditions.checkArgument(StringUtils.isNotBlank(name), "Name cannot be blank: %s", name);
Token.verifyName(name);
Preconditions.checkArgument(sortKeys.length > 0, "Need to specify sort keys");
for (RelationType key : sortKeys) Preconditions.checkArgument(key != null, "Keys cannot be null");
Preconditions.checkArgument(!(type instanceof EdgeLabel) || !((EdgeLabel) type).isUnidirected() || direction == Direction.OUT, "Can only index uni-directed labels in the out-direction: %s", type);
Preconditions.checkArgument(!((InternalRelationType) type).multiplicity().isUnique(direction), "The relation type [%s] has a multiplicity or cardinality constraint in direction [%s] and can therefore not be indexed", type, direction);
String composedName = composeRelationTypeIndexName(type, name);
StandardRelationTypeMaker maker;
if (type.isEdgeLabel()) {
StandardEdgeLabelMaker lm = (StandardEdgeLabelMaker) transaction.makeEdgeLabel(composedName);
lm.unidirected(direction);
maker = lm;
} else {
assert type.isPropertyKey();
assert direction == Direction.OUT;
StandardPropertyKeyMaker lm = (StandardPropertyKeyMaker) transaction.makePropertyKey(composedName);
lm.dataType(((PropertyKey) type).dataType());
maker = lm;
}
boolean canIndexBeEnabled = type.isNew() || Arrays.stream(sortKeys).anyMatch(JanusGraphElement::isNew);
maker.status(canIndexBeEnabled ? SchemaStatus.ENABLED : SchemaStatus.INSTALLED);
maker.invisible();
maker.multiplicity(Multiplicity.MULTI);
maker.sortKey(sortKeys);
maker.sortOrder(sortOrder);
// Compose signature
long[] typeSig = ((InternalRelationType) type).getSignature();
Set<PropertyKey> signature = new HashSet<>(typeSig.length);
for (long typeId : typeSig) {
signature.add(transaction.getExistingPropertyKey(typeId));
}
for (RelationType sortType : sortKeys) {
signature.remove(sortType);
}
if (!signature.isEmpty()) {
PropertyKey[] sig = signature.toArray(new PropertyKey[signature.size()]);
maker.signature(sig);
}
RelationType typeIndex = maker.make();
addSchemaEdge(type, typeIndex, TypeDefinitionCategory.RELATIONTYPE_INDEX, null);
RelationTypeIndexWrapper index = new RelationTypeIndexWrapper((InternalRelationType) typeIndex);
if (!canIndexBeEnabled) {
updateIndex(index, SchemaAction.REGISTER_INDEX);
}
return index;
}
Aggregations