Java 正在Parse LocalDataStore中保存数据,但无法检索数据。请参阅代码和日志
我正在执行来自服务的代码。该代码的工作方式如下:Java 正在Parse LocalDataStore中保存数据,但无法检索数据。请参阅代码和日志,java,android,parsing,datastore,Java,Android,Parsing,Datastore,我正在执行来自服务的代码。该代码的工作方式如下: // check the LocalDataStore // if the localDataStore is empty then fetch new jokes and update the localDataStore // then try again from the first step. // otherwise, continue with further logic private void f
// check the LocalDataStore
// if the localDataStore is empty then fetch new jokes and update the localDataStore
// then try again from the first step.
// otherwise, continue with further logic
private void fetchAndUploadJokesFromLocalDataStore() {
Log.v("uploading", "taking joke from the LocalDataStore");
ParseQuery<ParseObject> query = ParseQuery.getQuery("JokesDataToBeUploaded");
query.orderByDescending("objectId");
query.fromLocalDatastore();
query.findInBackground(new FindCallback<ParseObject>() {
@Override
public void done(List<ParseObject> list, ParseException e) {
if (e == null) {
if (list.size() > 0) {
Log.v("uploading", "found " + list.size() + " jokes in LocalDataStore");
} else {
Log.v("uploading", "localDataStore is empty, fetching new jokes");
SharedPreferences configData = getSharedPreferences("configData", 0);
uploadJokes(configData.getInt("uploadHowManyJokes", 1));
Log.v("Service", "uploadJokes called. uploadHowManyJokes=" + configData.getInt("uploadHowManyJokes", 1));
}
} else {
}
} ... // more methods follow but the brackets are closed correctly in real code.
}
这是一个无限循环,ParseRequest.NETWORK_EXECUTOR-thread-3调用detatch被一次又一次调用我找到了答案 问题是,我正在保存一个名为JokesDataCollection、名为JokesDataToBeUploaded的类。新名称只是一个标识符,用于标识本地数据存储中要删除、更新等的项。然后,我用于查询本地数据存储的类名是JokesDataToBeUploaded,而从internet获取并保存的实际类名为JokesDataCollection 因此,我甚至需要调用以下函数来从LocalDatastore获取项目
ParseQuery.getQuery("JokesDataCollection");
query.fromLocalDatastore();
private void updateLocalFeedWithNewData(final List<ParseObject> newFeed) {
// Release any objects previously pinned for this query.
final ParseObject feed = new ParseObject("JokesDataToBeUploaded");
ParseObject.unpinAllInBackground("JokesDataToBeUploaded", new DeleteCallback() {
public void done(ParseException e) {
if (e == null) {
// Cache the new results.
Log.v("pinning", "unpinned all");
ParseObject.pinAllInBackground("JokesDataToBeUploaded", newFeed, new SaveCallback() {
@Override
public void done(ParseException e) {
if (e == null) {
Log.v("pinning", "pinned successfully");
fetchAndUploadJokesFromLocalDataStore();
} else {
Log.v("pinning", "pinning FAILED");
// todo try again, either by restarting the service and getting entirely new jokes, or by trying again on the same object list
stopSelf();
}
}
});
} else {
Log.v("pinning", "UNpinning FAILED");
Log.v("ParseException caught", e.getMessage());
stopSelf();
}
}
}
);
}
10-30 22:00:09.429 4102-4102/com.appsbyusman.jokesmanager V/Service: Started
10-30 22:00:09.459 4102-4102/com.appsbyusman.jokesmanager V/uploading: taking joke from the LocalDataStore
10-30 22:00:09.519 4102-4102/com.appsbyusman.jokesmanager V/uploading: localDataStore is empty, fetching new jokes
10-30 22:00:09.529 4102-4102/com.appsbyusman.jokesmanager V/Service: uploadJokes called. uploadHowManyJokes=1
10-30 22:00:09.539 4102-6493/com.appsbyusman.jokesmanager I/System.out: Thread-12964(ApacheHTTPLog):Reading from variable values from setDefaultValuesToVariables
10-30 22:00:09.539 4102-6493/com.appsbyusman.jokesmanager I/System.out: Thread-12964(ApacheHTTPLog):isSBSettingEnabled false
10-30 22:00:09.539 4102-6493/com.appsbyusman.jokesmanager I/System.out: Thread-12964(ApacheHTTPLog):isShipBuild true
10-30 22:00:09.539 4102-6493/com.appsbyusman.jokesmanager I/System.out: Thread-12964(ApacheHTTPLog):SmartBonding Enabling is false, SHIP_BUILD is true, log to file is false, DBG is false
10-30 22:00:10.751 4102-6493/com.appsbyusman.jokesmanager I/System.out: ParseRequest.NETWORK_EXECUTOR-thread-1 calls detatch()
10-30 22:00:10.761 4102-4102/com.appsbyusman.jokesmanager D/Uploading Joke: Jokes Retrieved: 1
10-30 22:00:10.791 4102-4102/com.appsbyusman.jokesmanager V/pinning: unpinned all
10-30 22:00:10.831 4102-4102/com.appsbyusman.jokesmanager V/pinning: pinned successfully
10-30 22:00:20.841 4102-6525/com.appsbyusman.jokesmanager V/uploading: taking joke from the LocalDataStore
10-30 22:00:20.941 4102-4102/com.appsbyusman.jokesmanager V/uploading: localDataStore is empty, fetching new jokes
10-30 22:00:20.941 4102-4102/com.appsbyusman.jokesmanager V/Service: uploadJokes called. uploadHowManyJokes=1
10-30 22:00:21.321 4102-6809/com.appsbyusman.jokesmanager I/System.out: ParseRequest.NETWORK_EXECUTOR-thread-2 calls detatch()
10-30 22:00:21.351 4102-4102/com.appsbyusman.jokesmanager D/Uploading Joke: Jokes Retrieved: 1
10-30 22:00:21.521 4102-4102/com.appsbyusman.jokesmanager V/pinning: unpinned all
10-30 22:00:21.561 4102-4102/com.appsbyusman.jokesmanager V/pinning: pinned successfully
10-30 22:00:31.571 4102-6837/com.appsbyusman.jokesmanager V/uploading: taking joke from the LocalDataStore
10-30 22:00:31.681 4102-4102/com.appsbyusman.jokesmanager V/uploading: localDataStore is empty, fetching new jokes
10-30 22:00:31.681 4102-4102/com.appsbyusman.jokesmanager V/Service: uploadJokes called. uploadHowManyJokes=1
10-30 22:00:31.971 4102-6981/com.appsbyusman.jokesmanager I/System.out: ParseRequest.NETWORK_EXECUTOR-thread-3 calls detatch()
10-30 22:00:31.991 4102-4102/com.appsbyusman.jokesmanager D/Uploading Joke: Jokes Retrieved: 1
10-30 22:00:32.051 4102-4102/com.appsbyusman.jokesmanager V/pinning: unpinned all
10-30 22:00:32.132 4102-4102/com.appsbyusman.jokesmanager V/pinning: pinned successfully
ParseQuery.getQuery("JokesDataCollection");
query.fromLocalDatastore();