English 中文(简体)
如何使用Dao.setAutoCommit()?
原标题:How to use Dao.setAutoCommit()?

I m parsing JSON from a services, using ORMLite to persistent Object to the database as Iread out. 这些档案可能非常庞大,因此,我认为是在阅读时发射物体,而不是读数以百计的物体以备记忆和进行大规模攻击(这在讲智能的人中是稀有的)。 然而,每个目标都将包含具有多种价值的收集(我试图为这些价值使用<代码>>ForeignCollection,因此每个数值都需作为单独目标处理),并且认为最好把所有物品一劳永逸地投在物体收集中,而不是在每一个人Sting或Integer上。

I believe that to make a group of commits in a batch, I would simply call dao.setAutoCommit(false), call dao.create() for each item, call dao.commit() afterwards and then call dao.setAutoCommit(true) to go back to piecemeal commits.

我有三个问题:

  1. Is it right to commit as I go, or should I to a batch commit--even if it means up to a thousand objects would get committed at once?
  2. Is it better to commit the collection of items one at a time, or in a batch?
  3. Where do I get the databaseConnection value from that dao.setAutoCommit() and dao.commit() require? Maybe I missed it, but I can t find it in the documentation or examples.
最佳回答

是否有权在我到场时作出承诺,或者如果这意味着一度会发生多达1 000件物体的话,我是否应当承诺承诺。

If you have a large number of items it may be better commit a couple of 100 objects at once instead of 1000s. It depends a lot on the size of the objects so running it with various different batch sizes and timing them would be a good thing to try. As you mention, you need to balance memory and database performance. I d be curious of the results so please comment with your timing data.

是否最好在某个时间或批次中收集物品?

最好在批量中做事。 我以前所努力的每一个数据库都是如此。

If you are talking about a foreign collection then there is really no difference between a foreign collection of objects and a large list of objects that you want to create. Both will benefit from batching.

我不会在每一物体创建后投入使用。 我大打了100件外物体和它们拥有的任何外国物体。 然后对100人做出修改,然后是100人。 然后,将100至200条改为50条。 你们应当看到偏袒点。

Did I answer this one right?

在什么地方,我从dao.setAutoCommit(dao.commit()中获取数据库Connection值? 也许我错过了,但我可以在文件或实例中发现。

Edit #2:

正如@Chad所指出的,我错误地建议使用安的汽车。 虽然Sqlite司机通常通过开始交易和在进行交易时承诺支持汽车开关。 但安乐团似乎不支持这一点。 在信安数据库链接中,该代码是一环。

在Anderson,与ORMLite共同开展批量任务的恰当方式是使用:dao.newBatchTasks(Callable)。 类似:

accountDao.callBatchTasks(connectionSource,
  new Callable<Void>() {
    public Void call() throws SQLException {
        // insert a number of accounts at once
        for (Account account : accountsToInsert) {
           // update our account object
           accountDao.create(account);
        }
        return null;
    }
});
问题回答

暂无回答




相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签