Permalink
Browse files

Merge pull request #46 from varju/return-write-result

Expose WriteResult to callers of DAO.update
  • Loading branch information...
2 parents bfb59a0 + 9c57a44 commit 25aac993a670b815581d9ce73a118ceebcf13e61 @rktoomey rktoomey committed Nov 24, 2012
@@ -131,17 +131,19 @@ trait BaseDAOMethods[ObjectType <: AnyRef, ID <: Any] {
* @param upsert if the database should create the element if it does not exist
* @param multi if the update should be applied to all objects matching
* @param wc write concern
+ * @return (WriteResult) result of write operation
*/
- def update(q: DBObject, o: DBObject, upsert: Boolean, multi: Boolean, wc: WriteConcern)
+ def update(q: DBObject, o: DBObject, upsert: Boolean, multi: Boolean, wc: WriteConcern): WriteResult
/** Performs an update operation.
* @param q search query for old object to update
* @param t object with which to update <tt>q</tt>
* @param upsert if the database should create the element if it does not exist
* @param multi if the update should be applied to all objects matching
* @param wc write concern
+ * @return (WriteResult) result of write operation
*/
- def update(q: DBObject, t: ObjectType, upsert: Boolean, multi: Boolean, wc: WriteConcern) {
+ def update(q: DBObject, t: ObjectType, upsert: Boolean, multi: Boolean, wc: WriteConcern): WriteResult = {
update(q = q, o = toDBObject(t), upsert = upsert, multi = multi, wc = wc)
}
@@ -267,7 +267,7 @@ trait ModelCompanion[ObjectType <: AnyRef, ID <: Any] extends BaseDAOMethods[Obj
dao.save(t, wc)
}
- def update(q: DBObject, o: DBObject, upsert: Boolean, multi: Boolean, wc: WriteConcern = defaultWriteConcern) {
+ def update(q: DBObject, o: DBObject, upsert: Boolean, multi: Boolean, wc: WriteConcern = defaultWriteConcern): WriteResult = {
dao.update(q, o, upsert, multi, wc)
}
@@ -376,14 +376,16 @@ abstract class SalatDAO[ObjectType <: AnyRef, ID <: Any](val collection: MongoCo
* @param upsert if the database should create the element if it does not exist
* @param multi if the update should be applied to all objects matching
* @param wc write concern
+ * @return (WriteResult) result of write operation
*/
- def update(q: DBObject, o: DBObject, upsert: Boolean = false, multi: Boolean = false, wc: WriteConcern = defaultWriteConcern) {
+ def update(q: DBObject, o: DBObject, upsert: Boolean = false, multi: Boolean = false, wc: WriteConcern = defaultWriteConcern): WriteResult = {
try {
val wr = collection.update(q, o, upsert, multi, wc)
val lastError = wr.getCachedLastError
if (lastError != null && !lastError.ok()) {
throw SalatDAOUpdateError(description, collection, q, o, wc, wr, upsert, multi)
}
+ wr
}
}
@@ -117,11 +117,12 @@ class SalatDAOSpec extends SalatSpec {
AlphaDAO.collection.count must_== 1L
// need to explicitly specify upsert and multi when updating using an object instead of dbo
- val cr = AlphaDAO.update(q = MongoDBObject("_id" -> 3),
+ val wr = AlphaDAO.update(q = MongoDBObject("_id" -> 3),
t = alpha3.copy(beta = List[Beta](Gamma("gamma3"))),
upsert = false,
multi = false,
wc = new WriteConcern())
+ wr.getN must_== 1L
AlphaDAO.collection.count must_== 1L

0 comments on commit 25aac99

Please sign in to comment.