harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From py...@apache.org
Subject svn commit: r532274 - 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/
Date Wed, 25 Apr 2007 09:20:19 GMT
Author: pyang
Date: Wed Apr 25 02:20:18 2007
New Revision: 532274

URL: http://svn.apache.org/viewvc?view=rev&rev=532274
Log:
Apply patch for HARMONY-3748( [classlib][sql] 9 new methods in RowSetMetaDataImpl) with modifications

Added:
    harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/sql/rowset/SqlUtil.java
  (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=532274&r1=532273&r2=532274
==============================================================================
--- 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
Wed Apr 25 02:20:18 2007
@@ -40,7 +40,7 @@
     private static final int DEFAULT_COLUMN_COUNT = 4;
 
     private static final long serialVersionUID = 6893806403181801867L;
-
+        
     private int colCount;
 
     private ColInfo[] colInfo;
@@ -161,14 +161,30 @@
         colInfo[arrayIndex].columnLabel = label == null ? EMPTY_STRING : label;
     }
 
+    /**
+     * {@inheritDoc}
+     * 
+     * @see javax.sql.RowSetMetaData#setColumnName(int, String)
+     */
     public void setColumnName(int columnIndex, String columnName)
             throws SQLException {
-        throw new NotImplementedException();
+        int arrayIndex = columnIndex - 1;
+        checkColumnIndex(arrayIndex);
+        colInfo[arrayIndex].columnName = columnName == null ? EMPTY_STRING
+                : columnName;
     }
 
+    /**
+     * {@inheritDoc}
+     * 
+     * @see javax.sql.RowSetMetaData#setSchemaName(int, String)
+     */
     public void setSchemaName(int columnIndex, String schemaName)
             throws SQLException {
-        throw new NotImplementedException();
+        int arrayIndex = columnIndex - 1;
+        checkColumnIndex(arrayIndex);
+        colInfo[arrayIndex].schemaName = schemaName == null ? EMPTY_STRING
+                : schemaName;
     }
 
     public void setPrecision(int columnIndex, int precision)
@@ -190,13 +206,30 @@
         throw new NotImplementedException();
     }
 
+    /**
+     * {@inheritDoc}
+     * 
+     * @see javax.sql.RowSetMetaData#setColumnType(int, int)
+     */
     public void setColumnType(int columnIndex, int SQLType) throws SQLException {
-        throw new NotImplementedException();
+        SqlUtil.validateType(SQLType);
+        
+        int arrayIndex = columnIndex - 1;        
+        checkColumnIndex(arrayIndex);        
+        colInfo[arrayIndex].colType = SQLType;
     }
 
+    /**
+     * {@inheritDoc}
+     * 
+     * @see javax.sql.RowSetMetaData#setColumnTypeName(int, String)
+     */
     public void setColumnTypeName(int columnIndex, String typeName)
             throws SQLException {
-        throw new NotImplementedException();
+        int arrayIndex = columnIndex - 1;
+        checkColumnIndex(arrayIndex);
+        colInfo[arrayIndex].colTypeName = typeName == null ? EMPTY_STRING
+                : typeName;
     }
 
     /**
@@ -282,12 +315,26 @@
         return colInfo[arrayIndex].columnLabel;
     }
 
+    /**
+     * {@inheritDoc}
+     * 
+     * @see java.sql.ResultSetMetaData#getColumnName(int)
+     */
     public String getColumnName(int columnIndex) throws SQLException {
-        throw new NotImplementedException();
+        int arrayIndex = columnIndex - 1;
+        checkColumnIndex(arrayIndex);
+        return colInfo[arrayIndex].columnName;
     }
 
+    /**
+     * {@inheritDoc}
+     * 
+     * @see java.sql.ResultSetMetaData#getSchemaName(int)
+     */
     public String getSchemaName(int columnIndex) throws SQLException {
-        throw new NotImplementedException();
+        int arrayIndex = columnIndex - 1;
+        checkColumnIndex(arrayIndex);
+        return colInfo[arrayIndex].schemaName;
     }
 
     public int getPrecision(int columnIndex) throws SQLException {
@@ -306,12 +353,26 @@
         throw new NotImplementedException();
     }
 
