开发者

How can I store an ArrayList field in a Java Berkeley DB?

I have this structure in Java to be stored in berkeley DB using TupleSerialBinding:

public class SampleValues implements Serializable, MarshalledEntity {
private static final long serialVersionUID = 1L;

    protected double min;
    protected double max;

    protected ArrayList<Double> values = new ArrayList<Double>();
}

The key is the min value which is created using a class to make an EntryBinding. After I 开发者_StackOverflow中文版create an EntityBinding based on SamplesValues

I didn't find how to store the "values array" using TupleSerialBinding.

The values of min and max are stored, but the values array is not.


I would create a Proxy for the SampleValues class as

@Persistent(proxyFor = SampleValues.class)
public class SampleValuesProxy implements PersistentProxy<SampleValues>, Serializable {
    ....
}

implementing the

initializeProxy
convertProxy
newInstance

instance methods to convert your SampleValues class to a SampleValuesProxy class. Substituting a simple [] for the ArrayList in the proxy.

then you need to register the proxy with the EntityModel as

EntityModel model = new AnnotationModel();
model.registerClass(SampleValuesProxy.class);

and put the model in the storeconfig

So then when berkleydb goes to store your SampleValues object, it converts it to the proxy class, and writes it (and when reading vice-versa)

Look at the class

com.sleepycat.persist.impl.MapProxy

in the berkeleydb source distribution for an example on how to implement it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