2015-02-23 43 views
0

我正在尝试为泰坦图编写一个自定义java.util.Date序列化器。这里是我的泰坦配置文件:在titan图中配置自定义属性序列化器时发生java.lang.IllegalStateException

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版本的泰坦图形文档,但Iam无法找出问题所在。我也经历了类似的帖子,但我仍然无法解决这个问题。有没有人遇到过这个问题?

如果我试图坚持巨头顶点内java.util.Date如下:

vertex.setProperty("myDate",new 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) 

回答

0

您不能覆盖日期处理,因为已经存在泰坦包含默认处理程序。

使用您的指示,泰坦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 
+0

感谢您的答复。当我将日期保存到顶点(vertex.setProperty(“date”,new Date()))时,获取的日期是classcast异常,说明java.lang.String不能转换为java.util.Date。这就是为什么我有动力编写一个序列化程序。任何想法在直接在顶点中保存新的Date()时会出现什么问题? – user3244615 2015-03-09 11:39:04

+0

你有堆栈跟踪吗? – Bryn 2015-03-09 13:44:15

+0

我已经用堆栈跟踪更新了帖子 – user3244615 2015-03-10 08:01:09

相关问题