You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by to...@apache.org on 2007/08/30 11:14:59 UTC
svn commit: r571081 - in /harmony/enhanced/classlib/trunk/modules/sql/src:
main/java/org/apache/harmony/sql/internal/nls/
main/java/org/apache/harmony/sql/internal/rowset/
test/java/org/apache/harmony/sql/tests/internal/rowset/
Author: tonywu
Date: Thu Aug 30 02:14:58 2007
New Revision: 571081
URL: http://svn.apache.org/viewvc?rev=571081&view=rev
Log:
several methods' implemetation and their testcases
Added:
harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRow.java (with props)
Modified:
harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/nls/messages.properties
harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRowSetImpl.java
harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRowSetReader.java
harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetImplTest.java
Modified: harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/nls/messages.properties
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/nls/messages.properties?rev=571081&r1=571080&r2=571081&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/nls/messages.properties (original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/nls/messages.properties Thu Aug 30 02:14:58 2007
@@ -59,3 +59,6 @@
sql.42=Illegal Argument
sql.43=The object is not serializable
sql.44=No logger has been set
+
+rowset.0=Not a valid position
+rowset.1=Not a valid column name
Added: harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRow.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRow.java?rev=571081&view=auto
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRow.java (added)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRow.java Thu Aug 30 02:14:58 2007
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.harmony.sql.internal.rowset;
+
+import java.util.BitSet;
+
+public class CachedRow {
+ private Object[] columnData;
+
+ private BitSet mask;
+
+ public CachedRow(Object[] columnData) {
+ this.columnData = columnData;
+ mask = new BitSet(columnData.length);
+ }
+
+ public boolean setUpdateMask(int i) {
+ return mask.get(i);
+ }
+}
Propchange: harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRow.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRowSetImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRowSetImpl.java?rev=571081&r1=571080&r2=571081&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRowSetImpl.java (original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRowSetImpl.java Thu Aug 30 02:14:58 2007
@@ -16,24 +16,56 @@
*/
package org.apache.harmony.sql.internal.rowset;
+import java.io.InputStream;
+import java.io.Reader;
+import java.math.BigDecimal;
+import java.sql.Array;
+import java.sql.Blob;
+import java.sql.Clob;
import java.sql.Connection;
+import java.sql.Date;
+import java.sql.Ref;
import java.sql.ResultSet;
+import java.sql.ResultSetMetaData;
import java.sql.SQLException;
+import java.sql.SQLWarning;
import java.sql.Savepoint;
+import java.sql.Statement;
+import java.sql.Time;
+import java.sql.Timestamp;
+import java.util.ArrayList;
+import java.util.Calendar;
import java.util.Collection;
+import java.util.Map;
import javax.sql.RowSet;
import javax.sql.RowSetEvent;
+import javax.sql.RowSetInternal;
import javax.sql.RowSetMetaData;
+import javax.sql.rowset.BaseRowSet;
import javax.sql.rowset.CachedRowSet;
+import javax.sql.rowset.RowSetMetaDataImpl;
import javax.sql.rowset.RowSetWarning;
import javax.sql.rowset.spi.SyncProvider;
import javax.sql.rowset.spi.SyncProviderException;
import org.apache.harmony.luni.util.NotImplementedException;
+import org.apache.harmony.sql.internal.nls.Messages;
-public class CachedRowSetImpl extends AbstractRowSetImpl implements
- CachedRowSet {
+public class CachedRowSetImpl extends BaseRowSet implements CachedRowSet,
+ RowSetInternal {
+
+ private ArrayList<CachedRow> rows;
+
+ private RowSetMetaData meta;
+
+ private CachedRow currentRow;
+
+ private int currentRowIndex;
+
+ public void setRows(ArrayList<CachedRow> data) {
+ this.rows = data;
+ }
public void acceptChanges() throws SyncProviderException {
throw new NotImplementedException();
@@ -44,11 +76,25 @@
}
public boolean columnUpdated(int idx) throws SQLException {
- throw new NotImplementedException();
+ if (currentRow == null || idx > meta.getColumnCount()) {
+ // rowset.0 = Not a valid position
+ throw new SQLException(Messages.getString("rowset.0"));
+ }
+ return currentRow.setUpdateMask(idx - 1);
}
public boolean columnUpdated(String columnName) throws SQLException {
- throw new NotImplementedException();
+ return columnUpdated(getIndexByName(columnName));
+ }
+
+ private int getIndexByName(String columnName) throws SQLException {
+ for (int i = 1; i <= meta.getColumnCount(); i++) {
+ if (columnName.equals(meta.getColumnName(i))) {
+ return i;
+ }
+ }
+ // rowset.1=Not a valid column name
+ throw new SQLException(Messages.getString("rowset.1"));
}
public void commit() throws SQLException {
@@ -108,11 +154,23 @@
}
public void populate(ResultSet data) throws SQLException {
- throw new NotImplementedException();
+ populate(data, 0);
}
public void populate(ResultSet rs, int startRow) throws SQLException {
- throw new NotImplementedException();
+ new CachedRowSetReader(rs, startRow).readData(this);
+ composeMetaData(rs.getMetaData());
+ }
+
+ private void composeMetaData(ResultSetMetaData metaData)
+ throws SQLException {
+ RowSetMetaDataImpl rowSetMetaData = new RowSetMetaDataImpl();
+ rowSetMetaData.setColumnCount(metaData.getColumnCount());
+ for (int i = 1; i <= metaData.getColumnCount(); i++) {
+ rowSetMetaData.setColumnName(i, metaData.getColumnName(i));
+ }
+ // TODO set other meta info when necessary
+ this.meta = rowSetMetaData;
}
public boolean previousPage() throws SQLException {
@@ -135,7 +193,8 @@
throw new NotImplementedException();
}
- public void rowSetPopulated(RowSetEvent event, int numRows) throws SQLException {
+ public void rowSetPopulated(RowSetEvent event, int numRows)
+ throws SQLException {
throw new NotImplementedException();
}
@@ -144,7 +203,7 @@
}
public void setMetaData(RowSetMetaData md) throws SQLException {
- throw new NotImplementedException();
+ this.meta = md;
}
public void setOriginalRow() throws SQLException {
@@ -231,6 +290,567 @@
throw new NotImplementedException();
}
-
+ public boolean absolute(int row) throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public void afterLast() throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public void beforeFirst() throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public void cancelRowUpdates() throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public void clearWarnings() throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public void close() throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public void deleteRow() throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public int findColumn(String columnName) throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public boolean first() throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public Array getArray(int columnIndex) throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public Array getArray(String colName) throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public InputStream getAsciiStream(int columnIndex) throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public InputStream getAsciiStream(String columnName) throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public BigDecimal getBigDecimal(int columnIndex) throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public BigDecimal getBigDecimal(int columnIndex, int scale)
+ throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public BigDecimal getBigDecimal(String columnName) throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public BigDecimal getBigDecimal(String columnName, int scale)
+ throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public InputStream getBinaryStream(int columnIndex) throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public InputStream getBinaryStream(String columnName) throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public Blob getBlob(int columnIndex) throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public Blob getBlob(String columnName) throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public boolean getBoolean(int columnIndex) throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public boolean getBoolean(String columnName) throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public byte getByte(int columnIndex) throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public byte getByte(String columnName) throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public byte[] getBytes(int columnIndex) throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public byte[] getBytes(String columnName) throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public Reader getCharacterStream(int columnIndex) throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public Reader getCharacterStream(String columnName) throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public Clob getClob(int columnIndex) throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public Clob getClob(String colName) throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public String getCursorName() throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public Date getDate(int columnIndex) throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public Date getDate(int columnIndex, Calendar cal) throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public Date getDate(String columnName) throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public Date getDate(String columnName, Calendar cal) throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public double getDouble(int columnIndex) throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public double getDouble(String columnName) throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public float getFloat(int columnIndex) throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public float getFloat(String columnName) throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public int getInt(int columnIndex) throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public int getInt(String columnName) throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public long getLong(int columnIndex) throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public long getLong(String columnName) throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public ResultSetMetaData getMetaData() throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public Object getObject(int columnIndex) throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public Object getObject(int columnIndex, Map<String, Class<?>> map)
+ throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public Object getObject(String columnName) throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public Object getObject(String columnName, Map<String, Class<?>> map)
+ throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public Ref getRef(int columnIndex) throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public Ref getRef(String colName) throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public int getRow() throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public short getShort(int columnIndex) throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public short getShort(String columnName) throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public Statement getStatement() throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public String getString(int columnIndex) throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public String getString(String columnName) throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public Time getTime(int columnIndex) throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public Time getTime(int columnIndex, Calendar cal) throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public Time getTime(String columnName) throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public Time getTime(String columnName, Calendar cal) throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public Timestamp getTimestamp(int columnIndex) throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public Timestamp getTimestamp(int columnIndex, Calendar cal)
+ throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public Timestamp getTimestamp(String columnName) throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public Timestamp getTimestamp(String columnName, Calendar cal)
+ throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public java.net.URL getURL(int columnIndex) throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public java.net.URL getURL(String columnName) throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public InputStream getUnicodeStream(int columnIndex) throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public InputStream getUnicodeStream(String columnName) throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public SQLWarning getWarnings() throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public void insertRow() throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public boolean isAfterLast() throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public boolean isBeforeFirst() throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public boolean isFirst() throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public boolean isLast() throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public boolean last() throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public void moveToCurrentRow() throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public void moveToInsertRow() throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public boolean next() throws SQLException {
+ currentRowIndex++;
+ if (rows.size() < currentRowIndex) {
+ return false;
+ }
+ currentRow = rows.get(currentRowIndex);
+ return true;
+ }
+
+ public boolean previous() throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public void refreshRow() throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public boolean relative(int rows) throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public boolean rowDeleted() throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public boolean rowInserted() throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public boolean rowUpdated() throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public void updateArray(int columnIndex, Array x) throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public void updateArray(String columnName, Array x) throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public void updateAsciiStream(int columnIndex, InputStream x, int length)
+ throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public void updateAsciiStream(String columnName, InputStream x, int length)
+ throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public void updateBigDecimal(int columnIndex, BigDecimal x)
+ throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public void updateBigDecimal(String columnName, BigDecimal x)
+ throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public void updateBinaryStream(int columnIndex, InputStream x, int length)
+ throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public void updateBinaryStream(String columnName, InputStream x, int length)
+ throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public void updateBlob(int columnIndex, Blob x) throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public void updateBlob(String columnName, Blob x) throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public void updateBoolean(int columnIndex, boolean x) throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public void updateBoolean(String columnName, boolean x) throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public void updateByte(int columnIndex, byte x) throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public void updateByte(String columnName, byte x) throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public void updateBytes(int columnIndex, byte[] x) throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public void updateBytes(String columnName, byte[] x) throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public void updateCharacterStream(int columnIndex, Reader x, int length)
+ throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public void updateCharacterStream(String columnName, Reader reader,
+ int length) throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public void updateClob(int columnIndex, Clob x) throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public void updateClob(String columnName, Clob x) throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public void updateDate(int columnIndex, Date x) throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public void updateDate(String columnName, Date x) throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public void updateDouble(int columnIndex, double x) throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public void updateDouble(String columnName, double x) throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public void updateFloat(int columnIndex, float x) throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public void updateFloat(String columnName, float x) throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public void updateInt(int columnIndex, int x) throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public void updateInt(String columnName, int x) throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public void updateLong(int columnIndex, long x) throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public void updateLong(String columnName, long x) throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public void updateNull(int columnIndex) throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public void updateNull(String columnName) throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public void updateObject(int columnIndex, Object x) throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public void updateObject(int columnIndex, Object x, int scale)
+ throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public void updateObject(String columnName, Object x) throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public void updateObject(String columnName, Object x, int scale)
+ throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public void updateRef(int columnIndex, Ref x) throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public void updateRef(String columnName, Ref x) throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public void updateRow() throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public void updateShort(int columnIndex, short x) throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public void updateShort(String columnName, short x) throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public void updateString(int columnIndex, String x) throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public void updateString(String columnName, String x) throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public void updateTime(int columnIndex, Time x) throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public void updateTime(String columnName, Time x) throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public void updateTimestamp(int columnIndex, Timestamp x)
+ throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public void updateTimestamp(String columnName, Timestamp x)
+ throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public boolean wasNull() throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public void execute() throws SQLException {
+ throw new NotImplementedException();
+ }
+
+ public Connection getConnection() throws SQLException {
+ throw new NotImplementedException();
+ }
}
Modified: harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRowSetReader.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRowSetReader.java?rev=571081&r1=571080&r2=571081&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRowSetReader.java (original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRowSetReader.java Thu Aug 30 02:14:58 2007
@@ -16,17 +16,38 @@
*/
package org.apache.harmony.sql.internal.rowset;
+import java.sql.ResultSet;
+import java.sql.ResultSetMetaData;
import java.sql.SQLException;
+import java.util.ArrayList;
import javax.sql.RowSetInternal;
import javax.sql.RowSetReader;
-import org.apache.harmony.luni.util.NotImplementedException;
-
public class CachedRowSetReader implements RowSetReader {
- public void readData(RowSetInternal theCaller) throws SQLException {
- throw new NotImplementedException();
+ private ResultSet rs;
+
+ private int startRow;
+
+ private ResultSetMetaData metadata;
+
+ public CachedRowSetReader(ResultSet rs, int startRow) throws SQLException {
+ this.rs = rs;
+ this.startRow = startRow;
+ this.metadata = rs.getMetaData();
}
+ public void readData(RowSetInternal theCaller) throws SQLException {
+ ArrayList<CachedRow> data = new ArrayList<CachedRow>();
+ while (rs.next()) {
+ int columnCount = metadata.getColumnCount();
+ Object[] columnData = new Object[columnCount];
+ for (int i = 0; i < columnCount; i++) {
+ columnData[i] = rs.getObject(i+1);
+ }
+ data.add(new CachedRow(columnData));
+ }
+ ((CachedRowSetImpl) theCaller).setRows(data);
+ }
}
Modified: harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetImplTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetImplTest.java?rev=571081&r1=571080&r2=571081&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetImplTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetImplTest.java Thu Aug 30 02:14:58 2007
@@ -55,14 +55,15 @@
try {
crset = (CachedRowSet) Class.forName(
"com.sun.rowset.CachedRowSetImpl").newInstance();
+ System.out.println("Testing RI");
} catch (ClassNotFoundException e) {
- System.out.println("Test Harmony");
+ System.out.println("Testing Harmony");
crset = (CachedRowSet) Class.forName(
"org.apache.harmony.sql.internal.rowset.CachedRowSetImpl")
.newInstance();
}
-// crset.populate(rs);
-// rs = st.executeQuery("select * from USER_INFO");
+ crset.populate(rs);
+ rs = st.executeQuery("select * from USER_INFO");
}
public void tearDown() throws SQLException {
@@ -71,32 +72,72 @@
}
}
+ public void testColumnUpdatedInt() throws SQLException {
+ try {
+ assertFalse(crset.columnUpdated(1));
+ fail("should throw SQLException");
+ } catch (SQLException e) {
+ // expected;
+ }
+ crset.next();
+ try {
+ crset.columnUpdated(-1);
+ fail("should throw IndexOutOfBoundsException");
+ } catch (IndexOutOfBoundsException e) {
+ // expected;
+ }
+ try {
+ crset.columnUpdated(0);
+ fail("should throw IndexOutOfBoundsException");
+ } catch (IndexOutOfBoundsException e) {
+ // expected;
+ }
+ assertFalse(crset.columnUpdated(1));
+ }
+
+ public void testColumnUpdatedString() throws SQLException {
+ try {
+ assertFalse(crset.columnUpdated("ID"));
+ fail("should throw SQLException");
+ } catch (SQLException e) {
+ // expected;
+ }
+ crset.next();
+ try {
+ assertFalse(crset.columnUpdated("Incorrect"));
+ fail("should throw SQLException");
+ } catch (SQLException e) {
+ // expected;
+ }
+ assertFalse(crset.columnUpdated("NAME"));
+ }
+
public void testAcceptChanges() throws SQLException {
-// rs.next();
-// assertEquals(1, rs.getInt(1));
-// crset.next();
-// assertEquals(1, crset.getInt(1));
-// crset.updateInt(1, 3);
-// assertEquals(3, crset.getInt(1));
-// try {
-// crset.acceptChanges();
-// fail("should throw SyncProviderException");
-// } catch (SQLException e) {
-// // expected;
-// }
+ // rs.next();
+ // assertEquals(1, rs.getInt(1));
+ // crset.next();
+ // assertEquals(1, crset.getInt(1));
+ // crset.updateInt(1, 3);
+ // assertEquals(3, crset.getInt(1));
+ // try {
+ // crset.acceptChanges();
+ // fail("should throw SyncProviderException");
+ // } catch (SQLException e) {
+ // // expected;
+ // }
}
public void testAcceptChangesConnection() throws SQLException {
-// rs.next();
-// assertEquals(1, rs.getInt(1));
-// crset.first();
-// assertEquals(1, crset.getInt(1));
-// crset.updateInt(1, 3);
-// assertEquals(3, crset.getInt(1));
-// crset.updateRow();
-// crset.acceptChanges(conn);
-// rs = st.executeQuery("select * from USER_INFO");
-// rs.next();
-// assertEquals(3, rs.getInt(1));
+ // rs.next();
+ // assertEquals(1, rs.getInt(1));
+ // crset.first();
+ // assertEquals(1, crset.getInt(1));
+ // crset.updateInt(1, 3);
+ // assertEquals(3, crset.getInt(1));
+ // crset.updateRow();
+ // crset.acceptChanges(conn);
+ // rs = st.executeQuery("select * from USER_INFO");
+ // rs.next();
+ // assertEquals(3, rs.getInt(1));
}
}