Skip to content

Commit

Permalink
Prefix beans for commonly used classes
Browse files Browse the repository at this point in the history
  • Loading branch information
jacodg committed May 7, 2024
1 parent abe0924 commit 8afde68
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
13 changes: 9 additions & 4 deletions src/main/java/nl/nn/testtool/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,10 @@ String xsltResource() {

@Bean
@Scope("singleton")
DataSource dataSource() {
// Prefix with ladybug to prevent interference with other beans of the application that is using Ladybug. E.g. in
// F!F when ladybug.jdbc.datasource is empty this bean should not be initialized but when it's name is dataSource
// it will be wired to the scheduler bean and initialized (giving error with ladybug.jdbc.datasource is empty)
DataSource ladybugDataSource() {
return new SimpleDriverDataSource();
}

Expand All @@ -237,15 +240,17 @@ DataSource dataSource() {
// F!F matrix test several combination fail with 5 scenarios failed (all JMS related)
TransactionManager ladybugTransactionManager(DataSource dataSource) {
OptionalJtaTransactionManager optionalJtaTransactionManager = new OptionalJtaTransactionManager();
optionalJtaTransactionManager.setDataSource(dataSource);
optionalJtaTransactionManager.setDataSource(ladybugDataSource);
return optionalJtaTransactionManager;
}

@Bean
@Scope("prototype")
JdbcTemplate jdbcTemplate(DataSource dataSource) {
// Prefix with ladybug to prevent interference with other beans of the application that is using Ladybug as this is
// a commonly used class. Other classes (except the above two that are also prefixed) are Ladybug specific
JdbcTemplate ladybugJdbcTemplate(DataSource ladybugDataSource) {
JdbcTemplate jdbcTemplate = new JdbcTemplate();
jdbcTemplate.setDataSource(dataSource);
jdbcTemplate.setDataSource(ladybugDataSource);
return jdbcTemplate;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public class DatabaseStorage implements LogStorage, CrudStorage {
protected @Setter List<String> bigValueColumns; // Columns for which to limit the number of retrieved characters to 100
protected @Setter Boolean storeReportXml;
protected @Setter Long maxStorageSize;
protected @Setter @Getter @Inject @Autowired JdbcTemplate jdbcTemplate;
protected @Setter @Getter @Inject @Autowired JdbcTemplate ladybugJdbcTemplate;
protected @Setter @Getter @Inject @Autowired DbmsSupport dbmsSupport;
protected @Setter @Getter @Inject @Autowired MetadataExtractor metadataExtractor;
protected String lastExceptionMessage;
Expand Down Expand Up @@ -200,7 +200,7 @@ public void store(Report report) throws StorageException {
}
query.append(")");
log.debug("Store report query: " + query.toString());
jdbcTemplate.update(query.toString(),
ladybugJdbcTemplate.update(query.toString(),
new PreparedStatementSetter() {
@Override
public void setValues(PreparedStatement ps) throws SQLException {
Expand Down Expand Up @@ -259,7 +259,7 @@ public String getWarningsAndErrors() {
public Report getReport(Integer storageId) throws StorageException {
String query = "select report from " + getTable() + " where " + getStorageIdColumn() + " = ?";
log.debug("Get report query: " + query);
List<Report> result = jdbcTemplate.query(query, new Object[]{storageId}, new int[] {Types.INTEGER},
List<Report> result = ladybugJdbcTemplate.query(query, new Object[]{storageId}, new int[] {Types.INTEGER},
(resultSet, rowNum) -> getReport(storageId, resultSet.getBlob(1)));
return result.get(0);
}
Expand Down Expand Up @@ -289,7 +289,7 @@ private void delete(Integer storageId) throws StorageException {

private void delete(String query, int i) throws StorageException {
log.debug("Delete report query (with param value " + i + "): " + query);
jdbcTemplate.update(query,
ladybugJdbcTemplate.update(query,
new PreparedStatementSetter() {
@Override
public void setValues(PreparedStatement ps) throws SQLException {
Expand All @@ -309,7 +309,7 @@ public int getSize() throws StorageException {
buildSizeQuery(query);
log.debug("Get size query: " + query);
try {
return jdbcTemplate.queryForObject(query.toString(), Integer.class);
return ladybugJdbcTemplate.queryForObject(query.toString(), Integer.class);
} catch(DataAccessException e){
throw new StorageException("Could not read size", e);
}
Expand All @@ -324,7 +324,7 @@ public List<Integer> getStorageIds() throws StorageException {
String query = getStorageIdsQuery();
log.debug("Get storage id's query: " + query);
try {
List<Integer> storageIds = jdbcTemplate.query(query, (rs, rowNum) -> rs.getInt(1));
List<Integer> storageIds = ladybugJdbcTemplate.query(query, (rs, rowNum) -> rs.getInt(1));
return storageIds;
} catch(DataAccessException e){
throw new StorageException("Could not read storage id's", e);
Expand Down Expand Up @@ -378,7 +378,8 @@ public List<List<Object>> getMetadata(int maxNumberOfRecords, List<String> metad
}
List<List<Object>> metadata;
try {
metadata = jdbcTemplate.query(query.toString(), args.toArray(), argTypes.stream().mapToInt(i -> i).toArray(),
metadata = ladybugJdbcTemplate.query(query.toString(), args.toArray(),
argTypes.stream().mapToInt(i -> i).toArray(),
(rs, rowNum) ->
{
List<Object> row = new ArrayList<Object>();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2022 WeAreFrank!
Copyright 2022, 2024 WeAreFrank!
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -40,12 +40,12 @@ into this class to prevent a dependency on F!F
*/
// @Singleton disabled for Quarkus for now because of the use of JdbcTemplate
public class DbmsSupport {
private @Setter @Inject @Autowired JdbcTemplate jdbcTemplate;
private @Setter @Inject @Autowired JdbcTemplate ladybugJdbcTemplate;
private String commonDatabaseName;

@PostConstruct
public void init() throws SQLException, MetaDataAccessException {
String databaseProductName = JdbcUtils.extractDatabaseMetaData(jdbcTemplate.getDataSource(), (dbmd) -> dbmd.getDatabaseProductName());
String databaseProductName = JdbcUtils.extractDatabaseMetaData(ladybugJdbcTemplate.getDataSource(), (dbmd) -> dbmd.getDatabaseProductName());
commonDatabaseName = JdbcUtils.commonDatabaseName(databaseProductName);
}

Expand Down

0 comments on commit 8afde68

Please sign in to comment.