1
0

调整类命名

This commit is contained in:
2025-01-03 14:56:46 +08:00
parent b82c8fe4ea
commit 57bc3fb2a8
8 changed files with 127 additions and 139 deletions

View File

@@ -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<com.lanyuanxiaoyao.flowable.core.model.FlowableNode> 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<com.lanyuanxiaoyao.flowable.core.model.FlowableNode> 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<com.lanyuanxiaoyao.flowable.core.model.FlowableInstance> 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<com.lanyuanxiaoyao.flowable.core.model.FlowableHistory> 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);
}
}

View File

@@ -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<FlowableNode> 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<FlowableNode> 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<FlowableInstance> 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<FlowableHistory> 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);
}
}

View File

@@ -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);
}
}

View File

@@ -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<String, Object>) bytesToObject(this.metadata),

View File

@@ -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;
}

View File

@@ -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<JpaFlowableHistory, String> {
List<JpaFlowableHistory> findAllByInstanceId(String instanceId);
public interface FlowableHistoryRepository extends JpaRepository<FlowableHistory, String> {
List<FlowableHistory> findAllByInstanceId(String instanceId);
}

View File

@@ -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<JpaFlowableInstance, String> {
public interface FlowableInstanceRepository extends JpaRepository<FlowableInstance, String> {
}

View File

@@ -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<JpaFlowableNode, String> {
public interface FlowableNodeRepository extends JpaRepository<FlowableNode, String> {
}