Permalink
Browse files

[play-jdbc] New Play JDBC module (with DSL)

  • Loading branch information...
cchantep
cchantep committed Feb 12, 2016
1 parent 2eb464a commit b527a212302abda6c3943aad97a60c37676a2d58
Showing with 1,101 additions and 503 deletions.
  1. +2 −2 .travis.yml
  2. +0 −7 .travis_scripts/beforeInstall.sh
  3. +18 −0 .travis_scripts/validate.sh
  4. +23 −11 jdbc-driver/src/test/scala/acolyte/jdbc/AbstractResultSetSpec.scala
  5. +39 −20 jdbc-driver/src/test/scala/acolyte/jdbc/AbstractStatementSpec.scala
  6. +2 −1 jdbc-driver/src/test/scala/acolyte/jdbc/AcolyteSpec.scala
  7. +32 −19 jdbc-driver/src/test/scala/acolyte/jdbc/BlobSpec.scala
  8. +10 −5 jdbc-driver/src/test/scala/acolyte/jdbc/CallableStatementSpec.scala
  9. +8 −5 jdbc-driver/src/test/scala/acolyte/jdbc/ColumnSpec.scala
  10. +184 −96 jdbc-driver/src/test/scala/acolyte/jdbc/ConnectionSpec.scala
  11. +6 −3 jdbc-driver/src/test/scala/acolyte/jdbc/DatabaseMetaDataSpec.scala
  12. +24 −17 jdbc-driver/src/test/scala/acolyte/jdbc/DriverSpec.scala
  13. +16 −8 jdbc-driver/src/test/scala/acolyte/jdbc/ImmutableArraySpec.scala
  14. +43 −22 jdbc-driver/src/test/scala/acolyte/jdbc/ParameterMetaDataSpec.scala
  15. +70 −38 jdbc-driver/src/test/scala/acolyte/jdbc/PreparedStatementSpec.scala
  16. +144 −81 jdbc-driver/src/test/scala/acolyte/jdbc/RowListSpec.scala
  17. +12 −6 jdbc-java8/src/test/scala/acolyte/jdbc/AcolyteSpec.scala
  18. +11 −10 jdbc-scala/src/main/scala/{jdbc → }/AcolyteDSL.scala
  19. +8 −5 jdbc-scala/src/main/scala/{jdbc → }/Execution.scala
  20. +5 −3 jdbc-scala/src/test/scala/acolyte/jdbc/AcolyteSpec.scala
  21. +3 −3 jdbc-scala/src/test/scala/acolyte/jdbc/ConnectionSpec.scala
  22. +2 −1 jdbc-scala/src/test/scala/acolyte/jdbc/ExecutionSpec.scala
  23. +14 −8 jdbc-scala/src/test/scala/acolyte/jdbc/ScalaUseCases.scala
  24. +88 −0 play-jdbc/src/main/scala/AcolyteDatabase.scala
  25. +71 −0 play-jdbc/src/main/scala/PlayJdbcDSL.scala
  26. +22 −0 play-jdbc/src/test/scala/PlayJdbcSpec.scala
  27. +36 −6 project/Acolyte.scala
  28. +35 −33 project/JdbcScala.scala
  29. +44 −0 project/PlayJdbc.scala
  30. +30 −29 project/ReactiveMongo.scala
  31. +29 −28 project/ScalacPlugin.scala
  32. +2 −1 project/Studio.scala
  33. +1 −1 project/build.properties
  34. +2 −0 project/plugins.sbt
  35. +29 −15 scalac-plugin/src/main/scala/acolyte/AcolytePlugin.scala
  36. +36 −19 scalac-plugin/src/test/scala/acolyte/ExtractorComponentSpec.scala
