Return-Path: Delivered-To: apmail-harmony-commits-archive@www.apache.org Received: (qmail 20073 invoked from network); 3 Sep 2007 07:41:38 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 3 Sep 2007 07:41:38 -0000 Received: (qmail 34535 invoked by uid 500); 3 Sep 2007 07:41:33 -0000 Delivered-To: apmail-harmony-commits-archive@harmony.apache.org Received: (qmail 34508 invoked by uid 500); 3 Sep 2007 07:41:33 -0000 Mailing-List: contact commits-help@harmony.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@harmony.apache.org Delivered-To: mailing list commits@harmony.apache.org Received: (qmail 34499 invoked by uid 99); 3 Sep 2007 07:41:33 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 03 Sep 2007 00:41:33 -0700 X-ASF-Spam-Status: No, hits=-100.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 03 Sep 2007 07:41:37 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 3A0C11A9832; Mon, 3 Sep 2007 00:41:17 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r572246 - 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/ Date: Mon, 03 Sep 2007 07:41:16 -0000 To: commits@harmony.apache.org From: tonywu@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20070903074117.3A0C11A9832@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: tonywu Date: Mon Sep 3 00:41:15 2007 New Revision: 572246 URL: http://svn.apache.org/viewvc?rev=572246&view=rev Log: several methods about page size, table name, delete row and insert row of CachedRowSet 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/CachedRow.java 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=572246&r1=572245&r2=572246&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 Mon Sep 3 00:41:15 2007 @@ -62,3 +62,5 @@ rowset.0=Not a valid position rowset.1=Not a valid column name +rowset.2=Negative page size +rowset.3=Table name should not be null Modified: 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=572246&r1=572245&r2=572246&view=diff ============================================================================== --- harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRow.java (original) +++ harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRow.java Mon Sep 3 00:41:15 2007 @@ -23,12 +23,46 @@ private BitSet mask; + private boolean isDelete; + + private boolean insert; + public CachedRow(Object[] columnData) { this.columnData = columnData; mask = new BitSet(columnData.length); } - public boolean setUpdateMask(int i) { + public boolean getUpdateMask(int i) { return mask.get(i); + } + + public void setUpdateMask(int i) { + mask.set(i); + } + + public void setDelete() { + this.isDelete = true; + } + + public boolean getDelete() { + return isDelete; + } + + public void setInsert() { + this.insert = true; + } + + public boolean getInsert() { + return this.insert; + } + + public void updateString(int columnIndex, String x) { + this.columnData[columnIndex - 1] = x; + setUpdateMask(columnIndex - 1); + } + + public void updateInt(int columnIndex, int x) { + this.columnData[columnIndex - 1] = x; + setUpdateMask(columnIndex - 1); } } 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=572246&r1=572245&r2=572246&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 Mon Sep 3 00:41:15 2007 @@ -63,8 +63,19 @@ private int currentRowIndex; - public void setRows(ArrayList data) { + private int pageSize; + + private String tableName; + + private int rememberedCursorPosition; + + private CachedRow insertRow; + + private int columnCount; + + public void setRows(ArrayList data, int cloumnCount) { this.rows = data; + this.columnCount = cloumnCount; } public void acceptChanges() throws SyncProviderException { @@ -80,7 +91,7 @@ // rowset.0 = Not a valid position throw new SQLException(Messages.getString("rowset.0")); } - return currentRow.setUpdateMask(idx - 1); + return currentRow.getUpdateMask(idx - 1); } public boolean columnUpdated(String columnName) throws SQLException { @@ -89,7 +100,7 @@ private int getIndexByName(String columnName) throws SQLException { for (int i = 1; i <= meta.getColumnCount(); i++) { - if (columnName.equals(meta.getColumnName(i))) { + if (columnName.equalsIgnoreCase(meta.getColumnName(i))) { return i; } } @@ -134,7 +145,7 @@ } public int getPageSize() { - throw new NotImplementedException(); + return pageSize; } public RowSetWarning getRowSetWarnings() throws SQLException { @@ -146,7 +157,7 @@ } public String getTableName() throws SQLException { - throw new NotImplementedException(); + return tableName; } public boolean nextPage() throws SQLException { @@ -211,7 +222,11 @@ } public void setPageSize(int size) throws SQLException { - throw new NotImplementedException(); + if (size < 0) { + // rowset.2=Negative page size + throw new SQLException(Messages.getString("rowset.2")); + } + this.pageSize = size; } public void setSyncProvider(String provider) throws SQLException { @@ -219,11 +234,15 @@ } public void setTableName(String tabName) throws SQLException { - throw new NotImplementedException(); + if (tabName == null) { + // rowset.3=Table name should not be null + throw new SQLException("rowset.3"); + } + this.tableName = tabName; } public int size() { - throw new NotImplementedException(); + return rows.size(); } public Collection toCollection() throws SQLException { @@ -315,7 +334,15 @@ } public void deleteRow() throws SQLException { - throw new NotImplementedException(); + checkValidRow(); + currentRow.setDelete(); + } + + private void checkValidRow() throws SQLException { + if (currentRow == null) { + // rowset.0 = Not a valid position + throw new SQLException(Messages.getString("rowset.0")); + } } public int findColumn(String columnName) throws SQLException { @@ -577,7 +604,13 @@ } public void insertRow() throws SQLException { - throw new NotImplementedException(); + checkValidRow(); + if (currentRow != insertRow) { + throw new SQLException(); + } + currentRow.setInsert(); + rows.add(insertRow); + currentRowIndex++; } public boolean isAfterLast() throws SQLException { @@ -601,11 +634,14 @@ } public void moveToCurrentRow() throws SQLException { - throw new NotImplementedException(); + this.currentRowIndex = rememberedCursorPosition; + this.currentRow = rows.get(currentRowIndex); } public void moveToInsertRow() throws SQLException { - throw new NotImplementedException(); + insertRow = new CachedRow(new Object[columnCount]); + this.currentRow = insertRow; + this.currentRowIndex = rows.size(); } public boolean next() throws SQLException { @@ -630,7 +666,8 @@ } public boolean rowDeleted() throws SQLException { - throw new NotImplementedException(); + checkValidRow(); + return currentRow.getDelete(); } public boolean rowInserted() throws SQLException { @@ -754,11 +791,11 @@ } public void updateInt(int columnIndex, int x) throws SQLException { - throw new NotImplementedException(); + currentRow.updateInt(columnIndex, x); } public void updateInt(String columnName, int x) throws SQLException { - throw new NotImplementedException(); + currentRow.updateInt(getIndexByName(columnName), x); } public void updateLong(int columnIndex, long x) throws SQLException { @@ -816,11 +853,11 @@ } public void updateString(int columnIndex, String x) throws SQLException { - throw new NotImplementedException(); + currentRow.updateString(columnIndex, x); } public void updateString(String columnName, String x) throws SQLException { - throw new NotImplementedException(); + currentRow.updateString(getIndexByName(columnName), x); } public void updateTime(int columnIndex, Time x) throws SQLException { 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=572246&r1=572245&r2=572246&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 Mon Sep 3 00:41:15 2007 @@ -40,14 +40,14 @@ public void readData(RowSetInternal theCaller) throws SQLException { ArrayList data = new ArrayList(); + int columnCount = metadata.getColumnCount(); 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); + ((CachedRowSetImpl) theCaller).setRows(data, columnCount); } } 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=572246&r1=572245&r2=572246&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 Mon Sep 3 00:41:15 2007 @@ -112,6 +112,88 @@ assertFalse(crset.columnUpdated("NAME")); } + public void testGetPageSize() throws SQLException { + assertEquals(0, crset.getPageSize()); + crset.setPageSize(1); + assertEquals(1, crset.getPageSize()); + } + + public void testSetPageSize() throws SQLException { + try { + crset.setPageSize(-1); + fail("should throw SQLException"); + } catch (SQLException e) { + // expected; + } + crset.setPageSize(0); + crset.setPageSize(Integer.MAX_VALUE); + assertEquals(Integer.MAX_VALUE, crset.getPageSize()); + } + + public void testGetTableName() throws SQLException { + assertEquals(null, crset.getTableName()); + crset.setTableName("USER"); + assertEquals("USER", crset.getTableName()); + } + + public void testSetTableName() throws SQLException { + try { + crset.setTableName(null); + fail("should throw SQLException"); + } catch (SQLException e) { + // expected; + } + } + + public void testSize() { + assertEquals(2, crset.size()); + } + + public void testDeleteRow() throws SQLException { + try { + crset.deleteRow(); + fail("should throw SQLException"); + } catch (SQLException e) { + // expected; + } + crset.next(); + assertFalse(crset.rowDeleted()); + crset.deleteRow(); + assertEquals(2, crset.size()); + assertTrue(crset.rowDeleted()); + } + + public void testRowDeleted() throws SQLException{ + try { + crset.rowDeleted(); + fail("should throw SQLException"); + } catch (SQLException e) { + // expected; + } + } + + public void testInsertRow() throws SQLException{ + try { + crset.insertRow(); + fail("should throw SQLException"); + } catch (SQLException e) { + // expected; + } + crset.next(); + try { + crset.insertRow(); + fail("should throw SQLException"); + } catch (SQLException e) { + // expected; + } + crset.moveToInsertRow(); + crset.updateString("Name", "TonyWu"); + crset.updateInt("ID", 3); + crset.insertRow(); +// crset.moveToCurrentRow(); +// assertTrue(crset.rowInserted()); + } + public void testAcceptChanges() throws SQLException { // rs.next(); // assertEquals(1, rs.getInt(1));