+    /**
+     * {@inheritDoc}
+     * 
+     * @see java.sql.ResultSetMetaData#getColumnType(int)
+     */
     public int getColumnType(int columnIndex) throws SQLException {
-        throw new NotImplementedException();
+        int arrayIndex = columnIndex - 1;
+        checkColumnIndex(arrayIndex);
+        return colInfo[arrayIndex].colType;
     }
 
+    /**
+     * {@inheritDoc}
+     * 
+     * @see java.sql.ResultSetMetaData#getColumnTypeName(int)
+     */
     public String getColumnTypeName(int columnIndex) throws SQLException {
-        throw new NotImplementedException();
+        int arrayIndex = columnIndex - 1;
+        checkColumnIndex(arrayIndex);
+        return colInfo[arrayIndex].colTypeName;
     }
 
     /**
@@ -345,8 +406,13 @@
         return colInfo[arrayIndex].definiteWritable; 
     }
 
+    /**
+     * {@inheritDoc}
+     * 
+     * @see java.sql.ResultSetMetaData#getColumnClassName(int)
+     */    
     public String getColumnClassName(int columnIndex) throws SQLException {
-        throw new NotImplementedException();
+        return SqlUtil.getClassNameByType(getColumnType(columnIndex));
     }
 
     /**
@@ -369,5 +435,13 @@
         public boolean definiteWritable = true;
         
         public String columnLabel;
+
+        public String columnName;
+
+        public String schemaName = EMPTY_STRING;
+
+        public String colTypeName;
+
+        public int colType;
     }
-}
\ No newline at end of file
+}

Added: harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/sql/rowset/SqlUtil.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/sql/rowset/SqlUtil.java?view=auto&rev=532274
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/sql/rowset/SqlUtil.java
(added)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/sql/rowset/SqlUtil.java
Wed Apr 25 02:20:18 2007
@@ -0,0 +1,119 @@
+/*
+ * 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 javax.sql.rowset;
+
+import java.sql.SQLException;
+import java.sql.Types;
+import org.apache.harmony.sql.internal.nls.Messages;
+
+
+class SqlUtil{
+    /*
+     * FIXME:Validate column types is defined by java.sql.Types, current implementation is
ugly, need to find 
+     * an elegant and effient way to check all constants defined in java.util.sql.Types 
+     */
+    static void validateType(int type) throws SQLException {
+        switch(type){
+            case Types.ARRAY:
+            case Types.BIGINT:
+            case Types.BINARY:
+            case Types.BIT:
+            case Types.BLOB:
+            case Types.BOOLEAN:
+            case Types.CHAR:
+            case Types.CLOB:
+            case Types.DATALINK:
+            case Types.DATE:
+            case Types.DECIMAL:
+            case Types.DISTINCT:
+            case Types.DOUBLE:
+            case Types.FLOAT:
+            case Types.INTEGER:
+            case Types.JAVA_OBJECT:
+            case Types.LONGVARBINARY:
+            case Types.LONGVARCHAR:
+            case Types.NULL:
+            case Types.NUMERIC:
+            case Types.OTHER:
+            case Types.REAL:
+            case Types.REF:
+            case Types.SMALLINT:
+            case Types.STRUCT:
+            case Types.TIME:
+            case Types.TIMESTAMP:
+            case Types.TINYINT:
+            case Types.VARBINARY:
+            case Types.VARCHAR:
+                return;
+        }
+        throw new SQLException(Messages.getString("sql.28")); //$NON-NLS-1$
+    }
+
+    static String getClassNameByType(int type){ 
+        String className = null;
+        switch (type) {        
+        case Types.BINARY:
+        case Types.BLOB:
+        case Types.LONGVARBINARY:
+        case Types.VARBINARY:
+            className = new byte[0].getClass().getName();
+            break;
+        case Types.DOUBLE:
+        case Types.FLOAT:
+            className = Double.class.getName();
+            break;
+        case Types.BIGINT:
+            className = Long.class.getName();
+            break;
+        case Types.BIT:
+            className = Boolean.class.getName();
+            break;
+        case Types.DECIMAL:
+        case Types.NUMERIC:
+            className = java.math.BigDecimal.class.getName();
+            break;
+        case Types.CLOB:
+            className = new char[0].getClass().getName();
+            break;
+        case Types.DATE:
+            className = java.sql.Date.class.getName();
+            break;
+        case Types.INTEGER:
+            className = Integer.class.getName();
+            break;
+        case Types.REAL:
+            className = Float.class.getName();
+            break;
+        case Types.SMALLINT:
+            className = Short.class.getName();
+            break;
+        case Types.TIME:
+            className = java.sql.Time.class.getName();
+            break;
+        case Types.TIMESTAMP:
+            className = java.sql.Timestamp.class.getName();
+            break;
+        case Types.TINYINT:
+            className = Byte.class.getName();
+            break;
+        default:
+            className = String.class.getName();
+        }
+        return className;
+    }
+}

