harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From py...@apache.org
Subject svn commit: r532633 - in /harmony/enhanced/classlib/trunk/modules/sql/src: main/java/javax/sql/rowset/ main/java/org/apache/harmony/sql/internal/nls/ test/java/org/apache/harmony/sql/tests/javax/sql/rowset/ test/resources/serialization/org/apache/harmo...
Date Thu, 26 Apr 2007 07:09:12 GMT
Author: pyang
Date: Thu Apr 26 00:09:11 2007
New Revision: 532633

URL: http://svn.apache.org/viewvc?view=rev&rev=532633
Log:
Apply patch for HARMONY-3760([classlib][sql] 12 new methods in RowSetMetaDataImpl)

Added:
    harmony/enhanced/classlib/trunk/modules/sql/src/test/resources/serialization/org/apache/harmony/sql/tests/javax/sql/rowset/RowSetMetaDataImplTest.golden.ser
  (with props)
Modified:
    harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/sql/rowset/RowSetMetaDataImpl.java
    harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/nls/messages.properties
    harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/RowSetMetaDataImplTest.java

Modified: harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/sql/rowset/RowSetMetaDataImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/sql/rowset/RowSetMetaDataImpl.java?view=diff&rev=532633&r1=532632&r2=532633
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/sql/rowset/RowSetMetaDataImpl.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/sql/rowset/RowSetMetaDataImpl.java
Thu Apr 26 00:09:11 2007
@@ -18,11 +18,11 @@
 package javax.sql.rowset;
 
 import java.io.Serializable;
+import java.sql.ResultSetMetaData;
 import java.sql.SQLException;
 
 import javax.sql.RowSetMetaData;
 
-import org.apache.harmony.luni.util.NotImplementedException;
 import org.apache.harmony.sql.internal.nls.Messages;
 
 /**
@@ -37,7 +37,7 @@
 
     private static final String EMPTY_STRING = ""; //$NON-NLS-1$
 
-    private static final int DEFAULT_COLUMN_COUNT = 4;
+    private static final int DEFAULT_COLUMN_COUNT = 5;
 
     private static final long serialVersionUID = 6893806403181801867L;
         
@@ -52,13 +52,20 @@
         // do nothing
     }
     
-    private void checkColumnIndex(int arrayIndex) throws SQLException {
-        if (null == colInfo || arrayIndex < 0 || arrayIndex >= colInfo.length) {
-            throw new SQLException(Messages.getString("sql.27", arrayIndex + 1)); //$NON-NLS-1$
+    private void checkNegativeValue(int value, String msg) throws SQLException {
+        if (value < 0) {
+            throw new SQLException(Messages.getString(msg));
         }
-        // lazy initialization
-        if (null == colInfo[arrayIndex]) {
-            colInfo[arrayIndex] = new ColInfo();
+    }
+    
+    private void checkColumnIndex(int columnIndex) throws SQLException {
+        if (null == colInfo || columnIndex < 1 || columnIndex >= colInfo.length) {
+            throw new SQLException(Messages
+                    .getString("sql.27", columnIndex + 1)); //$NON-NLS-1$
+        }
+        // lazy initialization        
+        if (null == colInfo[columnIndex]) {
+            colInfo[columnIndex] = new ColInfo();
         }
     }
     
@@ -67,12 +74,16 @@
      * 
      * @see javax.sql.RowSetMetaData#setColumnCount(int)
      */
