Permalink
Browse files

- Adjusted conversions of incoming data on $in/$nin/$all to catch every

   case properly and not create nested arrays.   Should convert all
   possible values.
- Rel 1.0.7.3
  • Loading branch information...
bwmcadams committed Aug 2, 2010
1 parent 8fe206c commit 743c153cd0d7276f40a75f0b9c13102fa02db8e2
View
@@ -3,7 +3,7 @@
project.organization=com.novus
project.name=casbah
sbt.version=0.7.4
-project.version=1.0.7
+project.version=1.0.7.3
def.scala.version=2.7.7
build.scala.versions=2.8.0
project.initialize=false
@@ -263,7 +263,13 @@ trait GreaterThanEqualOp extends QueryOperator {
*/
trait InOp extends QueryOperator {
def $in(target: Array[Any]) = op("$in", target.toList.asJava)
- def $in(target: Any*) = op("$in", target.toList.asJava)
+ def $in(target: Any*) =
+ if (target.size > 1)
+ op("$in", target.toList.asJava)
+ else if (!target(0).isInstanceOf[Iterable[_]] &&
+ !target(0).isInstanceOf[Array[_]])
+ op("$in", List(target(0)))
+ else op("$in", target(0))
}
/**
@@ -283,7 +289,13 @@ trait InOp extends QueryOperator {
*/
trait NotInOp extends QueryOperator {
def $nin(target: Array[Any]) = op("$nin", target.toList.asJava)
- def $nin(target: Any*) = op("$nin", target.toList.asJava)
+ def $nin(target: Any*) =
+ if (target.size > 1)
+ op("$nin", target.toList.asJava)
+ else if (!target(0).isInstanceOf[Iterable[_]] &&
+ !target(0).isInstanceOf[Array[_]])
+ op("$nin", List(target(0)))
+ else op("$nin", target(0))
}
/**
@@ -303,7 +315,13 @@ trait NotInOp extends QueryOperator {
*/
trait AllOp extends QueryOperator {
def $all(target: Array[Any]) = op("$all", target.toList.asJava)
- def $all(target: Any*) = op("$all", target.toList.asJava)
+ def $all(target: Any*) =
+ if (target.size > 1)
+ op("$all", target.toList.asJava)
+ else if (!target(0).isInstanceOf[Iterable[_]] &&
+ !target(0).isInstanceOf[Array[_]])
+ op("$all", List(target(0)))
+ else op("$all", target(0))
}
/**
@@ -1,5 +1,5 @@
log {
- level = "trace"
+ level = "info"
console = on
}
@@ -138,9 +138,18 @@ class FluidMongoSyntaxSpec extends FeatureSpec with GivenWhenThen with ShouldMat
assert(exists == ("foo" -> new BasicDBObject("$exists", false)))
given("A field, <IN OPERATOR>, target array")
val in = "foo" $in (1, 8, 12)
+ log.info("in: %s", in)
+ log.info("in: %s", in.get("foo"))
then("The implicit conversions provide a map-entry formatted Tuple-set matching the query.")
assert(in._1 == "foo")
assert(in.toString != null) // Test to verify mongo's toString serialization doesn't choke
+ and("Iterables serialize correctly")
+ val in2 = "foo" $in List(1, 2, 3)
+ log.info("in2: %s", in2)
+ log.info("in2: %s", in2.get("foo"))
+ val in3 = "bar" $in List("Test")
+ log.info("in3: %s", in3)
+ log.info("in3: %s", in3.get("bar"))
// One more test of bad data that keeps cropping up
val x = scala.collection.mutable.Buffer("X:YZ", "X:FOOBAR", "X:123", "Z:ABC", "Z:SPAM", "Z:EGGS")
for ((tag, values) <- x.map(_.split(":")).groupBy(_(0))) {

0 comments on commit 743c153

Please sign in to comment.