jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rve...@apache.org
Subject svn commit: r1463773 - in /jena/Experimental/jena-jdbc: jena-jdbc-core/src/main/java/org/apache/jena/jdbc/results/ jena-jdbc-core/src/main/java/org/apache/jena/jdbc/results/metadata/ jena-jdbc-core/src/test/java/org/apache/jena/jdbc/ jena-jdbc-core/src...
Date Tue, 02 Apr 2013 21:58:54 GMT
Author: rvesse
Date: Tue Apr  2 21:58:54 2013
New Revision: 1463773

URL: http://svn.apache.org/r1463773
Log:
Expand result set tests to cover both CONSTRUCT queries, test clean up fix to some TDB tests
to avoid a OOM error

Modified:
    jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/results/TripleIteratorResults.java
    jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/results/metadata/TripleResultsMetadata.java
    jena/Experimental/jena-jdbc/jena-jdbc-core/src/test/java/org/apache/jena/jdbc/AbstractJenaJdbcConnectionTests.java
    jena/Experimental/jena-jdbc/jena-jdbc-core/src/test/java/org/apache/jena/jdbc/results/AbstractResultSetTests.java
    jena/Experimental/jena-jdbc/jena-jdbc-driver-tdb/src/test/java/org/apache/jena/jdbc/tdb/results/TestTdbDiskResultSets.java
    jena/Experimental/jena-jdbc/jena-jdbc-driver-tdb/src/test/java/org/apache/jena/jdbc/tdb/results/TestTdbMemResultSets.java

Modified: jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/results/TripleIteratorResults.java
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/results/TripleIteratorResults.java?rev=1463773&r1=1463772&r2=1463773&view=diff
==============================================================================
--- jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/results/TripleIteratorResults.java
(original)
+++ jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/results/TripleIteratorResults.java
Tue Apr  2 21:58:54 2013
@@ -39,24 +39,6 @@ public class TripleIteratorResults exten
 
     private static final TripleResultsMetadata metadata = new TripleResultsMetadata();
     
