vendredi 18 décembre 2015

Android ORMLite query for all is taking quite some time to load

Inside my activity, I'm loading all Objects for one of my tables called "Person".

Previously, I did a queryForAll, but realised this should not be used if data gets too big. I'm loading about 73 objects from my Person table which has a Foreign Collection eager loaded to a max level of 1 and that Foreign Collection also has it's own Foreign Collection with the same eager loading configuration.

I tried to change my code using an iterator() but I don't feel any difference in speed.

The code can be seen below:

Dao<Person, Long> personDao = databaseHelper.getPersonDao();
CloseableIterator<Person> iterator = personDao.closeableIterator();
     try {
          while (iterator.hasNext()) {
               Person person = iterator.next();
               person.add(person);
          }
     } finally {
          iterator.close();
     }

I have a list of 63 Person Objects and it's taking an average of around 6-7 seconds to load.

To show my Person Object table structure, I'll show it here (This code excluded the eager = true and changed it to false)

public class Person implements  Serializable{

@DatabaseField(id = true, canBeNull = false, columnName = "id")
private long id;

@DatabaseField
private long parentPersonId;

@DatabaseField(canBeNull = true, foreign = true, foreignAutoRefresh = true)
private Job job;

@DatabaseField
private Integer flags = 0;

@ForeignCollectionField(eager = false)
private Collection<Siblings> siblings = new ArrayList<>();

@DatabaseField(canBeNull = true, foreign = true, foreignAutoRefresh = true)
private Car car;

@DatabaseField(columnName = "parent", foreign = true, foreignAutoCreate = true, foreignAutoRefresh = true)
private Person parent;

@ForeignCollectionField(eager = false)
private Collection<Person> childPersons;

@DatabaseField(canBeNull = true, foreign = true, foreignAutoRefresh = true)
private PersonData personData;

@DatabaseField
private int age;

@DatabaseField
private Date timeStamp;

Not sure what I'm missing here...I'm assuming it's probably my data structure. If you notice, the Person table has a foreign entity of itself. Could this be a problem?

Aucun commentaire:

Enregistrer un commentaire