mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-07 01:54:22 +00:00
Merge pull request #1933 from mwoodiupui/DS-3434-7
[DS-3434] DSpace fails to start when a database connection pool is supplied through JNDI
This commit is contained in:
@@ -24,7 +24,6 @@ import java.util.regex.Pattern;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.apache.commons.dbcp2.BasicDataSource;
|
||||
import org.apache.commons.lang.ArrayUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
@@ -545,6 +544,9 @@ public class DatabaseUtils
|
||||
{
|
||||
// Get our configured dataSource
|
||||
DataSource dataSource = getDataSource();
|
||||
if (null == dataSource) {
|
||||
throw new SQLException("The DataSource is a null reference -- cannot continue.");
|
||||
}
|
||||
|
||||
try(Connection connection = dataSource.getConnection())
|
||||
{
|
||||
@@ -598,9 +600,14 @@ public class DatabaseUtils
|
||||
* @throws SQLException if database error
|
||||
* If database cannot be upgraded.
|
||||
*/
|
||||
protected static synchronized void updateDatabase(DataSource datasource, Connection connection, String targetVersion, boolean outOfOrder)
|
||||
protected static synchronized void updateDatabase(DataSource datasource,
|
||||
Connection connection, String targetVersion, boolean outOfOrder)
|
||||
throws SQLException
|
||||
{
|
||||
if (null == datasource) {
|
||||
throw new SQLException("The datasource is a null reference -- cannot continue.");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// Setup Flyway API against our database
|
||||
@@ -1380,6 +1387,7 @@ public class DatabaseUtils
|
||||
/**
|
||||
* Get a reference to the configured DataSource (which can be used to
|
||||
* initialize the database using Flyway).
|
||||
* The DataSource is configured via our ServiceManager (i.e. via Spring).
|
||||
* <P>
|
||||
* This is NOT public, as we discourage direct connections to the database
|
||||
* which bypass Hibernate. Only Flyway should be allowed a direct connection.
|
||||
@@ -1387,8 +1395,13 @@ public class DatabaseUtils
|
||||
*/
|
||||
protected static DataSource getDataSource()
|
||||
{
|
||||
// DataSource is configured via our ServiceManager (i.e. via Spring).
|
||||
return DSpaceServicesFactory.getInstance().getServiceManager().getServiceByName("dataSource", BasicDataSource.class);
|
||||
DataSource dataSource = DSpaceServicesFactory.getInstance()
|
||||
.getServiceManager()
|
||||
.getServiceByName("dataSource", DataSource.class);
|
||||
if (null == dataSource) {
|
||||
log.error("The service manager could not find the DataSource.");
|
||||
}
|
||||
return dataSource;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user