@@ -0,0 +1,2077 @@
+package com.appacts.plugin.DB;%0A%0Aimport java.util.concurrent.atomic.AtomicInteger;%0A%0Aimport android.database.sqlite.SQLiteDatabase;%0Aimport android.database.sqlite.SQLiteOpenHelper;%0A%0A/**%0A * @author lixiaoqing%0A */%0Apublic class DBManager %7B%0A%0A%09private static AtomicInteger writableCounter = new AtomicInteger();%0A%09private static AtomicInteger readableCounter = new AtomicInteger();%0A%09private static DBManager instance;%0A%09private static SQLiteOpenHelper myHelper;%0A%09private SQLiteDatabase writableDatabase;%0A%09private SQLiteDatabase readableDatabase;%0A%0A%09public static synchronized DBManager getInstance(SQLiteOpenHelper helper) %7B%0A%0A%09%09if (instance == null) %7B%0A%09%09%09instance = new DBManager();%0A%09%09%09myHelper = helper;%0A%09%09%7D%0A%09%09return instance;%0A%09%7D%0A%0A%09public SQLiteDatabase getWritableDatabase() %7B%0A%09%09return closeOrOpenWritableDatabase(true);%0A%09%7D%0A%0A%09public void closeWritableDatabase() %7B%0A%09%09closeOrOpenWritableDatabase(false);%0A%09%7D%0A%0A%09public SQLiteDatabase getReadableDatabase() %7B%0A%09%09return closeOrOpenReadableDatabase(true);%0A%09%7D%0A%0A%09public void closeReadableDatabase() %7B%0A%09%09closeOrOpenReadableDatabase(false);%0A%09%7D%0A%0A%09/**%0A%09 * close or open writable database%0A%09 * %0A%09 * @param operateType%0A%09 *            true:open, false:close%0A%09 * @return%0A%09 */%0A%09private synchronized SQLiteDatabase closeOrOpenWritableDatabase(boolean operateType) %7B%0A%0A%09%09if (true == operateType) %7B%0A%0A%09%09%09if (writableCounter.incrementAndGet() == 1) %7B%0A%09%09%09%09writableDatabase = myHelper.getWritableDatabase();%0A%09%09%09%7D%0A%09%09%09return writableDatabase;%0A%0A%09%09%7D else %7B%0A%0A%09%09%09if (writableCounter.decrementAndGet() == 0) %7B%0A%09%09%09%09writableDatabase.close();%0A%09%09%09%7D%0A%09%09%09return null;%0A%09%09%7D%0A%09%7D%0A%0A%09/**%0A%09 * close or open readable database%0A%09 * %0A%09 * @param operateType%0A%09 *            true:open, false:close%0A%09 * @return%0A%09 */%0A%09private synchronized SQLiteDatabase closeOrOpenReadableDatabase(boolean operateType) %7B%0A%0A%09%09if (true == operateType) %7B%0A%0A%09%09%09if (readableCounter.incrementAndGet() == 1) %7B%0A%09%09%09%09readableDatabase = myHelper.getReadableDatabase();%0A%09%09%09%7D%0A%09%09%09return readableDatabase;%0A%0A%09%09%7D else %7B%0A%0A%09%09%09if (readableCounter.decrementAndGet() == 0) %7B%0A%09%09%09%09readableDatabase.close();%0A%09%09%09%7D%0A%09%09%09return null;%0A%09%09%7D%0A%09%7D%0A%7D%0A

Create DBManager.java