wmedvede commented on code in PR #3441:
URL:
https://github.com/apache/incubator-kie-kogito-runtimes/pull/3441#discussion_r1525975497
##########
addons/common/persistence/jdbc/src/main/java/org/kie/kogito/persistence/jdbc/GenericRepository.java:
##########
@@ -34,32 +34,35 @@
import javax.sql.DataSource;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
public class GenericRepository extends Repository {
private static final String PAYLOAD = "payload";
private static final String VERSION = "version";
- private static final Logger LOGGER =
LoggerFactory.getLogger(GenericRepository.class);
-
private final DataSource dataSource;
public GenericRepository(DataSource dataSource) {
this.dataSource = dataSource;
}
@Override
- void insertInternal(String processId, String processVersion, UUID id,
byte[] payload) {
+ void insertInternal(String processId, String processVersion, UUID id,
byte[] payload, String businessKey) {
Review Comment:
I believe that analogous to the insertInternal, deleteInternal should
remove the associated businessKey if any.
##########
addons/common/persistence/jdbc/src/main/java/org/kie/kogito/persistence/jdbc/GenericRepository.java:
##########
@@ -140,6 +143,19 @@ Optional<Record> findByIdInternal(String processId, String
processVersion, UUID
return Optional.empty();
}
+ @Override
+ Optional<Record> findByBusinessKey(String processId, String
processVersion, String businessKey) {
+ try (Connection connection = dataSource.getConnection();
+ PreparedStatement statement =
connection.prepareStatement(FIND_BY_BUSINESS_KEY)) {
+ statement.setString(1, businessKey);
+ try (ResultSet resultSet = statement.executeQuery()) {
+ return resultSet.next() ? Optional.of(from(resultSet)) :
Optional.empty();
+ }
+ } catch (Exception e) {
+ throw uncheckedException(e, "Error finding process instance using
business key %s", businessKey);
Review Comment:
Nit pick, but maybe if we add the processId and the processVersion to the
exception it can help future error debuging/tracing etc, since we'll know all
about the failing query.
##########
addons/common/persistence/jdbc/src/main/java/org/kie/kogito/persistence/jdbc/GenericRepository.java:
##########
@@ -34,32 +34,35 @@
import javax.sql.DataSource;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
public class GenericRepository extends Repository {
private static final String PAYLOAD = "payload";
private static final String VERSION = "version";
- private static final Logger LOGGER =
LoggerFactory.getLogger(GenericRepository.class);
-
private final DataSource dataSource;
public GenericRepository(DataSource dataSource) {
this.dataSource = dataSource;
}
@Override
- void insertInternal(String processId, String processVersion, UUID id,
byte[] payload) {
+ void insertInternal(String processId, String processVersion, UUID id,
byte[] payload, String businessKey) {
try (Connection connection = dataSource.getConnection();
PreparedStatement statement =
connection.prepareStatement(INSERT)) {
- statement.setString(1, id.toString());
+ String processInstanceId = id.toString();
+ statement.setString(1, processInstanceId);
statement.setBytes(2, payload);
statement.setString(3, processId);
statement.setString(4, processVersion);
statement.setLong(5, 0L);
statement.executeUpdate();
+ if (businessKey != null) {
+ try (PreparedStatement businessKeyStmt =
connection.prepareStatement(INSERT_BUSINESS_KEY)) {
+ businessKeyStmt.setString(1, businessKey);
+ businessKeyStmt.setString(2, processInstanceId);
+ businessKeyStmt.executeUpdate();
+ }
+ }
} catch (Exception e) {
throw uncheckedException(e, "Error inserting process instance %s",
id);
Review Comment:
Simillar to the other comment, I believe it could make sense to incorporate
the processId, processVersion and businessKey in this message.
##########
addons/common/persistence/jdbc/src/main/resources/db/ansi/V10.0.0__add_business_key_ansi.sql:
##########
@@ -0,0 +1,11 @@
+CREATE TABLE business_key_mapping (
+ name VARCHAR (255) NOT NULL,
Review Comment:
I think it could make sense to name this field business_key instead, wdyt?
##########
addons/common/persistence/jdbc/src/main/resources/db/postgresql/V10.0.0__add_business_key_PostgreSQL.sql:
##########
@@ -0,0 +1,12 @@
+CREATE TABLE business_key_mapping (
+ name character (255) NOT NULL,
Review Comment:
same here?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]