Skip to content

Commit 7448f75

Browse files
committed
fixing clear database functionality
+ some ex.printStackTrace warnings
1 parent b1a5024 commit 7448f75

2 files changed

Lines changed: 20 additions & 8 deletions

File tree

auto-content-provider/src/main/java/pl/selvin/android/autocontentprovider/content/AutoContentProvider.java

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public abstract class AutoContentProvider extends ContentProvider {
3939
protected final ContentHelper contentHelper;
4040
protected final Class<?> clazz = getClass();
4141
protected final Logger logger;
42+
protected final Object getDatabaseLock = new Object();
4243
private final SupportSQLiteOpenHelper.Callback defaultCallback;
4344
private final SupportSQLiteOpenHelperFactoryProvider supportSQLiteOpenHelperFactoryProvider;
4445
private SupportSQLiteOpenHelper mDB;
@@ -72,11 +73,23 @@ public boolean onCreate() {
7273
}
7374

7475
final public SupportSQLiteDatabase getReadableDatabase() {
75-
return mDB.getReadableDatabase();
76+
synchronized (getDatabaseLock) {
77+
return mDB.getReadableDatabase();
78+
}
7679
}
7780

7881
final public SupportSQLiteDatabase getWritableDatabase() {
79-
return mDB.getWritableDatabase();
82+
synchronized (getDatabaseLock) {
83+
return mDB.getWritableDatabase();
84+
}
85+
}
86+
87+
final protected void clearDatabase() {
88+
synchronized (getDatabaseLock) {
89+
mDB.getWritableDatabase().setVersion(1);
90+
mDB.close();
91+
requireContextEx().getContentResolver().notifyChange(contentHelper.CONTENT_URI, null, false);
92+
}
8093
}
8194

8295
@Nullable
@@ -156,7 +169,7 @@ public int delete(@NonNull Uri uri, String selection, String[] selectionArgs) {
156169
if (code != UriMatcher.NO_MATCH) {
157170
if (code == ContentHelper.uriClearCode) {
158171
logger.LogD(clazz, "delete uriClearCode");
159-
getHelperCallback().onUpgrade(getWritableDatabase(), 1, contentHelper.DATABASE_VERSION);
172+
clearDatabase();
160173
return 0;
161174
}
162175
boolean syncToNetwork = ContentHelper.checkSyncToNetwork(uri);
@@ -209,7 +222,8 @@ public int delete(@NonNull Uri uri, String selection, String[] selectionArgs) {
209222
cascadeResults += delete(deleteUri, deleteWhere, whereArgs);
210223
}
211224
} catch (Exception ex) {
212-
ex.printStackTrace();
225+
logger.LogD(clazz, "*onCreateDataBase*: " + ex, ex);
226+
throw new RuntimeException(ex);
213227
}
214228
}
215229
} finally {

sync-framework/src/main/java/pl/selvin/android/syncframework/content/BaseContentProvider.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public Bundle call(@NonNull String method, String arg, Bundle syncParams) {
103103
inout.numIoExceptions++;
104104
syncParams.putParcelable(SYNC_PARAM_IN_SYNC_STATS, inout);
105105
}
106-
ex.printStackTrace();
106+
logger.LogD(clazz, "*call", ex);
107107
}
108108
return syncParams;
109109
}
@@ -317,9 +317,7 @@ public Stats sync(String service, String scope, String params, Stats stats) {
317317
}
318318
jp.close();
319319
if (resolveConflicts)
320-
logger.LogE(clazz, "*Sync* has resolve conflicts: " + resolveConflicts);
321-
else
322-
logger.LogD(clazz, "*Sync* has resolve conflicts: " + resolveConflicts);
320+
logger.LogE(clazz, "*Sync* has resolve conflicts !!!");
323321
} else {
324322
boolean fixed = false;
325323
final String error = result.error;

0 commit comments

Comments
 (0)