db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject svn commit: r359290 - in /db/derby/code/trunk/java: client/org/apache/derby/jdbc/ testing/org/apache/derbyTesting/functionTests/master/ testing/org/apache/derbyTesting/functionTests/suites/ testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/
Date Tue, 27 Dec 2005 21:44:41 GMT
Author: djd
Date: Tue Dec 27 13:44:37 2005
New Revision: 359290

URL: http://svn.apache.org/viewcvs?rev=359290&view=rev
Log:
DERBY-445 Ensure client data sources do not lose the value of their
connectionAttributes property during serialization. Added data source
test that stores DataSource instances using Serialization and Reference
and checks they are restored correctly.

Added:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/dataSourceReference.out
  (with props)
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/dataSourceReference.java
  (with props)
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/dataSourceReference_app.properties
  (with props)
Modified:
    db/derby/code/trunk/java/client/org/apache/derby/jdbc/ClientBaseDataSource.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/DerbyNet.exclude
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/DerbyNetClient.exclude
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/jdbc20.runall
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/copyfiles.ant

Modified: db/derby/code/trunk/java/client/org/apache/derby/jdbc/ClientBaseDataSource.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/client/org/apache/derby/jdbc/ClientBaseDataSource.java?rev=359290&r1=359289&r2=359290&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/jdbc/ClientBaseDataSource.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/jdbc/ClientBaseDataSource.java Tue Dec
27 13:44:37 2005
@@ -783,6 +783,7 @@
     }
 
     protected String connectionAttributes = null;
