Browse files

Merge branch 'master' into ALTERNATE_REALITY

  • Loading branch information...
2 parents d9961cf + 5744ccd commit b79834156e83e2b01ca74d271261022099ac97ed @rktoomey rktoomey committed Jan 10, 2012
Showing with 12 additions and 6 deletions.
  1. +12 −6 salat-core/src/main/scala/com/novus/salat/dao/SalatDAO.scala
View
18 salat-core/src/main/scala/com/novus/salat/dao/SalatDAO.scala
@@ -196,7 +196,8 @@ abstract class SalatDAO[ObjectType <: CaseClass, ID <: Any](val collection: Mong
val _id = try {
val dbo = ctx.toDBObject(t)
val wr = collection.insert(dbo, wc)
- if (wr.getCachedLastError == null) {
+ val error = wr.getCachedLastError
+ if (error == null || (error != null && error.ok())) {
dbo.getAs[ID]("_id")
}
else {
@@ -211,7 +212,8 @@ abstract class SalatDAO[ObjectType <: CaseClass, ID <: Any](val collection: Mong
val _ids = try {
val dbos = docs.map(t => ctx.toDBObject(t))
val wr = collection.insert(dbos, wc)
- if (wr.getCachedLastError == null) {
+ val lastError = wr.getCachedLastError
+ if (lastError == null || (lastError != null && lastError.ok())) {
val builder = List.newBuilder[Option[ID]]
for (dbo <- dbos) {
builder += dbo.getAs[ID]("_id") orElse {
@@ -248,7 +250,8 @@ abstract class SalatDAO[ObjectType <: CaseClass, ID <: Any](val collection: Mong
try {
val dbo = ctx.toDBObject(t)
val wr = collection.remove(dbo, wc)
- if (wr.getCachedLastError != null) {
+ val lastError = wr.getCachedLastError
+ if (lastError != null && !lastError.ok()) {
throw SalatRemoveError(description, collection, wc, wr, List(dbo))
}
}
@@ -261,7 +264,8 @@ abstract class SalatDAO[ObjectType <: CaseClass, ID <: Any](val collection: Mong
def remove[A <% DBObject](q: A, wc: WriteConcern) {
try {
val wr = collection.remove(q, wc)
- if (wr.getCachedLastError != null) {
+ val lastError = wr.getCachedLastError
+ if (lastError != null && !lastError.ok()) {
throw SalatRemoveQueryError(description, collection, q, wc, wr)
}
}
@@ -283,7 +287,8 @@ abstract class SalatDAO[ObjectType <: CaseClass, ID <: Any](val collection: Mong
try {
val dbo = ctx.toDBObject(t)
val wr = collection.save(dbo, wc)
- if (wr.getCachedLastError != null) {
+ val lastError = wr.getCachedLastError
+ if (lastError != null && !lastError.ok()) {
throw SalatSaveError(description, collection, wc, wr, List(dbo))
}
}
@@ -292,7 +297,8 @@ abstract class SalatDAO[ObjectType <: CaseClass, ID <: Any](val collection: Mong
def update[A <% DBObject, B <% DBObject](q: A, o: B, upsert: Boolean = false, multi: Boolean = false, wc: WriteConcern = collection.writeConcern) {
try {
val wr = collection.update(q, o, upsert, multi, wc)
- if (wr.getCachedLastError != null) {
+ val lastError = wr.getCachedLastError
+ if (lastError != null && !lastError.ok()) {
throw SalatDAOUpdateError(description, collection, q, o, wc, wr, upsert, multi)
}
}

0 comments on commit b798341

Please sign in to comment.