db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ti...@apache.org
Subject svn commit: r1078461 - in /db/derby/code/trunk/java: engine/org/apache/derby/jdbc/ testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ testing/org/apache/derbyTesting/junit/
Date Sun, 06 Mar 2011 12:24:42 GMT
Author: tiago
Date: Sun Mar  6 12:24:42 2011
New Revision: 1078461

URL: http://svn.apache.org/viewvc?rev=1078461&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>
.


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

Modified: db/derby/code/trunk/java/engine/org/apache/derby/jdbc/EmbeddedXADataSource.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/jdbc/EmbeddedXADataSource.java?rev=1078461&r1=1078460&r2=1078461&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/jdbc/EmbeddedXADataSource.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/jdbc/EmbeddedXADataSource.java Sun Mar
 6 12:24:42 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/trunk/java/engine/org/apache/derby/jdbc/ReferenceableDataSource.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/jdbc/ReferenceableDataSource.java?rev=1078461&r1=1078460&r2=1078461&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/jdbc/ReferenceableDataSource.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/jdbc/ReferenceableDataSource.java Sun
Mar  6 12:24:42 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/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/J2EEDataSourceTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/J2EEDataSourceTest.java?rev=1078461&r1=1078460&r2=1078461&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/J2EEDataSourceTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/J2EEDataSourceTest.java
Sun Mar  6 12:24:42 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/trunk/java/testing/org/apache/derbyTesting/junit/JDBCDataSource.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBCDataSource.java?rev=1078461&r1=1078460&r2=1078461&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBCDataSource.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBCDataSource.java Sun
Mar  6 12:24:42 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