These are working notes the BAAS platform Parse. This is going to be a new chapter in our upcoming book. We are also developing a few apps with Parse as the backend. It has been a wonderful experience so far.

satya - Fri Jan 11 2013 11:05:43 GMT-0500 (Eastern Standard Time)

parse.com homepage

parse.com homepage

satya - Fri Jan 11 2013 14:50:25 GMT-0500 (Eastern Standard Time)

download the sdk: quick start guide

download the sdk

satya - Fri Jan 11 2013 14:52:08 GMT-0500 (Eastern Standard Time)

What are application Id and client key?

What are application Id and client key?

Search for: What are application Id and client key?

satya - Fri Jan 11 2013 14:52:41 GMT-0500 (Eastern Standard Time)

They are used like this


public void onCreate() { 
    Parse.initialize(this, appIdString, clientKeyString); 
}

satya - Tue Jan 15 2013 09:36:32 GMT-0500 (Eastern Standard Time)

Parse Android Guide

Parse Android Guide

satya - Tue Jan 15 2013 09:44:28 GMT-0500 (Eastern Standard Time)

ParseObject


//a set of key value pairs
//Exammple

ParseObject gameScore = new ParseObject("GameScore");
gameScore.put("score", 1337);
gameScore.put("playerName", "Sean Plott");
gameScore.put("cheatMode", false);
gameScore.saveInBackground();

satya - Tue Jan 15 2013 09:49:26 GMT-0500 (Eastern Standard Time)

Default fields of a ParseObject


objectId
createdAt
udpatedAt

satya - Tue Jan 15 2013 09:49:37 GMT-0500 (Eastern Standard Time)

ObjectId separates one parse object from the other

ObjectId separates one parse object from the other

satya - Tue Jan 15 2013 09:50:35 GMT-0500 (Eastern Standard Time)

Implications


Be aware two objects of same type could have different key/value pairs
A programmer may want to use java types to deal with this well.

satya - Tue Jan 15 2013 09:51:50 GMT-0500 (Eastern Standard Time)

Retrieving


ParseQuery query = new ParseQuery("GameScore");
query.getInBackground("xWMyZ4YEGZ", new GetCallback() {
  public void done(ParseObject object, ParseException e) {
    if (e == null) {
      // object will be your game score
    } else {
      // something went wrong
    }
  }
});

Notice how you need an object id to retrieve it in this case. I suppose there will be query clauses just like SQL to retrieve sets of these objects satisfying a criteria.

satya - Tue Jan 15 2013 09:52:10 GMT-0500 (Eastern Standard Time)

Refreshing them


myObject.refreshInBackground(new RefreshCallback() {
  public void done(ParseObject object, ParseException e) {
    if (e == null) {
      // Success!
    } else {
      // Failure!
    }
  }
})

satya - Tue Jan 15 2013 09:53:26 GMT-0500 (Eastern Standard Time)

Save locally if the connection is not available


ParseObject gameScore = new ParseObject("GameScore");
gameScore.put("score", 1337);
gameScore.put("playerName", "Sean Plott");
gameScore.put("cheatMode", false);
gameScore.saveEventually();

A final save will happen when the connection is up.

satya - 1/16/2013 9:22:15 AM

You can have nested objects


int myNumber = 42;
String myString = "the number is " + myNumber;
Date myDate = new Date();
 
JSONArray myArray = new JSONArray();
myArray.put(myString);
myArray.put(myNumber);
 
JSONObject myObject = new JSONObject();
myObject.put("number", myNumber);
myObject.put("string", myString);
 
byte[] myData = { 4, 8, 16, 32 };
 
ParseObject bigObject = new ParseObject("BigObject");
bigObject.put("myNumber", myNumber);
bigObject.put("myString", myString);
bigObject.put("myDate", myDate);
bigObject.put("myData", myData);
bigObject.put("myArray", myArray);
bigObject.put("myObject", myObject);
bigObject.put("myNull", JSONObject.NULL);
bigObject.saveInBackground();

satya - 1/16/2013 9:28:07 AM

Types of queries


On a single object type
or, and, on multiple attributes
nested queries like in clause
join like
data caching
compound queries

satya - 1/16/2013 9:28:59 AM

File uploads with progress indicator is possible

File uploads with progress indicator is possible

satya - 1/16/2013 9:35:14 AM

A ParseUser is a ParseObject


ParseUser user = new ParseUser();
user.setUsername("my name");
user.setPassword("my pass");
user.setEmail("email@example.com");
 
// other fields can be set just like with ParseObject
user.put("phone", "650-253-0000");

satya - 1/16/2013 9:40:04 AM

Some ParseUser features


signup
login
verify emails
persistent logged in user/current user/session
Annonymous users that can join later
facebook user integration
twitter user integration
automatic annonymous users
user object seem to have security features