-    /**
-     * Constant for the number of columns in triple results
-     */
-    public static final int NUM_COLUMNS = 3;
-
-    /**
-     * Constant for the subject column label
-     */
-    public static final String COLUMN_LABEL_SUBJECT = "Subject";
-    /**
-     * Constant for the predicate column label
-     */
-    public static final String COLUMN_LABEL_PREDICATE = "Predicate";
-    /**
-     * Constant for the object column label
-     */
-    public static final String COLUMN_LABEL_OBJECT = "Object";
-
     private Iterator<Triple> triples;
 
     /**
@@ -79,11 +61,11 @@ public class TripleIteratorResults exten
     }
 
     public int findColumn(String columnLabel) throws SQLException {
-        if (COLUMN_LABEL_SUBJECT.equals(columnLabel)) {
+        if (TripleResultsMetadata.COLUMN_LABEL_SUBJECT.equals(columnLabel)) {
             return 1;
-        } else if (COLUMN_LABEL_PREDICATE.equals(columnLabel)) {
+        } else if (TripleResultsMetadata.COLUMN_LABEL_PREDICATE.equals(columnLabel)) {
             return 2;
-        } else if (COLUMN_LABEL_OBJECT.equals(columnLabel)) {
+        } else if (TripleResultsMetadata.COLUMN_LABEL_OBJECT.equals(columnLabel)) {
             return 3;
         } else {
             throw new SQLException("Column " + columnLabel + " does not exist in these results");
@@ -121,14 +103,14 @@ public class TripleIteratorResults exten
     protected String findColumnLabel(int columnIndex) throws SQLException {
         if (this.isClosed())
             throw new SQLException("Result Set is closed");
-        if (columnIndex >= 1 && columnIndex <= NUM_COLUMNS) {
+        if (columnIndex >= 1 && columnIndex <= TripleResultsMetadata.NUM_COLUMNS)
{
             switch (columnIndex) {
             case 1:
-                return COLUMN_LABEL_SUBJECT;
+                return TripleResultsMetadata.COLUMN_LABEL_SUBJECT;
             case 2:
-                return COLUMN_LABEL_PREDICATE;
+                return TripleResultsMetadata.COLUMN_LABEL_PREDICATE;
             case 3:
-                return COLUMN_LABEL_OBJECT;
+                return TripleResultsMetadata.COLUMN_LABEL_OBJECT;
             default:
                 throw new SQLException("Column Index is out of bounds");
             }
@@ -144,11 +126,11 @@ public class TripleIteratorResults exten
         if (this.getCurrentRow() == null)
             throw new SQLException("Not currently at a row");
         Triple t = this.getCurrentRow();
-        if (COLUMN_LABEL_SUBJECT.equals(columnLabel)) {
+        if (TripleResultsMetadata.COLUMN_LABEL_SUBJECT.equals(columnLabel)) {
             return t.getSubject();
-        } else if (COLUMN_LABEL_PREDICATE.equals(columnLabel)) {
+        } else if (TripleResultsMetadata.COLUMN_LABEL_PREDICATE.equals(columnLabel)) {
             return t.getPredicate();
-        } else if (COLUMN_LABEL_OBJECT.equals(columnLabel)) {
+        } else if (TripleResultsMetadata.COLUMN_LABEL_OBJECT.equals(columnLabel)) {
             return t.getObject();
         } else {
             throw new SQLException("Unknown column label");

Modified: jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/results/metadata/TripleResultsMetadata.java
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/results/metadata/TripleResultsMetadata.java?rev=1463773&r1=1463772&r2=1463773&view=diff
==============================================================================
--- jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/results/metadata/TripleResultsMetadata.java
(original)
+++ jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/results/metadata/TripleResultsMetadata.java
Tue Apr  2 21:58:54 2013
@@ -28,20 +28,37 @@ import org.apache.jena.jdbc.results.Trip
  */
 public class TripleResultsMetadata extends JenaJdbcResultsMetadata {
 
+    /**
+     * Constant for the subject column label
+     */
+    public static final String COLUMN_LABEL_SUBJECT = "Subject";
+    /**
+     * Constant for the predicate column label
+     */
+    public static final String COLUMN_LABEL_PREDICATE = "Predicate";
+    /**
+     * Constant for the object column label
+     */
+    public static final String COLUMN_LABEL_OBJECT = "Object";
+    /**
+     * Constant for the number of columns in triple results
+     */
+    public static final int NUM_COLUMNS = 3;
+
     @Override
     public int getColumnCount() throws SQLException {
-        return TripleIteratorResults.NUM_COLUMNS;
+        return TripleResultsMetadata.NUM_COLUMNS;
     }
 
     @Override
     public String getColumnLabel(int column) throws SQLException {
         switch (column) {
         case 1:
-            return TripleIteratorResults.COLUMN_LABEL_SUBJECT;
+            return TripleResultsMetadata.COLUMN_LABEL_SUBJECT;
         case 2:
-            return TripleIteratorResults.COLUMN_LABEL_PREDICATE;
+            return TripleResultsMetadata.COLUMN_LABEL_PREDICATE;
         case 3:
-            return TripleIteratorResults.COLUMN_LABEL_OBJECT;
+            return TripleResultsMetadata.COLUMN_LABEL_OBJECT;
         default:
             throw new SQLException("Column Index is out of bounds");
         }

Modified: jena/Experimental/jena-jdbc/jena-jdbc-core/src/test/java/org/apache/jena/jdbc/AbstractJenaJdbcConnectionTests.java
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-jdbc/jena-jdbc-core/src/test/java/org/apache/jena/jdbc/AbstractJenaJdbcConnectionTests.java?rev=1463773&r1=1463772&r2=1463773&view=diff
==============================================================================
--- jena/Experimental/jena-jdbc/jena-jdbc-core/src/test/java/org/apache/jena/jdbc/AbstractJenaJdbcConnectionTests.java
(original)
+++ jena/Experimental/jena-jdbc/jena-jdbc-core/src/test/java/org/apache/jena/jdbc/AbstractJenaJdbcConnectionTests.java
Tue Apr  2 21:58:54 2013
@@ -23,7 +23,7 @@ import java.sql.SQLException;
 import java.sql.Statement;
 import java.sql.Types;
 
-import org.apache.jena.jdbc.results.TripleIteratorResults;
+import org.apache.jena.jdbc.results.metadata.TripleResultsMetadata;
 import org.apache.log4j.BasicConfigurator;
 import org.apache.log4j.Level;
 import org.apache.log4j.Logger;
@@ -459,7 +459,7 @@ public abstract class AbstractJenaJdbcCo
         // Check result set metadata
         ResultSetMetaData metadata = results.getMetaData();
         Assert.assertEquals(3, metadata.getColumnCount());
-        for (int i = 1; i <= TripleIteratorResults.NUM_COLUMNS; i++) {
+        for (int i = 1; i <= TripleResultsMetadata.NUM_COLUMNS; i++) {
             Assert.assertEquals(Node.class.getCanonicalName(), metadata.getColumnClassName(i));
             Assert.assertEquals(Node.class.getCanonicalName(), metadata.getColumnTypeName(i));
             Assert.assertEquals(Types.JAVA_OBJECT, metadata.getColumnType(i));

Modified: jena/Experimental/jena-jdbc/jena-jdbc-core/src/test/java/org/apache/jena/jdbc/results/AbstractResultSetTests.java
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-jdbc/jena-jdbc-core/src/test/java/org/apache/jena/jdbc/results/AbstractResultSetTests.java?rev=1463773&r1=1463772&r2=1463773&view=diff
==============================================================================
--- jena/Experimental/jena-jdbc/jena-jdbc-core/src/test/java/org/apache/jena/jdbc/results/AbstractResultSetTests.java
(original)
+++ jena/Experimental/jena-jdbc/jena-jdbc-core/src/test/java/org/apache/jena/jdbc/results/AbstractResultSetTests.java
Tue Apr  2 21:58:54 2013
@@ -24,6 +24,7 @@ import java.sql.SQLException;
 import java.util.Calendar;
 
 import org.apache.jena.jdbc.results.metadata.AskResultsMetadata;
+import org.apache.jena.jdbc.results.metadata.TripleResultsMetadata;
 import org.apache.log4j.BasicConfigurator;
 import org.apache.log4j.Level;
 import org.apache.log4j.Logger;
@@ -238,6 +239,54 @@ public abstract class AbstractResultSetT
     }
 
     /**
+     * Tests that CONSTRUCT result values can be marshalled to strings OK
+     * 
+     * @throws SQLException
+     */
+    @Test
+    public void test_results_construct_strings_01() throws SQLException {
+        ResultSet rset = this.createResults(ds,
+                "CONSTRUCT { ?s ?p ?str } WHERE { ?s ?p ?o . FILTER(!ISBLANK(?o)) . BIND(STR(?o)
AS ?str) }");
+        Assert.assertFalse(rset.isClosed());
+        Assert.assertTrue(rset.isBeforeFirst());
+        Assert.assertFalse(rset.isLast());
+
+        // Check all rows allow us to marshal strings OK
+        while (rset.next()) {
+            Assert.assertNotNull(rset.getString(TripleResultsMetadata.COLUMN_LABEL_OBJECT));
+            Assert.assertFalse(rset.wasNull());
+        }
+
+        Assert.assertTrue(rset.isAfterLast());
+        rset.close();
+        Assert.assertTrue(rset.isClosed());
+    }
+
+    /**
+     * Tests that CONSTRUCT result values can be marshalled to strings OK
+     * 
+     * @throws SQLException
+     */
+    @Test
+    public void test_results_construct_strings_02() throws SQLException {
+        ResultSet rset = this.createResults(ds,
+                "CONSTRUCT { ?s ?p ?str } WHERE { ?s ?p ?o . FILTER(!ISBLANK(?o)) . BIND(STR(?o)
AS ?str) }");
+        Assert.assertFalse(rset.isClosed());
+        Assert.assertTrue(rset.isBeforeFirst());
+        Assert.assertFalse(rset.isLast());
+
+        // Check all rows allow us to marshal strings OK
+        while (rset.next()) {
+            Assert.assertNotNull(rset.getNString(TripleResultsMetadata.COLUMN_LABEL_OBJECT));
+            Assert.assertFalse(rset.wasNull());
+        }
+
+        Assert.assertTrue(rset.isAfterLast());
+        rset.close();
+        Assert.assertTrue(rset.isClosed());
+    }
+
+    /**
      * Tests that SELECT result values can be marshalled to numerics OK
      * 
      * @throws SQLException
@@ -265,6 +314,33 @@ public abstract class AbstractResultSetT
     }
 
     /**
+     * Tests that CONSTRUCT result values can be marshalled to numerics OK
+     * 
+     * @throws SQLException
+     */
+    @Test
+    public void test_results_construct_numerics() throws SQLException {
+        ResultSet rset = this.createResults(ds, "CONSTRUCT { ?s ?p ?o } WHERE { ?s ?p ?o
. FILTER(ISNUMERIC(?o)) }");
+        Assert.assertFalse(rset.isClosed());
+        Assert.assertTrue(rset.isBeforeFirst());
+        Assert.assertFalse(rset.isLast());
+
+        // Check all rows allow us to marshal big decimal OK
+        BigDecimal zero = new BigDecimal(0);
+        while (rset.next()) {
+            Assert.assertNotNull(rset.getString(TripleResultsMetadata.COLUMN_LABEL_OBJECT));
+            // Use decimal since all numeric types should be promotable to
+            // decimal
+            Assert.assertFalse(rset.getBigDecimal(TripleResultsMetadata.COLUMN_LABEL_OBJECT).equals(zero));
+            Assert.assertFalse(rset.wasNull());
+        }
+
+        Assert.assertTrue(rset.isAfterLast());
+        rset.close();
+        Assert.assertTrue(rset.isClosed());
+    }
+
+    /**
      * Tests that SELECT result values can be marshalled to integers OK
      * 
      * @throws SQLException
@@ -290,6 +366,31 @@ public abstract class AbstractResultSetT
     }
 
     /**
+     * Tests that CONSTRUCT result values can be marshalled to integers OK
+     * 
+     * @throws SQLException
+     */
+    @Test
+    public void test_results_construct_integers() throws SQLException {
+        ResultSet rset = this.createResults(ds,
+                "CONSTRUCT { ?s ?p ?o } WHERE { ?s ?p ?o . FILTER(DATATYPE(?o) = <" +
this.getIntegerTypeUri() + ">) }");
+        Assert.assertFalse(rset.isClosed());
+        Assert.assertTrue(rset.isBeforeFirst());
+        Assert.assertFalse(rset.isLast());
+
+        // Check all rows allow us to marshal integers OK
+        while (rset.next()) {
+            Assert.assertNotNull(rset.getString(TripleResultsMetadata.COLUMN_LABEL_OBJECT));
+            Assert.assertFalse(0 == rset.getInt(TripleResultsMetadata.COLUMN_LABEL_OBJECT));
+            Assert.assertFalse(rset.wasNull());
+        }
+
+        Assert.assertTrue(rset.isAfterLast());
+        rset.close();
+        Assert.assertTrue(rset.isClosed());
+    }
+
+    /**
      * Tests that SELECT result values can be marshalled to bytes OK
      * 
      * @throws SQLException
@@ -315,6 +416,32 @@ public abstract class AbstractResultSetT
     }
 
     /**
+     * Tests that CONSTRUCT result values can be marshalled to bytes OK
+     * 
+     * @throws SQLException
+     */
+    @Test
+    public void test_results_construct_bytes() throws SQLException {
+        ResultSet rset = this
+                .createResults(ds, "CONSTRUCT { ?s ?p ?o } WHERE { ?s ?p ?o . FILTER(DATATYPE(?o)
= <" + this.getByteTypeUri()
+                        + "> && ?o <= 255) }");
+        Assert.assertFalse(rset.isClosed());
+        Assert.assertTrue(rset.isBeforeFirst());
+        Assert.assertFalse(rset.isLast());
+
+        // Check all rows allow us to marshal bytes OK
+        while (rset.next()) {
+            Assert.assertNotNull(rset.getString(TripleResultsMetadata.COLUMN_LABEL_OBJECT));
+            Assert.assertFalse((byte) 0 == rset.getByte(TripleResultsMetadata.COLUMN_LABEL_OBJECT));
+            Assert.assertFalse(rset.wasNull());
+        }
+
+        Assert.assertTrue(rset.isAfterLast());
+        rset.close();
+        Assert.assertTrue(rset.isClosed());
+    }
+
+    /**
      * Tests that SELECT result values can be marshalled to floats OK
      * 
      * @throws SQLException
@@ -340,6 +467,31 @@ public abstract class AbstractResultSetT
     }
 
     /**
+     * Tests that CONSTRUCT result values can be marshalled to floats OK
+     * 
+     * @throws SQLException
+     */
+    @Test
+    public void test_results_construct_floats() throws SQLException {
+        ResultSet rset = this.createResults(ds,
+                "CONSTRUCT { ?s ?p ?o } WHERE { ?s ?p ?o . FILTER(DATATYPE(?o) = <" +
XSD.xfloat.toString() + ">) }");
+        Assert.assertFalse(rset.isClosed());
+        Assert.assertTrue(rset.isBeforeFirst());
+        Assert.assertFalse(rset.isLast());
+
+        // Check all rows allow us to marshal floats OK
+        while (rset.next()) {
+            Assert.assertNotNull(rset.getString(TripleResultsMetadata.COLUMN_LABEL_OBJECT));
+            Assert.assertFalse(0f == rset.getFloat(TripleResultsMetadata.COLUMN_LABEL_OBJECT));
+            Assert.assertFalse(rset.wasNull());
+        }
+
+        Assert.assertTrue(rset.isAfterLast());
+        rset.close();
+        Assert.assertTrue(rset.isClosed());
+    }
+
+    /**
      * Tests that SELECT result values can be marshalled to doubles OK
      * 
      * @throws SQLException
@@ -365,6 +517,31 @@ public abstract class AbstractResultSetT
     }
 
     /**
+     * Tests that CONSTRUCT result values can be marshalled to doubles OK
+     * 
+     * @throws SQLException
+     */
+    @Test
+    public void test_results_construct_doubles() throws SQLException {
+        ResultSet rset = this.createResults(ds,
+                "CONSTRUCT { ?s ?p ?o } WHERE { ?s ?p ?o . FILTER(DATATYPE(?o) = <" +
XSD.xdouble.toString() + ">) }");
+        Assert.assertFalse(rset.isClosed());
+        Assert.assertTrue(rset.isBeforeFirst());
+        Assert.assertFalse(rset.isLast());
+
+        // Check all rows allow us to marshal doubles OK
+        while (rset.next()) {
+            Assert.assertNotNull(rset.getString(TripleResultsMetadata.COLUMN_LABEL_OBJECT));
+            Assert.assertFalse(0d == rset.getDouble(TripleResultsMetadata.COLUMN_LABEL_OBJECT));
+            Assert.assertFalse(rset.wasNull());
+        }
+
+        Assert.assertTrue(rset.isAfterLast());
+        rset.close();
+        Assert.assertTrue(rset.isClosed());
+    }
+
+    /**
      * Tests that SELECT result values can be marshalled to longs OK
      * 
      * @throws SQLException
@@ -390,6 +567,31 @@ public abstract class AbstractResultSetT
     }
 
     /**
+     * Tests that CONSTRUCT result values can be marshalled to longs OK
+     * 
+     * @throws SQLException
+     */
+    @Test
+    public void test_results_construct_longs() throws SQLException {
+        ResultSet rset = this.createResults(ds,
+                "CONSTRUCT { ?s ?p ?o } WHERE { ?s ?p ?o . FILTER(DATATYPE(?o) = <" +
this.getLongTypeUri() + ">) }");
+        Assert.assertFalse(rset.isClosed());
+        Assert.assertTrue(rset.isBeforeFirst());
+        Assert.assertFalse(rset.isLast());
+
+        // Check all rows allow us to marshal longs OK
+        while (rset.next()) {
+            Assert.assertNotNull(rset.getString(TripleResultsMetadata.COLUMN_LABEL_OBJECT));
+            Assert.assertFalse(0l == rset.getLong(TripleResultsMetadata.COLUMN_LABEL_OBJECT));
+            Assert.assertFalse(rset.wasNull());
+        }
+
+        Assert.assertTrue(rset.isAfterLast());
+        rset.close();
+        Assert.assertTrue(rset.isClosed());
+    }
+
+    /**
      * Tests that SELECT result values can be marshalled to shorts OK
      * 
      * @throws SQLException
@@ -413,7 +615,32 @@ public abstract class AbstractResultSetT
         rset.close();
         Assert.assertTrue(rset.isClosed());
     }
-    
+
+    /**
+     * Tests that SELECT result values can be marshalled to shorts OK
+     * 
+     * @throws SQLException
+     */
+    @Test
+    public void test_results_construct_shorts() throws SQLException {
+        ResultSet rset = this.createResults(ds,
+                "CONSTRUCT { ?s ?p ?o } WHERE { ?s ?p ?o . FILTER(DATATYPE(?o) = <" +
this.getShortTypeUri() + ">) }");
+        Assert.assertFalse(rset.isClosed());
+        Assert.assertTrue(rset.isBeforeFirst());
+        Assert.assertFalse(rset.isLast());
+
+        // Check all rows allow us to marshal shorts OK
+        while (rset.next()) {
+            Assert.assertNotNull(rset.getString(TripleResultsMetadata.COLUMN_LABEL_OBJECT));
+            Assert.assertFalse((short) 0 == rset.getShort(TripleResultsMetadata.COLUMN_LABEL_OBJECT));
+            Assert.assertFalse(rset.wasNull());
+        }
+
+        Assert.assertTrue(rset.isAfterLast());
+        rset.close();
+        Assert.assertTrue(rset.isClosed());
+    }
+
     /**
      * Tests that SELECT result values can be marshalled to dates OK
      * 
@@ -421,7 +648,8 @@ public abstract class AbstractResultSetT
      */
     @Test
     public void test_results_select_dates_01() throws SQLException {
-        ResultSet rset = this.createResults(ds, "SELECT ?o { ?s ?p ?o . FILTER(DATATYPE(?o)
= <" + XSD.dateTime.toString() + ">) }");
+        ResultSet rset = this.createResults(ds, "SELECT ?o { ?s ?p ?o . FILTER(DATATYPE(?o)
= <" + XSD.dateTime.toString()
+                + ">) }");
         Assert.assertFalse(rset.isClosed());
         Assert.assertTrue(rset.isBeforeFirst());
         Assert.assertFalse(rset.isLast());
@@ -437,7 +665,7 @@ public abstract class AbstractResultSetT
         rset.close();
         Assert.assertTrue(rset.isClosed());
     }
