Skip to content

Commit

Permalink
fix: register SQL KeyPairResource store
Browse files Browse the repository at this point in the history
  • Loading branch information
paullatzelsperger committed Feb 23, 2024
1 parent 8f3d1c1 commit 5ea7d7d
Showing 1 changed file with 52 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,59 @@

package org.eclipse.edc.identityhub.store.sql.keypair;

import org.eclipse.edc.identityhub.spi.store.KeyPairResourceStore;
import org.eclipse.edc.identityhub.store.sql.keypair.schema.postgres.PostgresDialectStatements;
import org.eclipse.edc.runtime.metamodel.annotation.Extension;
import org.eclipse.edc.runtime.metamodel.annotation.Inject;
import org.eclipse.edc.runtime.metamodel.annotation.Provider;
import org.eclipse.edc.runtime.metamodel.annotation.Setting;
import org.eclipse.edc.spi.system.ServiceExtension;
import org.eclipse.edc.spi.system.ServiceExtensionContext;
import org.eclipse.edc.spi.types.TypeManager;
import org.eclipse.edc.sql.QueryExecutor;
import org.eclipse.edc.transaction.datasource.spi.DataSourceRegistry;
import org.eclipse.edc.transaction.spi.TransactionContext;

import static org.eclipse.edc.identityhub.store.sql.keypair.SqlKeyPairResourceStoreExtension.NAME;

@Extension(NAME)
public class SqlKeyPairResourceStoreExtension implements ServiceExtension {
public static final String NAME = "KeyPair Resource SQL Store Extension";

@Setting(value = "Datasource name for the KeyPairResource database", defaultValue = DataSourceRegistry.DEFAULT_DATASOURCE)
public static final String DATASOURCE_SETTING_NAME = "edc.datasource.keypair.name";

@Inject
private DataSourceRegistry dataSourceRegistry;

@Inject
private TransactionContext transactionContext;

@Inject
private TypeManager typemanager;

@Inject
private QueryExecutor queryExecutor;

@Inject(required = false)
private KeyPairResourceStoreStatements statements;

@Override
public String name() {
return NAME;
}

@Provider
public KeyPairResourceStore createSqlStore(ServiceExtensionContext context) {
return new SqlKeyPairResourceStore(dataSourceRegistry, getDataSourceName(context), transactionContext, typemanager.getMapper(),
queryExecutor, getStatementImpl());
}

private KeyPairResourceStoreStatements getStatementImpl() {
return statements != null ? statements : new PostgresDialectStatements();
}

private String getDataSourceName(ServiceExtensionContext context) {
return context.getConfig().getString(DATASOURCE_SETTING_NAME, DataSourceRegistry.DEFAULT_DATASOURCE);
}
}

0 comments on commit 5ea7d7d

Please sign in to comment.