diff --git a/adapter/flowable-spring-boot-jpa-starter/src/main/java/com/lanyuanxiaoyao/flowable/jpa/SpringFlowableRepository.java b/adapter/flowable-spring-boot-jpa-starter/src/main/java/com/lanyuanxiaoyao/flowable/jpa/SpringFlowableRepository.java new file mode 100644 index 0000000..4406704 --- /dev/null +++ b/adapter/flowable-spring-boot-jpa-starter/src/main/java/com/lanyuanxiaoyao/flowable/jpa/SpringFlowableRepository.java @@ -0,0 +1,106 @@ +package com.lanyuanxiaoyao.flowable.jpa; + +import com.lanyuanxiaoyao.flowable.core.repository.FlowableRepository; +import com.lanyuanxiaoyao.flowable.jpa.entity.FlowableHistory; +import com.lanyuanxiaoyao.flowable.jpa.entity.FlowableInstance; +import com.lanyuanxiaoyao.flowable.jpa.entity.FlowableNode; +import com.lanyuanxiaoyao.flowable.jpa.repository.FlowableHistoryRepository; +import com.lanyuanxiaoyao.flowable.jpa.repository.FlowableInstanceRepository; +import com.lanyuanxiaoyao.flowable.jpa.repository.FlowableNodeRepository; +import java.util.List; +import java.util.stream.Collectors; +import javax.transaction.Transactional; +import org.springframework.stereotype.Service; + +/** + * @author lanyuanxiaoyao + * @version 20241231 + */ +@Service +public class SpringFlowableRepository implements FlowableRepository { + private final FlowableNodeRepository flowableNodeRepository; + private final FlowableInstanceRepository flowableInstanceRepository; + private final FlowableHistoryRepository flowableHistoryRepository; + + public SpringFlowableRepository(FlowableNodeRepository flowableNodeRepository, FlowableInstanceRepository flowableInstanceRepository, FlowableHistoryRepository flowableHistoryRepository) { + this.flowableNodeRepository = flowableNodeRepository; + this.flowableInstanceRepository = flowableInstanceRepository; + this.flowableHistoryRepository = flowableHistoryRepository; + } + + @Transactional(rollbackOn = Exception.class) + @Override + public void saveNode(com.lanyuanxiaoyao.flowable.core.model.FlowableNode node) { + flowableNodeRepository.save(new FlowableNode(node)); + } + + @Transactional(rollbackOn = Exception.class) + @Override + public void saveNode(List nodes) { + flowableNodeRepository.saveAll(nodes.stream().map(FlowableNode::new).collect(Collectors.toList())); + } + + @Override + public com.lanyuanxiaoyao.flowable.core.model.FlowableNode getNode(String nodeId) { + return flowableNodeRepository.findById(nodeId) + .map(FlowableNode::toFlowableNode) + .orElse(null); + } + + @Override + public List listNodes() { + return flowableNodeRepository.findAll() + .stream() + .map(FlowableNode::toFlowableNode) + .collect(Collectors.toList()); + } + + @Transactional(rollbackOn = Exception.class) + @Override + public void saveInstance(com.lanyuanxiaoyao.flowable.core.model.FlowableInstance instance) { + flowableInstanceRepository.save(new FlowableInstance(instance)); + } + + @Override + public com.lanyuanxiaoyao.flowable.core.model.FlowableInstance getInstance(String instantId) { + return flowableInstanceRepository.findById(instantId) + .map(FlowableInstance::toFlowableInstance) + .orElse(null); + } + + @Override + public List listInstances() { + return flowableInstanceRepository.findAll() + .stream() + .map(FlowableInstance::toFlowableInstance) + .collect(Collectors.toList()); + } + + @Transactional(rollbackOn = Exception.class) + @Override + public void saveHistory(com.lanyuanxiaoyao.flowable.core.model.FlowableHistory history) { + flowableHistoryRepository.save(new FlowableHistory(history)); + } + + @Override + public com.lanyuanxiaoyao.flowable.core.model.FlowableHistory getHistory(String historyId) { + return flowableHistoryRepository.findById(historyId) + .map(FlowableHistory::toFlowableHistory) + .orElse(null); + } + + @Override + public List listHistories(String instanceId) { + return flowableHistoryRepository.findAllByInstanceId(instanceId) + .stream() + .map(FlowableHistory::toFlowableHistory) + .collect(Collectors.toList()); + } + + @Transactional(rollbackOn = Exception.class) + @Override + public void saveInstanceAndHistory(com.lanyuanxiaoyao.flowable.core.model.FlowableInstance instance, com.lanyuanxiaoyao.flowable.core.model.FlowableHistory history) { + saveInstance(instance); + saveHistory(history); + } +} diff --git a/adapter/flowable-spring-boot-jpa-starter/src/main/java/com/lanyuanxiaoyao/flowable/jpa/SpringJpaFlowableRepository.java b/adapter/flowable-spring-boot-jpa-starter/src/main/java/com/lanyuanxiaoyao/flowable/jpa/SpringJpaFlowableRepository.java deleted file mode 100644 index 31e3f39..0000000 --- a/adapter/flowable-spring-boot-jpa-starter/src/main/java/com/lanyuanxiaoyao/flowable/jpa/SpringJpaFlowableRepository.java +++ /dev/null @@ -1,109 +0,0 @@ -package com.lanyuanxiaoyao.flowable.jpa; - -import com.lanyuanxiaoyao.flowable.core.model.FlowableHistory; -import com.lanyuanxiaoyao.flowable.core.model.FlowableInstance; -import com.lanyuanxiaoyao.flowable.core.model.FlowableNode; -import com.lanyuanxiaoyao.flowable.core.repository.FlowableRepository; -import com.lanyuanxiaoyao.flowable.jpa.entity.JpaFlowableHistory; -import com.lanyuanxiaoyao.flowable.jpa.entity.JpaFlowableInstance; -import com.lanyuanxiaoyao.flowable.jpa.entity.JpaFlowableNode; -import com.lanyuanxiaoyao.flowable.jpa.repository.JpaFlowableHistoryRepository; -import com.lanyuanxiaoyao.flowable.jpa.repository.JpaFlowableInstanceRepository; -import com.lanyuanxiaoyao.flowable.jpa.repository.JpaFlowableNodeRepository; -import java.util.List; -import java.util.stream.Collectors; -import javax.transaction.Transactional; -import org.springframework.stereotype.Service; - -/** - * @author lanyuanxiaoyao - * @version 20241231 - */ -@Service -public class SpringJpaFlowableRepository implements FlowableRepository { - private final JpaFlowableNodeRepository jpaFlowableNodeRepository; - private final JpaFlowableInstanceRepository jpaFlowableInstanceRepository; - private final JpaFlowableHistoryRepository jpaFlowableHistoryRepository; - - public SpringJpaFlowableRepository(JpaFlowableNodeRepository jpaFlowableNodeRepository, JpaFlowableInstanceRepository jpaFlowableInstanceRepository, JpaFlowableHistoryRepository jpaFlowableHistoryRepository) { - this.jpaFlowableNodeRepository = jpaFlowableNodeRepository; - this.jpaFlowableInstanceRepository = jpaFlowableInstanceRepository; - this.jpaFlowableHistoryRepository = jpaFlowableHistoryRepository; - } - - @Transactional(rollbackOn = Exception.class) - @Override - public void saveNode(FlowableNode node) { - jpaFlowableNodeRepository.save(new JpaFlowableNode(node)); - } - - @Transactional(rollbackOn = Exception.class) - @Override - public void saveNode(List nodes) { - jpaFlowableNodeRepository.saveAll(nodes.stream().map(JpaFlowableNode::new).collect(Collectors.toList())); - } - - @Override - public FlowableNode getNode(String nodeId) { - return jpaFlowableNodeRepository.findById(nodeId) - .map(JpaFlowableNode::toFlowableNode) - .orElse(null); - } - - @Override - public List listNodes() { - return jpaFlowableNodeRepository.findAll() - .stream() - .map(JpaFlowableNode::toFlowableNode) - .collect(Collectors.toList()); - } - - @Transactional(rollbackOn = Exception.class) - @Override - public void saveInstance(FlowableInstance instance) { - jpaFlowableInstanceRepository.save(new JpaFlowableInstance(instance)); - } - - @Override - public FlowableInstance getInstance(String instantId) { - return jpaFlowableInstanceRepository.findById(instantId) - .map(JpaFlowableInstance::toFlowableInstance) - .orElse(null); - } - - @Override - public List listInstances() { - return jpaFlowableInstanceRepository.findAll() - .stream() - .map(JpaFlowableInstance::toFlowableInstance) - .collect(Collectors.toList()); - } - - @Transactional(rollbackOn = Exception.class) - @Override - public void saveHistory(FlowableHistory history) { - jpaFlowableHistoryRepository.save(new JpaFlowableHistory(history)); - } - - @Override - public FlowableHistory getHistory(String historyId) { - return jpaFlowableHistoryRepository.findById(historyId) - .map(JpaFlowableHistory::toFlowableHistory) - .orElse(null); - } - - @Override - public List listHistories(String instanceId) { - return jpaFlowableHistoryRepository.findAllByInstanceId(instanceId) - .stream() - .map(JpaFlowableHistory::toFlowableHistory) - .collect(Collectors.toList()); - } - - @Transactional(rollbackOn = Exception.class) - @Override - public void saveInstanceAndHistory(FlowableInstance instance, FlowableHistory history) { - saveInstance(instance); - saveHistory(history); - } -} diff --git a/adapter/flowable-spring-boot-jpa-starter/src/main/java/com/lanyuanxiaoyao/flowable/jpa/entity/JpaFlowableHistory.java b/adapter/flowable-spring-boot-jpa-starter/src/main/java/com/lanyuanxiaoyao/flowable/jpa/entity/FlowableHistory.java similarity index 77% rename from adapter/flowable-spring-boot-jpa-starter/src/main/java/com/lanyuanxiaoyao/flowable/jpa/entity/JpaFlowableHistory.java rename to adapter/flowable-spring-boot-jpa-starter/src/main/java/com/lanyuanxiaoyao/flowable/jpa/entity/FlowableHistory.java index 452dd0a..5892a32 100644 --- a/adapter/flowable-spring-boot-jpa-starter/src/main/java/com/lanyuanxiaoyao/flowable/jpa/entity/JpaFlowableHistory.java +++ b/adapter/flowable-spring-boot-jpa-starter/src/main/java/com/lanyuanxiaoyao/flowable/jpa/entity/FlowableHistory.java @@ -1,7 +1,6 @@ package com.lanyuanxiaoyao.flowable.jpa.entity; import com.lanyuanxiaoyao.flowable.core.model.FlowableAction; -import com.lanyuanxiaoyao.flowable.core.model.FlowableHistory; import java.time.LocalDateTime; import javax.persistence.Column; import javax.persistence.Entity; @@ -9,7 +8,6 @@ import javax.persistence.EntityListeners; import javax.persistence.EnumType; import javax.persistence.Enumerated; import javax.persistence.Id; -import javax.persistence.Table; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; @@ -27,10 +25,9 @@ import org.springframework.data.jpa.domain.support.AuditingEntityListener; @Getter @Setter @Entity -@Table(name = "flowable_history") @DynamicUpdate @EntityListeners(AuditingEntityListener.class) -public class JpaFlowableHistory { +public class FlowableHistory { @Id private String historyId; @Column(nullable = false) @@ -41,14 +38,14 @@ public class JpaFlowableHistory { @CreatedDate private LocalDateTime createdTime; - public JpaFlowableHistory(FlowableHistory history) { + public FlowableHistory(com.lanyuanxiaoyao.flowable.core.model.FlowableHistory history) { this.historyId = history.getHistoryId(); this.instanceId = history.getInstanceId(); this.action = history.getAction(); this.comment = history.getComment(); } - public FlowableHistory toFlowableHistory() { - return new FlowableHistory(historyId, instanceId, action, comment, createdTime); + public com.lanyuanxiaoyao.flowable.core.model.FlowableHistory toFlowableHistory() { + return new com.lanyuanxiaoyao.flowable.core.model.FlowableHistory(historyId, instanceId, action, comment, createdTime); } } diff --git a/adapter/flowable-spring-boot-jpa-starter/src/main/java/com/lanyuanxiaoyao/flowable/jpa/entity/JpaFlowableInstance.java b/adapter/flowable-spring-boot-jpa-starter/src/main/java/com/lanyuanxiaoyao/flowable/jpa/entity/FlowableInstance.java similarity index 85% rename from adapter/flowable-spring-boot-jpa-starter/src/main/java/com/lanyuanxiaoyao/flowable/jpa/entity/JpaFlowableInstance.java rename to adapter/flowable-spring-boot-jpa-starter/src/main/java/com/lanyuanxiaoyao/flowable/jpa/entity/FlowableInstance.java index a56fe7e..8b07e76 100644 --- a/adapter/flowable-spring-boot-jpa-starter/src/main/java/com/lanyuanxiaoyao/flowable/jpa/entity/JpaFlowableInstance.java +++ b/adapter/flowable-spring-boot-jpa-starter/src/main/java/com/lanyuanxiaoyao/flowable/jpa/entity/FlowableInstance.java @@ -1,6 +1,5 @@ package com.lanyuanxiaoyao.flowable.jpa.entity; -import com.lanyuanxiaoyao.flowable.core.model.FlowableInstance; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -15,7 +14,6 @@ import javax.persistence.EnumType; import javax.persistence.Enumerated; import javax.persistence.Id; import javax.persistence.Lob; -import javax.persistence.Table; import lombok.Cleanup; import lombok.Getter; import lombok.NoArgsConstructor; @@ -36,10 +34,9 @@ import org.springframework.data.jpa.domain.support.AuditingEntityListener; @Getter @Setter @Entity -@Table(name = "flowable_instance") @DynamicUpdate @EntityListeners(AuditingEntityListener.class) -public class JpaFlowableInstance { +public class FlowableInstance { @Id private String instanceId; @Lob @@ -48,7 +45,7 @@ public class JpaFlowableInstance { private String currentNodeId; @Enumerated(EnumType.STRING) @Column(nullable = false) - private FlowableInstance.Status status = FlowableInstance.Status.RUNNING; + private com.lanyuanxiaoyao.flowable.core.model.FlowableInstance.Status status = com.lanyuanxiaoyao.flowable.core.model.FlowableInstance.Status.RUNNING; @CreatedDate private LocalDateTime createdTime; @@ -56,7 +53,7 @@ public class JpaFlowableInstance { private LocalDateTime updatedTime; @SneakyThrows - public JpaFlowableInstance(FlowableInstance instance) { + public FlowableInstance(com.lanyuanxiaoyao.flowable.core.model.FlowableInstance instance) { this.instanceId = instance.getInstanceId(); this.metadata = objectToBytes(instance.getMetadata()); this.currentNodeId = instance.getCurrentNodeId(); @@ -81,8 +78,8 @@ public class JpaFlowableInstance { } @SneakyThrows - public FlowableInstance toFlowableInstance() { - return new FlowableInstance( + public com.lanyuanxiaoyao.flowable.core.model.FlowableInstance toFlowableInstance() { + return new com.lanyuanxiaoyao.flowable.core.model.FlowableInstance( instanceId, currentNodeId, (Map) bytesToObject(this.metadata), diff --git a/adapter/flowable-spring-boot-jpa-starter/src/main/java/com/lanyuanxiaoyao/flowable/jpa/entity/JpaFlowableNode.java b/adapter/flowable-spring-boot-jpa-starter/src/main/java/com/lanyuanxiaoyao/flowable/jpa/entity/FlowableNode.java similarity index 81% rename from adapter/flowable-spring-boot-jpa-starter/src/main/java/com/lanyuanxiaoyao/flowable/jpa/entity/JpaFlowableNode.java rename to adapter/flowable-spring-boot-jpa-starter/src/main/java/com/lanyuanxiaoyao/flowable/jpa/entity/FlowableNode.java index 7c46d74..099dcce 100644 --- a/adapter/flowable-spring-boot-jpa-starter/src/main/java/com/lanyuanxiaoyao/flowable/jpa/entity/JpaFlowableNode.java +++ b/adapter/flowable-spring-boot-jpa-starter/src/main/java/com/lanyuanxiaoyao/flowable/jpa/entity/FlowableNode.java @@ -1,7 +1,6 @@ package com.lanyuanxiaoyao.flowable.jpa.entity; import com.lanyuanxiaoyao.flowable.core.model.FlowableAction; -import com.lanyuanxiaoyao.flowable.core.model.FlowableNode; import java.time.LocalDateTime; import java.util.Map; import javax.persistence.CollectionTable; @@ -15,7 +14,6 @@ import javax.persistence.Enumerated; import javax.persistence.ForeignKey; import javax.persistence.Id; import javax.persistence.MapKeyColumn; -import javax.persistence.Table; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; @@ -34,10 +32,9 @@ import org.springframework.data.jpa.domain.support.AuditingEntityListener; @Getter @Setter @Entity -@Table(name = "flowable_node") @DynamicUpdate @EntityListeners(AuditingEntityListener.class) -public class JpaFlowableNode { +public class FlowableNode { @Id private String nodeId; @Column(nullable = false) @@ -46,7 +43,7 @@ public class JpaFlowableNode { @Enumerated(EnumType.STRING) @Column(nullable = false) - private FlowableNode.Type type; + private com.lanyuanxiaoyao.flowable.core.model.FlowableNode.Type type; private String handler; @ElementCollection(fetch = javax.persistence.FetchType.EAGER) @MapKeyColumn(name = "action") @@ -59,7 +56,7 @@ public class JpaFlowableNode { @LastModifiedDate private LocalDateTime updateTime; - public JpaFlowableNode(FlowableNode node) { + public FlowableNode(com.lanyuanxiaoyao.flowable.core.model.FlowableNode node) { this.nodeId = node.getNodeId(); this.name = node.getName(); this.description = node.getDescription(); @@ -68,8 +65,8 @@ public class JpaFlowableNode { this.targets = node.getTargets(); } - public FlowableNode toFlowableNode() { - FlowableNode node = new FlowableNode(nodeId, name, description, type, handler, targets, null, createdTime); + public com.lanyuanxiaoyao.flowable.core.model.FlowableNode toFlowableNode() { + com.lanyuanxiaoyao.flowable.core.model.FlowableNode node = new com.lanyuanxiaoyao.flowable.core.model.FlowableNode(nodeId, name, description, type, handler, targets, null, createdTime); node.setUpdatedTime(updateTime); return node; } diff --git a/adapter/flowable-spring-boot-jpa-starter/src/main/java/com/lanyuanxiaoyao/flowable/jpa/repository/JpaFlowableHistoryRepository.java b/adapter/flowable-spring-boot-jpa-starter/src/main/java/com/lanyuanxiaoyao/flowable/jpa/repository/FlowableHistoryRepository.java similarity index 52% rename from adapter/flowable-spring-boot-jpa-starter/src/main/java/com/lanyuanxiaoyao/flowable/jpa/repository/JpaFlowableHistoryRepository.java rename to adapter/flowable-spring-boot-jpa-starter/src/main/java/com/lanyuanxiaoyao/flowable/jpa/repository/FlowableHistoryRepository.java index 408cac3..00f98bc 100644 --- a/adapter/flowable-spring-boot-jpa-starter/src/main/java/com/lanyuanxiaoyao/flowable/jpa/repository/JpaFlowableHistoryRepository.java +++ b/adapter/flowable-spring-boot-jpa-starter/src/main/java/com/lanyuanxiaoyao/flowable/jpa/repository/FlowableHistoryRepository.java @@ -1,6 +1,6 @@ package com.lanyuanxiaoyao.flowable.jpa.repository; -import com.lanyuanxiaoyao.flowable.jpa.entity.JpaFlowableHistory; +import com.lanyuanxiaoyao.flowable.jpa.entity.FlowableHistory; import java.util.List; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; @@ -10,6 +10,6 @@ import org.springframework.stereotype.Repository; * @version 20250102 */ @Repository -public interface JpaFlowableHistoryRepository extends JpaRepository { - List findAllByInstanceId(String instanceId); +public interface FlowableHistoryRepository extends JpaRepository { + List findAllByInstanceId(String instanceId); } diff --git a/adapter/flowable-spring-boot-jpa-starter/src/main/java/com/lanyuanxiaoyao/flowable/jpa/repository/JpaFlowableInstanceRepository.java b/adapter/flowable-spring-boot-jpa-starter/src/main/java/com/lanyuanxiaoyao/flowable/jpa/repository/FlowableInstanceRepository.java similarity index 58% rename from adapter/flowable-spring-boot-jpa-starter/src/main/java/com/lanyuanxiaoyao/flowable/jpa/repository/JpaFlowableInstanceRepository.java rename to adapter/flowable-spring-boot-jpa-starter/src/main/java/com/lanyuanxiaoyao/flowable/jpa/repository/FlowableInstanceRepository.java index 8c39442..365f963 100644 --- a/adapter/flowable-spring-boot-jpa-starter/src/main/java/com/lanyuanxiaoyao/flowable/jpa/repository/JpaFlowableInstanceRepository.java +++ b/adapter/flowable-spring-boot-jpa-starter/src/main/java/com/lanyuanxiaoyao/flowable/jpa/repository/FlowableInstanceRepository.java @@ -1,6 +1,6 @@ package com.lanyuanxiaoyao.flowable.jpa.repository; -import com.lanyuanxiaoyao.flowable.jpa.entity.JpaFlowableInstance; +import com.lanyuanxiaoyao.flowable.jpa.entity.FlowableInstance; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; @@ -9,5 +9,5 @@ import org.springframework.stereotype.Repository; * @version 20250102 */ @Repository -public interface JpaFlowableInstanceRepository extends JpaRepository { +public interface FlowableInstanceRepository extends JpaRepository { } diff --git a/adapter/flowable-spring-boot-jpa-starter/src/main/java/com/lanyuanxiaoyao/flowable/jpa/repository/JpaFlowableNodeRepository.java b/adapter/flowable-spring-boot-jpa-starter/src/main/java/com/lanyuanxiaoyao/flowable/jpa/repository/FlowableNodeRepository.java similarity index 60% rename from adapter/flowable-spring-boot-jpa-starter/src/main/java/com/lanyuanxiaoyao/flowable/jpa/repository/JpaFlowableNodeRepository.java rename to adapter/flowable-spring-boot-jpa-starter/src/main/java/com/lanyuanxiaoyao/flowable/jpa/repository/FlowableNodeRepository.java index 606d759..27bed89 100644 --- a/adapter/flowable-spring-boot-jpa-starter/src/main/java/com/lanyuanxiaoyao/flowable/jpa/repository/JpaFlowableNodeRepository.java +++ b/adapter/flowable-spring-boot-jpa-starter/src/main/java/com/lanyuanxiaoyao/flowable/jpa/repository/FlowableNodeRepository.java @@ -1,6 +1,6 @@ package com.lanyuanxiaoyao.flowable.jpa.repository; -import com.lanyuanxiaoyao.flowable.jpa.entity.JpaFlowableNode; +import com.lanyuanxiaoyao.flowable.jpa.entity.FlowableNode; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; @@ -9,5 +9,5 @@ import org.springframework.stereotype.Repository; * @version 20250102 */ @Repository -public interface JpaFlowableNodeRepository extends JpaRepository { +public interface FlowableNodeRepository extends JpaRepository { }