0

I'm new to Ormlite integration but managed to make it work on a learning project (android app)

The issue that I'm facing is a performance + conceptual one .

I'm using Jackson to get a list of Center objects then use ORMLite to persist everything into DB .

My Center object has two ForeignCollectionField , my annotations are correct and with the above code I can get a correct "join" of the wastes that this center can handle and the nature of the center it self .

I can check my DB using an sqlite editor and it seems fine.

The problem is that it takes about 8mn to populate the data base with the 4000objects which is a bit long .

Here is a portion of the code used in my asyncTask(this code works well)

Center[] c = new Center[0];
//fill c with Center objects from jackson OK
assert pCenterDao != null;

for(final Center center : c) {
    try {
        pCenterDao.create(center);

        for (CenterTypesItem typesItem : center.getCenterTypesCollection()) {
            CenterTypesItem centerTypesItem = new CenterTypesItem(typesItem.getId(),center);
            pCenterTypesItemDao.createOrUpdate(centerTypesItem);
        }

        for (CenterWastesItem wastesItem : center.getWastesCollection()) {
            CenterWastesItem centerWasteItem = new CenterWastesItem(wastesItem.getId(),center);
            pCenterWastesItemDao.createOrUpdate(centerWasteItem);
        }

        count = pCenterDao.countOf();
        publishProgress(count, Long.valueOf(c.length));

    } catch (SQLException e) {
        e.printStackTrace();
        result = false ;
    }

    if (isCancelled()){
        result = false ;
        break;
    }
}

As you can see I have two FOR loops inside a main FOR loop (not very clever) , can you please tell me how to optimize and correct this . @Gray please help :) Thank you

Pozzo Apps
  • 1,859
  • 2
  • 22
  • 32
moujib
  • 742
  • 2
  • 7
  • 26

1 Answers1

1

you should use callBatchTasks method. It permit to improve the speed.

You have a good explication here :

ORMLite's createOrUpdate seems slow - what is normal speed?

and a good example here :

Android ORMLite slow create object

Community
  • 1
  • 1
Eliott Roynette
  • 716
  • 8
  • 21