This repository has been archived by the owner on Nov 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #138 from Apicurio/add-unified-storage-utilities
Add the required utilities for the unified storage
- Loading branch information
Showing
11 changed files
with
120 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ | |
* limitations under the License. | ||
*/ | ||
|
||
package io.apicurio.common.apps.config.impl.storage; | ||
package io.apicurio.common.apps.config; | ||
|
||
/** | ||
* @author [email protected] | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,7 +29,7 @@ | |
* @author [email protected] | ||
* @author Jakub Senko <em>[email protected]</em> | ||
*/ | ||
public interface BaseSqlStatements { | ||
public interface SqlStatements { | ||
|
||
/** | ||
* Gets the database type associated with these statements. | ||
|
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 |
---|---|---|
|
@@ -22,7 +22,7 @@ | |
* @author [email protected] | ||
* @author Jakub Senko <em>[email protected]</em> | ||
*/ | ||
public abstract class AbstractH2BaseSqlStatements implements BaseSqlStatements { | ||
public abstract class AbstractH2SqlStatements implements SqlStatements { | ||
|
||
@Override | ||
public boolean isPrimaryKeyViolation(SQLException error) { | ||
|
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 |
---|---|---|
|
@@ -22,7 +22,7 @@ | |
* @author [email protected] | ||
* @author Jakub Senko <em>[email protected]</em> | ||
*/ | ||
public abstract class AbstractPostgresBaseSqlStatements implements BaseSqlStatements { | ||
public abstract class AbstractPostgresSqlStatements implements SqlStatements { | ||
|
||
@Override | ||
public boolean isPrimaryKeyViolation(SQLException ex) { | ||
|
18 changes: 18 additions & 0 deletions
18
storage/src/main/java/io/apicurio/common/apps/storage/sql/DatabaseKind.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,18 @@ | ||
package io.apicurio.common.apps.storage.sql; | ||
|
||
public enum DatabaseKind { | ||
|
||
postgresql("org.postgresql.Driver"), | ||
h2("org.h2.Driver"), | ||
mssql("com.microsoft.sqlserver.jdbc.SQLServerDriver"); | ||
|
||
final String driverClassName; | ||
|
||
DatabaseKind(String driverClassName) { | ||
this.driverClassName = driverClassName; | ||
} | ||
|
||
public String getDriverClassName() { | ||
return driverClassName; | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
storage/src/main/java/io/apicurio/common/apps/storage/sql/DatasourceProducer.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 @@ | ||
package io.apicurio.common.apps.storage.sql; | ||
|
||
import io.agroal.api.AgroalDataSource; | ||
import io.agroal.api.configuration.supplier.AgroalPropertiesReader; | ||
import io.apicurio.common.apps.config.Info; | ||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.inject.Inject; | ||
import jakarta.inject.Named; | ||
import org.eclipse.microprofile.config.inject.ConfigProperty; | ||
import org.slf4j.Logger; | ||
|
||
import java.sql.SQLException; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class DatasourceProducer { | ||
|
||
@Inject | ||
Logger log; | ||
|
||
@ConfigProperty(name = "apicurio.storage.db-kind", defaultValue = "h2") | ||
@Info(category = "storage", description = "Application datasource database type", availableSince = "0.2.5.Final", registryAvailableSince = "3.0.0.Final") | ||
String databaseType; | ||
|
||
@ConfigProperty(name = "apicurio.datasource.url", defaultValue = "jdbc:h2:mem:registry_db") | ||
@Info(category = "storage", description = "Application datasource jdbc url", availableSince = "0.2.5.Final", registryAvailableSince = "3.0.0.Final") | ||
String jdbcUrl; | ||
|
||
@ConfigProperty(name = "apicurio.datasource.username", defaultValue = "sa") | ||
@Info(category = "storage", description = "Application datasource username", availableSince = "0.2.5.Final", registryAvailableSince = "3.0.0.Final") | ||
String username; | ||
|
||
@ConfigProperty(name = "apicurio.datasource.password", defaultValue = "sa") | ||
@Info(category = "storage", description = "Application datasource password", availableSince = "0.2.5.Final", registryAvailableSince = "3.0.0.Final") | ||
String password; | ||
|
||
@ConfigProperty(name = "apicurio.datasource.jdbc.initial-size", defaultValue = "20") | ||
@Info(category = "storage", description = "Application datasource pool initial size", availableSince = "0.2.5.Final", registryAvailableSince = "3.0.0.Final") | ||
String initialSize; | ||
|
||
@ConfigProperty(name = "apicurio.datasource.jdbc.min-size", defaultValue = "20") | ||
@Info(category = "storage", description = "Application datasource pool minimum size", availableSince = "0.2.5.Final", registryAvailableSince = "3.0.0.Final") | ||
String minSize; | ||
|
||
@ConfigProperty(name = "apicurio.datasource.jdbc.max-size", defaultValue = "100") | ||
@Info(category = "storage", description = "Application datasource pool maximum size", availableSince = "0.2.5.Final", registryAvailableSince = "3.0.0.Final") | ||
String maxSize; | ||
|
||
@ApplicationScoped | ||
@Named("apicurioDatasource") | ||
public AgroalDataSource produceDatasource() throws SQLException { | ||
log.debug("Creating an instance of ISqlStatements for DB: " + databaseType); | ||
|
||
final DatabaseKind databaseKind = DatabaseKind.valueOf(databaseType); | ||
|
||
Map<String, String> props = new HashMap<>(); | ||
|
||
props.put(AgroalPropertiesReader.MAX_SIZE, maxSize); | ||
props.put(AgroalPropertiesReader.MIN_SIZE, minSize); | ||
props.put(AgroalPropertiesReader.INITIAL_SIZE, initialSize); | ||
props.put(AgroalPropertiesReader.JDBC_URL, jdbcUrl); | ||
props.put(AgroalPropertiesReader.PRINCIPAL, username); | ||
props.put(AgroalPropertiesReader.CREDENTIAL, password); | ||
props.put(AgroalPropertiesReader.PROVIDER_CLASS_NAME, databaseKind.getDriverClassName()); | ||
|
||
AgroalDataSource datasource = AgroalDataSource.from(new AgroalPropertiesReader() | ||
.readProperties(props) | ||
.get()); | ||
|
||
|
||
log.info("Using {} SQL storage.", databaseType); | ||
|
||
return 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,7 @@ | |
* @author Jakub Senko <em>[email protected]</em> | ||
*/ | ||
@ApplicationScoped | ||
public class BaseSqlStorageComponent { | ||
public class SqlStorageComponent { | ||
|
||
private static final String DB_PROPERTY_VERSION = "db_version"; | ||
|
||
|
@@ -42,7 +42,7 @@ public static class Configuration { | |
|
||
private Boolean supportsAtomicSequenceIncrement; | ||
|
||
private BaseSqlStatements sqlStatements; | ||
private SqlStatements sqlStatements; | ||
|
||
private String ddlDirRootPath; | ||
|
||
|
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 |
---|---|---|
|
@@ -20,12 +20,13 @@ | |
import io.apicurio.common.apps.storage.exceptions.AlreadyExistsException; | ||
import io.apicurio.common.apps.storage.exceptions.StorageException; | ||
import io.apicurio.common.apps.storage.exceptions.StorageExceptionMapper; | ||
import io.apicurio.common.apps.storage.sql.BaseSqlStatements; | ||
import io.apicurio.common.apps.storage.sql.SqlStatements; | ||
|
||
import java.sql.Connection; | ||
import java.sql.SQLException; | ||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.inject.Inject; | ||
import jakarta.inject.Named; | ||
|
||
/** | ||
* @author [email protected] | ||
|
@@ -34,10 +35,12 @@ | |
public class HandleFactoryImpl implements HandleFactory { | ||
|
||
@Inject | ||
@Named("apicurioDatasource") | ||
AgroalDataSource dataSource; | ||
|
||
@Inject | ||
BaseSqlStatements sqlStatements; | ||
@Named("apicurioSqlStatements") | ||
SqlStatements sqlStatements; | ||
|
||
@Inject | ||
StorageExceptionMapper exceptionMapper; | ||
|