在titan图中配置自定义属性序列化程序时出现java.lang.IllegalStateException

时间:2015-02-23 08:01:40

标签: illegalstateexception titan java.util.date serializer

我正在尝试为titan图编写一个自定义的java.util.Date序列化程序。这是我的泰坦配置文件:

attributes.allow-all = true
attributes.custom.attribute1.attribute-class = java.util.Date
attributes.custom.attribute1.serializer-class = com.serializer.MyDateSerializer

我的序列化器看起来像:

public class MyDateSerializer implements AttributeSerializer<Date> {
    @Override
    public void verifyAttribute(Date value) {
        // TODO Auto-generated method stub
    }
    @Override
    public Date convert(Object value) {
        // TODO Auto-generated method stub
        return null;
    }
    @Override
    public Date read(ScanBuffer buffer) {
        // TODO Auto-generated method stub
    }
    @Override
    public void write(WriteBuffer buffer, Date date) {
        // TODO Auto-generated method stub
    }
}

但是在打开TitanGraph后,我得到以下例外:

java.lang.IllegalStateException: Need to set configuration value: root.attributes.custom.serializer-class
at com.google.common.base.Preconditions.checkState(Preconditions.java:177)
at com.thinkaurelius.titan.diskstorage.configuration.ConfigOption.get(ConfigOption.java:158)
at com.thinkaurelius.titan.diskstorage.configuration.BasicConfiguration.get(BasicConfiguration.java:56)
at com.thinkaurelius.titan.graphdb.configuration.GraphDatabaseConfiguration.<init>(GraphDatabaseConfiguration.java:1334)
at com.thinkaurelius.titan.core.TitanFactory.open(TitanFactory.java:91)
at com.thinkaurelius.titan.core.TitanFactory.open(TitanFactory.java:71)

以下是我尝试从属性文件中读取配置的方法:

        BaseConfiguration configuration = new BaseConfiguration();
        Properties properties = new Properties();
        properties.load(getClass().getResourceAsStream(
                "/titanConfiguration.properties"));
        Set<Entry<Object, Object>> entrySet = properties.entrySet();

        for (Entry<Object, Object> entry : entrySet) {
            configuration.setProperty(entry.getKey().toString(), entry
                    .getValue().toString());
        }

我已经浏览了版本0.5.2的titan图形文档,但我无法弄清楚问题。我也经历过类似的帖子,但我仍然无法解决这个问题。以前有人遇到过这个问题吗?

如果我尝试将titan顶点中的java.util.Date持久化,如下所示:

vertex.setProperty("myDate",new Date());

然后当我尝试从顶点检索Date时:

((Date)vertex.getProperty("myDate"));

我得到以下异常:

java.lang.ClassCastException: java.lang.String cannot be cast to java.util.Date
at org.rampal.Transaction.getUsers(Transaction.java:179)
at org.rampal.Controller.getUsers(Controller.java:71)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)

1 个答案:

答案 0 :(得分:0)

您无法覆盖日期处理,因为Titan中已包含默认处理程序。

使用你的指示和Titan 0.5.2,你得到:

java.lang.IllegalArgumentException: DataType has already been registered: class java.util.Date

您收到的错误消息含糊不清,除非我指定的自定义属性不是从数字1开始,否则不会发生。例如:

attributes.allow-all = true
attributes.custom.attribute10.attribute-class = java.util.Date
attributes.custom.attribute10.serializer-class = com.serializer.MyDateSerializer

将导致:

java.lang.IllegalStateException: Need to set configuration value: root.attributes.custom.serializer-class