我正在将Spring Integration与Spring JPA一起使用。 我需要从5个表中读取数据并将其发送到一个处理器类以进行复杂处理。
这5个表是:UserExecution,UserExecutionDetail,Master,Inventory,Store。
我需要这些表中的每一个的点点滴滴的数据。我不想创建POJO来存储数据库数据,而是想将数据库数据存储在地图中。
然后将映射传递给处理器类以进行复杂处理。
处理器中的代码应该是什么样的?我已经在下面附上了我使用的代码。
处理器类:
public class DataProcessor {
@Transformer
public void processUserData(Message<Map<String,String>> msg) {
//Some complex logic using userDetailsMap
}
}
检索数据库数据:
class ServicetoDBAdaptor {
@Autowired
UserExecutionDetail userExecutionDetail;
@Autowired
UserExecution userExecution;
@Autowired
Master master;
@Autowired
Inventory inventory;
@Autowired
Store store;
@Autowired
UserExecutionDetailRepository userExecutionDetailRepository;
@Autowired
UserExecutionRepository userExecutionRepository;
@Transactional(propagation=Propagation.REQUIRED)
@ServiceActivator
private void readFromTable1_UserExecutionDetail(Message<UserExecutionDetail> msg) throws Exception {
userExecutionDetail = userExecutionDetailRepository.findById(msg.getPayload().getId());
}
@Transactional(propagation=Propagation.REQUIRED)
@ServiceActivator
private void readFromTable2_UserExecution(Message<UserExecutionDetail> msg) throws Exception {
userExecution = userExecutionRepository.findById(msg.getPayload().getId());
}
@Transactional(propagation=Propagation.REQUIRED)
@ServiceActivator
private void readFromTable3_Master(Message<UserExecutionDetail> msg) throws Exception {
master = userExecutionRepository.findById(msg.getPayload().getId());
}
@Transactional(propagation=Propagation.REQUIRED)
@ServiceActivator
private void readFromTable4_Inventory(Message<UserExecutionDetail> msg) throws Exception {
inventory = userExecutionRepository.findById(msg.getPayload().getId());
}
@Transactional(propagation=Propagation.REQUIRED)
@ServiceActivator
private void readFromTable5_Store(Message<UserExecutionDetail> msg) throws Exception {
store = userExecutionRepository.findById(msg.getPayload().getId());
}
Map<String,String> userDetailsMap = new HashMap<String,String>();
userDetailsMap.put("ID",msg.getPayload().getId());
userDetailsMap.put("ExecutionStatus",userExecution.getStatus());
userDetailsMap.put("ExecutionDetailStatus",userExecution.getDetailedStatus());
userDetailsMap.put("TotalOrders",master.getTotalOrders());
userDetailsMap.put("OrdersCompleted",inventory.getOrdersCompleted());
userDetailsMap.put("StoreStatus",store.getStoreStatus());
return userDetailsMap;
}
答案 0 :(得分:0)
尝试如下所示的变压器类。
@Transformer
public SomeResponse processUserData((Message<?> message) {
// use message.getPayload() and cast it to map.
//Some complex logic using userDetailsMap
}
,然后从以下流程中调用此方法。您可以将'processUserData'方法保留在相同的流类中。
.transform(this)