@@ -52,9 +52,21 @@ public class RecordCountFilter extends AbstractXMLFilter {
52
52
private static final Logger LOGGER = LoggerFactory .getLogger (RecordCountFilter .class );
53
53
private static final int LOG_COUNT = 10000 ;
54
54
55
+ /**
56
+ * The default depth of records. Set to 2 as we normally count second
57
+ * level elements.
58
+ */
59
+ private static final int DEFAULT_RECORD_DEPTH = 2 ;
60
+
55
61
private final RecordCountService recordCountService ;
56
62
private final RecordCount recordCount ;
57
63
64
+ /**
65
+ * This defines the depth at which to count records. It is zero based (root
66
+ * element = 0).
67
+ */
68
+ private int recordDepth = DEFAULT_RECORD_DEPTH ;
69
+
58
70
private boolean countRead = true ;
59
71
private int depth = 0 ;
60
72
private long logCounter = 0 ;
@@ -77,7 +89,6 @@ public RecordCountFilter(final RecordCountService recordCountService,
77
89
public void startProcessing () {
78
90
try {
79
91
recordCount .setStartMs (System .currentTimeMillis ());
80
- // if (recordCount != null && recordCountService != null) {
81
92
if (countRead ) {
82
93
incrementor = () -> {
83
94
recordCount .getReadIncrementor ().increment ();
@@ -89,19 +100,6 @@ public void startProcessing() {
89
100
recordCountService .getWriteIncrementor ().increment ();
90
101
};
91
102
}
92
- // } else if (recordCount != null) {
93
- // if (countRead) {
94
- // incrementor = recordCount.getReadIncrementor();
95
- // } else {
96
- // incrementor = recordCount.getWriteIncrementor();
97
- // }
98
- // } else if (recordCountService != null) {
99
- // if (countRead) {
100
- // incrementor = recordCountService.getReadIncrementor();
101
- // } else {
102
- // incrementor = recordCountService.getWriteIncrementor();
103
- // }
104
- // }
105
103
} finally {
106
104
super .startProcessing ();
107
105
}
@@ -158,7 +156,7 @@ public void startElement(final String uri, final String localName, final String
158
156
159
157
depth ++;
160
158
161
- if (depth == 2 ) {
159
+ if (depth == recordDepth ) {
162
160
// This is a first level element.
163
161
incrementor .increment ();
164
162
@@ -203,4 +201,13 @@ public void endElement(final String uri, final String localName, final String qN
203
201
public void setCountRead (final boolean countRead ) {
204
202
this .countRead = countRead ;
205
203
}
204
+
205
+ @ PipelineProperty (
206
+ description = "The depth of XML elements to count records." ,
207
+ defaultValue = "1" ,
208
+ displayPriority = 2 )
209
+ public void setRecordDepth (final int recordDepth ) {
210
+ // Add a fudge in here to cope with legacy depth being 0 based.
211
+ this .recordDepth = recordDepth + 1 ;
212
+ }
206
213
}
0 commit comments