-    
+
     /**
      * Tests that SELECT result values can be marshalled to dates OK
      * 
@@ -445,7 +673,8 @@ public abstract class AbstractResultSetT
      */
     @Test
     public void test_results_select_dates_02() throws SQLException {
-        ResultSet rset = this.createResults(ds, "SELECT ?o { ?s ?p ?o . FILTER(DATATYPE(?o)
= <" + XSD.dateTime.toString() + ">) }");
+        ResultSet rset = this.createResults(ds, "SELECT ?o { ?s ?p ?o . FILTER(DATATYPE(?o)
= <" + XSD.dateTime.toString()
+                + ">) }");
         Assert.assertFalse(rset.isClosed());
         Assert.assertTrue(rset.isBeforeFirst());
         Assert.assertFalse(rset.isLast());
@@ -461,7 +690,7 @@ public abstract class AbstractResultSetT
         rset.close();
         Assert.assertTrue(rset.isClosed());
     }
-    
+
     /**
      * Tests that SELECT result values can be marshalled to dates OK
      * 
@@ -469,7 +698,8 @@ public abstract class AbstractResultSetT
      */
     @Test
     public void test_results_select_dates_03() throws SQLException {
-        ResultSet rset = this.createResults(ds, "SELECT ?o { ?s ?p ?o . FILTER(DATATYPE(?o)
= <" + XSD.dateTime.toString() + ">) }");
+        ResultSet rset = this.createResults(ds, "SELECT ?o { ?s ?p ?o . FILTER(DATATYPE(?o)
= <" + XSD.dateTime.toString()
+                + ">) }");
         Assert.assertFalse(rset.isClosed());
         Assert.assertTrue(rset.isBeforeFirst());
         Assert.assertFalse(rset.isLast());
