Skip to content

Commit c1b6311

Browse files
committed
Thread safety for database updates
1 parent 20f11a0 commit c1b6311

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

core/src/main/java/io/snabble/sdk/ProductDatabase.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ public Date getLastUpdateDate() {
295295
* <p>
296296
* Returns true if successful, false otherwise
297297
*/
298-
void applyDeltaUpdate(InputStream inputStream) throws IOException {
298+
synchronized void applyDeltaUpdate(InputStream inputStream) throws IOException {
299299
if(dbName == null){
300300
return;
301301
}
@@ -308,6 +308,9 @@ void applyDeltaUpdate(InputStream inputStream) throws IOException {
308308
File dbFile = application.getDatabasePath(dbName);
309309
File tempDbFile = application.getDatabasePath("_" + dbName);
310310

311+
SQLiteDatabase tempDbBUG123 = SQLiteDatabase.openOrCreateDatabase(tempDbFile, null);
312+
tempDbBUG123.beginTransaction();
313+
311314
if (!deleteDatabase(tempDbFile)) {
312315
Logger.e("Could not apply delta update: Could not delete temp database");
313316
return;
@@ -401,7 +404,7 @@ void applyDeltaUpdate(InputStream inputStream) throws IOException {
401404
* <p>
402405
* If a read error occurs, an IOException will be thrown.
403406
*/
404-
void applyFullUpdate(InputStream inputStream) throws IOException {
407+
synchronized void applyFullUpdate(InputStream inputStream) throws IOException {
405408
if(dbName == null){
406409
return;
407410
}

0 commit comments

Comments
 (0)