-
Notifications
You must be signed in to change notification settings - Fork 245
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: separate sql stores from datasources (#4381)
- Loading branch information
Showing
27 changed files
with
331 additions
and
197 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,41 @@ | ||
# SQL persistence | ||
|
||
Every store in the EDC, intended as persistence for state, comes out of the box with two implementations: | ||
- in-memory | ||
- sql (postgresql dialect) | ||
|
||
By default, the `in-memory` stores are provided by the dependency injection, the `sql` implementations can be used by | ||
simply registering the relative extensions (e.g. `asset-index-sql`, `contract-negotiation-store-sql`, ...). | ||
|
||
## Configuration | ||
|
||
### DataSources | ||
|
||
For using `sql` extensions, a `DataSource` is needed, and it should be registered on the `DataSourceRegistry` service. | ||
|
||
The `sql-pool-apache-commons` extension takes care to create and register pooled data sources starting from configuration. | ||
It expects at least one data source called `default` that can be configured with `Vault` keys: | ||
``` | ||
edc.datasource.default.url=... | ||
edc.datasource.default.name=... | ||
edc.datasource.default.password=... | ||
``` | ||
(note: if no vault entries are found for such keys, they will be obtained from the configuration). | ||
|
||
Other datasources can be defined using the same settings structure: | ||
``` | ||
edc.datasource.<datasource-name>.url=... | ||
edc.datasource.<datasource-name>.name=... | ||
edc.datasource.<datasource-name>.password=... | ||
``` | ||
|
||
`<datasource-name>` can be a string that then can be used by the stores configuration to use specific data sources. | ||
|
||
### Using custom datasource in stores | ||
|
||
Using a custom datasource in a store can be done by configuring the setting: | ||
``` | ||
edc.sql.store.<store-context>.datasource=<datasource-name> | ||
``` | ||
|
||
This way the `<store-context>` (that could be `asset`, `contractnegotiation`...) will use the `<datasource-name>` datasource. |
56 changes: 56 additions & 0 deletions
56
...s/common/sql/sql-core/src/main/java/org/eclipse/edc/sql/configuration/DataSourceName.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,56 @@ | ||
/* | ||
* 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.sql.configuration; | ||
|
||
import org.eclipse.edc.spi.monitor.Monitor; | ||
import org.eclipse.edc.spi.system.configuration.Config; | ||
|
||
import static org.eclipse.edc.transaction.datasource.spi.DataSourceRegistry.DEFAULT_DATASOURCE; | ||
|
||
/** | ||
* This interface is only functional to the migration from the old format to the new one. | ||
* Ref. <a href="https://github.com/eclipse-edc/Connector/issues/3811">https://github.com/eclipse-edc/Connector/issues/3811</a> | ||
*/ | ||
public interface DataSourceName { | ||
|
||
/** | ||
* Extracts datasource name from configuration considering deprecated key as fallback. | ||
* | ||
* @param key the setting key. | ||
* @param deprecatedKey the deprecate setting key. | ||
* @param config the config. | ||
* @param monitor the monitor. | ||
* @return the datasource name | ||
* @deprecated will be removed together with the deprecated settings. | ||
*/ | ||
@Deprecated(since = "0.8.1") | ||
static String getDataSourceName(String key, String deprecatedKey, Config config, Monitor monitor) { | ||
var datasourceName = config.getString(key, null); | ||
|
||
if (datasourceName != null) { | ||
return datasourceName; | ||
} | ||
|
||
var name = config.getString(deprecatedKey, null); | ||
|
||
if (name != null) { | ||
monitor.warning("Datasource name setting key %s has been deprecated, please switch to %s".formatted(deprecatedKey, key)); | ||
return name; | ||
} | ||
|
||
return DEFAULT_DATASOURCE; | ||
} | ||
|
||
} |
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.