Restore old driver logic
This commit is contained in:
parent
fd5854ea85
commit
798982773a
|
@ -1,17 +1,18 @@
|
||||||
package ca.uhn.fhir.jpa.migrate;
|
package ca.uhn.fhir.jpa.migrate;
|
||||||
|
|
||||||
import ca.uhn.fhir.context.ConfigurationException;
|
|
||||||
import org.apache.commons.lang3.Validate;
|
import org.apache.commons.lang3.Validate;
|
||||||
import org.springframework.beans.factory.DisposableBean;
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.jdbc.core.JdbcTemplate;
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
|
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
|
||||||
import org.springframework.jdbc.datasource.SimpleDriverDataSource;
|
import org.springframework.jdbc.datasource.SingleConnectionDataSource;
|
||||||
import org.springframework.transaction.TransactionDefinition;
|
import org.springframework.transaction.TransactionDefinition;
|
||||||
import org.springframework.transaction.support.TransactionTemplate;
|
import org.springframework.transaction.support.TransactionTemplate;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.sql.DataSource;
|
|
||||||
import java.sql.Driver;
|
import java.sql.Driver;
|
||||||
|
import java.sql.DriverManager;
|
||||||
|
import java.util.Enumeration;
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* #%L
|
* #%L
|
||||||
|
@ -22,9 +23,9 @@ import java.sql.Driver;
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
@ -49,6 +50,7 @@ public enum DriverTypeEnum {
|
||||||
|
|
||||||
;
|
;
|
||||||
|
|
||||||
|
private static final Logger ourLog = LoggerFactory.getLogger(DriverTypeEnum.class);
|
||||||
private String myDriverClassName;
|
private String myDriverClassName;
|
||||||
private boolean myDerby;
|
private boolean myDerby;
|
||||||
|
|
||||||
|
@ -60,21 +62,15 @@ public enum DriverTypeEnum {
|
||||||
myDerby = theDerby;
|
myDerby = theDerby;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public ConnectionProperties newConnectionProperties(String theUrl, String theUsername, String thePassword) {
|
public ConnectionProperties newConnectionProperties(String theUrl, String theUsername, String thePassword) {
|
||||||
|
|
||||||
Driver driver = null;
|
SingleConnectionDataSource dataSource = new SingleConnectionDataSource();
|
||||||
try {
|
dataSource.setAutoCommit(false);
|
||||||
driver = (Driver) Class.forName(myDriverClassName).newInstance();
|
dataSource.setDriverClassName(myDriverClassName);
|
||||||
} catch (Exception e) {
|
|
||||||
throw new ConfigurationException("Failed to initialize driver: " + myDriverClassName + ": " + e.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
SimpleDriverDataSource dataSource = new SimpleDriverDataSource();
|
|
||||||
dataSource.setDriver(driver);
|
|
||||||
dataSource.setUrl(theUrl);
|
dataSource.setUrl(theUrl);
|
||||||
dataSource.setUsername(theUsername);
|
dataSource.setUsername(theUsername);
|
||||||
dataSource.setPassword(thePassword);
|
dataSource.setPassword(thePassword);
|
||||||
|
dataSource.setSuppressClose(true);
|
||||||
|
|
||||||
DataSourceTransactionManager transactionManager = new DataSourceTransactionManager();
|
DataSourceTransactionManager transactionManager = new DataSourceTransactionManager();
|
||||||
transactionManager.setDataSource(dataSource);
|
transactionManager.setDataSource(dataSource);
|
||||||
|
@ -91,12 +87,13 @@ public enum DriverTypeEnum {
|
||||||
public static class ConnectionProperties {
|
public static class ConnectionProperties {
|
||||||
|
|
||||||
private final DriverTypeEnum myDriverType;
|
private final DriverTypeEnum myDriverType;
|
||||||
private final DataSource myDataSource;
|
private final SingleConnectionDataSource myDataSource;
|
||||||
private final TransactionTemplate myTxTemplate;
|
private final TransactionTemplate myTxTemplate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*/
|
*/
|
||||||
public ConnectionProperties(DataSource theDataSource, TransactionTemplate theTxTemplate, DriverTypeEnum theDriverType) {
|
public ConnectionProperties(SingleConnectionDataSource theDataSource, TransactionTemplate theTxTemplate, DriverTypeEnum theDriverType) {
|
||||||
Validate.notNull(theDataSource);
|
Validate.notNull(theDataSource);
|
||||||
Validate.notNull(theTxTemplate);
|
Validate.notNull(theTxTemplate);
|
||||||
Validate.notNull(theDriverType);
|
Validate.notNull(theDriverType);
|
||||||
|
@ -111,7 +108,7 @@ public enum DriverTypeEnum {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public DataSource getDataSource() {
|
public SingleConnectionDataSource getDataSource() {
|
||||||
return myDataSource;
|
return myDataSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -128,13 +125,7 @@ public enum DriverTypeEnum {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void close() {
|
public void close() {
|
||||||
if (myDataSource instanceof DisposableBean) {
|
myDataSource.destroy();
|
||||||
try {
|
|
||||||
((DisposableBean) myDataSource).destroy();
|
|
||||||
} catch (Exception theE) {
|
|
||||||
// ignore
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue