Hello,
I work on a db4o database, which should store parameters from different devices. My actually structure is like this:
public class Parameter {
public boolean write,...;
public int nr, access, hash ...;
public VaildValues vaildValues;
public VaildEnum vaildEnum;
public Parameter(int nr, boolean write, int access) {
this.nr = nr;
this.access = access;
this.write = write;
}
There are a lot more fields in that class. The fields VaildValues and VaildEnum are optional.
public class Device {
public int firmware;
public String type;
public List parameter;
public Device(int firmware, String type)
{
this.firmware = firmware;
this.type = type;
parameter = new ArrayList();
}
}
That's the class, which hold the parameter for the different devices.
My first problem is, that more devices could have the same parameter and I don't want to store the same parameter twice in the database. So I look for each parameter if it is already in the database befor putting it there:
Query query = db.query();
query.constrain(Parameter.class);
query.descend("nr").constrain(p.nr);
query.descend("hash").constrain(p.hash);
ObjectSet result = query.execute();
if (result.size() > 0) {
device.parameter.add(result.get(0));
}
else
device.parameter.add(p);
The hash is a field, there I hash over all elements in the Parameter.class, so that I only have to compare the parameter number and the hash value. To make things a little bit faster, I indexed the nr and index value. But to insert 1000 parameter, which are already in the database i need over 30 seconds.
Another problem is that every parameter have a label in english and german. But I don' t have a idea how to store that in a efficent way in relation to a parameter. I don't want to store it in a field in the parameter class. Because it could be that parameter that aren't exactly the same have the same label. So also here I don't want to store them twice in the database.
Before I work with dbo4 I stored the parameter in a SQLite database. There was an option, that I could define fields as "unique on confilct ignore" and if I add a parameter which is already in the database I got back the existing index of the parameter. That method was extrem fast and stable. Is there any function like that in db4o?
Thanks & Regards
Christopher