public boolean isConstrained(Direction direction) { if (direction==Direction.BOTH) return isConstrained(); if (this==MULTI) return false; if (this==SIMPLE) return true; return isUnique(direction); }
protected boolean hasAllCanonicalTypes() { if (types.length==0) return false; for (String typeName : types) { InternalRelationType type = QueryUtil.getType(tx, typeName); if (type!=null && !type.isPropertyKey() && !type.multiplicity().isUnique(dir)) return false; } return true; }
@Override public EdgeLabel make() { TypeDefinitionMap definition = makeDefinition(); Preconditions.checkArgument(unidirectionality==Direction.BOTH || !getMultiplicity().isUnique(unidirectionality.opposite()), "Unidirectional labels cannot have restricted multiplicity at the other end"); Preconditions.checkArgument(unidirectionality==Direction.BOTH || !hasSortKey() || !getMultiplicity().isUnique(unidirectionality), "Unidirectional labels with restricted multiplicity cannot have a sort key"); Preconditions.checkArgument(unidirectionality!=Direction.IN || definition.getValue(INVISIBLE,Boolean.class)); definition.setValue(UNIDIRECTIONAL, unidirectionality); return tx.makeEdgeLabel(getName(), definition); }
public static boolean acquireLock(InternalRelation relation, int pos, boolean acquireLocksConfig) { InternalRelationType type = (InternalRelationType)relation.getType(); return acquireLocksConfig && type.getConsistencyModifier()== ConsistencyModifier.LOCK && ( type.multiplicity().isUnique(EdgeDirection.fromPosition(pos)) || pos==0 && type.multiplicity()== Multiplicity.SIMPLE); }
@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> iter = ElementHelper.getValues(element,(PropertyKey)type).iterator(); if (iter.hasNext()) { while (iter.hasNext()) { if (satisfiesCondition(iter.next())) return true; } return false; } return satisfiesCondition(null); } else { assert ((InternalRelationType)type).multiplicity().isUnique(Direction.OUT); return satisfiesCondition((TitanVertex)element.value(type.name())); } }
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().isUnique(dir1)) return 0;
throw new SchemaViolationException("An edge with the given label already exists between the pair of vertices and the label [%s] is simple", label.name()); if (multiplicity.isUnique(Direction.OUT)) { if (!Iterables.isEmpty(query(outVertex).type(label).direction(Direction.OUT).edges())) throw new SchemaViolationException("An edge with the given label already exists on the out-vertex and the label [%s] is out-unique", label.name()); if (multiplicity.isUnique(Direction.IN)) { if (!Iterables.isEmpty(query(inVertex).type(label).direction(Direction.IN).edges())) throw new SchemaViolationException("An edge with the given label already exists on the in-vertex and the label [%s] is in-unique", label.name());
long otherVertexId = relation.getVertex((position + 1) % 2).longId(); if (multiplicity.isConstrained()) { if (multiplicity.isUnique(dir)) { valuePosition = out.getPosition(); VariableLong.writePositive(out, otherVertexId); if (multiplicity.isUnique(dir)) { //Cardinality=SINGLE valuePosition = out.getPosition(); writePropertyValue(out,key,value);
long otherVertexId; if (multiplicity.isConstrained()) { if (multiplicity.isUnique(dir)) { otherVertexId = VariableLong.readPositive(in); } else {
assert !type.multiplicity().isUnique(dir); assert (skey instanceof ImplicitKey) && (skey==ImplicitKey.TITANID || skey==ImplicitKey.ADJACENT_ID); assert skey!=ImplicitKey.ADJACENT_ID || (i==sortKeyIDs.length); assert !type.multiplicity().isUnique(dir); VariableLong.writePositiveBackward(colStart, (Long)interval.getStart()); VariableLong.writePositiveBackward(colEnd, (Long)interval.getEnd());
long newPartition; int otherpos = (pos+1)%2; if (((InternalRelationType)relation.getType()).multiplicity().isUnique(EdgeDirection.fromPosition(pos))) {
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 boolean hasAllCanonicalTypes() { for (String typeName : types) { InternalRelationType type = QueryUtil.getType(tx, typeName); if (type==null) continue; if (!type.getMultiplicity().isUnique(dir)) return false; } return true; }
protected boolean hasAllCanonicalTypes() { if (types.length==0) return false; for (String typeName : types) { InternalRelationType type = QueryUtil.getType(tx, typeName); if (type!=null && !type.isPropertyKey() && !type.multiplicity().isUnique(dir)) return false; } return true; }
@Override public EdgeLabel make() { TypeDefinitionMap definition = makeDefinition(); Preconditions.checkArgument(unidirectionality==Direction.BOTH || !getMultiplicity().isUnique(unidirectionality.opposite()), "Unidirectional labels cannot have restricted multiplicity at the other end"); Preconditions.checkArgument(unidirectionality==Direction.BOTH || !hasSortKey() || !getMultiplicity().isUnique(unidirectionality), "Unidirectional labels with restricted multiplicity cannot have a sort key"); Preconditions.checkArgument(unidirectionality!=Direction.IN || definition.getValue(HIDDEN,Boolean.class)); definition.setValue(UNIDIRECTIONAL, unidirectionality); return tx.makeEdgeLabel(getName(), definition); }
public static boolean acquireLock(InternalRelation relation, int pos, boolean acquireLocksConfig) { InternalRelationType type = (InternalRelationType)relation.getType(); return acquireLocksConfig && type.getConsistencyModifier()== ConsistencyModifier.LOCK && ( type.getMultiplicity().isUnique(EdgeDirection.fromPosition(pos)) || pos==0 && type.getMultiplicity()== Multiplicity.SIMPLE); }
public static boolean acquireLock(InternalRelation relation, int pos, boolean acquireLocksConfig) { InternalRelationType type = (InternalRelationType)relation.getType(); return acquireLocksConfig && type.getConsistencyModifier()== ConsistencyModifier.LOCK && ( type.multiplicity().isUnique(EdgeDirection.fromPosition(pos)) || pos==0 && type.multiplicity()== Multiplicity.SIMPLE); }