Displaying differences for changeset
 
display as  

src/org/csu/csip/sdm/SDMConnection.java

@@ -32,6 +32,7 @@
 
     private String url;
     private SDMClient sdmClient;
+    DatabaseMetaData metaData;
     
     public SDMConnection( String url ) throws SQLException{
         if ( url.contains(URL_TYPE)){
@@ -43,6 +44,7 @@
             
             sdmClient = new SDMClient();
             sdmClient.setURL(this.url);
+            metaData = new SDMDatabaseMetaData(this);
         }
     }
     
@@ -131,12 +133,12 @@
 
     @Override
     public boolean getAutoCommit() throws SQLException {
-        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+        return false;
     }
 
     @Override
     public void setAutoCommit(boolean autoCommit) throws SQLException {
-        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+        
     }
 
     @Override
@@ -176,7 +178,7 @@
 
     @Override
     public DatabaseMetaData getMetaData() throws SQLException {
-        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+        return this.metaData;
     }
 
     @Override
@@ -231,7 +233,7 @@
 
     @Override
     public boolean isClosed() throws SQLException {
-        return true;
+        return false;
     }
 
     @Override

src/org/csu/csip/sdm/SDMDriver.java

@@ -17,6 +17,12 @@
 /**
  *
  * @author <a href="mailto:shaun.case@colostate.edu">Shaun Case</a>
+ * 
+ * Use the following for your datasource environment:
+  @Resource(type = JDBC, file = "${<config key>}", id = <id string> , env = {
+        "driverClassName=org.csu.csip.sdm.SDMDriver","validationQuery=SELECT 1 FROM mapunit;",
+        "maxWait=300000", "testOnBorrow=false"
+    })
  */
 public class SDMDriver implements java.sql.Driver {
     static String URL_TYPE = "jdbc:sdm:rest://";

src/org/csu/csip/sdm/SDMResultSet.java

@@ -27,6 +27,7 @@
 import java.util.ArrayList;
 import java.util.Calendar;
 import java.util.HashMap;
+import java.util.Iterator;
 import java.util.Map;
 import java.util.logging.Level;
 import java.util.logging.Logger;
@@ -46,6 +47,7 @@
     int rowId;
     int maxRows;
     SDMStatement statement;
+    boolean lastReadNull = false;
 
     public SDMResultSet(SDMStatement statement, JSONObject result) throws SQLException {
         results = result;
@@ -81,7 +83,10 @@
             }
 
         } else {
-            throw new SQLException("Invalid results from database. No Table object found");
+            //  The USDA REST service for SDM returns an empty JSONObject when the result
+            //of the query had no return values.  Assume here that the query suceeded but had no results.
+            
+            //throw new SQLException("Invalid results from database. No Table object found");
         }
     }
 
@@ -118,7 +123,14 @@
     @Override
     public void close() throws SQLException {
         //TODO:  clean arraylists here.
-
+        rows.clear();
+        columns.clear();
+        rowId = -1;
+        maxRows = 0;
+        Iterator<String> itr = results.keys();
+        while (itr.hasNext()) {
+            results.remove(itr.next());
+        }
     }
 
     @Override
@@ -137,7 +149,7 @@
             throw new SQLException("ResultSet is empty, no column lables are found.");
         }
 
