Skip to content

Commit

Permalink
* get method extended
Browse files Browse the repository at this point in the history
* easy access query interface
  • Loading branch information
Juri Kuehn committed Oct 22, 2011
1 parent aba39d6 commit 9c1cb5b
Show file tree
Hide file tree
Showing 13 changed files with 818 additions and 650 deletions.
5 changes: 5 additions & 0 deletions CHANGES.textile
Expand Up @@ -2,6 +2,11 @@ h2. Change Log


Also see the "release notes of underlying morphia library":http://code.google.com/p/morphia/wiki/ReleaseNotes and the GORM-MongoDB "User Guide":http://jkuehn.github.com/gorm-mongodb/ Also see the "release notes of underlying morphia library":http://code.google.com/p/morphia/wiki/ReleaseNotes and the GORM-MongoDB "User Guide":http://jkuehn.github.com/gorm-mongodb/


h3. v0.7.5 - 2011-10-23
* MongoDB authentication configuration (thanks to Dave)
* "Convenient access to morphias query methods":http://jkuehn.github.com/gorm-mongodb/ref/Domain Classes/query.html
* Static get() method now also accepts com.mongodb.DBRef and com.google.code.morphia.Key instances

h3. v0.7.4 - 2011-10-13 h3. v0.7.4 - 2011-10-13
* Grails 2.0 compatibility * Grails 2.0 compatibility
* Added validation property to query parameters to optionally turn of validation (thanks to Alexander) * Added validation property to query parameters to optionally turn of validation (thanks to Alexander)
Expand Down
6 changes: 4 additions & 2 deletions MongodbMorphiaGrailsPlugin.groovy
Expand Up @@ -20,7 +20,7 @@ class MongodbMorphiaGrailsPlugin {
def scm = [ url: "https://github.com/jkuehn/gorm-mongodb" ] def scm = [ url: "https://github.com/jkuehn/gorm-mongodb" ]


// the plugin version // the plugin version
def version = "0.7.4" def version = "0.7.5"
// the version or versions of Grails the plugin is designed for // the version or versions of Grails the plugin is designed for
def grailsVersion = "1.3.4 > *" def grailsVersion = "1.3.4 > *"
// the other plugins this plugin depends on // the other plugins this plugin depends on
Expand All @@ -39,7 +39,7 @@ class MongodbMorphiaGrailsPlugin {


def author = "Juri Kuehn" def author = "Juri Kuehn"
def authorEmail = "juri.kuehn at gmail.com" def authorEmail = "juri.kuehn at gmail.com"
def title = "Alternative MongoDB GORM based on the Morphia library (former gorm-mongodb)" def title = "Alternative MongoDB GORM based on the Morphia library"
def description = '''GORM implementation for the MongoDB NoSQL database based on the Morphia library''' def description = '''GORM implementation for the MongoDB NoSQL database based on the Morphia library'''


// URL to the plugin's documentation // URL to the plugin's documentation
Expand Down Expand Up @@ -118,6 +118,8 @@ class MongodbMorphiaGrailsPlugin {
} }
datastore.getByKey(clazz, delegate) datastore.getByKey(clazz, delegate)
} }

MongoPluginSupport.enhanceMorphiaQueryClass()
} }


