-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: sql federated catalog cache (#218)
- Loading branch information
Showing
19 changed files
with
916 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
extensions/store/sql/federated-catalog-cache-sql/build.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Apache License, Version 2.0 which is available at | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Contributors: | ||
* Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation | ||
* | ||
*/ | ||
|
||
plugins { | ||
`java-library` | ||
} | ||
|
||
dependencies { | ||
api(project(":spi:federated-catalog-spi")) | ||
testImplementation(testFixtures(libs.edc.core.sql)) | ||
implementation(libs.edc.core.sql) // for the SqlStatements | ||
implementation(libs.edc.spi.transaction.datasource) | ||
implementation(libs.edc.lib.util) | ||
|
||
testImplementation(libs.edc.junit) | ||
testImplementation(testFixtures(libs.edc.core.sql)) | ||
testImplementation(testFixtures(project(":spi:federated-catalog-spi"))) | ||
} |
21 changes: 21 additions & 0 deletions
21
extensions/store/sql/federated-catalog-cache-sql/docs/schema.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
* Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Apache License, Version 2.0 which is available at | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Contributors: | ||
* Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation | ||
* | ||
*/ | ||
|
||
-- only intended for and tested with Postgres! | ||
CREATE TABLE IF NOT EXISTS edc_federated_catalog | ||
( | ||
id VARCHAR PRIMARY KEY NOT NULL, | ||
catalog JSON, | ||
marked BOOLEAN DEFAULT FALSE | ||
); |
75 changes: 75 additions & 0 deletions
75
...g-cache-sql/src/main/java/org/eclipse/edc/catalog/store/sql/BaseSqlDialectStatements.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Apache License, Version 2.0 which is available at | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Contributors: | ||
* Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation | ||
* | ||
*/ | ||
|
||
package org.eclipse.edc.catalog.store.sql; | ||
|
||
import org.eclipse.edc.catalog.store.sql.schema.postgres.FederatedCatalogMapping; | ||
import org.eclipse.edc.spi.query.QuerySpec; | ||
import org.eclipse.edc.sql.translation.SqlOperatorTranslator; | ||
import org.eclipse.edc.sql.translation.SqlQueryStatement; | ||
|
||
import static java.lang.String.format; | ||
|
||
public abstract class BaseSqlDialectStatements implements FederatedCatalogCacheStatements { | ||
|
||
protected final SqlOperatorTranslator operatorTranslator; | ||
|
||
protected BaseSqlDialectStatements(SqlOperatorTranslator operatorTranslator) { | ||
this.operatorTranslator = operatorTranslator; | ||
} | ||
|
||
@Override | ||
public String getFindByIdTemplate() { | ||
return format("SELECT * FROM %s WHERE %s = ?", getFederatedCatalogTable(), getIdColumn()); | ||
} | ||
|
||
@Override | ||
public String getUpdateAsMarkedTemplate() { | ||
return format("UPDATE %s SET %s = ?", getFederatedCatalogTable(), getMarkedColumn()); | ||
} | ||
|
||
@Override | ||
public String getDeleteByMarkedTemplate() { | ||
return executeStatement() | ||
.delete(getFederatedCatalogTable(), getMarkedColumn()); | ||
} | ||
|
||
@Override | ||
public String getInsertTemplate() { | ||
return executeStatement() | ||
.column(getIdColumn()) | ||
.jsonColumn(getCatalogColumn()) | ||
.column(getMarkedColumn()) | ||
.insertInto(getFederatedCatalogTable()); | ||
} | ||
|
||
@Override | ||
public String getUpdateTemplate() { | ||
return executeStatement() | ||
.jsonColumn(getCatalogColumn()) | ||
.column(getMarkedColumn()) | ||
.update(getFederatedCatalogTable(), getIdColumn()); | ||
} | ||
|
||
@Override | ||
public SqlQueryStatement createQuery(QuerySpec querySpec) { | ||
var select = getSelectStatement(); | ||
return new SqlQueryStatement(select, querySpec, new FederatedCatalogMapping(this), operatorTranslator); | ||
} | ||
|
||
@Override | ||
public String getSelectStatement() { | ||
return format("SELECT * FROM %s", getFederatedCatalogTable()); | ||
} | ||
} |
Oops, something went wrong.