1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.jumpmind.symmetric.service.impl;
23
24 import java.sql.ResultSet;
25 import java.sql.SQLException;
26 import java.util.Date;
27 import java.util.List;
28
29 import org.jumpmind.symmetric.model.BatchInfo;
30 import org.jumpmind.symmetric.model.OutgoingBatchHistory;
31 import org.jumpmind.symmetric.model.OutgoingBatch.Status;
32 import org.jumpmind.symmetric.service.IAcknowledgeService;
33 import org.jumpmind.symmetric.service.IOutgoingBatchService;
34 import org.springframework.jdbc.core.RowCallbackHandler;
35 import org.springframework.transaction.annotation.Transactional;
36
37 public class AcknowledgeService extends AbstractService implements IAcknowledgeService {
38
39 private IOutgoingBatchService outgoingBatchService;
40
41 @Deprecated
42 public void ack(final List<BatchInfo> batches) {
43 for (BatchInfo batch : batches) {
44 ack(batch);
45 }
46 }
47
48 @Transactional
49 public void ack(final BatchInfo batch) {
50 OutgoingBatchHistory history = new OutgoingBatchHistory(batch);
51 outgoingBatchService.setBatchStatus(batch.getBatchId(), batch.isOk() ? Status.OK : Status.ER);
52
53 if (!batch.isOk() && batch.getErrorLine() != 0) {
54 CallBackHandler handler = new CallBackHandler(batch.getErrorLine());
55 jdbcTemplate.query(getSql("selectDataIdSql"), new Object[] { history.getBatchId() }, handler);
56 history.setFailedDataId(handler.getDataId());
57 }
58
59 history.setEndTime(new Date());
60 outgoingBatchService.insertOutgoingBatchHistory(history);
61 }
62
63 class CallBackHandler implements RowCallbackHandler {
64 int index = 0;
65
66 long dataId = -1;
67
68 long rowNumber;
69
70 CallBackHandler(long rowNumber) {
71 this.rowNumber = rowNumber;
72 }
73
74 public void processRow(ResultSet rs) throws SQLException {
75 if (++index == rowNumber) {
76 dataId = rs.getLong(1);
77 }
78 }
79
80 public long getDataId() {
81 return dataId;
82 }
83 }
84
85 public void setOutgoingBatchService(IOutgoingBatchService outgoingBatchService) {
86 this.outgoingBatchService = outgoingBatchService;
87 }
88
89 }