lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbern...@apache.org
Subject lucene-solr git commit: SOLR-8517: Implement minimal set of get* methods in ResultSetImpl for column names
Date Tue, 26 Jan 2016 02:36:11 GMT
Repository: lucene-solr
Updated Branches:
  refs/heads/master 7b4310190 -> ce0069a75


SOLR-8517: Implement minimal set of get* methods in ResultSetImpl for column names


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/ce0069a7
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/ce0069a7
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/ce0069a7

Branch: refs/heads/master
Commit: ce0069a75126ee9d9f2b82aaf380317562bf5f50
Parents: 7b43101
Author: jbernste <jbernste@apache.org>
Authored: Mon Jan 25 21:39:44 2016 -0500
Committer: jbernste <jbernste@apache.org>
Committed: Mon Jan 25 21:39:44 2016 -0500

----------------------------------------------------------------------
 .../org/apache/solr/client/solrj/io/Tuple.java  |  2 +-
 .../solr/client/solrj/io/sql/ResultSetImpl.java | 96 ++++++++++++++++----
 .../solr/client/solrj/io/sql/JdbcTest.java      | 22 +++--
 3 files changed, 92 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/ce0069a7/solr/solrj/src/java/org/apache/solr/client/solrj/io/Tuple.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/io/Tuple.java b/solr/solrj/src/java/org/apache/solr/client/solrj/io/Tuple.java
index c864309..24699c4 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/io/Tuple.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/io/Tuple.java
@@ -68,7 +68,7 @@ public class Tuple implements Cloneable {
   }
 
   public String getString(Object key) {
-    return this.fields.get(key).toString();
+    return String.valueOf(this.fields.get(key));
   }
 
   public String getException(){ return (String)this.fields.get("EXCEPTION"); }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/ce0069a7/solr/solrj/src/java/org/apache/solr/client/solrj/io/sql/ResultSetImpl.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/io/sql/ResultSetImpl.java b/solr/solrj/src/java/org/apache/solr/client/solrj/io/sql/ResultSetImpl.java
index f4f7332..09dbb7a 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/io/sql/ResultSetImpl.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/io/sql/ResultSetImpl.java
@@ -76,8 +76,16 @@ class ResultSetImpl implements ResultSet {
     return this.metadataTuple;
   }
 
