diff --git a/.travis.yml b/.travis.yml index cf607e9fe9..f60fb8f0f6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,5 @@ language: scala -script: sbt -Dslick.testkit.dbprops=test-dbs/databases.travis.properties test doctest:test +script: sbt -jvm-opts jvmopts.travis -Dslick.testkit.dbprops=test-dbs/databases.travis.properties +testAll jdk: - openjdk6 notifications: diff --git a/jvmopts.travis b/jvmopts.travis new file mode 100644 index 0000000000..5f98470956 --- /dev/null +++ b/jvmopts.travis @@ -0,0 +1,7 @@ +-Xmx3076M +-XX:MaxPermSize=1024M +-Xss2M +-XX:+DoEscapeAnalysis +-XX:+UseParallelGC +-XX:+UseCompressedOops +-XX:ReservedCodeCacheSize=128M diff --git a/project/Build.scala b/project/Build.scala index 568c0dd3c1..aeab63a266 100644 --- a/project/Build.scala +++ b/project/Build.scala @@ -15,9 +15,9 @@ object SlickBuild extends Build { val repoKind = SettingKey[String]("repo-kind", "Maven repository kind (\"snapshots\" or \"releases\")") val publishedScalaSettings = Seq( - scalaVersion := "2.10.3", + scalaVersion := "2.10.4", + crossScalaVersions := Seq(scalaVersion.value, "2.11.0-RC3"), //scalaBinaryVersion <<= scalaVersion, - //crossScalaVersions ++= "2.10.0-M4" :: Nil, libraryDependencies <+= scalaVersion("org.scala-lang" % "scala-compiler" % _ % "optional") ) @@ -104,13 +104,23 @@ object SlickBuild extends Build { ) ++ scalaSettings + /* A command that runs 'testkit/test:test' and 'testkit/doctest:test' sequentially */ + def testAll = Command.command("testAll") { state => + Project.runTask(test in (slickTestkitProject, Test), state) flatMap { + case (s, Inc(_)) => Some(s) + case (s, _) => + Project.runTask(test in (slickTestkitProject, DocTest), state).map(_._1) + } getOrElse state + } + /* Project Definitions */ lazy val aRootProject = Project(id = "root", base = file("."), settings = Project.defaultSettings ++ sharedSettings ++ extTarget("root", Some("target/root")) ++ Seq( sourceDirectory := file("target/root-src"), publishArtifact := false, test := (), // suppress test status output - testOnly := () + testOnly := (), + commands += testAll )).aggregate(slickProject, slickTestkitProject) lazy val slickProject: Project = Project(id = "slick", base = file("."), settings = Project.defaultSettings ++ inConfig(config("macro"))(Defaults.configSettings) ++ sharedSettings ++ fmppSettings ++ site.settings ++ site.sphinxSupport() ++ mimaDefaultSettings ++ extTarget("slick", None) ++ Seq( diff --git a/slick-testkit/src/main/scala/com/typesafe/slick/testkit/tests/JdbcMapperTest.scala b/slick-testkit/src/main/scala/com/typesafe/slick/testkit/tests/JdbcMapperTest.scala index b084642d7e..77d84db81f 100644 --- a/slick-testkit/src/main/scala/com/typesafe/slick/testkit/tests/JdbcMapperTest.scala +++ b/slick-testkit/src/main/scala/com/typesafe/slick/testkit/tests/JdbcMapperTest.scala @@ -194,7 +194,7 @@ class JdbcMapperTest extends TestkitTest[JdbcTestDB] { // A Shape that maps Pair to a ProductNode final class PairShape[Level <: ShapeLevel, M <: Pair[_,_], U <: Pair[_,_] : ClassTag, P <: Pair[_,_]](val shapes: Seq[Shape[_, _, _, _]]) extends MappedScalaProductShape[Level, Pair[_,_], M, U, P] { def buildValue(elems: IndexedSeq[Any]) = Pair(elems(0), elems(1)) - def copy(shapes: Seq[Shape[_, _, _, _]]) = new PairShape(shapes) + def copy(shapes: Seq[Shape[_ <: ShapeLevel, _, _, _]]) = new PairShape(shapes) } implicit def pairShape[Level <: ShapeLevel, M1, M2, U1, U2, P1, P2](implicit s1: Shape[_ <: Level, M1, U1, P1], s2: Shape[_ <: Level, M2, U2, P2]) = new PairShape[Level, Pair[M1, M2], Pair[U1, U2], Pair[P1, P2]](Seq(s1, s2)) diff --git a/slick-testkit/src/main/scala/com/typesafe/slick/testkit/tests/RelationalMiscTest.scala b/slick-testkit/src/main/scala/com/typesafe/slick/testkit/tests/RelationalMiscTest.scala index 7796ba7187..fe3540e23a 100644 --- a/slick-testkit/src/main/scala/com/typesafe/slick/testkit/tests/RelationalMiscTest.scala +++ b/slick-testkit/src/main/scala/com/typesafe/slick/testkit/tests/RelationalMiscTest.scala @@ -71,7 +71,7 @@ class RelationalMiscTest extends TestkitTest[RelationalTestDB] { implicit class TupledQueryExtensionMethods[E1, E2, U1, U2, C[_]](q: Query[(E1, E2), (U1, U2), C]) { def sortedValues(implicit ordered: (E1 => Ordered), - shape: Shape[ShapeLevel.Flat, E2, U2, E2]): Query[E2, U2, C] = + shape: Shape[FlatShapeLevel, E2, U2, E2]): Query[E2, U2, C] = q.sortBy(_._1).map(_._2) } diff --git a/slick-testkit/src/test/scala/scala/slick/test/compile/NestedShapesTest.scala b/slick-testkit/src/test/scala/scala/slick/test/compile/NestedShapesTest.scala index 10146c05a6..d5db3b0789 100644 --- a/slick-testkit/src/test/scala/scala/slick/test/compile/NestedShapesTest.scala +++ b/slick-testkit/src/test/scala/scala/slick/test/compile/NestedShapesTest.scala @@ -7,67 +7,67 @@ import scala.slick.lifted.{Shape, ShapeLevel} class NestedShapesTest { def legal = { // Flat and Nested alike, only Mixed specified - implicitly[Shape[ShapeLevel.Flat, Int, _, _]] - implicitly[Shape[ShapeLevel.Flat, (Int, String), _, _]] - implicitly[Shape[ShapeLevel.Flat, (Column[Int], Int), _, _]] - implicitly[Shape[ShapeLevel.Flat, (Column[Int], (Int, Column[String])), _, _]] - implicitly[Shape[ShapeLevel.Nested, Int, _, _]] - implicitly[Shape[ShapeLevel.Nested, (Int, String), _, _]] - implicitly[Shape[ShapeLevel.Nested, (Column[Int], Int), _, _]] - implicitly[Shape[ShapeLevel.Nested, (Column[Int], (Int, Column[String])), _, _]] + implicitly[Shape[FlatShapeLevel, Int, _, _]] + implicitly[Shape[FlatShapeLevel, (Int, String), _, _]] + implicitly[Shape[FlatShapeLevel, (Column[Int], Int), _, _]] + implicitly[Shape[FlatShapeLevel, (Column[Int], (Int, Column[String])), _, _]] + implicitly[Shape[NestedShapeLevel, Int, _, _]] + implicitly[Shape[NestedShapeLevel, (Int, String), _, _]] + implicitly[Shape[NestedShapeLevel, (Column[Int], Int), _, _]] + implicitly[Shape[NestedShapeLevel, (Column[Int], (Int, Column[String])), _, _]] // Flat and Nested alike, fully specified - implicitly[Shape[ShapeLevel.Flat, Int, Int, Column[Int]]] - implicitly[Shape[ShapeLevel.Flat, (Int, String), (Int, String), (Column[Int], Column[String])]] - implicitly[Shape[ShapeLevel.Flat, (Column[Int], Int), (Int, Int), (Column[Int], Column[Int])]] - implicitly[Shape[ShapeLevel.Flat, (Column[Int], (Int, Column[String])), (Int, (Int, String)), (Column[Int], (Column[Int], Column[String]))]] - implicitly[Shape[ShapeLevel.Nested, Int, Int, Column[Int]]] - implicitly[Shape[ShapeLevel.Nested, (Int, String), (Int, String), (Column[Int], Column[String])]] - implicitly[Shape[ShapeLevel.Nested, (Column[Int], Int), (Int, Int), (Column[Int], Column[Int])]] - implicitly[Shape[ShapeLevel.Nested, (Column[Int], (Int, Column[String])), (Int, (Int, String)), (Column[Int], (Column[Int], Column[String]))]] + implicitly[Shape[FlatShapeLevel, Int, Int, Column[Int]]] + implicitly[Shape[FlatShapeLevel, (Int, String), (Int, String), (Column[Int], Column[String])]] + implicitly[Shape[FlatShapeLevel, (Column[Int], Int), (Int, Int), (Column[Int], Column[Int])]] + implicitly[Shape[FlatShapeLevel, (Column[Int], (Int, Column[String])), (Int, (Int, String)), (Column[Int], (Column[Int], Column[String]))]] + implicitly[Shape[NestedShapeLevel, Int, Int, Column[Int]]] + implicitly[Shape[NestedShapeLevel, (Int, String), (Int, String), (Column[Int], Column[String])]] + implicitly[Shape[NestedShapeLevel, (Column[Int], Int), (Int, Int), (Column[Int], Column[Int])]] + implicitly[Shape[NestedShapeLevel, (Column[Int], (Int, Column[String])), (Int, (Int, String)), (Column[Int], (Column[Int], Column[String]))]] // Only Nested, only Mixed specified - implicitly[Shape[ShapeLevel.Nested, Query[Column[Int], Int, Seq], _, _]] // 1 - implicitly[Shape[ShapeLevel.Nested, Query[(Column[Int], Column[String]), (Int, String), Seq], _, _]] // 2 - implicitly[Shape[ShapeLevel.Nested, (Column[Int], Query[(Column[Int], Column[String]), (Int, String), Seq]), _, _]] // 3 - implicitly[Shape[ShapeLevel.Nested, (Int, Query[(Column[Int], Column[String]), (Int, String), Seq]), _, _]] // 4 + implicitly[Shape[NestedShapeLevel, Query[Column[Int], Int, Seq], _, _]] // 1 + implicitly[Shape[NestedShapeLevel, Query[(Column[Int], Column[String]), (Int, String), Seq], _, _]] // 2 + implicitly[Shape[NestedShapeLevel, (Column[Int], Query[(Column[Int], Column[String]), (Int, String), Seq]), _, _]] // 3 + implicitly[Shape[NestedShapeLevel, (Int, Query[(Column[Int], Column[String]), (Int, String), Seq]), _, _]] // 4 // Only Nested, fully specified - implicitly[Shape[ShapeLevel.Nested, Query[Column[Int], Int, Seq], Seq[Int], Query[Column[Int], Int, Seq]]] // 5 - implicitly[Shape[ShapeLevel.Nested, Query[(Column[Int], Column[String]), (Int, String), Seq], Seq[(Int, String)], Query[(Column[Int], Column[String]), (Int, String), Seq]]] // 6 - implicitly[Shape[ShapeLevel.Nested, (Column[Int], Query[(Column[Int], Column[String]), (Int, String), Seq]), (Int, Seq[(Int, String)]), (Column[Int], Query[(Column[Int], Column[String]), (Int, String), Seq])]] // 7 - implicitly[Shape[ShapeLevel.Nested, (Int, Query[(Column[Int], Column[String]), (Int, String), Seq]), (Int, Seq[(Int, String)]), (Column[Int], Query[(Column[Int], Column[String]), (Int, String), Seq])]] // 8 + implicitly[Shape[NestedShapeLevel, Query[Column[Int], Int, Seq], Seq[Int], Query[Column[Int], Int, Seq]]] // 5 + implicitly[Shape[NestedShapeLevel, Query[(Column[Int], Column[String]), (Int, String), Seq], Seq[(Int, String)], Query[(Column[Int], Column[String]), (Int, String), Seq]]] // 6 + implicitly[Shape[NestedShapeLevel, (Column[Int], Query[(Column[Int], Column[String]), (Int, String), Seq]), (Int, Seq[(Int, String)]), (Column[Int], Query[(Column[Int], Column[String]), (Int, String), Seq])]] // 7 + implicitly[Shape[NestedShapeLevel, (Int, Query[(Column[Int], Column[String]), (Int, String), Seq]), (Int, Seq[(Int, String)]), (Column[Int], Query[(Column[Int], Column[String]), (Int, String), Seq])]] // 8 } def illegal1 = ShouldNotTypecheck(""" - implicitly[Shape[ShapeLevel.Flat, Query[Column[Int], Int, Seq], _, _]] // 1 + implicitly[Shape[FlatShapeLevel, Query[Column[Int], Int, Seq], _, _]] // 1 """, "No matching Shape.*") def illegal2 = ShouldNotTypecheck(""" - implicitly[Shape[ShapeLevel.Flat, Query[(Column[Int], Column[String]), (Int, String), Seq], _, _]] // 2 + implicitly[Shape[FlatShapeLevel, Query[(Column[Int], Column[String]), (Int, String), Seq], _, _]] // 2 """, "No matching Shape.*") def illegal3 = ShouldNotTypecheck(""" - implicitly[Shape[ShapeLevel.Flat, (Column[Int], Query[(Column[Int], Column[String]), (Int, String), Seq]), _, _]] // 3 + implicitly[Shape[FlatShapeLevel, (Column[Int], Query[(Column[Int], Column[String]), (Int, String), Seq]), _, _]] // 3 """, "No matching Shape.*") def illegal4 = ShouldNotTypecheck(""" - implicitly[Shape[ShapeLevel.Flat, (Int, Query[(Column[Int], Column[String]), (Int, String), Seq]), _, _]] // 4 + implicitly[Shape[FlatShapeLevel, (Int, Query[(Column[Int], Column[String]), (Int, String), Seq]), _, _]] // 4 """, "No matching Shape.*") def illegal5 = ShouldNotTypecheck(""" - implicitly[Shape[ShapeLevel.Flat, Query[Column[Int], Int, Seq], Seq[Int], Query[Column[Int], Int, Seq]]] // 5 + implicitly[Shape[FlatShapeLevel, Query[Column[Int], Int, Seq], Seq[Int], Query[Column[Int], Int, Seq]]] // 5 """, "No matching Shape.*") def illegal6 = ShouldNotTypecheck(""" - implicitly[Shape[ShapeLevel.Flat, Query[(Column[Int], Column[String]), (Int, String), Seq], Seq[(Int, String)], Query[(Column[Int], Column[String]), (Int, String), Seq]]] // 6 + implicitly[Shape[FlatShapeLevel, Query[(Column[Int], Column[String]), (Int, String), Seq], Seq[(Int, String)], Query[(Column[Int], Column[String]), (Int, String), Seq]]] // 6 """, "No matching Shape.*") def illegal7 = ShouldNotTypecheck(""" - implicitly[Shape[ShapeLevel.Flat, (Column[Int], Query[(Column[Int], Column[String]), (Int, String), Seq]), (Int, Seq[(Int, String)]), (Column[Int], Query[(Column[Int], Column[String]), (Int, String), Seq])]] // 7 + implicitly[Shape[FlatShapeLevel, (Column[Int], Query[(Column[Int], Column[String]), (Int, String), Seq]), (Int, Seq[(Int, String)]), (Column[Int], Query[(Column[Int], Column[String]), (Int, String), Seq])]] // 7 """, "No matching Shape.*") def illegal8 = ShouldNotTypecheck(""" - implicitly[Shape[ShapeLevel.Flat, (Int, Query[(Column[Int], Column[String]), (Int, String), Seq]), (Int, Seq[(Int, String)]), (Column[Int], Query[(Column[Int], Column[String]), (Int, String), Seq])]] // 8 + implicitly[Shape[FlatShapeLevel, (Int, Query[(Column[Int], Column[String]), (Int, String), Seq]), (Int, Seq[(Int, String)]), (Column[Int], Query[(Column[Int], Column[String]), (Int, String), Seq])]] // 8 """, "No matching Shape.*") } diff --git a/src/macro/scala/scala/slick/util/MacroSupportInterpolationImpl.scala b/src/macro/scala/scala/slick/util/MacroSupportInterpolationImpl.scala index e4a6b4818c..fff837595c 100644 --- a/src/macro/scala/scala/slick/util/MacroSupportInterpolationImpl.scala +++ b/src/macro/scala/scala/slick/util/MacroSupportInterpolationImpl.scala @@ -61,7 +61,7 @@ object MacroSupportInterpolationImpl { val s = pit.next() val ae @ Expr(a) = ait.next() val len = s.length - val marker = if(len == 0) '\0' else s.charAt(len-1) + val marker = if(len == 0) '\u0000' else s.charAt(len-1) marker match { case '`' => exprs ++= appendString(s.substring(0, len-1)) diff --git a/src/main/scala/scala/slick/collection/heterogenous/HList.scala b/src/main/scala/scala/slick/collection/heterogenous/HList.scala index 04bbb5f81f..4660699d58 100644 --- a/src/main/scala/scala/slick/collection/heterogenous/HList.scala +++ b/src/main/scala/scala/slick/collection/heterogenous/HList.scala @@ -129,7 +129,7 @@ final object HList { final class HListShape[Level <: ShapeLevel, M <: HList, U <: HList : ClassTag, P <: HList](val shapes: Seq[Shape[_, _, _, _]]) extends MappedScalaProductShape[Level, HList, M, U, P] { def buildValue(elems: IndexedSeq[Any]) = elems.foldRight(HNil: HList)(_ :: _) - def copy(shapes: Seq[Shape[_, _, _, _]]) = new HListShape(shapes) + def copy(shapes: Seq[Shape[_ <: ShapeLevel, _, _, _]]) = new HListShape(shapes) } implicit def hnilShape[Level <: ShapeLevel] = new HListShape[Level, HNil.type, HNil.type, HNil.type](Nil) implicit def hconsShape[Level <: ShapeLevel, L1 <: Level, L2 <: Level, M1, M2 <: HList, U1, U2 <: HList, P1, P2 <: HList](implicit s1: Shape[L1, M1, U1, P1], s2: HListShape[L2, M2, U2, P2]) = diff --git a/src/main/scala/scala/slick/direct/SlickBackend.scala b/src/main/scala/scala/slick/direct/SlickBackend.scala index 76a7d78750..d1d97582d3 100644 --- a/src/main/scala/scala/slick/direct/SlickBackend.scala +++ b/src/main/scala/scala/slick/direct/SlickBackend.scala @@ -11,6 +11,11 @@ import scala.reflect.ClassTag import scala.reflect.runtime.universe.TypeRef import scala.annotation.StaticAnnotation import scala.reflect.runtime.universe._ + +// TODO 2.11 Remove this after dropping 2.10.x support +// http://docs.scala-lang.org/overviews/macros/changelog211.html +private object HasCompat { val compat = ??? }; import HasCompat._ + import scala.reflect.runtime.{currentMirror=>cm} /** maps a Scala method to a Slick FunctionSymbol */ @@ -77,14 +82,15 @@ object CustomNodes{ import CustomNodes._ class SlickBackend( val driver: JdbcDriver, mapper:Mapper ) extends QueryableBackend{ + import scala.reflect.runtime.universe.{Scope => _, _} + import compat._ type Session = JdbcDriver#Backend#Session - import slick.ast.ScalaBaseType val columnTypes = { Map( // FIXME use symbols instead of strings for type names here - typeOf[Int].typeSymbol -> ScalaBaseType.intType - ,typeOf[Double].typeSymbol -> ScalaBaseType.doubleType - ,typeOf[String].typeSymbol -> ScalaBaseType.stringType - ,typeOf[Boolean].typeSymbol -> ScalaBaseType.booleanType + typeOf[Int].typeSymbol -> sq.ScalaBaseType.intType + ,typeOf[Double].typeSymbol -> sq.ScalaBaseType.doubleType + ,typeOf[String].typeSymbol -> sq.ScalaBaseType.stringType + ,typeOf[Boolean].typeSymbol -> sq.ScalaBaseType.booleanType ) } /** generates a map from Scala symbols to Slick FunctionSymbols from description in OperatorMapping */ @@ -366,8 +372,7 @@ class SlickBackend( val driver: JdbcDriver, mapper:Mapper ) extends QueryableBac op, components ) - if definitions - .TupleClass + if (2 to 22).map(definitions.TupleClass) .filter(_ != NoSymbol) .map( _.companionSymbol.typeSignature.member( newTermName("apply") ) ) .contains( op.symbol ) diff --git a/src/main/scala/scala/slick/driver/JdbcExecutorComponent.scala b/src/main/scala/scala/slick/driver/JdbcExecutorComponent.scala index 322fe4a7f5..901f05e8dc 100644 --- a/src/main/scala/scala/slick/driver/JdbcExecutorComponent.scala +++ b/src/main/scala/scala/slick/driver/JdbcExecutorComponent.scala @@ -6,7 +6,7 @@ import scala.slick.ast.Util._ import scala.slick.ast.TypeUtil._ import scala.slick.util.SQLBuilder import scala.slick.profile.SqlExecutorComponent -import scala.slick.lifted.{Shape, ShapeLevel} +import scala.slick.lifted.{Shape, FlatShapeLevel} trait JdbcExecutorComponent extends SqlExecutorComponent { driver: JdbcDriver => @@ -33,7 +33,7 @@ trait JdbcExecutorComponent extends SqlExecutorComponent { driver: JdbcDriver => } class UnshapedQueryExecutorDef[M](value: M) extends super.UnshapedQueryExecutorDef[M](value) { - @inline final def selectStatement[U](implicit shape: Shape[_ <: ShapeLevel.Flat, M, U, _], session: Backend#Session): String = + @inline final def selectStatement[U](implicit shape: Shape[_ <: FlatShapeLevel, M, U, _], session: Backend#Session): String = executor[U].selectStatement } } diff --git a/src/main/scala/scala/slick/driver/JdbcInvokerComponent.scala b/src/main/scala/scala/slick/driver/JdbcInvokerComponent.scala index f8a817aad9..58bb2981a7 100644 --- a/src/main/scala/scala/slick/driver/JdbcInvokerComponent.scala +++ b/src/main/scala/scala/slick/driver/JdbcInvokerComponent.scala @@ -4,7 +4,7 @@ import scala.language.higherKinds import java.sql.{Statement, PreparedStatement} import scala.slick.SlickException import scala.slick.ast.{Insert, CompiledStatement, ResultSetMapping, Node} -import scala.slick.lifted.{ShapeLevel, Query, Shape} +import scala.slick.lifted.{FlatShapeLevel, Query, Shape} import scala.slick.jdbc._ import scala.slick.util.SQLBuilder import scala.slick.profile.BasicInvokerComponent @@ -87,7 +87,7 @@ trait JdbcInvokerComponent extends BasicInvokerComponent{ driver: JdbcDriver => lazy val insertStatement = insertResult.sql lazy val forceInsertStatement = insertForcedResult.sql def insertStatementFor[TT, C[_]](query: Query[TT, U, C]): String = builder.buildInsert(query).sql - def insertStatementFor[TT](c: TT)(implicit shape: Shape[_ <: ShapeLevel.Flat, TT, U, _]): String = insertStatementFor(Query(c)(shape)) + def insertStatementFor[TT](c: TT)(implicit shape: Shape[_ <: FlatShapeLevel, TT, U, _]): String = insertStatementFor(Query(c)(shape)) def useBatchUpdates(implicit session: Backend#Session) = session.capabilities.supportsBatchUpdates @@ -152,7 +152,7 @@ trait JdbcInvokerComponent extends BasicInvokerComponent{ driver: JdbcDriver => protected def retQuery(st: Statement, updateCount: Int): QueryInsertResult - def insertExpr[TT](c: TT)(implicit shape: Shape[_ <: ShapeLevel.Flat, TT, U, _], session: Backend#Session): QueryInsertResult = + def insertExpr[TT](c: TT)(implicit shape: Shape[_ <: FlatShapeLevel, TT, U, _], session: Backend#Session): QueryInsertResult = insert(Query(c)(shape))(session) def insert[TT, C[_]](query: Query[TT, U, C])(implicit session: Backend#Session): QueryInsertResult = { diff --git a/src/main/scala/scala/slick/lifted/AbstractTable.scala b/src/main/scala/scala/slick/lifted/AbstractTable.scala index 69280d2912..e8e304967a 100644 --- a/src/main/scala/scala/slick/lifted/AbstractTable.scala +++ b/src/main/scala/scala/slick/lifted/AbstractTable.scala @@ -66,7 +66,7 @@ abstract class AbstractTable[T](val tableTag: Tag, val schemaName: Option[String def foreignKey[P, PU, TT <: AbstractTable[_], U] (name: String, sourceColumns: P, targetTableQuery: TableQuery[TT]) (targetColumns: TT => P, onUpdate: model.ForeignKeyAction = model.ForeignKeyAction.NoAction, - onDelete: model.ForeignKeyAction = model.ForeignKeyAction.NoAction)(implicit unpack: Shape[_ <: ShapeLevel.Flat, TT, U, _], unpackp: Shape[_ <: ShapeLevel.Flat, P, PU, _]): ForeignKeyQuery[TT, U] = { + onDelete: model.ForeignKeyAction = model.ForeignKeyAction.NoAction)(implicit unpack: Shape[_ <: FlatShapeLevel, TT, U, _], unpackp: Shape[_ <: FlatShapeLevel, P, PU, _]): ForeignKeyQuery[TT, U] = { val targetTable: TT = targetTableQuery.shaped.value val q = targetTableQuery.asInstanceOf[Query[TT, U, Seq]] val generator = new AnonSymbol @@ -82,7 +82,7 @@ abstract class AbstractTable[T](val tableTag: Tag, val schemaName: Option[String * key column but this method allows you to define compound primary keys * or give them user-defined names (when defining the database schema * with Slick). */ - def primaryKey[T](name: String, sourceColumns: T)(implicit shape: Shape[_ <: ShapeLevel.Flat, T, _, _]): PrimaryKey = PrimaryKey(name, ExtraUtil.linearizeFieldRefs(shape.toNode(sourceColumns))) + def primaryKey[T](name: String, sourceColumns: T)(implicit shape: Shape[_ <: FlatShapeLevel, T, _, _]): PrimaryKey = PrimaryKey(name, ExtraUtil.linearizeFieldRefs(shape.toNode(sourceColumns))) def tableConstraints: Iterator[Constraint] = for { m <- getClass().getMethods.iterator @@ -97,7 +97,7 @@ abstract class AbstractTable[T](val tableTag: Tag, val schemaName: Option[String tableConstraints.collect{ case k: PrimaryKey => k }.toIndexedSeq /** Define an index or a unique constraint. */ - def index[T](name: String, on: T, unique: Boolean = false)(implicit shape: Shape[_ <: ShapeLevel.Flat, T, _, _]) = new Index(name, this, ExtraUtil.linearizeFieldRefs(shape.toNode(on)), unique) + def index[T](name: String, on: T, unique: Boolean = false)(implicit shape: Shape[_ <: FlatShapeLevel, T, _, _]) = new Index(name, this, ExtraUtil.linearizeFieldRefs(shape.toNode(on)), unique) def indexes: Iterable[Index] = (for { m <- getClass().getMethods.view diff --git a/src/main/scala/scala/slick/lifted/Aliases.scala b/src/main/scala/scala/slick/lifted/Aliases.scala index 21f805771f..8c09590292 100644 --- a/src/main/scala/scala/slick/lifted/Aliases.scala +++ b/src/main/scala/scala/slick/lifted/Aliases.scala @@ -37,7 +37,9 @@ trait Aliases { type MappedProductShape[Level <: ShapeLevel, C, M <: C, U <: C, P <: C] = lifted.MappedProductShape[Level, C, M, U, P] type MappedScalaProductShape[Level <: ShapeLevel, C <: Product, M <: C, U <: C, P <: C] = lifted.MappedScalaProductShape[Level, C, M, U, P] type ShapeLevel = lifted.ShapeLevel - val ShapeLevel = lifted.ShapeLevel + type NestedShapeLevel = lifted.NestedShapeLevel + type FlatShapeLevel = lifted.FlatShapeLevel + type ColumnsShapeLevel = lifted.ColumnsShapeLevel type Isomorphism[A, B] = lifted.Isomorphism[A, B] type MappedTo[T] = lifted.MappedTo[T] } diff --git a/src/main/scala/scala/slick/lifted/CompilableFunctions.fm b/src/main/scala/scala/slick/lifted/CompilableFunctions.fm index 9aa996f05a..a1fb51a2dd 100644 --- a/src/main/scala/scala/slick/lifted/CompilableFunctions.fm +++ b/src/main/scala/scala/slick/lifted/CompilableFunctions.fm @@ -4,9 +4,9 @@ import scala.slick.profile.BasicProfile trait CompilableFunctions extends CompilableLowPriority { <#list 2..22 as i> - implicit def function${i}IsCompilable[<#list 1..i as j>A${j}, B <: Rep[_], P, U](implicit ashape: Shape[ShapeLevel.Columns, (<#list 1..i as j>A${j}<#if i != j>, ), P, (<#list 1..i as j>A${j}<#if i != j>, )], pshape: Shape[ShapeLevel.Columns, P, P, _], bexe: Executable[B, U]): Compilable[(<#list 1..i as j>A${j}<#if i != j>, ) => B, CompiledFunction[(<#list 1..i as j>A${j}<#if i != j>, ) => B, (<#list 1..i as j>A${j}<#if i != j>, ), P, B, U]] = new Compilable[(<#list 1..i as j>A${j}<#if i != j>, ) => B, CompiledFunction[(<#list 1..i as j>A${j}<#if i != j>, ) => B, (<#list 1..i as j>A${j}<#if i != j>, ), P, B, U]] { + implicit def function${i}IsCompilable[<#list 1..i as j>A${j}, B <: Rep[_], P, U](implicit ashape: Shape[ColumnsShapeLevel, (<#list 1..i as j>A${j}<#if i != j>, ), P, (<#list 1..i as j>A${j}<#if i != j>, )], pshape: Shape[ColumnsShapeLevel, P, P, _], bexe: Executable[B, U]): Compilable[(<#list 1..i as j>A${j}<#if i != j>, ) => B, CompiledFunction[(<#list 1..i as j>A${j}<#if i != j>, ) => B, (<#list 1..i as j>A${j}<#if i != j>, ), P, B, U]] = new Compilable[(<#list 1..i as j>A${j}<#if i != j>, ) => B, CompiledFunction[(<#list 1..i as j>A${j}<#if i != j>, ) => B, (<#list 1..i as j>A${j}<#if i != j>, ), P, B, U]] { def compiled(raw: (<#list 1..i as j>A${j}<#if i != j>, ) => B, driver: BasicProfile) = - new CompiledFunction[(<#list 1..i as j>A${j}<#if i != j>, ) => B, (<#list 1..i as j>A${j}<#if i != j>, ), P, B, U](raw, ((f: (<#list 1..i as j>A${j}<#if i != j>, ) => B) => f.tupled), pshape.asInstanceOf[Shape[ShapeLevel.Columns, P, P, (<#list 1..i as j>A${j}<#if i != j>, )]], driver) + new CompiledFunction[(<#list 1..i as j>A${j}<#if i != j>, ) => B, (<#list 1..i as j>A${j}<#if i != j>, ), P, B, U](raw, ((f: (<#list 1..i as j>A${j}<#if i != j>, ) => B) => f.tupled), pshape.asInstanceOf[Shape[ColumnsShapeLevel, P, P, (<#list 1..i as j>A${j}<#if i != j>, )]], driver) } } diff --git a/src/main/scala/scala/slick/lifted/Compiled.scala b/src/main/scala/scala/slick/lifted/Compiled.scala index eb45941b3d..5a08c12244 100644 --- a/src/main/scala/scala/slick/lifted/Compiled.scala +++ b/src/main/scala/scala/slick/lifted/Compiled.scala @@ -47,7 +47,7 @@ trait CompilersMixin { this: Compiled[_] => lazy val compiledDelete = compile(driver.deleteCompiler) } -class CompiledFunction[F, PT, PU, R <: Rep[_], RU](val extract: F, val tuple: F => PT => R, val pshape: Shape[ShapeLevel.Columns, PU, PU, PT], val driver: BasicProfile) extends Compiled[F] with CompilersMixin { +class CompiledFunction[F, PT, PU, R <: Rep[_], RU](val extract: F, val tuple: F => PT => R, val pshape: Shape[ColumnsShapeLevel, PU, PU, PT], val driver: BasicProfile) extends Compiled[F] with CompilersMixin { /** Create an applied `Compiled` value for this compiled function. All applied * values share their compilation state with the original compiled function. */ def apply(p: PU) = new AppliedCompiledFunction[PU, R, RU](p, this, driver) @@ -90,7 +90,7 @@ trait Executable[T, TU] object Executable { @inline implicit def queryIsExecutable[B, BU, C[_]]: Executable[Query[B, BU, C], C[BU]] = null - @inline implicit def scalarIsExecutable[A, AU](implicit shape: Shape[ShapeLevel.Flat, A, AU, A]): Executable[A, AU] = null + @inline implicit def scalarIsExecutable[A, AU](implicit shape: Shape[FlatShapeLevel, A, AU, A]): Executable[A, AU] = null } /** Typeclass for types that can be contained in a `Compiled` container. This @@ -102,9 +102,9 @@ trait Compilable[T, C <: Compiled[T]] { } object Compilable extends CompilableFunctions { - implicit def function1IsCompilable[A , B <: Rep[_], P, U](implicit ashape: Shape[ShapeLevel.Columns, A, P, A], pshape: Shape[ShapeLevel.Columns, P, P, _], bexe: Executable[B, U]): Compilable[A => B, CompiledFunction[A => B, A , P, B, U]] = new Compilable[A => B, CompiledFunction[A => B, A, P, B, U]] { + implicit def function1IsCompilable[A , B <: Rep[_], P, U](implicit ashape: Shape[ColumnsShapeLevel, A, P, A], pshape: Shape[ColumnsShapeLevel, P, P, _], bexe: Executable[B, U]): Compilable[A => B, CompiledFunction[A => B, A , P, B, U]] = new Compilable[A => B, CompiledFunction[A => B, A, P, B, U]] { def compiled(raw: A => B, driver: BasicProfile) = - new CompiledFunction[A => B, A, P, B, U](raw, identity[A => B], pshape.asInstanceOf[Shape[ShapeLevel.Columns, P, P, A]], driver) + new CompiledFunction[A => B, A, P, B, U](raw, identity[A => B], pshape.asInstanceOf[Shape[ColumnsShapeLevel, P, P, A]], driver) } } @@ -114,14 +114,14 @@ trait CompilableLowPriority { } } -final class Parameters[PU, PP](pshape: Shape[ShapeLevel.Columns, PU, PU, _]) { +final class Parameters[PU, PP](pshape: Shape[ColumnsShapeLevel, PU, PU, _]) { def flatMap[R <: Rep[_], RU](f: PP => R)(implicit rexe: Executable[R, RU], driver: BasicProfile): CompiledFunction[PP => R, PP, PU, R, RU] = - new CompiledFunction[PP => R, PP, PU, R, RU](f, identity[PP => R], pshape.asInstanceOf[Shape[ShapeLevel.Columns, PU, PU, PP]], driver) + new CompiledFunction[PP => R, PP, PU, R, RU](f, identity[PP => R], pshape.asInstanceOf[Shape[ColumnsShapeLevel, PU, PU, PP]], driver) @inline def withFilter(f: PP => Boolean): Parameters[PU, PP] = this } object Parameters { - @inline def apply[U](implicit pshape: Shape[ShapeLevel.Columns, U, U, _]): Parameters[U, pshape.Packed] = + @inline def apply[U](implicit pshape: Shape[ColumnsShapeLevel, U, U, _]): Parameters[U, pshape.Packed] = new Parameters[U, pshape.Packed](pshape) } diff --git a/src/main/scala/scala/slick/lifted/Constraint.scala b/src/main/scala/scala/slick/lifted/Constraint.scala index 2e3cac0ac3..8b7bab67ff 100644 --- a/src/main/scala/scala/slick/lifted/Constraint.scala +++ b/src/main/scala/scala/slick/lifted/Constraint.scala @@ -20,7 +20,7 @@ final class ForeignKey( //TODO Simplify this mess! val linearizedTargetColumns: IndexedSeq[Node], val linearizedTargetColumnsForOriginalTargetTable: IndexedSeq[Node], val targetTable: TableNode, - val columnsShape: Shape[_ <: ShapeLevel.Flat, _, _, _]) + val columnsShape: Shape[_ <: FlatShapeLevel, _, _, _]) object ForeignKey { def apply[TT <: AbstractTable[_], P]( @@ -28,7 +28,7 @@ object ForeignKey { sourceTable: Node, targetTableShaped: ShapedValue[TT, _], originalTargetTable: TT, - pShape: Shape[_ <: ShapeLevel.Flat, P, _, _], + pShape: Shape[_ <: FlatShapeLevel, P, _, _], originalSourceColumns: P, originalTargetColumns: TT => P, onUpdate: model.ForeignKeyAction, @@ -65,7 +65,7 @@ class ForeignKeyQuery[E <: AbstractTable[_], U]( def & (other: ForeignKeyQuery[E, U]): ForeignKeyQuery[E, U] = { val newFKs = fks ++ other.fks val conditions = newFKs.map { fk => - val sh = fk.columnsShape.asInstanceOf[Shape[ShapeLevel.Flat, Any, Any, Any]] + val sh = fk.columnsShape.asInstanceOf[Shape[FlatShapeLevel, Any, Any, Any]] Library.==.typed[Boolean](sh.toNode(fk.targetColumns(aliasedValue)), sh.toNode(fk.sourceColumns)) }.reduceLeft[Node]((a, b) => Library.And.typed[Boolean](a, b)) val newDelegate = Filter.ifRefutable(generator, targetBaseQuery.toNode, conditions) diff --git a/src/main/scala/scala/slick/lifted/Query.scala b/src/main/scala/scala/slick/lifted/Query.scala index dd452e7ead..f33b8f5a7e 100644 --- a/src/main/scala/scala/slick/lifted/Query.scala +++ b/src/main/scala/scala/slick/lifted/Query.scala @@ -28,7 +28,7 @@ sealed abstract class Query[+E, U, C[_]] extends Rep[C[U]] { self => } /** Build a new query by applying a function to all elements of this query. */ - def map[F, G, T](f: E => F)(implicit shape: Shape[_ <: ShapeLevel.Flat, F, T, G]): Query[G, T, C] = + def map[F, G, T](f: E => F)(implicit shape: Shape[_ <: FlatShapeLevel, F, T, G]): Query[G, T, C] = flatMap(v => Query[F, T, G](f(v))) /** Select all elements of this query which satisfy a predicate. */ @@ -79,13 +79,13 @@ sealed abstract class Query[+E, U, C[_]] extends Rep[C[U]] { self => def zip[E2, U2, D[_]](q2: Query[E2, U2, D]): Query[(E, E2), (U, U2), C] = join(q2, JoinType.Zip) /** Return a query formed from this query and another query by combining * corresponding elements with the specified function. */ - def zipWith[E2, U2, F, G, T, D[_]](q2: Query[E2, U2, D], f: (E, E2) => F)(implicit shape: Shape[_ <: ShapeLevel.Flat, F, T, G]): Query[G, T, C] = + def zipWith[E2, U2, F, G, T, D[_]](q2: Query[E2, U2, D], f: (E, E2) => F)(implicit shape: Shape[_ <: FlatShapeLevel, F, T, G]): Query[G, T, C] = join(q2, JoinType.Zip).map[F, G, T](x => f(x._1, x._2)) /** Zip this query with its indices (starting at 0). */ def zipWithIndex = { val leftGen, rightGen = new AnonSymbol val aliased1 = shaped.encodeRef(leftGen :: Nil) - val aliased2 = ShapedValue(Column.forNode[Long](Ref(rightGen)), Shape.columnShape[Long, ShapeLevel.Flat]) + val aliased2 = ShapedValue(Column.forNode[Long](Ref(rightGen)), Shape.columnShape[Long, FlatShapeLevel]) new BaseJoinQuery[E, Column[Long], U, Long, C](leftGen, rightGen, toNode, RangeFrom(0L), JoinType.Zip, aliased1.zip(aliased2)) } @@ -103,10 +103,10 @@ sealed abstract class Query[+E, U, C[_]] extends Rep[C[U]] { self => /** Partition this query into a query of pairs of a key and a nested query * containing the elements for the key, according to some discriminator * function. */ - def groupBy[K, T, G, P](f: E => K)(implicit kshape: Shape[_ <: ShapeLevel.Flat, K, T, G], vshape: Shape[_ <: ShapeLevel.Flat, E, _, P]): Query[(G, Query[P, U, Seq]), (T, Query[P, U, Seq]), C] = { + def groupBy[K, T, G, P](f: E => K)(implicit kshape: Shape[_ <: FlatShapeLevel, K, T, G], vshape: Shape[_ <: FlatShapeLevel, E, _, P]): Query[(G, Query[P, U, Seq]), (T, Query[P, U, Seq]), C] = { val sym = new AnonSymbol val key = ShapedValue(f(shaped.encodeRef(sym :: Nil).value), kshape).packedValue - val value = ShapedValue(pack.to[Seq], Shape.repShape.asInstanceOf[Shape[ShapeLevel.Flat, Query[P, U, Seq], Query[P, U, Seq], Query[P, U, Seq]]]) + val value = ShapedValue(pack.to[Seq], Shape.repShape.asInstanceOf[Shape[FlatShapeLevel, Query[P, U, Seq], Query[P, U, Seq], Query[P, U, Seq]]]) val group = GroupBy(sym, toNode, key.toNode) new WrappingQuery[(G, Query[P, U, Seq]), (T, Query[P, U, Seq]), C](group, key.zip(value)) } @@ -139,7 +139,7 @@ sealed abstract class Query[+E, U, C[_]] extends Rep[C[U]] { self => /** Test whether this query is non-empty. */ def exists = Library.Exists.column[Boolean](toNode) - def pack[R](implicit packing: Shape[_ <: ShapeLevel.Flat, E, _, R]): Query[R, U, C] = + def pack[R](implicit packing: Shape[_ <: FlatShapeLevel, E, _, R]): Query[R, U, C] = new Query[R, U, C] { val shaped: ShapedValue[_ <: R, U] = self.shaped.packedValue(packing) def toNode = self.toNode @@ -159,19 +159,19 @@ sealed abstract class Query[+E, U, C[_]] extends Rep[C[U]] { self => /** The companion object for Query contains factory methods for creating queries. */ object Query { /** Lift a scalar value to a Query. */ - def apply[E, U, R](value: E)(implicit unpack: Shape[_ <: ShapeLevel.Flat, E, U, R]): Query[R, U, Seq] = { + def apply[E, U, R](value: E)(implicit unpack: Shape[_ <: FlatShapeLevel, E, U, R]): Query[R, U, Seq] = { val shaped = ShapedValue(value, unpack).packedValue new WrappingQuery[R, U, Seq](Pure(shaped.toNode), shaped) } @deprecated("Use Query.apply instead of Query.pure", "2.1") - def pure[E, U, R](value: E)(implicit unpack: Shape[_ <: ShapeLevel.Flat, E, U, R]): Query[R, U, Seq] = + def pure[E, U, R](value: E)(implicit unpack: Shape[_ <: FlatShapeLevel, E, U, R]): Query[R, U, Seq] = apply[E, U, R](value) /** The empty Query. */ def empty: Query[Unit, Unit, Seq] = new Query[Unit, Unit, Seq] { val toNode = shaped.toNode - def shaped = ShapedValue((), Shape.unitShape[ShapeLevel.Flat]) + def shaped = ShapedValue((), Shape.unitShape[FlatShapeLevel]) } } @@ -218,7 +218,7 @@ class TableQuery[E <: AbstractTable[_]](cons: Tag => E) extends Query[E, E#Table def taggedAs(path: List[Symbol]) = base.taggedAs(path) }) }) - ShapedValue(baseTable, Shape.repShape.asInstanceOf[Shape[ShapeLevel.Flat, E, E#TableElementType, E]]) + ShapedValue(baseTable, Shape.repShape.asInstanceOf[Shape[FlatShapeLevel, E, E#TableElementType, E]]) } val toNode = shaped.toNode diff --git a/src/main/scala/scala/slick/lifted/Shape.scala b/src/main/scala/scala/slick/lifted/Shape.scala index f8ad5742d4..d12b7755b1 100644 --- a/src/main/scala/scala/slick/lifted/Shape.scala +++ b/src/main/scala/scala/slick/lifted/Shape.scala @@ -61,20 +61,20 @@ trait ShapeLowPriority extends ShapeLowPriority1 { repShape.asInstanceOf[Shape[Level, Column[T], T, Column[T]]] /** Shape for Rep values (always fully packed) */ - val repShape: Shape[ShapeLevel.Flat, Rep[_], Any, Rep[_]] = new Shape[ShapeLevel.Flat, Rep[_], Any, Rep[_]] { + val repShape: Shape[FlatShapeLevel, Rep[_], Any, Rep[_]] = new Shape[FlatShapeLevel, Rep[_], Any, Rep[_]] { def pack(value: Mixed): Packed = value - def packedShape: Shape[ShapeLevel.Flat, Packed, Unpacked, Packed] = this + def packedShape: Shape[FlatShapeLevel, Packed, Unpacked, Packed] = this def buildParams(extract: Any => Unpacked): Packed = throw new SlickException("Shape does not have the same Mixed and Unpacked type") def encodeRef(value: Mixed, path: List[Symbol]) = value.encodeRef(path) def toNode(value: Mixed): Node = value.toNode } - implicit def provenShape[T, P](implicit shape: Shape[_ <: ShapeLevel.Flat, T, _, P]): Shape[ShapeLevel.Flat, ProvenShape[T], T, P] = new Shape[ShapeLevel.Flat, ProvenShape[T], T, P] { + implicit def provenShape[T, P](implicit shape: Shape[_ <: FlatShapeLevel, T, _, P]): Shape[FlatShapeLevel, ProvenShape[T], T, P] = new Shape[FlatShapeLevel, ProvenShape[T], T, P] { def pack(value: Mixed): Packed = value.shape.pack(value.value.asInstanceOf[value.shape.Mixed]).asInstanceOf[Packed] - def packedShape: Shape[ShapeLevel.Flat, Packed, Unpacked, Packed] = - shape.packedShape.asInstanceOf[Shape[ShapeLevel.Flat, Packed, Unpacked, Packed]] + def packedShape: Shape[FlatShapeLevel, Packed, Unpacked, Packed] = + shape.packedShape.asInstanceOf[Shape[FlatShapeLevel, Packed, Unpacked, Packed]] def buildParams(extract: Any => Unpacked): Packed = shape.buildParams(extract.asInstanceOf[Any => shape.Unpacked]) def encodeRef(value: Mixed, path: List[Symbol]) = @@ -83,12 +83,12 @@ trait ShapeLowPriority extends ShapeLowPriority1 { value.shape.toNode(value.value.asInstanceOf[value.shape.Mixed]) } - @inline implicit def queryShape[Level >: ShapeLevel.Nested <: ShapeLevel, M, U, C[_]]: Shape[Level, Query[M, U, C], Seq[U], Query[M, U, C]] = + @inline implicit def queryShape[Level >: NestedShapeLevel <: ShapeLevel, M, U, C[_]]: Shape[Level, Query[M, U, C], Seq[U], Query[M, U, C]] = repShape.asInstanceOf[Shape[Level, Query[M, U, C], Seq[U], Query[M, U, C]]] } class ShapeLowPriority1 extends ShapeLowPriority2 { - @inline implicit final def columnBaseShape[Level >: ShapeLevel.Flat <: ShapeLevel, T, C <: ColumnBase[_]](implicit ev: C <:< ColumnBase[T]): Shape[Level, C, T, C] = + @inline implicit final def columnBaseShape[Level >: FlatShapeLevel <: ShapeLevel, T, C <: ColumnBase[_]](implicit ev: C <:< ColumnBase[T]): Shape[Level, C, T, C] = Shape.repShape.asInstanceOf[Shape[Level, C, T, C]] implicit final def primitiveShape[T, Level <: ShapeLevel](implicit tm: TypedType[T]): Shape[Level, T, T, Column[T]] = new Shape[Level, T, T, Column[T]] { @@ -103,9 +103,9 @@ class ShapeLowPriority1 extends ShapeLowPriority2 { @inline implicit final def unitShape[Level <: ShapeLevel]: Shape[Level, Unit, Unit, Unit] = unitShapePrototype.asInstanceOf[Shape[Level, Unit, Unit, Unit]] - val unitShapePrototype: Shape[ShapeLevel.Flat, Unit, Unit, Unit] = new Shape[ShapeLevel.Flat, Unit, Unit, Unit] { + val unitShapePrototype: Shape[FlatShapeLevel, Unit, Unit, Unit] = new Shape[FlatShapeLevel, Unit, Unit, Unit] { def pack(value: Mixed) = () - def packedShape: Shape[ShapeLevel.Flat, Packed, Unpacked, Packed] = this + def packedShape: Shape[FlatShapeLevel, Packed, Unpacked, Packed] = this def buildParams(extract: Any => Unpacked) = () def encodeRef(value: Mixed, path: List[Symbol]) = () def toNode(value: Mixed) = ProductNode(Nil) @@ -129,7 +129,7 @@ abstract class ProductNodeShape[Level <: ShapeLevel, C, M <: C, U <: C, P <: C] /** Create a copy of this Shape with new element Shapes. This is used for * packing Shapes recursively. */ - def copy(shapes: Seq[Shape[_, _, _, _]]): Shape[Level, _, _, _] + def copy(shapes: Seq[Shape[_ <: ShapeLevel, _, _, _]]): Shape[Level, _, _, _] /** Get the element value from a record value at the specified index. */ def getElement(value: C, idx: Int): Any @@ -144,7 +144,7 @@ abstract class ProductNodeShape[Level <: ShapeLevel, C, M <: C, U <: C, P <: C] buildValue(elems.toIndexedSeq).asInstanceOf[Packed] } def packedShape: Shape[Level, Packed, Unpacked, Packed] = - copy(shapes.map(_.packedShape)).asInstanceOf[Shape[Level, Packed, Unpacked, Packed]] + copy(shapes.map(_.packedShape.asInstanceOf[Shape[_ <: ShapeLevel, _, _, _]])).asInstanceOf[Shape[Level, Packed, Unpacked, Packed]] def buildParams(extract: Any => Unpacked): Packed = { val elems = shapes.iterator.zipWithIndex.map { case (p, idx) => def chExtract(u: C): p.Unpacked = getElement(u, idx).asInstanceOf[p.Unpacked] @@ -182,40 +182,41 @@ final class TupleShape[Level <: ShapeLevel, M <: Product, U <: Product, P <: Pro override def getIterator(value: Product) = value.productIterator def getElement(value: Product, idx: Int) = value.productElement(idx) def buildValue(elems: IndexedSeq[Any]) = TupleSupport.buildTuple(elems) - def copy(shapes: Seq[Shape[_, _, _, _]]) = new TupleShape(shapes: _*) + def copy(shapes: Seq[Shape[_ <: ShapeLevel, _, _, _]]) = new TupleShape(shapes: _*) } /** The level of a Shape, i.e. what kind of types it allows. - * This is used as a phantom type for Shape resolution. There are no - * instances of any ShapeLevel. */ + * Subtypes of this trait are used as a phantom type for Shape resolution. + * There are no instances of any ShapeLevel. */ trait ShapeLevel -object ShapeLevel { - /** Allows nested collections but no computations. */ - trait Nested extends ShapeLevel - /** Does not allow nested collections. - * This is the standard level for executable queries. */ - trait Flat extends Nested - /** Only records of individual columns. - * This level is used for parameters of compiled queries. */ - trait Columns extends Flat -} + +/** ShapeLevel that allows nested collections. */ +trait NestedShapeLevel extends ShapeLevel + +/** ShapeLevel that does not allow nested collections. + * This is the standard level for executable queries. */ +trait FlatShapeLevel extends NestedShapeLevel + +/** ShapeLevel that only allows records of individual columns. + * This level is used for parameters of compiled queries. */ +trait ColumnsShapeLevel extends FlatShapeLevel /** A value together with its Shape */ -case class ShapedValue[T, U](value: T, shape: Shape[_ <: ShapeLevel.Flat, T, U, _]) { +case class ShapedValue[T, U](value: T, shape: Shape[_ <: FlatShapeLevel, T, U, _]) { def encodeRef(path: List[Symbol]): ShapedValue[T, U] = { val fv = shape.encodeRef(value, path).asInstanceOf[T] if(fv.asInstanceOf[AnyRef] eq value.asInstanceOf[AnyRef]) this else new ShapedValue(fv, shape) } def toNode = shape.toNode(value) - def packedValue[R](implicit ev: Shape[_ <: ShapeLevel.Flat, T, _, R]): ShapedValue[R, U] = ShapedValue(shape.pack(value).asInstanceOf[R], shape.packedShape.asInstanceOf[Shape[ShapeLevel.Flat, R, U, _]]) + def packedValue[R](implicit ev: Shape[_ <: FlatShapeLevel, T, _, R]): ShapedValue[R, U] = ShapedValue(shape.pack(value).asInstanceOf[R], shape.packedShape.asInstanceOf[Shape[FlatShapeLevel, R, U, _]]) def zip[T2, U2](s2: ShapedValue[T2, U2]) = new ShapedValue[(T, T2), (U, U2)]((value, s2.value), Shape.tuple2Shape(shape, s2.shape)) @inline def <>[R : ClassTag](f: (U => R), g: (R => Option[U])) = new MappedProjection[R, U](shape.toNode(value), f, g.andThen(_.get), implicitly[ClassTag[R]]) } // Work-around for SI-3346 final class ToShapedValue[T](val value: T) extends AnyVal { - @inline def shaped[U](implicit shape: Shape[_ <: ShapeLevel.Flat, T, U, _]) = new ShapedValue[T, U](value, shape) - @inline def <>[R : ClassTag, U](f: (U => R), g: (R => Option[U]))(implicit shape: Shape[_ <: ShapeLevel.Flat, T, U, _]) = new MappedProjection[R, U](shape.toNode(value), f, g.andThen(_.get), implicitly[ClassTag[R]]) + @inline def shaped[U](implicit shape: Shape[_ <: FlatShapeLevel, T, U, _]) = new ShapedValue[T, U](value, shape) + @inline def <>[R : ClassTag, U](f: (U => R), g: (R => Option[U]))(implicit shape: Shape[_ <: FlatShapeLevel, T, U, _]) = new MappedProjection[R, U](shape.toNode(value), f, g.andThen(_.get), implicitly[ClassTag[R]]) } /** A limited version of ShapedValue which can be constructed for every type @@ -224,18 +225,18 @@ final class ToShapedValue[T](val value: T) extends AnyVal { * place of the value that it wraps for purposes of packing and unpacking. */ trait ProvenShape[U] { def value: Any - val shape: Shape[_ <: ShapeLevel.Flat, _, U, _] - def packedValue[R](implicit ev: Shape[_ <: ShapeLevel.Flat, _, U, R]): ShapedValue[R, U] + val shape: Shape[_ <: FlatShapeLevel, _, U, _] + def packedValue[R](implicit ev: Shape[_ <: FlatShapeLevel, _, U, R]): ShapedValue[R, U] def toNode = packedValue(shape).toNode } object ProvenShape { /** Convert an appropriately shaped value to a ProvenShape */ - implicit def proveShapeOf[T, U](v: T)(implicit sh: Shape[_ <: ShapeLevel.Flat, T, U, _]): ProvenShape[U] = + implicit def proveShapeOf[T, U](v: T)(implicit sh: Shape[_ <: FlatShapeLevel, T, U, _]): ProvenShape[U] = new ProvenShape[U] { def value = v - val shape: Shape[_ <: ShapeLevel.Flat, _, U, _] = sh.asInstanceOf[Shape[ShapeLevel.Flat, _, U, _]] - def packedValue[R](implicit ev: Shape[_ <: ShapeLevel.Flat, _, U, R]): ShapedValue[R, U] = ShapedValue(sh.pack(value).asInstanceOf[R], sh.packedShape.asInstanceOf[Shape[ShapeLevel.Flat, R, U, _]]) + val shape: Shape[_ <: FlatShapeLevel, _, U, _] = sh.asInstanceOf[Shape[FlatShapeLevel, _, U, _]] + def packedValue[R](implicit ev: Shape[_ <: FlatShapeLevel, _, U, R]): ShapedValue[R, U] = ShapedValue(sh.pack(value).asInstanceOf[R], sh.packedShape.asInstanceOf[Shape[FlatShapeLevel, R, U, _]]) } } diff --git a/src/main/scala/scala/slick/model/codegen/AbstractSourceCodeGenerator.scala b/src/main/scala/scala/slick/model/codegen/AbstractSourceCodeGenerator.scala index 2fedfda3c3..8cf379d84a 100644 --- a/src/main/scala/scala/slick/model/codegen/AbstractSourceCodeGenerator.scala +++ b/src/main/scala/scala/slick/model/codegen/AbstractSourceCodeGenerator.scala @@ -143,7 +143,7 @@ class $name(tag: Tag) extends Table[$elementType](tag, ${args.mkString(", ")})$p class ColumnDef(model: m.Column) extends super.ColumnDef(model){ import ColumnOption._ def columnOptionCode = { - case PrimaryKey => Some(s"O.PrimaryKey") + case ColumnOption.PrimaryKey => Some(s"O.PrimaryKey") case Default(value) => Some(s"O.Default(${default.get})") // .get is safe here case DBType(dbType) => Some(s"O.DBType($dbType)") case AutoInc => Some(s"O.AutoInc") diff --git a/src/main/scala/scala/slick/profile/BasicProfile.scala b/src/main/scala/scala/slick/profile/BasicProfile.scala index 4668aeb7c8..1a4b9d7d59 100644 --- a/src/main/scala/scala/slick/profile/BasicProfile.scala +++ b/src/main/scala/scala/slick/profile/BasicProfile.scala @@ -47,7 +47,7 @@ trait BasicProfile extends BasicInvokerComponent with BasicExecutorComponent { d implicit def shapedValueToQueryExecutor[U](u: ShapedValue[_, U]): QueryExecutor[U] = createQueryExecutor[U](queryCompiler.run(u.toNode).tree, ()) implicit def runnableCompiledToQueryExecutor[RU](c: RunnableCompiled[_, RU]): QueryExecutor[RU] = createQueryExecutor[RU](c.compiledQuery, c.param) // We can't use this direct way due to SI-3346 - def recordToQueryExecutor[M, R](q: M)(implicit shape: Shape[_ <: ShapeLevel.Flat, M, R, _]): QueryExecutor[R] = createQueryExecutor[R](queryCompiler.run(shape.toNode(q)).tree, ()) + def recordToQueryExecutor[M, R](q: M)(implicit shape: Shape[_ <: FlatShapeLevel, M, R, _]): QueryExecutor[R] = createQueryExecutor[R](queryCompiler.run(shape.toNode(q)).tree, ()) implicit def recordToUnshapedQueryExecutor[M <: Rep[_]](q: M): UnshapedQueryExecutor[M] = createUnshapedQueryExecutor[M](q) implicit def columnBaseToInsertInvoker[T](c: ColumnBase[T]) = createInsertInvoker[T](insertCompiler.run(c.toNode).tree) @@ -144,10 +144,10 @@ trait BasicExecutorComponent { driver: BasicDriver => // Work-around for SI-3346 class UnshapedQueryExecutorDef[M](protected[this] val value: M) { - @inline final def run[U](implicit shape: Shape[_ <: ShapeLevel.Flat, M, U, _], session: Backend#Session): U = + @inline final def run[U](implicit shape: Shape[_ <: FlatShapeLevel, M, U, _], session: Backend#Session): U = executor[U].run - @inline final def executor[U](implicit shape: Shape[_ <: ShapeLevel.Flat, M, U, _]): QueryExecutor[U] = + @inline final def executor[U](implicit shape: Shape[_ <: FlatShapeLevel, M, U, _]): QueryExecutor[U] = createQueryExecutor[U](queryCompiler.run(shape.toNode(value)).tree, ()) } } diff --git a/src/sphinx/code/LiftedEmbedding.scala b/src/sphinx/code/LiftedEmbedding.scala index b3d5f3b7b1..b5ec18cf0e 100644 --- a/src/sphinx/code/LiftedEmbedding.scala +++ b/src/sphinx/code/LiftedEmbedding.scala @@ -454,7 +454,7 @@ object LiftedEmbedding extends App { val shapes: Seq[Shape[_, _, _, _]]) extends MappedScalaProductShape[Level, Pair[_,_], M, U, P] { def buildValue(elems: IndexedSeq[Any]) = Pair(elems(0), elems(1)) - def copy(shapes: Seq[Shape[_, _, _, _]]) = new PairShape(shapes) + def copy(shapes: Seq[Shape[_ <: ShapeLevel, _, _, _]]) = new PairShape(shapes) } implicit def pairShape[Level <: ShapeLevel, M1, M2, U1, U2, P1, P2](