Monday, February 27, 2012

Storing Documents in AppEngine's Datastore

Storing Documents in AppEngine's Datastore

One of the advantages of Google AppEngine's Datastore is that it is schema-less. You can simply store any Entity you wish, as long as you abide the indexes.
In this post, I will mimic the MongoDB document store, where you can store any kind of JSON document in your collection, as long as it has attributes for your collection's indexes.

Objectives

  • I would like to access the document store using a generic REST-JSON API, which implements basic CRUD methods plus a query method
  • On the consumer side, I  would like to map to POJOs, not a map
  • I would like to be able to store new kinds of objects without interrupting the service
  • I would like to be able to introduce new attributes on my entities without updating any of the existing entities

Source for the json-doc-store

The source code is hosted on BitBucket.
hg clone https://bitbucket.org/f94os/json-doc-store

Binding request from JSON to Map

The intermediate data type when using Spring and jackson JSON mapper is the Map class:
    @RequestMapping(value="{kind}", method= RequestMethod.POST)
    public ResponseEntity createDocument(
            @PathVariable String kind,
            @RequestParam String id,
            @RequestBody Map props
            ) { 
      // Spring and Jackson binds my JSON object to a Map 
// Bind to AppEngine Datastore Entities // persist in datastore }

Read a document from the datastore

The Spring Controller method to create entities looks like this:
Create by kind only (generate key)
    @RequestMapping(value="{kind}/{id}", method= RequestMethod.GET)
    public ResponseEntity> getDocument(
            @PathVariable String kind,
            @PathVariable Object id
            ) {
        
        // query for ancestors, including ancestor

        // bind from Entities to Map
 
        // Jackson will serialize from Map to JSON 
     }

Namespace and Kind

A relational database can be compared to using Namespaces in the Datastore, and a table can be compared to using the Entity Kind.

Admin database

MySQL uses a database with tables for users, user databases, user tables and so on. The same concept is done here, with an admin Namespace of json-doc-store, and two Kinds, _DBs and _Users.

Friday, December 23, 2011

Podcast

Here's a link to the podcast SourceForge created about mardao, featuring me :-)
http://sourceforge.net/blog/podcast-mardao/

Merry Chrismas everyone!
Ola

Saturday, December 10, 2011

Mardao going Mobile

Mardao is a tool saving you hours and hours of boring work writing boilerplate data access code. It could also save you a bug or two, as it generates code.

Currently, Mardao supports generating code for Spring JDBC / MySQL, JPA and Google AppEngine's Datastore. It is used in production services on all three platforms, and the tool is considered stable. The current version is 1.15.

Next step in Mardao's roadmap is to generate code for Android apps, as the fit with the SQLite database is really good.

I'd simply love to hear about your usage, and feedback on the API as well as features. Perhaps even write a review?

Are you keen to contribute? Mardao is open source, and can be found at http://mardao.sourceforge.net/
 

Saturday, August 27, 2011

Ricotta now speaks Khmer!

Welcome Bormy to the Ricotta development team!
The first step of recursion has been taken, making Ricotta a localised service by using Ricotta! So now, point your browsers to
http://ricotta-ost.appspot.com/index.html
and make sure your browser prefers Khmer, and you'll see.

Saturday, May 21, 2011

Ricotta revisited

Hi, after many weeks without new features, Ricotta has now undergone a major refactoring. Switching to mardao 1.9 gives dramatic improvements on the data persistence layer, and changes to the UI based on real user feedback are appreciated.

Ricotta is a translations tool for any software project with resources separated from code, e.g. Android and iPhone apps projects, and most JavaEE web apps.

Make sure you have a look, it's free to use, hosted on Google AppEngine at
http://ricotta-ost.appspot.com

Saturday, January 15, 2011

Ricotta - Translation Management Tool

I have been working on a new open source project called Ricotta, which is a translations management tool.

You define your tokens and translate them online. Then, you download resource files to your workspace, and they are rendered using different templates. One for java web apps, a different one for Android projects and so on.
You can also import your existing resource files into Ricotta, to get a quick start.

This project is using Mardao, and is hosted on Google AppEngine.

For downloads and more information, see
http://ricotta-ost.appspot.com/index.html

Sunday, November 28, 2010

Spring-ws on AppEngine

Use Spring-ws 1.5.8 and Spring framework 3.0.2.RELEASE.

Replace soap's messageFactory with an AxiomMessageFactory. Use Axiom 1.2.8.

Use xmlBeans for marshalling.