Skip to content

Commit

Permalink
Merge pull request #181 from graben/housekeeping
Browse files Browse the repository at this point in the history
Remove some obsolete code for XADataSource handling
  • Loading branch information
geoand authored Jan 7, 2025
2 parents ed0b3f9 + ca1d7fb commit eb2e51a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 86 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,20 @@
import javax.sql.XADataSource;

import com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule;
import com.arjuna.ats.jta.recovery.XAResourceRecoveryHelper;
import dev.snowdrop.boot.narayana.core.properties.RecoveryCredentialsProperties;
import org.springframework.boot.jdbc.XADataSourceWrapper;

/**
* {@link AbstractXADataSourceWrapper} implementation that uses {@link NarayanaDataSource} to wrap an
* {@link XADataSource}.
* An {@link XADataSourceWrapper} implementation which handles {@link XAResourceRecoveryHelper} creation and
* registration. It delegates the actual {@link XADataSource} wrapping to its subclass {@link NarayanaDataSource}.
*
* @author <a href="mailto:[email protected]">Gytis Trikleris</a>
*/
public class GenericXADataSourceWrapper extends AbstractXADataSourceWrapper {
public class GenericXADataSourceWrapper implements XADataSourceWrapper {

private final XARecoveryModule xaRecoveryModule;
private final RecoveryCredentialsProperties recoveryCredentials;

/**
* Create a new {@link GenericXADataSourceWrapper} instance.
Expand All @@ -46,18 +51,29 @@ public GenericXADataSourceWrapper(XARecoveryModule xaRecoveryModule) {
* @param recoveryCredentials credentials for recovery helper
*/
public GenericXADataSourceWrapper(XARecoveryModule xaRecoveryModule, RecoveryCredentialsProperties recoveryCredentials) {
super(xaRecoveryModule, recoveryCredentials);
this.xaRecoveryModule = xaRecoveryModule;
this.recoveryCredentials = recoveryCredentials;
}

/**
* Wrap provided {@link XADataSource} with an instance of {@link NarayanaDataSource}.
* Register newly created recovery helper with the {@link XARecoveryModule} and delegate data source wrapping.
*
* @param dataSource data source that needs to be wrapped.
* @return wrapped data source.
* @param dataSource {@link XADataSource} that needs to be wrapped.
* @return wrapped data source
* @throws Exception in case data source wrapping has failed
*/
@Override
protected DataSource wrapDataSourceInternal(XADataSource dataSource) {
public DataSource wrapDataSource(XADataSource dataSource) throws Exception {
XAResourceRecoveryHelper recoveryHelper = getRecoveryHelper(dataSource);
this.xaRecoveryModule.addXAResourceRecoveryHelper(recoveryHelper);
return new NarayanaDataSource(dataSource);
}

private XAResourceRecoveryHelper getRecoveryHelper(XADataSource dataSource) {
if (this.recoveryCredentials.isValid()) {
return new DataSourceXAResourceRecoveryHelper(dataSource, this.recoveryCredentials.getUser(),
this.recoveryCredentials.getPassword());
}
return new DataSourceXAResourceRecoveryHelper(dataSource);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import javax.sql.XADataSource;

import com.arjuna.ats.internal.jdbc.ConnectionImple;
import com.arjuna.ats.jdbc.TransactionalDriver;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
Expand Down Expand Up @@ -92,10 +91,6 @@ void shouldGetConnectionAndCommit() throws SQLException {
given(mockXaConnection.getConnection()).willReturn(mockConnection);
given(this.mockXaDataSource.getXAConnection()).willReturn(mockXaConnection);

// TODO properties not used
Properties properties = new Properties();
properties.put(TransactionalDriver.XADataSource, this.mockXaDataSource);

Connection connection = this.dataSourceBean.getConnection();
assertThat(connection).isInstanceOf(ConnectionImple.class);

Expand Down Expand Up @@ -125,12 +120,6 @@ void shouldGetConnectionAndCommitWithCredentials() throws IOException, SQLExcept
given(mockXaConnection.getConnection()).willReturn(mockConnection);
given(this.mockXaDataSource.getXAConnection(authProperties.getProperty("username"), authProperties.getProperty("username"))).willReturn(mockXaConnection);

// TODO properties not used
Properties properties = new Properties();
properties.put(TransactionalDriver.XADataSource, this.mockXaDataSource);
properties.put(TransactionalDriver.userName, authProperties.getProperty("username"));
properties.put(TransactionalDriver.password, authProperties.getProperty("username"));

Connection connection = this.dataSourceBean.getConnection(authProperties.getProperty("username"), authProperties.getProperty("username"));
assertThat(connection).isInstanceOf(ConnectionImple.class);

Expand Down

0 comments on commit eb2e51a

Please sign in to comment.