Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added statically typed magics, also added support of Date for insertion

  • Loading branch information...
commit cbe162a0ecbf7996eba2ab028264a9cc332cb915 1 parent 5246807
Sadek Drobi authored
Showing with 5,022 additions and 437 deletions.
  1. +4 −4 samples-and-tests/just-test-cases/test/SqlTests.scala
  2. +13 −3 src/play/db/anorm/Anorm.scala
  3. +155 −0 src/play/db/anorm/Magic10.scala
  4. +161 −0 src/play/db/anorm/Magic11.scala
  5. +167 −0 src/play/db/anorm/Magic12.scala
  6. +173 −0 src/play/db/anorm/Magic13.scala
  7. +179 −0 src/play/db/anorm/Magic14.scala
  8. +185 −0 src/play/db/anorm/Magic15.scala
  9. +191 −0 src/play/db/anorm/Magic16.scala
  10. +197 −0 src/play/db/anorm/Magic17.scala
  11. +203 −0 src/play/db/anorm/Magic18.scala
  12. +209 −0 src/play/db/anorm/Magic19.scala
  13. +32 −32 src/play/db/anorm/Magic2.scala
  14. +215 −0 src/play/db/anorm/Magic20.scala
  15. +221 −0 src/play/db/anorm/Magic21.scala
  16. +227 −0 src/play/db/anorm/Magic22.scala
  17. +33 −33 src/play/db/anorm/Magic3.scala
  18. +34 −34 src/play/db/anorm/Magic4.scala
  19. +35 −35 src/play/db/anorm/Magic5.scala
  20. +131 −0 src/play/db/anorm/Magic6.scala
  21. +137 −0 src/play/db/anorm/Magic7.scala
  22. +143 −0 src/play/db/anorm/Magic8.scala
  23. +149 −0 src/play/db/anorm/Magic9.scala
  24. +1,828 −0 src/play/db/anorm/MagicN.scala
  25. +0 −296 src/play/db/anorm/packaged.scala
