public static boolean hasGenericDataType(PropertyKey key) { return key.getDataType().equals(Object.class); } }
@Override public GraphCentricQueryBuilder orderBy(PropertyKey key, Order order) { Preconditions.checkArgument(key!=null && order!=null,"Need to specify and key and an order"); Preconditions.checkArgument(Comparable.class.isAssignableFrom(key.getDataType()), "Can only order on keys with comparable data type. [%s] has datatype [%s]", key.getName(), key.getDataType()); Preconditions.checkArgument(key.getCardinality()== Cardinality.SINGLE, "Ordering is undefined on multi-valued key [%s]", key.getName()); Preconditions.checkArgument(!orders.containsKey(key)); orders.add(key, order); return this; }
@Override public GraphCentricQueryBuilder orderBy(PropertyKey key, Order order) { Preconditions.checkArgument(key!=null && order!=null, "Need to specify and key and an order"); Preconditions.checkArgument(Comparable.class.isAssignableFrom(key.getDataType()), "Can only order on keys with comparable data type. [%s] has datatype [%s]", key.getName(), key.getDataType()); Preconditions.checkArgument(key.getCardinality()== Cardinality.SINGLE, "Ordering is undefined on multi-valued key [%s]", key.getName()); Preconditions.checkArgument(!orders.containsKey(key)); orders.add(key, order); return this; }
@Override public GraphCentricQueryBuilder orderBy(PropertyKey key, Order order) { Preconditions.checkArgument(key!=null && order!=null,"Need to specify and key and an order"); Preconditions.checkArgument(Comparable.class.isAssignableFrom(key.getDataType()), "Can only order on keys with comparable data type. [%s] has datatype [%s]", key.getName(), key.getDataType()); Preconditions.checkArgument(key.getCardinality()== Cardinality.SINGLE, "Ordering is undefined on multi-valued key [%s]", key.getName()); Preconditions.checkArgument(!orders.containsKey(key)); orders.add(key, order); return this; }
private void writePropertyValue(DataOutput out, PropertyKey key, Object value, InlineType inlineType) { if (AttributeUtil.hasGenericDataType(key)) { assert !inlineType.writeByteOrdered(); out.writeClassAndObject(value); } else { assert value==null || value.getClass().equals(key.getDataType()); if (inlineType.writeByteOrdered()) out.writeObjectByteOrder(value, key.getDataType()); else out.writeObject(value, key.getDataType()); } }
@Override public Q orderBy(PropertyKey key, Order order) { Preconditions.checkArgument(key!=null && order!=null,"Need to specify and key and an order"); Preconditions.checkArgument(Comparable.class.isAssignableFrom(key.getDataType()), "Can only order on keys with comparable data type. [%s] has datatype [%s]", key.getName(), key.getDataType()); Preconditions.checkArgument(key.getCardinality()== Cardinality.SINGLE, "Ordering is undefined on multi-valued key [%s]", key.getName()); 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); return getThis(); }
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; }
private long[] checkSortKey(List<RelationType> sig) { for (RelationType t : sig) { Preconditions.checkArgument(t.isEdgeLabel() || attributeHandler.isOrderPreservingDatatype(((PropertyKey) t).getDataType()), "Key must have an order-preserving data type to be used as sort key: " + t); } return checkSignature(sig); }
private Object readPropertyValue(ReadBuffer read, PropertyKey key, InlineType inlineType) { if (AttributeUtil.hasGenericDataType(key)) { return serializer.readClassAndObject(read); } else { if (inlineType.writeByteOrdered()) return serializer.readObjectByteOrder(read, key.getDataType()); else return serializer.readObject(read, key.getDataType()); } }
public final Object verifyAttribute(PropertyKey key, Object attribute) { if (attribute==null) throw new SchemaViolationException("Property value cannot be null"); Class<?> datatype = key.getDataType(); if (datatype.equals(Object.class)) { 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.getName(), datatype, attribute.getClass()); attribute = converted; } Preconditions.checkState(attribute.getClass().equals(datatype)); attributeHandler.verifyAttribute(datatype, attribute); return attribute; } }
public PropertyKeyDefinition(PropertyKey key) { this(key.getName(),key.getLongId(),key.getCardinality(),key.getDataType()); }
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); String fieldname = configuration.get(INDEX_NAME_MAPPING,indexName)?key.getName():keyID2Name(key); return mixedIndexes.get(indexName).mapKey2Field(fieldname, new StandardKeyInformation(key.getDataType(),parameters)); }
private static StandardKeyInformation getKeyInformation(final ParameterIndexField field) { return new StandardKeyInformation(field.getFieldKey().getDataType(),field.getParameters()); }
public static GraphCentricQueryBuilder getQuery(CompositeIndexType index, Object[] values, StandardTitanTx tx) { Preconditions.checkArgument(index != null && values != null && values.length > 0 && tx != null); Preconditions.checkArgument(values.length==index.getFieldKeys().length); GraphCentricQueryBuilder gb = tx.query(); IndexField[] fields = index.getFieldKeys(); for (int i = 0; i <fields.length; i++) { IndexField f = fields[i]; Object value = values[i]; Preconditions.checkNotNull(value); PropertyKey key = f.getFieldKey(); Preconditions.checkArgument(key.getDataType().equals(value.getClass()),"Incompatible data types for: " + value); gb.has(key, Cmp.EQUAL,value); } if (index.hasSchemaTypeConstraint()) { gb.has(ImplicitKey.LABEL,Cmp.EQUAL,index.getSchemaTypeConstraint().getName()); } return gb; } }
private final StaticBuffer getIndexKey(CompositeIndexType index, Object[] values) { DataOutput out = serializer.getDataOutput(8*DEFAULT_OBJECT_BYTELEN + 8); VariableLong.writePositive(out, index.getID()); IndexField[] fields = index.getFieldKeys(); Preconditions.checkArgument(fields.length>0 && fields.length==values.length); for (int i = 0; i < fields.length; i++) { IndexField f = fields[i]; Object value = values[i]; Preconditions.checkNotNull(value); if (AttributeUtil.hasGenericDataType(f.getFieldKey())) { out.writeClassAndObject(value); } else { assert value.getClass().equals(f.getFieldKey().getDataType()) : value.getClass() + " - " + f.getFieldKey().getDataType(); out.writeObjectNotNull(value); } } StaticBuffer key = out.getStaticBuffer(); if (hashKeys) key = HashingUtil.hashPrefixKey(hashLength,key); return key; }
public IndexQuery getQuery(final MixedIndexType index, final Condition condition, final OrderList orders) { Condition newCondition = ConditionUtil.literalTransformation(condition, new Function<Condition<TitanElement>, Condition<TitanElement>>() { @Nullable @Override public Condition<TitanElement> apply(@Nullable Condition<TitanElement> condition) { Preconditions.checkArgument(condition instanceof PredicateCondition); PredicateCondition pc = (PredicateCondition) condition; PropertyKey key = (PropertyKey) pc.getKey(); return new PredicateCondition<String, TitanElement>(key2Field(index,key), pc.getPredicate(), pc.getValue()); } }); ImmutableList<IndexQuery.OrderEntry> newOrders = IndexQuery.NO_ORDER; if (!orders.isEmpty() && GraphCentricQueryBuilder.indexCoversOrder(index,orders)) { ImmutableList.Builder<IndexQuery.OrderEntry> lb = ImmutableList.builder(); for (int i = 0; i < orders.size(); i++) { lb.add(new IndexQuery.OrderEntry(key2Field(index,orders.getKey(i)), orders.getOrder(i), orders.getKey(i).getDataType())); } newOrders = lb.build(); } return new IndexQuery(index.getStoreName(), newCondition, newOrders); } //
PropertyKey key = (PropertyKey) type; assert predicate.isValidCondition(value); Preconditions.checkArgument(key.getDataType()==Object.class || predicate.isValidValueType(key.getDataType()), "Data type of key is not compatible with condition"); } else { //its a label Preconditions.checkArgument(((EdgeLabel) type).isUnidirected());
assert direction==Direction.OUT; StandardPropertyKeyMaker lm = (StandardPropertyKeyMaker)transaction.makePropertyKey(composedName); lm.dataType(((PropertyKey)type).getDataType()); maker = lm;
assert key.getDataType().equals(p.getValue().getClass()) : key + " -> " + p; values.add(new RecordEntry(p));
if (!o1.equals(o2)) { int objectcompare = 0; if (Comparable.class.isAssignableFrom(((PropertyKey) t1).getDataType())) { objectcompare = ((Comparable) o1).compareTo(o2); } else {