I am migrating my app from Play! 2.1 to 2.3.
Compilation errors are gone and having few failing tests.
One of them is Anorm related.
[error] NullPointerException: (BatchSql.scala:100)
[error] anorm.BatchSql$class.execute(BatchSql.scala:100)
[error] anorm.BatchSql$Copy.execute(BatchSql.scala:193)
[error] models.StoreUser$.insertByCsv(User.scala:314)
Sounds like I need to hack Anorm code. I consult the following page to compile Play! from source:
https://www.playframework.com/documentation/2.3.x/BuildingFromSource
$ git clone git://github.com/playframework/playframework.git
$ cd playframework
$ git checkout remotes/origin/2.3.x
As a start point, I tried to change playframework/framework/src/anorm/src/main/scala/anorm/BatchSql.scala
def execute()(implicit connection: Connection): Array[Int] = {
val s = getFilledStatement(connection)
println("*** statement = " + s)
Thread.sleep(30000)
s.executeBatch()
}
Compile and publish locally:
$ PLAY_OPTS=-Dscala.version=2.11.6 ./build clean publish-local
Remove my ivy cache:
$ rm -rf ~/.ivy2/cache
Change my project's project/plugins.sbt:
//addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.3.8")
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.3-SNAPSHOT")
Build.sbt file:
libraryDependencies ++= Seq(
"postgresql" % "postgresql" % "9.1-901.jdbc4",
"com.typesafe.play" %% "play-mailer" % "2.4.0",
...
jdbc,
// anorm,
"com.typesafe.play" %% "anorm" % "2.3-SNAPSHOT",
cache,
ws,
filters
)
Reload my project and test-only my failing test again.
But no print message ('*** statement = xxx'") is shown.
How can I use my modified Anorm code?
Update:
I git cloned anorm only from https://github.com/playframework/anorm and invoked publish-local. In this way, now I can use my own compiled anorm in Play!. The root cause is that recent version of anorm requires at least one list of paramters when invoking batch query (https://github.com/playframework/anorm/blob/master/docs/manual/working/scalaGuide/main/sql/ScalaAnorm.md).
Batch update must be called with at least one list of parameter. If a batch is executed with the mandatory first list of parameter being empty (e.g. Nil), only one statement will be executed (without parameter), which is equivalent to SQL(statement).executeUpdate().
If no parameters are served, NPE will be thrown. I fixed my application not to invoke execute() method if the parameter list is empty.
"com.typesafe.play" %% "anorm" % "2.4-SNAPSHOT" changing()
. – cchantep