-    public void setColumnCount(int columnCount) throws SQLException {
+    public void setColumnCount(int columnCount) throws SQLException {        
         if (columnCount <= 0) {
             throw new SQLException(Messages.getString("sql.26")); //$NON-NLS-1$
         }
         try {
-            colInfo = new ColInfo[columnCount];            
+            if (columnCount + 1 > 0) {
+                colInfo = new ColInfo[columnCount + 1];                
+            } else {
+                colInfo = new ColInfo[DEFAULT_COLUMN_COUNT];
+            }
         } catch (OutOfMemoryError e) {
             // For compatibility, use same default value as RI
             colInfo = new ColInfo[DEFAULT_COLUMN_COUNT];
@@ -87,9 +98,8 @@
      */
     public void setAutoIncrement(int columnIndex, boolean property)
             throws SQLException {
-        int arrayIndex = columnIndex - 1;
-        checkColumnIndex(arrayIndex);
-        colInfo[arrayIndex].autoIncrement = property;
+        checkColumnIndex(columnIndex);
+        colInfo[columnIndex].autoIncrement = property;
     }
 
     /**
@@ -99,9 +109,8 @@
      */
     public void setCaseSensitive(int columnIndex, boolean property)
             throws SQLException {
-        int arrayIndex = columnIndex - 1;
-        checkColumnIndex(arrayIndex);
-        colInfo[arrayIndex].caseSensitive = property;
+        checkColumnIndex(columnIndex);
+        colInfo[columnIndex].caseSensitive = property;
     }
 
     /**
@@ -111,9 +120,8 @@
      */
     public void setSearchable(int columnIndex, boolean property)
             throws SQLException {
-        int arrayIndex = columnIndex - 1;
-        checkColumnIndex(arrayIndex);
-        colInfo[arrayIndex].searchable = property;
+        checkColumnIndex(columnIndex);
+        colInfo[columnIndex].searchable = property;
     }
 
     /**
@@ -123,13 +131,24 @@
      */
     public void setCurrency(int columnIndex, boolean property)
             throws SQLException {
-        int arrayIndex = columnIndex - 1;
-        checkColumnIndex(arrayIndex);
-        colInfo[arrayIndex].currency = property;
+        checkColumnIndex(columnIndex);
+        colInfo[columnIndex].currency = property;
     }
 
+    /**
+     * {@inheritDoc}
+     * 
+     * @see javax.sql.RowSetMetaData#setNullable(int, int)
+     */
     public void setNullable(int columnIndex, int property) throws SQLException {
-        throw new NotImplementedException();
+        if (property != ResultSetMetaData.columnNoNulls
+                && property != ResultSetMetaData.columnNullable
+                && property != ResultSetMetaData.columnNullableUnknown) {
+            throw new SQLException(Messages.getString("sql.29")); //$NON-NLS-1$
+        }
+
+        checkColumnIndex(columnIndex);
+        colInfo[columnIndex].nullable = property;
     }
 
     /**
@@ -139,14 +158,21 @@
      */
     public void setSigned(int columnIndex, boolean property)
             throws SQLException {
-        int arrayIndex = columnIndex - 1;
-        checkColumnIndex(arrayIndex);
-        colInfo[arrayIndex].signed = property;
+        checkColumnIndex(columnIndex);
+        colInfo[columnIndex].signed = property;
     }
 
+    /**
+     * {@inheritDoc}
+     * 
+     * @see javax.sql.RowSetMetaData#setColumnDisplaySize(int, int)
+     */
     public void setColumnDisplaySize(int columnIndex, int size)
             throws SQLException {
-        throw new NotImplementedException();
+        checkNegativeValue(size, "sql.30"); //$NON-NLS-1$
+        
+        checkColumnIndex(columnIndex);
+        colInfo[columnIndex].columnDisplaySize = size;
     }
 
     /**
@@ -156,9 +182,8 @@
      */
     public void setColumnLabel(int columnIndex, String label)
             throws SQLException {
-        int arrayIndex = columnIndex - 1;
-        checkColumnIndex(arrayIndex);
-        colInfo[arrayIndex].columnLabel = label == null ? EMPTY_STRING : label;
+        checkColumnIndex(columnIndex);
+        colInfo[columnIndex].columnLabel = label == null ? EMPTY_STRING : label;
     }
 
     /**
@@ -168,9 +193,8 @@
      */
     public void setColumnName(int columnIndex, String columnName)
             throws SQLException {
-        int arrayIndex = columnIndex - 1;
-        checkColumnIndex(arrayIndex);
-        colInfo[arrayIndex].columnName = columnName == null ? EMPTY_STRING
+        checkColumnIndex(columnIndex);
+        colInfo[columnIndex].columnName = columnName == null ? EMPTY_STRING
                 : columnName;
     }
 
@@ -181,29 +205,58 @@
      */
     public void setSchemaName(int columnIndex, String schemaName)
             throws SQLException {
-        int arrayIndex = columnIndex - 1;
-        checkColumnIndex(arrayIndex);
-        colInfo[arrayIndex].schemaName = schemaName == null ? EMPTY_STRING
+        checkColumnIndex(columnIndex);
+        colInfo[columnIndex].schemaName = schemaName == null ? EMPTY_STRING
                 : schemaName;
     }
 
+    /**
+     * {@inheritDoc}
+     * 
+     * @see javax.sql.RowSetMetaData#setPrecision(int, int)
+     */
     public void setPrecision(int columnIndex, int precision)
             throws SQLException {
-        throw new NotImplementedException();
+        checkNegativeValue(precision, "sql.31"); //$NON-NLS-1$
+        
+        checkColumnIndex(columnIndex);
+        colInfo[columnIndex].precision = precision;
     }
 
+    /**
+     * {@inheritDoc}
+     * 
+     * @see javax.sql.RowSetMetaData#setScale(int, int)
+     */
     public void setScale(int columnIndex, int scale) throws SQLException {
-        throw new NotImplementedException();
+        checkNegativeValue(scale, "sql.32"); //$NON-NLS-1$
+        
+        checkColumnIndex(columnIndex);
+        colInfo[columnIndex].scale = scale;
     }
 
+    /**
+     * {@inheritDoc}
+     * 
+     * @see javax.sql.RowSetMetaData#setTableName(int, String)
+     */
     public void setTableName(int columnIndex, String tableName)
             throws SQLException {
-        throw new NotImplementedException();
+        checkColumnIndex(columnIndex);
+        colInfo[columnIndex].tableName = tableName == null ? EMPTY_STRING
+                : tableName;
     }
 
+    /**
+     * {@inheritDoc}
+     * 
+     * @see javax.sql.RowSetMetaData#setCatalogName(int, String)
+     */
     public void setCatalogName(int columnIndex, String catalogName)
             throws SQLException {
-        throw new NotImplementedException();
+        checkColumnIndex(columnIndex);
+        colInfo[columnIndex].catalogName = catalogName == null ? EMPTY_STRING
+                : catalogName;
     }
 
     /**
@@ -214,9 +267,8 @@
     public void setColumnType(int columnIndex, int SQLType) throws SQLException {
         SqlUtil.validateType(SQLType);
         
-        int arrayIndex = columnIndex - 1;        
-        checkColumnIndex(arrayIndex);        
-        colInfo[arrayIndex].colType = SQLType;
+        checkColumnIndex(columnIndex);        
+        colInfo[columnIndex].colType = SQLType;
     }
 
     /**
@@ -226,9 +278,8 @@
      */
     public void setColumnTypeName(int columnIndex, String typeName)
             throws SQLException {
-        int arrayIndex = columnIndex - 1;
-        checkColumnIndex(arrayIndex);
-        colInfo[arrayIndex].colTypeName = typeName == null ? EMPTY_STRING
+        checkColumnIndex(columnIndex);
+        colInfo[columnIndex].colTypeName = typeName == null ? EMPTY_STRING
                 : typeName;
     }
 
@@ -247,9 +298,8 @@
      * @see java.sql.ResultSetMetaData#isAutoIncrement(int)
      */
     public boolean isAutoIncrement(int columnIndex) throws SQLException {
-        int arrayIndex = columnIndex - 1;
-        checkColumnIndex(arrayIndex);
-        return colInfo[arrayIndex].autoIncrement; 
+        checkColumnIndex(columnIndex);
+        return colInfo[columnIndex].autoIncrement; 
     }
 
     /**
@@ -258,9 +308,8 @@
      * @see java.sql.ResultSetMetaData#isCaseSensitive(int)
      */
     public boolean isCaseSensitive(int columnIndex) throws SQLException {
-        int arrayIndex = columnIndex - 1;
-        checkColumnIndex(arrayIndex);
-        return colInfo[arrayIndex].caseSensitive;
+        checkColumnIndex(columnIndex);
+        return colInfo[columnIndex].caseSensitive;
     }
 
     /**
@@ -269,9 +318,8 @@
      * @see java.sql.ResultSetMetaData#isSearchable(int)
      */
     public boolean isSearchable(int columnIndex) throws SQLException {
-        int arrayIndex = columnIndex - 1;
-        checkColumnIndex(arrayIndex);
-        return colInfo[arrayIndex].searchable;
+        checkColumnIndex(columnIndex);
+        return colInfo[columnIndex].searchable;
     }
 
     /**
@@ -280,13 +328,18 @@
      * @see java.sql.ResultSetMetaData#isCurrency(int)
      */
     public boolean isCurrency(int columnIndex) throws SQLException {
-        int arrayIndex = columnIndex - 1;
-        checkColumnIndex(arrayIndex);
-        return colInfo[arrayIndex].currency;
+        checkColumnIndex(columnIndex);
+        return colInfo[columnIndex].currency;
     }
 
+    /**
+     * {@inheritDoc}
+     * 
+     * @see java.sql.ResultSetMetaData#isNullable(int)
+     */
     public int isNullable(int columnIndex) throws SQLException {
-        throw new NotImplementedException();
+        checkColumnIndex(columnIndex);
+        return colInfo[columnIndex].nullable;
     }
 
     /**
@@ -295,13 +348,18 @@
      * @see java.sql.ResultSetMetaData#isSigned(int)
      */
     public boolean isSigned(int columnIndex) throws SQLException {
-        int arrayIndex = columnIndex - 1;
-        checkColumnIndex(arrayIndex);
-        return colInfo[arrayIndex].signed;
+        checkColumnIndex(columnIndex);
+        return colInfo[columnIndex].signed;
     }
 
+    /**
+     * {@inheritDoc}
+     * 
+     * @see java.sql.ResultSetMetaData#getColumnDisplaySize(int)
+     */
     public int getColumnDisplaySize(int columnIndex) throws SQLException {
-        throw new NotImplementedException();
+        checkColumnIndex(columnIndex);
+        return colInfo[columnIndex].columnDisplaySize;
     }
 
     /**
@@ -310,9 +368,8 @@
      * @see java.sql.ResultSetMetaData#getColumnLabel(int)
      */
     public String getColumnLabel(int columnIndex) throws SQLException {
-        int arrayIndex = columnIndex - 1;
-        checkColumnIndex(arrayIndex);
-        return colInfo[arrayIndex].columnLabel;
+        checkColumnIndex(columnIndex);
+        return colInfo[columnIndex].columnLabel;
     }
 
     /**
@@ -321,9 +378,8 @@
      * @see java.sql.ResultSetMetaData#getColumnName(int)
      */
     public String getColumnName(int columnIndex) throws SQLException {
-        int arrayIndex = columnIndex - 1;
-        checkColumnIndex(arrayIndex);
-        return colInfo[arrayIndex].columnName;
+        checkColumnIndex(columnIndex);
+        return colInfo[columnIndex].columnName;
     }
 
     /**
@@ -332,25 +388,48 @@
      * @see java.sql.ResultSetMetaData#getSchemaName(int)
      */
     public String getSchemaName(int columnIndex) throws SQLException {
-        int arrayIndex = columnIndex - 1;
-        checkColumnIndex(arrayIndex);
-        return colInfo[arrayIndex].schemaName;
+        checkColumnIndex(columnIndex);
+        return colInfo[columnIndex].schemaName;
     }
 
+    /**
+     * {@inheritDoc}
+     * 
+     * @see java.sql.ResultSetMetaData#getPrecision(int)
+     */
     public int getPrecision(int columnIndex) throws SQLException {
-        throw new NotImplementedException();
+        checkColumnIndex(columnIndex);
+        return colInfo[columnIndex].precision;
     }
 
+    /**
+     * {@inheritDoc}
+     * 
+     * @see java.sql.ResultSetMetaData#getScale(int)
+     */
     public int getScale(int columnIndex) throws SQLException {
-        throw new NotImplementedException();
+        checkColumnIndex(columnIndex);
+        return colInfo[columnIndex].scale;
     }
 
+    /**
+     * {@inheritDoc}
+     * 
+     * @see java.sql.ResultSetMetaData#getTableName(int)
+     */
     public String getTableName(int columnIndex) throws SQLException {
-        throw new NotImplementedException();
+        checkColumnIndex(columnIndex);
+        return colInfo[columnIndex].tableName;
     }
 
+    /**
+     * {@inheritDoc}
+     * 
+     * @see java.sql.ResultSetMetaData#getCatalogName(int)
+     */
     public String getCatalogName(int columnIndex) throws SQLException {
-        throw new NotImplementedException();
+        checkColumnIndex(columnIndex);
+        return colInfo[columnIndex].catalogName;
     }
 
     /**
@@ -359,9 +438,8 @@
      * @see java.sql.ResultSetMetaData#getColumnType(int)
      */
     public int getColumnType(int columnIndex) throws SQLException {
-        int arrayIndex = columnIndex - 1;
-        checkColumnIndex(arrayIndex);
-        return colInfo[arrayIndex].colType;
+        checkColumnIndex(columnIndex);
+        return colInfo[columnIndex].colType;
     }
 
     /**
@@ -370,9 +448,8 @@
      * @see java.sql.ResultSetMetaData#getColumnTypeName(int)
      */
     public String getColumnTypeName(int columnIndex) throws SQLException {
-        int arrayIndex = columnIndex - 1;
-        checkColumnIndex(arrayIndex);
-        return colInfo[arrayIndex].colTypeName;
+        checkColumnIndex(columnIndex);
+        return colInfo[columnIndex].colTypeName;
     }
 
     /**
@@ -390,9 +467,8 @@
      * @see java.sql.ResultSetMetaData#isWritable(int)
      */
     public boolean isWritable(int columnIndex) throws SQLException {
-        int arrayIndex = columnIndex - 1;
-        checkColumnIndex(arrayIndex);
-        return colInfo[arrayIndex].writeable; 
+        checkColumnIndex(columnIndex);
+        return colInfo[columnIndex].writeable; 
     }
 
     /**
@@ -401,9 +477,8 @@
      * @see java.sql.ResultSetMetaData#isDefinitelyWritable(int)
      */    
     public boolean isDefinitelyWritable(int columnIndex) throws SQLException {
-        int arrayIndex = columnIndex - 1;
-        checkColumnIndex(arrayIndex);
-        return colInfo[arrayIndex].definiteWritable; 
+        checkColumnIndex(columnIndex);
+        return colInfo[columnIndex].definiteWritable; 
     }
 
     /**
@@ -418,8 +493,10 @@
     /**
      * The inner class to store meta information of columns.
      */
-    private class ColInfo {
+    private class ColInfo implements Serializable {
         
+        private static final long serialVersionUID = 5490834817919311283L;
+
         public boolean autoIncrement;
 
         public boolean caseSensitive;
@@ -443,5 +520,17 @@
         public String colTypeName;
 
         public int colType;
+        
+        public int nullable;
+        
+        public int columnDisplaySize;
+        
+        public int precision;
+        
+        public int scale;
+        
+        public String tableName = EMPTY_STRING;
+        
+        public String catalogName = EMPTY_STRING;
     }
 }

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?view=diff&rev=532633&r1=532632&r2=532633
==============================================================================
--- 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 Apr 26 00:09:11 2007
@@ -42,4 +42,8 @@
 sql.25=Unsupported operation. SerialClob is not instantiated with a fully implemented Clob
object.
 sql.26=Invalid column count. Cannot be less or equal to zero
 sql.27=Invalid column index :{0}
-sql.28=Invalid SQL type for column
\ No newline at end of file
+sql.28=Invalid SQL type for column
+sql.29=Invalid nullable constant set. Must be either columnNoNulls, columnNullable or columnNullableUnknown
+sql.30=Invalid column display size. Cannot be less than zero
+sql.31=Invalid precision value. Cannot be less than zero
+sql.32=Invalid scale size. Cannot be less than zero
\ No newline at end of file

Modified: harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/RowSetMetaDataImplTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/RowSetMetaDataImplTest.java?view=diff&rev=532633&r1=532632&r2=532633
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/RowSetMetaDataImplTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/RowSetMetaDataImplTest.java
Thu Apr 26 00:09:11 2007
@@ -1,10 +1,16 @@
 package org.apache.harmony.sql.tests.javax.sql.rowset;
 
 
+import java.io.Serializable;
+import java.sql.ResultSetMetaData;
 import java.sql.SQLException;
 import java.sql.Types;
 
 import javax.sql.rowset.RowSetMetaDataImpl;
+
+import org.apache.harmony.testframework.serialization.SerializationTest;
+import org.apache.harmony.testframework.serialization.SerializationTest.SerializableAssert;
+import junit.framework.Assert;
 import junit.framework.TestCase;
 
 /**
@@ -16,12 +22,33 @@
     private static RowSetMetaDataImpl metaDataImpl = null;
     
     /**
+     * This comparator is designed for RowSetMetaDataImpl objects whose
+     * colCount has already been set. Other objects may fail when using it.
+     */
+    private final static SerializableAssert ROWSET_METADATA_COMPARATOR = new SerializableAssert()
{
+
+        public void assertDeserialized(Serializable initial,
+                Serializable deserialized) {
+            try {
+                RowSetMetaDataImpl initialImpl = (RowSetMetaDataImpl) initial;
+                RowSetMetaDataImpl deserializedImpl = (RowSetMetaDataImpl) deserialized;
+                
+                Assert.assertEquals(initialImpl.getColumnCount(), deserializedImpl.getColumnCount());
               
+                Assert.assertEquals(initialImpl.getColumnType(1), deserializedImpl.getColumnType(1));
+            } catch (SQLException e) {
+                fail();
+            }
+        }
+    };
+    
+    /**
      * @tests javax.sql.rowset.RowSetMetaDataImpl#RowSetMetaDataImpl()
      */
     public void test_Constructor() {
         assertNotNull(metaDataImpl);        
     }
     
+    
     /**
      * @tests {@link javax.sql.rowset.RowSetMetaDataImpl#getColumnCount()}
      */
@@ -40,7 +67,7 @@
         
         metaDataImpl.setColumnCount(Integer.MAX_VALUE);
         assertFalse(metaDataImpl.isAutoIncrement(4));
-        assertEquals(Integer.MAX_VALUE, metaDataImpl.getColumnCount());
+        //assertEquals(Integer.MAX_VALUE, metaDataImpl.getColumnCount());
         // RI throws ArrayIndexOutOfBoundsException here, which is a RI's bug
         try {
             metaDataImpl.isAutoIncrement(5);
@@ -79,6 +106,32 @@
     }
     
     /**
+     * @tests {@link javax.sql.rowset.RowSetMetaDataImpl#getCatalogName(int)}
+     */
+    public void test_getCatalogNameI() throws SQLException {
+        try {
+            metaDataImpl.getCatalogName(1);
+            fail ("should throw SQLException");
+        } catch (SQLException e) {            
+            // expected
+        }
+        
+        metaDataImpl.setColumnCount(2);
+        assertEquals("", metaDataImpl.getCatalogName(1));
+        metaDataImpl.setCatalogName(1, "catalog");
+        assertEquals("catalog", metaDataImpl.getCatalogName(1));
+        metaDataImpl.setCatalogName(1, null);
+        assertEquals("", metaDataImpl.getCatalogName(1));
+        
+        try {
+            metaDataImpl.getCatalogName(Integer.MIN_VALUE);
+            fail ("should throw SQLException");
+        } catch (SQLException e) {            
+            // expected
+        }
+    }
+    
+    /**
      * @tests {@link javax.sql.rowset.RowSetMetaDataImpl#getColumnClassName(int)}
      */
     public void test_getColumnClassNameI() throws SQLException {
@@ -116,6 +169,30 @@
     }
     
     /**
+     * @tests {@link javax.sql.rowset.RowSetMetaDataImpl#getColumnDisplaySize(int)}
+     */
+    public void test_getColumnDisplaySizeI() throws SQLException {
+        try {
+            metaDataImpl.getColumnDisplaySize(1);
+            fail ("should throw SQLException");
+        } catch (SQLException e) {            
+            // expected
+        }
+        
+        metaDataImpl.setColumnCount(2);
+        assertEquals(0, metaDataImpl.getColumnDisplaySize(1));
+        metaDataImpl.setColumnDisplaySize(1, 4);
+        assertEquals(4, metaDataImpl.getColumnDisplaySize(1));
+        
+        try {
+            metaDataImpl.getColumnDisplaySize(-32);
+            fail ("should throw SQLException");
+        } catch (SQLException e) {            
+            // expected
+        }
+    }
+    
+    /**
      * @tests {@link javax.sql.rowset.RowSetMetaDataImpl#getColumnLabel(int)}
      */
     public void test_getColumnLabelI() throws SQLException {
@@ -217,6 +294,54 @@
     }
     
     /**
+     * @tests {@link javax.sql.rowset.RowSetMetaDataImpl#getPrecision(int)}
+     */
+    public void test_getPrecisionI() throws SQLException {
+        try {
+            metaDataImpl.getPrecision(2);
+            fail ("should throw SQLException");
+        } catch (SQLException e) {            
+            // expected
+        }
+        
+        metaDataImpl.setColumnCount(1);
+        assertEquals(0, metaDataImpl.getPrecision(1));
+        metaDataImpl.setPrecision(1, Integer.MAX_VALUE);
+        assertEquals(Integer.MAX_VALUE, metaDataImpl.getPrecision(1));
+        
+        try {
+            metaDataImpl.getPrecision(3);
+            fail ("should throw SQLException");
+        } catch (SQLException e) {            
+            // expected
+        }
+    }
+    
+    /**
+     * @tests {@link javax.sql.rowset.RowSetMetaDataImpl#getSchemaName(int)}
+     */
+    public void test_getScaleI() throws SQLException {
+        try {
+            metaDataImpl.getScale(1);
+            fail ("should throw SQLException");
+        } catch (SQLException e) {            
+            // expected
+        }
+        
+        metaDataImpl.setColumnCount(2);
+        assertEquals(0, metaDataImpl.getScale(2));
+        metaDataImpl.setScale(2, Integer.MAX_VALUE);
+        assertEquals(Integer.MAX_VALUE, metaDataImpl.getScale(2));
+        
+        try {
+            metaDataImpl.getScale(3);
+            fail ("should throw SQLException");
+        } catch (SQLException e) {            
+            // expected
+        }
+    }
+    
+    /**
      * @tests {@link javax.sql.rowset.RowSetMetaDataImpl#getSchemaName(int)}
      */
     public void test_getSchemaNameI() throws SQLException {
@@ -241,6 +366,31 @@
         }
     }
     
+    /**
+     * @tests {@link javax.sql.rowset.RowSetMetaDataImpl#getTableName(int)}
+     */
+    public void test_getTableNameI() throws SQLException {
+        try {
+            metaDataImpl.getTableName(2);
+            fail ("should throw SQLException");
+        } catch (SQLException e) {            
+            // expected
+        }
+        
+        metaDataImpl.setColumnCount(2);
+        assertEquals("", metaDataImpl.getTableName(1));
+        assertEquals("", metaDataImpl.getTableName(2));
+        metaDataImpl.setTableName(1, "tableName");
+        assertEquals("tableName", metaDataImpl.getTableName(1));
+        assertEquals("", metaDataImpl.getTableName(2));
+        
+        try {
+            metaDataImpl.getTableName(Integer.MIN_VALUE);
+            fail("should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+    }
     
     /**
      * @tests {@link javax.sql.rowset.RowSetMetaDataImpl#isAutoIncrement(int)}
@@ -332,6 +482,30 @@
     }
     
     /**
+     * @tests {@link javax.sql.rowset.RowSetMetaDataImpl#isNullable(int)}
+     */
+    public void test_isNullableI() throws SQLException {
+        try {
+            metaDataImpl.isNullable(1);
+            fail("should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+        
+        metaDataImpl.setColumnCount(2);
+        assertEquals(ResultSetMetaData.columnNoNulls, metaDataImpl.isNullable(1));
+        metaDataImpl.setNullable(1, ResultSetMetaData.columnNullableUnknown);
+        assertEquals(ResultSetMetaData.columnNullableUnknown, metaDataImpl.isNullable(1));
+        
+        try {
+            metaDataImpl.isNullable(3);
+            fail("should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+    }
+    
+    /**
      * @tests {@link javax.sql.rowset.RowSetMetaDataImpl#isReadOnly(int)}
      */
     public void test_isReadOnlyI() throws SQLException {
@@ -496,6 +670,62 @@
     }
     
     /**
+     * @tests {@link javax.sql.rowset.RowSetMetaDataImpl#setCatalogName(int, String)}
+     */
+    public void test_setCatalogNameILjava_lang_String() throws SQLException {
+        try {
+            metaDataImpl.setCatalogName(1, "test");
+            fail ("should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+        
+        metaDataImpl.setColumnCount(1);
+        metaDataImpl.setCatalogName(1, "AbC");
+        assertEquals("AbC", metaDataImpl.getCatalogName(1));
+        metaDataImpl.setCatalogName(1, null);
+        assertEquals("", metaDataImpl.getCatalogName(1));
+        
+        try {
+            metaDataImpl.setCatalogName(10, null);
+            fail ("should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+    }
+    
+    /**
+     * @tests {@link javax.sql.rowset.RowSetMetaDataImpl#setColumnDisplaySize(int, int)}
+     */
+    public void test_setColumnDisplaySizeII() throws SQLException {
+        try {
+            metaDataImpl.setColumnDisplaySize(1, 2);
+            fail ("should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+        
+        metaDataImpl.setColumnCount(1);
+        assertEquals(0, metaDataImpl.getColumnDisplaySize(1));
+        metaDataImpl.setColumnDisplaySize(1, Integer.MAX_VALUE);
+        assertEquals(Integer.MAX_VALUE, metaDataImpl.getColumnDisplaySize(1));
+        
+        try {
+            metaDataImpl.setColumnDisplaySize(2, 0);
+            fail ("should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+        
+        try {
+            metaDataImpl.setColumnDisplaySize(2, Integer.MIN_VALUE);
+            fail ("should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+    }
+    
+    /**
      * @tests {@link javax.sql.rowset.RowSetMetaDataImpl#setColumnName(int, String)}
      */
     public void test_setColumnNameILjava_lang_String() throws SQLException {
@@ -626,6 +856,90 @@
     }
     
     /**
+     * @tests {@link javax.sql.rowset.RowSetMetaDataImpl#setNullable(int, int)}
+     */
+    public void test_setNullableII() throws SQLException {
+        try {
+            metaDataImpl.setNullable(21, 1);
+            fail ("should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+        
+        metaDataImpl.setColumnCount(1);
+        assertEquals(0, metaDataImpl.isNullable(1));
+        metaDataImpl.setNullable(1, ResultSetMetaData.columnNullable);
+        assertEquals(ResultSetMetaData.columnNullable, metaDataImpl.isNullable(1));
+        
+        try {
+            metaDataImpl.setNullable(2, ResultSetMetaData.columnNullableUnknown);
+            fail ("should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+        
+        try {
+            metaDataImpl.setNullable(2, 3);
+            fail ("should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+    }
+    
+    /**
+     * @tests {@link javax.sql.rowset.RowSetMetaDataImpl#setPrecision(int, int)}
+     */
+    public void test_setPrecisionII() throws SQLException {
+        try {
+            metaDataImpl.setPrecision(12, 1);
+            fail ("should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+        
+        metaDataImpl.setColumnCount(1);
+        metaDataImpl.setPrecision(1, 0);
+        assertEquals(0, metaDataImpl.getPrecision(1));
+        
+        try {
+            metaDataImpl.setPrecision(12, Integer.MIN_VALUE);
+            fail ("should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+    }
+    
+    /**
+     * @tests {@link javax.sql.rowset.RowSetMetaDataImpl#setScale(int, int)}
+     */
+    public void test_setScaleII() throws SQLException {
+        try {
+            metaDataImpl.setScale(34, 5);
+            fail ("should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+        
+        metaDataImpl.setColumnCount(1);
+        metaDataImpl.setScale(1, 252);
+        assertEquals(252, metaDataImpl.getScale(1));
+        
+        try {
+            metaDataImpl.setScale(1, -23);
+            fail ("should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+        
+        try {
+            metaDataImpl.setScale(2, Integer.MIN_VALUE);
+            fail ("should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+    }
+    
+    /**
      * @tests {@link javax.sql.rowset.RowSetMetaDataImpl#setSchemaName(int, String)}
      */
     public void test_setSchemaNameILjava_lang_String() throws SQLException {
@@ -701,6 +1015,52 @@
         } catch (SQLException e) {
             // expected
         }
+    }
+    
+    /**
+     * @tests {@link javax.sql.rowset.RowSetMetaDataImpl#setTableName(int, String)}
+     */
+    public void test_setTableNameILjava_lang_String() throws SQLException {
+        try {
+            metaDataImpl.setTableName(34, null);
+            fail ("should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+        
+        metaDataImpl.setColumnCount(2);
+        metaDataImpl.setTableName(2, "test");
+        assertEquals("test", metaDataImpl.getTableName(2));
+        metaDataImpl.setTableName(2, null);
+        assertEquals("", metaDataImpl.getTableName(2));
+        
+        try {
+            metaDataImpl.setTableName(-3, null);
+            fail("should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+    }
+    
+    /**
+     * @tests serialization/deserialization.
+     */
+    public void test_serialization_self() throws Exception {
+       RowSetMetaDataImpl impl = new RowSetMetaDataImpl();
+       impl.setColumnCount(1);
+       impl.setColumnType(1, Types.CHAR);
+       SerializationTest.verifySelf(impl, ROWSET_METADATA_COMPARATOR);
+    }
+    
+    /**
+     * @tests serialization/deserialization compatibility with RI.
+     */
+    public void test_serialization_compatibility() throws Exception {
+        RowSetMetaDataImpl impl = new RowSetMetaDataImpl();
+        impl.setColumnCount(2);
+        impl.setColumnType(1, Types.ARRAY);
+        impl.setColumnType(2, Types.BIGINT);
+        SerializationTest.verifyGolden(this, impl, ROWSET_METADATA_COMPARATOR);
     }
 
     @Override

Added: harmony/enhanced/classlib/trunk/modules/sql/src/test/resources/serialization/org/apache/harmony/sql/tests/javax/sql/rowset/RowSetMetaDataImplTest.golden.ser
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/test/resources/serialization/org/apache/harmony/sql/tests/javax/sql/rowset/RowSetMetaDataImplTest.golden.ser?view=auto&rev=532633
==============================================================================
Binary file - no diff available.

Propchange: harmony/enhanced/classlib/trunk/modules/sql/src/test/resources/serialization/org/apache/harmony/sql/tests/javax/sql/rowset/RowSetMetaDataImplTest.golden.ser
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream



Mime
View raw message