Hey guys,
I'm developing a MIDlet that uses floggy. I'm storing information about people with floggy with a class called Person.
The class is of course persistable. The Person object has a Version member which determines the current version of the Person object.
When the application is requested to check for an update, it reads an XML file on the device and parses the data into Person objects and puts them in a Vector.
This works perfectly (the process of parsing an XML file to a Vector of Persons, that is). My update algorithm is as follows:
1. Fetch a Person from the Vector
2. If the Person doesn't exists* in the floggy database, add it
3. If the Person does exists* in the floggy database, check the version of it
4. If the version of the Person in the floggy database is lower than the version of the Person fetched, update the floggy database to contain the newest version.
* Person objects are compared by an ID member
The algorithm works well, but as it progresses (in terms of iterations), it gets slower and slower -
for example, it finishes the first few iterations in less than a second, but each iteration after the 50th one takes more than 15 seconds and so forth.
This is the update algorithm function:
public void performDataUpdate(Vector data) {
if (null == data || data.isEmpty()) {
return;
}
for (int i = 0; i < data.size(); i++) {
if (data.elementAt(i).getClass().equals(Person.class)) {
try {
Person person= (Person)data.elementAt(i);
int local_person_version = getPersonVersionByID(person.getID());
if (0 >= local_person_version) { //this means that the Person doesn't exists in the DB
this.saveToDb(person);
} else {
if (local_person_version < person.getVersion()) {
try {
this.deletePersonByID(person.getID());
this.saveToDb(pesron);
} catch (Exception ignored) {}
}
}
// help the gc
person = null;
} catch (Exception ignored) {}
}
I checked, and the line that causes this to get slower and slower by the iteration is:
int local_person_version = getPersonVersionByID(person.getID());
Here is the code of the function getPersonByID:
public int getPersonVersionByID(String id) {
try {
Person person = new Person();
ObjectSet persons = m_pm.find(Person.class, null, null);
if (null == persons) {
return 0;
}
for (int i = 0; i < persons.size(); i++) {
persons.get(i, person);
if (id.equals(person.getID())) {
return person.getVersion();
}
}
}
catch (Exception ignored) {}
return 0;
}
All exception are ignored for the sake of this example, but not in my real code (and non are being thrown).
Anyone has a clue what could be done in order to improve the performance of this? It takes 15 minutes for the MIDlet to go over 100 "Persons" where as it finishes the first 10 in 5 seconds..
Thanks!

Reply With Quote


