forked from hugegraph/hugegraph
Fix can't insert data with List<Date> property (#534)
Change-Id: I232ab865e5599b6994955f671607696dd24a1d8c
This commit is contained in:
parent
0061d4f159
commit
0b5a702685
|
|
@ -19,7 +19,7 @@
|
|||
<dependency>
|
||||
<groupId>com.baidu.hugegraph</groupId>
|
||||
<artifactId>hugegraph-common</artifactId>
|
||||
<version>1.6.2</version>
|
||||
<version>1.6.3</version>
|
||||
</dependency>
|
||||
|
||||
<!-- tinkerpop -->
|
||||
|
|
|
|||
|
|
@ -168,7 +168,7 @@ public class BinarySerializer extends AbstractSerializer {
|
|||
PropertyKey pkey = owner.graph().propertyKey(pkeyId);
|
||||
|
||||
// Parse value
|
||||
Object value = KryoUtil.fromKryo(val, pkey.clazz());
|
||||
Object value = KryoUtil.fromKryo(val, pkey.implementClazz());
|
||||
|
||||
// Set properties of vertex/edge
|
||||
if (pkey.cardinality() == Cardinality.SINGLE) {
|
||||
|
|
|
|||
|
|
@ -96,7 +96,7 @@ public abstract class TableSerializer extends AbstractSerializer {
|
|||
PropertyKey pkey = owner.graph().propertyKey(key);
|
||||
|
||||
// Parse value
|
||||
Object value = JsonUtil.fromJson(colValue, pkey.clazz());
|
||||
Object value = JsonUtil.fromJson(colValue, pkey.implementClazz());
|
||||
|
||||
// Set properties of vertex/edge
|
||||
if (pkey.cardinality() == Cardinality.SINGLE) {
|
||||
|
|
|
|||
|
|
@ -123,7 +123,7 @@ public class TextSerializer extends AbstractSerializer {
|
|||
PropertyKey pkey = owner.graph().propertyKey(readId(colParts[1]));
|
||||
|
||||
// Parse value
|
||||
Object value = JsonUtil.fromJson(colValue, pkey.clazz());
|
||||
Object value = JsonUtil.fromJson(colValue, pkey.implementClazz());
|
||||
|
||||
// Set properties of vertex/edge
|
||||
if (pkey.cardinality() == Cardinality.SINGLE) {
|
||||
|
|
|
|||
|
|
@ -24,7 +24,6 @@ import java.util.Collection;
|
|||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
|
@ -84,7 +83,24 @@ public class PropertyKey extends SchemaElement implements Propfiable {
|
|||
return this;
|
||||
}
|
||||
|
||||
public Class<?> clazz() {
|
||||
public String clazz() {
|
||||
String dataType = this.dataType().clazz().getSimpleName();
|
||||
switch (this.cardinality) {
|
||||
case SINGLE:
|
||||
return dataType;
|
||||
// A set of values: Set<DataType>
|
||||
case SET:
|
||||
return String.format("Set<%s>", dataType);
|
||||
// A list of values: List<DataType>
|
||||
case LIST:
|
||||
return String.format("List<%s>", dataType);
|
||||
default:
|
||||
throw new AssertionError(String.format(
|
||||
"Unsupported cardinality: '%s'", this.cardinality));
|
||||
}
|
||||
}
|
||||
|
||||
public Class<?> implementClazz() {
|
||||
Class<?> cls;
|
||||
switch (this.cardinality) {
|
||||
case SINGLE:
|
||||
|
|
@ -96,7 +112,7 @@ public class PropertyKey extends SchemaElement implements Propfiable {
|
|||
break;
|
||||
// A list of values: List<DataType>
|
||||
case LIST:
|
||||
cls = LinkedList.class;
|
||||
cls = ArrayList.class;
|
||||
break;
|
||||
default:
|
||||
throw new AssertionError(String.format(
|
||||
|
|
@ -177,6 +193,16 @@ public class PropertyKey extends SchemaElement implements Propfiable {
|
|||
return validValue;
|
||||
}
|
||||
|
||||
public <V> V validValueOrThrow(V value) {
|
||||
V validValue = this.validValue(value);
|
||||
E.checkArgument(validValue != null,
|
||||
"Invalid property value '%s' for key '%s', " +
|
||||
"expect a value of type %s, actual type %s",
|
||||
value, this.name(), this.clazz(),
|
||||
value.getClass().getSimpleName());
|
||||
return validValue;
|
||||
}
|
||||
|
||||
public <V> V validValue(V value) {
|
||||
return this.convValue(value, true);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -213,24 +213,14 @@ public abstract class HugeElement implements Element, GraphType {
|
|||
this.setProperty(property);
|
||||
}
|
||||
|
||||
Collection<V> values = null;
|
||||
if (value instanceof Collection) {
|
||||
values = (Collection<V>) value;
|
||||
} else if (value.getClass().isArray()) {
|
||||
Collection<V> values;
|
||||
if (pkey.cardinality() == Cardinality.SET) {
|
||||
values = CollectionUtil.toSet(value);
|
||||
} else {
|
||||
assert pkey.cardinality() == Cardinality.LIST;
|
||||
values = CollectionUtil.toList(value);
|
||||
}
|
||||
|
||||
if (values != null) {
|
||||
E.checkArgument(pkey.checkDataType(values),
|
||||
"Invalid type of property values %s for key '%s'",
|
||||
value, pkey.name());
|
||||
property.value().addAll(values);
|
||||
} else {
|
||||
E.checkArgument(pkey.checkDataType(value),
|
||||
"Invalid type of property value '%s' for key '%s'",
|
||||
value, pkey.name());
|
||||
property.value().add(value);
|
||||
}
|
||||
property.value().addAll(pkey.validValueOrThrow(values));
|
||||
|
||||
// Any better ways?
|
||||
return (HugeProperty) property;
|
||||
|
|
|
|||
|
|
@ -42,16 +42,7 @@ public abstract class HugeProperty<V> implements Property<V>, GraphType {
|
|||
|
||||
this.owner = owner;
|
||||
this.pkey = pkey;
|
||||
this.value = pkey.validValue(value);
|
||||
|
||||
if (this.value == null) {
|
||||
E.checkArgument(false,
|
||||
"Invalid property value '%s' for key '%s', " +
|
||||
"expect a value of type %s, actual type %s",
|
||||
value, pkey.name(),
|
||||
pkey.clazz().getSimpleName(),
|
||||
value.getClass().getSimpleName());
|
||||
}
|
||||
this.value = pkey.validValueOrThrow(value);
|
||||
}
|
||||
|
||||
public PropertyKey propertyKey() {
|
||||
|
|
|
|||
Loading…
Reference in New Issue