-        if ( ret_val == -1 ){
+        if (ret_val == -1) {
             throw new SQLException("Column was not found in the ResultSet: " + columnLabel);
         }
         return ret_val;
@@ -295,9 +307,11 @@
     @Override
     public double getDouble(int columnIndex) throws SQLException {
         String value = rows.get(rowId).getValue(columnIndex);
-
+        this.lastReadNull = false;
         if ((null != value) && !value.equalsIgnoreCase("null")) {
             return Double.parseDouble(value);
+        } else {
+            this.lastReadNull = true;
         }
         return Double.NaN;
     }
@@ -306,9 +320,11 @@
     public double getDouble(String columnLabel) throws SQLException {
         int index = findColumn(columnLabel);
         String value = rows.get(rowId).getValue(index);
-
+        this.lastReadNull = false;
         if ((null != value) && !value.equalsIgnoreCase("null")) {
             return Double.parseDouble(value);
+        } else {
+            this.lastReadNull = true;
         }
         return Double.NaN;
     }
@@ -336,9 +352,11 @@
     @Override
     public float getFloat(int columnIndex) throws SQLException {
         String value = rows.get(rowId).getValue(columnIndex);
-
+        this.lastReadNull = false;
         if ((null != value) && !value.equalsIgnoreCase("null")) {
             return Float.parseFloat(value);
+        } else {
+            this.lastReadNull = true;
         }
         return Float.NaN;
     }
@@ -347,9 +365,11 @@
     public float getFloat(String columnLabel) throws SQLException {
         int index = findColumn(columnLabel);
         String value = rows.get(rowId).getValue(index);
-
+        this.lastReadNull = false;
         if ((null != value) && !value.equalsIgnoreCase("null")) {
             return Float.parseFloat(value);
+        } else {
+            this.lastReadNull = true;
         }
         return Float.NaN;
     }
@@ -362,9 +382,11 @@
     @Override
     public int getInt(int columnIndex) throws SQLException {
         String value = rows.get(rowId).getValue(columnIndex);
-
+        this.lastReadNull = false;
         if ((null != value) && !value.equalsIgnoreCase("null")) {
             return Integer.parseInt(value);
+        } else {
+            this.lastReadNull = true;
         }
         return Integer.MAX_VALUE;
     }
@@ -373,9 +395,11 @@
     public int getInt(String columnLabel) throws SQLException {
         int index = findColumn(columnLabel);
         String value = rows.get(rowId).getValue(index);
-
+        this.lastReadNull = false;
         if ((null != value) && !value.equalsIgnoreCase("null")) {
             return Integer.parseInt(value);
+        } else {
+            this.lastReadNull = true;
         }
         return Integer.MAX_VALUE;
     }
@@ -383,9 +407,11 @@
     @Override
     public long getLong(int columnIndex) throws SQLException {
         String value = rows.get(rowId).getValue(columnIndex);
-
+        this.lastReadNull = false;
         if ((null != value) && !value.equalsIgnoreCase("null")) {
             return Long.parseLong(value);
+        } else {
+            this.lastReadNull = true;
         }
         return Long.MAX_VALUE;
     }
@@ -394,9 +420,11 @@
     public long getLong(String columnLabel) throws SQLException {
         int index = findColumn(columnLabel);
         String value = rows.get(rowId).getValue(index);
-
+        this.lastReadNull = false;
         if ((null != value) && !value.equalsIgnoreCase("null")) {
             return Long.parseLong(value);
+        } else {
+            this.lastReadNull = true;
         }
         return Long.MAX_VALUE;
     }
@@ -518,13 +546,28 @@
 
     @Override
     public String getString(int columnIndex) throws SQLException {
-        return rows.get(rowId).getValue(columnIndex);
+        String ret_val;
+        this.lastReadNull = false;
+
+        ret_val = rows.get(rowId).getValue(columnIndex);
+        if ((null == ret_val) || (ret_val.equalsIgnoreCase("null"))) {
+            this.lastReadNull = true;
+        }
+
+        return ret_val;
     }
 
     @Override
     public String getString(String columnLabel) throws SQLException {
         int index = findColumn(columnLabel);
-        return rows.get(rowId).getValue(index);
+        String ret_val;
+        this.lastReadNull = false;
+
+        ret_val = rows.get(rowId).getValue(index);
+        if ((null == ret_val) || (ret_val.equalsIgnoreCase("null"))) {
+            this.lastReadNull = true;
+        }
+        return ret_val;
     }
 
     @Override
@@ -649,7 +692,7 @@
 
     @Override
     public boolean next() throws SQLException {
-        if ((maxRows > 0) && (rowId < (maxRows-1))) {
+        if ((maxRows > 0) && (rowId < (maxRows - 1))) {
             rowId++;
             return true;
         }
@@ -1114,7 +1157,7 @@
 
     @Override
     public boolean wasNull() throws SQLException {
-        throw new SQLFeatureNotSupportedException("Operation not supported."); //To change body of generated methods, choose Tools | Templates.
+        return lastReadNull;
     }
 
     private class ResultRow {
@@ -1135,5 +1178,5 @@
                 throw new SQLException("Invalid index used in row operation: getValue");
             }
         }
-    }
+    }           
 }

src/org/csu/csip/sdm/SDMStatement.java

@@ -50,7 +50,7 @@
 
     @Override
     public void close() throws SQLException {
-        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+        
     }
 
     @Override