Skip to content

Commit

Permalink
Merge pull request #1933 from mwoodiupui/DS-3434-7
Browse files Browse the repository at this point in the history
[DS-3434] DSpace fails to start when a database connection pool is supplied through JNDI
  • Loading branch information
mwoodiupui committed Feb 7, 2018
2 parents a8cd35d + e5b30f3 commit 2990729
Showing 1 changed file with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

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;
Expand Down Expand Up @@ -545,6 +544,9 @@ public static synchronized void updateDatabase()
{
// 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())
{
Expand Down Expand Up @@ -598,9 +600,14 @@ protected static synchronized void updateDatabase(DataSource datasource, Connect
* @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
Expand Down Expand Up @@ -1380,15 +1387,21 @@ else if (dbms_lc.contains("h2")) // Used for unit testing only
/**
* 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.
* @return DataSource
*/
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;
}

/**
Expand Down

0 comments on commit 2990729

Please sign in to comment.