Skip to content

Commit

Permalink
[Fix apache#3480] Changing jsonb to varchar (apache#3484)
Browse files Browse the repository at this point in the history
* [Fix apache#3469 Fix apache#3480] Changing jsonb to varchar

* [Fix apache#3480]  Change blob to varbinary for ansi
  • Loading branch information
fjtirado authored and rgdoliveira committed May 7, 2024
1 parent 92c33c5 commit 0ac6c2e
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 29 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
@@ -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,
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);
}
}

0 comments on commit 0ac6c2e

Please sign in to comment.