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

This commit is contained in:
jbernste 2016-01-25 21:39:44 -05:00
parent 7b43101902
commit ce0069a751
3 changed files with 92 additions and 28 deletions

View File

@ -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"); }

View File

@ -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

View File

@ -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());
}
}