Skip to content

Commit

Permalink
[Fix apache#3469 Fix apache#3480] Changing jsonb to varchar
Browse files Browse the repository at this point in the history
  • Loading branch information
fjtirado committed Apr 23, 2024
1 parent 2c9b5e4 commit 1c193f0
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,17 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.module.SimpleModule;

public class PostgreSQLCorrelationRepository {
public class JDBCCorrelationRepository {

static final String INSERT = "INSERT INTO correlation_instances (id, encoded_correlation_id, correlated_id, correlation) VALUES (?, ?, ?, ?::json)";
static final String INSERT = "INSERT INTO correlation_instances (id, encoded_correlation_id, correlated_id, correlation) VALUES (?, ?, ?, ?)";
static final String DELETE = "DELETE FROM correlation_instances WHERE encoded_correlation_id = ?";
private static final String FIND_BY_ENCODED_ID = "SELECT correlated_id, correlation FROM correlation_instances WHERE encoded_correlation_id = ?";
private static final String FIND_BY_CORRELATED_ID = "SELECT encoded_correlation_id, correlation FROM correlation_instances WHERE correlated_id = ?";

private DataSource dataSource;
private ObjectMapper objectMapper;

public PostgreSQLCorrelationRepository(DataSource dataSource) {
public JDBCCorrelationRepository(DataSource dataSource) {
this.dataSource = dataSource;
this.objectMapper = ObjectMapperFactory.get().copy();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@
import org.kie.kogito.correlation.CorrelationService;
import org.kie.kogito.event.correlation.MD5CorrelationEncoder;

public class PostgreSQLCorrelationService implements CorrelationService {
public class JDBCCorrelationService implements CorrelationService {

private PostgreSQLCorrelationRepository repository;
private JDBCCorrelationRepository repository;
private CorrelationEncoder correlationEncoder;

public PostgreSQLCorrelationService(DataSource dataSource) {
this.repository = new PostgreSQLCorrelationRepository(dataSource);
public JDBCCorrelationService(DataSource dataSource) {
this.repository = new JDBCCorrelationRepository(dataSource);
this.correlationEncoder = new MD5CorrelationEncoder();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CREATE TABLE correlation_instances
(
id character(36) NOT NULL,
encoded_correlation_id character varying(36) NOT NULL UNIQUE,
correlated_id character varying(36) NOT NULL,
correlation character varying NOT NULL,
version bigint,
CONSTRAINT correlation_instances_pkey PRIMARY KEY (id)
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE correlation_instances
ALTER COLUMN correlation TYPE character varying;
Original file line number Diff line number Diff line change
Expand Up @@ -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.PostgreSQLCorrelationService;
import org.kie.kogito.persistence.jdbc.correlation.JDBCCorrelationService;
import org.kie.kogito.testcontainers.KogitoPostgreSqlContainer;
import org.postgresql.ds.PGSimpleDataSource;
import org.testcontainers.containers.JdbcDatabaseContainer;
Expand All @@ -42,15 +42,15 @@ public class JDBCCorrelationServiceIT {
@Container
private static final KogitoPostgreSqlContainer PG_CONTAINER = new KogitoPostgreSqlContainer();
private static PGSimpleDataSource dataSource;
private static PostgreSQLCorrelationService correlationService;
private static JDBCCorrelationService correlationService;

@BeforeAll
public static void setUp() {
dataSource = new PGSimpleDataSource();
dataSource.setUrl(PG_CONTAINER.getJdbcUrl());
dataSource.setUser(PG_CONTAINER.getUsername());
dataSource.setPassword(PG_CONTAINER.getPassword());
correlationService = new PostgreSQLCorrelationService(dataSource);
correlationService = new JDBCCorrelationService(dataSource);
//create table
// DDLRunner.init(new GenericRepository(dataSource), true);
initMigration(PG_CONTAINER, "postgresql");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,17 @@
*/
package org.kie.kogito.persistence.quarkus;

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.correlation.PostgreSQLCorrelationService;
import org.kie.kogito.persistence.jdbc.correlation.JDBCCorrelationService;

import jakarta.enterprise.inject.Produces;
import jakarta.inject.Inject;

import static org.kie.kogito.persistence.quarkus.KogitoAddOnPersistenceJDBCConfigSourceFactory.DATASOURCE_DB_KIND;
import static org.kie.kogito.persistence.quarkus.KogitoAddOnPersistenceJDBCConfigSourceFactory.POSTGRESQL;

public class JDBCorrelationServiceProducer {

@Inject
@ConfigProperty(name = DATASOURCE_DB_KIND)
Optional<String> dbKind;

@Produces
public CorrelationService jdbcCorrelationService(DataSource dataSource) {
return dbKind.filter(POSTGRESQL::equals).isPresent() ? new PostgreSQLCorrelationService(dataSource) : new DefaultCorrelationService();
return new JDBCCorrelationService(dataSource);
}
}

0 comments on commit 1c193f0

Please sign in to comment.