harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hinde...@apache.org
Subject svn commit: r480596 - in /harmony/enhanced/classlib/trunk/modules/sql/src: main/java/javax/sql/rowset/serial/ main/java/org/apache/harmony/sql/internal/nls/ test/java/org/apache/harmony/sql/tests/javax/sql/rowset/serial/
Date Wed, 29 Nov 2006 15:26:29 GMT
Author: hindessm
Date: Wed Nov 29 07:26:28 2006
New Revision: 480596

URL: http://svn.apache.org/viewvc?view=rev&rev=480596
Log:
Applied patch from "[#HARMONY-2323] [classlib][sql]
javax.sql.rowset.serial.SerialRef is not implemented yet in Harmony".

Added:
    harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/sql/rowset/serial/SerialRef.java
  (with props)
    harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/serial/SerialRefTest.java
  (with props)
Modified:
    harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/nls/messages.properties

Added: harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/sql/rowset/serial/SerialRef.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/sql/rowset/serial/SerialRef.java?view=auto&rev=480596
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/sql/rowset/serial/SerialRef.java
(added)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/sql/rowset/serial/SerialRef.java
Wed Nov 29 07:26:28 2006
@@ -0,0 +1,84 @@
+/*
+ *  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.serial;
+
+import java.io.Serializable;
+import java.sql.Ref;
+import java.sql.SQLException;
+import java.util.Map;
+
+import org.apache.harmony.sql.internal.nls.Messages;
+
+public class SerialRef implements Ref, Serializable, Cloneable {
+	private static final long serialVersionUID = -4727123500609662274L;
+
+	/**
+	 * required by serialized form
+	 */
+	private String baseTypeName;
+
+	/**
+	 * store <code> reference </code> as an object, required by serialized form.
+	 */
+	private Object object;
+
+	/**
+	 * required by serialized form
+	 */
+	private Ref reference;
+
+	public SerialRef(Ref ref) throws SerialException, SQLException {
+		if (ref == null) {
+			throw new SQLException(Messages.getString("sql.9")); //$NON-NLS-1$
+		}
+		reference = ref;
+		object = ref;
+		baseTypeName = ref.getBaseTypeName();
+		if (baseTypeName == null) {
+			throw new SQLException(Messages.getString("sql.10"));//$NON-NLS-1$
+		}
+	}
+
+	public String getBaseTypeName() throws SQLException {
+		return baseTypeName;
+	}
+
+	public Object getObject() throws SerialException {
+		try {
+			return reference.getObject();
+		} catch (SQLException e) {
+			throw new SerialException(Messages.getString(
+					"sql.11", e.getMessage())); //$NON-NLS-1$
+		}
+	}
+
+	public Object getObject(Map<String, Class<?>> map) throws SerialException {
+		return map.get(object);
+	}
+
+	public void setObject(Object value) throws SerialException {
+		try {
+			reference.setObject(value);
+			object = value;
+		} catch (SQLException e) {
+			throw new SerialException(Messages.getString(
+					"sql.11", e.getMessage())); //$NON-NLS-1$
+		}
+	}
+
+}

Propchange: harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/sql/rowset/serial/SerialRef.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=480596&r1=480595&r2=480596
==============================================================================
--- 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 Nov 29 07:26:28 2006
@@ -24,3 +24,6 @@
 sql.6=No suitable driver
 sql.7=Userid and/or password not supplied
 sql.8=SQLWarning chain holds value that is not a SQLWarning
+sql.9=Cannot instantiate a SerialRef object with a null Ref object
+sql.10=Cannot instantiate a SerialRef object that returns a null base type name
+sql.11=SQLException: {0}

