Permalink
Browse files

Fixed scope of some more obnoxious implicit conversions.

  • Loading branch information...
nuttycom committed Dec 28, 2012
1 parent f22cc94 commit 1e9b8964de1202ffa8d323dc4649afb2cb29a989
Showing with 390 additions and 364 deletions.
  1. 0 actor/src/main/scala/blueeyes/{actor/package.scala → actor.scala}
  2. 0 actor/src/main/scala/blueeyes/persistence/cache/{functional/package.scala → functional.scala}
  3. 0 core/src/main/scala/{blueeyes/package.scala → blueeyes.scala}
  4. 0 core/src/main/scala/blueeyes/core/{http/package.scala → http.scala}
  5. +35 −147 mongo/src/main/scala/blueeyes/persistence/mongo/MongoFilter.scala
  6. +49 −0 mongo/src/main/scala/blueeyes/persistence/mongo/MongoFilterOperators.scala
  7. +0 −24 mongo/src/main/scala/blueeyes/persistence/mongo/MongoImplicits.scala
  8. +1 −7 mongo/src/main/scala/blueeyes/persistence/mongo/MongoPatch.scala
  9. +4 −2 mongo/src/main/scala/blueeyes/persistence/mongo/MongoPatches.scala
  10. +72 −0 mongo/src/main/scala/blueeyes/persistence/mongo/MongoPrimitive.scala
  11. +1 −1 mongo/src/main/scala/blueeyes/persistence/mongo/MongoQuery.scala
  12. +1 −1 mongo/src/main/scala/blueeyes/persistence/mongo/MongoStage.scala
  13. +58 −25 mongo/src/main/scala/blueeyes/persistence/mongo/MongoUpdate.scala
  14. +52 −0 mongo/src/main/scala/blueeyes/persistence/mongo/dsl.scala
  15. +0 −60 mongo/src/main/scala/blueeyes/persistence/mongo/package.scala
  16. +2 −1 mongo/src/test/scala/blueeyes/persistence/mongo/AddToSetFSpec.scala
  17. +3 −1 mongo/src/test/scala/blueeyes/persistence/mongo/ArbitraryMongo.scala
  18. +1 −1 mongo/src/test/scala/blueeyes/persistence/mongo/EnsureIndexQueryBehaviourSpec.scala
  19. +1 −0 mongo/src/test/scala/blueeyes/persistence/mongo/ExplainQueryBehaviourSpec.scala
  20. +2 −1 mongo/src/test/scala/blueeyes/persistence/mongo/IncFSpec.scala
  21. +1 −1 mongo/src/test/scala/blueeyes/persistence/mongo/InsertQueryBehaviourSpec.scala
  22. +2 −2 mongo/src/test/scala/blueeyes/persistence/mongo/MongoAndFilterSpec.scala
  23. +2 −2 mongo/src/test/scala/blueeyes/persistence/mongo/MongoCountQuerySpec.scala
  24. +2 −3 mongo/src/test/scala/blueeyes/persistence/mongo/MongoDistinctQuerySpec.scala
  25. +3 −2 mongo/src/test/scala/blueeyes/persistence/mongo/MongoEnsureIndexQuerySpec.scala
  26. +2 −13 mongo/src/test/scala/blueeyes/persistence/mongo/MongoFieldFilterSpec.scala
  27. +1 −1 mongo/src/test/scala/blueeyes/persistence/mongo/MongoFilterBuilderSpec.scala
  28. +5 −4 mongo/src/test/scala/blueeyes/persistence/mongo/MongoGroupQuerySpec.scala
  29. +4 −4 mongo/src/test/scala/blueeyes/persistence/mongo/MongoMapReduceQuerySpec.scala
  30. +8 −8 mongo/src/test/scala/blueeyes/persistence/mongo/MongoOrFilterSpec.scala
  31. +13 −10 mongo/src/test/scala/blueeyes/persistence/mongo/MongoPatchesSpec.scala
  32. +1 −1 mongo/src/test/scala/blueeyes/persistence/mongo/MongoQueryBehaviourSpec.scala
  33. +1 −1 mongo/src/test/scala/blueeyes/persistence/mongo/MongoQueryBuilderSpec.scala
  34. +3 −2 mongo/src/test/scala/blueeyes/persistence/mongo/MongoRemoveQuerySpec.scala
  35. +3 −4 mongo/src/test/scala/blueeyes/persistence/mongo/MongoSelectOneQuerySpec.scala
  36. +5 −5 mongo/src/test/scala/blueeyes/persistence/mongo/MongoSelectQuerySpec.scala
  37. +10 −9 mongo/src/test/scala/blueeyes/persistence/mongo/MongoStageSpec.scala
  38. +5 −2 mongo/src/test/scala/blueeyes/persistence/mongo/MongoUpdateBuilderSpec.scala
  39. +1 −0 mongo/src/test/scala/blueeyes/persistence/mongo/MongoUpdateFieldSpec.scala
  40. +2 −0 mongo/src/test/scala/blueeyes/persistence/mongo/MongoUpdateFieldsSpec.scala
  41. +3 −2 mongo/src/test/scala/blueeyes/persistence/mongo/MongoUpdateNothingSpec.scala
  42. +3 −2 mongo/src/test/scala/blueeyes/persistence/mongo/MongoUpdateQuerySpec.scala
  43. +4 −2 mongo/src/test/scala/blueeyes/persistence/mongo/MongoUpdateSpec.scala
  44. +3 −1 mongo/src/test/scala/blueeyes/persistence/mongo/PullAllFSpec.scala
  45. +4 −1 mongo/src/test/scala/blueeyes/persistence/mongo/PullFSpec.scala
  46. +2 −1 mongo/src/test/scala/blueeyes/persistence/mongo/PushAllFSpec.scala
  47. +2 −1 mongo/src/test/scala/blueeyes/persistence/mongo/PushFSpec.scala
  48. +2 −1 mongo/src/test/scala/blueeyes/persistence/mongo/RealMongoBenchmarkSpec.scala
  49. +1 −1 mongo/src/test/scala/blueeyes/persistence/mongo/RemoveQueryBehaviourSpec.scala
  50. +2 −2 mongo/src/test/scala/blueeyes/persistence/mongo/SelectOneQueryBehaviourSpec.scala
  51. +2 −1 mongo/src/test/scala/blueeyes/persistence/mongo/SetFSpec.scala
  52. +2 −1 mongo/src/test/scala/blueeyes/persistence/mongo/UnsetFSpec.scala
  53. +4 −3 mongo/src/test/scala/blueeyes/persistence/mongo/UpdateQueryBehaviourSpec.scala