View
@@ -2,11 +2,11 @@ language: scala
jdk:
- openjdk7
- oraclejdk8
env: JAVA_OPTS="-Xms32m -Xmx128m"
sudo: false
cache:
directories:
- $HOME/.ivy2
- $HOME/.sbt
scala:
- 2.11.7
- 2.11.8
script: ./.travis_scripts/validate.sh
@@ -1,7 +0,0 @@
#! /bin/sh
# Travis OpenJDK workaround
#cat /etc/hosts # optionally check the content *before*
hostname "$(hostname | cut -c1-63)"
sed -e "s/^\\(127\\.0\\.0\\.1.*\\)/\\1 $(hostname | cut -c1-63)/" /etc/hosts | tee /etc/hosts
#cat /etc/hosts # optionally check the content *after*
@@ -0,0 +1,18 @@
#! /bin/bash
if [ "$TRAVIS_SCALA_VERSION" = "2.10.5" -a `javac -version 2>&1 | grep 1.7 | wc -l` -eq 1 ]; then
echo "[INFO] Check the source format and backward compatibility"
sbt ++$TRAVIS_SCALA_VERSION scalariformFormat test:scalariformFormat > /dev/null
git diff --exit-code || (cat >> /dev/stdout <<EOF
ERROR: Scalariform check failed, see differences above.
To fix, format your sources using sbt scalariformFormat test:scalariformFormat before submitting a pull request.
Additionally, please squash your commits (eg, use git commit --amend) if you're going to update this pull request.
EOF
false
)
#sbt ++$TRAVIS_SCALA_VERSION ";error ;mimaReportBinaryIssues" || exit 2
fi
sbt ++$TRAVIS_SCALA_VERSION test-only
@@ -95,10 +95,13 @@ object AbstractResultSetSpec extends Specification {
"fail to be set when not scrollable" in {
defaultSet.setFetchDirection(ResultSet.FETCH_REVERSE).
aka("setting fetch direction") must throwA[SQLException](
"Type of result set is forward only") and (
"Type of result set is forward only"
) and (
defaultSet.setFetchDirection(ResultSet.FETCH_UNKNOWN).
aka("setting fetch direction") must throwA[SQLException](
"Type of result set is forward only"))
"Type of result set is forward only"
)
)
}
"be property set on scrollable set" >> {
@@ -136,7 +139,8 @@ object AbstractResultSetSpec extends Specification {
"with failure for negative count" in {
defaultSet.relative(-2) aka "backward move" must throwA[SQLException](
message = "Backward move")
message = "Backward move"
)
}
"with failure when out-of bounds" in {
@@ -181,7 +185,8 @@ object AbstractResultSetSpec extends Specification {
(rs.getRow aka "current row" mustEqual 1).
and(rs.absolute(0) aka "backward move" must throwA[SQLException](
message = "Backward move"))
message = "Backward move"
))
}
@@ -230,15 +235,17 @@ object AbstractResultSetSpec extends Specification {
lazy val rs = defaultSet
rs.beforeFirst aka "moving before first" must throwA[SQLException](
message = "Type of result set is forward only")
message = "Type of result set is forward only"
)
}
"without change if scrollable" in {
lazy val rs = scrollInsensitiveSet
rs.beforeFirst
rs.getRow aka "row" must_== 0 and (
rs.isBeforeFirst aka "before first" must beTrue)
rs.isBeforeFirst aka "before first" must beTrue
)
}
"with failure when backward and not scrollable" in {
@@ -248,7 +255,8 @@ object AbstractResultSetSpec extends Specification {
(rs.first aka "move first" must beTrue).
and(rs.getRow aka "row" mustEqual 1).
and(rs.beforeFirst aka "before first" must throwA[SQLException](
message = "Type of result set is forward only"))
message = "Type of result set is forward only"
))
}
}
@@ -277,7 +285,8 @@ object AbstractResultSetSpec extends Specification {
(rs.absolute(2) aka "forward move" must beTrue).
and(rs.getRow aka "row" mustEqual 2).
and(rs.first aka "backward first" must throwA[SQLException](
message = "Backward move"))
message = "Backward move"
))
}
}
@@ -299,7 +308,8 @@ object AbstractResultSetSpec extends Specification {
"be moved to after last" >> {
"with failure when not scrollable" in {
defaultSet.afterLast aka "moving after last" must throwA[SQLException](
"Type of result set is forward only")
"Type of result set is forward only"
)
}
"at 2" in {
@@ -514,11 +524,13 @@ object AbstractResultSetSpec extends Specification {
(s.isClosed aka "closed" must beTrue).
and(s.checkClosed aka "check" must throwA[SQLException](
message = "Result set is closed"))
message = "Result set is closed"
))
}
}
def defaultSet = new AbstractResultSet {}
def scrollInsensitiveSet = new AbstractResultSet(
"si", ResultSet.TYPE_SCROLL_INSENSITIVE) {}
"si", ResultSet.TYPE_SCROLL_INSENSITIVE
) {}
}
@@ -21,13 +21,15 @@ object AbstractStatementSpec extends Specification {
"Constructor" should {
"refuse null connection" in {
statement(c = null) aka "ctor" must throwA[IllegalArgumentException](
message = "Invalid connection")
message = "Invalid connection"
)
}
"refuse null handler" in {
statement(h = null).
aka("ctor") must throwA[IllegalArgumentException](
message = "Invalid handler")
message = "Invalid handler"
)
}
}
@@ -73,7 +75,8 @@ object AbstractStatementSpec extends Specification {
s.close()
s.executeQuery("QUERY") aka "query" must throwA[SQLException](
message = "Statement is closed")
message = "Statement is closed"
)
}
@@ -175,7 +178,8 @@ object AbstractStatementSpec extends Specification {
s.close()
s.executeUpdate("UPDATE") aka "update" must throwA[SQLException](
message = "Statement is closed")
message = "Statement is closed"
)
}
@@ -198,7 +202,8 @@ object AbstractStatementSpec extends Specification {
and(s.getUpdateCount aka "update count" mustEqual 5).
and(s.getResultSet aka "resultset" must beNull).
and(s.getGeneratedKeys aka "generated keys" mustEqual (
RowLists.stringList.resultSet)).
RowLists.stringList.resultSet
)).
and(sql aka "executed SQL" mustEqual "UPDATE")
}
@@ -273,15 +278,18 @@ object AbstractStatementSpec extends Specification {
s.close()
(s.getFetchSize aka "getter" must throwA[SQLException](
message = "Statement is closed")).
message = "Statement is closed"
)).
and(s.setFetchSize(1) aka "setter" must throwA[SQLException](
message = "Statement is closed"))
message = "Statement is closed"
))
}
"not be set negative" in {
statement().setFetchSize(-1) aka "setter" must throwA[SQLException](
message = "Negative fetch size")
message = "Negative fetch size"
)
}
}
@@ -304,15 +312,18 @@ object AbstractStatementSpec extends Specification {
s.close()
(s.getMaxRows aka "getter" must throwA[SQLException](
message = "Statement is closed")).
message = "Statement is closed"
)).
and(s.setMaxRows(1) aka "setter" must throwA[SQLException](
message = "Statement is closed"))
message = "Statement is closed"
))
}
"not be set negative" in {
statement().setMaxRows(-1) aka "setter" must throwA[SQLException](
message = "Negative max rows")
message = "Negative max rows"
)
}
@@ -323,8 +334,9 @@ object AbstractStatementSpec extends Specification {
(s.execute("QUERY") aka "flag" must beTrue).
and(rs.getFetchSize must_== 2).
and(rs aka "resultset" mustEqual(
RowLists.stringList("A", "B").resultSet))
and(rs aka "resultset" mustEqual (
RowLists.stringList("A", "B").resultSet
))
}
}
@@ -343,7 +355,8 @@ object AbstractStatementSpec extends Specification {
s.close()
s.addBatch("UPDATE") aka "add batch" must throwA[SQLException](
message = "Statement is closed")
message = "Statement is closed"
)
}
"be executed with 2 elements" in {
@@ -352,7 +365,8 @@ object AbstractStatementSpec extends Specification {
s.addBatch("BATCH1"); s.addBatch("2_BATCH")
s.executeBatch() aka "batch execution" mustEqual Array[Int](1, 2) and (
h.exed aka "executed" must contain(allOf("BATCH1", "2_BATCH").inOrder))
h.exed aka "executed" must contain(allOf("BATCH1", "2_BATCH").inOrder)
)
}
"throw exception as error is raised while executing first element" in {
@@ -367,7 +381,8 @@ object AbstractStatementSpec extends Specification {
like {
case ex: BatchUpdateException
(ex.getUpdateCounts aka "update count" must_== Array[Int](
EXECUTE_FAILED, EXECUTE_FAILED)).
EXECUTE_FAILED, EXECUTE_FAILED
)).
and(ex.getCause.getMessage aka "cause" mustEqual "Batch error")
}
}
@@ -392,7 +407,8 @@ object AbstractStatementSpec extends Specification {
like {
case ex: BatchUpdateException
(ex.getUpdateCounts aka "update count" must_== Array[Int](
EXECUTE_FAILED, 2)).
EXECUTE_FAILED, 2
)).
and(ex.getCause.getMessage aka "cause" mustEqual "Batch error: 1")
}
}
@@ -413,7 +429,8 @@ object AbstractStatementSpec extends Specification {
like {
case ex: BatchUpdateException
(ex.getUpdateCounts aka "update count" must_== Array[Int](
1, EXECUTE_FAILED)).
1, EXECUTE_FAILED
)).
and(ex.getCause.getMessage aka "cause" mustEqual "Batch error: 2")
}
}
@@ -438,7 +455,8 @@ object AbstractStatementSpec extends Specification {
like {
case ex: BatchUpdateException
(ex.getUpdateCounts aka "update count" must_== Array[Int](
1, EXECUTE_FAILED)).
1, EXECUTE_FAILED
)).
and(ex.getCause.getMessage aka "cause" mustEqual "Batch error: 2")
}
}
@@ -449,7 +467,8 @@ object AbstractStatementSpec extends Specification {
s.addBatch("BATCH1"); s.addBatch("2_BATCH")
s.clearBatch() aka "clear batch" must not(throwA[SQLException]) and (
h.exed.size aka "executed" must_== 0)
h.exed.size aka "executed" must_== 0
)
}
}
@@ -20,7 +20,8 @@ object AcolyteSpec extends Specification {
"return 1 for other update statement" in {
lazy val s = con.prepareStatement(
"INSERT INTO table('id', 'name') VALUES (?, ?)")
"INSERT INTO table('id', 'name') VALUES (?, ?)"
)
s.setString(1, "idVal");
s.setString(2, "idName")
Oops, something went wrong.

0 comments on commit b527a21

Please sign in to comment.