diff --git a/extensions/federated-catalog-cache-sql/src/main/java/org/upm/inesdata/federated/sql/index/SqlFederatedCacheStore.java b/extensions/federated-catalog-cache-sql/src/main/java/org/upm/inesdata/federated/sql/index/SqlFederatedCacheStore.java index 4d9584d..311079d 100644 --- a/extensions/federated-catalog-cache-sql/src/main/java/org/upm/inesdata/federated/sql/index/SqlFederatedCacheStore.java +++ b/extensions/federated-catalog-cache-sql/src/main/java/org/upm/inesdata/federated/sql/index/SqlFederatedCacheStore.java @@ -120,7 +120,10 @@ public Collection query(QuerySpec query) { public void deleteExpired() { transactionContext.execute(() -> { try (var connection = getConnection()) { - queryExecutor.execute(connection, databaseStatements.getDeleteExpiredCatalogsTemplate(), true); + List expiredCatalogs = getExpiredCatalogs(); + for (Catalog catalog: expiredCatalogs) { + this.deleteRelatedCatalogData(connection, catalog); + } return null; } catch (SQLException e) { throw new EdcPersistenceException(e); @@ -161,6 +164,16 @@ public Collection queryPagination(QuerySpec querySpec) { }); } + private List getExpiredCatalogs() { + try (var connection = getConnection()) { + String selectCatalog = databaseStatements.getSelectExpiredCatalogsTemplate(); + return queryExecutor.query(connection, false, this::mapResultSetToCatalog, selectCatalog) + .collect(Collectors.toList()); + } catch (SQLException e) { + throw new EdcPersistenceException(e); + } + } + private void deleteRelatedCatalogData(Connection connection, Catalog catalog) { Catalog catalogByParticipantId = getCatalogByParticipantId(catalog.getParticipantId()); @@ -180,7 +193,6 @@ private void deleteRelatedCatalogData(Connection connection, Catalog catalog) { String deleteCatalogSql = databaseStatements.getDeleteCatalogByParticipantIdTemplate(); queryExecutor.execute(connection, deleteCatalogSql, catalog.getParticipantId()); } - } private boolean dataServiceExists(String dataServiceId) throws SQLException { diff --git a/extensions/federated-catalog-cache-sql/src/main/java/org/upm/inesdata/federated/sql/index/schema/BaseSqlDialectStatements.java b/extensions/federated-catalog-cache-sql/src/main/java/org/upm/inesdata/federated/sql/index/schema/BaseSqlDialectStatements.java index 317fee0..b738bf7 100644 --- a/extensions/federated-catalog-cache-sql/src/main/java/org/upm/inesdata/federated/sql/index/schema/BaseSqlDialectStatements.java +++ b/extensions/federated-catalog-cache-sql/src/main/java/org/upm/inesdata/federated/sql/index/schema/BaseSqlDialectStatements.java @@ -267,4 +267,14 @@ public String getSelectCatalogForParticipantIdTemplate() { public String getSelectDatasetTemplate() { return format("SELECT * FROM %s AS a", getDatasetTable()); } + + /** + * {@inheritDoc} + * + * @see SqlFederatedCatalogStatements#getSelectExpiredCatalogsTemplate() + */ + @Override + public String getSelectExpiredCatalogsTemplate() { + return format("SELECT * FROM %s AS a WHERE expired = true", getCatalogTable()); + } } diff --git a/extensions/federated-catalog-cache-sql/src/main/java/org/upm/inesdata/federated/sql/index/schema/SqlFederatedCatalogStatements.java b/extensions/federated-catalog-cache-sql/src/main/java/org/upm/inesdata/federated/sql/index/schema/SqlFederatedCatalogStatements.java index eb981c0..8a5e999 100644 --- a/extensions/federated-catalog-cache-sql/src/main/java/org/upm/inesdata/federated/sql/index/schema/SqlFederatedCatalogStatements.java +++ b/extensions/federated-catalog-cache-sql/src/main/java/org/upm/inesdata/federated/sql/index/schema/SqlFederatedCatalogStatements.java @@ -336,4 +336,11 @@ default String getDistributionDatasetIdColumn() { * @return the SQL template for selecting a dataset. */ String getSelectDatasetTemplate(); + + /** + * Retrieves the SQL template for expired catalogs. + * + * @return the SQL template for selecting expired catalogs. + */ + String getSelectExpiredCatalogsTemplate(); }