-
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.
feat(sql): create SqlDidResourceStore (#191)
* feat: add implementations for `DidResourceStore` * DEPENDENCIES
- Loading branch information
1 parent
7dbde58
commit eb7b540
Showing
26 changed files
with
1,191 additions
and
24 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,27 @@ | ||
/* | ||
* Copyright (c) 2023 Metaform Systems, Inc. | ||
* | ||
* 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: | ||
* Metaform Systems, Inc. - initial API and implementation | ||
* | ||
*/ | ||
|
||
plugins { | ||
`java-library` | ||
} | ||
|
||
dependencies { | ||
api(project(":spi:identity-hub-did-spi")) | ||
implementation(libs.edc.core.sql) // for the SqlStatements | ||
implementation(libs.edc.spi.transaction.datasource) | ||
|
||
testImplementation(testFixtures(project(":spi:identity-hub-did-spi"))) | ||
testImplementation(testFixtures(libs.edc.core.sql)) | ||
testImplementation(libs.edc.junit) | ||
} |
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 Metaform Systems, Inc. | ||
* | ||
* 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: | ||
* Metaform Systems, Inc. - 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) | ||
); |
67 changes: 67 additions & 0 deletions
67
...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 |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Copyright (c) 2023 Metaform Systems, Inc. | ||
* | ||
* 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: | ||
* Metaform Systems, Inc. - initial API and implementation | ||
* | ||
*/ | ||
|
||
package org.eclipse.edc.identityhub.did.store.sql; | ||
|
||
import org.eclipse.edc.identityhub.did.store.sql.schema.postgres.DidResourceMapping; | ||
import org.eclipse.edc.spi.query.QuerySpec; | ||
import org.eclipse.edc.sql.translation.SqlQueryStatement; | ||
|
||
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 SqlQueryStatement createQuery(QuerySpec querySpec) { | ||
var select = getSelectStatement(); | ||
return new SqlQueryStatement(select, querySpec, new DidResourceMapping(this)); | ||
} | ||
|
||
@Override | ||
public String getSelectStatement() { | ||
return format("SELECT * FROM %s", getDidResourceTableName()); | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
...re-sql/src/main/java/org/eclipse/edc/identityhub/did/store/sql/DidResourceStatements.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,60 @@ | ||
/* | ||
* Copyright (c) 2023 Metaform Systems, Inc. | ||
* | ||
* 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: | ||
* Metaform Systems, Inc. - initial API and implementation | ||
* | ||
*/ | ||
|
||
package org.eclipse.edc.identityhub.did.store.sql; | ||
|
||
import org.eclipse.edc.spi.query.QuerySpec; | ||
import org.eclipse.edc.sql.statement.SqlStatements; | ||
import org.eclipse.edc.sql.translation.SqlQueryStatement; | ||
|
||
/** | ||
* Defines SQL-statements and column names for use with a SQL-based {@link org.eclipse.edc.identithub.did.spi.store.DidResourceStore} | ||
*/ | ||
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(); | ||
|
||
SqlQueryStatement createQuery(QuerySpec query); | ||
|
||
String getSelectStatement(); | ||
} |
Oops, something went wrong.