You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by km...@apache.org on 2011/03/16 17:57:36 UTC

svn commit: r1082205 - in /db/derby/code/branches/10.5/java: engine/org/apache/derby/jdbc/ testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ testing/org/apache/derbyTesting/junit/

Author: kmarsden
Date: Wed Mar 16 16:57:35 2011
New Revision: 1082205

URL: http://svn.apache.org/viewvc?rev=1082205&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 <ak...@gmail.com> and Dave Brosius <db...@apache.org> . 

merge revision 1078461 from trunk


Modified:
    db/derby/code/branches/10.5/java/engine/org/apache/derby/jdbc/EmbeddedXADataSource.java
    db/derby/code/branches/10.5/java/engine/org/apache/derby/jdbc/ReferenceableDataSource.java
    db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/J2EEDataSourceTest.java
    db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/junit/JDBCDataSource.java

Modified: db/derby/code/branches/10.5/java/engine/org/apache/derby/jdbc/EmbeddedXADataSource.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/engine/org/apache/derby/jdbc/EmbeddedXADataSource.java?rev=1082205&r1=1082204&r2=1082205&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/engine/org/apache/derby/jdbc/EmbeddedXADataSource.java (original)
+++ db/derby/code/branches/10.5/java/engine/org/apache/derby/jdbc/EmbeddedXADataSource.java Wed Mar 16 16:57:35 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.5/java/engine/org/apache/derby/jdbc/ReferenceableDataSource.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/engine/org/apache/derby/jdbc/ReferenceableDataSource.java?rev=1082205&r1=1082204&r2=1082205&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/engine/org/apache/derby/jdbc/ReferenceableDataSource.java (original)
+++ db/derby/code/branches/10.5/java/engine/org/apache/derby/jdbc/ReferenceableDataSource.java Wed Mar 16 16:57:35 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.5/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/J2EEDataSourceTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/J2EEDataSourceTest.java?rev=1082205&r1=1082204&r2=1082205&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/J2EEDataSourceTest.java (original)
+++ db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/J2EEDataSourceTest.java Wed Mar 16 16:57:35 2011
@@ -788,6 +788,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.5/java/testing/org/apache/derbyTesting/junit/JDBCDataSource.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/junit/JDBCDataSource.java?rev=1082205&r1=1082204&r2=1082205&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/junit/JDBCDataSource.java (original)
+++ db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/junit/JDBCDataSource.java Wed Mar 16 16:57:35 2011
@@ -131,7 +131,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.
@@ -227,7 +227,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)