Object Data Store using Google's App Engine
I have a working version of the webservice component of my google apps engine project now. Essentially, it means you can post xml to the webservice and it saves/retrieves/deletes it for you.
Here's a simple overview:
Let's say, for example, you had the following Class:
public class Contact { public string Author; public string Notes; public int NumOfBooks; public datetime Date; public bool isAuthor; }
With the following values:
Contact.Author = "Kenny Jacobson"; Contact.Notes = "Computer Programming"; Contact.NumOfBooks = 14; Contact.Date = "2008-05-22 21:35:33.796000"; Contact.isAuthor = True;
You would then format an XML doc as below and Post it to the "persist" function of our webservice (http://myGoogleApp/persist):
Since the value is blank, it knows this is a new record and will add it to the data store. After posting it, the webservice will return to you the unique Key it generated for your object. Let's say it gave us the key "aghvb2RzdG9yZXITCxINVEVTVDFfQ29udGFjdBglDA".
Then if we want to update the object we just added, we would include the key value when we post it again to the "persist" webservice (http://myGoogleApp/persist):
This will now Update our object.
Now, let's say we want to retrieve our object from the data store. We post an XML doc to the "retreive" function of our webservice (http://myGoogleApp/retrieve).
The XML document will contain the structure, but not the data and it will also include the Key of the object we what to retrieve:
This will return to us the structure with the data filled in.
There are two other options for the Key property when retrieving data, we can use the "All" keyword or we can use a "Where [property] [operator] [value]" (ex., "Where NumOfBooks > 10")
For example, to get all the objects of the type "Contact" you would send the following XML to the "retreive" function of our webservice (http://myGoogleApp/retrieve).
Which would return something like this:
Using the Where clause would look like this:
And return something like this (since Harper Lee only wrote one book...unlike the prolific two of us ;):
To delete, you post your XML to the "remove" function of the webservice (http://myGoogleApp/retrieve), with either the unique Key:
Or a where clause
Anyway, that's what I got so far it in a nutshell. It probably doesn't seem like much yet, but when I finish the next parts, I think it will come together a little more. What I'm looking at is eventually when you define your classes, you'll add a couple methods that will call the .NET "OO DataStore" class I create (in the example below I call it"KennysOODStore") that will allow you to the retrieve/persist/remove your objects. The KennysOODStore class (which is part of my mini framework) will format your class object (through reflection) into the XML doc and post it to my googleAppEngine webservice it will also retrieve the results and (again through reflection) "re-hydrate" your class object with the data it retrieved and return it to your calling client.
So your class that once looked like this:
public class Contact
{
public string Author;
public string Notes;
public int NumOfBooks;
public datetime Date;
public bool isAuthor;
}
{
public string Author;
public string Notes;
public int NumOfBooks;
public datetime Date;
public bool isAuthor;
}
would now look something like this:
public class Contact
{
public string Author;
public string Notes;
public int NumOfBooks;
public datetime Date;
public bool isAuthor;
{
public string Author;
public string Notes;
public int NumOfBooks;
public datetime Date;
public bool isAuthor;
public void Persist()
{
KennysOODStore.Persist(this);
}
public void Remove()
{
KennysOODStore.Remove(this);
}
public static Contact Retrieve(KennysOODStoreKey key)
{
return KennysOODStore.Retrieve(key);
}
{
KennysOODStore.Persist(this);
}
public void Remove()
{
KennysOODStore.Remove(this);
}
public static Contact Retrieve(KennysOODStoreKey key)
{
return KennysOODStore.Retrieve(key);
}
}
And your client code might look somethign like this:
Private void Page_Load(Object sender, EventArgs e)
{
Contact[] contacts = Contact.Retrieve("All");
{
Contact[] contacts = Contact.Retrieve("All");
/*Code to load your UI from the contacts you retrieved*/
}
Private void SaveContact_Click(Object sender, EventArgs e)
{
Contact contact = (Contact)myUIElement.Tag;
contact.Persist();
}
{
Contact contact = (Contact)myUIElement.Tag;
contact.Persist();
}
And that's it! No worrying about databases or data access layers or mapping your object to a relational model.
Now of course, I've created a very trivial example and objects get more complex since they can have properties which themselves our objects. So the developer would have to write the logic to persist the children objects too when the parent object is being persisted, but that's part of the fun of programming. To me the goal is to allow the developer to stay in the OO realm and not be bothered by the plumbing code that we always seem to have to write when when take OO stuff into the Relational world and then take Relational stuff back into the OO world. It also, of course, takes advantage of Google's speed, redundancy, high availability, indexing, low cost, etc.
Now, for asynchronous calls to the OO Datastore, it will require a couple more steps: probably five lines of code on the Client side, instead of the one line of code in the Client side. But hey, it's still going to be a very fast and efficient way to code your Silverlight front end with a Google backend.