View
8 samples-and-tests/just-test-cases/test/SqlTests.scala
@@ -132,7 +132,7 @@ class SqlTests extends UnitTestCase with ShouldMatchersForJUnit {
import withDef._
case class BBB(id:String,comment:String)
- object BBB extends MagicParser2[String,String,BBB](Some(Description2("Task")))
+ object BBB extends AbstractMagicParser2[String,String,BBB](Some(Description2("Task")))
@Test def useSomeMagicSqlCompileTime{
@@ -148,7 +148,7 @@ class SqlTests extends UnitTestCase with ShouldMatchersForJUnit {
play.db.DB.execute("""insert into Task Values('1','some comment')""")
play.db.DB.execute("""insert into Student Values('1','1')""")
- object TT2 extends MagicParser2[String,String,(String,String)](Some(Description2("Task"))) {
+ object TT2 extends AbstractMagicParser2[String,String,(String,String)](Some(Description2("Task"))) {
def apply(id:String,comment:String) = (id,comment)
@@ -158,9 +158,9 @@ class SqlTests extends UnitTestCase with ShouldMatchersForJUnit {
SQL("select * from Task ").as(TT2) should be (("1","some comment"))
}
- implicit def statementInOut[A](implicit c:ColumnTo[A], ts:ToStatement[A]):(ColumnTo[A],ToStatement[A]) = (c,ts)
- object AAA extends Magic2[Pk[Int],String,AAA]()
+
+ object AAA extends AbstractMagic2[Pk[Int],String,AAA]()
case class AAA(id:Pk[Int],comment:String)
View
16 src/play/db/anorm/Anorm.scala
@@ -13,9 +13,13 @@ package object anorm {
def SQL(stmt: String) = Sql.sql(stmt)
val asIs :PartialFunction[AnalyserInfo,String] = {case ColumnC(t,f) => t+"."+f; case TableC(typeName) => typeName}
- val defaults = Convention(asIs)
-// implicit def statementInOut[A](implicit c:ColumnTo[A]):(ColumnTo[A],ToStatement[A]) = (c,null)
+ val defaults = new Convention(asIs) with WithDefaults{
+
+ override lazy val defaultConvention = asIs
+ }
+
+ implicit def statementInOut[A](implicit c:ColumnTo[A], ts:ToStatement[A]):(ColumnTo[A],ToStatement[A]) = (c,ts)
}
@@ -786,6 +790,7 @@ package anorm {
case Some(o) => stmt.setObject(index, o)
case None => stmt.setObject(index, null)
case bd:java.math.BigDecimal => stmt.setBigDecimal(index,bd)
+ case date:java.util.Date => stmt.setDate(index,new java.sql.Date(date.getTime()))
case o => stmt.setObject(index,o)
}
stmt
@@ -794,6 +799,11 @@ package anorm {
def set(s:java.sql.PreparedStatement,index:Int,aValue:T):Unit = setAny(index, aValue, s)
}
+ implicit val dateToStatement = new ToStatement[java.util.Date] {
+ def set(s:java.sql.PreparedStatement, index:Int, aValue:java.util.Date):Unit = s.setDate(index,new java.sql.Date(aValue.getTime()))
+
+ }
+
implicit def optionToStatement[A](implicit ts:ToStatement[A]):ToStatement[Option[A]] = new ToStatement[Option[A]] {
def set(s:java.sql.PreparedStatement,index:Int,aValue:Option[A]):Unit = {
aValue match {
@@ -973,4 +983,4 @@ package anorm {
}
-}
+}
View
155 src/play/db/anorm/Magic10.scala
@@ -0,0 +1,155 @@
+
+
+
+
+package play.db
+
+import play.utils.Scala.MayErr
+import play.utils.Scala.MayErr._
+
+package anorm {
+
+ trait MParser10[ A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, R] extends ParserWithId[R] {
+
+ val p1:ColumnTo[A1]
+
+ val p2:ColumnTo[A2]
+
+ val p3:ColumnTo[A3]
+
+ val p4:ColumnTo[A4]
+
+ val p5:ColumnTo[A5]
+
+ val p6:ColumnTo[A6]
+
+ val p7:ColumnTo[A7]
+
+ val p8:ColumnTo[A8]
+
+ val p9:ColumnTo[A9]
+
+ val p10:ColumnTo[A10]
+
+ def apply(a1:A1, a2:A2, a3:A3, a4:A4, a5:A5, a6:A6, a7:A7, a8:A8, a9:A9, a10:A10 ):R
+
+ val containerName:String
+ val columnNames:(String, String, String, String, String, String, String, String, String, String)
+
+ lazy val (name1 ,name2 ,name3 ,name4 ,name5 ,name6 ,name7 ,name8 ,name9 ,name10) = columnNames
+
+ import SqlParser._
+ override def apply(input:Input):SqlParser.ParseResult[R] =
+ (
+ get[A1](name1)(p1) ~<
+ get[A2](name2)(p2) ~<
+ get[A3](name3)(p3) ~<
+ get[A4](name4)(p4) ~<
+ get[A5](name5)(p5) ~<
+ get[A6](name6)(p6) ~<
+ get[A7](name7)(p7) ~<
+ get[A8](name8)(p8) ~<
+ get[A9](name9)(p9) ~<
+ get[A10](name10)(p10) ^^ { case a1 ~ a2 ~ a3 ~ a4 ~ a5 ~ a6 ~ a7 ~ a8 ~ a9 ~ a10 => apply(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10)} )(input)
+
+ val uniqueId : (Row=> MayErr[SqlRequestError,Any]) = null
+ }
+
+ trait M10[ A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, R] {
+ self: MParser10[ A1, A2, A3, A4, A5, A6, A7, A8, A9, A10,R] =>
+
+ val pt1:(ColumnTo[A1],ToStatement[A1])
+ val pt2:(ColumnTo[A2],ToStatement[A2])
+ val pt3:(ColumnTo[A3],ToStatement[A3])
+ val pt4:(ColumnTo[A4],ToStatement[A4])
+ val pt5:(ColumnTo[A5],ToStatement[A5])
+ val pt6:(ColumnTo[A6],ToStatement[A6])
+ val pt7:(ColumnTo[A7],ToStatement[A7])
+ val pt8:(ColumnTo[A8],ToStatement[A8])
+ val pt9:(ColumnTo[A9],ToStatement[A9])
+ val pt10:(ColumnTo[A10],ToStatement[A10])
+
+ def unapply(r:R):Option[( A1, A2, A3, A4, A5, A6, A7, A8, A9, A10)]
+ def unqualify(columnName:String) = columnName.split('.').last
+
+ def update(v:R)(implicit hasId: (A1 <:< Pk[_])|:|(A2 <:< Pk[_])|:|(A3 <:< Pk[_])|:|(A4 <:< Pk[_])|:|(A5 <:< Pk[_])|:|(A6 <:< Pk[_])|:|(A7 <:< Pk[_])|:|(A8 <:< Pk[_])|:|(A9 <:< Pk[_])|:|(A10 <:< Pk[_]) ) = {
+
+ val all = ((v,hasId) match {
+ case (self( a1, a2, a3, a4, a5, a6, a7, a8, a9, a10), ( e1 |:| e2 |:| e3 |:| e4 |:| e5 |:| e6 |:| e7 |:| e8 |:| e9 |:| e10)) =>
+ List (
+ (e1, unqualify(name1), toParameterValue(a1)(pt1._2)),
+ (e2, unqualify(name2), toParameterValue(a2)(pt2._2)),
+ (e3, unqualify(name3), toParameterValue(a3)(pt3._2)),
+ (e4, unqualify(name4), toParameterValue(a4)(pt4._2)),
+ (e5, unqualify(name5), toParameterValue(a5)(pt5._2)),
+ (e6, unqualify(name6), toParameterValue(a6)(pt6._2)),
+ (e7, unqualify(name7), toParameterValue(a7)(pt7._2)),
+ (e8, unqualify(name8), toParameterValue(a8)(pt8._2)),
+ (e9, unqualify(name9), toParameterValue(a9)(pt9._2)),
+ (e10, unqualify(name10), toParameterValue(a10)(pt10._2)))
+ })
+
+ val (ids,toSet) = all.partition(_._1.isDefined)
+ if(ids == all) throw new Exception("everything is a Pk, nothing left to set!")
+
+ val toUpdate = toSet.map(_._2).map(n => n+" = "+"{"+n+"}").mkString(", ")
+
+ import Sql._
+
+ sql("update "+containerName +" set "+toUpdate+
+ " where "+ ids.map(_._2).map( n => n+" = "+"{"+n+"}").mkString(" and ") )
+ .on(all.map(v => (v._2,v._3)): _* )
+ .executeUpdate()
+
+ }
+
+ def create(v:R)(implicit hasId: (A1 <:< Pk[_])|:|(A2 <:< Pk[_])|:|(A3 <:< Pk[_])|:|(A4 <:< Pk[_])|:|(A5 <:< Pk[_])|:|(A6 <:< Pk[_])|:|(A7 <:< Pk[_])|:|(A8 <:< Pk[_])|:|(A9 <:< Pk[_])|:|(A10 <:< Pk[_]) ) :R = {
+
+ val all = ((v,hasId) match {
+ case (self( a1, a2, a3, a4, a5, a6, a7, a8, a9, a10), ( e1 |:| e2 |:| e3 |:| e4 |:| e5 |:| e6 |:| e7 |:| e8 |:| e9 |:| e10)) =>
+ List (
+ (e1, unqualify(name1), toParameterValue(a1)(pt1._2)),
+ (e2, unqualify(name2), toParameterValue(a2)(pt2._2)),
+ (e3, unqualify(name3), toParameterValue(a3)(pt3._2)),
+ (e4, unqualify(name4), toParameterValue(a4)(pt4._2)),
+ (e5, unqualify(name5), toParameterValue(a5)(pt5._2)),
+ (e6, unqualify(name6), toParameterValue(a6)(pt6._2)),
+ (e7, unqualify(name7), toParameterValue(a7)(pt7._2)),
+ (e8, unqualify(name8), toParameterValue(a8)(pt8._2)),
+ (e9, unqualify(name9), toParameterValue(a9)(pt9._2)),
+ (e10, unqualify(name10), toParameterValue(a10)(pt10._2)))
+ })
+
+ val (notSetIds,toSet) = all.partition(i => i._1.isDefined && i._3.aValue==NotAssigned)
+ if(notSetIds.length > 1) throw new Exception("multi ids not supported")
+ val toInsert = toSet.map(_._2)
+
+ import Sql._
+ import scala.util.control.Exception._
+ import SqlParser._
+
+ val idParser:SqlParser.Parser[_] = {
+ SqlParser.RowParser(row =>
+ row.asList.headOption.flatMap(a =>
+ (if (a.isInstanceOf[Option[_]]) a else Option(a)).asInstanceOf[Option[_]]
+ ).toRight(NoColumnsInReturnedResult)
+ )
+ }
+
+ val (statement, ok) = sql("insert into "+containerName+" ( "+toInsert.mkString(", ")+" ) values ( "+toInsert.map("{"+_+"}").mkString(", ")+")")
+ .on(all.map(v => (v._2,v._3)): _* )
+ .execute1(getGeneratedKeys=true)
+
+ val rs = statement.getGeneratedKeys();
+ val id = idParser(StreamReader(Sql.resultSetToStream(rs))).get
+
+ val List( a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) = all.map(_._3.aValue).map({case NotAssigned => Id(id); case other => other})
+ apply(a1.asInstanceOf[A1], a2.asInstanceOf[A2], a3.asInstanceOf[A3], a4.asInstanceOf[A4], a5.asInstanceOf[A5], a6.asInstanceOf[A6], a7.asInstanceOf[A7], a8.asInstanceOf[A8], a9.asInstanceOf[A9], a10.asInstanceOf[A10])
+
+
+ }
+ }
+
+}
+
+
View
161 src/play/db/anorm/Magic11.scala
@@ -0,0 +1,161 @@
+
+
+
+
+package play.db
+
+import play.utils.Scala.MayErr
+import play.utils.Scala.MayErr._
+
+package anorm {
+
+ trait MParser11[ A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, R] extends ParserWithId[R] {
+
+ val p1:ColumnTo[A1]
+
+ val p2:ColumnTo[A2]
+
+ val p3:ColumnTo[A3]
+
+ val p4:ColumnTo[A4]
+
+ val p5:ColumnTo[A5]
+
+ val p6:ColumnTo[A6]
+
+ val p7:ColumnTo[A7]
+
+ val p8:ColumnTo[A8]
+
+ val p9:ColumnTo[A9]
+
+ val p10:ColumnTo[A10]
+
+ val p11:ColumnTo[A11]
+
+ def apply(a1:A1, a2:A2, a3:A3, a4:A4, a5:A5, a6:A6, a7:A7, a8:A8, a9:A9, a10:A10, a11:A11 ):R
+
+ val containerName:String
+ val columnNames:(String, String, String, String, String, String, String, String, String, String, String)
+
+ lazy val (name1 ,name2 ,name3 ,name4 ,name5 ,name6 ,name7 ,name8 ,name9 ,name10 ,name11) = columnNames
+
+ import SqlParser._
+ override def apply(input:Input):SqlParser.ParseResult[R] =
+ (
+ get[A1](name1)(p1) ~<
+ get[A2](name2)(p2) ~<
+ get[A3](name3)(p3) ~<
+ get[A4](name4)(p4) ~<
+ get[A5](name5)(p5) ~<
+ get[A6](name6)(p6) ~<
+ get[A7](name7)(p7) ~<
+ get[A8](name8)(p8) ~<
+ get[A9](name9)(p9) ~<
+ get[A10](name10)(p10) ~<
+ get[A11](name11)(p11) ^^ { case a1 ~ a2 ~ a3 ~ a4 ~ a5 ~ a6 ~ a7 ~ a8 ~ a9 ~ a10 ~ a11 => apply(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11)} )(input)
+
+ val uniqueId : (Row=> MayErr[SqlRequestError,Any]) = null
+ }
+
+ trait M11[ A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, R] {
+ self: MParser11[ A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11,R] =>
+
+ val pt1:(ColumnTo[A1],ToStatement[A1])
+ val pt2:(ColumnTo[A2],ToStatement[A2])
+ val pt3:(ColumnTo[A3],ToStatement[A3])
+ val pt4:(ColumnTo[A4],ToStatement[A4])
+ val pt5:(ColumnTo[A5],ToStatement[A5])
+ val pt6:(ColumnTo[A6],ToStatement[A6])
+ val pt7:(ColumnTo[A7],ToStatement[A7])
+ val pt8:(ColumnTo[A8],ToStatement[A8])
+ val pt9:(ColumnTo[A9],ToStatement[A9])
+ val pt10:(ColumnTo[A10],ToStatement[A10])
+ val pt11:(ColumnTo[A11],ToStatement[A11])
+
+ def unapply(r:R):Option[( A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11)]
+ def unqualify(columnName:String) = columnName.split('.').last
+
+ def update(v:R)(implicit hasId: (A1 <:< Pk[_])|:|(A2 <:< Pk[_])|:|(A3 <:< Pk[_])|:|(A4 <:< Pk[_])|:|(A5 <:< Pk[_])|:|(A6 <:< Pk[_])|:|(A7 <:< Pk[_])|:|(A8 <:< Pk[_])|:|(A9 <:< Pk[_])|:|(A10 <:< Pk[_])|:|(A11 <:< Pk[_]) ) = {
+
+ val all = ((v,hasId) match {
+ case (self( a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11), ( e1 |:| e2 |:| e3 |:| e4 |:| e5 |:| e6 |:| e7 |:| e8 |:| e9 |:| e10 |:| e11)) =>
+ List (
+ (e1, unqualify(name1), toParameterValue(a1)(pt1._2)),
+ (e2, unqualify(name2), toParameterValue(a2)(pt2._2)),
+ (e3, unqualify(name3), toParameterValue(a3)(pt3._2)),
+ (e4, unqualify(name4), toParameterValue(a4)(pt4._2)),
+ (e5, unqualify(name5), toParameterValue(a5)(pt5._2)),
+ (e6, unqualify(name6), toParameterValue(a6)(pt6._2)),
+ (e7, unqualify(name7), toParameterValue(a7)(pt7._2)),
+ (e8, unqualify(name8), toParameterValue(a8)(pt8._2)),
+ (e9, unqualify(name9), toParameterValue(a9)(pt9._2)),
+ (e10, unqualify(name10), toParameterValue(a10)(pt10._2)),
+ (e11, unqualify(name11), toParameterValue(a11)(pt11._2)))
+ })
+
+ val (ids,toSet) = all.partition(_._1.isDefined)
+ if(ids == all) throw new Exception("everything is a Pk, nothing left to set!")
+
+ val toUpdate = toSet.map(_._2).map(n => n+" = "+"{"+n+"}").mkString(", ")
+
+ import Sql._
+
+ sql("update "+containerName +" set "+toUpdate+
+ " where "+ ids.map(_._2).map( n => n+" = "+"{"+n+"}").mkString(" and ") )
+ .on(all.map(v => (v._2,v._3)): _* )
+ .executeUpdate()
+
+ }
+
+ def create(v:R)(implicit hasId: (A1 <:< Pk[_])|:|(A2 <:< Pk[_])|:|(A3 <:< Pk[_])|:|(A4 <:< Pk[_])|:|(A5 <:< Pk[_])|:|(A6 <:< Pk[_])|:|(A7 <:< Pk[_])|:|(A8 <:< Pk[_])|:|(A9 <:< Pk[_])|:|(A10 <:< Pk[_])|:|(A11 <:< Pk[_]) ) :R = {
+
+ val all = ((v,hasId) match {
+ case (self( a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11), ( e1 |:| e2 |:| e3 |:| e4 |:| e5 |:| e6 |:| e7 |:| e8 |:| e9 |:| e10 |:| e11)) =>
+ List (
+ (e1, unqualify(name1), toParameterValue(a1)(pt1._2)),
+ (e2, unqualify(name2), toParameterValue(a2)(pt2._2)),
+ (e3, unqualify(name3), toParameterValue(a3)(pt3._2)),
+ (e4, unqualify(name4), toParameterValue(a4)(pt4._2)),
+ (e5, unqualify(name5), toParameterValue(a5)(pt5._2)),
+ (e6, unqualify(name6), toParameterValue(a6)(pt6._2)),
+ (e7, unqualify(name7), toParameterValue(a7)(pt7._2)),
+ (e8, unqualify(name8), toParameterValue(a8)(pt8._2)),
+ (e9, unqualify(name9), toParameterValue(a9)(pt9._2)),
+ (e10, unqualify(name10), toParameterValue(a10)(pt10._2)),
+ (e11, unqualify(name11), toParameterValue(a11)(pt11._2)))
+ })
+
+ val (notSetIds,toSet) = all.partition(i => i._1.isDefined && i._3.aValue==NotAssigned)
+ if(notSetIds.length > 1) throw new Exception("multi ids not supported")
+ val toInsert = toSet.map(_._2)
+
+ import Sql._
+ import scala.util.control.Exception._
+ import SqlParser._
+
+ val idParser:SqlParser.Parser[_] = {
+ SqlParser.RowParser(row =>
+ row.asList.headOption.flatMap(a =>
+ (if (a.isInstanceOf[Option[_]]) a else Option(a)).asInstanceOf[Option[_]]
+ ).toRight(NoColumnsInReturnedResult)
+ )
+ }
+
+ val (statement, ok) = sql("insert into "+containerName+" ( "+toInsert.mkString(", ")+" ) values ( "+toInsert.map("{"+_+"}").mkString(", ")+")")
+ .on(all.map(v => (v._2,v._3)): _* )
+ .execute1(getGeneratedKeys=true)
+
+ val rs = statement.getGeneratedKeys();
+ val id = idParser(StreamReader(Sql.resultSetToStream(rs))).get
+
+ val List( a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11) = all.map(_._3.aValue).map({case NotAssigned => Id(id); case other => other})
+ apply(a1.asInstanceOf[A1], a2.asInstanceOf[A2], a3.asInstanceOf[A3], a4.asInstanceOf[A4], a5.asInstanceOf[A5], a6.asInstanceOf[A6], a7.asInstanceOf[A7], a8.asInstanceOf[A8], a9.asInstanceOf[A9], a10.asInstanceOf[A10], a11.asInstanceOf[A11])
+
+
+ }
+ }
+
+}
+
+
View
167 src/play/db/anorm/Magic12.scala
@@ -0,0 +1,167 @@
+
+
+
+
+package play.db
+
+import play.utils.Scala.MayErr
+import play.utils.Scala.MayErr._
+
+package anorm {
+
+ trait MParser12[ A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, R] extends ParserWithId[R] {
+
+ val p1:ColumnTo[A1]
+
+ val p2:ColumnTo[A2]
+
+ val p3:ColumnTo[A3]
+
+ val p4:ColumnTo[A4]
+
+ val p5:ColumnTo[A5]
+
+ val p6:ColumnTo[A6]
+
+ val p7:ColumnTo[A7]
+
+ val p8:ColumnTo[A8]
+
+ val p9:ColumnTo[A9]
+
+ val p10:ColumnTo[A10]
+
+ val p11:ColumnTo[A11]
+
+ val p12:ColumnTo[A12]
+
+ def apply(a1:A1, a2:A2, a3:A3, a4:A4, a5:A5, a6:A6, a7:A7, a8:A8, a9:A9, a10:A10, a11:A11, a12:A12 ):R
+
+ val containerName:String
+ val columnNames:(String, String, String, String, String, String, String, String, String, String, String, String)
+
+ lazy val (name1 ,name2 ,name3 ,name4 ,name5 ,name6 ,name7 ,name8 ,name9 ,name10 ,name11 ,name12) = columnNames
+
+ import SqlParser._
+ override def apply(input:Input):SqlParser.ParseResult[R] =
+ (
+ get[A1](name1)(p1) ~<
+ get[A2](name2)(p2) ~<
+ get[A3](name3)(p3) ~<
+ get[A4](name4)(p4) ~<
+ get[A5](name5)(p5) ~<
+ get[A6](name6)(p6) ~<
+ get[A7](name7)(p7) ~<
+ get[A8](name8)(p8) ~<
+ get[A9](name9)(p9) ~<
+ get[A10](name10)(p10) ~<
+ get[A11](name11)(p11) ~<
+ get[A12](name12)(p12) ^^ { case a1 ~ a2 ~ a3 ~ a4 ~ a5 ~ a6 ~ a7 ~ a8 ~ a9 ~ a10 ~ a11 ~ a12 => apply(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12)} )(input)
+
+ val uniqueId : (Row=> MayErr[SqlRequestError,Any]) = null
+ }
+
+ trait M12[ A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, R] {
+ self: MParser12[ A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12,R] =>
+
+ val pt1:(ColumnTo[A1],ToStatement[A1])
+ val pt2:(ColumnTo[A2],ToStatement[A2])
+ val pt3:(ColumnTo[A3],ToStatement[A3])
+ val pt4:(ColumnTo[A4],ToStatement[A4])
+ val pt5:(ColumnTo[A5],ToStatement[A5])
+ val pt6:(ColumnTo[A6],ToStatement[A6])
+ val pt7:(ColumnTo[A7],ToStatement[A7])
+ val pt8:(ColumnTo[A8],ToStatement[A8])
+ val pt9:(ColumnTo[A9],ToStatement[A9])
+ val pt10:(ColumnTo[A10],ToStatement[A10])
+ val pt11:(ColumnTo[A11],ToStatement[A11])
+ val pt12:(ColumnTo[A12],ToStatement[A12])
+
+ def unapply(r:R):Option[( A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12)]
+ def unqualify(columnName:String) = columnName.split('.').last
+
+ def update(v:R)(implicit hasId: (A1 <:< Pk[_])|:|(A2 <:< Pk[_])|:|(A3 <:< Pk[_])|:|(A4 <:< Pk[_])|:|(A5 <:< Pk[_])|:|(A6 <:< Pk[_])|:|(A7 <:< Pk[_])|:|(A8 <:< Pk[_])|:|(A9 <:< Pk[_])|:|(A10 <:< Pk[_])|:|(A11 <:< Pk[_])|:|(A12 <:< Pk[_]) ) = {
+
+ val all = ((v,hasId) match {
+ case (self( a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12), ( e1 |:| e2 |:| e3 |:| e4 |:| e5 |:| e6 |:| e7 |:| e8 |:| e9 |:| e10 |:| e11 |:| e12)) =>
+ List (
+ (e1, unqualify(name1), toParameterValue(a1)(pt1._2)),
+ (e2, unqualify(name2), toParameterValue(a2)(pt2._2)),
+ (e3, unqualify(name3), toParameterValue(a3)(pt3._2)),
+ (e4, unqualify(name4), toParameterValue(a4)(pt4._2)),
+ (e5, unqualify(name5), toParameterValue(a5)(pt5._2)),
+ (e6, unqualify(name6), toParameterValue(a6)(pt6._2)),
+ (e7, unqualify(name7), toParameterValue(a7)(pt7._2)),
+ (e8, unqualify(name8), toParameterValue(a8)(pt8._2)),
+ (e9, unqualify(name9), toParameterValue(a9)(pt9._2)),
+ (e10, unqualify(name10), toParameterValue(a10)(pt10._2)),
+ (e11, unqualify(name11), toParameterValue(a11)(pt11._2)),
+ (e12, unqualify(name12), toParameterValue(a12)(pt12._2)))
+ })
+
+ val (ids,toSet) = all.partition(_._1.isDefined)
+ if(ids == all) throw new Exception("everything is a Pk, nothing left to set!")
+
+ val toUpdate = toSet.map(_._2).map(n => n+" = "+"{"+n+"}").mkString(", ")
+
+ import Sql._
+
+ sql("update "+containerName +" set "+toUpdate+
+ " where "+ ids.map(_._2).map( n => n+" = "+"{"+n+"}").mkString(" and ") )
+ .on(all.map(v => (v._2,v._3)): _* )
+ .executeUpdate()
+
+ }
+
+ def create(v:R)(implicit hasId: (A1 <:< Pk[_])|:|(A2 <:< Pk[_])|:|(A3 <:< Pk[_])|:|(A4 <:< Pk[_])|:|(A5 <:< Pk[_])|:|(A6 <:< Pk[_])|:|(A7 <:< Pk[_])|:|(A8 <:< Pk[_])|:|(A9 <:< Pk[_])|:|(A10 <:< Pk[_])|:|(A11 <:< Pk[_])|:|(A12 <:< Pk[_]) ) :R = {
+
+ val all = ((v,hasId) match {
+ case (self( a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12), ( e1 |:| e2 |:| e3 |:| e4 |:| e5 |:| e6 |:| e7 |:| e8 |:| e9 |:| e10 |:| e11 |:| e12)) =>
+ List (
+ (e1, unqualify(name1), toParameterValue(a1)(pt1._2)),
+ (e2, unqualify(name2), toParameterValue(a2)(pt2._2)),
+ (e3, unqualify(name3), toParameterValue(a3)(pt3._2)),
+ (e4, unqualify(name4), toParameterValue(a4)(pt4._2)),
+ (e5, unqualify(name5), toParameterValue(a5)(pt5._2)),
+ (e6, unqualify(name6), toParameterValue(a6)(pt6._2)),
+ (e7, unqualify(name7), toParameterValue(a7)(pt7._2)),
+ (e8, unqualify(name8), toParameterValue(a8)(pt8._2)),
+ (e9, unqualify(name9), toParameterValue(a9)(pt9._2)),
+ (e10, unqualify(name10), toParameterValue(a10)(pt10._2)),
+ (e11, unqualify(name11), toParameterValue(a11)(pt11._2)),
+ (e12, unqualify(name12), toParameterValue(a12)(pt12._2)))
+ })
+
+ val (notSetIds,toSet) = all.partition(i => i._1.isDefined && i._3.aValue==NotAssigned)
+ if(notSetIds.length > 1) throw new Exception("multi ids not supported")
+ val toInsert = toSet.map(_._2)
+
+ import Sql._
+ import scala.util.control.Exception._
+ import SqlParser._
+
+ val idParser:SqlParser.Parser[_] = {
+ SqlParser.RowParser(row =>
+ row.asList.headOption.flatMap(a =>
+ (if (a.isInstanceOf[Option[_]]) a else Option(a)).asInstanceOf[Option[_]]
+ ).toRight(NoColumnsInReturnedResult)
+ )
+ }
+
+ val (statement, ok) = sql("insert into "+containerName+" ( "+toInsert.mkString(", ")+" ) values ( "+toInsert.map("{"+_+"}").mkString(", ")+")")
+ .on(all.map(v => (v._2,v._3)): _* )
+ .execute1(getGeneratedKeys=true)
+
+ val rs = statement.getGeneratedKeys();
+ val id = idParser(StreamReader(Sql.resultSetToStream(rs))).get
+
+ val List( a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12) = all.map(_._3.aValue).map({case NotAssigned => Id(id); case other => other})
+ apply(a1.asInstanceOf[A1], a2.asInstanceOf[A2], a3.asInstanceOf[A3], a4.asInstanceOf[A4], a5.asInstanceOf[A5], a6.asInstanceOf[A6], a7.asInstanceOf[A7], a8.asInstanceOf[A8], a9.asInstanceOf[A9], a10.asInstanceOf[A10], a11.asInstanceOf[A11], a12.asInstanceOf[A12])
+
+
+ }
+ }
+
+}
+
+
View
173 src/play/db/anorm/Magic13.scala
@@ -0,0 +1,173 @@
+
+
+
+
+package play.db
+
+import play.utils.Scala.MayErr
+import play.utils.Scala.MayErr._
+
+package anorm {
+
+ trait MParser13[ A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, R] extends ParserWithId[R] {
+
+ val p1:ColumnTo[A1]
+
+ val p2:ColumnTo[A2]
+
+ val p3:ColumnTo[A3]
+
+ val p4:ColumnTo[A4]
+
+ val p5:ColumnTo[A5]
+
+ val p6:ColumnTo[A6]
+
+ val p7:ColumnTo[A7]
+
+ val p8:ColumnTo[A8]
+
+ val p9:ColumnTo[A9]
+
+ val p10:ColumnTo[A10]
+
+ val p11:ColumnTo[A11]
+
+ val p12:ColumnTo[A12]
+
+ val p13:ColumnTo[A13]
+
+ def apply(a1:A1, a2:A2, a3:A3, a4:A4, a5:A5, a6:A6, a7:A7, a8:A8, a9:A9, a10:A10, a11:A11, a12:A12, a13:A13 ):R
+
+ val containerName:String
+ val columnNames:(String, String, String, String, String, String, String, String, String, String, String, String, String)
+
+ lazy val (name1 ,name2 ,name3 ,name4 ,name5 ,name6 ,name7 ,name8 ,name9 ,name10 ,name11 ,name12 ,name13) = columnNames
+
+ import SqlParser._
+ override def apply(input:Input):SqlParser.ParseResult[R] =
+ (
+ get[A1](name1)(p1) ~<
+ get[A2](name2)(p2) ~<
+ get[A3](name3)(p3) ~<
+ get[A4](name4)(p4) ~<
+ get[A5](name5)(p5) ~<
+ get[A6](name6)(p6) ~<
+ get[A7](name7)(p7) ~<
+ get[A8](name8)(p8) ~<
+ get[A9](name9)(p9) ~<
+ get[A10](name10)(p10) ~<
+ get[A11](name11)(p11) ~<
+ get[A12](name12)(p12) ~<
+ get[A13](name13)(p13) ^^ { case a1 ~ a2 ~ a3 ~ a4 ~ a5 ~ a6 ~ a7 ~ a8 ~ a9 ~ a10 ~ a11 ~ a12 ~ a13 => apply(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13)} )(input)
+
+ val uniqueId : (Row=> MayErr[SqlRequestError,Any]) = null
+ }
+
+ trait M13[ A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, R] {
+ self: MParser13[ A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13,R] =>
+
+ val pt1:(ColumnTo[A1],ToStatement[A1])
+ val pt2:(ColumnTo[A2],ToStatement[A2])
+ val pt3:(ColumnTo[A3],ToStatement[A3])
+ val pt4:(ColumnTo[A4],ToStatement[A4])
+ val pt5:(ColumnTo[A5],ToStatement[A5])
+ val pt6:(ColumnTo[A6],ToStatement[A6])
+ val pt7:(ColumnTo[A7],ToStatement[A7])
+ val pt8:(ColumnTo[A8],ToStatement[A8])
+ val pt9:(ColumnTo[A9],ToStatement[A9])
+ val pt10:(ColumnTo[A10],ToStatement[A10])
+ val pt11:(ColumnTo[A11],ToStatement[A11])
+ val pt12:(ColumnTo[A12],ToStatement[A12])
+ val pt13:(ColumnTo[A13],ToStatement[A13])
+
+ def unapply(r:R):Option[( A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13)]
+ def unqualify(columnName:String) = columnName.split('.').last
+
+ def update(v:R)(implicit hasId: (A1 <:< Pk[_])|:|(A2 <:< Pk[_])|:|(A3 <:< Pk[_])|:|(A4 <:< Pk[_])|:|(A5 <:< Pk[_])|:|(A6 <:< Pk[_])|:|(A7 <:< Pk[_])|:|(A8 <:< Pk[_])|:|(A9 <:< Pk[_])|:|(A10 <:< Pk[_])|:|(A11 <:< Pk[_])|:|(A12 <:< Pk[_])|:|(A13 <:< Pk[_]) ) = {
+
+ val all = ((v,hasId) match {
+ case (self( a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13), ( e1 |:| e2 |:| e3 |:| e4 |:| e5 |:| e6 |:| e7 |:| e8 |:| e9 |:| e10 |:| e11 |:| e12 |:| e13)) =>
+ List (
+ (e1, unqualify(name1), toParameterValue(a1)(pt1._2)),
+ (e2, unqualify(name2), toParameterValue(a2)(pt2._2)),
+ (e3, unqualify(name3), toParameterValue(a3)(pt3._2)),
+ (e4, unqualify(name4), toParameterValue(a4)(pt4._2)),
+ (e5, unqualify(name5), toParameterValue(a5)(pt5._2)),
+ (e6, unqualify(name6), toParameterValue(a6)(pt6._2)),
+ (e7, unqualify(name7), toParameterValue(a7)(pt7._2)),
+ (e8, unqualify(name8), toParameterValue(a8)(pt8._2)),
+ (e9, unqualify(name9), toParameterValue(a9)(pt9._2)),
+ (e10, unqualify(name10), toParameterValue(a10)(pt10._2)),
+ (e11, unqualify(name11), toParameterValue(a11)(pt11._2)),
+ (e12, unqualify(name12), toParameterValue(a12)(pt12._2)),
+ (e13, unqualify(name13), toParameterValue(a13)(pt13._2)))
+ })
+
+ val (ids,toSet) = all.partition(_._1.isDefined)
+ if(ids == all) throw new Exception("everything is a Pk, nothing left to set!")
+
+ val toUpdate = toSet.map(_._2).map(n => n+" = "+"{"+n+"}").mkString(", ")
+
+ import Sql._
+
+ sql("update "+containerName +" set "+toUpdate+
+ " where "+ ids.map(_._2).map( n => n+" = "+"{"+n+"}").mkString(" and ") )
+ .on(all.map(v => (v._2,v._3)): _* )
+ .executeUpdate()
+
+ }
+
+ def create(v:R)(implicit hasId: (A1 <:< Pk[_])|:|(A2 <:< Pk[_])|:|(A3 <:< Pk[_])|:|(A4 <:< Pk[_])|:|(A5 <:< Pk[_])|:|(A6 <:< Pk[_])|:|(A7 <:< Pk[_])|:|(A8 <:< Pk[_])|:|(A9 <:< Pk[_])|:|(A10 <:< Pk[_])|:|(A11 <:< Pk[_])|:|(A12 <:< Pk[_])|:|(A13 <:< Pk[_]) ) :R = {
+
+ val all = ((v,hasId) match {
+ case (self( a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13), ( e1 |:| e2 |:| e3 |:| e4 |:| e5 |:| e6 |:| e7 |:| e8 |:| e9 |:| e10 |:| e11 |:| e12 |:| e13)) =>
+ List (
+ (e1, unqualify(name1), toParameterValue(a1)(pt1._2)),
+ (e2, unqualify(name2), toParameterValue(a2)(pt2._2)),
+ (e3, unqualify(name3), toParameterValue(a3)(pt3._2)),
+ (e4, unqualify(name4), toParameterValue(a4)(pt4._2)),
+ (e5, unqualify(name5), toParameterValue(a5)(pt5._2)),
+ (e6, unqualify(name6), toParameterValue(a6)(pt6._2)),
+ (e7, unqualify(name7), toParameterValue(a7)(pt7._2)),
+ (e8, unqualify(name8), toParameterValue(a8)(pt8._2)),
+ (e9, unqualify(name9), toParameterValue(a9)(pt9._2)),
+ (e10, unqualify(name10), toParameterValue(a10)(pt10._2)),
+ (e11, unqualify(name11), toParameterValue(a11)(pt11._2)),
+ (e12, unqualify(name12), toParameterValue(a12)(pt12._2)),
+ (e13, unqualify(name13), toParameterValue(a13)(pt13._2)))
+ })
+
+ val (notSetIds,toSet) = all.partition(i => i._1.isDefined && i._3.aValue==NotAssigned)
+ if(notSetIds.length > 1) throw new Exception("multi ids not supported")
+ val toInsert = toSet.map(_._2)
+
+ import Sql._
+ import scala.util.control.Exception._
+ import SqlParser._
+
+ val idParser:SqlParser.Parser[_] = {
+ SqlParser.RowParser(row =>
+ row.asList.headOption.flatMap(a =>
+ (if (a.isInstanceOf[Option[_]]) a else Option(a)).asInstanceOf[Option[_]]
+ ).toRight(NoColumnsInReturnedResult)
+ )
+ }
+
+ val (statement, ok) = sql("insert into "+containerName+" ( "+toInsert.mkString(", ")+" ) values ( "+toInsert.map("{"+_+"}").mkString(", ")+")")
+ .on(all.map(v => (v._2,v._3)): _* )
+ .execute1(getGeneratedKeys=true)
+
+ val rs = statement.getGeneratedKeys();
+ val id = idParser(StreamReader(Sql.resultSetToStream(rs))).get
+
+ val List( a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13) = all.map(_._3.aValue).map({case NotAssigned => Id(id); case other => other})
+ apply(a1.asInstanceOf[A1], a2.asInstanceOf[A2], a3.asInstanceOf[A3], a4.asInstanceOf[A4], a5.asInstanceOf[A5], a6.asInstanceOf[A6], a7.asInstanceOf[A7], a8.asInstanceOf[A8], a9.asInstanceOf[A9], a10.asInstanceOf[A10], a11.asInstanceOf[A11], a12.asInstanceOf[A12], a13.asInstanceOf[A13])
+
+
+ }
+ }
+
+}
+
+
View
179 src/play/db/anorm/Magic14.scala
@@ -0,0 +1,179 @@
+
+
+
+
+package play.db
+
+import play.utils.Scala.MayErr
+import play.utils.Scala.MayErr._
+
+package anorm {
+
+ trait MParser14[ A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, R] extends ParserWithId[R] {
+
+ val p1:ColumnTo[A1]
+
+ val p2:ColumnTo[A2]
+
+ val p3:ColumnTo[A3]
+
+ val p4:ColumnTo[A4]
+
+ val p5:ColumnTo[A5]
+
+ val p6:ColumnTo[A6]
+
+ val p7:ColumnTo[A7]
+
+ val p8:ColumnTo[A8]
+
+ val p9:ColumnTo[A9]
+
+ val p10:ColumnTo[A10]
+
+ val p11:ColumnTo[A11]
+
+ val p12:ColumnTo[A12]
+
+ val p13:ColumnTo[A13]
+
+ val p14:ColumnTo[A14]
+
+ def apply(a1:A1, a2:A2, a3:A3, a4:A4, a5:A5, a6:A6, a7:A7, a8:A8, a9:A9, a10:A10, a11:A11, a12:A12, a13:A13, a14:A14 ):R
+
+ val containerName:String
+ val columnNames:(String, String, String, String, String, String, String, String, String, String, String, String, String, String)
+
+ lazy val (name1 ,name2 ,name3 ,name4 ,name5 ,name6 ,name7 ,name8 ,name9 ,name10 ,name11 ,name12 ,name13 ,name14) = columnNames
+
+ import SqlParser._
+ override def apply(input:Input):SqlParser.ParseResult[R] =
+ (
+ get[A1](name1)(p1) ~<
+ get[A2](name2)(p2) ~<
+ get[A3](name3)(p3) ~<
+ get[A4](name4)(p4) ~<
+ get[A5](name5)(p5) ~<
+ get[A6](name6)(p6) ~<
+ get[A7](name7)(p7) ~<
+ get[A8](name8)(p8) ~<
+ get[A9](name9)(p9) ~<
+ get[A10](name10)(p10) ~<
+ get[A11](name11)(p11) ~<
+ get[A12](name12)(p12) ~<
+ get[A13](name13)(p13) ~<
+ get[A14](name14)(p14) ^^ { case a1 ~ a2 ~ a3 ~ a4 ~ a5 ~ a6 ~ a7 ~ a8 ~ a9 ~ a10 ~ a11 ~ a12 ~ a13 ~ a14 => apply(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14)} )(input)
+
+ val uniqueId : (Row=> MayErr[SqlRequestError,Any]) = null
+ }
+
+ trait M14[ A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, R] {
+ self: MParser14[ A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14,R] =>
+
+ val pt1:(ColumnTo[A1],ToStatement[A1])
+ val pt2:(ColumnTo[A2],ToStatement[A2])
+ val pt3:(ColumnTo[A3],ToStatement[A3])
+ val pt4:(ColumnTo[A4],ToStatement[A4])
+ val pt5:(ColumnTo[A5],ToStatement[A5])
+ val pt6:(ColumnTo[A6],ToStatement[A6])
+ val pt7:(ColumnTo[A7],ToStatement[A7])
+ val pt8:(ColumnTo[A8],ToStatement[A8])
+ val pt9:(ColumnTo[A9],ToStatement[A9])
+ val pt10:(ColumnTo[A10],ToStatement[A10])
+ val pt11:(ColumnTo[A11],ToStatement[A11])
+ val pt12:(ColumnTo[A12],ToStatement[A12])
+ val pt13:(ColumnTo[A13],ToStatement[A13])
+ val pt14:(ColumnTo[A14],ToStatement[A14])
+
+ def unapply(r:R):Option[( A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14)]
+ def unqualify(columnName:String) = columnName.split('.').last
+
+ def update(v:R)(implicit hasId: (A1 <:< Pk[_])|:|(A2 <:< Pk[_])|:|(A3 <:< Pk[_])|:|(A4 <:< Pk[_])|:|(A5 <:< Pk[_])|:|(A6 <:< Pk[_])|:|(A7 <:< Pk[_])|:|(A8 <:< Pk[_])|:|(A9 <:< Pk[_])|:|(A10 <:< Pk[_])|:|(A11 <:< Pk[_])|:|(A12 <:< Pk[_])|:|(A13 <:< Pk[_])|:|(A14 <:< Pk[_]) ) = {
+
+ val all = ((v,hasId) match {
+ case (self( a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14), ( e1 |:| e2 |:| e3 |:| e4 |:| e5 |:| e6 |:| e7 |:| e8 |:| e9 |:| e10 |:| e11 |:| e12 |:| e13 |:| e14)) =>
+ List (
+ (e1, unqualify(name1), toParameterValue(a1)(pt1._2)),
+ (e2, unqualify(name2), toParameterValue(a2)(pt2._2)),
+ (e3, unqualify(name3), toParameterValue(a3)(pt3._2)),
+ (e4, unqualify(name4), toParameterValue(a4)(pt4._2)),
+ (e5, unqualify(name5), toParameterValue(a5)(pt5._2)),
+ (e6, unqualify(name6), toParameterValue(a6)(pt6._2)),
+ (e7, unqualify(name7), toParameterValue(a7)(pt7._2)),
+ (e8, unqualify(name8), toParameterValue(a8)(pt8._2)),
+ (e9, unqualify(name9), toParameterValue(a9)(pt9._2)),
+ (e10, unqualify(name10), toParameterValue(a10)(pt10._2)),
+ (e11, unqualify(name11), toParameterValue(a11)(pt11._2)),
+ (e12, unqualify(name12), toParameterValue(a12)(pt12._2)),
+ (e13, unqualify(name13), toParameterValue(a13)(pt13._2)),
+ (e14, unqualify(name14), toParameterValue(a14)(pt14._2)))
+ })
+
+ val (ids,toSet) = all.partition(_._1.isDefined)
+ if(ids == all) throw new Exception("everything is a Pk, nothing left to set!")
+
+ val toUpdate = toSet.map(_._2).map(n => n+" = "+"{"+n+"}").mkString(", ")
+
+ import Sql._
+
+ sql("update "+containerName +" set "+toUpdate+
+ " where "+ ids.map(_._2).map( n => n+" = "+"{"+n+"}").mkString(" and ") )
+ .on(all.map(v => (v._2,v._3)): _* )
+ .executeUpdate()
+
+ }
+
+ def create(v:R)(implicit hasId: (A1 <:< Pk[_])|:|(A2 <:< Pk[_])|:|(A3 <:< Pk[_])|:|(A4 <:< Pk[_])|:|(A5 <:< Pk[_])|:|(A6 <:< Pk[_])|:|(A7 <:< Pk[_])|:|(A8 <:< Pk[_])|:|(A9 <:< Pk[_])|:|(A10 <:< Pk[_])|:|(A11 <:< Pk[_])|:|(A12 <:< Pk[_])|:|(A13 <:< Pk[_])|:|(A14 <:< Pk[_]) ) :R = {
+
+ val all = ((v,hasId) match {
+ case (self( a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14), ( e1 |:| e2 |:| e3 |:| e4 |:| e5 |:| e6 |:| e7 |:| e8 |:| e9 |:| e10 |:| e11 |:| e12 |:| e13 |:| e14)) =>
+ List (
+ (e1, unqualify(name1), toParameterValue(a1)(pt1._2)),
+ (e2, unqualify(name2), toParameterValue(a2)(pt2._2)),
+ (e3, unqualify(name3), toParameterValue(a3)(pt3._2)),
+ (e4, unqualify(name4), toParameterValue(a4)(pt4._2)),
+ (e5, unqualify(name5), toParameterValue(a5)(pt5._2)),
+ (e6, unqualify(name6), toParameterValue(a6)(pt6._2)),
+ (e7, unqualify(name7), toParameterValue(a7)(pt7._2)),
+ (e8, unqualify(name8), toParameterValue(a8)(pt8._2)),
+ (e9, unqualify(name9), toParameterValue(a9)(pt9._2)),
+ (e10, unqualify(name10), toParameterValue(a10)(pt10._2)),
+ (e11, unqualify(name11), toParameterValue(a11)(pt11._2)),
+ (e12, unqualify(name12), toParameterValue(a12)(pt12._2)),
+ (e13, unqualify(name13), toParameterValue(a13)(pt13._2)),
+ (e14, unqualify(name14), toParameterValue(a14)(pt14._2)))
+ })
+
+ val (notSetIds,toSet) = all.partition(i => i._1.isDefined && i._3.aValue==NotAssigned)
+ if(notSetIds.length > 1) throw new Exception("multi ids not supported")
+ val toInsert = toSet.map(_._2)
+
+ import Sql._
+ import scala.util.control.Exception._
+ import SqlParser._
+
+ val idParser:SqlParser.Parser[_] = {
+ SqlParser.RowParser(row =>
+ row.asList.headOption.flatMap(a =>
+ (if (a.isInstanceOf[Option[_]]) a else Option(a)).asInstanceOf[Option[_]]
+ ).toRight(NoColumnsInReturnedResult)
+ )
+ }
+
+ val (statement, ok) = sql("insert into "+containerName+" ( "+toInsert.mkString(", ")+" ) values ( "+toInsert.map("{"+_+"}").mkString(", ")+")")
+ .on(all.map(v => (v._2,v._3)): _* )
+ .execute1(getGeneratedKeys=true)
+
+ val rs = statement.getGeneratedKeys();
+ val id = idParser(StreamReader(Sql.resultSetToStream(rs))).get
+
+ val List( a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14) = all.map(_._3.aValue).map({case NotAssigned => Id(id); case other => other})
+ apply(a1.asInstanceOf[A1], a2.asInstanceOf[A2], a3.asInstanceOf[A3], a4.asInstanceOf[A4], a5.asInstanceOf[A5], a6.asInstanceOf[A6], a7.asInstanceOf[A7], a8.asInstanceOf[A8], a9.asInstanceOf[A9], a10.asInstanceOf[A10], a11.asInstanceOf[A11], a12.asInstanceOf[A12], a13.asInstanceOf[A13], a14.asInstanceOf[A14])
+
+
+ }
+ }
+
+}
+
+
View
185 src/play/db/anorm/Magic15.scala
@@ -0,0 +1,185 @@
+
+
+
+
+package play.db
+
+import play.utils.Scala.MayErr
+import play.utils.Scala.MayErr._
+
+package anorm {
+
+ trait MParser15[ A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, R] extends ParserWithId[R] {
+
+ val p1:ColumnTo[A1]
+
+ val p2:ColumnTo[A2]
+
+ val p3:ColumnTo[A3]
+
+ val p4:ColumnTo[A4]
+
+ val p5:ColumnTo[A5]
+
+ val p6:ColumnTo[A6]
+
+ val p7:ColumnTo[A7]
+
+ val p8:ColumnTo[A8]
+
+ val p9:ColumnTo[A9]
+
+ val p10:ColumnTo[A10]
+
+ val p11:ColumnTo[A11]
+
+ val p12:ColumnTo[A12]
+
+ val p13:ColumnTo[A13]
+
+ val p14:ColumnTo[A14]
+
+ val p15:ColumnTo[A15]
+
+ def apply(a1:A1, a2:A2, a3:A3, a4:A4, a5:A5, a6:A6, a7:A7, a8:A8, a9:A9, a10:A10, a11:A11, a12:A12, a13:A13, a14:A14, a15:A15 ):R
+
+ val containerName:String
+ val columnNames:(String, String, String, String, String, String, String, String, String, String, String, String, String, String, String)
+
+ lazy val (name1 ,name2 ,name3 ,name4 ,name5 ,name6 ,name7 ,name8 ,name9 ,name10 ,name11 ,name12 ,name13 ,name14 ,name15) = columnNames
+
+ import SqlParser._
+ override def apply(input:Input):SqlParser.ParseResult[R] =
+ (
+ get[A1](name1)(p1) ~<
+ get[A2](name2)(p2) ~<
+ get[A3](name3)(p3) ~<
+ get[A4](name4)(p4) ~<
+ get[A5](name5)(p5) ~<
+ get[A6](name6)(p6) ~<
+ get[A7](name7)(p7) ~<
+ get[A8](name8)(p8) ~<
+ get[A9](name9)(p9) ~<
+ get[A10](name10)(p10) ~<
+ get[A11](name11)(p11) ~<
+ get[A12](name12)(p12) ~<
+ get[A13](name13)(p13) ~<
+ get[A14](name14)(p14) ~<
+ get[A15](name15)(p15) ^^ { case a1 ~ a2 ~ a3 ~ a4 ~ a5 ~ a6 ~ a7 ~ a8 ~ a9 ~ a10 ~ a11 ~ a12 ~ a13 ~ a14 ~ a15 => apply(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15)} )(input)
+
+ val uniqueId : (Row=> MayErr[SqlRequestError,Any]) = null
+ }
+
+ trait M15[ A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, R] {
+ self: MParser15[ A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15,R] =>
+
+ val pt1:(ColumnTo[A1],ToStatement[A1])
+ val pt2:(ColumnTo[A2],ToStatement[A2])
+ val pt3:(ColumnTo[A3],ToStatement[A3])
+ val pt4:(ColumnTo[A4],ToStatement[A4])
+ val pt5:(ColumnTo[A5],ToStatement[A5])
+ val pt6:(ColumnTo[A6],ToStatement[A6])
+ val pt7:(ColumnTo[A7],ToStatement[A7])
+ val pt8:(ColumnTo[A8],ToStatement[A8])
+ val pt9:(ColumnTo[A9],ToStatement[A9])
+ val pt10:(ColumnTo[A10],ToStatement[A10])
+ val pt11:(ColumnTo[A11],ToStatement[A11])
+ val pt12:(ColumnTo[A12],ToStatement[A12])
+ val pt13:(ColumnTo[A13],ToStatement[A13])
+ val pt14:(ColumnTo[A14],ToStatement[A14])
+ val pt15:(ColumnTo[A15],ToStatement[A15])
+
+ def unapply(r:R):Option[( A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15)]
+ def unqualify(columnName:String) = columnName.split('.').last
+
+ def update(v:R)(implicit hasId: (A1 <:< Pk[_])|:|(A2 <:< Pk[_])|:|(A3 <:< Pk[_])|:|(A4 <:< Pk[_])|:|(A5 <:< Pk[_])|:|(A6 <:< Pk[_])|:|(A7 <:< Pk[_])|:|(A8 <:< Pk[_])|:|(A9 <:< Pk[_])|:|(A10 <:< Pk[_])|:|(A11 <:< Pk[_])|:|(A12 <:< Pk[_])|:|(A13 <:< Pk[_])|:|(A14 <:< Pk[_])|:|(A15 <:< Pk[_]) ) = {
+
+ val all = ((v,hasId) match {
+ case (self( a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15), ( e1 |:| e2 |:| e3 |:| e4 |:| e5 |:| e6 |:| e7 |:| e8 |:| e9 |:| e10 |:| e11 |:| e12 |:| e13 |:| e14 |:| e15)) =>
+ List (
+ (e1, unqualify(name1), toParameterValue(a1)(pt1._2)),
+ (e2, unqualify(name2), toParameterValue(a2)(pt2._2)),
+ (e3, unqualify(name3), toParameterValue(a3)(pt3._2)),
+ (e4, unqualify(name4), toParameterValue(a4)(pt4._2)),
+ (e5, unqualify(name5), toParameterValue(a5)(pt5._2)),
+ (e6, unqualify(name6), toParameterValue(a6)(pt6._2)),
+ (e7, unqualify(name7), toParameterValue(a7)(pt7._2)),
+ (e8, unqualify(name8), toParameterValue(a8)(pt8._2)),
+ (e9, unqualify(name9), toParameterValue(a9)(pt9._2)),
+ (e10, unqualify(name10), toParameterValue(a10)(pt10._2)),
+ (e11, unqualify(name11), toParameterValue(a11)(pt11._2)),
+ (e12, unqualify(name12), toParameterValue(a12)(pt12._2)),
+ (e13, unqualify(name13), toParameterValue(a13)(pt13._2)),
+ (e14, unqualify(name14), toParameterValue(a14)(pt14._2)),
+ (e15, unqualify(name15), toParameterValue(a15)(pt15._2)))
+ })
+
+ val (ids,toSet) = all.partition(_._1.isDefined)
+ if(ids == all) throw new Exception("everything is a Pk, nothing left to set!")
+
+ val toUpdate = toSet.map(_._2).map(n => n+" = "+"{"+n+"}").mkString(", ")
+
+ import Sql._
+
+ sql("update "+containerName +" set "+toUpdate+
+ " where "+ ids.map(_._2).map( n => n+" = "+"{"+n+"}").mkString(" and ") )
+ .on(all.map(v => (v._2,v._3)): _* )
+ .executeUpdate()
+
+ }
+
+ def create(v:R)(implicit hasId: (A1 <:< Pk[_])|:|(A2 <:< Pk[_])|:|(A3 <:< Pk[_])|:|(A4 <:< Pk[_])|:|(A5 <:< Pk[_])|:|(A6 <:< Pk[_])|:|(A7 <:< Pk[_])|:|(A8 <:< Pk[_])|:|(A9 <:< Pk[_])|:|(A10 <:< Pk[_])|:|(A11 <:< Pk[_])|:|(A12 <:< Pk[_])|:|(A13 <:< Pk[_])|:|(A14 <:< Pk[_])|:|(A15 <:< Pk[_]) ) :R = {
+
+ val all = ((v,hasId) match {
+ case (self( a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15), ( e1 |:| e2 |:| e3 |:| e4 |:| e5 |:| e6 |:| e7 |:| e8 |:| e9 |:| e10 |:| e11 |:| e12 |:| e13 |:| e14 |:| e15)) =>
+ List (
+ (e1, unqualify(name1), toParameterValue(a1)(pt1._2)),
+ (e2, unqualify(name2), toParameterValue(a2)(pt2._2)),
+ (e3, unqualify(name3), toParameterValue(a3)(pt3._2)),
+ (e4, unqualify(name4), toParameterValue(a4)(pt4._2)),
+ (e5, unqualify(name5), toParameterValue(a5)(pt5._2)),
+ (e6, unqualify(name6), toParameterValue(a6)(pt6._2)),
+ (e7, unqualify(name7), toParameterValue(a7)(pt7._2)),
+ (e8, unqualify(name8), toParameterValue(a8)(pt8._2)),
+ (e9, unqualify(name9), toParameterValue(a9)(pt9._2)),
+ (e10, unqualify(name10), toParameterValue(a10)(pt10._2)),
+ (e11, unqualify(name11), toParameterValue(a11)(pt11._2)),
+ (e12, unqualify(name12), toParameterValue(a12)(pt12._2)),
+ (e13, unqualify(name13), toParameterValue(a13)(pt13._2)),
+ (e14, unqualify(name14), toParameterValue(a14)(pt14._2)),
+ (e15, unqualify(name15), toParameterValue(a15)(pt15._2)))
+ })
+
+ val (notSetIds,toSet) = all.partition(i => i._1.isDefined && i._3.aValue==NotAssigned)
+ if(notSetIds.length > 1) throw new Exception("multi ids not supported")
+ val toInsert = toSet.map(_._2)
+
+ import Sql._
+ import scala.util.control.Exception._
+ import SqlParser._
+
+ val idParser:SqlParser.Parser[_] = {
+ SqlParser.RowParser(row =>
+ row.asList.headOption.flatMap(a =>
+ (if (a.isInstanceOf[Option[_]]) a else Option(a)).asInstanceOf[Option[_]]
+ ).toRight(NoColumnsInReturnedResult)
+ )
+ }
+
+ val (statement, ok) = sql("insert into "+containerName+" ( "+toInsert.mkString(", ")+" ) values ( "+toInsert.map("{"+_+"}").mkString(", ")+")")
+ .on(all.map(v => (v._2,v._3)): _* )
+ .execute1(getGeneratedKeys=true)
+
+ val rs = statement.getGeneratedKeys();
+ val id = idParser(StreamReader(Sql.resultSetToStream(rs))).get
+
+ val List( a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15) = all.map(_._3.aValue).map({case NotAssigned => Id(id); case other => other})
+ apply(a1.asInstanceOf[A1], a2.asInstanceOf[A2], a3.asInstanceOf[A3], a4.asInstanceOf[A4], a5.asInstanceOf[A5], a6.asInstanceOf[A6], a7.asInstanceOf[A7], a8.asInstanceOf[A8], a9.asInstanceOf[A9], a10.asInstanceOf[A10], a11.asInstanceOf[A11], a12.asInstanceOf[A12], a13.asInstanceOf[A13], a14.asInstanceOf[A14], a15.asInstanceOf[A15])
+
+
+ }
+ }
+
+}
+
+
View
191 src/play/db/anorm/Magic16.scala
@@ -0,0 +1,191 @@
+
+
+
+
+package play.db
+
+import play.utils.Scala.MayErr
+import play.utils.Scala.MayErr._
+
+package anorm {
+
+ trait MParser16[ A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, R] extends ParserWithId[R] {
+
+ val p1:ColumnTo[A1]
+
+ val p2:ColumnTo[A2]
+
+ val p3:ColumnTo[A3]
+
+ val p4:ColumnTo[A4]
+
+ val p5:ColumnTo[A5]
+
+ val p6:ColumnTo[A6]
+
+ val p7:ColumnTo[A7]
+
+ val p8:ColumnTo[A8]
+
+ val p9:ColumnTo[A9]
+
+ val p10:ColumnTo[A10]
+
+ val p11:ColumnTo[A11]
+
+ val p12:ColumnTo[A12]
+
+ val p13:ColumnTo[A13]
+
+ val p14:ColumnTo[A14]
+
+ val p15:ColumnTo[A15]
+
+ val p16:ColumnTo[A16]
+
+ def apply(a1:A1, a2:A2, a3:A3, a4:A4, a5:A5, a6:A6, a7:A7, a8:A8, a9:A9, a10:A10, a11:A11, a12:A12, a13:A13, a14:A14, a15:A15, a16:A16 ):R
+
+ val containerName:String
+ val columnNames:(String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String)
+
+ lazy val (name1 ,name2 ,name3 ,name4 ,name5 ,name6 ,name7 ,name8 ,name9 ,name10 ,name11 ,name12 ,name13 ,name14 ,name15 ,name16) = columnNames
+
+ import SqlParser._
+ override def apply(input:Input):SqlParser.ParseResult[R] =
+ (
+ get[A1](name1)(p1) ~<
+ get[A2](name2)(p2) ~<
+ get[A3](name3)(p3) ~<
+ get[A4](name4)(p4) ~<
+ get[A5](name5)(p5) ~<
+ get[A6](name6)(p6) ~<
+ get[A7](name7)(p7) ~<
+ get[A8](name8)(p8) ~<
+ get[A9](name9)(p9) ~<
+ get[A10](name10)(p10) ~<
+ get[A11](name11)(p11) ~<
+ get[A12](name12)(p12) ~<
+ get[A13](name13)(p13) ~<
+ get[A14](name14)(p14) ~<
+ get[A15](name15)(p15) ~<
+ get[A16](name16)(p16) ^^ { case a1 ~ a2 ~ a3 ~ a4 ~ a5 ~ a6 ~ a7 ~ a8 ~ a9 ~ a10 ~ a11 ~ a12 ~ a13 ~ a14 ~ a15 ~ a16 => apply(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16)} )(input)
+
+ val uniqueId : (Row=> MayErr[SqlRequestError,Any]) = null
+ }
+
+ trait M16[ A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, R] {
+ self: MParser16[ A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16,R] =>
+
+ val pt1:(ColumnTo[A1],ToStatement[A1])
+ val pt2:(ColumnTo[A2],ToStatement[A2])
+ val pt3:(ColumnTo[A3],ToStatement[A3])
+ val pt4:(ColumnTo[A4],ToStatement[A4])
+ val pt5:(ColumnTo[A5],ToStatement[A5])
+ val pt6:(ColumnTo[A6],ToStatement[A6])
+ val pt7:(ColumnTo[A7],ToStatement[A7])
+ val pt8:(ColumnTo[A8],ToStatement[A8])
+ val pt9:(ColumnTo[A9],ToStatement[A9])
+ val pt10:(ColumnTo[A10],ToStatement[A10])
+ val pt11:(ColumnTo[A11],ToStatement[A11])
+ val pt12:(ColumnTo[A12],ToStatement[A12])
+ val pt13:(ColumnTo[A13],ToStatement[A13])
+ val pt14:(ColumnTo[A14],ToStatement[A14])
+ val pt15:(ColumnTo[A15],ToStatement[A15])
+ val pt16:(ColumnTo[A16],ToStatement[A16])
+
+ def unapply(r:R):Option[( A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16)]
+ def unqualify(columnName:String) = columnName.split('.').last
+
+ def update(v:R)(implicit hasId: (A1 <:< Pk[_])|:|(A2 <:< Pk[_])|:|(A3 <:< Pk[_])|:|(A4 <:< Pk[_])|:|(A5 <:< Pk[_])|:|(A6 <:< Pk[_])|:|(A7 <:< Pk[_])|:|(A8 <:< Pk[_])|:|(A9 <:< Pk[_])|:|(A10 <:< Pk[_])|:|(A11 <:< Pk[_])|:|(A12 <:< Pk[_])|:|(A13 <:< Pk[_])|:|(A14 <:< Pk[_])|:|(A15 <:< Pk[_])|:|(A16 <:< Pk[_]) ) = {
+
+ val all = ((v,hasId) match {
+ case (self( a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16), ( e1 |:| e2 |:| e3 |:| e4 |:| e5 |:| e6 |:| e7 |:| e8 |:| e9 |:| e10 |:| e11 |:| e12 |:| e13 |:| e14 |:| e15 |:| e16)) =>
+ List (
+ (e1, unqualify(name1), toParameterValue(a1)(pt1._2)),
+ (e2, unqualify(name2), toParameterValue(a2)(pt2._2)),
+ (e3, unqualify(name3), toParameterValue(a3)(pt3._2)),
+ (e4, unqualify(name4), toParameterValue(a4)(pt4._2)),
+ (e5, unqualify(name5), toParameterValue(a5)(pt5._2)),
+ (e6, unqualify(name6), toParameterValue(a6)(pt6._2)),
+ (e7, unqualify(name7), toParameterValue(a7)(pt7._2)),
+ (e8, unqualify(name8), toParameterValue(a8)(pt8._2)),
+ (e9, unqualify(name9), toParameterValue(a9)(pt9._2)),
+ (e10, unqualify(name10), toParameterValue(a10)(pt10._2)),
+ (e11, unqualify(name11), toParameterValue(a11)(pt11._2)),
+ (e12, unqualify(name12), toParameterValue(a12)(pt12._2)),
+ (e13, unqualify(name13), toParameterValue(a13)(pt13._2)),
+ (e14, unqualify(name14), toParameterValue(a14)(pt14._2)),
+ (e15, unqualify(name15), toParameterValue(a15)(pt15._2)),
+ (e16, unqualify(name16), toParameterValue(a16)(pt16._2)))
+ })
+
+ val (ids,toSet) = all.partition(_._1.isDefined)
+ if(ids == all) throw new Exception("everything is a Pk, nothing left to set!")
+
+ val toUpdate = toSet.map(_._2).map(n => n+" = "+"{"+n+"}").mkString(", ")
+
+ import Sql._
+
+ sql("update "+containerName +" set "+toUpdate+
+ " where "+ ids.map(_._2).map( n => n+" = "+"{"+n+"}").mkString(" and ") )
+ .on(all.map(v => (v._2,v._3)): _* )
+ .executeUpdate()
+
+ }
+
+ def create(v:R)(implicit hasId: (A1 <:< Pk[_])|:|(A2 <:< Pk[_])|:|(A3 <:< Pk[_])|:|(A4 <:< Pk[_])|:|(A5 <:< Pk[_])|:|(A6 <:< Pk[_])|:|(A7 <:< Pk[_])|:|(A8 <:< Pk[_])|:|(A9 <:< Pk[_])|:|(A10 <:< Pk[_])|:|(A11 <:< Pk[_])|:|(A12 <:< Pk[_])|:|(A13 <:< Pk[_])|:|(A14 <:< Pk[_])|:|(A15 <:< Pk[_])|:|(A16 <:< Pk[_]) ) :R = {
+
+ val all = ((v,hasId) match {
+ case (self( a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16), ( e1 |:| e2 |:| e3 |:| e4 |:| e5 |:| e6 |:| e7 |:| e8 |:| e9 |:| e10 |:| e11 |:| e12 |:| e13 |:| e14 |:| e15 |:| e16)) =>
+ List (
+ (e1, unqualify(name1), toParameterValue(a1)(pt1._2)),
+ (e2, unqualify(name2), toParameterValue(a2)(pt2._2)),
+ (e3, unqualify(name3), toParameterValue(a3)(pt3._2)),
+ (e4, unqualify(name4), toParameterValue(a4)(pt4._2)),
+ (e5, unqualify(name5), toParameterValue(a5)(pt5._2)),
+ (e6, unqualify(name6), toParameterValue(a6)(pt6._2)),
+ (e7, unqualify(name7), toParameterValue(a7)(pt7._2)),
+ (e8, unqualify(name8), toParameterValue(a8)(pt8._2)),
+ (e9, unqualify(name9), toParameterValue(a9)(pt9._2)),
+ (e10, unqualify(name10), toParameterValue(a10)(pt10._2)),
+ (e11, unqualify(name11), toParameterValue(a11)(pt11._2)),
+ (e12, unqualify(name12), toParameterValue(a12)(pt12._2)),
+ (e13, unqualify(name13), toParameterValue(a13)(pt13._2)),
+ (e14, unqualify(name14), toParameterValue(a14)(pt14._2)),
+ (e15, unqualify(name15), toParameterValue(a15)(pt15._2)),
+ (e16, unqualify(name16), toParameterValue(a16)(pt16._2)))
+ })
+
+ val (notSetIds,toSet) = all.partition(i => i._1.isDefined && i._3.aValue==NotAssigned)
+ if(notSetIds.length > 1) throw new Exception("multi ids not supported")
+ val toInsert = toSet.map(_._2)
+
+ import Sql._
+ import scala.util.control.Exception._
+ import SqlParser._
+
+ val idParser:SqlParser.Parser[_] = {
+ SqlParser.RowParser(row =>
+ row.asList.headOption.flatMap(a =>
+ (if (a.isInstanceOf[Option[_]]) a else Option(a)).asInstanceOf[Option[_]]
+ ).toRight(NoColumnsInReturnedResult)
+ )
+ }
+
+ val (statement, ok) = sql("insert into "+containerName+" ( "+toInsert.mkString(", ")+" ) values ( "+toInsert.map("{"+_+"}").mkString(", ")+")")
+ .on(all.map(v => (v._2,v._3)): _* )
+ .execute1(getGeneratedKeys=true)
+
+ val rs = statement.getGeneratedKeys();
+ val id = idParser(StreamReader(Sql.resultSetToStream(rs))).get
+
+ val List( a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16) = all.map(_._3.aValue).map({case NotAssigned => Id(id); case other => other})
+ apply(a1.asInstanceOf[A1], a2.asInstanceOf[A2], a3.asInstanceOf[A3], a4.asInstanceOf[A4], a5.asInstanceOf[A5], a6.asInstanceOf[A6], a7.asInstanceOf[A7], a8.asInstanceOf[A8], a9.asInstanceOf[A9], a10.asInstanceOf[A10], a11.asInstanceOf[A11], a12.asInstanceOf[A12], a13.asInstanceOf[A13], a14.asInstanceOf[A14], a15.asInstanceOf[A15], a16.asInstanceOf[A16])
+
+
+ }
+ }
+
+}
+
+
View
197 src/play/db/anorm/Magic17.scala
@@ -0,0 +1,197 @@
+
+
+
+
+package play.db
+
+import play.utils.Scala.MayErr
+import play.utils.Scala.MayErr._
+
+package anorm {
+
+ trait MParser17[ A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, R] extends ParserWithId[R] {
+
+ val p1:ColumnTo[A1]
+
+ val p2:ColumnTo[A2]
+
+ val p3:ColumnTo[A3]
+
+ val p4:ColumnTo[A4]
+
+ val p5:ColumnTo[A5]
+
+ val p6:ColumnTo[A6]
+
+ val p7:ColumnTo[A7]
+
+ val p8:ColumnTo[A8]
+
+ val p9:ColumnTo[A9]
+
+ val p10:ColumnTo[A10]
+
+ val p11:ColumnTo[A11]
+
+ val p12:ColumnTo[A12]
+
+ val p13:ColumnTo[A13]
+
+ val p14:ColumnTo[A14]
+
+ val p15:ColumnTo[A15]
+
+ val p16:ColumnTo[A16]
+
+ val p17:ColumnTo[A17]
+
+ def apply(a1:A1, a2:A2, a3:A3, a4:A4, a5:A5, a6:A6, a7:A7, a8:A8, a9:A9, a10:A10, a11:A11, a12:A12, a13:A13, a14:A14, a15:A15, a16:A16, a17:A17 ):R
+
+ val containerName:String
+ val columnNames:(String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String)
+
+ lazy val (name1 ,name2 ,name3 ,name4 ,name5 ,name6 ,name7 ,name8 ,name9 ,name10 ,name11 ,name12 ,name13 ,name14 ,name15 ,name16 ,name17) = columnNames
+
+ import SqlParser._
+ override def apply(input:Input):SqlParser.ParseResult[R] =
+ (
+ get[A1](name1)(p1) ~<
+ get[A2](name2)(p2) ~<
+ get[A3](name3)(p3) ~<
+ get[A4](name4)(p4) ~<
+ get[A5](name5)(p5) ~<
+ get[A6](name6)(p6) ~<
+ get[A7](name7)(p7) ~<
+ get[A8](name8)(p8) ~<
+ get[A9](name9)(p9) ~<
+ get[A10](name10)(p10) ~<
+ get[A11](name11)(p11) ~<
+ get[A12](name12)(p12) ~<
+ get[A13](name13)(p13) ~<
+ get[A14](name14)(p14) ~<
+ get[A15](name15)(p15) ~<
+ get[A16](name16)(p16) ~<
+ get[A17](name17)(p17) ^^ { case a1 ~ a2 ~ a3 ~ a4 ~ a5 ~ a6 ~ a7 ~ a8 ~ a9 ~ a10 ~ a11 ~ a12 ~ a13 ~ a14 ~ a15 ~ a16 ~ a17 => apply(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17)} )(input)
+
+ val uniqueId : (Row=> MayErr[SqlRequestError,Any]) = null
+ }
+
+ trait M17[ A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, R] {
+ self: MParser17[ A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17,R] =>
+
+ val pt1:(ColumnTo[A1],ToStatement[A1])
+ val pt2:(ColumnTo[A2],ToStatement[A2])
+ val pt3:(ColumnTo[A3],ToStatement[A3])
+ val pt4:(ColumnTo[A4],ToStatement[A4])
+ val pt5:(ColumnTo[A5],ToStatement[A5])
+ val pt6:(ColumnTo[A6],ToStatement[A6])
+ val pt7:(ColumnTo[A7],ToStatement[A7])
+ val pt8:(ColumnTo[A8],ToStatement[A8])
+ val pt9:(ColumnTo[A9],ToStatement[A9])
+ val pt10:(ColumnTo[A10],ToStatement[A10])
+ val pt11:(ColumnTo[A11],ToStatement[A11])
+ val pt12:(ColumnTo[A12],ToStatement[A12])
+ val pt13:(ColumnTo[A13],ToStatement[A13])
+ val pt14:(ColumnTo[A14],ToStatement[A14])
+ val pt15:(ColumnTo[A15],ToStatement[A15])
+ val pt16:(ColumnTo[A16],ToStatement[A16])
+ val pt17:(ColumnTo[A17],ToStatement[A17])
+
+ def unapply(r:R):Option[( A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17)]
+ def unqualify(columnName:String) = columnName.split('.').last
+
+ def update(v:R)(implicit hasId: (A1 <:< Pk[_])|:|(A2 <:< Pk[_])|:|(A3 <:< Pk[_])|:|(A4 <:< Pk[_])|:|(A5 <:< Pk[_])|:|(A6 <:< Pk[_])|:|(A7 <:< Pk[_])|:|(A8 <:< Pk[_])|:|(A9 <:< Pk[_])|:|(A10 <:< Pk[_])|:|(A11 <:< Pk[_])|:|(A12 <:< Pk[_])|:|(A13 <:< Pk[_])|:|(A14 <:< Pk[_])|:|(A15 <:< Pk[_])|:|(A16 <:< Pk[_])|:|(A17 <:< Pk[_]) ) = {
+
+ val all = ((v,hasId) match {
+ case (self( a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17), ( e1 |:| e2 |:| e3 |:| e4 |:| e5 |:| e6 |:| e7 |:| e8 |:| e9 |:| e10 |:| e11 |:| e12 |:| e13 |:| e14 |:| e15 |:| e16 |:| e17)) =>
+ List (
+ (e1, unqualify(name1), toParameterValue(a1)(pt1._2)),
+ (e2, unqualify(name2), toParameterValue(a2)(pt2._2)),
+ (e3, unqualify(name3), toParameterValue(a3)(pt3._2)),
+ (e4, unqualify(name4), toParameterValue(a4)(pt4._2)),
+ (e5, unqualify(name5), toParameterValue(a5)(pt5._2)),
+ (e6, unqualify(name6), toParameterValue(a6)(pt6._2)),
+ (e7, unqualify(name7), toParameterValue(a7)(pt7._2)),
+ (e8, unqualify(name8), toParameterValue(a8)(pt8._2)),
+ (e9, unqualify(name9), toParameterValue(a9)(pt9._2)),
+ (e10, unqualify(name10), toParameterValue(a10)(pt10._2)),
+ (e11, unqualify(name11), toParameterValue(a11)(pt11._2)),
+ (e12, unqualify(name12), toParameterValue(a12)(pt12._2)),
+ (e13, unqualify(name13), toParameterValue(a13)(pt13._2)),
+ (e14, unqualify(name14), toParameterValue(a14)(pt14._2)),
+ (e15, unqualify(name15), toParameterValue(a15)(pt15._2)),
+ (e16, unqualify(name16), toParameterValue(a16)(pt16._2)),
+ (e17, unqualify(name17), toParameterValue(a17)(pt17._2)))
+ })
+
+ val (ids,toSet) = all.partition(_._1.isDefined)
+ if(ids == all) throw new Exception("everything is a Pk, nothing left to set!")
+
+ val toUpdate = toSet.map(_._2).map(n => n+" = "+"{"+n+"}").mkString(", ")
+
+ import Sql._
+
+ sql("update "+containerName +" set "+toUpdate+
+ " where "+ ids.map(_._2).map( n => n+" = "+"{"+n+"}").mkString(" and ") )
+ .on(all.map(v => (v._2,v._3)): _* )
+ .executeUpdate()
+
+ }
+
+ def create(v:R)(implicit hasId: (A1 <:< Pk[_])|:|(A2 <:< Pk[_])|:|(A3 <:< Pk[_])|:|(A4 <:< Pk[_])|:|(A5 <:< Pk[_])|:|(A6 <:< Pk[_])|:|(A7 <:< Pk[_])|:|(A8 <:< Pk[_])|:|(A9 <:< Pk[_])|:|(A10 <:< Pk[_])|:|(A11 <:< Pk[_])|:|(A12 <:< Pk[_])|:|(A13 <:< Pk[_])|:|(A14 <:< Pk[_])|:|(A15 <:< Pk[_])|:|(A16 <:< Pk[_])|:|(A17 <:< Pk[_]) ) :R = {
+
+ val all = ((v,hasId) match {
+ case (self( a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17), ( e1 |:| e2 |:| e3 |:| e4 |:| e5 |:| e6 |:| e7 |:| e8 |:| e9 |:| e10 |:| e11 |:| e12 |:| e13 |:| e14 |:| e15 |:| e16 |:| e17)) =>
+ List (
+ (e1, unqualify(name1), toParameterValue(a1)(pt1._2)),
+ (e2, unqualify(name2), toParameterValue(a2)(pt2._2)),
+ (e3, unqualify(name3), toParameterValue(a3)(pt3._2)),
+ (e4, unqualify(name4), toParameterValue(a4)(pt4._2)),
+ (e5, unqualify(name5), toParameterValue(a5)(pt5._2)),
+ (e6, unqualify(name6), toParameterValue(a6)(pt6._2)),
+ (e7, unqualify(name7), toParameterValue(a7)(pt7._2)),
+ (e8, unqualify(name8), toParameterValue(a8)(pt8._2)),
+ (e9, unqualify(name9), toParameterValue(a9)(pt9._2)),
+ (e10, unqualify(name10), toParameterValue(a10)(pt10._2)),
+ (e11, unqualify(name11), toParameterValue(a11)(pt11._2)),
+ (e12, unqualify(name12), toParameterValue(a12)(pt12._2)),
+ (e13, unqualify(name13), toParameterValue(a13)(pt13._2)),
+ (e14, unqualify(name14), toParameterValue(a14)(pt14._2)),
+ (e15, unqualify(name15), toParameterValue(a15)(pt15._2)),
+ (e16, unqualify(name16), toParameterValue(a16)(pt16._2)),
+ (e17, unqualify(name17), toParameterValue(a17)(pt17._2)))
+ })
+
+ val (notSetIds,toSet) = all.partition(i => i._1.isDefined && i._3.aValue==NotAssigned)
+ if(notSetIds.length > 1) throw new Exception("multi ids not supported")
+ val toInsert = toSet.map(_._2)
+
+ import Sql._
+ import scala.util.control.Exception._
+ import SqlParser._
+
+ val idParser:SqlParser.Parser[_] = {
+ SqlParser.RowParser(row =>
+ row.asList.headOption.flatMap(a =>
+ (if (a.isInstanceOf[Option[_]]) a else Option(a)).asInstanceOf[Option[_]]
+ ).toRight(NoColumnsInReturnedResult)
+ )
+ }
+
+ val (statement, ok) = sql("insert into "+containerName+" ( "+toInsert.mkString(", ")+" ) values ( "+toInsert.map("{"+_+"}").mkString(", ")+")")
+ .on(all.map(v => (v._2,v._3)): _* )
+ .execute1(getGeneratedKeys=true)
+
+ val rs = statement.getGeneratedKeys();
+ val id = idParser(StreamReader(Sql.resultSetToStream(rs))).get
+
+ val List( a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17) = all.map(_._3.aValue).map({case NotAssigned => Id(id); case other => other})
+ apply(a1.asInstanceOf[A1], a2.asInstanceOf[A2], a3.asInstanceOf[A3], a4.asInstanceOf[A4], a5.asInstanceOf[A5], a6.asInstanceOf[A6], a7.asInstanceOf[A7], a8.asInstanceOf[A8], a9.asInstanceOf[A9], a10.asInstanceOf[A10], a11.asInstanceOf[A11], a12.asInstanceOf[A12], a13.asInstanceOf[A13], a14.asInstanceOf[A14], a15.asInstanceOf[A15], a16.asInstanceOf[A16], a17.asInstanceOf[A17])
+
+
+ }
+ }
+
+}
+
+
View
203 src/play/db/anorm/Magic18.scala
@@ -0,0 +1,203 @@
+
+
+
+
+package play.db
+
+import play.utils.Scala.MayErr
+import play.utils.Scala.MayErr._
+
+package anorm {
+
+ trait MParser18[ A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, R] extends ParserWithId[R] {
+
+ val p1:ColumnTo[A1]
+
+ val p2:ColumnTo[A2]
+
+ val p3:ColumnTo[A3]
+
+ val p4:ColumnTo[A4]
+
+ val p5:ColumnTo[A5]
+
+ val p6:ColumnTo[A6]
+
+ val p7:ColumnTo[A7]
+
+ val p8:ColumnTo[A8]
+
+ val p9:ColumnTo[A9]
+
+ val p10:ColumnTo[A10]
+
+ val p11:ColumnTo[A11]
+
+ val p12:ColumnTo[A12]
+
+ val p13:ColumnTo[A13]
+
+ val p14:ColumnTo[A14]
+
+ val p15:ColumnTo[A15]
+
+ val p16:ColumnTo[A16]
+
+ val p17:ColumnTo[A17]
+
+ val p18:ColumnTo[A18]
+
+ def apply(a1:A1, a2:A2, a3:A3, a4:A4, a5:A5, a6:A6, a7:A7, a8:A8, a9:A9, a10:A10, a11:A11, a12:A12, a13:A13, a14:A14, a15:A15, a16:A16, a17:A17, a18:A18 ):R
+
+ val containerName:String
+ val columnNames:(String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String)
+
+ lazy val (name1 ,name2 ,name3 ,name4 ,name5 ,name6 ,name7 ,name8 ,name9 ,name10 ,name11 ,name12 ,name13 ,name14 ,name15 ,name16 ,name17 ,name18) = columnNames
+
+ import SqlParser._
+ override def apply(input:Input):SqlParser.ParseResult[R] =
+ (
+ get[A1](name1)(p1) ~<
+ get[A2](name2)(p2) ~<
+ get[A3](name3)(p3) ~<
+ get[A4](name4)(p4) ~<
+ get[A5](name5)(p5) ~<
+ get[A6](name6)(p6) ~<
+ get[A7](name7)(p7) ~<
+ get[A8](name8)(p8) ~<
+ get[A9](name9)(p9) ~<
+ get[A10](name10)(p10) ~<
+ get[A11](name11)(p11) ~<
+ get[A12](name12)(p12) ~<
+ get[A13](name13)(p13) ~<
+ get[A14](name14)(p14) ~<
+ get[A15](name15)(p15) ~<
+ get[A16](name16)(p16) ~<
+ get[A17](name17)(p17) ~<
+ get[A18](name18)(p18) ^^ { case a1 ~ a2 ~ a3 ~ a4 ~ a5 ~ a6 ~ a7 ~ a8 ~ a9 ~ a10 ~ a11 ~ a12 ~ a13 ~ a14 ~ a15 ~ a16 ~ a17 ~ a18 => apply(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18)} )(input)
+
+ val uniqueId : (Row=> MayErr[SqlRequestError,Any]) = null
+ }
+
+ trait M18[ A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, R] {
+ self: MParser18[ A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18,R] =>
+
+ val pt1:(ColumnTo[A1],ToStatement[A1])
+ val pt2:(ColumnTo[A2],ToStatement[A2])
+ val pt3:(ColumnTo[A3],ToStatement[A3])
+ val pt4:(ColumnTo[A4],ToStatement[A4])
+ val pt5:(ColumnTo[A5],ToStatement[A5])
+ val pt6:(ColumnTo[A6],ToStatement[A6])
+ val pt7:(ColumnTo[A7],ToStatement[A7])
+ val pt8:(ColumnTo[A8],ToStatement[A8])
+ val pt9:(ColumnTo[A9],ToStatement[A9])
+ val pt10:(ColumnTo[A10],ToStatement[A10])
+ val pt11:(ColumnTo[A11],ToStatement[A11])
+ val pt12:(ColumnTo[A12],ToStatement[A12])
+ val pt13:(ColumnTo[A13],ToStatement[A13])
+ val pt14:(ColumnTo[A14],ToStatement[A14])
+ val pt15:(ColumnTo[A15],ToStatement[A15])
+ val pt16:(ColumnTo[A16],ToStatement[A16])
+ val pt17:(ColumnTo[A17],ToStatement[A17])
+ val pt18:(ColumnTo[A18],ToStatement[A18])
+
+ def unapply(r:R):Option[( A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18)]
+ def unqualify(columnName:String) = columnName.split('.').last
+
+ def update(v:R)(implicit hasId: (A1 <:< Pk[_])|:|(A2 <:< Pk[_])|:|(A3 <:< Pk[_])|:|(A4 <:< Pk[_])|:|(A5 <:< Pk[_])|:|(A6 <:< Pk[_])|:|(A7 <:< Pk[_])|:|(A8 <:< Pk[_])|:|(A9 <:< Pk[_])|:|(A10 <:< Pk[_])|:|(A11 <:< Pk[_])|:|(A12 <:< Pk[_])|:|(A13 <:< Pk[_])|:|(A14 <:< Pk[_])|:|(A15 <:< Pk[_])|:|(A16 <:< Pk[_])|:|(A17 <:< Pk[_])|:|(A18 <:< Pk[_]) ) = {
+
+ val all = ((v,hasId) match {
+ case (self( a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18), ( e1 |:| e2 |:| e3 |:| e4 |:| e5 |:| e6 |:| e7 |:| e8 |:| e9 |:| e10 |:| e11 |:| e12 |:| e13 |:| e14 |:| e15 |:| e16 |:| e17 |:| e18)) =>
+ List (
+ (e1, unqualify(name1), toParameterValue(a1)(pt1._2)),
+ (e2, unqualify(name2), toParameterValue(a2)(pt2._2)),
+ (e3, unqualify(name3), toParameterValue(a3)(pt3._2)),
+ (e4, unqualify(name4), toParameterValue(a4)(pt4._2)),
+ (e5, unqualify(name5), toParameterValue(a5)(pt5._2)),
+ (e6, unqualify(name6), toParameterValue(a6)(pt6._2)),
+ (e7, unqualify(name7), toParameterValue(a7)(pt7._2)),
+ (e8, unqualify(name8), toParameterValue(a8)(pt8._2)),
+ (e9, unqualify(name9), toParameterValue(a9)(pt9._2)),
+ (e10, unqualify(name10), toParameterValue(a10)(pt10._2)),
+ (e11, unqualify(name11), toParameterValue(a11)(pt11._2)),
+ (e12, unqualify(name12), toParameterValue(a12)(pt12._2)),
+ (e13, unqualify(name13), toParameterValue(a13)(pt13._2)),
+ (e14, unqualify(name14), toParameterValue(a14)(pt14._2)),
+ (e15, unqualify(name15), toParameterValue(a15)(pt15._2)),
+ (e16, unqualify(name16), toParameterValue(a16)(pt16._2)),
+ (e17, unqualify(name17), toParameterValue(a17)(pt17._2)),
+ (e18, unqualify(name18), toParameterValue(a18)(pt18._2)))
+ })
+
+ val (ids,toSet) = all.partition(_._1.isDefined)
+ if(ids == all) throw new Exception("everything is a Pk, nothing left to set!")
+
+ val toUpdate = toSet.map(_._2).map(n => n+" = "+"{"+n+"}").mkString(", ")
+
+ import Sql._
+
+ sql("update "+containerName +" set "+toUpdate+
+ " where "+ ids.map(_._2).map( n => n+" = "+"{"+n+"}").mkString(" and ") )
+ .on(all.map(v => (v._2,v._3)): _* )
+ .executeUpdate()
+
+ }
+
+ def create(v:R)(implicit hasId: (A1 <:< Pk[_])|:|(A2 <:< Pk[_])|:|(A3 <:< Pk[_])|:|(A4 <:< Pk[_])|:|(A5 <:< Pk[_])|:|(A6 <:< Pk[_])|:|(A7 <:< Pk[_])|:|(A8 <:< Pk[_])|:|(A9 <:< Pk[_])|:|(A10 <:< Pk[_])|:|(A11 <:< Pk[_])|:|(A12 <:< Pk[_])|:|(A13 <:< Pk[_])|:|(A14 <:< Pk[_])|:|(A15 <:< Pk[_])|:|(A16 <:< Pk[_])|:|(A17 <:< Pk[_])|:|(A18 <:< Pk[_]) ) :R = {
+
+ val all = ((v,hasId) match {
+ case (self( a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18), ( e1 |:| e2 |:| e3 |:| e4 |:| e5 |:| e6 |:| e7 |:| e8 |:| e9 |:| e10 |:| e11 |:| e12 |:| e13 |:| e14 |:| e15 |:| e16 |:| e17 |:| e18)) =>
+ List (
+ (e1, unqualify(name1), toParameterValue(a1)(pt1._2)),
+ (e2, unqualify(name2), toParameterValue(a2)(pt2._2)),
+ (e3, unqualify(name3), toParameterValue(a3)(pt3._2)),
+ (e4, unqualify(name4), toParameterValue(a4)(pt4._2)),
+ (e5, unqualify(name5), toParameterValue(a5)(pt5._2)),
+ (e6, unqualify(name6), toParameterValue(a6)(pt6._2)),
+ (e7, unqualify(name7), toParameterValue(a7)(pt7._2)),
+ (e8, unqualify(name8), toParameterValue(a8)(pt8._2)),
+ (e9, unqualify(name9), toParameterValue(a9)(pt9._2)),
+ (e10, unqualify(name10), toParameterValue(a10)(pt10._2)),
+ (e11, unqualify(name11), toParameterValue(a11)(pt11._2)),
+ (e12, unqualify(name12), toParameterValue(a12)(pt12._2)),
+ (e13, unqualify(name13), toParameterValue(a13)(pt13._2)),
+ (e14, unqualify(name14), toParameterValue(a14)(pt14._2)),
+ (e15, unqualify(name15), toParameterValue(a15)(pt15._2)),
+ (e16, unqualify(name16), toParameterValue(a16)(pt16._2)),
+ (e17, unqualify(name17), toParameterValue(a17)(pt17._2)),
+ (e18, unqualify(name18), toParameterValue(a18)(pt18._2)))
+ })
+
+ val (notSetIds,toSet) = all.partition(i => i._1.isDefined && i._3.aValue==NotAssigned)
+ if(notSetIds.length > 1) throw new Exception("multi ids not supported")
+ val toInsert = toSet.map(_._2)
+
+ import Sql._
+ import scala.util.control.Exception._
+ import SqlParser._
+
+ val idParser:SqlParser.Parser[_] = {
+ SqlParser.RowParser(row =>
+ row.asList.headOption.flatMap(a =>
+ (if (a.isInstanceOf[Option[_]]) a else Option(a)).asInstanceOf[Option[_]]
+ ).toRight(NoColumnsInReturnedResult)
+ )
+ }
+
+ val (statement, ok) = sql("insert into "+containerName+" ( "+toInsert.mkString(", ")+" ) values ( "+toInsert.map("{"+_+"}").mkString(", ")+")")
+ .on(all.map(v => (v._2,v._3)): _* )
+ .execute1(getGeneratedKeys=true)
+
+ val rs = statement.getGeneratedKeys();
+ val id = idParser(StreamReader(Sql.resultSetToStream(rs))).get
+
+ val List( a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18) = all.map(_._3.aValue).map({case NotAssigned => Id(id); case other => other})
+ apply(a1.asInstanceOf[A1], a2.asInstanceOf[A2], a3.asInstanceOf[A3], a4.asInstanceOf[A4], a5.asInstanceOf[A5], a6.asInstanceOf[A6], a7.asInstanceOf[A7], a8.asInstanceOf[A8], a9.asInstanceOf[A9], a10.asInstanceOf[A10], a11.asInstanceOf[A11], a12.asInstanceOf[A12], a13.asInstanceOf[A13], a14.asInstanceOf[A14], a15.asInstanceOf[A15], a16.asInstanceOf[A16], a17.asInstanceOf[A17], a18.asInstanceOf[A18])
+
+
+ }
+ }
+
+}
+
+
View
209 src/play/db/anorm/Magic19.scala
@@ -0,0 +1,209 @@
+
+
+
+
+package play.db
+
+import play.utils.Scala.MayErr
+import play.utils.Scala.MayErr._
+
+package anorm {
+
+ trait MParser19[ A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19, R] extends ParserWithId[R] {
+
+ val p1:ColumnTo[A1]
+
+ val p2:ColumnTo[A2]
+
+ val p3:ColumnTo[A3]
+
+ val p4:ColumnTo[A4]
+
+ val p5:ColumnTo[A5]
+
+ val p6:ColumnTo[A6]
+
+ val p7:ColumnTo[A7]
+
+ val p8:ColumnTo[A8]
+
+ val p9:ColumnTo[A9]
+
+ val p10:ColumnTo[A10]
+
+ val p11:ColumnTo[A11]
+
+ val p12:ColumnTo[A12]
+
+ val p13:ColumnTo[A13]
+
+ val p14:ColumnTo[A14]
+
+ val p15:ColumnTo[A15]
+
+ val p16:ColumnTo[A16]
+
+ val p17:ColumnTo[A17]
+
+ val p18:ColumnTo[A18]
+
+ val p19:ColumnTo[A19]
+
+ def apply(a1:A1, a2:A2, a3:A3, a4:A4, a5:A5, a6:A6, a7:A7, a8:A8, a9:A9, a10:A10, a11:A11, a12:A12, a13:A13, a14:A14, a15:A15, a16:A16, a17:A17, a18:A18, a19:A19 ):R
+
+ val containerName:String
+ val columnNames:(String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String)
+
+ lazy val (name1 ,name2 ,name3 ,name4 ,name5 ,name6 ,name7 ,name8 ,name9 ,name10 ,name11 ,name12 ,name13 ,name14 ,name15 ,name16 ,name17 ,name18 ,name19) = columnNames
+
+ import SqlParser._
+ override def apply(input:Input):SqlParser.ParseResult[R] =
+ (
+ get[A1](name1)(p1) ~<
+ get[A2](name2)(p2) ~<
+ get[A3](name3)(p3) ~<
+ get[A4](name4)(p4) ~<
+ get[A5](name5)(p5) ~<
+ get[A6](name6)(p6) ~<
+ get[A7](name7)(p7) ~<
+ get[A8](name8)(p8) ~<
+ get[A9](name9)(p9) ~<
+ get[A10](name10)(p10) ~<
+ get[A11](name11)(p11) ~<
+ get[A12](name12)(p12) ~<
+ get[A13](name13)(p13) ~<
+ get[A14](name14)(p14) ~<
+ get[A15](name15)(p15) ~<
+ get[A16](name16)(p16) ~<
+ get[A17](name17)(p17) ~<
+ get[A18](name18)(p18) ~<
+ get[A19](name19)(p19) ^^ { case a1 ~ a2 ~ a3 ~ a4 ~ a5 ~ a6 ~ a7 ~ a8 ~ a9 ~ a10 ~ a11 ~ a12 ~ a13 ~ a14 ~ a15 ~ a16 ~ a17 ~ a18 ~ a19 => apply(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19)} )(input)
+
+ val uniqueId : (Row=> MayErr[SqlRequestError,Any]) = null
+ }
+
+ trait M19[ A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19, R] {
+ self: MParser19[ A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19,R] =>
+
+ val pt1:(ColumnTo[A1],ToStatement[A1])
+ val pt2:(ColumnTo[A2],ToStatement[A2])
+ val pt3:(ColumnTo[A3],ToStatement[A3])
+ val pt4:(ColumnTo[A4],ToStatement[A4])
+ val pt5:(ColumnTo[A5],ToStatement[A5])
+ val pt6:(ColumnTo[A6],ToStatement[A6])
+ val pt7:(ColumnTo[A7],ToStatement[A7])
+ val pt8:(ColumnTo[A8],ToStatement[A8])
+ val pt9:(ColumnTo[A9],ToStatement[A9])
+ val pt10:(ColumnTo[A10],ToStatement[A10])
+ val pt11:(ColumnTo[A11],ToStatement[A11])
+ val pt12:(ColumnTo[A12],ToStatement[A12])
+ val pt13:(ColumnTo[A13],ToStatement[A13])
+ val pt14:(ColumnTo[A14],ToStatement[A14])
+ val pt15:(ColumnTo[A15],ToStatement[A15])
+ val pt16:(ColumnTo[A16],ToStatement[A16])
+ val pt17:(ColumnTo[A17],ToStatement[A17])
+ val pt18:(ColumnTo[A18],ToStatement[A18])
+ val pt19:(ColumnTo[A19],ToStatement[A19])
+
+ def unapply(r:R):Option[( A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19)]
+ def unqualify(columnName:String) = columnName.split('.').last
+
+ def update(v:R)(implicit hasId: (A1 <:< Pk[_])|:|(A2 <:< Pk[_])|:|(A3 <:< Pk[_])|:|(A4 <:< Pk[_])|:|(A5 <:< Pk[_])|:|(A6 <:< Pk[_])|:|(A7 <:< Pk[_])|:|(A8 <:< Pk[_])|:|(A9 <:< Pk[_])|:|(A10 <:< Pk[_])|:|(A11 <:< Pk[_])|:|(A12 <:< Pk[_])|:|(A13 <:< Pk[_])|:|(A14 <:< Pk[_])|:|(A15 <:< Pk[_])|:|(A16 <:< Pk[_])|:|(A17 <:< Pk[_])|:|(A18 <:< Pk[_])|:|(A19 <:< Pk[_]) ) = {
+
+ val all = ((v,hasId) match {
+ case (self( a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19), ( e1 |:| e2 |:| e3 |:| e4 |:| e5 |:| e6 |:| e7 |:| e8 |:| e9 |:| e10 |:| e11 |:| e12 |:| e13 |:| e14 |:| e15 |:| e16 |:| e17 |:| e18 |:| e19)) =>
+ List (
+ (e1, unqualify(name1), toParameterValue(a1)(pt1._2)),
+ (e2, unqualify(name2), toParameterValue(a2)(pt2._2)),
+ (e3, unqualify(name3), toParameterValue(a3)(pt3._2)),
+ (e4, unqualify(name4), toParameterValue(a4)(pt4._2)),
+ (e5, unqualify(name5), toParameterValue(a5)(pt5._2)),
+ (e6, unqualify(name6), toParameterValue(a6)(pt6._2)),
+ (e7, unqualify(name7), toParameterValue(a7)(pt7._2)),
+ (e8, unqualify(name8), toParameterValue(a8)(pt8._2)),
+ (e9, unqualify(name9), toParameterValue(a9)(pt9._2)),
+ (e10, unqualify(name10), toParameterValue(a10)(pt10._2)),
+ (e11, unqualify(name11), toParameterValue(a11)(pt11._2)),
+ (e12, unqualify(name12), toParameterValue(a12)(pt12._2)),
+ (e13, unqualify(name13), toParameterValue(a13)(pt13._2)),
+ (e14, unqualify(name14), toParameterValue(a14)(pt14._2)),
+ (e15, unqualify(name15), toParameterValue(a15)(pt15._2)),
+ (e16, unqualify(name16), toParameterValue(a16)(pt16._2)),
+ (e17, unqualify(name17), toParameterValue(a17)(pt17._2)),
+ (e18, unqualify(name18), toParameterValue(a18)(pt18._2)),
+ (e19, unqualify(name19), toParameterValue(a19)(pt19._2)))
+ })
+
+ val (ids,toSet) = all.partition(_._1.isDefined)
+ if(ids == all) throw new Exception("everything is a Pk, nothing left to set!")
+
+ val toUpdate = toSet.map(_._2).map(n => n+" = "+"{"+n+"}").mkString(", ")
+
+ import Sql._
+
+ sql("update "+containerName +" set "+toUpdate+
+ " where "+ ids.map(_._2).map( n => n+" = "+"{"+n+"}").mkString(" and ") )
+ .on(all.map(v => (v._2,v._3)): _* )
+ .executeUpdate()
+
+ }
+
+ def create(v:R)(implicit hasId: (A1 <:< Pk[_])|:|(A2 <:< Pk[_])|:|(A3 <:< Pk[_])|:|(A4 <:< Pk[_])|:|(A5 <:< Pk[_])|:|(A6 <:< Pk[_])|:|(A7 <:< Pk[_])|:|(A8 <:< Pk[_])|:|(A9 <:< Pk[_])|:|(A10 <:< Pk[_])|:|(A11 <:< Pk[_])|:|(A12 <:< Pk[_])|:|(A13 <:< Pk[_])|:|(A14 <:< Pk[_])|:|(A15 <:< Pk[_])|:|(A16 <:< Pk[_])|:|(A17 <:< Pk[_])|:|(A18 <:< Pk[_])|:|(A19 <:< Pk[_]) ) :R = {
+
+ val all = ((v,hasId) match {
+ case (self( a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19), ( e1 |:| e2 |:| e3 |:| e4 |:| e5 |:| e6 |:| e7 |:| e8 |:| e9 |:| e10 |:| e11 |:| e12 |:| e13 |:| e14 |:| e15 |:| e16 |:| e17 |:| e18 |:| e19)) =>
+ List (
+ (e1, unqualify(name1), toParameterValue(a1)(pt1._2)),
+ (e2, unqualify(name2), toParameterValue(a2)(pt2._2)),
+ (e3, unqualify(name3), toParameterValue(a3)(pt3._2)),
+ (e4, unqualify(name4), toParameterValue(a4)(pt4._2)),
+ (e5, unqualify(name5), toParameterValue(a5)(pt5._2)),
+ (e6, unqualify(name6), toParameterValue(a6)(pt6._2)),
+ (e7, unqualify(name7), toParameterValue(a7)(pt7._2)),
+ (e8, unqualify(name8), toParameterValue(a8)(pt8._2)),
+ (e9, unqualify(name9), toParameterValue(a9)(pt9._2)),
+ (e10, unqualify(name10), toParameterValue(a10)(pt10._2)),
+ (e11, unqualify(name11), toParameterValue(a11)(pt11._2)),
+ (e12, unqualify(name12), toParameterValue(a12)(pt12._2)),
+ (e13, unqualify(name13), toParameterValue(a13)(pt13._2)),
+ (e14, unqualify(name14), toParameterValue(a14)(pt14._2)),
+ (e15, unqualify(name15), toParameterValue(a15)(pt15._2)),
+ (e16, unqualify(name16), toParameterValue(a16)(pt16._2)),
+ (e17, unqualify(name17), toParameterValue(a17)(pt17._2)),
+ (e18, unqualify(name18), toParameterValue(a18)(pt18._2)),
+ (e19, unqualify(name19), toParameterValue(a19)(pt19._2)))
+ })
+
+ val (notSetIds,toSet) = all.partition(i => i._1.isDefined && i._3.aValue==NotAssigned)
+ if(notSetIds.length > 1) throw new Exception("multi ids not supported")
+ val toInsert = toSet.map(_._2)
+
+ import Sql._
+ import scala.util.control.Exception._
+ import SqlParser._
+
+ val idParser:SqlParser.Parser[_] = {
+ SqlParser.RowParser(row =>
+ row.asList.headOption.flatMap(a =>
+ (if (a.isInstanceOf[Option[_]]) a else Option(a)).asInstanceOf[Option[_]]
+ ).toRight(NoColumnsInReturnedResult)
+ )
+ }
+
+ val (statement, ok) = sql("insert into "+containerName+" ( "+toInsert.mkString(", ")+" ) values ( "+toInsert.map("{"+_+"}").mkString(", ")+")")
+ .on(all.map(v => (v._2,v._3)): _* )
+ .execute1(getGeneratedKeys=true)
+
+ val rs = statement.getGeneratedKeys();
+ val id = idParser(StreamReader(Sql.resultSetToStream(rs))).get
+
+ val List( a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19) = all.map(_._3.aValue).map({case NotAssigned => Id(id); case other => other})
+ apply(a1.asInstanceOf[A1], a2.asInstanceOf[A2], a3.asInstanceOf[A3], a4.asInstanceOf[A4], a5.asInstanceOf[A5], a6.asInstanceOf[A6], a7.asInstanceOf[A7], a8.asInstanceOf[A8], a9.asInstanceOf[A9], a10.asInstanceOf[A10], a11.asInstanceOf[A11], a12.asInstanceOf[A12], a13.asInstanceOf[A13], a14.asInstanceOf[A14], a15.asInstanceOf[A15], a16.asInstanceOf[A16], a17.asInstanceOf[A17], a18.asInstanceOf[A18], a19.asInstanceOf[A19])
+
+
+ }
+ }
+
+}
+
+
View
64 src/play/db/anorm/Magic2.scala
@@ -1,86 +1,85 @@
-
-
-
-
+
+
+
package play.db
-
+
import play.utils.Scala.MayErr
import play.utils.Scala.MayErr._
-
+
package anorm {
-
+
trait MParser2[ A1, A2, R] extends ParserWithId[R] {
val p1:ColumnTo[A1]
-
+
val p2:ColumnTo[A2]
-
+
def apply(a1:A1, a2:A2 ):R
-
+
val containerName:String
val columnNames:(String, String)
-
+
lazy val (name1 ,name2) = columnNames
-
+
import SqlParser._
override def apply(input:Input):SqlParser.ParseResult[R] =
(
get[A1](name1)(p1) ~<
get[A2](name2)(p2) ^^ { case a1 ~ a2 => apply(a1, a2)} )(input)
-
+
val uniqueId : (Row=> MayErr[SqlRequestError,Any]) = null
}
-
+
trait M2[ A1, A2, R] {
self: MParser2[ A1, A2,R] =>
val pt1:(ColumnTo[A1],ToStatement[A1])
val pt2:(ColumnTo[A2],ToStatement[A2])
-
+
def unapply(r:R):Option[( A1, A2)]
def unqualify(columnName:String) = columnName.split('.').last
-
+
def update(v:R)(implicit hasId: (A1 <:< Pk[_])|:|(A2 <:< Pk[_]) ) = {
-
+
val all = ((v,hasId) match {