Propchange: harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/sql/rowset/SqlUtil.java
------------------------------------------------------------------------------
    svn:eol-style = native

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=532274&r1=532273&r2=532274
==============================================================================
--- 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
Wed Apr 25 02:20:18 2007
@@ -41,4 +41,5 @@
 sql.24=Invalid length for truncate
 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}
\ No newline at end of file
+sql.27=Invalid column index :{0}
+sql.28=Invalid SQL type for column
\ 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=532274&r1=532273&r2=532274
==============================================================================
--- 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
Wed Apr 25 02:20:18 2007
@@ -2,6 +2,7 @@
 
 
 import java.sql.SQLException;
+import java.sql.Types;
 
 import javax.sql.rowset.RowSetMetaDataImpl;
 import junit.framework.TestCase;
@@ -78,7 +79,44 @@
     }
     
     /**
-     * @tests {@link javax.sql.rowset.RowSetMetaDataImpl#getColumnLabel(int)
+     * @tests {@link javax.sql.rowset.RowSetMetaDataImpl#getColumnClassName(int)}
+     */
+    public void test_getColumnClassNameI() throws SQLException {
+        try {
+            metaDataImpl.getColumnClassName(1);
+            fail ("should throw SQLException");
+        } catch (SQLException e) {            
+            // expected
+        }
+        
+        metaDataImpl.setColumnCount(12);
+        assertEquals("java.lang.String", metaDataImpl.getColumnClassName(12));
+        
+        metaDataImpl.setColumnTypeName(12, null);
+        assertEquals("java.lang.String", metaDataImpl.getColumnClassName(12));
+        metaDataImpl.setColumnType(12, Types.BLOB);
+        assertEquals("[B", metaDataImpl.getColumnClassName(12));
+        metaDataImpl.setColumnType(12, Types.FLOAT);
+        assertEquals("java.lang.Double", metaDataImpl.getColumnClassName(12));
+        metaDataImpl.setColumnType(12, Types.BIGINT);
+        assertEquals("java.lang.Long", metaDataImpl.getColumnClassName(12));
+        metaDataImpl.setColumnType(12, Types.BIT);
+        assertEquals("java.lang.Boolean", metaDataImpl.getColumnClassName(12));
+        metaDataImpl.setColumnType(12, Types.DECIMAL);
+        assertEquals("java.math.BigDecimal", metaDataImpl.getColumnClassName(12));
+        metaDataImpl.setColumnType(12, Types.TINYINT);
+        assertEquals("java.lang.Byte", metaDataImpl.getColumnClassName(12));
+        
+        try {
+            metaDataImpl.getColumnClassName(0);
+            fail ("should throw SQLException");
+        } catch (SQLException e) {            
+            // expected
+        }
+    }
+    
+    /**
+     * @tests {@link javax.sql.rowset.RowSetMetaDataImpl#getColumnLabel(int)}
      */
     public void test_getColumnLabelI() throws SQLException {
         try {
@@ -104,6 +142,107 @@
     }
     
     /**
+     * @tests {@link javax.sql.rowset.RowSetMetaDataImpl#getColumnName(int)}
+     */
+    public void test_getColumnNameI() throws SQLException {
+        try {
+            metaDataImpl.getColumnName(1);
+            fail ("should throw SQLException");
+        } catch (SQLException e) {            
+            // expected
+        }
+        
+        metaDataImpl.setColumnCount(13);
+        assertNull(metaDataImpl.getColumnName(12));
+        metaDataImpl.setColumnName(12, null);
+        assertEquals("", metaDataImpl.getColumnName(12));
+        metaDataImpl.setColumnName(12, "ColumnName");
+        assertEquals("ColumnName", metaDataImpl.getColumnName(12));
+        
+        try {
+            metaDataImpl.getColumnName(0);
+            fail ("should throw SQLException");
+        } catch (SQLException e) {            
+            // expected
+        }
+    }
+    
+    /**
+     * @tests {@link javax.sql.rowset.RowSetMetaDataImpl#getColumnType(int)}
+     */
+    public void test_getColumnTypeI() throws SQLException {
+        try {
+            metaDataImpl.getColumnType(1);
+            fail ("should throw SQLException");
+        } catch (SQLException e) {            
+            // expected
+        }
+        
+        metaDataImpl.setColumnCount(13);
+        metaDataImpl.setColumnType(13, Types.ARRAY);
+        assertEquals(Types.ARRAY, metaDataImpl.getColumnType(13));
+        
+        try {
+            metaDataImpl.getColumnType(14);
+            fail ("should throw SQLException");
+        } catch (SQLException e) {            
+            // expected
+        }
+    }
+    
+    /**
+     * @tests {@link javax.sql.rowset.RowSetMetaDataImpl#getColumnTypeName(int)}
+     */
+    public void test_getColumnTypeNameI() throws SQLException {
+        try {
+            metaDataImpl.getColumnTypeName(223);
+            fail ("should throw SQLException");
+        } catch (SQLException e) {            
+            // expected
+        }
+        
+        metaDataImpl.setColumnCount(21);
+        metaDataImpl.setColumnType(14, Types.BIGINT);
+        metaDataImpl.setColumnTypeName(14, null);
+        assertEquals("", metaDataImpl.getColumnTypeName(14));
+        metaDataImpl.setColumnTypeName(14, "haha");
+        assertEquals("haha", metaDataImpl.getColumnTypeName(14));
+        
+        try {
+            metaDataImpl.getColumnTypeName(22);
+            fail ("should throw SQLException");
+        } catch (SQLException e) {            
+            // expected
+        }
+    }
+    
+    /**
+     * @tests {@link javax.sql.rowset.RowSetMetaDataImpl#getSchemaName(int)}
+     */
+    public void test_getSchemaNameI() throws SQLException {
+        try {
+            metaDataImpl.getSchemaName(352);
+            fail ("should throw SQLException");
+        } catch (SQLException e) {            
+            // expected
+        }
+        
+        metaDataImpl.setColumnCount(67);
+        metaDataImpl.setSchemaName(67, null);
+        assertEquals("", metaDataImpl.getSchemaName(67));
+        metaDataImpl.setSchemaName(67, "a \u0053");
+        assertEquals("a S", metaDataImpl.getSchemaName(67));
+        
+        try {
+            metaDataImpl.getSchemaName(Integer.MIN_VALUE);
+            fail ("should throw SQLException");
+        } catch (SQLException e) {            
+            // expected
+        }
+    }
+    
+    
+    /**
      * @tests {@link javax.sql.rowset.RowSetMetaDataImpl#isAutoIncrement(int)}
      */
     public void test_isAutoIncrementI() throws SQLException {
@@ -357,9 +496,35 @@
     }
     
     /**
+     * @tests {@link javax.sql.rowset.RowSetMetaDataImpl#setColumnName(int, String)}
+     */
+    public void test_setColumnNameILjava_lang_String() throws SQLException {
+        try {
+            metaDataImpl.setColumnName(1, null);
+            fail ("should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+        
+        metaDataImpl.setColumnCount(4);
+        assertNull(metaDataImpl.getColumnName(1));
+        metaDataImpl.setColumnName(1, "ate dsW");
+        assertEquals("ate dsW", metaDataImpl.getColumnName(1));
+        metaDataImpl.setColumnName(1, null);
+        assertEquals("", metaDataImpl.getColumnName(1));
+        
+        try {
+            metaDataImpl.setColumnName(5, "exception");
+            fail ("should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+    }
+    
+    /**
      * @tests {@link javax.sql.rowset.RowSetMetaDataImpl#setColumnLabel(int, String)}
      */
-    public void test_setColumnLabelIZ() throws SQLException {
+    public void test_setColumnLabelILjava_lang_String() throws SQLException {
         try {
             metaDataImpl.setColumnLabel(1, null);
             fail ("should throw SQLException");
@@ -381,6 +546,60 @@
     }
     
     /**
+     * @tests {@link javax.sql.rowset.RowSetMetaDataImpl#setColumnType(int, int)}
+     */
+    public void test_setColumnTypeII() throws SQLException {
+       try {
+           metaDataImpl.setColumnType(1, Types.BIGINT);
+           fail ("should throw SQLException");
+       } catch (SQLException e) {
+           // expected
+       }
+       
+       metaDataImpl.setColumnCount(2);
+       assertEquals(0, metaDataImpl.getColumnType(1));
+       metaDataImpl.setColumnType(1, Types.CLOB);
+       assertEquals(Types.CLOB, metaDataImpl.getColumnType(1));
+       metaDataImpl.setColumnType(1, Types.BOOLEAN);
+       assertEquals(Types.BOOLEAN, metaDataImpl.getColumnType(1));
+       
+       try {
+           metaDataImpl.setColumnType(1, 66);
+           fail ("should throw SQLException");
+       } catch (SQLException e) {
+           // expected
+       }       
+       
+       try {
+           metaDataImpl.setColumnType(3, 58);
+           fail ("should throw SQLException");
+       } catch (SQLException e) {
+           // expected
+       }
+    } 
+    
+    /**
+     * @tests {@link javax.sql.rowset.RowSetMetaDataImpl#setColumnTypeName(int, String)}
+     */
+    public void test_setColumnTypeNameILjava_lang_String() throws SQLException {
+        try {
+            metaDataImpl.setColumnTypeName(1, "aa");
+            fail ("should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+        
+        metaDataImpl.setColumnCount(2);
+        assertNull(metaDataImpl.getColumnTypeName(2));
+        metaDataImpl.setColumnTypeName(2, null);
+        assertEquals("", metaDataImpl.getColumnTypeName(2));
+        metaDataImpl.setColumnTypeName(2, "");
+        assertEquals("", metaDataImpl.getColumnTypeName(2));
+        metaDataImpl.setColumnTypeName(2, "java.lang.String");
+        assertEquals(0, metaDataImpl.getColumnType(2));
+    }
+    
+    /**
      * @tests {@link javax.sql.rowset.RowSetMetaDataImpl#setCurrency(int, boolean)}
      */
     public void test_setCurrencyIZ() throws SQLException {
@@ -400,6 +619,32 @@
         
         try {
             metaDataImpl.setCurrency(8, true);
+            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 {
+        try {
+            metaDataImpl.setSchemaName(-12, "asw");
+            fail ("should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+        
+        metaDataImpl.setColumnCount(7);
+        assertEquals("", metaDataImpl.getSchemaName(3));
+        metaDataImpl.setSchemaName(3, "schema name");
+        assertEquals("schema name", metaDataImpl.getSchemaName(3));
+        metaDataImpl.setSchemaName(3, null);
+        assertEquals("", metaDataImpl.getSchemaName(3));
+        
+        try {
+            metaDataImpl.setSchemaName(Integer.MIN_VALUE, null);
             fail ("should throw SQLException");
         } catch (SQLException e) {
             // expected



Mime
View raw message