Permalink
Browse files

[core] Implements statement creation with supported result set

type, concurrency or holdability:

```java
conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.CLOSE_CURSORS_AT_COMMIT);

conn.prepareStatement("SQL", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
conn.prepareStatement("SQL", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.CLOSE_CURSORS_AT_COMMIT);

conn.prepareCall("SQL", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
conn.prepareCall("SQL", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.CLOSE_CURSORS_AT_COMMIT);
```
  • Loading branch information...
cchantep
cchantep committed Nov 27, 2013
1 parent 334711b commit 44f9c1e4cb12ca18cd3584eed5ae16636ecb3b3e
Showing with 181 additions and 39 deletions.
  1. +47 −14 core/src/main/java/acolyte/Connection.java
  2. +134 −25 core/src/test/scala/acolyte/ConnectionSpec.scala
@@ -321,7 +321,16 @@ public Statement createStatement(final int resultSetType,
final int resultSetConcurrency)
throws SQLException {
throw new SQLFeatureNotSupportedException();
if (resultSetType != ResultSet.TYPE_FORWARD_ONLY) {
throw new SQLFeatureNotSupportedException("Unsupported result set type");
} // end of if
if (resultSetConcurrency != ResultSet.CONCUR_READ_ONLY) {
throw new SQLFeatureNotSupportedException("Unsupported result set concurrency");
} // end of if
return createStatement();
} // end of createStatement
/**
@@ -332,7 +341,16 @@ public PreparedStatement prepareStatement(final String sql,
final int resultSetConcurrency)
throws SQLException {
throw new SQLFeatureNotSupportedException();
if (resultSetType != ResultSet.TYPE_FORWARD_ONLY) {
throw new SQLFeatureNotSupportedException("Unsupported result set type");
} // end of if
if (resultSetConcurrency != ResultSet.CONCUR_READ_ONLY) {
throw new SQLFeatureNotSupportedException("Unsupported result set concurrency");
} // end of if
return prepareStatement(sql);
} // end of prepareStatement
/**
@@ -343,7 +361,16 @@ public CallableStatement prepareCall(final String sql,
final int resultSetConcurrency)
throws SQLException {
throw new SQLFeatureNotSupportedException();
if (resultSetType != ResultSet.TYPE_FORWARD_ONLY) {
throw new SQLFeatureNotSupportedException("Unsupported result set type");
} // end of if
if (resultSetConcurrency != ResultSet.CONCUR_READ_ONLY) {
throw new SQLFeatureNotSupportedException("Unsupported result set concurrency");
} // end of if
return prepareCall(sql);
} // end of prepareCall
/**
@@ -445,46 +472,52 @@ public void releaseSavepoint(final Savepoint savepoint)
/**
* {@inheritDoc}
* @throws java.sql.SQLFeatureNotSupportedException
* @throws java.sql.SQLFeatureNotSupportedException if |resultSetHoldability| is not ResultSet.CLOSE_CURSORS_AT_COMMIT
*/
public Statement createStatement(final int resultSetType,
final int resultSetConcurrency,
final int resultSetHoldability)
throws SQLException {
checkClosed();
if (resultSetHoldability != ResultSet.CLOSE_CURSORS_AT_COMMIT) {
throw new SQLFeatureNotSupportedException("Unsupported result set holdability");
} // end of if
throw new SQLFeatureNotSupportedException();
return createStatement(resultSetType, resultSetConcurrency);
} // end of createStatement
/**
* {@inheritDoc}
* @throws java.sql.SQLFeatureNotSupportedException
* @throws java.sql.SQLFeatureNotSupportedException if |resultSetHoldability| is not ResultSet.CLOSE_CURSORS_AT_COMMIT
*/
public PreparedStatement prepareStatement(final String sql,
final int resultSetType,
final int resultSetConcurrency,
final int resultSetHoldability)
throws SQLException {
checkClosed();
if (resultSetHoldability != ResultSet.CLOSE_CURSORS_AT_COMMIT) {
throw new SQLFeatureNotSupportedException("Unsupported result set holdability");
} // end of if
throw new SQLFeatureNotSupportedException();
return prepareStatement(sql, resultSetType, resultSetConcurrency);
} // end of prepareStatement
/**
* {@inheritDoc}
* @throws java.sql.SQLFeatureNotSupportedException
* @throws java.sql.SQLFeatureNotSupportedException if |resultSetHoldability| is not ResultSet.CLOSE_CURSORS_AT_COMMIT
*/
public CallableStatement prepareCall(final String sql,
final int resultSetType,
final int resultSetConcurrency,
final int resultSetHoldability)
throws SQLException {
checkClosed();
if (resultSetHoldability != ResultSet.CLOSE_CURSORS_AT_COMMIT) {
throw new SQLFeatureNotSupportedException("Unsupported result set holdability");
} // end of if
throw new SQLFeatureNotSupportedException();
return prepareCall(sql, resultSetType, resultSetConcurrency);
} // end of prepareCall
/**
@@ -663,7 +696,7 @@ public String getSchema() throws SQLException {
} // end of getSchema
/**
* {@inheritDoc}
* {@inheritDoc} (Java 1.7)
*/
public void abort(final Executor exec) throws SQLException {
if (exec == null) {
@@ -688,7 +721,7 @@ public void setNetworkTimeout(final Executor executor,
} // end of setNetworkTimeout
/**
* {@inheritDoc}
* {@inheritDoc} (Java 1.7)
* @throws java.sql.SQLFeatureNotSupportedException
*/
public int getNetworkTimeout() throws SQLException {
@@ -9,6 +9,14 @@ import java.sql.{
SQLException,
SQLFeatureNotSupportedException
}
import java.sql.ResultSet.{
TYPE_FORWARD_ONLY,
TYPE_SCROLL_INSENSITIVE,
CONCUR_READ_ONLY,
CONCUR_UPDATABLE,
CLOSE_CURSORS_AT_COMMIT,
HOLD_CURSORS_OVER_COMMIT
}
import org.specs2.mutable.Specification
@@ -530,23 +538,56 @@ object ConnectionSpec extends Specification with ConnectionFixtures {
"be owned by connection" in {
lazy val c = defaultCon
c.createStatement.getConnection aka "statement connection" mustEqual c
(c.createStatement.getConnection aka "statement connection" mustEqual c).
and(c.createStatement(TYPE_FORWARD_ONLY, CONCUR_READ_ONLY).
getConnection aka "statement connection" mustEqual c).
and(c.createStatement(
TYPE_FORWARD_ONLY, CONCUR_READ_ONLY, CLOSE_CURSORS_AT_COMMIT).
getConnection aka "statement connection" mustEqual c)
}
"not be created from a closed connection" in {
lazy val c = defaultCon
c.close()
c.createStatement aka "creation" must throwA[SQLException](
message = "Connection is closed")
(c.createStatement aka "creation" must throwA[SQLException](
message = "Connection is closed")).
and(c.createStatement(TYPE_FORWARD_ONLY, CONCUR_READ_ONLY).
aka("creation") must throwA[SQLException]("Connection is closed")).
and(c.createStatement(
TYPE_FORWARD_ONLY, CONCUR_READ_ONLY, CLOSE_CURSORS_AT_COMMIT).
aka("creation") must throwA[SQLException]("Connection is closed"))
}
"not be created with specific resultset type and/or concurrency" in {
(defaultCon.createStatement(1, 2).
aka("creation") must throwA[SQLFeatureNotSupportedException]).
and(defaultCon.createStatement(1, 2, 3).
aka("creation") must throwA[SQLFeatureNotSupportedException])
"not be created with unsupported resultset type" in {
(defaultCon.createStatement(TYPE_SCROLL_INSENSITIVE, CONCUR_READ_ONLY).
aka("creation") must throwA[SQLFeatureNotSupportedException](
message = "Unsupported result set type")).
and(defaultCon.createStatement(
TYPE_SCROLL_INSENSITIVE, CONCUR_READ_ONLY, CLOSE_CURSORS_AT_COMMIT).
aka("creation") must throwA[SQLFeatureNotSupportedException](
message = "Unsupported result set type"))
}
"not be created with unsupported resultset concurrency" in {
(defaultCon.createStatement(TYPE_FORWARD_ONLY, CONCUR_UPDATABLE).
aka("creation") must throwA[SQLFeatureNotSupportedException](
message = "Unsupported result set concurrency")).
and(defaultCon.createStatement(
TYPE_FORWARD_ONLY, CONCUR_UPDATABLE, CLOSE_CURSORS_AT_COMMIT).
aka("creation") must throwA[SQLFeatureNotSupportedException](
message = "Unsupported result set concurrency"))
}
"not be created with unsupported resultset holdability" in {
defaultCon.createStatement(
TYPE_FORWARD_ONLY, CONCUR_READ_ONLY, HOLD_CURSORS_OVER_COMMIT).
aka("creation") must throwA[SQLFeatureNotSupportedException](
message = "Unsupported result set holdability")
}
}
@@ -558,6 +599,11 @@ object ConnectionSpec extends Specification with ConnectionFixtures {
(c.prepareStatement("TEST").getConnection.
aka("statement connection") mustEqual c).
and(c.prepareStatement("TEST", Statement.NO_GENERATED_KEYS).
getConnection aka "statement connection" mustEqual c).
and(c.prepareStatement("TEST", TYPE_FORWARD_ONLY, CONCUR_READ_ONLY).
getConnection aka "statement connection" mustEqual c).
and(c.prepareStatement("TEST",
TYPE_FORWARD_ONLY, CONCUR_READ_ONLY, CLOSE_CURSORS_AT_COMMIT).
getConnection aka "statement connection" mustEqual c)
}
@@ -566,20 +612,50 @@ object ConnectionSpec extends Specification with ConnectionFixtures {
lazy val c = defaultCon
c.close()
c.prepareStatement("TEST") aka "creation" must throwA[SQLException](
message = "Connection is closed")
(c.prepareStatement("TEST") aka "creation" must throwA[SQLException](
message = "Connection is closed")).
and(c.prepareStatement("TEST", Statement.NO_GENERATED_KEYS).
aka("creation") must throwA[SQLException]("Connection is closed")).
and(c.prepareStatement("TEST", TYPE_FORWARD_ONLY, CONCUR_READ_ONLY).
aka("creation") must throwA[SQLException]("Connection is closed")).
and(c.prepareStatement("TEST",
TYPE_FORWARD_ONLY, CONCUR_READ_ONLY, CLOSE_CURSORS_AT_COMMIT).
aka("creation") must throwA[SQLException]("Connection is closed"))
}
"not be created with specific resultset type and/or concurrency" in {
(defaultCon.prepareStatement("TEST", 1, 2).
aka("creation") must throwA[SQLFeatureNotSupportedException]).
and(defaultCon.prepareStatement("TEST", 1, 2, 3).
aka("creation") must throwA[SQLFeatureNotSupportedException])
"not be created with unsupported resultset type" in {
(defaultCon.prepareStatement("TEST",
TYPE_SCROLL_INSENSITIVE, CONCUR_READ_ONLY).
aka("creation") must throwA[SQLFeatureNotSupportedException](
message = "Unsupported result set type")).
and(defaultCon.prepareStatement("TEST",
TYPE_SCROLL_INSENSITIVE, CONCUR_READ_ONLY, CLOSE_CURSORS_AT_COMMIT).
aka("creation") must throwA[SQLFeatureNotSupportedException](
message = "Unsupported result set type"))
}
"not supported auto-generated keys" in {
"not be created with unsupported resultset concurrency" in {
(defaultCon.prepareStatement("TEST", TYPE_FORWARD_ONLY, CONCUR_UPDATABLE).
aka("creation") must throwA[SQLFeatureNotSupportedException](
message = "Unsupported result set concurrency")).
and(defaultCon.prepareStatement("TEST",
TYPE_FORWARD_ONLY, CONCUR_UPDATABLE, CLOSE_CURSORS_AT_COMMIT).
aka("creation") must throwA[SQLFeatureNotSupportedException](
message = "Unsupported result set concurrency"))
}
"not be created with unsupported resultset holdability" in {
defaultCon.prepareStatement("TEST",
TYPE_FORWARD_ONLY, CONCUR_READ_ONLY, HOLD_CURSORS_OVER_COMMIT).
aka("creation") must throwA[SQLFeatureNotSupportedException](
message = "Unsupported result set holdability")
}
"not support auto-generated keys" in {
(defaultCon.prepareStatement("TEST", Array[Int]()).
aka("creation") must throwA[SQLFeatureNotSupportedException]).
and(defaultCon.prepareStatement("TEST", Array[String]()).
@@ -591,25 +667,58 @@ object ConnectionSpec extends Specification with ConnectionFixtures {
"be owned by connection" in {
lazy val c = defaultCon
c.prepareCall("TEST").getConnection.
aka("statement connection") mustEqual c
(c.prepareCall("TEST").getConnection.
aka("statement connection") mustEqual c).
and(c.prepareCall("TEST", TYPE_FORWARD_ONLY, CONCUR_READ_ONLY).
getConnection aka "statement connection" mustEqual c).
and(c.prepareCall("TEST",
TYPE_FORWARD_ONLY, CONCUR_READ_ONLY, CLOSE_CURSORS_AT_COMMIT).
getConnection aka "statement connection" mustEqual c)
}
"not be created from a closed connection" in {
lazy val c = defaultCon
c.close()
c.prepareCall("TEST") aka "creation" must throwA[SQLException](
message = "Connection is closed")
(c.prepareCall("TEST") aka "creation" must throwA[SQLException](
message = "Connection is closed")).
and(c.prepareCall("TEST", TYPE_FORWARD_ONLY, CONCUR_READ_ONLY).
aka("creation") must throwA[SQLException]("Connection is closed")).
and(c.prepareCall("TEST",
TYPE_FORWARD_ONLY, CONCUR_READ_ONLY, CLOSE_CURSORS_AT_COMMIT).
aka("creation") must throwA[SQLException]("Connection is closed"))
}
"not be created with specific resultset type and/or concurrency" in {
(defaultCon.prepareCall("TEST", 1, 2).
aka("creation") must throwA[SQLFeatureNotSupportedException]).
and(defaultCon.prepareCall("TEST", 1, 2, 3).
aka("creation") must throwA[SQLFeatureNotSupportedException])
"not be created with unsupported resultset type" in {
(defaultCon.prepareCall("TEST",
TYPE_SCROLL_INSENSITIVE, CONCUR_READ_ONLY).
aka("creation") must throwA[SQLFeatureNotSupportedException](
message = "Unsupported result set type")).
and(defaultCon.prepareCall("TEST",
TYPE_SCROLL_INSENSITIVE, CONCUR_READ_ONLY, CLOSE_CURSORS_AT_COMMIT).
aka("creation") must throwA[SQLFeatureNotSupportedException](
message = "Unsupported result set type"))
}
"not be created with unsupported resultset concurrency" in {
(defaultCon.prepareCall("TEST", TYPE_FORWARD_ONLY, CONCUR_UPDATABLE).
aka("creation") must throwA[SQLFeatureNotSupportedException](
message = "Unsupported result set concurrency")).
and(defaultCon.prepareCall("TEST",
TYPE_FORWARD_ONLY, CONCUR_UPDATABLE, CLOSE_CURSORS_AT_COMMIT).
aka("creation") must throwA[SQLFeatureNotSupportedException](
message = "Unsupported result set concurrency"))
}
"not be created with unsupported resultset holdability" in {
defaultCon.prepareCall("TEST",
TYPE_FORWARD_ONLY, CONCUR_READ_ONLY, HOLD_CURSORS_OVER_COMMIT).
aka("creation") must throwA[SQLFeatureNotSupportedException](
message = "Unsupported result set holdability")
}
}

0 comments on commit 44f9c1e

Please sign in to comment.