+  private void checkClosed() throws SQLException {
+    if(isClosed()) {
+      throw new SQLException("ResultSet is closed.");
+    }
+  }
+
   @Override
   public boolean next() throws SQLException {
+    checkClosed();
+
     try {
       if(done) {
         return false;
@@ -102,7 +110,8 @@ class ResultSetImpl implements ResultSet {
 
   @Override
   public boolean wasNull() throws SQLException {
-    throw new UnsupportedOperationException();
+    // TODO implement logic to check if last value was null
+    return false;
   }
 
   @Override
@@ -187,77 +196,118 @@ class ResultSetImpl implements ResultSet {
 
   @Override
   public String getString(String columnLabel) throws SQLException {
+    checkClosed();
+
     return tuple.getString(columnLabel);
   }
 
   @Override
   public boolean getBoolean(String columnLabel) throws SQLException {
-    throw new UnsupportedOperationException();
+    checkClosed();
+
+    return (boolean)getObject(columnLabel);
   }
 
   @Override
   public byte getByte(String columnLabel) throws SQLException {
-    throw new UnsupportedOperationException();
+    checkClosed();
+    Number number = (Number)getObject(columnLabel);
+    if(number == null) {
+      return 0;
+    } else {
+      return number.byteValue();
+    }
   }
 
   @Override
   public short getShort(String columnLabel) throws SQLException {
-    throw new UnsupportedOperationException();
+    checkClosed();
+    Number number = (Number)getObject(columnLabel);
+    if(number == null) {
+      return 0;
+    } else {
+      return number.shortValue();
+    }
   }
 
   @Override
   public int getInt(String columnLabel) throws SQLException {
-    throw new UnsupportedOperationException();
+    checkClosed();
+
+    Number number = (Number)getObject(columnLabel);
+    if(number == null) {
+      return 0;
+    } else {
+      return number.intValue();
+    }
   }
 
   @Override
   public long getLong(String columnLabel) throws SQLException {
-    Long l =  tuple.getLong(columnLabel);
-    if(l == null) {
-      return 0;
+    checkClosed();
+
+    Number number = (Number)getObject(columnLabel);
+    if(number == null) {
+      return 0L;
     } else {
-      return l.longValue();
+      return number.longValue();
     }
   }
 
   @Override
   public float getFloat(String columnLabel) throws SQLException {
-    throw new UnsupportedOperationException();
+    checkClosed();
+    Number number = (Number)getObject(columnLabel);
+    if(number == null) {
+      return 0.0F;
+    } else {
+      return number.floatValue();
+    }
   }
 
   @Override
   public double getDouble(String columnLabel) throws SQLException {
-    Double d = tuple.getDouble(columnLabel);
-    if(d == null) {
+    checkClosed();
+
+    Number number = (Number)getObject(columnLabel);
+    if(number == null) {
       return 0.0D;
     } else {
-      return d.doubleValue();
+      return number.doubleValue();
     }
   }
 
   @Override
   public BigDecimal getBigDecimal(String columnLabel, int scale) throws SQLException {
-    return null;
+    throw new UnsupportedOperationException();
   }
 
   @Override
   public byte[] getBytes(String columnLabel) throws SQLException {
-    return new byte[0];
+    checkClosed();
+
+    return (byte[]) getObject(columnLabel);
   }
 
   @Override
   public Date getDate(String columnLabel) throws SQLException {
-    throw new UnsupportedOperationException();
+    checkClosed();
+
+    return (Date)getObject(columnLabel);
   }
 
   @Override
   public Time getTime(String columnLabel) throws SQLException {
-    throw new UnsupportedOperationException();
+    checkClosed();
+
+    return (Time)getObject(columnLabel);
   }
 
   @Override
   public Timestamp getTimestamp(String columnLabel) throws SQLException {
-    throw new UnsupportedOperationException();
+    checkClosed();
+
+    return (Timestamp)getObject(columnLabel);
   }
 
   @Override
@@ -300,6 +350,8 @@ class ResultSetImpl implements ResultSet {
 
   @Override
   public ResultSetMetaData getMetaData() throws SQLException {
+    checkClosed();
+
     return this.resultSetMetaData;
   }
 
@@ -310,7 +362,9 @@ class ResultSetImpl implements ResultSet {
 
   @Override
   public Object getObject(String columnLabel) throws SQLException {
-    throw new UnsupportedOperationException();
+    checkClosed();
+
+    return this.tuple.get(columnLabel);
   }
 
   @Override
@@ -335,7 +389,9 @@ class ResultSetImpl implements ResultSet {
 
   @Override
   public BigDecimal getBigDecimal(String columnLabel) throws SQLException {
-    throw new UnsupportedOperationException();
+    checkClosed();
+
+    return (BigDecimal)getObject(columnLabel);
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/ce0069a7/solr/solrj/src/test/org/apache/solr/client/solrj/io/sql/JdbcTest.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/io/sql/JdbcTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/io/sql/JdbcTest.java
index 644e2b3..ef98c99 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/io/sql/JdbcTest.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/io/sql/JdbcTest.java
@@ -365,15 +365,23 @@ public class JdbcTest extends AbstractFullDistribZkTestBase {
     assertNull(rs.getWarnings());
 
     assertTrue(rs.next());
-    assertEquals(14, rs.getLong("a_i"));
+    assertEquals(14L, rs.getObject("a_i"));
+    assertEquals(14L, rs.getLong("a_i"));
+    assertEquals(14D, rs.getDouble("a_i"), 0);
+    assertEquals(14f, rs.getFloat("a_i"), 0);
+    assertEquals(14, rs.getShort("a_i"));
+    assertEquals(14, rs.getByte("a_i"));
+    assertEquals("hello0", rs.getObject("a_s"));
     assertEquals("hello0", rs.getString("a_s"));
-    assertEquals(10, rs.getDouble("a_f"), 0);
-
+    assertEquals(10D, rs.getObject("a_f"));
+    assertEquals(10D, rs.getDouble("a_f"), 0);
+    assertEquals(10F, rs.getFloat("a_f"), 0);
+    assertEquals(10, rs.getInt("a_f"), 0);
+    assertEquals(10L, rs.getLong("a_f"), 0);
+    assertEquals(10, rs.getShort("a_f"), 0);
+    assertEquals(10, rs.getByte("a_f"), 0);
+    
     assertTrue(rs.next());
-    assertEquals(13, rs.getLong("a_i"));
-    assertEquals("hello3", rs.getString("a_s"));
-    assertEquals(9, rs.getDouble("a_f"), 0);
-
     assertFalse(rs.next());
   }
 }


Mime
View raw message