satya - 1/16/2013 10:33:31 AM

What to understand


automatic user
user ACLs

satya - 3/1/2013 3:31:44 PM

Knowing who has logged in


ParseUser currentUser = ParseUser.getCurrentUser();
if (currentUser != null) {
  // do stuff with the user
} else {
  // show the signup or login screen
}

satya - 3/1/2013 3:32:04 PM

You can find this docs at

You can find this docs at

satya - 3/1/2013 3:36:30 PM

Enabling automatic user


//This will automatically create an annonymous user
//The data associated to this user is abandoned when it is 
//logged out.

ParseUser.enableAutomaticUser();

satya - 3/1/2013 4:21:12 PM

You can reset password through emails. Here is a link to the doc

You can reset password through emails. Here is a link to the doc

satya - 3/4/2013 3:10:19 PM

How do you logout?


ParseUser.logout()

satya - 3/4/2013 3:11:15 PM

Here is the example to signup


ParseUser user = new ParseUser();
user.setUsername("my name");
user.setPassword("my pass");
user.setEmail("email@example.com");
 
// other fields can be set just like with ParseObject
user.put("phone", "650-253-0000");
 
user.signUpInBackground(new SignUpCallback() {
  public void done(ParseException e) {
    if (e == null) {
      // Hooray! Let them use the app now.
    } else {
      // Sign up didn't succeed. Look at the ParseException
      // to figure out what went wrong
    }
  }
});

satya - 3/4/2013 3:13:14 PM

Here is the guide for signup

Here is the guide for signup

satya - 3/4/2013 3:36:12 PM

Use this article to use progress dialogs to track asyncs

Use this article to use progress dialogs to track asyncs

satya - 3/4/2013 3:57:45 PM

Here is a quick design for login/signup/reset sequence

satya - 3/8/2013 5:01:10 PM

Here is what parse looks like when a new user is signed up

satya - 3/8/2013 5:01:57 PM

Here is a sample parse app home page

satya - 3/8/2013 5:02:19 PM

Sign up page

satya - 3/8/2013 5:03:08 PM

Form Error handling

satya - 3/8/2013 5:03:35 PM

Use this article to handle forms better

Use this article to handle forms better

satya - 3/8/2013 5:03:57 PM

Login or reset password

satya - 3/8/2013 5:04:19 PM

Waiting while you login

satya - 3/8/2013 5:04:40 PM

Reset using the email

satya - 3/12/2013 4:24:10 PM

How do I implement cursor behavior with ParseQuery?

How do I implement cursor behavior with ParseQuery?

Search for: How do I implement cursor behavior with ParseQuery?

satya - 3/13/2013 9:54:25 AM

Here is the parse forum

Here is the parse forum

satya - 3/13/2013 9:58:54 AM

is there a record of who created a ParseObject

is there a record of who created a ParseObject

satya - 3/13/2013 9:59:07 AM

is there a record of who created a ParseObject?

is there a record of who created a ParseObject?

Search for: is there a record of who created a ParseObject?

satya - 3/13/2013 11:39:27 AM

Here is something called parsefacade

Here is something called parsefacade

This might throw some light on some that has used parse for a while and what insights there might be....

satya - 3/13/2013 3:22:09 PM

Can I retrieve multiple types of Parse objects in one query?

Yes and No. Parse only returns collections of one object type. That is the No part. However, if that object contains pointers to other objects it can return those (apparently) internal objects populated as well. (essentially kind of a join)

satya - 3/13/2013 3:22:32 PM

See this discussion link at Parse.com to support this idea

See this discussion link at Parse.com to support this idea

satya - 3/13/2013 3:24:05 PM

Here is what the parse docs says about this

Here is what the parse docs says about this

- 3/13/2013 3:25:25 PM

Briefly

In some situations, you want to return multiple types of related objects in one query. You can do this with the include method. For example, let's say you are retrieving the last ten comments, and you want to retrieve their related posts at the same time:

annonymous - 3/13/2013 3:25:57 PM

Sample code


ParseQuery query = new ParseQuery("Comment");
 
// Retrieve the most recent ones
query.orderByDescending("createdAt");
 
// Only retrieve the last ten
query.setLimit(10);
 
// Include the post data with each comment
query.include("post");
 
query.findInBackground(new FindCallback() {
  public void done(List<ParseObject> commentList, ParseException e) {
    // commentList now contains the last ten comments, and the "post"
    // field has been populated. For example:
    for (ParseObject comment : commentList) {
      // This does not require a network access.
      ParseObject post = comment.getParseObject("post");
      Log.d("post", "retrieved a related post");
    }
  }
});

satya - 3/15/2013 11:35:43 AM

Is there a way to put unique constraints in Parse?

Is there a way to put unique constraints in Parse?

Search for: Is there a way to put unique constraints in Parse?

satya - 4/1/2013 3:55:17 PM

