Skip to content

Commit

Permalink
Some sonar
Browse files Browse the repository at this point in the history
  • Loading branch information
LesTR committed Jan 13, 2020
1 parent 36a4055 commit def2b83
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Object> 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<String, Object> 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(
Expand Down Expand Up @@ -90,13 +98,6 @@ protected JdbcDataAccessor(EntityDescriptor entityDesc, URI uri, Map<String, Obj
Classpath.newInstance(cfg.get(JDBC_RESULT_CONVERTER).toString(), Converter.class);
resultConverter.setup();
}

/* @TODO
for (Map.Entry<String, Object> entry : cfg.entrySet()) {
log.debug("Setting property {} to value {}.", entry.getKey(), entry.getValue());
dataSourceConfig.addDataSourceProperty(entry.getKey(), entry.getValue());
}
*/
}

@Override
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Byte[]> attr;
final EntityDescriptor entity;

final Map<String, Object> config = new HashMap<>();

final JdbcDataAccessor accessor;

public JdbcBaseTest() throws URISyntaxException {
Expand All @@ -54,6 +51,7 @@ public JdbcBaseTest() throws URISyntaxException {
.setSchemeUri(new URI("bytes:///"))
.build();
entity = EntityDescriptor.newBuilder().setName("dummy").addAttribute(attr).build();
Map<String, Object> 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");
Expand Down

0 comments on commit def2b83

Please sign in to comment.