From efc0a11bd421dacd32f269910e8b35ebb16ec6b1 Mon Sep 17 00:00:00 2001 From: Anton Abushkevich Date: Wed, 9 Nov 2022 12:38:09 +0300 Subject: [PATCH 1/2] Cannot delete a datasource if the source on the connection string does not exists #2152 --- .../CohortGenerationCacheProvider.java | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/ohdsi/webapi/generationcache/CohortGenerationCacheProvider.java b/src/main/java/org/ohdsi/webapi/generationcache/CohortGenerationCacheProvider.java index e4fdf71e4d..5fa857aee1 100644 --- a/src/main/java/org/ohdsi/webapi/generationcache/CohortGenerationCacheProvider.java +++ b/src/main/java/org/ohdsi/webapi/generationcache/CohortGenerationCacheProvider.java @@ -13,8 +13,11 @@ import org.ohdsi.webapi.util.SessionUtils; import org.ohdsi.webapi.util.SourceUtils; import org.ohdsi.webapi.util.StatementCancel; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; +import java.sql.SQLException; import java.util.Objects; import static org.ohdsi.webapi.Constants.Params.DESIGN_HASH; @@ -22,6 +25,7 @@ @Component public class CohortGenerationCacheProvider extends AbstractDaoService implements GenerationCacheProvider { + private static final Logger log = LoggerFactory.getLogger(CohortGenerationCacheProvider.class); private static final String CACHE_VALIDATION_TIME = "Checksum of Generation cache for designHash = {} has been calculated in {} milliseconds"; @@ -88,9 +92,16 @@ public void remove(Source source, Integer designHash) { new String[]{SourceUtils.getResultsQualifier(source), designHash.toString()} ); sql = SqlTranslate.translateSql(sql, source.getSourceDialect()); - // StatementCancel parameter is needed for calling batchUpdate of CancelableJdbcTemplate class - // Without StatementCancel parameter JdbcTemplate.batchUpdate will be used. - // JdbcTemplate incorrectly determines the support of batch update for impala datasource - getSourceJdbcTemplate(source).batchUpdate(new StatementCancel(), SqlSplit.splitSql(sql)); + + try { + // StatementCancel parameter is needed for calling batchUpdate of CancelableJdbcTemplate class + // Without StatementCancel parameter JdbcTemplate.batchUpdate will be used. + // JdbcTemplate incorrectly determines the support of batch update for impala datasource + getSourceJdbcTemplate(source).batchUpdate(new StatementCancel(), SqlSplit.splitSql(sql)); + } catch (final Exception e) { + // if source is unavailable it throws exception that prevents source from being deleted. + // ignore exception and proceed with deletion. + log.warn("Cannot remove generation caches from source {}", source.getSourceId()); + } } } From a03b11f29b260eae82e78bf6d468985fe216b400 Mon Sep 17 00:00:00 2001 From: Anton Abushkevich Date: Wed, 9 Nov 2022 12:38:46 +0300 Subject: [PATCH 2/2] Cannot delete a datasource if the source on the connection string does not exists #2152 - cleanup --- .../webapi/generationcache/CohortGenerationCacheProvider.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/org/ohdsi/webapi/generationcache/CohortGenerationCacheProvider.java b/src/main/java/org/ohdsi/webapi/generationcache/CohortGenerationCacheProvider.java index 5fa857aee1..d893998f9e 100644 --- a/src/main/java/org/ohdsi/webapi/generationcache/CohortGenerationCacheProvider.java +++ b/src/main/java/org/ohdsi/webapi/generationcache/CohortGenerationCacheProvider.java @@ -17,7 +17,6 @@ import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; -import java.sql.SQLException; import java.util.Objects; import static org.ohdsi.webapi.Constants.Params.DESIGN_HASH;