KEMBAR78
Using MongoDB With Groovy | PPT
Using MongoDB with Groovy James Williams (@ecspike) BT/Ribbit
Just as NoSQL is... post - relational schemaless flexible
Groovy is ... a superset of Java open to metaprogramming a more concise way to write code
Groovy + Mongo Java BasicDBObject doc = new BasicDBObject(); doc.put("name", "MongoDB"); doc.put("type", "database"); doc.put("count", 1); coll.insert(doc); Groovier def doc = [name:"MongoDB", count:1,type:"database", info: [x:203, y:102]            ] as BasicDBObject coll.insert(doc) Grooviest (using groovy-mongo) coll.insert([name:"MongoDB", type:"database", info: [x:203, y:102]])
Dynamic Finders let you query the database as if there was a schema build complex query functions at runtime          Ex.  collection.findByAuthorAndPostCreatedGreaterThan(...)           collection.findByComments_CreatedOn(...)
How dynamic finders work Groovy tries to execute the function but can't find it It invokes methodMissing instead The body of methodMissing takes the attempted method name and parses it It uses the names and the modifiers (>, <, etc) with BasicDBObjectBuilder to create a prototype It caches the created function under that name and runs it.  Further invocations don't incur the performance hit.
Groovy + Mongo in the wild
Links Andrill: http://andrill.org CoreRef: http://coreref.org groovy-mongo: http://github.com/jwill/groovy-mongo Personal Blog: http://jameswilliams.be/blog Twitter: @ecspike

Using MongoDB With Groovy

  • 1.
    Using MongoDB withGroovy James Williams (@ecspike) BT/Ribbit
  • 2.
    Just as NoSQLis... post - relational schemaless flexible
  • 3.
    Groovy is ...a superset of Java open to metaprogramming a more concise way to write code
  • 4.
    Groovy + MongoJava BasicDBObject doc = new BasicDBObject(); doc.put(&quot;name&quot;, &quot;MongoDB&quot;); doc.put(&quot;type&quot;, &quot;database&quot;); doc.put(&quot;count&quot;, 1); coll.insert(doc); Groovier def doc = [name:&quot;MongoDB&quot;, count:1,type:&quot;database&quot;, info: [x:203, y:102]            ] as BasicDBObject coll.insert(doc) Grooviest (using groovy-mongo) coll.insert([name:&quot;MongoDB&quot;, type:&quot;database&quot;, info: [x:203, y:102]])
  • 5.
    Dynamic Finders letyou query the database as if there was a schema build complex query functions at runtime          Ex. collection.findByAuthorAndPostCreatedGreaterThan(...)           collection.findByComments_CreatedOn(...)
  • 6.
    How dynamic finderswork Groovy tries to execute the function but can't find it It invokes methodMissing instead The body of methodMissing takes the attempted method name and parses it It uses the names and the modifiers (>, <, etc) with BasicDBObjectBuilder to create a prototype It caches the created function under that name and runs it.  Further invocations don't incur the performance hit.
  • 7.
    Groovy + Mongoin the wild
  • 8.
    Links Andrill: http://andrill.orgCoreRef: http://coreref.org groovy-mongo: http://github.com/jwill/groovy-mongo Personal Blog: http://jameswilliams.be/blog Twitter: @ecspike