2015-09-22 95 views
-1

检索到的数据存储在本地数据库中,但在尝试从本地数据库中获取关系时,我得到空列表,表明关系数据未固定到本地数据库。如何在本地数据存储中解析关系数据?

public void retrieveThreadListStoreInDB() 
{ 
    ParseQuery<ParseObject> query = ParseQuery.getQuery("Threads"); 
    query.include("postedBy"); 
    query.findInBackground(new FindCallback<ParseObject>() { 
     @Override 
     public void done(List<ParseObject> list, ParseException e) { 
      if(e == null) 
      { 
       // Query is successful now lets load data from parse 
       ParseObject.pinAllInBackground((List<ParseObject>) list, new SaveCallback() { 
        @Override 
        public void done(ParseException e) { 
         if(e == null) 
         { 
          if(!isFinishing()) 
          { 
           // TODO : Notify to refresh data 
          } 
         } 
         else 
         { 
          Log.d("DEBUG","ERROR PINNING DATA WITH EXCEPTION : "+e); 
         } 
        } 
       }); 

      } 
     } 
    }); 

那么应该怎么针“关系”的数据到本地数据库??? 什么是阅读关系评论的最佳方式。我应该将它们存储在本地数据存储中还是将数据放在背景中?

回答

-1

请确保您enableLocalDatastore商店应用程序类Parse.enableLocalDatastore(getApplicationContext());

解析本地数据存储不会缓存策略工作。我们可以访问如下的关系数据:

private void getParseData() { 
    if (parseObjectId != null) { 
     mApp.show_PDialog(context, "Loading.."); 
     ParseQuery<ParseObject> parseQuery = new ParseQuery<>("Profile"); 
     parseQuery.getInBackground(parseObjectId, new GetCallback<ParseObject>() { 
      @Override 
      public void done(ParseObject parseObject, ParseException e) { 
       if (e == null) { 
        try { 
         newName = parseObject.getString("name"); 
         newGender = parseObject.getString("gender"); 
         newDOB.setTime(parseObject.getDate("dob")); 
         newTOB.setTime(parseObject.getDate("tob")); 
         newCurrentLocation = parseObject.getParseObject("currentLocation"); 
         newPOB = parseObject.getParseObject("placeOfBirth"); 

         if (newName != null) { 
          displayName.setText(newName); 
         } 
         if (newGender != null) { 
          gender.setText(newGender); 
         } 
         if (newDOB != null) { 
          DateFormat df = new SimpleDateFormat("MMM dd, yyyy", Locale.getDefault()); 
          df.setTimeZone(TimeZone.getTimeZone("UTC")); 
          String subdateStr = df.format(newDOB.getTime()); 
          datePicker.setText(subdateStr); 
         } 
         if (newTOB != null) { 
          DateFormat df = new SimpleDateFormat("hh:mm a", Locale.getDefault()); 
          df.setTimeZone(TimeZone.getTimeZone("UTC")); 
          String subdateStr = df.format(newTOB.getTime()); 
          timepicker.setText(subdateStr); 
         } 
         if (newPOB != null) { 
          placeOfBirth.setText(newPOB.fetchIfNeeded().getString("name") 
            + ", " + newPOB.fetchIfNeeded().getParseObject("Parent").fetchIfNeeded().getString("name") + ", " + newPOB.getParseObject("Parent").fetchIfNeeded().getParseObject("Parent").fetchIfNeeded().getString("name")); 
         } 
         if (newCurrentLocation != null) { 
          currentLocation.setText(newCurrentLocation.fetchIfNeeded().getString("name") 
            + ", " + newCurrentLocation.fetchIfNeeded().getParseObject("Parent").fetchIfNeeded().getString("name") + ", " + newCurrentLocation.fetchIfNeeded().getParseObject("Parent").fetchIfNeeded().getParseObject("Parent").fetchIfNeeded().getString("name")); 
         } 
        } catch (ParseException e1) { 
         e1.printStackTrace(); 
        } 
       } else { 
        e.printStackTrace(); 
       } 
       mApp.dialog.dismiss(); 
      } 
     }); 
    } else { 
     getActivity().finish(); 
    } 
} 
+0

我的本地数据存储已启用我试图将“关系”解析到本地数据存储?以上是相关的吗? –

+0

请参阅代码有方法** fetchIfNeeded()**从指针对象获取数据首先创建并保存关系对象,然后在您当前的表中获取其对象ID –

+0

你能解释清楚一点你在做什么?或在代码中写评论?我们可以将此讨论移至聊天吗? –