You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@weex.apache.org by GitBox <gi...@apache.org> on 2018/12/26 09:02:41 UTC

[GitHub] YorkShen closed pull request #1970: Android data base fix

YorkShen closed pull request #1970: Android data base fix
URL: https://github.com/apache/incubator-weex/pull/1970
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/android/sdk/src/main/java/com/taobao/weex/appfram/storage/DefaultWXStorage.java b/android/sdk/src/main/java/com/taobao/weex/appfram/storage/DefaultWXStorage.java
index 28988480d2..226525bc52 100644
--- a/android/sdk/src/main/java/com/taobao/weex/appfram/storage/DefaultWXStorage.java
+++ b/android/sdk/src/main/java/com/taobao/weex/appfram/storage/DefaultWXStorage.java
@@ -143,15 +143,20 @@ public void run() {
 
     @Override
     public void close() {
-        try {
-            mDatabaseSupplier.closeDatabase();
-            if (mExecutorService != null) {
-                mExecutorService.shutdown();
-                mExecutorService = null;
+        execute(new Runnable() {
+            @Override
+            public void run() {
+                try {
+                    mDatabaseSupplier.closeDatabase();
+                    if (mExecutorService != null) {
+                        mExecutorService.shutdown();
+                        mExecutorService = null;
+                    }
+                } catch (Exception e) {
+                    WXLogUtils.e(WXSQLiteOpenHelper.TAG_STORAGE, e.getMessage());
+                }
             }
-        } catch (Exception e) {
-            WXLogUtils.e(WXSQLiteOpenHelper.TAG_STORAGE, e.getMessage());
-        }
+        });
     }
 
     private boolean performSetItem(String key, String value, boolean isPersistent, boolean allowRetryWhenFull) {
diff --git a/android/sdk/src/main/java/com/taobao/weex/appfram/storage/WXSQLiteOpenHelper.java b/android/sdk/src/main/java/com/taobao/weex/appfram/storage/WXSQLiteOpenHelper.java
index ff67808786..447703084f 100644
--- a/android/sdk/src/main/java/com/taobao/weex/appfram/storage/WXSQLiteOpenHelper.java
+++ b/android/sdk/src/main/java/com/taobao/weex/appfram/storage/WXSQLiteOpenHelper.java
@@ -150,33 +150,40 @@ synchronized void ensureDatabase() {
         if (mDb != null && mDb.isOpen()) {
             return;
         }
-        // Sometimes retrieving the database fails. We do 2 retries: first without database deletion
-        // and then with deletion.
-        for (int tries = 0; tries < 2; tries++) {
-            try {
-                if (tries > 0) {
-                    //delete db and recreate
-                    deleteDB();
+
+        try {
+            // Sometimes retrieving the database fails. We do 2 retries: first without database deletion
+            // and then with deletion.
+            for (int tries = 0; tries < 2; tries++) {
+                try {
+                    if (tries > 0) {
+                        //delete db and recreate
+                        deleteDB();
+                    }
+                    mDb = getWritableDatabase();
+                    break;
+                } catch (SQLiteException e) {
+                    e.printStackTrace();
+                }
+                // Wait before retrying.
+                try {
+                    Thread.sleep(SLEEP_TIME_MS);
+                } catch (InterruptedException ie) {
+                    Thread.currentThread().interrupt();
                 }
-                mDb = getWritableDatabase();
-                break;
-            } catch (SQLiteException e) {
-                e.printStackTrace();
             }
-            // Wait before retrying.
-            try {
-                Thread.sleep(SLEEP_TIME_MS);
-            } catch (InterruptedException ie) {
-                Thread.currentThread().interrupt();
+            if(mDb == null){
+                return;
             }
-        }
-        if(mDb == null){
-            return;
-        }
 
-        createTableIfNotExists(mDb);
+            createTableIfNotExists(mDb);
+
+            mDb.setMaximumSize(mMaximumDatabaseSize);
+        } catch (Throwable e) {
+            mDb = null;
+            WXLogUtils.d(TAG_STORAGE,"ensureDatabase failed, throwable = " + e.getMessage());
+        }
 
-        mDb.setMaximumSize(mMaximumDatabaseSize);
     }
 
     public synchronized void setMaximumSize(long size) {


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services