greenrobot / greenDAO

greenDAO is a light & fast ORM solution for Android that maps objects to SQLite databases.
http://greenrobot.org/greendao/
12.63k stars 2.89k forks source link

should i declare a method for writing in db as synchronized? #604

Closed j386621930 closed 7 years ago

j386621930 commented 7 years ago

I have declared a method in my wrapper class for GreenDAO.

private boolean handleAddNewScreenInfo (List<ScreenInfo> screenInfoList) {
       ...
        ScreenInfoDBDao siDBDao = mDaoSession.getScreenInfoDBDao();
        for (ScreenInfo si : screenInfoList) {
            ScreenInfoDB siDB = encapsulateScreenInfoDBDaoItem(si);
            siDBDao.insertOrReplace(siDB);
        }
        ...
    }

should I declare this method as synchronized?

BTW, should I explicitly close my GreenDao sessions and DaoMaster when my application is closed?

thanks.

greenrobot-team commented 7 years ago

No, SQLite and therefore greenDAO is thread-safe. You only have to be careful with queries and be aware that greenDAO caches entities.

When your app is closed (by the user or Android), Android will clean up for you.

Note: There is a basic example app to help get you started. -ut