@Override public boolean containsPropertyKey(String name) { RelationType type = getRelationType(name); return type!=null && type.isPropertyKey(); }
@Override public void run() { TitanTransaction tx = graph.newTransaction(); for (int i = 0; i < numTypes; i++) { RelationType type = tx.getRelationType("test" + i); if (i < numTypes / 2) assertTrue(type.isPropertyKey()); else assertTrue(type.isEdgeLabel()); } tx.commit(); } });
if (type.isPropertyKey()) { VertexProperty.Cardinality card = getPropertyKeyCardinality(type.name()); tv.property(card, type.name(), value, T.id, relation.relationId); } else { assert type.isEdgeLabel(); "Read edge incident on a partitioned vertex, but partitioned vertex filtering is disabled. " + "Relation ID: %s. This vertex ID: %s. Other vertex ID: %s. Edge label: %s.", relation.relationId, vertexId, relation.getOtherVertexId(), type.name()); log.debug("Skipping edge with ID {} incident on partitioned vertex with ID {} (and nonpartitioned vertex with ID {})", relation.relationId, relation.getOtherVertexId(), vertexId); te = (TinkerEdge)outV.addEdge(type.name(), tv, T.id, relation.relationId); } else if (relation.direction.equals(Direction.OUT)) { te = (TinkerEdge)tv.addEdge(type.name(), inV, T.id, relation.relationId); } else { throw new RuntimeException("Direction.BOTH is not supported"); assert next.value != null; RelationType rt = typeManager.getExistingRelationType(next.key); if (rt.isPropertyKey()) { te.property(rt.name(), next.value); } else { throw new RuntimeException("Metaedges are not supported");
private VertexProperty.Cardinality getPropertyKeyCardinality(String name) { RelationType rt = typeManager.getRelationType(name); if (null == rt || !rt.isPropertyKey()) return VertexProperty.Cardinality.single; PropertyKey pk = typeManager.getExistingPropertyKey(rt.longId()); switch (pk.cardinality()) { case SINGLE: return VertexProperty.Cardinality.single; case LIST: return VertexProperty.Cardinality.list; case SET: return VertexProperty.Cardinality.set; default: throw new IllegalStateException("Unknown cardinality " + pk.cardinality()); } }
@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())); } }
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); maker = lm; maker.status(type.isNew() ? SchemaStatus.ENABLED : SchemaStatus.INSTALLED); maker.invisible(); maker.multiplicity(Multiplicity.MULTI); addSchemaEdge(type, typeIndex, TypeDefinitionCategory.RELATIONTYPE_INDEX, null); RelationTypeIndexWrapper index = new RelationTypeIndexWrapper((InternalRelationType) typeIndex); if (!type.isNew()) updateIndex(index, SchemaAction.REGISTER_INDEX); return index;
private void writeInline(DataOutput out, RelationType type, Object value, InlineType inlineType) { assert !(type.isPropertyKey() && !inlineType.writeEdgeType()) || !AttributeUtil.hasGenericDataType((PropertyKey) type); if (inlineType.writeEdgeType()) { IDHandler.writeInlineEdgeType(out, type.getLongId()); } if (type.isPropertyKey()) { writePropertyValue(out,(PropertyKey)type,value, inlineType); } else { assert type.isEdgeLabel() && ((EdgeLabel) type).isUnidirected(); long id = (value==null?0:((InternalVertex) value).getLongId()); if (inlineType.writeByteOrdered()) LongSerializer.INSTANCE.writeByteOrder(out,id); else VariableLong.writePositive(out,id); } }
private static long[] checkSignature(List<RelationType> sig) { Preconditions.checkArgument(sig.size() == (Sets.newHashSet(sig)).size(), "Signature and sort key cannot contain duplicate types"); long[] signature = new long[sig.size()]; for (int i = 0; i < sig.size(); i++) { RelationType et = sig.get(i); Preconditions.checkNotNull(et); Preconditions.checkArgument(!et.isEdgeLabel() || ((EdgeLabel) et).isUnidirected(), "Label must be unidirectional: %s", et.getName()); Preconditions.checkArgument(!et.isPropertyKey() || !((PropertyKey) et).getDataType().equals(Object.class), "Signature and sort keys must have a proper declared datatype: %s", et.getName()); signature[i] = et.getLongId(); } return signature; }
@Override public boolean containsEdgeLabel(String name) { RelationType type = getRelationType(name); return type!=null && type.isEdgeLabel(); }
public static String n(Object obj) { if (obj instanceof RelationType) return ((RelationType)obj).name(); else return obj.toString(); }
private static String composeRelationTypeIndexName(RelationType type, String name) { return String.valueOf(type.longId()) + RELATION_INDEX_SEPARATOR + name; }
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); maker = lm; maker.status(type.isNew() ? SchemaStatus.ENABLED : SchemaStatus.INSTALLED); maker.invisible(); maker.multiplicity(Multiplicity.MULTI); addSchemaEdge(type, typeIndex, TypeDefinitionCategory.RELATIONTYPE_INDEX, null); RelationTypeIndexWrapper index = new RelationTypeIndexWrapper((InternalRelationType) typeIndex); if (!type.isNew()) updateIndex(index, SchemaAction.REGISTER_INDEX); return index;
int startKeyPos = in.getPosition(); int endKeyPos = 0; if (relationType.isEdgeLabel()) { long otherVertexId; if (multiplicity.isConstrained()) { assert relationType.isPropertyKey(); PropertyKey key = (PropertyKey) relationType; Object pvalue = readInline(in, type, InlineType.NORMAL); assert pvalue != null; properties.put(type.getLongId(), pvalue);
@Override public EdgeLabel getEdgeLabel(String name) { RelationType el = getRelationType(name); Preconditions.checkArgument(el==null || el.isEdgeLabel(), "The relation type with name [%s] is not an edge label",name); return (EdgeLabel)el; }
@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 VertexProperty.Cardinality getPropertyKeyCardinality(String name) { RelationType rt = typeManager.getRelationType(name); if (null == rt || !rt.isPropertyKey()) return VertexProperty.Cardinality.single; PropertyKey pk = typeManager.getExistingPropertyKey(rt.longId()); switch (pk.cardinality()) { case SINGLE: return VertexProperty.Cardinality.single; case LIST: return VertexProperty.Cardinality.list; case SET: return VertexProperty.Cardinality.set; default: throw new IllegalStateException("Unknown cardinality " + pk.cardinality()); } }
@Override public Q types(RelationType... types) { String[] ts = new String[types.length]; for (int i = 0; i < types.length; i++) { ts[i] = types[i].name(); } return types(ts); }
static final RelationIdentifier get(InternalRelation r) { if (r.hasId()) { return new RelationIdentifier(r.getVertex(0).longId(), r.getType().longId(), r.longId(), (r.isEdge() ? r.getVertex(1).longId() : 0)); } else return null; }
private static Iterable<MixedIndexType> getMixedIndexes(RelationType type) { if (!type.isPropertyKey()) return Collections.EMPTY_LIST; return Iterables.filter(Iterables.filter(((InternalRelationType)type).getKeyIndexes(),MIXED_INDEX_FILTER),MixedIndexType.class); }
int startKeyPos = in.getPosition(); int endKeyPos = 0; if (relationType.isEdgeLabel()) { long otherVertexId; if (multiplicity.isConstrained()) { assert relationType.isPropertyKey(); PropertyKey key = (PropertyKey) relationType;