Titan 0.5.1自定义节点中的对象

时间:2014-10-24 14:47:03

标签: titan

我对Titan 0.5.1有疑问。我尝试将Titan 0.4.4升级到0.5.1。目前,我使用berkeleyje,我配置如下:

BaseConfiguration conf = new BaseConfiguration();

// Storage info
conf.setProperty("storage.directory", directory + File.separator + DB_NAME);
conf.setProperty("storage.backend", "berkeleyje");

// Class info storage
conf.setProperty("attributes.allow-all", "true");
conf.setProperty("attributes.custom.attribute1.attribute-class", "model.Property");
conf.setProperty("attributes.custom.attribute1.serializer-class", "PropertySerializer");

TitanGraph graph = TitanFactory.open(conf);

为了序列化我的对象我使用:

public class PropertySerializer implements AttributeSerializer<Property> {

    @Override
    public Property read(ScanBuffer buffer) {
        Property object = null;
        ArrayList<Byte> records = new ArrayList<Byte>();

        try {
            while (buffer.hasRemaining()) {
                records.add(Byte.valueOf(buffer.getByte()));
            }

            Byte[] bytes = records.toArray(new Byte[records.size()]);

            ByteArrayInputStream bis = new ByteArrayInputStream(ArrayUtils.toPrimitive(bytes));
            ObjectInput in = new ObjectInputStream(bis);
            object = (Property) in.readObject();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }

        return object;
    }

    @Override
    public void write(WriteBuffer out, Property attribute) {
        try {
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            ObjectOutput outobj;

            outobj = new ObjectOutputStream(bos);

            outobj.writeObject(attribute);
            byte[] propertybyte = bos.toByteArray();

            for (int i = 0; i < propertybyte.length; i++) {
                out.putByte(propertybyte[i]);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void verifyAttribute(Property value) {
        // TODO Auto-generated method stub

    }

    @Override
    public Property convert(Object value) {
        // TODO Auto-generated method stub
        return null;
    }

}

通常,我添加如下属性:

Vertex r = this.model.addVertex(null);
Property p = new Property();
r.setProperty("object", p);
this.model.commit();

但是我得到了这个错误:

  

线程中的异常&#34; main&#34;   com.thinkaurelius.titan.core.TitanException:无法提交   因持久性异常而导致的事务   com.thinkaurelius.titan.graphdb.transaction.StandardTitanTx.commit(StandardTitanTx.java:1310)     在   com.thinkaurelius.titan.graphdb.blueprints.TitanBlueprintsGraph.commit(TitanBlueprintsGraph.java:60)      引起:com.thinkaurelius.titan.core.TitanException:Serializer   限制:无法序列化类型:class的对象   .model.Property at   com.thinkaurelius.titan.graphdb.database.serialize.StandardSerializer $ StandardDataOutput.writeClassAndObject(StandardSerializer.java:160)     在   com.thinkaurelius.titan.graphdb.database.EdgeSerializer.writePropertyValue(EdgeSerializer.java:383)     在   com.thinkaurelius.titan.graphdb.database.EdgeSerializer.writePropertyValue(EdgeSerializer.java:377)     在   com.thinkaurelius.titan.graphdb.database.EdgeSerializer.writeRelation(EdgeSerializer.java:293)     在   com.thinkaurelius.titan.graphdb.database.StandardTitanGraph.prepareCommit(StandardTitanGraph.java:485)     在   com.thinkaurelius.titan.graphdb.database.StandardTitanGraph.commit(StandardTitanGraph.java:613)     在   com.thinkaurelius.titan.graphdb.transaction.StandardTitanTx.commit(StandardTitanTx.java:1299)

你能帮帮我吗?因为,0.4.4版本有效。新文档对我没有帮助。

提前致谢

0 个答案:

没有答案