/** * Check type of the value valid * @param value the property value to be checked data type * @return true if the value is or can convert to the data type, * otherwise false */ public <V> boolean checkDataType(V value) { if (value instanceof Number) { return this.dataType().valueToNumber(value) != null; } return this.dataType().clazz().isInstance(value); }
private <V> V convSingleValue(V value) { if (this.dataType().isNumber()) { @SuppressWarnings("unchecked") V number = (V) this.dataType().valueToNumber(value); return number; } else if (this.dataType().isDate()) { @SuppressWarnings("unchecked") V date = (V) this.dataType().valueToDate(value); return date; } else if (this.dataType().isUUID()) { @SuppressWarnings("unchecked") V uuid = (V) this.dataType().valueToUUID(value); return uuid; } return value; }
E.checkState(fields.size() == 1, "Invalid range index fields"); DataType dataType = graph.propertyKey(fields.get(0)).dataType(); E.checkState(dataType.isNumber() || dataType.isDate(), "Invalid range index field type"); Class<?> clazz = dataType.isNumber() ? dataType.clazz() : DataType.LONG.clazz(); values = bytes2number(buffer.read(id.length - labelLength), clazz);
DataType dataType = this.transaction.getPropertyKey(field) .dataType(); E.checkArgument(dataType.isNumber() || dataType.isDate(), "Range index can only build on numeric or " + "date property, but got %s(%s)", dataType, field); DataType dataType = this.transaction.getPropertyKey(field) .dataType(); E.checkArgument(dataType.isText(), "Search index can only build on text property, " + "but got %s(%s)", dataType, field);
public Class<?> clazz() { Class<?> cls; switch (this.cardinality) { case SINGLE: cls = this.dataType().clazz(); break; // A set of values: Set<DataType> case SET: cls = LinkedHashSet.class; break; // A list of values: List<DataType> case LIST: cls = LinkedList.class; break; default: throw new AssertionError(String.format( "Unsupported cardinality: '%s'", this.cardinality)); } return cls; }
public <V> Object serialValue(V value) { V validValue = this.validValue(value); E.checkArgument(validValue != null, "Invalid property value '%s' for key '%s'", value, this.name()); if (this.dataType.isNumber() || this.dataType.isDate()) { return LongEncoding.encodeNumber(validValue); } return validValue; }
public <V> UUID valueToUUID(V value) { if (value instanceof UUID) { return (UUID) value; } if (this.isUUID() && value instanceof String) { return java.util.UUID.fromString((String) value); } return null; } }
public <V> Date valueToDate(V value) { if (value instanceof Date) { return (Date) value; } if (this.isDate()) { if (value instanceof Number) { return new Date(((Number) value).longValue()); } else if (value instanceof String) { return DateUtil.parse((String) value); } } return null; }
@Override public BackendEntry writePropertyKey(PropertyKey propertyKey) { TableBackendEntry entry = newBackendEntry(propertyKey); entry.column(HugeKeys.ID, propertyKey.id().asLong()); entry.column(HugeKeys.NAME, propertyKey.name()); entry.column(HugeKeys.DATA_TYPE, propertyKey.dataType().code()); entry.column(HugeKeys.CARDINALITY, propertyKey.cardinality().code()); entry.column(HugeKeys.PROPERTIES, this.toLongSet(propertyKey.properties())); this.writeUserdata(propertyKey, entry); entry.column(HugeKeys.STATUS, propertyKey.status().code()); return entry; }
E.checkState(fields.size() == 1, "Invalid range index fields"); DataType dataType = graph.propertyKey(fields.get(0)).dataType(); E.checkState(dataType.isNumber() || dataType.isDate(), "Invalid range index field type"); Class<?> clazz = dataType.isNumber() ? dataType.clazz() : DataType.LONG.clazz(); values = bytes2number(buffer.read(id.length - labelLength), clazz);
DataType dataType = this.transaction.getPropertyKey(field) .dataType(); E.checkArgument(dataType.isNumber() || dataType.isDate(), "Range index can only build on numeric or " + "date property, but got %s(%s)", dataType, field); DataType dataType = this.transaction.getPropertyKey(field) .dataType(); E.checkArgument(dataType.isText(), "Search index can only build on text property, " + "but got %s(%s)", dataType, field);
private static <V> V validPredicateValue(V value, PropertyKey pkey) { V validValue = pkey.convValue(value, false); E.checkArgumentNotNull(validValue, "Invalid data type of query value, " + "expect '%s', actual '%s'", pkey.dataType().clazz(), value.getClass()); return validValue; }
public <V> UUID valueToUUID(V value) { if (value instanceof UUID) { return (UUID) value; } if (this.isUUID() && value instanceof String) { return java.util.UUID.fromString((String) value); } return null; } }
public <V> Date valueToDate(V value) { if (value instanceof Date) { return (Date) value; } if (this.isDate()) { if (value instanceof Number) { return new Date(((Number) value).longValue()); } else if (value instanceof String) { try { return HugeGraphSONModule.DATE_FORMAT.parse((String) value); } catch (ParseException e) { E.checkArgument(false, "%s, expect format: %s", e.getMessage(), HugeGraphSONModule.DATE_FORMAT.toPattern()); } } } return null; }
@Override public BackendEntry writePropertyKey(PropertyKey propertyKey) { TableBackendEntry entry = newBackendEntry(propertyKey); entry.column(HugeKeys.ID, propertyKey.id().asLong()); entry.column(HugeKeys.NAME, propertyKey.name()); entry.column(HugeKeys.DATA_TYPE, propertyKey.dataType().code()); entry.column(HugeKeys.CARDINALITY, propertyKey.cardinality().code()); entry.column(HugeKeys.PROPERTIES, this.toLongSet(propertyKey.properties())); this.writeUserdata(propertyKey, entry); entry.column(HugeKeys.STATUS, propertyKey.status().code()); return entry; }
private <V> V convSingleValue(V value) { if (this.dataType().isNumber()) { @SuppressWarnings("unchecked") V number = (V) this.dataType().valueToNumber(value); return number; } else if (this.dataType().isDate()) { @SuppressWarnings("unchecked") V date = (V) this.dataType().valueToDate(value); return date; } else if (this.dataType().isUUID()) { @SuppressWarnings("unchecked") V uuid = (V) this.dataType().valueToUUID(value); return uuid; } return value; }
/** * Check type of the value valid * @param value the property value to be checked data type * @return true if the value is or can convert to the data type, * otherwise false */ public <V> boolean checkDataType(V value) { if (value instanceof Number) { return this.dataType().valueToNumber(value) != null; } return this.dataType().clazz().isInstance(value); }
protected void parseProperty(Id key, String colValue, HugeElement owner) { // Get PropertyKey by PropertyKey name PropertyKey pkey = owner.graph().propertyKey(key); // Parse value Object value = JsonUtil.fromJson(colValue, pkey.clazz()); // Set properties of vertex/edge if (pkey.cardinality() == Cardinality.SINGLE) { owner.addProperty(pkey, value); } else { if (!(value instanceof Collection)) { throw new BackendException( "Invalid value of non-single property: %s", value); } for (Object v : (Collection<?>) value) { v = JsonUtil.castNumber(v, pkey.dataType().clazz()); owner.addProperty(pkey, v); } } }