@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; }
private static Iterable<MixedIndexType> getMixedIndexes(RelationType type) { if (!type.isPropertyKey()) { return Collections.emptyList(); } return Iterables.filter(Iterables.filter(((InternalRelationType)type).getKeyIndexes(), MIXED_INDEX_FILTER), MixedIndexType.class); }
public static String n(Object obj) { if (obj instanceof RelationType) return ((RelationType)obj).name(); else return obj.toString(); }
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); if (tv.equals(adjacentVertex) && isLoopAdded(tv, type.name())) { continue; te = (TinkerEdge)adjacentVertex.addEdge(type.name(), tv, T.id, relation.relationId); } else if (relation.direction.equals(Direction.OUT)) { te = (TinkerEdge)tv.addEdge(type.name(), adjacentVertex, 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");
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;
for (int i = 0; i < numTypes; i++) { RelationType type = tx.getRelationType("test" + i); if (i < numTypes / 2) assertTrue(type.isPropertyKey()); else assertTrue(type.isEdgeLabel());
@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())); } }
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()); } }
private static String composeRelationTypeIndexName(RelationType type, String name) { return String.valueOf(type.longId()) + RELATION_INDEX_SEPARATOR + name; }
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); if (tv.equals(adjacentVertex) && isLoopAdded(tv, type.name())) { continue; te = (TinkerEdge)adjacentVertex.addEdge(type.name(), tv, T.id, relation.relationId); } else if (relation.direction.equals(Direction.OUT)) { te = (TinkerEdge)tv.addEdge(type.name(), adjacentVertex, 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");
int startKeyPos = in.getPosition(); int endKeyPos = 0; if (relationType.isEdgeLabel()) { long otherVertexId; if (multiplicity.isConstrained()) { assert relationType.isPropertyKey(); PropertyKey key = (PropertyKey) relationType;
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()); } }
static 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; }
@Override public boolean containsPropertyKey(String name) { RelationType type = getRelationType(name); return type!=null && type.isPropertyKey(); }
@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); }
@Override public boolean containsEdgeLabel(String name) { RelationType type = getRelationType(name); return type!=null && type.isEdgeLabel(); }
@Override public PropertyKey getPropertyKey(String name) { RelationType pk = getRelationType(name); Preconditions.checkArgument(pk==null || pk.isPropertyKey(), "The relation type with name [%s] is not a property key",name); return (PropertyKey)pk; }
public Q type(RelationType type) { return types(type.name()); }
@Override public EdgeLabel getOrCreateEdgeLabel(String name) { RelationType et = getRelationType(name); if (et == null) { return config.getAutoSchemaMaker().makeEdgeLabel(makeEdgeLabel(name)); } else if (et.isEdgeLabel()) { return (EdgeLabel) et; } else throw new IllegalArgumentException("The type of given name is not a label: " + name); }
private static <E extends JanusGraphElement> void addConstraint(RelationType type, JanusGraphPredicate predicate, Object value, MultiCondition<E> conditions, StandardJanusGraphTx tx) { if (type.isPropertyKey()) { if (value != null) value = tx.verifyAttribute((PropertyKey) type, value); } else { //t.isEdgeLabel() Preconditions.checkArgument(value instanceof JanusGraphVertex); } final PredicateCondition<RelationType, E> pc = new PredicateCondition<>(type, predicate, value); if (!conditions.contains(pc)) conditions.add(pc); }