db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kmars...@apache.org
Subject svn commit: r1082020 - in /db/derby/code/branches/10.7: ./ java/engine/org/apache/derby/jdbc/ java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ java/testing/org/apache/derbyTesting/junit/
Date Wed, 16 Mar 2011 01:01:41 GMT
Author: kmarsden
Date: Wed Mar 16 01:01:40 2011
New Revision: 1082020

URL: http://svn.apache.org/viewvc?rev=1082020&view=rev
Log:
DERBY-4907 EmbeddedXADataSource with ;create=true attribute set in setDatabaseName fails with
java.sql.SQLException: Database not available

Patch contributed by Siddharth Srivastava <akssps011@gmail.com> and Dave Brosius <dbrosius@apache.org>
. 

merged revision 1078461 from trunk


Modified:
    db/derby/code/branches/10.7/   (props changed)
    db/derby/code/branches/10.7/java/engine/org/apache/derby/jdbc/EmbeddedXADataSource.java
    db/derby/code/branches/10.7/java/engine/org/apache/derby/jdbc/ReferenceableDataSource.java
    db/derby/code/branches/10.7/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/J2EEDataSourceTest.java
    db/derby/code/branches/10.7/java/testing/org/apache/derbyTesting/junit/JDBCDataSource.java

Propchange: db/derby/code/branches/10.7/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Mar 16 01:01:40 2011
@@ -1 +1 @@
-/db/derby/code/trunk:1035603,1036769,1038514,1038813,1039084,1039268,1040658,1041338,1043227,1043389,1044096,1051026,1053724,1055169,1059888,1060480,1062096,1063809,1065061,1066290,1067250,1067357,1071463,1076387,1078693
+/db/derby/code/trunk:1035603,1036769,1038514,1038813,1039084,1039268,1040658,1041338,1043227,1043389,1044096,1051026,1053724,1055169,1059888,1060480,1062096,1063809,1065061,1066290,1067250,1067357,1071463,1076387,1078461,1078693