/** /**
Expand Down
2 changes: 1 addition & 1 deletion README.textile
Expand Up @@ -12,4 +12,4 @@ Special thanks to the contributors:
* Alex Duan * Alex Duan
* Alexander Riss * Alexander Riss
* Hasan Ozgan * Hasan Ozgan

* Dave Smith
2 changes: 1 addition & 1 deletion TODO.textile
@@ -1,7 +1,7 @@
h1. TODOs / ideas for next releases h1. TODOs / ideas for next releases


* check code in MongoPluginSupport for changes borrowed from org.codehaus.groovy.grails.plugins.DomainClassGrailsPlugin
* implement "sparse index definitions":http://www.mongodb.org/display/DOCS/Indexes#Indexes-SparseIndexes for MongoDB 1.8 * implement "sparse index definitions":http://www.mongodb.org/display/DOCS/Indexes#Indexes-SparseIndexes for MongoDB 1.8
* Check out Datastore getByKeys(keys) for Key.fetch() - if not working with fetched keys from db (has no kindClass), then raise issue
* write some documentation with examples for referencing and embedding entities * write some documentation with examples for referencing and embedding entities
* document TransformationConfiguration annotation and put a page about inheritance in the docs * document TransformationConfiguration annotation and put a page about inheritance in the docs
* document merge() instance method * document merge() instance method
Expand Down
10 changes: 5 additions & 5 deletions application.properties
@@ -1,8 +1,8 @@
#Grails Metadata file #Grails Metadata file
#Thu Oct 13 18:24:25 CEST 2011 #Sat Oct 22 14:08:52 CEST 2011
app.grails.version=2.0.0.M2 app.grails.version=2.0.0.RC1
app.name=mongodb-morphia app.name=mongodb-morphia
app.version=0.7.4 app.version=0.7.5
plugins.hibernate=2.0.0.M2 plugins.hibernate=2.0.0.RC1
plugins.release=1.0.0.RC3 plugins.release=1.0.0.RC3
plugins.tomcat=2.0.0.M2 plugins.tomcat=2.0.0.RC1
2 changes: 1 addition & 1 deletion grails-app/conf/DataSource.groovy
Expand Up @@ -4,7 +4,7 @@ mongodb {
if (currentHost == 'rem-juri') { if (currentHost == 'rem-juri') {
replicaSet = [ "localhost:27017"] replicaSet = [ "localhost:27017"]
} else if (System.getProperty('user.name').toLowerCase() == 'juri') { } else if (System.getProperty('user.name').toLowerCase() == 'juri') {
replicaSet = [ "192.168.1.101:27017"] replicaSet = [ "192.168.1.100:27017"]
} else { } else {
replicaSet = [ "localhost:27017"] replicaSet = [ "localhost:27017"]
} }
Expand Down
4 changes: 2 additions & 2 deletions src/docs/guide/1. Introduction.gdoc
Expand Up @@ -9,9 +9,9 @@ Features implemented to far:
* Constraints and validation support * Constraints and validation support
* Automatic timestamping of dateCreated and lastUpdated * Automatic timestamping of dateCreated and lastUpdated
* Gorm events beforeSave, afterSave, beforeDelete, afterDelete, beforeValidate (others, like afterLoad are supported by "Morphia":http://code.google.com/p/morphia/wiki/LifecycleMethods ) * Gorm events beforeSave, afterSave, beforeDelete, afterDelete, beforeValidate (others, like afterLoad are supported by "Morphia":http://code.google.com/p/morphia/wiki/LifecycleMethods )
* Works with MongoDB 1.6 and 1.8 * Works with MongoDB 1.6, 1.8 and 2.0
* AST Transformations that inject all necessary fields and annotations for morphia * AST Transformations that inject all necessary fields and annotations for morphia
* Lazy references supported * Lazy references supported (experimental)
* generate-all support * generate-all support


This plugin is not feature complete concerning the GORM api. Yet it has been proven to be very stable in our production environment. See the "quickstart":2.%20Quickstart.html page for a usage example. You can also download a "petclinic sample application port":https://github.com/jkuehn/gorm-mongodb which uses mongodb-morphia to see the use of embedded and referenced domain classes. This plugin is not feature complete concerning the GORM api. Yet it has been proven to be very stable in our production environment. See the "quickstart":2.%20Quickstart.html page for a usage example. You can also download a "petclinic sample application port":https://github.com/jkuehn/gorm-mongodb which uses mongodb-morphia to see the use of embedded and referenced domain classes.
Expand Down
2 changes: 1 addition & 1 deletion src/docs/ref/Domain Classes/get.gdoc
Expand Up @@ -14,5 +14,5 @@ h2. Description


Parameters: Parameters:


* @id@ - The id of the object to retrieve * @id@ - The id of the object to retrieve. Alternatively, you can pass a "com.mongodb.DBRef":http://api.mongodb.org/java/current/com/mongodb/DBRef.html or a "com.google.code.morphia.Key":http://morphia.googlecode.com/svn/site/morphia/apidocs/com/google/code/morphia/Key.html object.


58 changes: 58 additions & 0 deletions src/docs/ref/Domain Classes/query.gdoc
@@ -0,0 +1,58 @@
h1. query

h2. Purpose

Finds all of the domain class instances using morphias "query":http://morphia.googlecode.com/svn/site/morphia/apidocs/com/google/code/morphia/query/QueryImpl.html

h2. Examples

{code:java}
// get a query instance for Book class
def query = Book.query()

// get a query instance for Book class, precofigured with pagination params
def query = Book.query(params)

// pass a closure that will be executed in query context
def query = Book.query([sort: "releaseDate", order: "desc"]) {
field('author').equal("Steven King")
field('title').startsWith("The")
}

// pass a closure only
def query = Book.query() {
field('author').equal("Steven King")
field('title').startsWith("The")
offset(10)
}.asList()

// work with query object
def query = Book.query()
query.field('author').equal("Steven King")
query.field('title').startsWith("The")
query.offset(10)


// Query interface provides many methods for returning the results
query.asList() // return matched results as List
query.get() // return first result
for (Book book in query) { ... } // query implements the Iterable interface

{code}

h2. Description

{code:java}
Book.query( )
Book.query( Map params )
Book.query( Map params, Closure config )
{code}

Parameters:

* @params@ - A Map containing parameters @max@, @offset@, @sort@, @order@ and @validation@ (to turn off morphia mapping validation)
* @config@ - A closure that will be executed in context of Query

Returns:

Instance of a "QueryImpl":http://morphia.googlecode.com/svn/site/morphia/apidocs/com/google/code/morphia/query/QueryImpl.html

0 comments on commit 9c1cb5b

Please sign in to comment.