Back to project page campus.
The source code is released under:
GNU General Public License
If you think the Android project campus listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package lecho.app.campus.utils; /*from w w w . j av a 2 s . c o m*/ import lecho.app.campus.dao.DaoMaster; import lecho.app.campus.dao.DaoMaster.DevOpenHelper; import lecho.app.campus.dao.DaoSession; import android.content.Context; /** * Use this class to get DevOpenHelper, DaoMaster or DaoSession instance. * * @author Lecho * */ public abstract class DatabaseHelper { public static final String DB_NAME = "campus_db"; // Single DevOpenHelper means single db connection. private static DevOpenHelper sDevOpenHelper; // Single DaoMaster means single db connection. private static DaoMaster sDaoMaster; private static DaoSession sDaoSession; public static DevOpenHelper getDevOpenHelper(Context context) { if (null == sDevOpenHelper) { sDevOpenHelper = new DevOpenHelper(context, DB_NAME, null); } return sDevOpenHelper; } public static DaoMaster getDaoMaster(Context context) { if (null == sDaoMaster) { sDaoMaster = new DaoMaster(getDevOpenHelper(context).getWritableDatabase()); } return sDaoMaster; } /** * Returns always the same read/write session instance. Bleh... no double instance checking, not final, not enum:) * * @param context * @return */ public static DaoSession getDaoSession(Context context) { if (null == sDaoSession) { sDaoSession = getDaoMaster(context).newSession(); } return sDaoSession; } public static void clearDB(Context context) { DaoSession daoSession = getDaoSession(context); daoSession.getPlaceCategoryDao().deleteAll(); daoSession.getPlaceFacultyDao().deleteAll(); daoSession.getPlaceUnitDao().deleteAll(); daoSession.getPlaceDao().deleteAll(); daoSession.getFacultyDao().deleteAll(); daoSession.getCategoryDao().deleteAll(); daoSession.getUnitDao().deleteAll(); } }