-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add SQL implementation for the DidResourceStore
- Loading branch information
1 parent
e462929
commit 0309010
Showing
9 changed files
with
295 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
-- | ||
-- Copyright (c) 2023 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 did_resources | ||
( | ||
did VARCHAR NOT NULL, | ||
create_timestamp BIGINT NOT NULL, | ||
state_timestamp BIGINT NOT NULL, | ||
state INT NOT NULL, | ||
did_document JSON NOT NULL, | ||
PRIMARY KEY (did) | ||
); |
57 changes: 56 additions & 1 deletion
57
...sql/src/main/java/org/eclipse/edc/identityhub/did/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 |
---|---|---|
@@ -1,2 +1,57 @@ | ||
package org.eclipse.edc.identityhub.did.store.sql;public class BaseDidResourceStatements { | ||
/* | ||
* Copyright (c) 2023 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.identityhub.did.store.sql; | ||
|
||
import static java.lang.String.format; | ||
|
||
public class BaseSqlDialectStatements implements DidResourceStatements { | ||
@Override | ||
public String getInsertTemplate() { | ||
return executeStatement() | ||
.column(getIdColumn()) | ||
.column(getStateColumn()) | ||
.column(getCreateTimestampColumn()) | ||
.column(getStateTimestampColumn()) | ||
.jsonColumn(getDidDocumentColumn()) | ||
.insertInto(getDidResourceTableName()); | ||
} | ||
|
||
@Override | ||
public String getUpdateTemplate() { | ||
return executeStatement() | ||
.column(getIdColumn()) | ||
.column(getStateColumn()) | ||
.column(getCreateTimestampColumn()) | ||
.column(getStateTimestampColumn()) | ||
.jsonColumn(getDidDocumentColumn()) | ||
.update(getDidResourceTableName(), getIdColumn()); | ||
} | ||
|
||
@Override | ||
public String getDeleteByIdTemplate() { | ||
return executeStatement().delete(getDidResourceTableName(), getIdColumn()); | ||
} | ||
|
||
@Override | ||
public String getFindByIdTemplate() { | ||
return format("SELECT * FROM %s WHERE %s = ?", getDidResourceTableName(), getIdColumn()); | ||
|
||
} | ||
|
||
@Override | ||
public String selectAllTemplate() { | ||
return format("SELECT * FROM %s".formatted(getDidResourceTableName())); | ||
} | ||
} |
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,57 @@ | ||
/* | ||
* Copyright (c) 2023 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.identityhub.did.store.sql; | ||
|
||
import org.eclipse.edc.sql.statement.SqlStatements; | ||
|
||
/** | ||
* The DidResourceStatements interface defines the SQL statements required to interact with the `did_resources` table. | ||
* It extends the SqlStatements interface. | ||
*/ | ||
public interface DidResourceStatements extends SqlStatements { | ||
default String getDidResourceTableName() { | ||
return "did_resources"; | ||
} | ||
|
||
default String getIdColumn() { | ||
return "did"; | ||
} | ||
|
||
default String getStateColumn() { | ||
return "state"; | ||
} | ||
|
||
default String getStateTimestampColumn() { | ||
return "state_timestamp"; | ||
} | ||
|
||
default String getCreateTimestampColumn() { | ||
return "create_timestamp"; | ||
} | ||
|
||
default String getDidDocumentColumn() { | ||
return "did_document"; | ||
} | ||
|
||
String getInsertTemplate(); | ||
|
||
String getUpdateTemplate(); | ||
|
||
String getDeleteByIdTemplate(); | ||
|
||
String getFindByIdTemplate(); | ||
|
||
String selectAllTemplate(); | ||
} |
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,24 @@ | ||
/* | ||
* Copyright (c) 2023 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.identityhub.did.store.sql; | ||
|
||
import org.eclipse.edc.sql.dialect.PostgresDialect; | ||
|
||
public class PostgresStatementsImpl extends BaseSqlDialectStatements { | ||
@Override | ||
public String getFormatAsJsonOperator() { | ||
return PostgresDialect.getJsonCastOperator(); | ||
} | ||
} |
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
Oops, something went wrong.