diff --git a/direct/io-jdbc/src/main/java/cz/o2/proxima/direct/jdbc/JdbcDataAccessor.java b/direct/io-jdbc/src/main/java/cz/o2/proxima/direct/jdbc/JdbcDataAccessor.java index 7d0d05c06..696ad2f4b 100644 --- a/direct/io-jdbc/src/main/java/cz/o2/proxima/direct/jdbc/JdbcDataAccessor.java +++ b/direct/io-jdbc/src/main/java/cz/o2/proxima/direct/jdbc/JdbcDataAccessor.java @@ -36,29 +36,37 @@ public class JdbcDataAccessor extends AbstractStorage implements DataAccessor { static final String JDBC_URI_STORAGE_PREFIX = "jdbc://"; static final String JDBC_DRIVER_CFG = "driverClassName"; static final String JDBC_USERNAME_CFG = "username"; + + @SuppressWarnings("squid:S2068") static final String JDBC_PASSWORD_CFG = "password"; + static final String JDBC_SQL_QUERY_FACTORY = "sqlQueryfactory"; static final String JDBC_RESULT_CONVERTER = "converter"; - private final Map cfg; private final String jdbcUri; + private final String jdbcUsername; + private final String jdbcPassword; + private final String jdbcDriver; private final EntityDescriptor entityDescriptor; private final URI uri; private final SqlStatementFactory sqlStatementFactory; - @Getter private final Converter resultConverter; + @Getter private final Converter resultConverter; private transient HikariDataSource dataSource; protected JdbcDataAccessor(EntityDescriptor entityDesc, URI uri, Map cfg) { super(entityDesc, uri); - this.cfg = cfg; this.jdbcUri = uri.toString().substring(JDBC_URI_STORAGE_PREFIX.length()); this.entityDescriptor = entityDesc; this.uri = uri; + jdbcDriver = cfg.getOrDefault(JDBC_DRIVER_CFG, "").toString(); + jdbcUsername = cfg.getOrDefault(JDBC_USERNAME_CFG, "").toString(); + jdbcPassword = cfg.getOrDefault(JDBC_PASSWORD_CFG, "").toString(); + if (!cfg.containsKey(JDBC_SQL_QUERY_FACTORY)) { log.error("Missing configuration param {}.", JDBC_URI_STORAGE_PREFIX); throw new IllegalStateException( @@ -90,13 +98,6 @@ protected JdbcDataAccessor(EntityDescriptor entityDesc, URI uri, Map entry : cfg.entrySet()) { - log.debug("Setting property {} to value {}.", entry.getKey(), entry.getValue()); - dataSourceConfig.addDataSourceProperty(entry.getKey(), entry.getValue()); - } - */ } @Override @@ -122,16 +123,17 @@ HikariDataSource getDataSource() { HikariConfig dataSourceConfig = new HikariConfig(); dataSourceConfig.setPoolName( String.format("jdbc-pool-%s", this.getEntityDescriptor().getName())); - if (cfg.containsKey(JDBC_DRIVER_CFG)) { - dataSourceConfig.setDataSourceClassName(cfg.get(JDBC_DRIVER_CFG).toString()); + + if (!jdbcDriver.isEmpty()) { + dataSourceConfig.setDataSourceClassName(jdbcDriver); } - log.info("Creating JDBC storage from url: {}", this.jdbcUri); - dataSourceConfig.setJdbcUrl(this.jdbcUri); - if (cfg.containsKey(JDBC_USERNAME_CFG)) { - dataSourceConfig.setUsername(cfg.get(JDBC_USERNAME_CFG).toString()); + log.info("Creating JDBC storage from url: {}", jdbcUri); + dataSourceConfig.setJdbcUrl(jdbcUri); + if (!jdbcUsername.isEmpty()) { + dataSourceConfig.setUsername(jdbcUsername); } - if (cfg.containsKey(JDBC_PASSWORD_CFG)) { - dataSourceConfig.setPassword(cfg.get(JDBC_PASSWORD_CFG).toString()); + if (!jdbcPassword.isEmpty()) { + dataSourceConfig.setPassword(jdbcPassword); } this.dataSource = new HikariDataSource(dataSourceConfig); } diff --git a/direct/io-jdbc/src/main/java/cz/o2/proxima/direct/jdbc/Offsets.java b/direct/io-jdbc/src/main/java/cz/o2/proxima/direct/jdbc/Offsets.java index 69660fb50..8f17ba149 100644 --- a/direct/io-jdbc/src/main/java/cz/o2/proxima/direct/jdbc/Offsets.java +++ b/direct/io-jdbc/src/main/java/cz/o2/proxima/direct/jdbc/Offsets.java @@ -18,6 +18,8 @@ import cz.o2.proxima.direct.randomaccess.RandomOffset; public class Offsets { + private Offsets() {} + public static class Raw implements RandomOffset { private final String key; diff --git a/direct/io-jdbc/src/test/java/cz/o2/proxima/direct/jdbc/JdbcBaseTest.java b/direct/io-jdbc/src/test/java/cz/o2/proxima/direct/jdbc/JdbcBaseTest.java index 2df2b7017..ca01068b2 100644 --- a/direct/io-jdbc/src/test/java/cz/o2/proxima/direct/jdbc/JdbcBaseTest.java +++ b/direct/io-jdbc/src/test/java/cz/o2/proxima/direct/jdbc/JdbcBaseTest.java @@ -35,15 +35,12 @@ import org.junit.Before; @Slf4j -public class JdbcBaseTest { +public abstract class JdbcBaseTest { final Repository repository = ConfigRepository.Builder.ofTest(ConfigFactory.defaultApplication()).build(); final AttributeDescriptor attr; final EntityDescriptor entity; - - final Map config = new HashMap<>(); - final JdbcDataAccessor accessor; public JdbcBaseTest() throws URISyntaxException { @@ -54,6 +51,7 @@ public JdbcBaseTest() throws URISyntaxException { .setSchemeUri(new URI("bytes:///")) .build(); entity = EntityDescriptor.newBuilder().setName("dummy").addAttribute(attr).build(); + Map config = new HashMap<>(); config.put(JdbcDataAccessor.JDBC_SQL_QUERY_FACTORY, HsqldbSqlStatementFactory.class.getName()); config.put(JdbcDataAccessor.JDBC_RESULT_CONVERTER, TestConverter.class.getName()); // config.put(JdbcDataAccessor.JDBC_DRIVER_CFG, "org.hsqldb.jdbc.JDBCDataSource");