From 5d2264fe9bef90e3d2729d428b4bfe5f974c83de Mon Sep 17 00:00:00 2001 From: Edvard Fonsell Date: Fri, 12 Dec 2014 11:10:19 +0200 Subject: [PATCH] fixes from code review by Mikko --- .../nflow/engine/internal/dao/WorkflowDefinitionDao.java | 8 ++++---- .../src/main/resources/scripts/db/h2.create.ddl.sql | 6 ++---- .../src/main/resources/scripts/db/mysql.create.ddl.sql | 3 +-- .../main/resources/scripts/db/mysql.legacy.create.ddl.sql | 3 +-- .../main/resources/scripts/db/postgresql.create.ddl.sql | 3 +-- 5 files changed, 9 insertions(+), 14 deletions(-) diff --git a/nflow-engine/src/main/java/com/nitorcreations/nflow/engine/internal/dao/WorkflowDefinitionDao.java b/nflow-engine/src/main/java/com/nitorcreations/nflow/engine/internal/dao/WorkflowDefinitionDao.java index 8f14e891d..076b09589 100644 --- a/nflow-engine/src/main/java/com/nitorcreations/nflow/engine/internal/dao/WorkflowDefinitionDao.java +++ b/nflow-engine/src/main/java/com/nitorcreations/nflow/engine/internal/dao/WorkflowDefinitionDao.java @@ -9,7 +9,7 @@ import java.sql.SQLException; import java.util.ArrayList; import java.util.Collection; -import java.util.LinkedHashMap; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -62,7 +62,7 @@ public void storeWorkflowDefinition(WorkflowDefinition params.addValue("executor_group", executorInfo.getExecutorGroup()); String sql = "update nflow_workflow_definition " + "set definition = :definition, modified_by = :modified_by " - + "where type = :type and executor_group = :executor_group"; + + "where type = :type and executor_group = :executor_group and definition <> :definition"; int updatedRows = namedJdbc.update(sql, params); if (updatedRows == 0) { sql = "insert into nflow_workflow_definition(type, definition, modified_by, executor_group) " @@ -76,7 +76,7 @@ public void storeWorkflowDefinition(WorkflowDefinition } public List queryStoredWorkflowDefinitions(Collection types) { - String sql = "select * from nflow_workflow_definition where " + executorInfo.getExecutorGroupCondition(); + String sql = "select definition from nflow_workflow_definition where " + executorInfo.getExecutorGroupCondition(); MapSqlParameterSource params = new MapSqlParameterSource(); if (!isEmpty(types)) { sql += " and type in (:types)"; @@ -95,7 +95,7 @@ StoredWorkflowDefinition convert(WorkflowDefinition def resp.type = definition.getType(); resp.description = definition.getDescription(); resp.onError = definition.getErrorState().name(); - Map states = new LinkedHashMap<>(); + Map states = new HashMap<>(); for (WorkflowState state : definition.getStates()) { states.put(state.name(), new StoredWorkflowDefinition.State(state.name(), state.getType().name(), state.getDescription())); } diff --git a/nflow-engine/src/main/resources/scripts/db/h2.create.ddl.sql b/nflow-engine/src/main/resources/scripts/db/h2.create.ddl.sql index 58c66e64e..875a597a2 100644 --- a/nflow-engine/src/main/resources/scripts/db/h2.create.ddl.sql +++ b/nflow-engine/src/main/resources/scripts/db/h2.create.ddl.sql @@ -50,13 +50,11 @@ create table if not exists nflow_executor ( ); create table if not exists nflow_workflow_definition ( - id int not null auto_increment primary key, type varchar(64) not null, definition text not null, created timestamp not null default current_timestamp, modified timestamp not null default current_timestamp, modified_by int not null, - executor_group varchar(64) not null + executor_group varchar(64) not null, + primary key (type, executor_group) ); - -create unique index if not exists nflow_workflow_definition_uniq on nflow_workflow_definition (type, executor_group); diff --git a/nflow-engine/src/main/resources/scripts/db/mysql.create.ddl.sql b/nflow-engine/src/main/resources/scripts/db/mysql.create.ddl.sql index bcb098e62..70ddf88f6 100644 --- a/nflow-engine/src/main/resources/scripts/db/mysql.create.ddl.sql +++ b/nflow-engine/src/main/resources/scripts/db/mysql.create.ddl.sql @@ -47,12 +47,11 @@ create table if not exists nflow_executor ( ); create table if not exists nflow_workflow_definition ( - id int not null auto_increment primary key, type varchar(64) not null, definition text not null, created timestamp(3) not null default current_timestamp(3), modified timestamp(3) not null default current_timestamp(3) on update current_timestamp(3), modified_by int not null, executor_group varchar(64) not null, - constraint nflow_workflow_definition_uniq unique (type, executor_group) + primary key (type, executor_group) ); diff --git a/nflow-engine/src/main/resources/scripts/db/mysql.legacy.create.ddl.sql b/nflow-engine/src/main/resources/scripts/db/mysql.legacy.create.ddl.sql index e2fe23d0c..8f9c0fac9 100644 --- a/nflow-engine/src/main/resources/scripts/db/mysql.legacy.create.ddl.sql +++ b/nflow-engine/src/main/resources/scripts/db/mysql.legacy.create.ddl.sql @@ -52,14 +52,13 @@ create table if not exists nflow_executor ( ); create table if not exists nflow_workflow_definition ( - id int not null auto_increment primary key, type varchar(64) not null, definition text not null, modified timestamp not null default current_timestamp on update current_timestamp, modified_by int not null, created timestamp not null, executor_group varchar(64) not null, - constraint nflow_workflow_definition_uniq unique (type, executor_group) + primary key (type, executor_group) ); drop trigger if exists nflow_workflow_definition_insert; diff --git a/nflow-engine/src/main/resources/scripts/db/postgresql.create.ddl.sql b/nflow-engine/src/main/resources/scripts/db/postgresql.create.ddl.sql index 69e0bf317..c25803a68 100644 --- a/nflow-engine/src/main/resources/scripts/db/postgresql.create.ddl.sql +++ b/nflow-engine/src/main/resources/scripts/db/postgresql.create.ddl.sql @@ -60,14 +60,13 @@ create table if not exists nflow_executor ( ); create table if not exists nflow_workflow_definition ( - id serial primary key, type varchar(64) not null, definition text not null, created timestamptz not null default current_timestamp, modified timestamptz not null default current_timestamp, modified_by int not null, executor_group varchar(64) not null, - constraint nflow_workflow_definition_uniq unique (type, executor_group) + primary key (type, executor_group) ); drop trigger if exists update_nflow_definition_modified on nflow_workflow_definition;