Added: harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/serial/SerialRefTest.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/SerialRefTest.java?view=auto&rev=480596
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/serial/SerialRefTest.java
(added)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/serial/SerialRefTest.java
Wed Nov 29 07:26:28 2006
@@ -0,0 +1,174 @@
+/*
+ *  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.tests.javax.sql.rowset.serial;
+
+import java.sql.Ref;
+import java.sql.SQLException;
+import java.util.Hashtable;
+import java.util.Map;
+
+import javax.sql.rowset.serial.SerialException;
+import javax.sql.rowset.serial.SerialRef;
+
+import junit.framework.TestCase;
+
+/**
+ * @tests SerialRef
+ */
+public class SerialRefTest extends TestCase {
+
+	private SerialRef sr;
+
+	private SerialRef sr2;
+
+	private MockRef ref;
+
+	protected void setUp() throws Exception {
+		super.setUp();
+		ref = new MockRef();
+		sr = new SerialRef(ref);
+
+		MockAbnormalRef maf = new MockAbnormalRef();
+		sr2 = new SerialRef(maf);
+	}
+
+	/**
+	 * @tests javax.sql.rowset.serial.SerialRef#SerialRef(Ref ref)
+	 */
+	public void testConstructorRef() throws SerialException, SQLException {
+		try {
+			new SerialRef(null);
+			fail("should throw SQLException");
+		} catch (SQLException e) {
+			// expected
+		}
+
+		try {
+			ref.setBaseTypeName(null);
+			new SerialRef(ref);
+			fail("should throw SQLException");
+		} catch (SQLException e) {
+			// expected
+		}
+	}
+
+	/**
+	 * @tests javax.sql.rowset.serial.SerialRef#getBaseTypeName()
+	 */
+	public void testGetBaseTypeName() throws SQLException {
+		assertEquals(MockRef.BASE_TYPE_NAME, sr.getBaseTypeName());
+	}
+
+	/**
+	 * @tests javax.sql.rowset.serial.SerialRef#getObject()
+	 */
+	public void testGetObject() throws SQLException {
+		assertSame(ref.obj1, sr.getObject());
+
+		sr.setObject(null);
+		assertNull(sr.getObject());
+
+		Object obj = new Object();
+		sr.setObject(obj);
+		assertSame(obj, sr.getObject());
+
+		try {
+			sr2.getObject();
+			fail("should throw SerialException");
+		} catch (SerialException e) {
+			// expected
+		}
+
+		try {
+			sr2.setObject(obj);
+			fail("should throw SerialException");
+		} catch (SerialException e) {
+			// expected
+		}
+
+	}
+
+	/**
+	 * @tests javax.sql.rowset.serial.SerialRef#getObject(Map)
+	 */
+	public void testGetObjectLjava_util_Map() throws SQLException {
+		try {
+			assertNull(sr.getObject(null));
+			fail("should throw NullPointerException");
+		} catch (NullPointerException e) {
+			// expected
+		}
+
+		Map<String, Class<?>> map = new Hashtable<String, Class<?>>();
+		assertNull(sr.getObject(map));
+
+		map.put("MockRef", MockRef.class);
+		assertNull(sr.getObject(map));
+
+		sr.setObject("MockRef1");
+		assertNull(sr.getObject(map));
+
+		sr.setObject("MockRef");
+		assertSame(MockRef.class, sr.getObject(map));
+	}
+
+	static class MockRef implements Ref {
+		private static final String BASE_TYPE_NAME = "MockBaseTypeName";
+
+		String baseTypeName = BASE_TYPE_NAME;
+
+		Object obj1 = new Object();
+
+		Object obj2 = new Object();
+
+		public String getBaseTypeName() throws SQLException {
+			return baseTypeName;
+		}
+
+		public Object getObject() throws SQLException {
+			return obj1;
+		}
+
+		public Object getObject(Map<String, Class<?>> map) throws SQLException {
+			return obj2;
+		}
+
+		public void setObject(Object value) throws SQLException {
+			obj1 = value;
+		}
+
+		public void setBaseTypeName(String name) {
+			baseTypeName = name;
+		}
+	};
+
+	static class MockAbnormalRef extends MockRef {
+		public Object getObject() throws SQLException {
+			throw new SQLException();
+		}
+
+		public Object getObject(Map<String, Class<?>> map) throws SQLException {
+			throw new SQLException();
+		}
+
+		public void setObject(Object value) throws SQLException {
+			throw new SQLException();
+		}
+	};
+
+}

Propchange: harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/serial/SerialRefTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message