I have a list of objectId where I am trying to retrieve another list in another class where the pointer value equals the objectId of the current parseObject.
I realised that I am comparing a string "objectId" to a pointer "threadPointer" so can someone help me with the query to retrieve a list of items from a class if the objectId equals the threadPointer _Pointer value
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);
}
}
});
}
}
});
}
public void retrievePostsListStoreInDB()
{
ParseQuery<ParseObject> query = ParseQuery.getQuery("Posts");
query.include("postedBy");
query.include("threadPointer");
query.findInBackground(new FindCallback<ParseObject>() {
#Override
public void done(final 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
Log.d("DEBUG: ","Finished retrieval");
Log.d("DEBUG", list.toString());
ParseObject object = (ParseObject)list.get(1).get("threadPointer");
Log.d("DEBUG_THREAD_POINTER", object.getObjectId());
}
} else {
Log.d("DEBUG", "ERROR PINNING DATA WITH EXCEPTION : " + e);
}
}
});
}
}
});
}
This is where I am retrieving the ThreadList from local db
public void retrieveThreadList(){
List<ParseObject> parseObjectList = new ArrayList<ParseObject>();
ParseQuery<ParseObject> query = ParseQuery.getQuery("Threads");
query.orderByDescending("updatedAt");
query.fromLocalDatastore();
// Data retrieval was successfull
try {
parseObjectList= query.find();
} catch (ParseException e) {
e.printStackTrace();
}
for (ParseObject parseObject : parseObjectList) {
String title = (String) parseObject.get("threadTitle");
ParseUser parseUser = (ParseUser) parseObject.get("postedBy");
String profilePictureUrl="local";
try {
profilePictureUrl = ((ParseFile) parseUser.get("profilePicture")).getUrl();
}catch (Exception exception)
{
Log.d("DEBUG_FB","profilePicture not retrieved");
}
String threadObjectId = parseObject.getObjectId();
Log.d("DEBUG_FB_THREAD_ID",threadObjectId);
ParseQuery parseQueryToRetrievePosts = ParseQuery.getQuery("Posts");
parseQueryToRetrievePosts.fromLocalDatastore();
//----****** NEED HELP HERE ******----
parseQueryToRetrievePosts.whereEqualTo("threadPointer",parseObject.getObjectId());
try {
List<ParseObject> postsList = parseQueryToRetrievePosts.find();
Log.d("DEBUG_FB_POSTS_LIST",postsList.toString());
} catch (ParseException e) {
e.printStackTrace();
}
/* To retrieve data over the network --- THIS WORKS WELL BUT I DONT WANT A NETWORK CALL
ParseRelation <ParseObject> posts = parseObject.getRelation("postMessage");
ParseQuery postsQuery = posts.getQuery();
List<ParseObject> postsList = new ArrayList();
try {
postsList=postsQuery.find();
for (ParseObject parseObject1: postsList)
{
String postMessage = (String)parseObject1.get("postMessage");
Log.d("DEBUG_FB_MSG", postMessage);
}
Log.d("DEBUG_FB_POSTS", postsList.toString());
}catch (Exception e)
{
}
*/
threadModelStore threadObject = new threadModelStore(title,profilePictureUrl);
Log.d("DEBUG_FB", profilePictureUrl);
Log.d("DEBUG_FB", title);
threadItemList.add(threadObject);
}
Sir my scenario is I have these classes
THREADS(Class) which has POSTS(RELATION TO _POSTS) class I want to retrieve the related posts of a particular thread. I was unable to pin
relations to local data store please let me know if there is a way to
do so ? -- (UNSOLVED)
So what I want to do is to compare the thread pointer in the POSTS
class and retrieve the related posts. For this I needed to compare a
string object id to pointer field _ThreadPointer in POSTS Class
Suggest a possible solution -- SOLVED BY ( VED ).
ParseObject threadPointer=ParseObject.createWithoutData("Pointer_class_Name", "pointer_object_id");
ParseQuery<ParseObject> query=ParseQuery.getQuery("className");
query.whereEqualTo("_Pointer", threadPointer);
query.include("_Pointer");
query.findInBackground(new FindCallback<ParseObject>() {
#Override
public void done(List<ParseObject> listCommunity, ParseException e) {
// TODO Auto-generated method stub
Log.d(TAG, "done");
if(e==null){
// access your data
}else{
// Error in retrieving data
}
Related
By using this code, I am not able to get the 'name' unless I use objectId = xJ34wEo.
Suggest a way, if not, at least by using pointer.
//Parse Query Initialization
final ParseQuery<ParseObject> query = ParseQuery.getQuery("MyUsers");
//To check the row which has "number"="1234"
query.whereEqualTo("number", "1234");
query.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> employees, ParseException e) {
if (e == null) {
try {
//xJ34wE0 is objectId
query.get("xJ34wEo").get("name") + "");
} catch (ParseException pe) {}
}
}
});
Are you just trying to get the employee object with that number?
You have a List<ParseObject>, so use it.
query.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> employees, ParseException e) {
if (e == null && employees.size() > 0) {
try {
String name = employees.get(0).get("name");
Log.d("PARSE", name);
} catch (ParseException pe) {}
}
}
});
I have created a Pointer in ParseClass I want to query from the Pointer added I have created ParseObject class so how can set the ParseObject for querying the pointer.
Games Parse class has Pointer 'Places'
#ParseClassName("Games")
public class Offers extends ParseObject{
public String getPlaceName() {
return getString(getParseObject("Places").getString("PlaceName"));
}
If you want to get Games objects with related Places data, you should use 'include' in the query.
ParseQuery<Offers> query = ParseQuery.getQuery(Offers.class);
//query.equalTo("objectId", "gameId");
query.include("Places");
query.getFirstInBackground(new GetCallback<Offers>() {
#Override
public void done(Offers obj, ParseException e) {
if(e!=null) {
Log.e("err", e.getMessage());
}
else {
Log.d("PlaceName", obj.getParseObject("Places").getString("PlaceName"));
}
}
});
If you want to get related data by pointer(ParseObject which only contains id)
ParseObject place = ParseObject.createWithoutData("Places","id");
place.fetchInBackground(new GetCallback<ParseObject>() {
#Override
public void done(ParseObject object, ParseException e) {
//do what you want
}
});
try it
final ArrayList<ParseObject> Places = new ArrayList<ParseObject>();
ParseQuery<ParseObject> offer = new ParseQuery<ParseObject>("className");
offer.findInBackground(new FindCallback<ParseObject>() {
#Override
public void done(List<ParseObject> objects, ParseException e) {
// TODO Auto-generated method stub
if (e == null) {
// success
for (ParseObject parseObject : objects) {
Places.add(parseObject.getParseObject("Places"));
}
Log.e("TAG ", "get parse pointer object " + Places.size());
} else {
// fail
}
}
});
I am having a table structure like this trying to fetch multiple data all those related tables-
I have list of category (ProfileCateGory Object) and inside every category list (ProfileData Object) of profile Date with the there view count (ProfileViewCount Object)
I am new to this Parse.com I tried like this -
ParseQuery<ParseObject> query = ParseQuery.getQuery("ProfileData");
query.whereEqualTo("profileName", "Profile");
try {
for (int i = 0; i < query.count(); i++) {
query.getFirstInBackground(new GetCallback<ParseObject>() {
public void done(ParseObject object, ParseException e) {
if (object == null) {
Log.d("ProfileData", "Error: " + e.getMessage());
} else {
Log.d("TAG", "Name: " + object.get("profileName").toString());
}
}
});
}
} catch (Throwable t) {
}
I am getting only one data from ProfileData.
You can use relational-queries
For that you have to make profileCode as Pointer type in ProfileViewCounts
ParseQuery<ParseObject> innerQuery = ParseQuery.getQuery("ProfileData");
innerQuery.whereEqualTo("profileName", "Profile");
ParseQuery<ParseObject> query =ParseQuery.getQuery("ProfileViewCounts");
query.whereMatchesQuery("profileCode", innerQuery);
query.getFirstInBackground(new GetCallback<ParseObject>() {
#Override
public void done(ParseObject objProfileViewCounts, ParseException e) {
// TODO Auto-generated method stub
}
});
getFirstInBackground() is to call and return just one item.
To get an array or more objets you need to do:
//profile or id of user , you have to pass as a parameter
ParseQuery<ParseObject> query = ParseQuery.getQuery("ProfileData");
query.whereEqualTo("profileName", Profile);
query.findInBackground(new FindCallback<ParseObject>() {
#Override
public void done(List<ParseObject> objects, ParseException e) {
if (e == null) {
for (int inP = 0; inP < objects.size(); inP++) {
String profileName = objects.get(inP).getString("profileName");
}
} else {
}
}
I am using parse as BaaS for my android project. Facing duplication of data if I create a custom parse object and saving it as required.
Moreover I tried even extending the parse object to the required class which causes other problems !
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) {
// Data retrieval was successfull
for (ParseObject parseObject : list) {
String title = (String) parseObject.get("threadTitle");
ParseUser parseUser = (ParseUser) parseObject.get("postedBy");
ParseFile userProfilePicture=null;
try
{
userProfilePicture = (ParseFile) parseUser.get("profilePicture");
}
catch (Exception e1)
{
}
String profilePictureUrl=null;
if(userProfilePicture != null) {
profilePictureUrl = (userProfilePicture).getUrl();
}
ParseObject threadsList = new ParseObject("ThreadsList");
threadsList.put("threadTitle",title);
if(profilePictureUrl != null) {
threadsList.put("postedByPicture", profilePictureUrl);
}
else {
threadsList.put("postedByPicture","local");
}
try {
threadsList.pin();
} catch (ParseException e1) {
e1.printStackTrace();
}
Log.d("DEBUG", title);
// Log.d("DEBUG",profilePictureUrl);
}
} else {
Log.d("DEBUG", "Problem with retrieval" + e);
}
}
});
}
HELP ME RESOLVE DUPLICATION OF DATA AND WHAT IS THE BEST WAY TO STORE FILE URL'S, POINTER RELATED INFORMATION AND RELATIONS INFORMATION ?????
I am facing a big problem in parse api. I am able to create new group on server as well able to add user to the group also. I created many group on server like Friends, Sports, College etc. But how can I retrieve the names of all group from server?
Using the below code I can retrieve all the user in the group.
public void getUserList() {
String groupName="Friends"
final ParseUser currentUser = ParseUser.getCurrentUser();
if (currentUser != null) {
ParseRelation relation = currentUser.getRelation(groupName);
ParseQuery query = relation.getQuery();
try {
Log.e("Size ", "Size " + query.count());
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// query.whereEqualTo("username", null);
query.findInBackground(new FindCallback<ParseObject>() {
#Override
public void done(List<ParseObject> objects, ParseException arg1) {
// TODO Auto-generated method stub
try {
for (int i = 0; i < objects.size(); i++) {
ParseObject r = objects.get(i);
String name = r.getString("username").toString();
Log.e("user name ", "===>" + name);
}
} catch (Exception e) {
Toast.makeText(getApplicationContext(),
"Error : " + e.toString(), 1).show();
}
}
});
}
}
In above screen-shot I need all the names like Friends, MYGroup and xyz using one query.
Please help me.
To get all groups, you need to query the Group class (or whatever you have called it):
ParseQuery<ParseObject> query = ParseQuery.getQuery("Group");
query.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> groupList, ParseException e) {
if (e == null) {
for (ParseObject group : groupList) {
Log.d("group", "Group name: " + group.get("name");
}
} else {
Log.d("score", "Error: " + e.getMessage());
}
}
});