@Override public String toString() { return "["+key.name()+"]"; }
public GraphCentricQueryBuilder has(PropertyKey key, JanusGraphPredicate predicate, Object condition) { Preconditions.checkNotNull(key); return has(key.name(),predicate,condition); }
@Override default String key() { return propertyKey().name(); }
public static JanusGraphVertex getVertex(JanusGraphTransaction tx, PropertyKey key, Object value) { return getVertex(tx, key.name(), value); }
private Parameter getFieldMap(PropertyKey key) { return ParameterType.MAPPED_NAME.getParameter(key.name()); }
private static long[] checkSignature(List<PropertyKey> 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++) { PropertyKey key = sig.get(i); Preconditions.checkNotNull(key); Preconditions.checkArgument(!((PropertyKey) key).dataType().equals(Object.class), "Signature and sort keys must have a proper declared datatype: %s", key.name()); signature[i] = key.longId(); } return signature; }
@Override public void setPropertyDirect(PropertyKey key, Object value) { Preconditions.checkArgument(!(key instanceof ImplicitKey), "Cannot use implicit type [%s] when setting property", key.name()); if (properties == EMPTY_PROPERTIES) { if (tx().getConfiguration().isSingleThreaded()) { properties = new HashMap<>(5); } else { synchronized (this) { if (properties == EMPTY_PROPERTIES) { properties = Collections.synchronizedMap(new HashMap<PropertyKey, Object>(5)); } } } } properties.put(key, value); }
private String printPropertyKeys(boolean calledDirectly) { StringBuilder sb = new StringBuilder(); String pattern = "%-30s | %-11s | %-50s |\n"; Iterable<PropertyKey> keys = getRelationTypes(PropertyKey.class); boolean hasResults = false; if (calledDirectly) { sb.append(FIRSTDASH); } else { sb.append(DASHBREAK); } sb.append(String.format(pattern, "Property Key Name", "Cardinality", "Data Type")); sb.append(DASHBREAK); for (PropertyKey key: keys) { hasResults = true; sb.append(String.format(pattern, key.name(), key.cardinality(), key.dataType())); } if (hasResults && calledDirectly) { sb.append(DASHBREAK); } return sb.toString(); }
public static Set<String> getPropertyKeys(JanusGraphVertex v) { final Set<String> s = new HashSet<>(); v.query().properties().forEach( p -> s.add(p.propertyKey().name())); return s; }
@Override public <A> A valueOrNull(PropertyKey key) { return (A) property(key.name()).orElse(null); }
@Override public <O> O valueOrNull(PropertyKey key) { return (O)property(key.name()).orElse(null); }
private String[][] getKeyStatus(PropertyKey[] keys, JanusGraphIndex index) { String[][] keyStatus = new String[keys.length][2]; for (int i = 0; i < keys.length; i++) { keyStatus[i][0] = keys[i].name(); keyStatus[i][1] = index.getIndexStatus(keys[i]).name(); } return keyStatus.length > 0 ? keyStatus: new String[][] {{"",""}}; }
@Override public GraphCentricQueryBuilder orderBy(String keyName, org.apache.tinkerpop.gremlin.process.traversal.Order order) { Preconditions.checkArgument(tx.containsPropertyKey(keyName),"Provided key does not exist: %s",keyName); final PropertyKey key = tx.getPropertyKey(keyName); Preconditions.checkArgument(key!=null && order!=null,"Need to specify and key and an order"); Preconditions.checkArgument(Comparable.class.isAssignableFrom(key.dataType()), "Can only order on keys with comparable data type. [%s] has datatype [%s]", key.name(), key.dataType()); Preconditions.checkArgument(key.cardinality()== Cardinality.SINGLE, "Ordering is undefined on multi-valued key [%s]", key.name()); Preconditions.checkArgument(!orders.containsKey(key)); orders.add(key, Order.convert(order)); return this; }
@Override public void setPropertyDirect(PropertyKey key, Object value) { Preconditions.checkArgument(!(key instanceof ImplicitKey), "Cannot use implicit type [%s] when setting property", key.name()); if (properties == EMPTY_PROPERTIES) { if (tx().getConfiguration().isSingleThreaded()) { properties = new HashMap<>(5); } else { synchronized (this) { if (properties == EMPTY_PROPERTIES) { properties = Collections.synchronizedMap(new HashMap<PropertyKey, Object>(5)); } } } } tx().checkPropertyConstraintForEdgeOrCreatePropertyConstraint(this, key); properties.put(key, value); }
@Override public Q orderBy(String keyName, org.apache.tinkerpop.gremlin.process.traversal.Order order) { Preconditions.checkArgument(schemaInspector.containsPropertyKey(keyName), "Provided key does not exist: %s", keyName); PropertyKey key = schemaInspector.getPropertyKey(keyName); Preconditions.checkArgument(key != null && order != null, "Need to specify and key and an order"); Preconditions.checkArgument(Comparable.class.isAssignableFrom(key.dataType()), "Can only order on keys with comparable data type. [%s] has datatype [%s]", key.name(), key.dataType()); Preconditions.checkArgument(!(key instanceof SystemRelationType), "Cannot use system types in ordering: %s", key); Preconditions.checkArgument(!orders.containsKey(key)); Preconditions.checkArgument(orders.isEmpty(), "Only a single sort order is supported on vertex queries"); orders.add(key, Order.convert(order)); return getThis(); }
public String getDefaultFieldName(final PropertyKey key, final Parameter[] parameters, final String indexName) { Preconditions.checkArgument(!ParameterType.MAPPED_NAME.hasParameter(parameters),"A field name mapping has been specified for key: %s",key); Preconditions.checkArgument(containsIndex(indexName),"Unknown backing index: %s",indexName); final String fieldname = configuration.get(INDEX_NAME_MAPPING,indexName)?key.name():keyID2Name(key); return mixedIndexes.get(indexName).mapKey2Field(fieldname, new StandardKeyInformation(key,parameters)); }
public void reindexElement(JanusGraphElement element, MixedIndexType index, Map<String,Map<String,List<IndexEntry>>> documentsPerStore) { if (!indexAppliesTo(index,element)) return; final List<IndexEntry> entries = Lists.newArrayList(); for (final ParameterIndexField field: index.getFieldKeys()) { final PropertyKey key = field.getFieldKey(); if (field.getStatus()==SchemaStatus.DISABLED) continue; if (element.properties(key.name()).hasNext()) { element.values(key.name()).forEachRemaining(value->entries.add(new IndexEntry(key2Field(field), value))); } } final Map<String, List<IndexEntry>> documents = documentsPerStore.computeIfAbsent(index.getStoreName(), k -> Maps.newHashMap()); getDocuments(documentsPerStore,index).put(element2String(element),entries); }
public static Iterable<Object> getValues(JanusGraphElement element, PropertyKey key) { if (element instanceof JanusGraphRelation) { Object value = element.valueOrNull(key); if (value==null) return Collections.EMPTY_LIST; else return ImmutableList.of(value); } else { assert element instanceof JanusGraphVertex; return Iterables.transform((((JanusGraphVertex) element).query()).keys(key.name()).properties(), new Function<JanusGraphVertexProperty, Object>() { @Nullable @Override public Object apply(final JanusGraphVertexProperty janusgraphProperty) { return janusgraphProperty.value(); } }); } }
public PropertyKeyDefinition(PropertyKey key) { this(key.name(),key.longId(),key.cardinality(),key.dataType()); }
public final Object verifyAttribute(PropertyKey key, Object attribute) { if (attribute==null) throw new SchemaViolationException("Property value cannot be null"); Class<?> datatype = key.dataType(); if (datatype.equals(Object.class)) { if (!attributeHandler.validDataType(attribute.getClass())) { throw Property.Exceptions.dataTypeOfPropertyValueNotSupported(attribute); } return attribute; } else { if (!attribute.getClass().equals(datatype)) { Object converted = null; try { converted = attributeHandler.convert(datatype, attribute); } catch (IllegalArgumentException e) { //Just means that data could not be converted } if (converted == null) throw new SchemaViolationException( "Value [%s] is not an instance of the expected data type for property key [%s] and cannot be converted. Expected: %s, found: %s", attribute, key.name(), datatype, attribute.getClass()); attribute = converted; } assert (attribute.getClass().equals(datatype)); attributeHandler.verifyAttribute(datatype, attribute); return attribute; } }