The include is documented here

The include is documented here

satya - 4/1/2013 3:59:05 PM

Apparently you can do this for nested includes


ParseQuery query = new ParseQuery(WordMeaning.t_tablename);
query.whereEqualTo(WordMeaning.f_word, word);
query.orderByDescending(WordMeaning.f_createdAt);
       
//Include who created me
query.include(WordMeaning.f_createdBy);
       
//Include who the parent word is
query.include(WordMeaning.f_word);
       
//How can I include the owner of the word
query.include(WordMeaning.f_word + "." + Word.f_createdBy);

I am not sure if I need to do both


include("parent1)
include("parent1.parent2");

or just the later would do

satya - 4/2/2013 8:55:38 AM

Can I tell parse to always include a child object?

Can I tell parse to always include a child object?

Search for: Can I tell parse to always include a child object?

satya - 4/2/2013 4:16:05 PM

Can I create a parse object from a parse Id on the client side?

Can I create a parse object from a parse Id on the client side?

Search for: Can I create a parse object from a parse Id on the client side?

satya - 4/5/2013 7:55:00 AM

Can I use put method to place arbitrary objects including date using parseobject.put method?

Can I use put method to place arbitrary objects including date using parseobject.put method?

satya - 4/5/2013 7:57:11 AM

Put method doc suggests

Values may be numerical, String, JSONObject, JSONArray, JSONObject.NULL, or other ParseObjects. value may not be null.

satya - 4/5/2013 7:58:06 AM

Here are my list of questions on parse at parse.com help section

Here are my list of questions on parse at parse.com help section

satya - 4/5/2013 7:59:14 AM

How can I create a shell of a parse object if I know its id

How can I create a shell of a parse object if I know its id

satya - 4/5/2013 8:13:56 AM

is there a way to know what are the list of keys in a parseobject?

is there a way to know what are the list of keys in a parseobject?

Search for: is there a way to know what are the list of keys in a parseobject?

satya - 4/5/2013 8:16:04 AM

Does anyone have an implementation of a Parcelable for a ParseObject?

Does anyone have an implementation of a Parcelable for a ParseObject?

Search for: Does anyone have an implementation of a Parcelable for a ParseObject?

satya - 4/5/2013 8:19:54 AM

Here is some discussion on this topic

Here is some discussion on this topic

Not yet!

satya - 4/5/2013 8:25:31 AM

is there a way to get the key collection of a ParseObject?

is there a way to get the key collection of a ParseObject?

Search for: is there a way to get the key collection of a ParseObject?

satya - 4/7/2013 8:28:28 AM

Few thoughts on parceling or serializing parse objects

They are not, by their sdk, parcelable or serializable. I have tried to write code to parcel them and they are not very cooperative. I was able to do this partially to get by.

But the fact appears to be a ParseObject may be doing more as part of its construction and behavior attached to it. If this were true we may be better of copying these objects where needed into pure Java Data Objects.

If you were to instead use a parse object underneath and do a look up based on reflection, we may not be able to overcome the need to searialize.

However we have to remember broadly that the power of no-sql is flexibility as well and not locked into a type. so what ever models we use they have to be hybrid. For instance you may want a parse object that can generate java objects of multiple types. or a single parse object behaving with multiple types. Like "TypeFaces!!" (A word I used to use when I want to cast a class to multiple types!)

satya - 4/10/2013 2:33:54 PM

Cache is enabled on the query object


query.setCachePolicy(ParseQuery.CachePolicy.CACHE_ELSE_NETWORK);
//milliseconds
query.setMaxCacheAge(100000L);

satya - 4/13/2013 9:34:23 PM

Here is an example of a query retrieving all objects

This query also sets the cache policy as above. This query did not put any where constraints.

satya - 4/13/2013 9:36:15 PM

Here is a screen that provides a meaning for a given word

This screen uses a particular approach for sending a parse object as a parcelable through an intent extra. The information you see about a word whose meaning we are trying to create is gotten through the intent extra!

satya - 4/13/2013 9:39:23 PM

And here is another query that uses wherclause and also the parcelable word

This screen uses an intent extra to get the word parse object extra and also uses that parceled parse object word as a target to the where clause of the meanings query.

Note that when I say I am transfering the parse object as a parcelable, that is not entirely true as I am using a parse object wrapper to do the trick and works reasonably well. I have to admit i have to write a page or two of code to make this work. Hopefully I will document that some other day!

satya - 4/15/2013 9:15:18 AM

Do I need to change parse keys if I change may android package name?

Do I need to change parse keys if I change may android package name?

Search for: Do I need to change parse keys if I change may android package name?

I have just changed my package name in my development environment. I didn't have to change my keys nor the application registration on parse.com. All the data is as before. So this is good. You can do this if you need to. Use the link above to see if there more nuances that I am not aware of at this early stage of a game!