Skip to content

Commit

Permalink
Simplify listener creation and enablement check
Browse files Browse the repository at this point in the history
  • Loading branch information
radovanradic committed Nov 27, 2024
1 parent 9face31 commit 90b9061
Showing 1 changed file with 6 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,14 @@
import io.micronaut.core.annotation.Nullable;
import io.micronaut.core.util.CollectionUtils;
import io.micronaut.core.util.StringUtils;
import io.micronaut.data.connection.jdbc.advice.DelegatingDataSource;
import io.micronaut.data.jdbc.config.DataJdbcConfiguration;
import io.micronaut.data.jdbc.connection.annotation.ClientInfo;
import io.micronaut.data.model.query.builder.sql.Dialect;
import io.micronaut.jdbc.BasicJdbcConfiguration;
import io.micronaut.runtime.ApplicationConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLClientInfoException;
import java.sql.SQLException;
Expand All @@ -53,7 +52,7 @@
* @author radovanradic
* @since 4.11
*/
@EachBean(DataSource.class)
@EachBean(BasicJdbcConfiguration.class)
@Internal
final class OracleClientInfoConnectionCustomizer implements ConnectionCustomizer {

Expand Down Expand Up @@ -90,34 +89,22 @@ final class OracleClientInfoConnectionCustomizer implements ConnectionCustomizer
private final boolean enabled;

OracleClientInfoConnectionCustomizer(@Parameter DataJdbcConfiguration jdbcConfiguration,
@Nullable DataSource dataSource,
ApplicationContext applicationContext,
@Nullable ApplicationConfiguration applicationConfiguration) {
this.applicationName = applicationConfiguration != null ? applicationConfiguration.getName().orElse(null) : null;
this.enabled = isEnabled(jdbcConfiguration, applicationContext, dataSource);
this.enabled = isEnabled(jdbcConfiguration, applicationContext);
this.dataSourceName = jdbcConfiguration.getName();
}

private boolean isEnabled(DataJdbcConfiguration dataJdbcConfiguration, ApplicationContext applicationContext, DataSource dataSource) {
if (dataSource == null || !dataJdbcConfiguration.isEnabled()) {
private boolean isEnabled(DataJdbcConfiguration dataJdbcConfiguration, ApplicationContext applicationContext) {
if (!dataJdbcConfiguration.isEnabled()) {
return false;
}
if (dataJdbcConfiguration.getDialect() != Dialect.ORACLE) {
return false;
}
String property = "datasources." + dataJdbcConfiguration.getName() + "." + ORACLE_CLIENT_INFO_ENABLED;
if (!applicationContext.getProperty(property, Boolean.class).orElse(false)) {
return false;
}
boolean customizerEnabled;
try {
Connection connection = DelegatingDataSource.unwrapDataSource(dataSource).getConnection();
customizerEnabled = isOracleConnection(connection);
} catch (SQLException e) {
LOG.error("Failed to get connection for oracle connection customizer", e);
customizerEnabled = false;
}
return customizerEnabled;
return applicationContext.getProperty(property, Boolean.class).orElse(false);
}

@Override
Expand Down

0 comments on commit 90b9061

Please sign in to comment.