Skip to content

Commit a06b0d7

Browse files
Juri Kuehnalexander-riss
Juri Kuehn
authored andcommitted
GPGORMMONGODB-15
1 parent ac69ea8 commit a06b0d7

File tree

1 file changed

+28
-20
lines changed

1 file changed

+28
-20
lines changed

Diff for: src/groovy/grails/plugins/mongodb/MongoPluginSupport.groovy

+28-20
Original file line numberDiff line numberDiff line change
@@ -172,19 +172,23 @@ class MongoPluginSupport {
172172
* http://code.google.com/p/morphia/wiki/Updating
173173
*/
174174
metaClass.update = { Closure data, boolean createIfMissing = false, WriteConcern wc = null ->
175-
if (!delegate.ident()) {
176-
throw new IllegalStateException("Cannot update instances without an id")
177-
}
178-
def query = datastore.createQuery(delegate.class)
179-
def updateOp = datastore.createUpdateOperations(delegate.class)
175+
update(data, createIfMissing, false, wc)
176+
}
180177

181-
query.filter(Mapper.ID_KEY, delegate.ident());
178+
metaClass.update = { Closure data, boolean createIfMissing = false, boolean multi = true, WriteConcern wc = null ->
179+
if (!delegate.ident()) {
180+
throw new IllegalStateException("Cannot update instances without an id")
181+
}
182+
def query = datastore.createQuery(delegate.class)
183+
def updateOp = datastore.createUpdateOperations(delegate.class)
182184

183-
data.delegate = updateOp
184-
data()
185+
query.filter(Mapper.ID_KEY, delegate.ident());
185186

186-
def updateResult = datastore.update(query, updateOp, createIfMissing, wc)
187-
}
187+
data.delegate = updateOp
188+
data()
189+
190+
datastore.update(query, updateOp, createIfMissing, multi, wc)
191+
}
188192

189193
metaClass.delete = { ->
190194
triggerEvent(EVENT_BEFORE_DELETE, delegate)
@@ -297,20 +301,24 @@ class MongoPluginSupport {
297301
}
298302

299303
metaClass.static.update = { filter, Closure data, boolean createIfMissing = false, WriteConcern wc = null ->
300-
if (!(filter instanceof Map)) filter = [(Mapper.ID_KEY): _checkedId(domainClass, filter)]
304+
update(filter, data, createIfMissing, false, wc)
305+
}
301306

302-
def query = datastore.createQuery(domainClass.clazz)
303-
def updateOp = datastore.createUpdateOperations(domainClass.clazz)
307+
metaClass.static.update = { filter, Closure data, boolean createIfMissing = false, boolean multi = true, WriteConcern wc = null ->
308+
if (!(filter instanceof Map)) filter = [(Mapper.ID_KEY): _checkedId(domainClass, filter)]
304309

305-
filter.each { k, v ->
306-
query.filter(k.toString(), v)
307-
}
310+
def query = datastore.createQuery(domainClass.clazz)
311+
def updateOp = datastore.createUpdateOperations(domainClass.clazz)
308312

309-
data.delegate = updateOp
310-
data()
313+
filter.each { k, v ->
314+
query.filter(k.toString(), v)
315+
}
311316

312-
def updateResult = datastore.update(query, updateOp, createIfMissing, wc)
313-
}
317+
data.delegate = updateOp
318+
data()
319+
320+
datastore.update(query, updateOp, createIfMissing, multi, wc)
321+
}
314322

315323
/**
316324
* creates a new instance of this class and populates fields from DBObject

0 commit comments

Comments
 (0)