/
IncomingBatch.java
174 lines (148 loc) · 6.86 KB
/
IncomingBatch.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/**
* Licensed to JumpMind Inc under one or more contributor
* license agreements. See the NOTICE file distributed
* with this work for additional information regarding
* copyright ownership. JumpMind Inc licenses this file
* to you under the GNU General Public License, version 3.0 (GPLv3)
* (the "License"); you may not use this file except in compliance
* with the License.
*
* You should have received a copy of the GNU General Public License,
* version 3.0 (GPLv3) along with this library; if not, see
* <http://www.gnu.org/licenses/>.
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jumpmind.symmetric.model;
import java.util.Date;
import org.apache.commons.lang.StringUtils;
import org.jumpmind.symmetric.io.data.Batch;
import org.jumpmind.symmetric.io.data.reader.DataReaderStatistics;
import org.jumpmind.symmetric.io.data.writer.DataWriterStatisticConstants;
import org.jumpmind.util.Statistics;
public class IncomingBatch extends AbstractBatch {
private static final long serialVersionUID = 1L;
private long failedRowNumber;
private long failedLineNumber;
private long startTime;
private boolean retry;
public IncomingBatch() {
}
public IncomingBatch(Batch batch) {
setBatchId(batch.getBatchId());
setNodeId(batch.getSourceNodeId());
setChannelId(batch.getChannelId());
setStatus(Status.LD);
}
public void setValues(Statistics readerStatistics, Statistics writerStatistics, boolean isSuccess) {
if (readerStatistics != null) {
setByteCount(readerStatistics.get(DataReaderStatistics.READ_BYTE_COUNT));
setParsedStatistics(readerStatistics);
}
if (writerStatistics != null) {
setFilterMillis(writerStatistics.get(DataWriterStatisticConstants.FILTERMILLIS));
setLoadMillis(writerStatistics.get(DataWriterStatisticConstants.LOADMILLIS));
setLoadRowCount(writerStatistics.get(DataWriterStatisticConstants.ROWCOUNT));
setFallbackInsertCount(writerStatistics.get(DataWriterStatisticConstants.FALLBACKINSERTCOUNT));
setFallbackUpdateCount(writerStatistics.get(DataWriterStatisticConstants.FALLBACKUPDATECOUNT));
setMissingDeleteCount(writerStatistics.get(DataWriterStatisticConstants.MISSINGDELETECOUNT));
setIgnoreCount(writerStatistics.get(DataWriterStatisticConstants.IGNORECOUNT));
setIgnoreRowCount(writerStatistics.get(DataWriterStatisticConstants.IGNOREROWCOUNT));
setStartTime(writerStatistics.get(DataWriterStatisticConstants.STARTTIME));
setLastUpdatedTime(new Date());
if (!isSuccess) {
failedRowNumber = getLoadRowCount();
failedLineNumber = writerStatistics.get(DataWriterStatisticConstants.LINENUMBER);
}
setLoadInsertRowCount(writerStatistics.get(DataWriterStatisticConstants.INSERTCOUNT));
setLoadUpdateRowCount(writerStatistics.get(DataWriterStatisticConstants.UPDATECOUNT));
setLoadDeleteRowCount(writerStatistics.get(DataWriterStatisticConstants.DELETECOUNT));
}
}
public void setParsedStatistics(Statistics statistics) {
setLoadFlag(statistics.get(DataReaderStatistics.LOAD_FLAG) == 1);
setExtractCount(statistics.get(DataReaderStatistics.EXTRACT_COUNT));
setSentCount(statistics.get(DataReaderStatistics.SENT_COUNT));
setLoadCount(statistics.get(DataReaderStatistics.LOAD_COUNT));
setLoadId(statistics.get(DataReaderStatistics.LOAD_ID));
setCommonFlag(statistics.get(DataReaderStatistics.COMMON_FLAG) == 1);
setRouterMillis(statistics.get(DataReaderStatistics.ROUTER_MILLIS));
setExtractMillis(statistics.get(DataReaderStatistics.EXTRACT_MILLIS));
setTransformExtractMillis(statistics.get(DataReaderStatistics.TRANSFORM_EXTRACT_MILLIS));
setTransformLoadMillis(statistics.get(DataReaderStatistics.TRANSFORM_LOAD_MILLIS));
setReloadRowCount(statistics.get(DataReaderStatistics.RELOAD_ROW_COUNT));
setOtherRowCount(statistics.get(DataReaderStatistics.OTHER_ROW_COUNT));
setDataRowCount(statistics.get(DataReaderStatistics.DATA_ROW_COUNT));
setDataInsertRowCount(statistics.get(DataReaderStatistics.DATA_INSERT_ROW_COUNT));
setDataUpdateRowCount(statistics.get(DataReaderStatistics.DATA_UPDATE_ROW_COUNT));
setDataDeleteRowCount(statistics.get(DataReaderStatistics.DATA_DELETE_ROW_COUNT));
setExtractRowCount(statistics.get(DataReaderStatistics.EXTRACT_ROW_COUNT));
setExtractInsertRowCount(statistics.get(DataReaderStatistics.EXTRACT_INSERT_ROW_COUNT));
setExtractUpdateRowCount(statistics.get(DataReaderStatistics.EXTRACT_UPDATE_ROW_COUNT));
setExtractDeleteRowCount(statistics.get(DataReaderStatistics.EXTRACT_DELETE_ROW_COUNT));
setFailedDataId(statistics.get(DataReaderStatistics.FAILED_DATA_ID));
}
public void setNodeBatchId(String value) {
if (value != null) {
int splitIndex = value.indexOf("-");
if (splitIndex > 0) {
setNodeId(value.substring(0, splitIndex));
setBatchId(Long.parseLong(value.substring(splitIndex + 1)));
}
}
}
public boolean isRetry() {
return retry;
}
public void setRetry(boolean isRetry) {
this.retry = isRetry;
}
public long getFailedRowNumber() {
return failedRowNumber;
}
public void setFailedRowNumber(long failedRowNumber) {
this.failedRowNumber = failedRowNumber;
}
public long getStartTime() {
return startTime;
}
public void setStartTime(long startTime) {
this.startTime = startTime;
}
/**
* An indicator to the incoming batch service as to whether this batch
* should be saved off.
*
* @return
*/
public boolean isPersistable() {
return getBatchId() >= 0;
}
public void setFailedLineNumber(long failedLineNumber) {
this.failedLineNumber = failedLineNumber;
}
public long getFailedLineNumber() {
return failedLineNumber;
}
@Override
public String toString() {
return Long.toString(getBatchId());
}
@Override
public boolean equals(Object o) {
if (o == null || !(o instanceof IncomingBatch)) {
return false;
}
IncomingBatch b = (IncomingBatch) o;
return getBatchId() == b.getBatchId() && StringUtils.equals(getNodeId(), b.getNodeId());
}
@Override
public int hashCode() {
return (String.valueOf(getBatchId()) + "-" + getNodeId()).hashCode();
}
}