Author: rvesse
Date: Mon Aug 26 23:06:53 2013
New Revision: 1517724
URL: http://svn.apache.org/r1517724
Log:
Fix for a test clean up bug that was highlighted by the JENA-522 changes
Modified:
jena/trunk/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/connections/DatasetConnection.java
jena/trunk/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/connections/JenaConnection.java
jena/trunk/jena-jdbc/jena-jdbc-driver-tdb/src/test/java/org/apache/jena/jdbc/tdb/results/AbstractTdbResultSetTests.java
Modified:
jena/trunk/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/connections/DatasetConnection.java
URL:
http://svn.apache.org/viewvc/jena/trunk/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/connections/DatasetConnection.java?rev=1517724&r1=1517723&r2=1517724&view=diff
==============================================================================
---
jena/trunk/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/connections/DatasetConnection.java
(original)
+++
jena/trunk/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/connections/DatasetConnection.java
Mon Aug 26 23:06:53 2013
@@ -18,6 +18,7 @@
package org.apache.jena.jdbc.connections;
+import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
@@ -79,6 +80,7 @@ public abstract class DatasetConnection
try {
if (this.ds != null) {
ds.close();
+ ds = null;
}
} catch (Exception e) {
throw new SQLException("Unexpected error closing a dataset backed
connection", e);
@@ -138,8 +140,9 @@ public abstract class DatasetConnection
return;
case TRANSACTION_SERIALIZABLE:
// Serializable is supported if the dataset supports transactions
- if (this.ds.supportsTransactions())
- return;
+ if (this.ds != null)
+ if (this.ds.supportsTransactions())
+ return;
// Otherwise we'll drop through and throw the error
default:
throw new SQLException(String.format("The Transaction level %d is
not supported by this connection", level));
@@ -160,6 +163,10 @@ public abstract class DatasetConnection
*/
public synchronized void begin(ReadWrite type) throws SQLException {
try {
+ if (this.isClosed())
+ throw new SQLException("Cannot start a transaction on a closed
connection");
+ if (this.getTransactionIsolation() == Connection.TRANSACTION_NONE)
+ throw new SQLException("Cannot start a transaction when
transaction isolation is set to NONE");
if (ds.supportsTransactions()) {
if (ds.isInTransaction()) {
// Additional participant in existing transaction
Modified:
jena/trunk/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/connections/JenaConnection.java
URL:
http://svn.apache.org/viewvc/jena/trunk/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/connections/JenaConnection.java?rev=1517724&r1=1517723&r2=1517724&view=diff
==============================================================================
---
jena/trunk/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/connections/JenaConnection.java
(original)
+++
jena/trunk/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/connections/JenaConnection.java
Mon Aug 26 23:06:53 2013
@@ -342,7 +342,7 @@ public abstract class JenaConnection imp
* @param results
* Results
* @return Results after processing by registered post-processors
- * @throws SQLException
+ * @throws SQLException
*/
public final com.hp.hpl.jena.query.ResultSet
applyPostProcessors(com.hp.hpl.jena.query.ResultSet results) throws
SQLException {
for (ResultsPostProcessor postProcessor : this.postProcessors) {
@@ -359,7 +359,7 @@ public abstract class JenaConnection imp
* @param triples
* Results
* @return Results after processing by registered post-processors
- * @throws SQLException
+ * @throws SQLException
*/
public final Iterator<Triple> applyPostProcessors(Iterator<Triple>
triples) throws SQLException {
for (ResultsPostProcessor postProcessor : this.postProcessors) {
@@ -376,7 +376,7 @@ public abstract class JenaConnection imp
* @param result
* Result
* @return Result after processing by registered post-processors
- * @throws SQLException
+ * @throws SQLException
*/
public final boolean applyPostProcessors(boolean result) throws
SQLException {
for (ResultsPostProcessor postProcessor : this.postProcessors) {
@@ -393,7 +393,7 @@ public abstract class JenaConnection imp
* @param metadata
* Results metadata
* @return Results metadata after processing by registered post-processors
- * @throws SQLException
+ * @throws SQLException
*/
public final SelectResultsMetadata
applyPostProcessors(SelectResultsMetadata metadata) throws SQLException {
for (ResultsPostProcessor postProcessor : this.postProcessors) {
@@ -410,7 +410,7 @@ public abstract class JenaConnection imp
* @param metadata
* Results metadata
* @return Results metadata after processing by registered post-processors
- * @throws SQLException
+ * @throws SQLException
*/
public final TripleResultsMetadata
applyPostProcessors(TripleResultsMetadata metadata) throws SQLException {
for (ResultsPostProcessor postProcessor : this.postProcessors) {
@@ -427,7 +427,7 @@ public abstract class JenaConnection imp
* @param metadata
* Results metadata
* @return Results metadata after processing by registered post-processors
- * @throws SQLException
+ * @throws SQLException
*/
public final AskResultsMetadata applyPostProcessors(AskResultsMetadata
metadata) throws SQLException {
for (ResultsPostProcessor postProcessor : this.postProcessors) {
Modified:
jena/trunk/jena-jdbc/jena-jdbc-driver-tdb/src/test/java/org/apache/jena/jdbc/tdb/results/AbstractTdbResultSetTests.java
URL:
http://svn.apache.org/viewvc/jena/trunk/jena-jdbc/jena-jdbc-driver-tdb/src/test/java/org/apache/jena/jdbc/tdb/results/AbstractTdbResultSetTests.java?rev=1517724&r1=1517723&r2=1517724&view=diff
==============================================================================
---
jena/trunk/jena-jdbc/jena-jdbc-driver-tdb/src/test/java/org/apache/jena/jdbc/tdb/results/AbstractTdbResultSetTests.java
(original)
+++
jena/trunk/jena-jdbc/jena-jdbc-driver-tdb/src/test/java/org/apache/jena/jdbc/tdb/results/AbstractTdbResultSetTests.java
Mon Aug 26 23:06:53 2013
@@ -29,11 +29,12 @@ import org.junit.AfterClass;
import org.junit.BeforeClass;
import com.hp.hpl.jena.query.Dataset;
+import com.hp.hpl.jena.query.DatasetFactory;
import com.hp.hpl.jena.vocabulary.XSD;
/**
* Abstract
- *
+ *
*/
public abstract class AbstractTdbResultSetTests extends AbstractResultSetTests
{
@@ -41,6 +42,7 @@ public abstract class AbstractTdbResultS
/**
* Sets up the tests by creating a fake connection for test use
+ *
* @throws SQLException
*/
@BeforeClass
@@ -52,35 +54,44 @@ public abstract class AbstractTdbResultS
/**
* Cleans up after the tests by closing the fake connection
+ *
* @throws SQLException
*/
@AfterClass
public static void teardown() throws SQLException {
+ // The derived test harnesses actually change the dataset behind the
+ // scenes and so we need a temporary fake final dataset for closing the
+ // connection or we get an error that the underlying dataset is already
+ // closed
+ connection.setJenaDataset(DatasetFactory.createMem());
connection.close();
}
/**
- * Method which derived test classes must implement which they can use to
turn
- * the provided dataset (which will be a memory dataset) into the actual
- * dataset they want to test against
- * @param ds Dataset
+ * Method which derived test classes must implement which they can use to
+ * turn the provided dataset (which will be a memory dataset) into the
+ * actual dataset they want to test against
+ *
+ * @param ds
+ * Dataset
* @return Prepared Dataset
- * @throws SQLException Thrown if the dataset cannot be prepared
+ * @throws SQLException
+ * Thrown if the dataset cannot be prepared
*/
protected abstract Dataset prepareDataset(Dataset ds) throws SQLException;
-
+
@Override
protected final ResultSet createResults(Dataset ds, String query) throws
SQLException {
return createResults(ds, query, ResultSet.TYPE_FORWARD_ONLY);
}
-
+
@Override
protected final ResultSet createResults(Dataset ds, String query, int
resultSetType) throws SQLException {
connection.setJenaDataset(this.prepareDataset(ds));
Statement stmt = connection.createStatement(resultSetType,
ResultSet.CONCUR_READ_ONLY);
return stmt.executeQuery(query);
}
-
+
@Override
protected String getIntegerTypeUri() {
return XSD.integer.toString();