diff --git a/driver/src/main/java/com/dbschema/resultSet/ResultSetWrapper.java b/driver/src/main/java/com/dbschema/resultSet/ResultSetWrapper.java index d14aba8..c14035e 100644 --- a/driver/src/main/java/com/dbschema/resultSet/ResultSetWrapper.java +++ b/driver/src/main/java/com/dbschema/resultSet/ResultSetWrapper.java @@ -15,6 +15,7 @@ import java.sql.*; import java.util.Calendar; import java.util.Iterator; +import java.util.List; import java.util.Map; public class ResultSetWrapper implements ResultSet @@ -893,10 +894,23 @@ public Clob getClob(int columnIndex) throws SQLException return null; } - public Array getArray(int columnIndex) throws SQLException - { + public Array getArray(int columnIndex) throws SQLException { + checkClosed(); + if (currentRow != null) { + Object o = currentRow.getObject(columnIndex - 1); + if (!(o instanceof List)) return null; + List list = (List) o; + return toArray(list); + } + throw new SQLException("Exhausted ResultSet."); + } - return null; + private Array toArray(List list) { + Object[] array = new Object[list.size()]; + for (int i = 0; i < list.size(); i++) { + array[i] = list.get(i); + } + return new ArrayImpl(array); } public Object getObject(String columnLabel, Map> map) throws SQLException @@ -923,10 +937,15 @@ public Clob getClob(String columnLabel) throws SQLException return null; } - public Array getArray(String columnLabel) throws SQLException - { - - return null; + public Array getArray(String columnLabel) throws SQLException { + checkClosed(); + if (currentRow != null) { + Object o = currentRow.getObject(columnLabel); + if (!(o instanceof List)) return null; + List list = (List) o; + return toArray(list); + } + throw new SQLException("Exhausted ResultSet."); } public Date getDate(int columnIndex, Calendar cal) throws SQLException @@ -1332,4 +1351,71 @@ public T getObject(int columnIndex, Class type) throws SQLException { public T getObject(String columnLabel, Class type) throws SQLException { return null; } + + private static class ArrayImpl implements Array { + + private Object[] array; + + public ArrayImpl(Object[] array) { + this.array = array; + } + + @Override + public String getBaseTypeName() throws SQLException { + throw new SQLFeatureNotSupportedException(); + } + + @Override + public int getBaseType() throws SQLException { + throw new SQLFeatureNotSupportedException(); + } + + @Override + public Object[] getArray() throws SQLException { + if (array == null) throw new SQLException("Array was freed"); + return array; + } + + @Override + public Object getArray(Map> map) throws SQLException { + throw new SQLFeatureNotSupportedException(); + } + + @Override + public Object getArray(long index, int count) throws SQLException { + throw new SQLFeatureNotSupportedException(); + } + + @Override + public Object getArray(long index, int count, Map> map) throws SQLException { + throw new SQLFeatureNotSupportedException(); + } + + @Override + public ResultSet getResultSet() throws SQLException { + throw new SQLFeatureNotSupportedException(); + } + + @Override + public ResultSet getResultSet(Map> map) throws SQLException { + throw new SQLFeatureNotSupportedException(); + } + + @Override + public ResultSet getResultSet(long index, int count) throws SQLException { + throw new SQLFeatureNotSupportedException(); + } + + @Override + public ResultSet getResultSet(long index, int count, Map> map) throws SQLException { + throw new SQLFeatureNotSupportedException(); + } + + @Override + public void free() { + if (array != null) { + array = null; + } + } + } }