public boolean isConstrained(Direction direction) { if (direction == Direction.BOTH) return isConstrained(); return this != MULTI && (this == SIMPLE || isUnique(direction)); }
private void checkGeneralArguments() { checkSortKey(sortKey); Preconditions.checkArgument(sortOrder==Order.ASC || hasSortKey(),"Must define a sort key to use ordering"); checkSignature(signature); Preconditions.checkArgument(Sets.intersection(Sets.newHashSet(sortKey), Sets.newHashSet(signature)).isEmpty(), "Signature and sort key must be disjoined"); Preconditions.checkArgument(!hasSortKey() || !multiplicity.isConstrained(),"Cannot define a sort-key on constrained edge labels"); }
/** * 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); }
@Override public boolean isDeleted(VertexCentricQuery query, JanusGraphRelation result) { if (deletedRelations.containsKey(result.longId()) || result != ((InternalRelation) result).it()) return true; //Check if this relation is replaced by an added one due to a multiplicity constraint InternalRelationType type = (InternalRelationType)result.getType(); InternalVertex vertex = query.getVertex(); if (type.multiplicity().isConstrained() && vertex.hasAddedRelations()) { final RelationComparator comparator = new RelationComparator(vertex); return !Iterables.isEmpty(vertex.getAddedRelations(internalRelation -> comparator.compare((InternalRelation) result, internalRelation) == 0)); } return false; }
private TransactionLock getUniquenessLock(final JanusGraphVertex out, final InternalRelationType type, final Object in) { Multiplicity multiplicity = type.multiplicity(); TransactionLock uniqueLock = FakeLock.INSTANCE; if (config.hasVerifyUniqueness() && multiplicity.isConstrained()) { uniqueLock = null; if (multiplicity==Multiplicity.SIMPLE) { uniqueLock = getLock(out, type, in); } else { for (Direction dir : Direction.proper) { if (multiplicity.isUnique(dir)) { TransactionLock lock = getLock(dir == Direction.OUT ? out : in, type, dir); if (uniqueLock==null) uniqueLock=lock; else uniqueLock=new CombinerLock(uniqueLock,lock,times); } } } } assert uniqueLock!=null; return uniqueLock; }
/** * Returns the extended sort key of the given type. The extended sort key extends the type's primary sort key * by ADJACENT_ID and ID depending on the multiplicity of the type in the given direction. * It also converts the type ids to actual types. * * @param type * @param dir * @param tx * @return */ private static PropertyKey[] getExtendedSortKey(InternalRelationType type, Direction dir, StandardJanusGraphTx tx) { int additional = 0; if (!type.multiplicity().isUnique(dir)) { if (!type.multiplicity().isConstrained()) additional++; if (type.isEdgeLabel()) additional++; } PropertyKey[] entireKey = new PropertyKey[type.getSortKey().length+additional]; int i; for (i=0;i<type.getSortKey().length;i++) { entireKey[i]=tx.getExistingPropertyKey(type.getSortKey()[i]); } if (type.isEdgeLabel() && !type.multiplicity().isUnique(dir)) entireKey[i++]=ImplicitKey.ADJACENT_ID; if (!type.multiplicity().isConstrained()) entireKey[i]=ImplicitKey.JANUSGRAPHID; return entireKey; }
if (t1.multiplicity().isConstrained()) return 0;
if (relationType.isEdgeLabel()) { long otherVertexId; if (multiplicity.isConstrained()) { if (multiplicity.isUnique(dir)) { otherVertexId = VariableLong.readPositive(in); PropertyKey key = (PropertyKey) relationType; if (multiplicity.isConstrained()) { other = readPropertyValue(in,key); relationId = VariableLong.readPositive(in); if (!excludeProperties && !multiplicity.isConstrained() && keySignature.length>0) { int currentPos = in.getPosition();
assert !multiplicity.isConstrained() || sortKey.length==0: type.name(); int keyStartPos = out.getPosition(); if (!multiplicity.isConstrained()) { writeInlineTypes(sortKey, relation, out, tx, InlineType.KEY); if (multiplicity.isConstrained()) { if (multiplicity.isUnique(dir)) { valuePosition = out.getPosition(); assert key.dataType().isInstance(value); if (multiplicity.isConstrained()) { if (multiplicity.isUnique(dir)) { //Cardinality=SINGLE valuePosition = out.getPosition();
&& (propertyKey==ImplicitKey.JANUSGRAPHID || propertyKey==ImplicitKey.ADJACENT_ID); assert propertyKey!=ImplicitKey.ADJACENT_ID || (i==sortKeyIDs.length); assert propertyKey!=ImplicitKey.JANUSGRAPHID || (!type.multiplicity().isConstrained() && (i==sortKeyIDs.length && propertyKey.isPropertyKey() || i==sortKeyIDs.length+1 && propertyKey.isEdgeLabel() )); assert !type.multiplicity().isConstrained(); assert propertyKey.longId() == sortKeyIDs[i];