@@ -485,4 +715,79 @@ public abstract class AbstractResultSetT
         rset.close();
         Assert.assertTrue(rset.isClosed());
     }
+
+    /**
+     * Tests that CONSTRUCT result values can be marshalled to dates OK
+     * 
+     * @throws SQLException
+     */
+    @Test
+    public void test_results_construct_dates_01() throws SQLException {
+        ResultSet rset = this.createResults(ds, "CONSTRUCT { ?s ?p ?o } WHERE { ?s ?p ?o
. FILTER(DATATYPE(?o) = <"
+                + XSD.dateTime.toString() + ">) }");
+        Assert.assertFalse(rset.isClosed());
+        Assert.assertTrue(rset.isBeforeFirst());
+        Assert.assertFalse(rset.isLast());
+
+        // Check all rows allow us to marshal strings OK
+        while (rset.next()) {
+            Assert.assertNotNull(rset.getString(TripleResultsMetadata.COLUMN_LABEL_OBJECT));
+            Assert.assertNotNull(rset.getDate(TripleResultsMetadata.COLUMN_LABEL_OBJECT));
+            Assert.assertFalse(rset.wasNull());
+        }
+
+        Assert.assertTrue(rset.isAfterLast());
+        rset.close();
+        Assert.assertTrue(rset.isClosed());
+    }
+
+    /**
+     * Tests that CONSTRUCT result values can be marshalled to dates OK
+     * 
+     * @throws SQLException
+     */
+    @Test
+    public void test_results_construct_dates_02() throws SQLException {
+        ResultSet rset = this.createResults(ds, "CONSTRUCT { ?s ?p ?o } WHERE { ?s ?p ?o
. FILTER(DATATYPE(?o) = <"
+                + XSD.dateTime.toString() + ">) }");
+        Assert.assertFalse(rset.isClosed());
+        Assert.assertTrue(rset.isBeforeFirst());
+        Assert.assertFalse(rset.isLast());
+
+        // Check all rows allow us to marshal strings OK
+        while (rset.next()) {
+            Assert.assertNotNull(rset.getString(TripleResultsMetadata.COLUMN_LABEL_OBJECT));
+            Assert.assertNotNull(rset.getTime(TripleResultsMetadata.COLUMN_LABEL_OBJECT));
+            Assert.assertFalse(rset.wasNull());
+        }
+
+        Assert.assertTrue(rset.isAfterLast());
+        rset.close();
+        Assert.assertTrue(rset.isClosed());
+    }
+
+    /**
+     * Tests that CONSTRUCT result values can be marshalled to dates OK
+     * 
+     * @throws SQLException
+     */
+    @Test
+    public void test_results_construct_dates_03() throws SQLException {
+        ResultSet rset = this.createResults(ds, "CONSTRUCT { ?s ?p ?o } WHERE { ?s ?p ?o
. FILTER(DATATYPE(?o) = <"
+                + XSD.dateTime.toString() + ">) }");
+        Assert.assertFalse(rset.isClosed());
+        Assert.assertTrue(rset.isBeforeFirst());
+        Assert.assertFalse(rset.isLast());
+
+        // Check all rows allow us to marshal strings OK
+        while (rset.next()) {
+            Assert.assertNotNull(rset.getString(TripleResultsMetadata.COLUMN_LABEL_OBJECT));
+            Assert.assertNotNull(rset.getTimestamp(TripleResultsMetadata.COLUMN_LABEL_OBJECT));
+            Assert.assertFalse(rset.wasNull());
+        }
+
+        Assert.assertTrue(rset.isAfterLast());
+        rset.close();
+        Assert.assertTrue(rset.isClosed());
+    }
 }

Modified: jena/Experimental/jena-jdbc/jena-jdbc-driver-tdb/src/test/java/org/apache/jena/jdbc/tdb/results/TestTdbDiskResultSets.java
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-jdbc/jena-jdbc-driver-tdb/src/test/java/org/apache/jena/jdbc/tdb/results/TestTdbDiskResultSets.java?rev=1463773&r1=1463772&r2=1463773&view=diff
==============================================================================
--- jena/Experimental/jena-jdbc/jena-jdbc-driver-tdb/src/test/java/org/apache/jena/jdbc/tdb/results/TestTdbDiskResultSets.java
(original)
+++ jena/Experimental/jena-jdbc/jena-jdbc-driver-tdb/src/test/java/org/apache/jena/jdbc/tdb/results/TestTdbDiskResultSets.java
Tue Apr  2 21:58:54 2013
@@ -21,6 +21,7 @@ package org.apache.jena.jdbc.tdb.results
 import java.sql.SQLException;
 
 import org.apache.jena.jdbc.utils.TestUtils;
+import org.junit.After;
 import org.junit.Rule;
 import org.junit.rules.TemporaryFolder;
 
@@ -39,11 +40,23 @@ public class TestTdbDiskResultSets exten
     @Rule
     public TemporaryFolder tempDir = new TemporaryFolder();
 
+    private Dataset currDataset;
+    
+    /**
+     * Cleans up after the tests by ensuring that the TDB dataset is closed
+     */
+    @After
+    public void cleanupTest() {
+        if (currDataset != null) {
+            currDataset.close();
+        }
+    }
     
     @Override
     protected Dataset prepareDataset(Dataset ds) throws SQLException {
         Dataset tdb = TDBFactory.createDataset(tempDir.getRoot().getAbsolutePath());
         TestUtils.copyDataset(ds, tdb, true);
+        this.currDataset = tdb;
         return tdb;
     }
 }

Modified: jena/Experimental/jena-jdbc/jena-jdbc-driver-tdb/src/test/java/org/apache/jena/jdbc/tdb/results/TestTdbMemResultSets.java
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-jdbc/jena-jdbc-driver-tdb/src/test/java/org/apache/jena/jdbc/tdb/results/TestTdbMemResultSets.java?rev=1463773&r1=1463772&r2=1463773&view=diff
==============================================================================
--- jena/Experimental/jena-jdbc/jena-jdbc-driver-tdb/src/test/java/org/apache/jena/jdbc/tdb/results/TestTdbMemResultSets.java
(original)
+++ jena/Experimental/jena-jdbc/jena-jdbc-driver-tdb/src/test/java/org/apache/jena/jdbc/tdb/results/TestTdbMemResultSets.java
Tue Apr  2 21:58:54 2013
@@ -21,6 +21,7 @@ package org.apache.jena.jdbc.tdb.results
 import java.sql.SQLException;
 
 import org.apache.jena.jdbc.utils.TestUtils;
+import org.junit.After;
 
 import com.hp.hpl.jena.query.Dataset;
 import com.hp.hpl.jena.tdb.TDBFactory;
@@ -31,10 +32,23 @@ import com.hp.hpl.jena.tdb.TDBFactory;
  */
 public class TestTdbMemResultSets extends AbstractTdbResultSetTests {
 
+    private Dataset currDataset;
+    
+    /**
+     * Cleans up after the tests by ensuring that the TDB dataset is closed
+     */
+    @After
+    public void cleanupTest() {
+        if (currDataset != null) {
+            currDataset.close();
+        }
+    }
+    
     @Override
     protected Dataset prepareDataset(Dataset ds) throws SQLException {
         Dataset tdb = TDBFactory.createDataset();
         TestUtils.copyDataset(ds, tdb, true);
+        currDataset = tdb;
         return tdb;
     }
 }



Mime
View raw message