public boolean isConstrained(Direction direction) { if (direction==Direction.BOTH) return isConstrained(); if (this==MULTI) return false; if (this==SIMPLE) return true; return 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(TitanSchemaElement 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 TitanGraphIndex) { IndexType index = ((TitanGraphIndexWrapper) 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, TitanRelation 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); if (!Iterables.isEmpty(vertex.getAddedRelations(new Predicate<InternalRelation>() { @Override public boolean apply(@Nullable InternalRelation internalRelation) { return comparator.compare((InternalRelation)result,internalRelation)==0; } }))) return true; } return false; }
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().isConstrained(direction), "The relation type [%s] has a multiplicity or cardinality constraint in direction [%s] and can therefore not be indexed", type, direction);
private TransactionLock getUniquenessLock(final TitanVertex 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, StandardTitanTx 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.TITANID; 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() && keysig.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();
assert (skey instanceof ImplicitKey) && (skey==ImplicitKey.TITANID || skey==ImplicitKey.ADJACENT_ID); assert skey!=ImplicitKey.ADJACENT_ID || (i==sortKeyIDs.length); assert skey!=ImplicitKey.TITANID || (!type.multiplicity().isConstrained() && (i==sortKeyIDs.length && skey.isPropertyKey() || i==sortKeyIDs.length+1 && skey.isEdgeLabel() )); assert colStart.getPosition()==colEnd.getPosition(); assert !type.multiplicity().isConstrained(); assert skey.longId() == sortKeyIDs[i];
public boolean isConstrained(Direction direction) { if (direction==Direction.BOTH) return isConstrained(); if (this==MULTI) return false; if (this==SIMPLE) return true; return isUnique(direction); }
public boolean isConstrained(Direction direction) { if (direction==Direction.BOTH) return isConstrained(); if (this==MULTI) return false; if (this==SIMPLE) return true; return 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"); }
private void checkGeneralArguments() { //Verify name checkName(name); 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"); }
@Override public boolean isDeleted(VertexCentricQuery query, TitanRelation 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); if (!Iterables.isEmpty(vertex.getAddedRelations(new Predicate<InternalRelation>() { @Override public boolean apply(@Nullable InternalRelation internalRelation) { return comparator.compare((InternalRelation)result,internalRelation)==0; } }))) return true; } return false; }
@Override public boolean isDeleted(final VertexCentricQuery query, final TitanRelation result) { if (deletedRelations.containsKey(result.getLongId()) || 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.getMultiplicity().isConstrained() && vertex.hasAddedRelations()) { final RelationComparator comparator = new RelationComparator(vertex); if (!Iterables.isEmpty(vertex.getAddedRelations(new Predicate<InternalRelation>() { @Override public boolean apply(@Nullable InternalRelation internalRelation) { return comparator.compare((InternalRelation) result, internalRelation) == 0; } }))) return true; } return false; }
private TransactionLock getUniquenessLock(final TitanVertex 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; }
private TransactionLock getUniquenessLock(final TitanVertex out, final InternalRelationType type, final Object in) { Multiplicity multiplicity = type.getMultiplicity(); 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 RelationType[] getExtendedSortKey(InternalRelationType type, Direction dir, StandardTitanTx tx) { int additional = 0; if (!type.getMultiplicity().isUnique(dir)) { if (!type.getMultiplicity().isConstrained()) additional++; if (type.isEdgeLabel()) additional++; } RelationType[] entireKey = new RelationType[type.getSortKey().length+additional]; int i; for (i=0;i<type.getSortKey().length;i++) { entireKey[i]=tx.getExistingRelationType(type.getSortKey()[i]); } if (type.isEdgeLabel() && !type.getMultiplicity().isUnique(dir)) entireKey[i++]=ImplicitKey.ADJACENT_ID; if (!type.getMultiplicity().isConstrained()) entireKey[i++]=ImplicitKey.TITANID; return entireKey; }