+    public final static String propertyKey_connectionAttributes = "connectionAttributes";
 
     /**
      * Set this property to pass in more Derby specific connection URL attributes.

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/dataSourceReference.out
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/dataSourceReference.out?rev=359290&view=auto
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/dataSourceReference.out
(added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/dataSourceReference.out
Tue Dec 27 13:44:37 2005
@@ -0,0 +1,371 @@
+Starting dataSourceReference
+DataSource class org.apache.derby.jdbc.EmbeddedDataSource
+ property list
+  attributesAsPassword
+  connectionAttributes
+  createDatabase
+  dataSourceName
+  databaseName
+  description
+  loginTimeout
+  password
+  shutdownDatabase
+  user
+ empty DataSource recreated using Reference as org.apache.derby.jdbc.EmbeddedDataSource
+ Start compare recreated
+  attributesAsPassword=false
+  loginTimeout=0
+ Completed compare recreated
+ empty DataSource recreated using serialization
+ Start compare recreated
+  attributesAsPassword=false
+  loginTimeout=0
+ Completed compare recreated
+ populated DataSource recreated using Reference as org.apache.derby.jdbc.EmbeddedDataSource
+ Start compare recreated
+  attributesAsPassword=true
+  connectionAttributes=XX_connectionAttributes_2135
+  createDatabase=create
+  dataSourceName=XX_dataSourceName_1420
+  databaseName=XX_databaseName_1206
+  description=XX_description_1188
+  loginTimeout=1280
+  password=XX_password_883
+  shutdownDatabase=shutdown
+  user=XX_user_447
+ Completed compare recreated
+ populated DataSource recreated using serialization
+ Start compare recreated
+  attributesAsPassword=true
+  connectionAttributes=XX_connectionAttributes_2135
+  createDatabase=create
+  dataSourceName=XX_dataSourceName_1420
+  databaseName=XX_databaseName_1206
+  description=XX_description_1188
+  loginTimeout=1280
+  password=XX_password_883
+  shutdownDatabase=shutdown
+  user=XX_user_447
+ Completed compare recreated
+DataSource class org.apache.derby.jdbc.EmbeddedConnectionPoolDataSource
+ property list
+  attributesAsPassword
+  connectionAttributes
+  createDatabase
+  dataSourceName
+  databaseName
+  description
+  loginTimeout
+  password
+  shutdownDatabase
+  user
+ empty DataSource recreated using Reference as org.apache.derby.jdbc.EmbeddedConnectionPoolDataSource
+ Start compare recreated
+  attributesAsPassword=false
+  loginTimeout=0
+ Completed compare recreated
+ empty DataSource recreated using serialization
+ Start compare recreated
+  attributesAsPassword=false
+  loginTimeout=0
+ Completed compare recreated
+ populated DataSource recreated using Reference as org.apache.derby.jdbc.EmbeddedConnectionPoolDataSource
+ Start compare recreated
+  attributesAsPassword=true
+  connectionAttributes=XX_connectionAttributes_2135
+  createDatabase=create
+  dataSourceName=XX_dataSourceName_1420
+  databaseName=XX_databaseName_1206
+  description=XX_description_1188
+  loginTimeout=1280
+  password=XX_password_883
+  shutdownDatabase=shutdown
+  user=XX_user_447
+ Completed compare recreated
+ populated DataSource recreated using serialization
+ Start compare recreated
+  attributesAsPassword=true
+  connectionAttributes=XX_connectionAttributes_2135
+  createDatabase=create
+  dataSourceName=XX_dataSourceName_1420
+  databaseName=XX_databaseName_1206
+  description=XX_description_1188
+  loginTimeout=1280
+  password=XX_password_883
+  shutdownDatabase=shutdown
+  user=XX_user_447
+ Completed compare recreated
+DataSource class org.apache.derby.jdbc.EmbeddedXADataSource
+ property list
+  attributesAsPassword
+  connectionAttributes
+  createDatabase
+  dataSourceName
+  databaseName
+  description
+  loginTimeout
+  password
+  shutdownDatabase
+  user
+ empty DataSource recreated using Reference as org.apache.derby.jdbc.EmbeddedXADataSource
+ Start compare recreated
+  attributesAsPassword=false
+  loginTimeout=0
+ Completed compare recreated
+ empty DataSource recreated using serialization
+ Start compare recreated
+  attributesAsPassword=false
+  loginTimeout=0
+ Completed compare recreated
+ populated DataSource recreated using Reference as org.apache.derby.jdbc.EmbeddedXADataSource
+ Start compare recreated
+  attributesAsPassword=true
+  connectionAttributes=XX_connectionAttributes_2135
+  createDatabase=create
+  dataSourceName=XX_dataSourceName_1420
+  databaseName=XX_databaseName_1206
+  description=XX_description_1188
+  loginTimeout=1280
+  password=XX_password_883
+  shutdownDatabase=shutdown
+  user=XX_user_447
+ Completed compare recreated
+ populated DataSource recreated using serialization
+ Start compare recreated
+  attributesAsPassword=true
+  connectionAttributes=XX_connectionAttributes_2135
+  createDatabase=create
+  dataSourceName=XX_dataSourceName_1420
+  databaseName=XX_databaseName_1206
+  description=XX_description_1188
+  loginTimeout=1280
+  password=XX_password_883
+  shutdownDatabase=shutdown
+  user=XX_user_447
+ Completed compare recreated
+DataSource class org.apache.derby.jdbc.ClientDataSource
+ property list
+  connectionAttributes
+  dataSourceName
+  databaseName
+  description
+  loginTimeout
+  password
+  portNumber
+  retrieveMessageText
+  securityMechanism
+  serverName
+  traceDirectory
+  traceFile
+  traceFileAppend
+  traceLevel
+  user
+ empty DataSource recreated using Reference as org.apache.derby.jdbc.ClientDataSource
+ Start compare recreated
+  loginTimeout=0
+  portNumber=1527
+  retrieveMessageText=true
+  securityMechanism=4
+  serverName=xxxFILTERED_HOSTNAMExxx
+  traceFileAppend=false
+  traceLevel=-1
+  user=APP
+ Completed compare recreated
+ empty DataSource recreated using serialization
+ Start compare recreated
+  loginTimeout=0
+  portNumber=1527
+  retrieveMessageText=true
+  securityMechanism=4
+  serverName=xxxFILTERED_HOSTNAMExxx
+  traceFileAppend=false
+  traceLevel=-1
+  user=APP
+ Completed compare recreated
+ populated DataSource recreated using Reference as org.apache.derby.jdbc.ClientDataSource
+ Start compare recreated
+  connectionAttributes=XX_connectionAttributes_2135
+  dataSourceName=XX_dataSourceName_1420
+  databaseName=XX_databaseName_1206
+  description=XX_description_1188
+  loginTimeout=1280
+  password=XX_password_883
+  portNumber=1070
+  retrieveMessageText=false
+  securityMechanism=1805
+  serverName=XX_serverName_1048
+  traceDirectory=XX_traceDirectory_1476
+  traceFile=XX_traceFile_911
+  traceFileAppend=true
+  traceLevel=1031
+  user=XX_user_447
+ Completed compare recreated
+ populated DataSource recreated using serialization
+ Start compare recreated
+  connectionAttributes=XX_connectionAttributes_2135
+  dataSourceName=XX_dataSourceName_1420
+  databaseName=XX_databaseName_1206
+  description=XX_description_1188
+  loginTimeout=1280
+  password=XX_password_883
+  portNumber=1070
+  retrieveMessageText=false
+  securityMechanism=1805
+  serverName=XX_serverName_1048
+  traceDirectory=XX_traceDirectory_1476
+  traceFile=XX_traceFile_911
+  traceFileAppend=true
+  traceLevel=1031
+  user=XX_user_447
+ Completed compare recreated
+DataSource class org.apache.derby.jdbc.ClientConnectionPoolDataSource
+ property list
+  connectionAttributes
+  dataSourceName
+  databaseName
+  description
+  loginTimeout
+  password
+  portNumber
+  retrieveMessageText
+  securityMechanism
+  serverName
+  traceDirectory
+  traceFile
+  traceFileAppend
+  traceLevel
+  user
+ empty DataSource recreated using Reference as org.apache.derby.jdbc.ClientConnectionPoolDataSource
+ Start compare recreated
+  loginTimeout=0
+  portNumber=1527
+  retrieveMessageText=true
+  securityMechanism=4
+  serverName=xxxFILTERED_HOSTNAMExxx
+  traceFileAppend=false
+  traceLevel=-1
+  user=APP
+ Completed compare recreated
+ empty DataSource recreated using serialization
+ Start compare recreated
+  loginTimeout=0
+  portNumber=1527
+  retrieveMessageText=true
+  securityMechanism=4
+  serverName=xxxFILTERED_HOSTNAMExxx
+  traceFileAppend=false
+  traceLevel=-1
+  user=APP
+ Completed compare recreated
+ populated DataSource recreated using Reference as org.apache.derby.jdbc.ClientConnectionPoolDataSource
+ Start compare recreated
+  connectionAttributes=XX_connectionAttributes_2135
+  dataSourceName=XX_dataSourceName_1420
+  databaseName=XX_databaseName_1206
+  description=XX_description_1188
+  loginTimeout=1280
+  password=XX_password_883
+  portNumber=1070
+  retrieveMessageText=false
+  securityMechanism=1805
+  serverName=XX_serverName_1048
+  traceDirectory=XX_traceDirectory_1476
+  traceFile=XX_traceFile_911
+  traceFileAppend=true
+  traceLevel=1031
+  user=XX_user_447
+ Completed compare recreated
+ populated DataSource recreated using serialization
+ Start compare recreated
+  connectionAttributes=XX_connectionAttributes_2135
+  dataSourceName=XX_dataSourceName_1420
+  databaseName=XX_databaseName_1206
+  description=XX_description_1188
+  loginTimeout=1280
+  password=XX_password_883
+  portNumber=1070
+  retrieveMessageText=false
+  securityMechanism=1805
+  serverName=XX_serverName_1048
+  traceDirectory=XX_traceDirectory_1476
+  traceFile=XX_traceFile_911
+  traceFileAppend=true
+  traceLevel=1031
+  user=XX_user_447
+ Completed compare recreated
+DataSource class org.apache.derby.jdbc.ClientXADataSource
+ property list
+  connectionAttributes
+  dataSourceName
+  databaseName
+  description
+  loginTimeout
+  password
+  portNumber
+  retrieveMessageText
+  securityMechanism
+  serverName
+  traceDirectory
+  traceFile
+  traceFileAppend
+  traceLevel
+  user
+ empty DataSource recreated using Reference as org.apache.derby.jdbc.ClientXADataSource
+ Start compare recreated
+  loginTimeout=0
+  portNumber=1527
+  retrieveMessageText=true
+  securityMechanism=4
+  serverName=xxxFILTERED_HOSTNAMExxx
+  traceFileAppend=false
+  traceLevel=-1
+  user=APP
+ Completed compare recreated
+ empty DataSource recreated using serialization
+ Start compare recreated
+  loginTimeout=0
+  portNumber=1527
+  retrieveMessageText=true
+  securityMechanism=4
+  serverName=xxxFILTERED_HOSTNAMExxx
+  traceFileAppend=false
+  traceLevel=-1
+  user=APP
+ Completed compare recreated
+ populated DataSource recreated using Reference as org.apache.derby.jdbc.ClientXADataSource
+ Start compare recreated
+  connectionAttributes=XX_connectionAttributes_2135
+  dataSourceName=XX_dataSourceName_1420
+  databaseName=XX_databaseName_1206
+  description=XX_description_1188
+  loginTimeout=1280
+  password=XX_password_883
+  portNumber=1070
+  retrieveMessageText=false
+  securityMechanism=1805
+  serverName=XX_serverName_1048
+  traceDirectory=XX_traceDirectory_1476
+  traceFile=XX_traceFile_911
+  traceFileAppend=true
+  traceLevel=1031
+  user=XX_user_447
+ Completed compare recreated
+ populated DataSource recreated using serialization
+ Start compare recreated
+  connectionAttributes=XX_connectionAttributes_2135
+  dataSourceName=XX_dataSourceName_1420
+  databaseName=XX_databaseName_1206
+  description=XX_description_1188
+  loginTimeout=1280
+  password=XX_password_883
+  portNumber=1070
+  retrieveMessageText=false
+  securityMechanism=1805
+  serverName=XX_serverName_1048
+  traceDirectory=XX_traceDirectory_1476
+  traceFile=XX_traceFile_911
+  traceFileAppend=true
+  traceLevel=1031
+  user=XX_user_447
+ Completed compare recreated
+Completed dataSourceReference

Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/dataSourceReference.out
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/DerbyNet.exclude
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/DerbyNet.exclude?rev=359290&r1=359289&r2=359290&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/DerbyNet.exclude
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/DerbyNet.exclude
Tue Dec 27 13:44:37 2005
@@ -11,6 +11,8 @@
 # excluding jdbcapi/checkDataSource30.java - Client behaves differently. Need to look into
this
 # excluding jdbcapi/statementJdbc30.java - Client behaves differently. Need to look into
this
 # excluding jdbcapi/holdCursorJava.java - JCC behaves differently with hold cursors.
+# excluding jdbcapi/dataSourceReference.java - client side only tests, tests all data sources
+#           regardless of framework
 jdbcapi/resultsetStream.java
 lang/errorStream.java
 lang/scrollCursors2.java
@@ -25,3 +27,4 @@
 jdbcapi/checkDataSource30.java
 jdbcapi/statementJdbc30.java
 lang/holdCursorJava.java
+jdbcapi/dataSourceReference.java

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/DerbyNetClient.exclude
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/DerbyNetClient.exclude?rev=359290&r1=359289&r2=359290&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/DerbyNetClient.exclude
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/DerbyNetClient.exclude
Tue Dec 27 13:44:37 2005
@@ -6,6 +6,8 @@
 # excluding jdbcapi/resultsetJdbc30.java because the features tested are not implemented
by Derby Client
 # excluding jdbcapi/checkDataSource30.java - Client behaves differently. Need to look into
this
 # excluding jdbcapi/statementJdbc30.java - Client behaves differently. Need to look into
this
+# excluding jdbcapi/dataSourceReference.java - client side only tests, tests all data sources
+#           regardless of framework
 lang/errorStream.java
 # lang/scrollCursors2.java
 jdbcapi/batchUpdate.java
@@ -14,3 +16,4 @@
 jdbcapi/resultsetJdbc30.java
 jdbcapi/checkDataSource30.java
 jdbcapi/statementJdbc30.java
+jdbcapi/dataSourceReference.java
\ No newline at end of file

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/jdbc20.runall
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/jdbc20.runall?rev=359290&r1=359289&r2=359290&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/jdbc20.runall
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/jdbc20.runall
Tue Dec 27 13:44:37 2005
@@ -7,3 +7,5 @@
 jdbcapi/connectionJdbc20.java
 jdbcapi/StmtCloseFunTest.java
 jdbcapi/resultsetJdbc20.java
+jdbcapi/dataSourceReference.java
+

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/copyfiles.ant
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/copyfiles.ant?rev=359290&r1=359289&r2=359290&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/copyfiles.ant
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/copyfiles.ant
Tue Dec 27 13:44:37 2005
@@ -8,6 +8,7 @@
 bestrowidentifier_app.properties
 checkDriver_app.properties
 checkDriver_derby.properties
+dataSourceReference_app.properties
 dbMetaDataJdbc30_app.properties
 dbMetaDataJdbc30_sed.properties
 default_app.properties

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/dataSourceReference.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/dataSourceReference.java?rev=359290&view=auto
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/dataSourceReference.java
(added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/dataSourceReference.java
Tue Dec 27 13:44:37 2005
@@ -0,0 +1,286 @@
+/*
+
+   Derby - Class org.apache.derbyTesting.functionTests.tests.jdbcapi.dataSourcePermissions
+
+   Copyright 2003, 2004 The Apache Software Foundation or its licensors, as applicable.
+
+   Licensed 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.derbyTesting.functionTests.tests.jdbcapi;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Arrays;
+
+import javax.naming.*;
+import javax.naming.spi.ObjectFactory;
+
+/**
+ * Test obtaining a javax.naming.Reference from a Derby data source
+ * and recreating a Derby data source from it. Tests that the recreated
+ * value has the same value for all the properties the data source supports.
+ * The list of properties is obtained dynamically from the getXXX methods
+ * that return int, String, boolean, short, long. Should Derby data sources
+ * support any other bean property types then this test should be modified
+ * to pick them up and handle them. Hopefully the test should fail when such
+ * a property is added.
+ * 
+ * At no point does this test attempt to connect using these data sources.
+ */
+public class dataSourceReference
+{
+	public static void main(String[] args) throws Exception {
+
+		System.out.println("Starting dataSourceReference");
+		
+		testDSReference("org.apache.derby.jdbc.EmbeddedDataSource");
+		testDSReference("org.apache.derby.jdbc.EmbeddedConnectionPoolDataSource");
+		testDSReference("org.apache.derby.jdbc.EmbeddedXADataSource");
+		
+		
+		testDSReference("org.apache.derby.jdbc.ClientDataSource");
+		testDSReference("org.apache.derby.jdbc.ClientConnectionPoolDataSource");
+		testDSReference("org.apache.derby.jdbc.ClientXADataSource");
+		
+		System.out.println("Completed dataSourceReference");
+
+	}
+	
+	/**
+	 * Test a data source
+	 * <OL>
+	 * <LI> Create an empty one from the class name
+	 * <LI> Discover the property list
+	 * <LI> Create a reference and recreate a data source
+	 * <LI> Compare the two
+	 * <LI> Serialize athe data source and recreate
+	 * <LI> Compare the two
+	 * <LI> Set every property for the data source
+	 * <LI> Create a reference and recreate a data source
+	 * <LI>  Compare the two
+	 * </OL>
+	 * @param dsName
+	 * @throws Exception
+	 */
+	private static void testDSReference(String dsName) throws Exception
+	{
+		Object ds = Class.forName(dsName).newInstance();
+		
+		System.out.println("DataSource class " + dsName);
+		String[] properties = getPropertyBeanList(ds);
+		System.out.println(" property list");
+		for (int i = 0; i < properties.length; i++)
+		{
+			System.out.println("  " + properties[i]);
+		}
+		
+		Referenceable refDS = (Referenceable) ds;
+		
+		Reference dsAsReference = refDS.getReference();
+		
+		String factoryClassName = dsAsReference.getFactoryClassName();
+		
+		ObjectFactory factory = (ObjectFactory) Class.forName(factoryClassName).newInstance();

+		
+		Object recreatedDS = factory.getObjectInstance(dsAsReference, null, null, null);
+		
+		System.out.println(" empty DataSource recreated using Reference as " + recreatedDS.getClass().getName());
+		if (recreatedDS == ds)
+			System.out.println("FAIL recreated as same instance!");
+		
+		compareDS(properties, ds, recreatedDS);
+		
+		// now serialize and recreate
+		ByteArrayOutputStream baos = new ByteArrayOutputStream();
+		ObjectOutputStream oos = new ObjectOutputStream(baos);	
+		oos.writeObject(ds);
+		oos.flush();
+		oos.close();
+		ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
+		ObjectInputStream ois = new ObjectInputStream(bais);
+		recreatedDS = ois.readObject();
+		System.out.println(" empty DataSource recreated using serialization");
+		compareDS(properties, ds, recreatedDS);
+		
+		// now populate the data source
+		for (int i = 0; i < properties.length; i++)
+		{
+			String property = properties[i];
+			Method getMethod = getGet(property, ds);
+			
+			Method setMethod = getSet(getMethod, ds);
+			
+			Class pt = getMethod.getReturnType();
+			
+			// generate a somewhat unique value for a property
+			int val = 0;
+			for (int j = 0; j < property.length(); j++)
+				val += property.charAt(j);
+			
+			if (pt.equals(Integer.TYPE))
+			{
+				setMethod.invoke(ds, new Object[] {new Integer(val)});
+				continue;
+			}
+			if (pt.equals(String.class))
+			{
+				String value;
+				if (property.equals("createDatabase"))
+					value = "create";
+				else if (property.equals("shutdownDatabase"))
+					value = "shutdown";
+				else
+					value = "XX_" + property + "_" + val;
+					
+				setMethod.invoke(ds, new Object[] {value});
+				continue;
+			}
+			if (pt.equals(Boolean.TYPE))
+			{
+				// set the opposite value
+				Object gbv = getMethod.invoke(ds, null);
+				Boolean sbv = Boolean.FALSE.equals(gbv) ? Boolean.TRUE : Boolean.FALSE;
+				setMethod.invoke(ds, new Object[] {sbv});
+				continue;
+			}			
+			if (pt.equals(Short.TYPE))
+			{
+				setMethod.invoke(ds, new Object[] {new Short((short)val)});
+				continue;
+			}
+			if (pt.equals(Long.TYPE))
+			{
+				setMethod.invoke(ds, new Object[] {new Long(val)});
+				continue;
+			}
+			System.out.println("FAIL " + property + " not settable - uhpdate test!!");
+		}
+		
+		dsAsReference = refDS.getReference();
+		recreatedDS = factory.getObjectInstance(dsAsReference, null, null, null);
+		System.out.println(" populated DataSource recreated using Reference as " + recreatedDS.getClass().getName());
+		if (recreatedDS == ds)
+			System.out.println("FAIL recreated as same instance!");
+		
+		compareDS(properties, ds, recreatedDS);		
+
+		// now serialize and recreate
+		 baos = new ByteArrayOutputStream();
+		oos = new ObjectOutputStream(baos);	
+		oos.writeObject(ds);
+		oos.flush();
+		oos.close();
+		bais = new ByteArrayInputStream(baos.toByteArray());
+		ois = new ObjectInputStream(bais);
+		recreatedDS = ois.readObject();
+		System.out.println(" populated DataSource recreated using serialization");
+		compareDS(properties, ds, recreatedDS);
+	}
+	
+	private static String[] getPropertyBeanList(Object ds) throws Exception
+	{
+		Method[] allMethods = ds.getClass().getMethods();
+		
+		ArrayList properties = new ArrayList();
+		for (int i = 0; i < allMethods.length; i++)
+		{
+			Method m = allMethods[i];
+			String methodName = m.getName();
+			// Need at least getXX
+			if (methodName.length() < 5)
+				continue;
+			if (!methodName.startsWith("get"))
+				continue;
+			if (m.getParameterTypes().length != 0)
+				continue;
+
+			Class rt = m.getReturnType();
+			
+			if (rt.equals(Integer.TYPE) || rt.equals(String.class) || rt.equals(Boolean.TYPE)
+					|| rt.equals(Short.TYPE) || rt.equals(Long.TYPE))
+			{
+				// valid Java Bean property
+				 String beanName = methodName.substring(3,4).toLowerCase() + methodName.substring(4);
+
+				properties.add(beanName);
+				continue;
+			}
+			
+			if (rt.isPrimitive())
+				System.out.println("FAIL " + methodName + " not supported - update test!!");
+
+		}
+		
+		String[] propertyList = (String[]) properties.toArray(new String[0]);
+		
+		Arrays.sort(propertyList);
+		
+		return propertyList;
+	}
+	
+	private static Method getGet(String property, Object ds) throws Exception
+	{
+		String methodName =
+			"get" + property.substring(0,1).toUpperCase()
+			+ property.substring(1);
+		Method m = ds.getClass().getMethod(methodName, null);
+		return m;
+	}
+	private static Method getSet(Method getMethod, Object ds) throws Exception
+	{
+		String methodName = "s" + getMethod.getName().substring(1);
+		Method m = ds.getClass().getMethod(methodName, new Class[] {getMethod.getReturnType()});
+		return m;
+	}	
+	private static void compareDS(String[] properties, Object ds, Object rds) throws Exception
+	{
+		System.out.println(" Start compare recreated");
+		for (int i = 0; i < properties.length; i++)
+		{
+			Method getMethod = getGet(properties[i], ds);
+			
+			Object dsValue = getMethod.invoke(ds, null);
+			Object rdsValue = getMethod.invoke(rds, null);
+			
+			if (dsValue == null)
+			{
+				if (rdsValue != null)
+				{
+				    System.out.println("  FAIL: " + properties[i] + " originally null, recreated as "
+ rdsValue);
+				    continue;
+				}
+			}
+			else
+			{
+				if (!dsValue.equals(rdsValue)) {
+					System.out.println("  FAIL: " + properties[i] + " originally " + dsValue + ", recreated
as " + rdsValue);
+					continue;
+				}
+				
+				
+			}
+			if (dsValue != null)
+				System.out.println("  " + properties[i] + "=" + dsValue);
+		
+		}
+		System.out.println(" Completed compare recreated");
+
+	}
+
+}

Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/dataSourceReference.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/dataSourceReference_app.properties
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/dataSourceReference_app.properties?rev=359290&view=auto
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/dataSourceReference_app.properties
(added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/dataSourceReference_app.properties
Tue Dec 27 13:44:37 2005
@@ -0,0 +1,8 @@
+# not tested yet
+runwithj9=false
+
+# Referencable interface not available in CDC/Foundation
+runwithfoundation=false
+
+# DERBY-446
+noSecurityManager=true

Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/dataSourceReference_app.properties
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message