Skip to content

Commit

Permalink
Merge pull request #47 from cchantep/feature/33
Browse files Browse the repository at this point in the history
New Play JDBC module (with DSL)
  • Loading branch information
cchantep authored Jul 25, 2016
2 parents 2eb464a + b527a21 commit e5c36d2
Show file tree
Hide file tree
Showing 36 changed files with 1,101 additions and 503 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 0 additions & 7 deletions .travis_scripts/beforeInstall.sh

This file was deleted.

18 changes: 18 additions & 0 deletions .travis_scripts/validate.sh
Original file line number Diff line number Diff line change
@@ -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
34 changes: 23 additions & 11 deletions jdbc-driver/src/test/scala/acolyte/jdbc/AbstractResultSetSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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" >> {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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"
))

}

Expand Down Expand Up @@ -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 {
Expand All @@ -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"
))

}
}
Expand Down Expand Up @@ -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"
))

}
}
Expand All @@ -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 {
Expand Down Expand Up @@ -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
) {}
}
59 changes: 39 additions & 20 deletions jdbc-driver/src/test/scala/acolyte/jdbc/AbstractStatementSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
}
}

Expand Down Expand Up @@ -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"
)

}

Expand Down Expand Up @@ -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"
)

}

Expand All @@ -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")

}
Expand Down Expand Up @@ -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"
)

}
}
Expand All @@ -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"
)

}

Expand All @@ -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
))
}
}

Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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")
}
}
Expand All @@ -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")
}
}
Expand All @@ -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")
}
}
Expand All @@ -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")
}
}
Expand All @@ -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
)
}
}

Expand Down
3 changes: 2 additions & 1 deletion jdbc-driver/src/test/scala/acolyte/jdbc/AcolyteSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Loading

0 comments on commit e5c36d2

Please sign in to comment.