harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From py...@apache.org
Subject svn commit: r537734 - in /harmony/enhanced/classlib/trunk/modules/sql/src: main/java/javax/sql/rowset/serial/SQLOutputImpl.java test/java/org/apache/harmony/sql/tests/javax/sql/rowset/serial/SQLOutputImplTest.java
Date Mon, 14 May 2007 06:57:23 GMT
Author: pyang
Date: Sun May 13 23:57:22 2007
New Revision: 537734

URL: http://svn.apache.org/viewvc?view=rev&rev=537734
Log:
Apply patch for HARMONY-3781([classlib][sql] 8 new methods in javax.sql.rowset.serial.SQLOutputImpl)

Modified:
    harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/sql/rowset/serial/SQLOutputImpl.java
    harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/serial/SQLOutputImplTest.java

Modified: harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/sql/rowset/serial/SQLOutputImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/sql/rowset/serial/SQLOutputImpl.java?view=diff&rev=537734&r1=537733&r2=537734
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/sql/rowset/serial/SQLOutputImpl.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/sql/rowset/serial/SQLOutputImpl.java
Sun May 13 23:57:22 2007
@@ -36,9 +36,32 @@
 import java.util.Vector;
 
 import org.apache.harmony.luni.util.NotImplementedException;
+import org.apache.harmony.sql.internal.nls.Messages;
 
 public class SQLOutputImpl implements SQLOutput {
-    public SQLOutputImpl(Vector<?> attributes, Map<String,?> map) throws SQLException,
NotImplementedException {
+    private Vector attributes;
+
+    private Map map;
+    
+    /**
+     * Constructs a new SQLOutputImpl object using a list of attributes and a
+     * custom name-type map. JDBC drivers will use this map to identify which
+     * SQLData.writeSQL will be invoked.
+     * 
+     * @param attributes -
+     *            the list of given attribute objects.
+     * @param map -
+     *            the UDT(user defined type) name-type map
+     * @throws SQLException -
+     *             if the attributes or the map is null
+     */
+    public SQLOutputImpl(Vector<?> attributes, Map<String, ?> map)
+            throws SQLException {
+        if (null == attributes || null == map) {
+            throw new SQLException(Messages.getString("sql.33")); //$NON-NLS-1$
+        }
+        this.attributes = attributes;
+        this.map = map;
     }
 
     public void writeArray(Array theArray) throws SQLException,
@@ -70,23 +93,36 @@
         throw new NotImplementedException();
 
     }
-
+    
+    /**
+     * {@inheritDoc}
+     * 
+     * @see java.sql.SQLOutput#writeBoolean(boolean)
+     */
+    @SuppressWarnings({ "boxing", "unchecked" })
     public void writeBoolean(boolean theFlag) throws SQLException,
             NotImplementedException {
-        throw new NotImplementedException();
-
+        attributes.addElement(theFlag);
     }
 
-    public void writeByte(byte theByte) throws SQLException,
-            NotImplementedException {
-        throw new NotImplementedException();
-
-    }
-
-    public void writeBytes(byte[] theBytes) throws SQLException,
-            NotImplementedException {
-        throw new NotImplementedException();
-
+    /**
+     * {@inheritDoc}
+     * 
+     * @see java.sql.SQLOutput#writeByte(byte)
+     */
+    @SuppressWarnings({ "boxing", "unchecked" })
+    public void writeByte(byte theByte) throws SQLException {
+        attributes.addElement(theByte);
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see java.sql.SQLOutput#writeBytes(byte[])
+     */
+    @SuppressWarnings({ "boxing", "unchecked" })
+    public void writeBytes(byte[] theBytes) throws SQLException {
+        attributes.addElement(theBytes);
     }
 
     public void writeCharacterStream(Reader theStream) throws SQLException,
@@ -106,29 +142,45 @@
         throw new NotImplementedException();
 
     }
-
-    public void writeDouble(double theDouble) throws SQLException,
-            NotImplementedException {
-        throw new NotImplementedException();
-
-    }
-
-    public void writeFloat(float theFloat) throws SQLException,
-            NotImplementedException {
-        throw new NotImplementedException();
-
-    }
-
-    public void writeInt(int theInt) throws SQLException,
-            NotImplementedException {
-        throw new NotImplementedException();
-
-    }
-
-    public void writeLong(long theLong) throws SQLException,
-            NotImplementedException {
-        throw new NotImplementedException();
-
+    
+    /**
+     * {@inheritDoc}
+     * 
+     * @see java.sql.SQLOutput#writeDouble(double)
+     */
+    @SuppressWarnings( { "boxing", "unchecked" })
+    public void writeDouble(double theDouble) throws SQLException {
+        attributes.addElement(theDouble);
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see java.sql.SQLOutput#writeFloat(float)
+     */
+    @SuppressWarnings( { "boxing", "unchecked" })
+    public void writeFloat(float theFloat) throws SQLException {
+        attributes.addElement(theFloat);
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see java.sql.SQLOutput#writeInt(int)
+     */
+    @SuppressWarnings( { "boxing", "unchecked" })
+    public void writeInt(int theInt) throws SQLException {
+        attributes.addElement(theInt);
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see java.sql.SQLOutput#writeLong(long)
+     */
+    @SuppressWarnings( { "boxing", "unchecked" })
+    public void writeLong(long theLong) throws SQLException {
+        attributes.addElement(theLong);
     }
 
     public void writeObject(SQLData theObject) throws SQLException,
@@ -143,10 +195,14 @@
 
     }
 
-    public void writeShort(short theShort) throws SQLException,
-            NotImplementedException {
-        throw new NotImplementedException();
-
+    /**
+     * {@inheritDoc}
+     * 
+     * @see java.sql.SQLOutput#writeShort(short)
+     */
+    @SuppressWarnings( { "boxing", "unchecked" })
+    public void writeShort(short theShort) throws SQLException {
+        attributes.addElement(theShort);
     }
 
     public void writeString(String theString) throws SQLException,

Modified: harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/serial/SQLOutputImplTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/serial/SQLOutputImplTest.java?view=diff&rev=537734&r1=537733&r2=537734
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/serial/SQLOutputImplTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/serial/SQLOutputImplTest.java
Sun May 13 23:57:22 2007
@@ -17,9 +17,48 @@
 
 package org.apache.harmony.sql.tests.javax.sql.rowset.serial;
 
+import java.sql.SQLException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Vector;
+
+import javax.sql.rowset.serial.SQLOutputImpl;
+
 import junit.framework.TestCase;
 
 public class SQLOutputImplTest extends TestCase {
+    
+    private static SQLOutputImpl impl;
+    
+    private static Vector attr;
+    
+    /**
+     * @tests {@link javax.sql.rowset.serial.SQLOutputImpl#SQLOutputImpl(Vector, Map)}
+     */
+    public void test_ConstructorLjava_util_VectorLjava_util_Map() {
+        assertNotNull(impl);
+        
+        try {
+            new SQLOutputImpl(null, new HashMap());
+            fail("should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+        
+        try {
+            new SQLOutputImpl(null, null);
+            fail("should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+        
+        try {
+            new SQLOutputImpl(new Vector(), null);
+            fail("should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+    }
 
     public void testWriteArray() {
 
@@ -41,16 +80,45 @@
 
     }
 
-    public void testWriteBoolean() {
-
-    }
-
-    public void testWriteByte() {
-
-    }
-
-    public void testWriteBytes() {
-
+    /**
+     * @tests {@link javax.sql.rowset.serial.SQLOutputImpl#writeBoolean(boolean)}
+     */
+    public void test_writeBooleanZ() throws SQLException {
+        impl.writeBoolean(true);
+        assertTrue(((Boolean)attr.get(0)).booleanValue());
+        
+        impl.writeBoolean(false);
+        assertFalse(((Boolean)attr.get(1)).booleanValue());
+        
+        impl.writeBoolean(true);
+        assertTrue(((Boolean)attr.get(2)).booleanValue());
+    }
+
+    /**
+     * @tests {@link javax.sql.rowset.serial.SQLOutputImpl#writeByte(byte)}
+     */
+    public void test_writeByteB() throws SQLException {
+        assertEquals(0, attr.size());
+        impl.writeByte((byte)1);
+        assertEquals(1, attr.size());
+        assertEquals(Byte.parseByte("1"), ((Byte)attr.get(0)).byteValue());
+        
+        impl.writeByte((byte) 256);
+        assertEquals(2, attr.size());
+        assertEquals(Byte.parseByte("0"), ((Byte)attr.get(1)).byteValue());
+    }
+
+    /**
+     * @tests {@link javax.sql.rowset.serial.SQLOutputImpl#writeBytes(byte[])}
+     */
+    public void test_writeBytes$B() throws SQLException {
+        byte[] bytes = new byte[] {4, 5, (byte)256};
+        impl.writeBytes(bytes);
+        assertEquals(1, attr.size());
+        
+        byte[] attrBytes = (byte[])attr.get(0);
+        assertEquals((byte)4, attrBytes[0]);
+        assertEquals((byte)0, attrBytes[2]);
     }
 
     public void testWriteCharacterStream() {
@@ -65,20 +133,46 @@
 
     }
 
-    public void testWriteDouble() {
-
-    }
-
-    public void testWriteFloat() {
-
-    }
-
-    public void testWriteInt() {
-
-    }
-
-    public void testWriteLong() {
-
+    /**
+     * @tests {@link javax.sql.rowset.serial.SQLOutputImpl#writeDouble(double)}
+     */
+    public void test_writeDoubleD() throws SQLException {
+        Object obj = new Object();
+        attr.add(obj);
+        impl.writeDouble(3.1415926);
+        assertEquals(2, attr.size());
+        
+        assertEquals(obj, attr.get(0));
+        assertEquals(3.1415926, ((Double)attr.get(1)).doubleValue(), 0);
+    }
+
+    /**
+     * @tests {@link javax.sql.rowset.serial.SQLOutputImpl#writeFloat(float)}
+     */
+    public void test_writeFloatF() throws SQLException {
+        impl.writeFloat(3.14f);
+        assertEquals(3.14f, ((Float) attr.get(0)).floatValue(), 0);
+
+        impl.writeFloat(Float.MAX_VALUE);
+        assertEquals(3.14f, ((Float) attr.get(0)).floatValue(), 0);
+        assertEquals(Float.MAX_VALUE, ((Float) attr.get(1)).floatValue(), 0);
+    }
+
+    /**
+     * @tests {@link javax.sql.rowset.serial.SQLOutputImpl#writeInt(int)}
+     */
+    public void test_writeIntI() throws SQLException {
+        impl.writeInt(Integer.MAX_VALUE);
+        assertEquals(Integer.MAX_VALUE, ((Integer)attr.get(0)).intValue());
+    }
+
+    /**
+     * @tests {@link javax.sql.rowset.serial.SQLOutputImpl#writeLong(long)}
+     */
+    public void test_writeLongJ() throws SQLException {
+        impl.writeInt(Integer.MIN_VALUE);
+        impl.writeLong(Long.MAX_VALUE);
+        assertEquals(Long.MAX_VALUE, ((Long)attr.get(1)).longValue());
     }
 
     public void testWriteObject() {
@@ -89,8 +183,14 @@
 
     }
 
-    public void testWriteShort() {
-
+    /**
+     * @tests {@link javax.sql.rowset.serial.SQLOutputImpl#writeShort(short)}
+     */
+    public void test_writeShortS() throws SQLException {
+        impl.writeShort((short) 12823);
+        assertEquals((short) 12823, ((Short) attr.get(0)).shortValue());
+        impl.writeShort((short) 32768);
+        assertEquals((short) -32768, ((Short) attr.get(1)).shortValue());
     }
 
     public void testWriteString() {
@@ -113,4 +213,18 @@
 
     }
 
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        attr = new Vector();
+        Map<String, Class<?>> map = new HashMap<String, Class<?>>();
+        impl = new SQLOutputImpl(attr, map);
+    }
+
+    @Override
+    protected void tearDown() throws Exception {
+        impl = null;
+        attr = null;
+        super.tearDown();
+    }
 }



Mime
View raw message