Skip to content

Commit

Permalink
Cannot delete a datasource if the source on the connection string do…
Browse files Browse the repository at this point in the history
…es not exists #2152  (#2156)

* Cannot delete a datasource if the source on the connection string does not exists #2152

* Cannot delete a datasource if the source on the connection string does not exists #2152 - cleanup
  • Loading branch information
anton-abushkevich committed Nov 9, 2022
1 parent b2235fe commit e79e04f
Showing 1 changed file with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
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.util.Objects;
Expand All @@ -22,6 +24,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";

Expand Down Expand Up @@ -88,9 +91,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());
}
}
}

0 comments on commit e79e04f

Please sign in to comment.