0

私はAzure SQLデータベースとcomunicateするアンドロイドアプリを持っています。私はオフライン同期を実装していますが、アプリケーションの最初の起動後にローカルテーブルはデータベースとviceversaと同期しません。私が最初に地元のテーブルに引っ張ってきたときだけ。Azure offlice syncはプッシュアンドプッシュしません

private AsyncTask<Void, Void, Void> initLocalStore() throws MobileServiceLocalStoreException, ExecutionException, InterruptedException { 

AsyncTask<Void, Void, Void> task = new AsyncTask<Void, Void, Void>() { 
    @Override 
    protected Void doInBackground(Void... params) { 
     try { 

      MobileServiceSyncContext syncContext = mClient.getSyncContext(); 

      if (syncContext.isInitialized()) 
       return null; 

      SQLiteLocalStore localStore = new SQLiteLocalStore(mClient.getContext(), "DB_ONYAX", null, 1); //DB_ONYAX = database name 

      //Level_Onyax_Structures table definition 
      Map<String, ColumnDataType> tableDefinitionLOS = new HashMap<String, ColumnDataType>(); 
      tableDefinitionLOS.put("id", ColumnDataType.String); 
      tableDefinitionLOS.put("updatedAt", ColumnDataType.DateTimeOffset); 
      tableDefinitionLOS.put("version", ColumnDataType.String); 
      tableDefinitionLOS.put("ID_ONYAX_STRUCTURE", ColumnDataType.Integer); 
      tableDefinitionLOS.put("Structure_name", ColumnDataType.String); 
      tableDefinitionLOS.put("Structure_LAT", ColumnDataType.Real); 
      tableDefinitionLOS.put("Structure_LON", ColumnDataType.Real); 
      tableDefinitionLOS.put("Structure_ZOOM", ColumnDataType.Real); 

      localStore.defineTable("Level_Onyax_Structures", tableDefinitionLOS); 
      SimpleSyncHandler handler = new SimpleSyncHandler(); 

      syncContext.initialize(localStore, handler).get(); 

     } catch (final Exception e) { 
      createAndShowDialogFromTask(e, "Error Creation Local Table"); 
     } 

     return null; 
    } 
}; 

return runAsyncTask(task); 
} 

モバイルサービスからアイテムを更新します

private List<My_Table> refreshItemsFromMobileServiceTableSyncTable() throws ExecutionException, InterruptedException { 
    //sync the data 
    syncLOS().get(); 
    return mLOSTable.read(null).get(); 
} 

同期方法:

private AsyncTask<Void, Void, Void> syncLOS() { 
    AsyncTask<Void, Void, Void> task = new AsyncTask<Void, Void, Void>(){ 
     @Override 
     protected Void doInBackground(Void... params) { 
      try { 
       MobileServiceSyncContext syncContext = mClient.getSyncContext(); 
       syncContext.push().get(); 
       mLOSTable.pull(null).get(); 
      } catch (final Exception e) { 
       e.printStackTrace(); 
      } 
      return null; 
     } 
    }; 
    return runAsyncTask(task); 
} 

そして、ここで私はすべてを呼び出す:私は更新しようとする場合は

AsyncTask<Void, Void, Void> task = new AsyncTask<Void, Void, Void>(){ 
     @Override 
     protected Void doInBackground(Void... params) { 

      try { 
       listOnyaxStructures = refreshItemsFromMobileServiceTableSyncTable(); 

       runOnUiThread(new Runnable() { 
        @Override 
        public void run() { 

         setLoading(false); 

         } 
        } 
       }); 
      } catch (final Exception e){ 
       e.printStackTrace(); 
      } 

      return null; 
     } 
    }; 

    runAsyncTask(task); 

を値:

item.setStructure_name(edt.getText().toString()); 

       new AsyncTask<Void, Void, Void>(){ 
        @Override 
        protected Void doInBackground(Void... params) { 
         try { 

          mLCSTable.update(item).get(); 
          MobileServiceSyncContext syncContext = mClient.getSyncContext(); 
          syncContext.push().get(); 
          mLCSTable.pull.get(); 

          runOnUiThread(new Runnable() { 
           @Override 
           public void run() { 
            //finish 
           } 
          }); 
         } catch (final Exception e) { 
          e.printStackTrace(); 
         } 

         return null; 
        } 
       }.execute(); 

いずれかが役に立ちますか?

+0

アイテムを更新すると、アイテムはローカルストレージ上でのみ更新されます。 –

答えて

0

更新:MobileServicePushFailedExceptionの原因が見つかりました。アイテムを更新しようとすると、オートインクリメントのインデックスを更新しようとしているので、MobileServicePushFailedExceptionが発生します。

これはEasy Tablesのログからのエラーです。ID列「ID_COMPANY_STRUCTURE」を更新できません。

ローカルテーブルにID_COMPANY_STRUCTUREを挿入しないで、すべてうまく動作しないようにしようとしましたが、別のテーブルへの外部キーであるために必要です。

アンドロイドでIDをオフに設定する方法、またはこのタイプのエラーを回避する方法はありますか?

関連する問題