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 kr...@apache.org on 2010/06/28 15:29:52 UTC
svn commit: r958572 - in /db/derby/code/branches/10.5: ./
java/client/org/apache/derby/jdbc/
java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/
Author: kristwaa
Date: Mon Jun 28 13:29:52 2010
New Revision: 958572
URL: http://svn.apache.org/viewvc?rev=958572&view=rev
Log:
DERBY-4070: Embedded and client data sources throw different exception when a connection attribute is badly formatted
Merged fix from trunk (revision 757811).
Modified:
db/derby/code/branches/10.5/ (props changed)
db/derby/code/branches/10.5/java/client/org/apache/derby/jdbc/ClientBaseDataSource.java
db/derby/code/branches/10.5/java/client/org/apache/derby/jdbc/ClientConnectionPoolDataSource.java
db/derby/code/branches/10.5/java/client/org/apache/derby/jdbc/ClientDataSource.java
db/derby/code/branches/10.5/java/client/org/apache/derby/jdbc/ClientXADataSource.java
db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DataSourceTest.java
Propchange: db/derby/code/branches/10.5/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Mon Jun 28 13:29:52 2010
@@ -1,2 +1,2 @@
/db/derby/code/branches/10.6:957000
-/db/derby/code/trunk:769596,769602,769606,769962,772090,772337,772449,772534,774281,777105,779681,782991,785131,785139,785163,785570,785662,788369,788670,788674,788968,789264,790218,792434,793089,793588,794106,794303,794955,795166,796020,796027,796316,796372,797147,798347,798742,800523,803548,803948,805696,808494,808850,809643,810860,812669,816531,816536,819006,822289,823659,824694,829022,832379,833430,835286,881074,881444,882732,884163,887246,892912,897161,898635,901165,901648,901760,903108,908418,911315,915733,916075,916897,918359,921028,927430,928065,942286,942476,942480,942587,946794,948045,948069,951346,954748,955001,955634,956075,956445,956659
+/db/derby/code/trunk:757811,769596,769602,769606,769962,772090,772337,772449,772534,774281,777105,779681,782991,785131,785139,785163,785570,785662,788369,788670,788674,788968,789264,790218,792434,793089,793588,794106,794303,794955,795166,796020,796027,796316,796372,797147,798347,798742,800523,803548,803948,805696,808494,808850,809643,810860,812669,816531,816536,819006,822289,823659,824694,829022,832379,833430,835286,881074,881444,882732,884163,887246,892912,897161,898635,901165,901648,901760,903108,908418,911315,915733,916075,916897,918359,921028,927430,928065,942286,942476,942480,942587,946794,948045,948069,951346,954748,955001,955634,956075,956445,956659
Modified: db/derby/code/branches/10.5/java/client/org/apache/derby/jdbc/ClientBaseDataSource.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/client/org/apache/derby/jdbc/ClientBaseDataSource.java?rev=958572&r1=958571&r2=958572&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/client/org/apache/derby/jdbc/ClientBaseDataSource.java (original)
+++ db/derby/code/branches/10.5/java/client/org/apache/derby/jdbc/ClientBaseDataSource.java Mon Jun 28 13:29:52 2010
@@ -33,6 +33,7 @@ import java.lang.reflect.InvocationTarge
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
+import java.sql.SQLException;
import javax.naming.Referenceable;
import javax.naming.Reference;
import javax.naming.NamingException;
@@ -46,6 +47,7 @@ import org.apache.derby.client.am.Client
import org.apache.derby.client.net.NetConfiguration;
import org.apache.derby.client.net.NetLogWriter;
import org.apache.derby.client.ClientDataSourceFactory;
+import org.apache.derby.shared.common.error.ExceptionUtil;
import org.apache.derby.shared.common.reference.Attribute;
import org.apache.derby.shared.common.reference.SQLState;
@@ -1155,4 +1157,54 @@ public abstract class ClientBaseDataSour
sslMode = getClientSSLMode(prop);
}
}
+
+ /**
+ * Handles common error situations that can happen when trying to
+ * obtain a physical connection to the server, and which require special
+ * handling.
+ * <p>
+ * If this method returns normally, the exception wasn't handled and should
+ * be handled elsewhere or be re-thrown.
+ *
+ * @param logWriter log writer, may be {@code null}
+ * @param sqle exception to handle
+ * @throws SQLException handled exception (if any)
+ */
+ protected final void handleConnectionException(LogWriter logWriter,
+ SqlException sqle)
+ throws SQLException {
+ // See DERBY-4070
+ if (sqle.getSQLState().equals(
+ ExceptionUtil.getSQLStateFromIdentifier(
+ SQLState.INVALID_ATTRIBUTE_SYNTAX))) {
+ // Wrap this in SQLState.MALFORMED_URL exception to be
+ // consistent with the embedded driver.
+ throw new SqlException(logWriter,
+ new ClientMessageId(SQLState.MALFORMED_URL),
+ constructUrl(), sqle).getSQLException();
+
+ }
+ }
+
+ /**
+ * Constructs the JDBC connection URL from the state of the data source.
+ *
+ * @return The JDBC connection URL.
+ */
+ private String constructUrl() {
+ StringBuffer sb = new StringBuffer(64);
+ // To support subSubProtocols, the protocol addition below must be
+ // changed.
+ sb.append(Attribute.DNC_PROTOCOL);
+ sb.append(serverName);
+ sb.append(':');
+ sb.append(portNumber);
+ sb.append('/');
+ sb.append(databaseName);
+ if (connectionAttributes != null) {
+ sb.append(';');
+ sb.append(connectionAttributes);
+ }
+ return sb.toString();
+ }
}
Modified: db/derby/code/branches/10.5/java/client/org/apache/derby/jdbc/ClientConnectionPoolDataSource.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/client/org/apache/derby/jdbc/ClientConnectionPoolDataSource.java?rev=958572&r1=958571&r2=958572&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/client/org/apache/derby/jdbc/ClientConnectionPoolDataSource.java (original)
+++ db/derby/code/branches/10.5/java/client/org/apache/derby/jdbc/ClientConnectionPoolDataSource.java Mon Jun 28 13:29:52 2010
@@ -71,9 +71,10 @@ public class ClientConnectionPoolDataSou
// Attempt to establish a physical database connection that can be used as a pooled connection.
public PooledConnection getPooledConnection() throws SQLException {
+ LogWriter dncLogWriter = null;
try
{
- LogWriter dncLogWriter = super.computeDncLogWriterForNewConnection("_cpds");
+ dncLogWriter = super.computeDncLogWriterForNewConnection("_cpds");
if (dncLogWriter != null) {
dncLogWriter.traceEntry(this, "getPooledConnection");
}
@@ -85,15 +86,19 @@ public class ClientConnectionPoolDataSou
}
catch ( SqlException se )
{
+ // The method below may throw an exception.
+ handleConnectionException(dncLogWriter, se);
+ // If the exception wasn't handled so far, re-throw it.
throw se.getSQLException();
}
}
// Standard method that establishes the initial physical connection using CPDS properties.
public PooledConnection getPooledConnection(String user, String password) throws SQLException {
+ LogWriter dncLogWriter = null;
try
{
- LogWriter dncLogWriter = super.computeDncLogWriterForNewConnection("_cpds");
+ dncLogWriter = super.computeDncLogWriterForNewConnection("_cpds");
if (dncLogWriter != null) {
dncLogWriter.traceEntry(this, "getPooledConnection", user, "<escaped>");
}
@@ -105,6 +110,9 @@ public class ClientConnectionPoolDataSou
}
catch ( SqlException se )
{
+ // The method below may throw an exception.
+ handleConnectionException(dncLogWriter, se);
+ // If the exception wasn't handled so far, re-throw it.
throw se.getSQLException();
}
}
Modified: db/derby/code/branches/10.5/java/client/org/apache/derby/jdbc/ClientDataSource.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/client/org/apache/derby/jdbc/ClientDataSource.java?rev=958572&r1=958571&r2=958572&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/client/org/apache/derby/jdbc/ClientDataSource.java (original)
+++ db/derby/code/branches/10.5/java/client/org/apache/derby/jdbc/ClientDataSource.java Mon Jun 28 13:29:52 2010
@@ -25,10 +25,12 @@ import java.sql.Connection;
import java.sql.SQLException;
import javax.sql.DataSource;
+import org.apache.derby.client.am.ClientMessageId;
import org.apache.derby.client.am.LogWriter;
import org.apache.derby.client.am.SqlException;
import org.apache.derby.client.net.NetConnection;
import org.apache.derby.client.net.NetLogWriter;
+import org.apache.derby.shared.common.error.ExceptionUtil;
/**
* ClientDataSource is a simple data source implementation
@@ -179,9 +181,10 @@ public class ClientDataSource extends Cl
// This log writer may be narrowed to the connection-level
// This log writer will be passed to the agent constructor.
+ LogWriter dncLogWriter = null;
try
{
- LogWriter dncLogWriter = super.computeDncLogWriterForNewConnection("_sds");
+ dncLogWriter = super.computeDncLogWriterForNewConnection("_sds");
updateDataSourceValues(tokenizeAttributes(getConnectionAttributes(), null));
return ClientDriver.getFactory().newNetConnection
((NetLogWriter) dncLogWriter, user,
@@ -189,6 +192,9 @@ public class ClientDataSource extends Cl
}
catch(SqlException se)
{
+ // The method below may throw an exception.
+ handleConnectionException(dncLogWriter, se);
+ // If the exception wasn't handled so far, re-throw it.
throw se.getSQLException();
}
Modified: db/derby/code/branches/10.5/java/client/org/apache/derby/jdbc/ClientXADataSource.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/client/org/apache/derby/jdbc/ClientXADataSource.java?rev=958572&r1=958571&r2=958572&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/client/org/apache/derby/jdbc/ClientXADataSource.java (original)
+++ db/derby/code/branches/10.5/java/client/org/apache/derby/jdbc/ClientXADataSource.java Mon Jun 28 13:29:52 2010
@@ -66,13 +66,18 @@ public class ClientXADataSource extends
}
public XAConnection getXAConnection(String user, String password) throws SQLException {
+ NetLogWriter dncLogWriter = null;
try
{
- NetLogWriter dncLogWriter = (NetLogWriter) super.computeDncLogWriterForNewConnection("_xads");
+ dncLogWriter = (NetLogWriter)
+ super.computeDncLogWriterForNewConnection("_xads");
return getXAConnectionX(dncLogWriter, this, user, password);
}
catch ( SqlException se )
{
+ // The method below may throw an exception.
+ handleConnectionException(dncLogWriter, se);
+ // If the exception wasn't handled so far, re-throw it.
throw se.getSQLException();
}
}
Modified: db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DataSourceTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DataSourceTest.java?rev=958572&r1=958571&r2=958572&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DataSourceTest.java (original)
+++ db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DataSourceTest.java Mon Jun 28 13:29:52 2010
@@ -247,10 +247,7 @@ public class DataSourceTest extends Base
ds.getConnection();
fail ("should have seen an error");
} catch (SQLException e) {
- if (usingEmbedded())
- assertSQLState("XJ028", e);
- else if (usingDerbyNetClient())
- assertSQLState("XJ212", e);
+ assertSQLState("XJ028", e);
}
} // End testBadConnectionAttributeSyntax