Modified: db/derby/code/branches/10.7/java/engine/org/apache/derby/jdbc/EmbeddedXADataSource.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.7/java/engine/org/apache/derby/jdbc/EmbeddedXADataSource.java?rev=1082020&r1=1082019&r2=1082020&view=diff
==============================================================================
--- db/derby/code/branches/10.7/java/engine/org/apache/derby/jdbc/EmbeddedXADataSource.java
(original)
+++ db/derby/code/branches/10.7/java/engine/org/apache/derby/jdbc/EmbeddedXADataSource.java
Wed Mar 16 01:01:40 2011
@@ -137,8 +137,11 @@ public class EmbeddedXADataSource extend
 			{
 				// If it is inactive, it is useless.
 				ra = null;
-
-				String dbName = getDatabaseName();
+				
+				// DERBY-4907 make sure the database name sent to find service
+				// does not include attributes.
+				String dbName = getShortDatabaseName();
+				
 				if (dbName != null) {
 
 					// see if database already booted, if it is, then don't make a

Modified: db/derby/code/branches/10.7/java/engine/org/apache/derby/jdbc/ReferenceableDataSource.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.7/java/engine/org/apache/derby/jdbc/ReferenceableDataSource.java?rev=1082020&r1=1082019&r2=1082020&view=diff
==============================================================================
--- db/derby/code/branches/10.7/java/engine/org/apache/derby/jdbc/ReferenceableDataSource.java
(original)
+++ db/derby/code/branches/10.7/java/engine/org/apache/derby/jdbc/ReferenceableDataSource.java
Wed Mar 16 01:01:40 2011
@@ -79,6 +79,9 @@ public class ReferenceableDataSource imp
 	private String description;
 	private String dataSourceName;
 	private String databaseName;
+	/** shortDatabaseName has attributes of databaseName stripped */
+	private String shortDatabaseName;	
+
 	private String password;
 	private String user;
 	private int loginTimeout;
@@ -109,11 +112,25 @@ public class ReferenceableDataSource imp
 	*/
 	public final synchronized void setDatabaseName(String databaseName) {
 		this.databaseName = databaseName;
+		if( databaseName!= null && (databaseName.indexOf(";") >= 0)){
+			String[] dbShort = databaseName.split(";");
+			this.shortDatabaseName = dbShort[0];
+		}
+		else {
+			this.shortDatabaseName = databaseName;
+		}
 		update();
 	}
 	public String getDatabaseName() {
 		return databaseName;
 	}
+	
+	/**
+	 * @return databaseName with attributes stripped.
+	 */
+	protected String getShortDatabaseName() {
+		return shortDatabaseName;
+	}
 
 	/** 
 		Set the data source name.  The property is not mandatory.  It is used

Modified: db/derby/code/branches/10.7/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/J2EEDataSourceTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.7/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/J2EEDataSourceTest.java?rev=1082020&r1=1082019&r2=1082020&view=diff
==============================================================================
--- db/derby/code/branches/10.7/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/J2EEDataSourceTest.java
(original)
+++ db/derby/code/branches/10.7/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/J2EEDataSourceTest.java
Wed Mar 16 01:01:40 2011
@@ -832,6 +832,67 @@ public class J2EEDataSourceTest extends 
     }
 
     /**
+     * Test that a connection to XADataSource can be established
+     * successfully while creating a database using setDatabaseName()
+     * with create=true
+     *  
+     * @throws SQLException
+     * @throws XAException
+     */
+    public void testCreateInDatabaseName_XA() throws SQLException, XAException
+    {
+    	//test with XADataSource
+    	XADataSource xads = J2EEDataSource.getXADataSource();
+    	String dbName = TestConfiguration.getCurrent().getDefaultDatabaseName();    	
+    	J2EEDataSource.setBeanProperty(xads,"databaseName",dbName +";create=true");       
+    	XAConnection xa = xads.getXAConnection();
+    	Connection c = xa.getConnection();  
+    	c.setAutoCommit(false); 
+    	c.close();
+    }
+    
+    /**
+     * Test that a connection to PoolDataSource can be established
+     * successfully while creating a database using setDatabaseName()
+     * with create=true
+     * 
+     * @throws SQLException
+     */
+    
+    public void testCreateInDatabaseName_Pooled() throws SQLException
+    {
+    	//test with PooledConnection
+    	ConnectionPoolDataSource cpds = J2EEDataSource.getConnectionPoolDataSource();
+    	PooledConnection pc = cpds.getPooledConnection();
+    	String dbName = TestConfiguration.getCurrent().getDefaultDatabaseName();
+    	J2EEDataSource.setBeanProperty(cpds, "databaseName",dbName +";create=true");
+    	Connection c;
+    	c = pc.getConnection();
+    	c.setAutoCommit(false);
+    	c.close();
+    	pc.close();
+    }
+    
+    /**
+     * Test that a connection to JDBCDataSource can be established
+     * successfully while creating a database using setDatabaseName()
+     * with create=true
+     * 
+     * @throws SQLException
+     */
+    
+    public void testCreateInDatabaseName_DS() throws SQLException
+    {
+    	DataSource ds = JDBCDataSource.getDataSource();
+    	String dbName = TestConfiguration.getCurrent().getDefaultDatabaseName();
+    	JDBCDataSource.setBeanProperty(ds, "databaseName", dbName +";create=true");
+        Connection c = ds.getConnection();
+        c.setAutoCommit(false);
+        c.close();
+    }
+        
+    
+    /**
      * Test that a PooledConnection can be reused and closed
      * (separately) during the close event raised by the
      * closing of its logical connection.

Modified: db/derby/code/branches/10.7/java/testing/org/apache/derbyTesting/junit/JDBCDataSource.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.7/java/testing/org/apache/derbyTesting/junit/JDBCDataSource.java?rev=1082020&r1=1082019&r2=1082020&view=diff
==============================================================================
--- db/derby/code/branches/10.7/java/testing/org/apache/derbyTesting/junit/JDBCDataSource.java
(original)
+++ db/derby/code/branches/10.7/java/testing/org/apache/derbyTesting/junit/JDBCDataSource.java
Wed Mar 16 01:01:40 2011
@@ -135,7 +135,7 @@ public class JDBCDataSource {
     }
     
     /**
-     * Return a DataSource object of the passsed in type
+     * Return a DataSource object of the passed in type
      * configured with the passed in Java bean properties.
      * This will actually work with any object that has Java bean
      * setter methods.
@@ -231,7 +231,7 @@ public class JDBCDataSource {
     
     /**
      * Clear a String Java bean property by setting it to null.
-     * @param ds ds DataSource to have property cleared
+     * @param ds DataSource to have property cleared
      * @param property name of property.
      */
     public static void clearStringBeanProperty(Object ds, String property)



Mime
View raw message