diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/DataSourceFactory.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/DataSourceFactory.java index d8e2b664e..a0779931b 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/DataSourceFactory.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/DataSourceFactory.java @@ -237,7 +237,14 @@ public class DataSourceFactory { return ds; } catch (Exception e) { - throw new StoreException(e).setFatal(true); + throw new StoreException(_loc.get("conn-failed", factory2 + ? new Object[]{conf.getConnection2DriverName(), + conf.getConnection2URL(), + conf.getConnection2Properties()} + : new Object[]{conf.getConnectionDriverName(), + conf.getConnectionURL(), + conf.getConnectionProperties()}), + e); } finally { if (conn != null) try { diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/SimpleDriverDataSource.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/SimpleDriverDataSource.java index 5a6395914..0644845a5 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/SimpleDriverDataSource.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/SimpleDriverDataSource.java @@ -30,7 +30,9 @@ import java.util.Properties; import org.apache.openjpa.jdbc.sql.DBDictionary; import org.apache.openjpa.lib.util.J2DoPrivHelper; +import org.apache.openjpa.lib.util.Localizer; import org.apache.openjpa.util.StoreException; +import org.apache.openjpa.util.UserException; /** * Non-pooling driver data source. @@ -46,6 +48,9 @@ public class SimpleDriverDataSource private Properties _connectionFactoryProperties; private Driver _driver; private ClassLoader _classLoader; + + protected static Localizer _loc = + Localizer.forPackage(SimpleDriverDataSource.class); public Connection getConnection() throws SQLException { @@ -70,7 +75,12 @@ public class SimpleDriverDataSource public Connection getConnection(Properties props) throws SQLException { - return getDriver().connect(_connectionURL, props); + Connection con = getDriver().connect(_connectionURL, props); + if (con == null) { + throw new UserException(_loc.get("conn-failed", + _connectionDriverName, _connectionURL, props)); + } + return con; } public int getLoginTimeout() { diff --git a/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/schema/localizer.properties b/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/schema/localizer.properties index 135fb33df..cab55e1be 100644 --- a/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/schema/localizer.properties +++ b/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/schema/localizer.properties @@ -148,4 +148,6 @@ no-custom-ds: use a custom DataSource delete-table-contents: An error occurred while attempting to delete all \ records from all mapped tables. set-auto-commit: DataSource connection setAutoCommit to "{0}" - +conn-failed: Failed to connect to DataSource. Verify Driver "{0}", URL "{1}" \ + and connection properties "{2}" are correct. See the nested exception for \ + further details. diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/util/StoreException.java b/openjpa-kernel/src/main/java/org/apache/openjpa/util/StoreException.java index 24055667f..bb831727e 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/util/StoreException.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/util/StoreException.java @@ -47,6 +47,14 @@ public class StoreException super(cause); } + public StoreException(String msg, Throwable cause) { + super(msg, cause); + } + + public StoreException(Message msg, Throwable cause) { + super(msg.getMessage(), cause); + } + public int getType() { return STORE; }