Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix #3480] Changing jsonb to varchar #3484

Merged
merged 2 commits into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
@@ -1,10 +1,10 @@
CREATE TABLE process_instances
(
id CHAR(36) NOT NULL,
payload BLOB NOT NULL,
process_id VARCHAR(4000) NOT NULL,
version BIGINT(19),
process_version VARCHAR(4000),
id character(36) NOT NULL,
payload varbinary(1000000) NOT NULL,
fjtirado marked this conversation as resolved.
Show resolved Hide resolved
process_id character varying(4000) NOT NULL,
version bigint,
process_version character varying(4000),
CONSTRAINT process_instances_pkey PRIMARY KEY (id)
);
CREATE INDEX idx_process_instances_process_id ON process_instances (process_id, id, process_version);
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(8000) 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);
}
}
Loading