0

I would serialize an basic Object in Titan Database. But doesnt work. I want serialize my object for register it in my titan database. But i don't understand why there is this problem. i post my source code and if you have a documentation it is with pleasure that I accept.

Typically i create my object :

public class Attribute implements KryoSerializable {

    private String typeunit;

    private Object value;

    private String valueS;


    public Attribute() {
        this.typeunit = "";
        this.value = null;
        this.valueS = "";
    }


    public void setValue(String type, Object value) {
        this.typeunit = type;
        this.value = value;

        try {
            if(value instanceof java.lang.String) {
                this.valueS = (String) value;
            }
        } catch(Exception e) {

        }
    }

    public Object getValue() {
        return value;
    }

    public String getValueS() {
        return valueS;
    }

    public String getTypeunit() {
        return typeunit;
    }

    @Override
    public boolean equals(Object obj) {
        // TODO Auto-generated method stub
        return super.equals(obj);
    }

    public void read(Kryo kryo, Input input) {
        this.typeunit = input.readString();
        this.value = kryo.readObject(input, Object.class);
        this.valueS = input.readString();
    }

    public void write(Kryo kryo, Output output) {
        kryo.register(Object.class);

        output.writeString(this.typeunit);
        kryo.writeObject(output, this.value);
        output.writeString(this.valueS);
    }

}

And after i try this :

Vertex r = this.model.addVertex(null);
r.setProperty("uuid", UUID.randomUUID().toString());
r.setProperty("object", attr);

this.model.commit();

for(Vertex vertex : this.model.query().vertices()) { 
     Attribute test = vertex.getProperty("object");
     System.out.println(test.getTypeunit());
}

But i have an exception :

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: -2
    at java.util.ArrayList.elementData(ArrayList.java:400)
    at java.util.ArrayList.get(ArrayList.java:413)
    at com.esotericsoftware.kryo.util.MapReferenceResolver.getReadObject(MapReferenceResolver.java:42)
    at com.esotericsoftware.kryo.Kryo.readReferenceOrNull(Kryo.java:773)
    at com.esotericsoftware.kryo.Kryo.readObject(Kryo.java:624)
    at XXXX.XXXXXX.Attribute.read(Attribute.java:140)
    at com.esotericsoftware.kryo.serializers.DefaultSerializers$KryoSerializableSerializer.read(DefaultSerializers.java:363)
    at com.esotericsoftware.kryo.serializers.DefaultSerializers$KryoSerializableSerializer.read(DefaultSerializers.java:355)
    at com.esotericsoftware.kryo.Kryo.readClassAndObject(Kryo.java:729)
    at com.thinkaurelius.titan.graphdb.database.serialize.kryo.KryoSerializer.readClassAndObject(KryoSerializer.java:119)
    at com.thinkaurelius.titan.graphdb.database.EdgeSerializer.parseRelation(EdgeSerializer.java:211)
    at com.thinkaurelius.titan.graphdb.database.EdgeSerializer.readRelation(EdgeSerializer.java:119)
    at com.thinkaurelius.titan.graphdb.database.EdgeSerializer.readRelation(EdgeSerializer.java:59)
    at com.thinkaurelius.titan.graphdb.transaction.StandardTitanTx$4$3.apply(StandardTitanTx.java:780)
    at com.thinkaurelius.titan.graphdb.transaction.StandardTitanTx$4$3.apply(StandardTitanTx.java:777)
    at com.google.common.collect.Iterators$8.transform(Iterators.java:860)
    at com.google.common.collect.TransformedIterator.next(TransformedIterator.java:48)
    at com.thinkaurelius.titan.graphdb.query.LimitAdjustingIterator.next(LimitAdjustingIterator.java:55)
    at com.thinkaurelius.titan.graphdb.query.QueryProcessor$OuterIterator.nextInternal(QueryProcessor.java:76)
    at com.thinkaurelius.titan.graphdb.query.QueryProcessor$OuterIterator.<init>(QueryProcessor.java:65)
    at com.thinkaurelius.titan.graphdb.query.QueryProcessor.iterator(QueryProcessor.java:46)
    at com.thinkaurelius.titan.graphdb.vertices.AbstractVertex.getProperty(AbstractVertex.java:105)
    at com.thinkaurelius.titan.graphdb.vertices.AbstractVertex.getProperty(AbstractVertex.java:121)

Can you help me please ?

Thanks you.

AkrogAmes
  • 45
  • 9
  • Please post your `Configuration` or properties file that you are giving to `TitanFactory.open()`. – stephen mallette Jul 10 '14 at 15:27
  • Ok stephen.Thank you. It's just a basic properties file : storage.backend=persistit storage.directory=/tmp/titanexample storage.buffercount=5000 – AkrogAmes Jul 10 '14 at 16:08

2 Answers2

1

Please look at the documentation for how to define custom serializers:

https://github.com/thinkaurelius/titan/wiki/Datatype-and-Attribute-Serializer-Configuration

There are configuration options that are required for this to work and requirements for your serializers It doesn't sound like you have much of that in place at the moment.

stephen mallette
  • 45,298
  • 5
  • 67
  • 135
  • My attribute class have a no-argument constructor, implement the equals(Object) method and KryoSerializable. I've read the page that tells me you. – AkrogAmes Jul 10 '14 at 16:34
  • do you have `attributes.allow-all` set? – stephen mallette Jul 10 '14 at 17:40
  • I am sorry stephen. We will continue tomorrow. Thanks you – AkrogAmes Jul 10 '14 at 22:32
  • Hello stephen, how are you ? So, i am sorry but i dont understand why i must set attributes.allow-all to true, because by default it's true... Then, must i to implement KryoSerializable in my Attribute class with read and write method ? – AkrogAmes Jul 14 '14 at 18:42
  • you're right - it is true by default. not sure what's wrong here then. will have to do more research. – stephen mallette Jul 14 '14 at 19:06
0

As an addition to the answer by @stephen mallette:

Titan uses a number of its own custom serializers, so you need to specify a sufficiently large number in the configuration, e.g. attributes.attribute20 = ... Note that there are no brackets around the index (that's why you were getting NumberFormatException).

gcvt
  • 1,482
  • 13
  • 15