0

我在 Java 中有这个结构要使用 TupleSerialBinding 存储在 berkeley DB 中:

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>();
}

键是使用类创建的最小值以进行 EntryBinding。在我创建基于 SamplesValues 的 EntityBinding 之后

我没有找到如何使用 TupleSerialBinding 存储“值数组”。

存储 min 和 max 的值,但不存储 values 数组。

4

1 回答 1

2

我会为 SampleValues 类创建一个代理

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

实施

initializeProxy
convertProxy
newInstance

将 SampleValues 类转换为 SampleValuesProxy 类的实例方法。用一个简单的 [] 代替代理中的 ArrayList。

那么您需要使用 EntityModel 将代理注册为

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

并将模型放入 storeconfig

因此,当 berkleydb 去存储您的 SampleValues 对象时,它将其转换为代理类,并写入它(反之亦然)

看看班级

com.sleepycat.persist.impl.MapProxy

在 berkeleydb 源代码分发中获取有关如何实现它的示例。

于 2011-09-10T22:28:34.183 回答