0

I have a data model almost identical to the one described in this link - where an object contains a list of another object. And in this case, that object contains a list of another.

When I get my data from the server, I set the references in each side of the objects:

final Dao<SurveyQuestion, Integer> questionDao = Db.get().getTableDao(SurveyQuestion.class);
final Dao<SurveyAnswer, Integer> answerDao = Db.get().getTableDao(SurveyAnswer.class);
for (final Action action : actions) {
    tableDao.createOrUpdate(action);
    for (final SurveyQuestion question : action.getQuestions()) {
        question.setAction(action);
        questionDao.createOrUpdate(question);
        for (final SurveyAnswer answer : question.getAnswers()) {
            answer.setQuestion(question);
            answerDao.createOrUpdate(answer);
        }
    }
}

So I'm calling 'createOrUpdate' on three different tables. The server returns around 300 Action objects, and this is taking around 40-50 seconds to save.

I'm new to Ormlite, so would like to know if it's possible to improve this routine so that it saves much more quickly.

Community
  • 1
  • 1
androidneil
  • 880
  • 1
  • 10
  • 21
  • possible duplicate of [ORMLite's createOrUpdate seems slow - what is normal speed?](http://stackoverflow.com/questions/11761472/ormlites-createorupdate-seems-slow-what-is-normal-speed) – Eugen Martynov Aug 27 '14 at 15:46
  • Also you can try `TransactionManager` (http://ormlite.com/javadoc/ormlite-core/com/j256/ormlite/misc/TransactionManager.html) – Eugen Martynov Aug 27 '14 at 15:46
  • Oh wow, using callBatchTasks has taken it down to almost 2 seconds! Thanks for pointing me in the right direction. How do I 'accept' your answer? – androidneil Aug 27 '14 at 16:09
  • Your question is duplicate for provided link. I would suggest you to search similar question before asking question. I'm glad that you resolved issue! – Eugen Martynov Aug 27 '14 at 16:17
  • Also exactly the same than http://stackoverflow.com/questions/25549940/ormlite-object-creation-with-foreigncollectionfield/25563847#25563847 – Eliott Roynette Sep 01 '14 at 07:45

0 Answers0