mirror of https://github.com/apache/openjpa.git
OPENJPA-656 : raise informational error on initial connection failure
git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@675952 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
07919b9bec
commit
cc85528f69
|
@ -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 {
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue