From e1793e2761de0726c94b6c864eda17018fe13e20 Mon Sep 17 00:00:00 2001 From: Francisco Javier Tirado Sarti Date: Wed, 7 Feb 2024 12:41:00 +0100 Subject: [PATCH] Removing oracle enum and script --- .../kogito/persistence/jdbc/DatabaseType.java | 67 ------------------- ...java => PostgreSQLCorrelationService.java} | 18 +---- .../V1.35.0__create_runtimes_Oracle.sql | 10 --- .../correlation/JDBCCorrelationServiceIT.java | 6 +- .../JDBCorrelationServiceProducer.java | 23 +++---- ...dOnPersistenceJDBCConfigSourceFactory.java | 3 - 6 files changed, 13 insertions(+), 114 deletions(-) delete mode 100644 addons/common/persistence/jdbc/src/main/java/org/kie/kogito/persistence/jdbc/DatabaseType.java rename addons/common/persistence/jdbc/src/main/java/org/kie/kogito/persistence/jdbc/correlation/{JDBCCorrelationService.java => PostgreSQLCorrelationService.java} (74%) delete mode 100644 addons/common/persistence/jdbc/src/main/resources/db/oracle/V1.35.0__create_runtimes_Oracle.sql diff --git a/addons/common/persistence/jdbc/src/main/java/org/kie/kogito/persistence/jdbc/DatabaseType.java b/addons/common/persistence/jdbc/src/main/java/org/kie/kogito/persistence/jdbc/DatabaseType.java deleted file mode 100644 index 8b33a481d36..00000000000 --- a/addons/common/persistence/jdbc/src/main/java/org/kie/kogito/persistence/jdbc/DatabaseType.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.kie.kogito.persistence.jdbc; - -import java.sql.Connection; -import java.sql.DatabaseMetaData; -import java.sql.SQLException; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public enum DatabaseType { - ANSI("ansi", "process_instances"), - ORACLE("Oracle", "PROCESS_INSTANCES"), - POSTGRES("PostgreSQL", "process_instances"); - - private static final Logger LOGGER = LoggerFactory.getLogger(DatabaseType.class); - private final String dbIdentifier; - private final String tableNamePattern; - - DatabaseType(final String dbIdentifier, final String tableNamePattern) { - this.dbIdentifier = dbIdentifier; - this.tableNamePattern = tableNamePattern; - } - - public String getDbIdentifier() { - return this.dbIdentifier; - } - - public String getTableNamePattern() { - return tableNamePattern; - } - - public static DatabaseType create(final String dbIdentifier) { - if (ORACLE.getDbIdentifier().equals(dbIdentifier)) { - return ORACLE; - } else if (POSTGRES.getDbIdentifier().equals(dbIdentifier)) { - return POSTGRES; - } else { - var msg = String.format("Unrecognized DB (%s), defaulting to ansi", dbIdentifier); - LOGGER.warn(msg); - return ANSI; - } - } - - public static DatabaseType getDataBaseType(Connection connection) throws SQLException { - final DatabaseMetaData metaData = connection.getMetaData(); - final String dbProductName = metaData.getDatabaseProductName(); - return DatabaseType.create(dbProductName); - } -} diff --git a/addons/common/persistence/jdbc/src/main/java/org/kie/kogito/persistence/jdbc/correlation/JDBCCorrelationService.java b/addons/common/persistence/jdbc/src/main/java/org/kie/kogito/persistence/jdbc/correlation/PostgreSQLCorrelationService.java similarity index 74% rename from addons/common/persistence/jdbc/src/main/java/org/kie/kogito/persistence/jdbc/correlation/JDBCCorrelationService.java rename to addons/common/persistence/jdbc/src/main/java/org/kie/kogito/persistence/jdbc/correlation/PostgreSQLCorrelationService.java index e43fc81c5db..d4eba667200 100644 --- a/addons/common/persistence/jdbc/src/main/java/org/kie/kogito/persistence/jdbc/correlation/JDBCCorrelationService.java +++ b/addons/common/persistence/jdbc/src/main/java/org/kie/kogito/persistence/jdbc/correlation/PostgreSQLCorrelationService.java @@ -18,8 +18,6 @@ */ package org.kie.kogito.persistence.jdbc.correlation; -import java.sql.Connection; -import java.sql.SQLException; import java.util.Optional; import javax.sql.DataSource; @@ -29,25 +27,13 @@ import org.kie.kogito.correlation.CorrelationInstance; import org.kie.kogito.correlation.CorrelationService; import org.kie.kogito.event.correlation.MD5CorrelationEncoder; -import org.kie.kogito.persistence.jdbc.DatabaseType; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -public class JDBCCorrelationService implements CorrelationService { - - private static final Logger LOGGER = LoggerFactory.getLogger(JDBCCorrelationService.class); +public class PostgreSQLCorrelationService implements CorrelationService { private PostgreSQLCorrelationRepository repository; private CorrelationEncoder correlationEncoder; - public JDBCCorrelationService(DataSource dataSource) { - try (Connection connection = dataSource.getConnection()) { - if (!DatabaseType.POSTGRES.equals(DatabaseType.getDataBaseType(connection))) { - throw new IllegalArgumentException("Only PostgreSQL is supported for correlation"); - } - } catch (SQLException e) { - LOGGER.error("Error getting connection for {}", dataSource); - } + public PostgreSQLCorrelationService(DataSource dataSource) { this.repository = new PostgreSQLCorrelationRepository(dataSource); this.correlationEncoder = new MD5CorrelationEncoder(); } diff --git a/addons/common/persistence/jdbc/src/main/resources/db/oracle/V1.35.0__create_runtimes_Oracle.sql b/addons/common/persistence/jdbc/src/main/resources/db/oracle/V1.35.0__create_runtimes_Oracle.sql deleted file mode 100644 index 25267ed6a6c..00000000000 --- a/addons/common/persistence/jdbc/src/main/resources/db/oracle/V1.35.0__create_runtimes_Oracle.sql +++ /dev/null @@ -1,10 +0,0 @@ -CREATE TABLE process_instances -( - id char(36) NOT NULL, - payload blob NOT NULL, - process_id varchar2(3000) NOT NULL, - version number(19), - process_version varchar2(3000), - CONSTRAINT process_instances_pkey PRIMARY KEY (id) -); -CREATE INDEX idx_process_instances_proc_id ON process_instances (process_id, id, process_version); diff --git a/addons/common/persistence/jdbc/src/test/java/org/kie/persistence/jdbc/correlation/JDBCCorrelationServiceIT.java b/addons/common/persistence/jdbc/src/test/java/org/kie/persistence/jdbc/correlation/JDBCCorrelationServiceIT.java index 62212ac0eb0..f374bf8dad1 100644 --- a/addons/common/persistence/jdbc/src/test/java/org/kie/persistence/jdbc/correlation/JDBCCorrelationServiceIT.java +++ b/addons/common/persistence/jdbc/src/test/java/org/kie/persistence/jdbc/correlation/JDBCCorrelationServiceIT.java @@ -27,7 +27,7 @@ import org.kie.kogito.correlation.CompositeCorrelation; import org.kie.kogito.correlation.CorrelationInstance; import org.kie.kogito.correlation.SimpleCorrelation; -import org.kie.kogito.persistence.jdbc.correlation.JDBCCorrelationService; +import org.kie.kogito.persistence.jdbc.correlation.PostgreSQLCorrelationService; import org.kie.kogito.testcontainers.KogitoPostgreSqlContainer; import org.postgresql.ds.PGSimpleDataSource; import org.testcontainers.containers.JdbcDatabaseContainer; @@ -42,7 +42,7 @@ public class JDBCCorrelationServiceIT { @Container private static final KogitoPostgreSqlContainer PG_CONTAINER = new KogitoPostgreSqlContainer(); private static PGSimpleDataSource dataSource; - private static JDBCCorrelationService correlationService; + private static PostgreSQLCorrelationService correlationService; @BeforeAll public static void setUp() { @@ -50,7 +50,7 @@ public static void setUp() { dataSource.setUrl(PG_CONTAINER.getJdbcUrl()); dataSource.setUser(PG_CONTAINER.getUsername()); dataSource.setPassword(PG_CONTAINER.getPassword()); - correlationService = new JDBCCorrelationService(dataSource); + correlationService = new PostgreSQLCorrelationService(dataSource); //create table // DDLRunner.init(new GenericRepository(dataSource), true); initMigration(PG_CONTAINER, "postgresql"); diff --git a/quarkus/addons/persistence/jdbc/runtime/src/main/java/org/kie/kogito/persistence/quarkus/JDBCorrelationServiceProducer.java b/quarkus/addons/persistence/jdbc/runtime/src/main/java/org/kie/kogito/persistence/quarkus/JDBCorrelationServiceProducer.java index 8bbcc59412e..46c5748fd0e 100644 --- a/quarkus/addons/persistence/jdbc/runtime/src/main/java/org/kie/kogito/persistence/quarkus/JDBCorrelationServiceProducer.java +++ b/quarkus/addons/persistence/jdbc/runtime/src/main/java/org/kie/kogito/persistence/quarkus/JDBCorrelationServiceProducer.java @@ -18,33 +18,26 @@ */ package org.kie.kogito.persistence.quarkus; -import java.sql.Connection; -import java.sql.SQLException; +import java.util.Optional; import javax.sql.DataSource; +import org.eclipse.microprofile.config.inject.ConfigProperty; import org.kie.kogito.correlation.CorrelationService; import org.kie.kogito.event.correlation.DefaultCorrelationService; -import org.kie.kogito.persistence.jdbc.DatabaseType; -import org.kie.kogito.persistence.jdbc.correlation.JDBCCorrelationService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import org.kie.kogito.persistence.jdbc.correlation.PostgreSQLCorrelationService; import jakarta.enterprise.inject.Produces; +import jakarta.inject.Inject; public class JDBCorrelationServiceProducer { - private static final Logger LOGGER = LoggerFactory.getLogger(JDBCorrelationServiceProducer.class); + @Inject + @ConfigProperty(name = "quarkus.datasource.db-kind") + Optional dbKind; @Produces public CorrelationService jdbcCorrelationService(DataSource dataSource) { - try (Connection connection = dataSource.getConnection()) { - if (!DatabaseType.POSTGRES.equals(DatabaseType.getDataBaseType(connection))) { - return new DefaultCorrelationService(); - } - } catch (SQLException e) { - LOGGER.error("Error getting connection for {}", dataSource); - } - return new JDBCCorrelationService(dataSource); + return dbKind.filter("postgresql"::equals).isPresent() ? new PostgreSQLCorrelationService(dataSource) : new DefaultCorrelationService(); } } diff --git a/quarkus/addons/persistence/jdbc/runtime/src/main/java/org/kie/kogito/persistence/quarkus/KogitoAddOnPersistenceJDBCConfigSourceFactory.java b/quarkus/addons/persistence/jdbc/runtime/src/main/java/org/kie/kogito/persistence/quarkus/KogitoAddOnPersistenceJDBCConfigSourceFactory.java index 010aa970b63..61051c36b83 100644 --- a/quarkus/addons/persistence/jdbc/runtime/src/main/java/org/kie/kogito/persistence/quarkus/KogitoAddOnPersistenceJDBCConfigSourceFactory.java +++ b/quarkus/addons/persistence/jdbc/runtime/src/main/java/org/kie/kogito/persistence/quarkus/KogitoAddOnPersistenceJDBCConfigSourceFactory.java @@ -43,7 +43,6 @@ public class KogitoAddOnPersistenceJDBCConfigSourceFactory implements ConfigSour private static final String DATASOURCE_DB_KIND = "quarkus.datasource.db-kind"; private static final String LOCATION_PREFIX = "classpath:/db/"; static final String POSTGRESQL = "postgresql"; - private static final String ORACLE = "oracle"; private static final String ANSI = "ansi"; @Override @@ -77,8 +76,6 @@ public OptionalInt getPriority() { private String getDBName(final String dbKind) { if (POSTGRESQL.equals(dbKind)) { return POSTGRESQL; - } else if (ORACLE.equals(dbKind)) { - return ORACLE; } else { return ANSI; }