@@ -1,52 +1,10 @@
package blueeyes.persistence.mongo
-import scala.math.BigInt
-import blueeyes.json.{JPath, JPathIndex, JPathField, MergeMonoid, ConcatMonoid}
import blueeyes.json._
-import blueeyes.util.ProductPrefixUnmangler
-
-import scalaz.Scalaz._
-
-object MongoFilterOperators {
- sealed trait MongoFilterOperator extends Product with ProductPrefixUnmangler {
- def symbol: String = unmangledName
-
- def unary_! : MongoFilterOperator
-
- override def toString = symbol
- }
- sealed trait MongoFilterOperatorBound extends MongoFilterOperator
- case object $gt extends MongoFilterOperatorBound { def unary_! = $lte; }
- case object $gte extends MongoFilterOperatorBound { def unary_! = $lt; }
- case object $lt extends MongoFilterOperatorBound { def unary_! = $gte; }
- case object $lte extends MongoFilterOperatorBound { def unary_! = $gt; }
-
- sealed trait MongoFilterOperatorEquality extends MongoFilterOperator
- case object $eq extends MongoFilterOperatorEquality { def unary_! = $ne; } // This is a virtual operator, it's not real!!!!
- case object $ne extends MongoFilterOperatorEquality { def unary_! = $eq; }
- case object $regex extends MongoFilterOperatorEquality { def unary_! : MongoFilterOperator = sys.error("The $regex operator does not have a negation"); }
-
- sealed trait MongoFilterOperatorContainment extends MongoFilterOperator
- case object $in extends MongoFilterOperatorContainment { def unary_! = $nin; }
- case object $nin extends MongoFilterOperatorContainment { def unary_! = $in; }
-
- case object $mod extends MongoFilterOperator { def unary_! : MongoFilterOperator = sys.error("The $mod operator does not have a negation"); }
- case object $all extends MongoFilterOperator { def unary_! : MongoFilterOperator = sys.error("The $all operator does not have a negation"); }
- case object $size extends MongoFilterOperator { def unary_! : MongoFilterOperator = sys.error("The $size operator does not have a negation"); }
- case object $exists extends MongoFilterOperator { def unary_! : MongoFilterOperator = sys.error("The $exists operator does not have a negation"); }
- case object $type extends MongoFilterOperator { def unary_! : MongoFilterOperator = sys.error("The $type operator does not have a negation"); }
- case object $or extends MongoFilterOperator { def unary_! : MongoFilterOperator = sys.error("The $or operator does not have a negation"); }
- case object $and extends MongoFilterOperator { def unary_! : MongoFilterOperator = sys.error("The $and operator does not have a negation"); }
- case object $each extends MongoFilterOperator { def unary_! : MongoFilterOperator = sys.error("The $each operator does not have a negation"); }
-
- sealed trait MongoFilterOperatorGeo extends MongoFilterOperator
- case object $near extends MongoFilterOperatorGeo { def unary_! : MongoFilterOperator = sys.error("The $near operator does not have a negation"); }
- case object $nearSphere extends MongoFilterOperatorGeo { def unary_! : MongoFilterOperator = sys.error("The $nearSphere operator does not have a negation"); }
- case object $within extends MongoFilterOperatorGeo { def unary_! : MongoFilterOperator = sys.error("The $within operator does not have a negation"); }
- case object $where extends MongoFilterOperatorGeo { def unary_! : MongoFilterOperator = sys.error("The $where operator does not have a negation"); }
-}
-
import MongoFilterOperators._
+import dsl._
+
+import scalaz._
sealed trait MongoFilter { self =>
def filter: JValue
@@ -57,18 +15,44 @@ sealed trait MongoFilter { self =>
def & (collection: MongoCollection) = MongoFilterCollection(self, collection)
- def && (that: MongoFilter) = MongoFilterAndMonoid.append(self, that)
+ def && (that: MongoFilter) = MongoFilter.conjunction.append(self, that)
def | (that: MongoFilter) = ||(that)
- def || (that: MongoFilter) = MongoFilterOrMonoid.append(self, that)
+ def || (that: MongoFilter) = MongoFilter.disjunction.append(self, that)
}
-object MongoFilter extends MongoFilterImplicits {
+object MongoFilter {
def apply(lhs: JPath, operator: MongoFilterOperator, rhs: MongoPrimitive): MongoFilter = rhs match {
case opt @ MongoPrimitiveOption(value) => value.map(MongoFieldFilter(lhs, operator, _)).getOrElse(MongoFilterAll)
case _ => MongoFieldFilter(lhs, operator, rhs)
}
+
+ object conjunction extends Monoid[MongoFilter]{
+ val zero = MongoFilterAll
+
+ def append(f1: MongoFilter, f2: => MongoFilter): MongoAndFilter = (f1, f2) match{
+ case (x: MongoAndFilter, y: MongoAndFilter) => MongoAndFilter(x.queries ++ y.queries)
+ case (_, y: MongoAndFilter) => MongoAndFilter(f1 +: y.queries)
+ case (x: MongoAndFilter, _) => MongoAndFilter(x.queries :+ f2)
+ case (MongoFilterAll, _) => MongoAndFilter(List(f2))
+ case (_, MongoFilterAll) => MongoAndFilter(List(f1))
+ case _ => MongoAndFilter(List(f1, f2))
+ }
+ }
+
+ object disjunction extends Monoid[MongoFilter]{
+ val zero = MongoFilterAll
+
+ def append(f1: MongoFilter, f2: => MongoFilter): MongoFilter = (f1, f2) match{
+ case (x: MongoOrFilter, y: MongoOrFilter) => MongoOrFilter(x.queries ++ y.queries)
+ case (_, y: MongoOrFilter) => MongoOrFilter(f1 +: y.queries)
+ case (x: MongoOrFilter, _) => MongoOrFilter(x.queries :+ f2)
+ case (MongoFilterAll, _) => f2
+ case (_, MongoFilterAll) => f1
+ case _ => MongoOrFilter(List(f1, f2))
+ }
+ }
}
case class MongoFilterCollection(filter: MongoFilter, collection: MongoCollection){ self =>
@@ -167,101 +151,6 @@ sealed case class MongoElementsMatchFilter(lhs: JPath, elementsQuery: MongoAndFi
}
}
-sealed trait MongoPrimitive {
- def toJValue: JValue
-}
-
-case class MongoPrimitiveOption(value: Option[MongoPrimitive]) extends MongoPrimitive {
- def toJValue = value.map(_.toJValue).getOrElse(JUndefined)
-}
-case class MongoPrimitiveString(value: String) extends MongoPrimitive {
- def toJValue = JString(value)
-}
-case class MongoPrimitiveLong(value: Long) extends MongoPrimitive {
- def toJValue = JNum(value)
-}
-case class MongoPrimitiveInt(value: Int) extends MongoPrimitive {
- def toJValue = JNum(value)
-}
-case class MongoPrimitiveBigInt(value: BigInt) extends MongoPrimitive {
- def toJValue = JNum(BigDecimal(value))
-}
-case class MongoPrimitiveDouble(value: Double) extends MongoPrimitive {
- def toJValue = JNum(value)
-}
-case class MongoPrimitiveBoolean(value: Boolean) extends MongoPrimitive {
- def toJValue = JBool(value)
-}
-case class MongoPrimitiveArray(value: List[MongoPrimitive]) extends MongoPrimitive {
- def toJValue = JArray(value.map(_.toJValue))
-}
-case class MongoPrimitiveJObject(value: JObject) extends MongoPrimitive {
- def toJValue = value
-}
-case object MongoPrimitiveNull extends MongoPrimitive {
- def toJValue = JNull
-}
-
-sealed class MongoPrimitiveWitness[T](val typeNumber: Int)
-
-trait MongoFilterImplicits {
- import MongoFilterOperators._
-
- implicit def mongoOperatorToSymbolString(op: MongoFilterOperator): String = op.symbol
-
- implicit def stringToMongoFilterBuilder(string: String): MongoFilterBuilder = MongoFilterBuilder(JPath(string))
-
- implicit def jpathToMongoFilterBuilder(jpath: JPath): MongoFilterBuilder = MongoFilterBuilder(jpath)
-
- implicit def optionToMongoFilter(opt: Option[MongoFilter]): MongoFilter = opt.getOrElse(MongoFilterAll)
-
- implicit def jvalueToMongoPrimitive(value: JValue): MongoPrimitive = value match {
- case x: JString => MongoPrimitiveString(x.value)
- case x: JNum => MongoPrimitiveDouble(x.toDouble)
- case x: JBool => MongoPrimitiveBoolean(x.value)
- case x: JObject => MongoPrimitiveJObject(x)
- case x: JArray => MongoPrimitiveArray(x.elements.map(jvalueToMongoPrimitive))
- case JNull | JUndefined => MongoPrimitiveNull
- }
-
- implicit def optionToMongoPrimitive[T <% MongoPrimitive](value: Option[T]) = MongoPrimitiveOption(value.map(a => a : MongoPrimitive))
- implicit def stringToMongoPrimitive(value: String) = MongoPrimitiveString(value)
- implicit def longToMongoPrimitive(value: Long) = MongoPrimitiveLong(value)
- implicit def intToMongoPrimitive(value: Int) = MongoPrimitiveInt(value)
- implicit def bigIntToMongoPrimitive(value: BigInt) = MongoPrimitiveBigInt(value)
- implicit def doubleToMongoPrimitive(value: Double) = MongoPrimitiveDouble(value)
- implicit def booleanToMongoPrimitive(value: Boolean) = MongoPrimitiveBoolean(value)
- implicit def arrayToMongoPrimitive(value: List[MongoPrimitive]) = MongoPrimitiveArray(value)
-
- /*
- Double 1
- String 2
- Object 3
- Array 4
- Binary data 5
- Object id 7
- Boolean 8
- Date 9
- Null 10
- Regular expression 11
- JavaScript code 13
- Symbol 14
- JavaScript code with scope 15
- 32-bit integer 16
- Timestamp 17
- 64-bit integer 18
- Min key 255
- Max key 127
- */
- implicit val MongoPrimitiveJStringWitness = new MongoPrimitiveWitness[JString](2)
- implicit val MongoPrimitiveJObjectWitness = new MongoPrimitiveWitness[JObject](3)
- implicit val MongoPrimitiveJArrayWitness = new MongoPrimitiveWitness[JArray](4)
- implicit val MongoPrimitiveJBoolWitness = new MongoPrimitiveWitness[JBool](8)
- implicit val MongoPrimitiveJNullWitness = new MongoPrimitiveWitness[JNull.type](10)
- implicit val MongoPrimitiveJNumWitness = new MongoPrimitiveWitness[JNum](18)
-}
-object MongoFilterImplicits extends MongoFilterImplicits
-
sealed trait WithinShape
case class Box(lowerLeft: (Double, Double), upperRight: (Double, Double)) extends WithinShape
case class Circle(center: (Double, Double), radius: Double) extends WithinShape
@@ -289,7 +178,6 @@ case class CenterSphere(center: (Double, Double), radiusInRadians: Double) exten
* <p>
*/
case class MongoFilterBuilder(jpath: JPath) {
- import MongoFilterImplicits._
def === [T](value: MongoPrimitive) = MongoFieldFilter(jpath, $eq, value)
def !== [T](value: MongoPrimitive) = MongoFieldFilter(jpath, $ne, value)
@@ -337,11 +225,11 @@ case class MongoFilterBuilder(jpath: JPath) {
}
}
-object evaluation{
- def apply(javascriptExpression: String) = MongoFieldFilter(JPath.Identity, $where, javascriptExpression)
+object evaluation {
+ def apply(javascriptExpression: String) = MongoFieldFilter(JPath.Identity, $where, MongoPrimitiveString(javascriptExpression))
}
-private[mongo] object JPathExtension{
+private[mongo] object JPathExtension {
def toMongoField(path: JPath) = {
val mongoPath = JPath(path.nodes.map{ node =>
node match{
@@ -0,0 +1,49 @@
+package blueeyes.persistence.mongo
+
+import blueeyes.json._
+import blueeyes.util.ProductPrefixUnmangler
+import MongoFilterOperators._
+
+import scalaz._
+
+object MongoFilterOperators {
+ sealed trait MongoFilterOperator extends Product with ProductPrefixUnmangler {
+ def symbol: String = unmangledName
+
+ def unary_! : MongoFilterOperator
+
+ override def toString = symbol
+ }
+
+ sealed trait MongoFilterOperatorBound extends MongoFilterOperator
+ case object $gt extends MongoFilterOperatorBound { def unary_! = $lte; }
+ case object $gte extends MongoFilterOperatorBound { def unary_! = $lt; }
+ case object $lt extends MongoFilterOperatorBound { def unary_! = $gte; }
+ case object $lte extends MongoFilterOperatorBound { def unary_! = $gt; }
+
+ sealed trait MongoFilterOperatorEquality extends MongoFilterOperator
+ case object $eq extends MongoFilterOperatorEquality { def unary_! = $ne; } // This is a virtual operator, it's not real!!!!
+ case object $ne extends MongoFilterOperatorEquality { def unary_! = $eq; }
+ case object $regex extends MongoFilterOperatorEquality { def unary_! : MongoFilterOperator = sys.error("The $regex operator does not have a negation"); }
+
+ sealed trait MongoFilterOperatorContainment extends MongoFilterOperator
+ case object $in extends MongoFilterOperatorContainment { def unary_! = $nin; }
+ case object $nin extends MongoFilterOperatorContainment { def unary_! = $in; }
+
+ case object $mod extends MongoFilterOperator { def unary_! : MongoFilterOperator = sys.error("The $mod operator does not have a negation"); }
+ case object $all extends MongoFilterOperator { def unary_! : MongoFilterOperator = sys.error("The $all operator does not have a negation"); }
+ case object $size extends MongoFilterOperator { def unary_! : MongoFilterOperator = sys.error("The $size operator does not have a negation"); }
+ case object $exists extends MongoFilterOperator { def unary_! : MongoFilterOperator = sys.error("The $exists operator does not have a negation"); }
+ case object $type extends MongoFilterOperator { def unary_! : MongoFilterOperator = sys.error("The $type operator does not have a negation"); }
+ case object $or extends MongoFilterOperator { def unary_! : MongoFilterOperator = sys.error("The $or operator does not have a negation"); }
+ case object $and extends MongoFilterOperator { def unary_! : MongoFilterOperator = sys.error("The $and operator does not have a negation"); }
+ case object $each extends MongoFilterOperator { def unary_! : MongoFilterOperator = sys.error("The $each operator does not have a negation"); }
+
+ sealed trait MongoFilterOperatorGeo extends MongoFilterOperator
+ case object $near extends MongoFilterOperatorGeo { def unary_! : MongoFilterOperator = sys.error("The $near operator does not have a negation"); }
+ case object $nearSphere extends MongoFilterOperatorGeo { def unary_! : MongoFilterOperator = sys.error("The $nearSphere operator does not have a negation"); }
+ case object $within extends MongoFilterOperatorGeo { def unary_! : MongoFilterOperator = sys.error("The $within operator does not have a negation"); }
+ case object $where extends MongoFilterOperatorGeo { def unary_! : MongoFilterOperator = sys.error("The $where operator does not have a negation"); }
+}
+
+// vim: set ts=4 sw=4 et:
@@ -1,24 +0,0 @@
-package blueeyes.persistence.mongo
-
-import blueeyes.json.JObject
-import blueeyes.json.{JPathImplicits, JPath}
-
-trait MongoImplicits extends JPathImplicits with MongoFilterImplicits with MongoQueryBuilder{
- implicit def stringToMongoCollection(string: String): MongoCollection = MongoCollectionReference(string)
-
- implicit def jpathToMongoSort(jpath: JPath): MongoSort = MongoSort(jpath, MongoSortOrderAscending)
-
- implicit def stringToMongoSort(string: String): MongoSort = MongoSort(JPath(string), MongoSortOrderAscending)
-
- implicit def stringToMongoUpdateBuilder(string: String): MongoUpdateBuilder = MongoUpdateBuilder(JPath(string))
-
- implicit def jpathToMongoUpdateBuilder(jpath: JPath): MongoUpdateBuilder = MongoUpdateBuilder(jpath)
-
- implicit def jvalueToMongoUpdateObject(value: JObject): MongoUpdateObject = MongoUpdateObject(value)
-
- implicit def stringToHint(indexName: String) = NamedHint(indexName)
-
- implicit def keysToHint(keys: List[JPath]) = KeyedHint(keys)
-}
-
-object MongoImplicits extends MongoImplicits
@@ -9,17 +9,11 @@ private[mongo] object Changes {
*/
def flatten: Seq[Change1]
- /**
- * Coalesces this change with that change, to produce a new change that
- * achieves the effect of both changes applied sequentially.
- */
- def *>(that: Change) = Changes.compose(flatten, that.flatten)
-
/**
* Coalesces this change with the list of changes, to produce a new
* change that achieves the effect of both changes applied sequentially.
*/
- def *>(list: Seq[Change]) = Changes.compose(flatten, Changelist(list).flatten)
+ def *>(that: Change*) = Changes.compose(flatten, Changelist(that).flatten)
}
trait Change1 extends Change {
@@ -5,8 +5,10 @@ import akka.dispatch.Future
import akka.dispatch.MessageDispatcher
import akka.util.Timeout
import blueeyes.json._
+
import scalaz._
-import Scalaz._
+import scalaz.std.map._
+import scalaz.syntax.semigroup._
/**
* Simple abstraction for representing a collections of MongoDB patches.
@@ -33,7 +35,7 @@ case class MongoPatches(patches: Map[MongoFilter, MongoUpdate]) {
*/
def commit(database: Database, collection: MongoCollection)(implicit messageDispatcher: MessageDispatcher, queryTimeout: Timeout): Future[Unit] = {
val futures = patches.toList.map {
- case (filter, update) => database(upsert(collection).set(update).where(filter))
+ case (filter, update) => database(MongoQueryBuilder.upsert(collection).set(update).where(filter))
}
Future.sequence(futures).map(_ => ())
Oops, something went wrong.

0 comments on commit 1e9b896

Please sign in to comment.