Forums

Get More Support

Here for you 24/7

learn more
VOD Free SDK

Start Building your Engine Now

Download Now
VOD Extranet

Access to patches, license management,
tech docs and more for existing VOD customers.

Learn More
Performance and design problems
Last Post 01 Mar 2013 09:11 AM by chris7topher. 2 Replies.
AddThis - Bookmarking and Sharing Button Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
chris7topher
New Member
New Member
Posts: 2


--
28 Feb 2013 09:00 AM

    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

     

    Vidisha Sharma
    New Member
    New Member
    Posts: 95


    --
    01 Mar 2013 06:45 AM
    Please go through the following: http://community.versant.com/docume...raints.htm
    chris7topher
    New Member
    New Member
    Posts: 2


    --
    01 Mar 2013 09:11 AM

    Thank you for your answer! I tried that, but there are two problems with unique fields:

    My first Problem is that I could have the same Parameternumber with different options. So I could not define the parameter number as unique. I must store several fields in one unique contraint. In SQLite I done that like that "UNIQUE (paramnr, write, access, ...) ON CONFLICT IGNORE" so that only if all fields are the same I got an on conflict error.

    Another problem is, that I have to commit each time then I store a parameter. But if I add more than 2000 parameter, this makes things extremly slow. The problem is, that more than 90% of the parameter are exactly the same. And each time, if the parameter is already in the database I have to search for the reference.

    Yesterday I found a solution, that works in 10s, but I don't think, that it is like "best practice":

         
            allParams = new ArrayList();
            for (Parameter p : db.query(Parameter.class)) {
                allParams.add(p);
            }           

    Befor I add a new device with several parameter to the database, I store all parameter existing in the database in an Arraylist. Than I look for each parameter with allParams.indexOf(newParam) if it's already there. I don't think that this is a good way to do that. But if I always query over the database I need over a minute. I think that there aren't all information in the memory. Is there a way to do this without an ArrayList in the same speed?

    Thanks & regards

    Christopher

    You are not authorized to post a reply.


    Active Forums 4.3