Permalink
Browse files

[jdbc-driver] Make warning of query result accessible on raised Resul…

…tSet
  • Loading branch information...
cchantep
cchantep committed May 25, 2014
1 parent 77611ac commit f4acc2dc143f0f584b9142c096e0194a91ad8bb9
@@ -162,9 +162,9 @@ public ResultSet executeQuery(final String sql) throws SQLException {
final QueryResult res = this.handler.whenSQLQuery(sql, NO_PARAMS);
this.warning = res.getWarning();
-
- return (this.result = res.getRowList().
- resultSet(this.maxRows).withStatement(this));
+
+ return (this.result = res.getRowList().resultSet(this.maxRows).
+ withStatement(this).withWarning(this.warning));
} catch (SQLException se) {
throw se;
@@ -178,8 +178,8 @@ public ResultSet executeQuery() throws SQLException {
this.warning = res.getWarning();
this.generatedKeys = EMPTY_GENERATED_KEYS.withStatement(this);
- return (this.result =
- res.getRowList().resultSet().withStatement(this));
+ return (this.result = res.getRowList().resultSet().
+ withStatement(this).withWarning(this.warning));
} catch (SQLException se) {
throw se;
@@ -11,6 +11,7 @@
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
+import java.sql.SQLWarning;
import java.sql.Statement;
import java.sql.Timestamp;
import java.sql.Date;
@@ -227,6 +228,7 @@ public NilRowList withNullable(final int columnIndex,
final Map<String,Integer> columnLabels;
final List<R> rows;
final Statement statement;
+ final SQLWarning warning;
private Object last;
// --- Constructors ---
@@ -244,6 +246,7 @@ protected RowResultSet(final List<R> rows) {
this.columnLabels = getColumnLabels();
this.rows = Collections.unmodifiableList(rows);
this.statement = null; // dettached
+ this.warning = null;
this.last = null;
super.fetchSize = rows.size();
} // end of <init>
@@ -253,7 +256,8 @@ protected RowResultSet(final List<R> rows) {
*/
private RowResultSet(final List<R> rows,
final Object last,
- final Statement statement) {
+ final Statement statement,
+ final SQLWarning warning) {
if (rows == null) {
// Impossible
@@ -265,6 +269,7 @@ private RowResultSet(final List<R> rows,
this.rows = Collections.unmodifiableList(rows);
this.statement = statement;
+ this.warning = warning;
this.last = null;
super.fetchSize = rows.size();
} // end of <init>
@@ -275,9 +280,27 @@ private RowResultSet(final List<R> rows,
* Returns updated resultset, attached with given |statement|.
*/
public RowResultSet<R> withStatement(final Statement statement) {
- return new RowResultSet<R>(this.rows, this.last, statement);
+ return new RowResultSet<R>(this.rows, this.last,
+ statement, this.warning);
+
} // end of withStatement
+ /**
+ * Returns updated resultset, with given |warning|.
+ */
+ public RowResultSet<R> withWarning(final SQLWarning warning) {
+ return new RowResultSet<R>(this.rows, this.last,
+ this.statement, warning);
+
+ } // end of withWarning
+
+ /**
+ * {@inheritDoc}
+ */
+ public SQLWarning getWarnings() throws SQLException {
+ return this.warning;
+ } // end of getWarnings
+
/**
* {@inheritDoc}
*/
@@ -262,12 +262,6 @@ object AbstractStatementSpec extends Specification {
}
}
- "Warning" should {
- "initially be null" in {
- statement().getWarnings aka "warning" must beNull
- }
- }
-
"Fetch size" should {
"initially be zero" in {
statement().getFetchSize aka "initial size" mustEqual 0
@@ -483,6 +477,10 @@ object AbstractStatementSpec extends Specification {
"Warning" should {
lazy val warning = new java.sql.SQLWarning("TEST")
+ "initially be null" in {
+ statement().getWarnings aka "warning" must beNull
+ }
+
"be found for query" in {
lazy val h = new StatementHandler {
def isQuery(s: String) = true
@@ -495,7 +493,10 @@ object AbstractStatementSpec extends Specification {
lazy val s = statement(h = h)
s.executeQuery("TEST")
- s.getWarnings aka "warning" mustEqual warning
+ (s.getWarnings aka "warning" mustEqual warning).
+ and(Option(s.getResultSet) aka "resultset" must beSome.which {
+ _.getWarnings aka "result warning" mustEqual warning
+ })
}
"be found for update" in {
@@ -1424,7 +1424,11 @@ trait StatementSpecification[S <: PreparedStatement] extends Setters {
lazy val s = statement(h = h)
s.executeQuery("TEST")
- s.getWarnings aka "warning" mustEqual warning
+ (s.getWarnings aka "warning" mustEqual warning).
+ and(Option(s.getResultSet) aka "resultset" must beSome.which {
+ _.getWarnings aka "result warning" mustEqual warning
+ })
+
}
"be found for update" in {
View
@@ -9,7 +9,7 @@ object Acolyte extends Build with Dependencies
aggregate(jdbcDriver, scalacPlugin, jdbcScala, studio).
settings(
organization in ThisBuild := "org.eu.acolyte",
- version in ThisBuild := "1.0.18",
+ version in ThisBuild := "1.0.18-1",
javaOptions in ThisBuild ++= Seq("-source", "1.6", "-target", "1.6"),
scalaVersion in ThisBuild := "2.10.4",
crossScalaVersions in ThisBuild := Seq("2.10.4", "2.11.0"),

0 comments on commit f4acc2d

Please sign in to comment.