Merge pull request #2627 from ByteHamster/get-instance-fix
Actually return instance in getInstance
This commit is contained in:
commit
e38cf741b9
@ -308,7 +308,6 @@ public class PodDBAdapter {
|
|||||||
KEY_CONTENT_ENCODED, KEY_FEED};
|
KEY_CONTENT_ENCODED, KEY_FEED};
|
||||||
|
|
||||||
private static Context context;
|
private static Context context;
|
||||||
private static PodDBHelper dbHelper;
|
|
||||||
|
|
||||||
private static volatile SQLiteDatabase db;
|
private static volatile SQLiteDatabase db;
|
||||||
private static int counter = 0;
|
private static int counter = 0;
|
||||||
@ -317,13 +316,14 @@ public class PodDBAdapter {
|
|||||||
PodDBAdapter.context = context.getApplicationContext();
|
PodDBAdapter.context = context.getApplicationContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class PodDBHelperholder {
|
// Bill Pugh Singleton Implementation
|
||||||
public static final PodDBHelper dbHelper = new PodDBHelper(PodDBAdapter.context, DATABASE_NAME, null);
|
private static class SingletonHolder {
|
||||||
|
private static final PodDBHelper dbHelper = new PodDBHelper(PodDBAdapter.context, DATABASE_NAME, null);
|
||||||
|
private static final PodDBAdapter dbAdapter = new PodDBAdapter();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PodDBAdapter getInstance() {
|
public static PodDBAdapter getInstance() {
|
||||||
dbHelper = PodDBHelperholder.dbHelper;
|
return SingletonHolder.dbAdapter;
|
||||||
return new PodDBAdapter();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private PodDBAdapter() {
|
private PodDBAdapter() {
|
||||||
@ -342,11 +342,11 @@ public class PodDBAdapter {
|
|||||||
private SQLiteDatabase openDb() {
|
private SQLiteDatabase openDb() {
|
||||||
SQLiteDatabase newDb;
|
SQLiteDatabase newDb;
|
||||||
try {
|
try {
|
||||||
newDb = dbHelper.getWritableDatabase();
|
newDb = SingletonHolder.dbHelper.getWritableDatabase();
|
||||||
newDb.enableWriteAheadLogging();
|
newDb.enableWriteAheadLogging();
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
Log.e(TAG, Log.getStackTraceString(ex));
|
Log.e(TAG, Log.getStackTraceString(ex));
|
||||||
newDb = dbHelper.getReadableDatabase();
|
newDb = SingletonHolder.dbHelper.getReadableDatabase();
|
||||||
}
|
}
|
||||||
return newDb;
|
return newDb;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user