• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mybatis / ibatis-2 / 736

29 Dec 2025 12:23AM UTC coverage: 65.571% (-0.03%) from 65.597%
736

push

github

web-flow
Merge pull request #339 from hazendaz/master

Key set cleanup to use size directly increasing speed for same result

1598 of 2797 branches covered (57.13%)

4 of 4 new or added lines in 1 file covered. (100.0%)

149 existing lines in 7 files now uncovered.

5047 of 7697 relevant lines covered (65.57%)

0.66 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

66.34
/src/main/java/com/ibatis/sqlmap/engine/mapping/statement/PaginatedDataList.java
1
/*
2
 * Copyright 2004-2025 the original author or authors.
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *    https://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
package com.ibatis.sqlmap.engine.mapping.statement;
17

18
import com.ibatis.common.util.PaginatedList;
19
import com.ibatis.sqlmap.client.SqlMapExecutor;
20

21
import java.sql.SQLException;
22
import java.util.ArrayList;
23
import java.util.Collection;
24
import java.util.Iterator;
25
import java.util.List;
26
import java.util.ListIterator;
27

28
/**
29
 * The Class PaginatedDataList.
30
 *
31
 * @deprecated All paginated list features have been deprecated
32
 */
33
@Deprecated
34
public class PaginatedDataList implements PaginatedList {
35

36
  /** The sql map executor. */
37
  private SqlMapExecutor sqlMapExecutor;
38

39
  /** The statement name. */
40
  private String statementName;
41

42
  /** The parameter object. */
43
  private Object parameterObject;
44

45
  /** The page size. */
46
  private int pageSize;
47

48
  /** The index. */
49
  private int index;
50

51
  /** The prev page list. */
52
  private List prevPageList;
53

54
  /** The current page list. */
55
  private List currentPageList;
56

57
  /** The next page list. */
58
  private List nextPageList;
59

60
  /**
61
   * Instantiates a new paginated data list.
62
   *
63
   * @param sqlMapExecutor
64
   *          the sql map executor
65
   * @param statementName
66
   *          the statement name
67
   * @param parameterObject
68
   *          the parameter object
69
   * @param pageSize
70
   *          the page size
71
   *
72
   * @throws SQLException
73
   *           the SQL exception
74
   */
75
  public PaginatedDataList(SqlMapExecutor sqlMapExecutor, String statementName, Object parameterObject, int pageSize)
76
      throws SQLException {
1✔
77
    this.sqlMapExecutor = sqlMapExecutor;
1✔
78
    this.statementName = statementName;
1✔
79
    this.parameterObject = parameterObject;
1✔
80
    this.pageSize = pageSize;
1✔
81
    this.index = 0;
1✔
82
    pageTo(0);
1✔
83
  }
1✔
84

85
  /**
86
   * Page forward.
87
   */
88
  private void pageForward() {
89
    try {
90
      prevPageList = currentPageList;
1✔
91
      currentPageList = nextPageList;
1✔
92
      nextPageList = getList(index + 1, pageSize);
1✔
93
    } catch (SQLException e) {
×
94
      throw new RuntimeException("Unexpected error while repaginating paged list.  Cause: " + e, e);
×
95
    }
1✔
96
  }
1✔
97

98
  /**
99
   * Page back.
100
   */
101
  private void pageBack() {
102
    try {
103
      nextPageList = currentPageList;
1✔
104
      currentPageList = prevPageList;
1✔
105
      if (index > 0) {
1✔
106
        prevPageList = getList(index - 1, pageSize);
1✔
107
      } else {
108
        prevPageList = new ArrayList<>();
1✔
109
      }
110
    } catch (SQLException e) {
×
111
      throw new RuntimeException("Unexpected error while repaginating paged list.  Cause: " + e, e);
×
112
    }
1✔
113
  }
1✔
114

115
  /**
116
   * Safe page to.
117
   *
118
   * @param idx
119
   *          the idx
120
   */
121
  private void safePageTo(int idx) {
122
    try {
123
      pageTo(idx);
1✔
124
    } catch (SQLException e) {
×
125
      throw new RuntimeException("Unexpected error while repaginating paged list.  Cause: " + e, e);
×
126
    }
1✔
127
  }
1✔
128

129
  /**
130
   * Page to.
131
   *
132
   * @param idx
133
   *          the idx
134
   *
135
   * @throws SQLException
136
   *           the SQL exception
137
   */
138
  public void pageTo(int idx) throws SQLException {
139
    index = idx;
1✔
140

141
    List list;
142

143
    if (idx < 1) {
1✔
144
      list = getList(idx, pageSize * 2);
1✔
145
    } else {
146
      list = getList(idx - 1, pageSize * 3);
1✔
147
    }
148

149
    if (list.size() < 1) {
1✔
150
      prevPageList = new ArrayList<>(0);
1✔
151
      currentPageList = new ArrayList<>(0);
1✔
152
      nextPageList = new ArrayList<>(0);
1✔
153
    } else if (idx < 1) {
1✔
154
      prevPageList = new ArrayList<>(0);
1✔
155
      if (list.size() <= pageSize) {
1✔
156
        currentPageList = list.subList(0, list.size());
1✔
157
        nextPageList = new ArrayList<>(0);
1✔
158
      } else {
159
        currentPageList = list.subList(0, pageSize);
1✔
160
        nextPageList = list.subList(pageSize, list.size());
1✔
161
      }
162
    } else {
163
      if (list.size() <= pageSize) {
1✔
164
        prevPageList = list.subList(0, list.size());
1✔
165
        currentPageList = new ArrayList<>(0);
1✔
166
        nextPageList = new ArrayList<>(0);
1✔
167
      } else if (list.size() <= pageSize * 2) {
1✔
168
        prevPageList = list.subList(0, pageSize);
1✔
169
        currentPageList = list.subList(pageSize, list.size());
1✔
170
        nextPageList = new ArrayList<>(0);
1✔
171
      } else {
172
        prevPageList = list.subList(0, pageSize);
1✔
173
        currentPageList = list.subList(pageSize, pageSize * 2);
1✔
174
        nextPageList = list.subList(pageSize * 2, list.size());
1✔
175
      }
176
    }
177

178
  }
1✔
179

180
  /**
181
   * Gets the list.
182
   *
183
   * @param idx
184
   *          the idx
185
   * @param localPageSize
186
   *          the local page size
187
   *
188
   * @return the list
189
   *
190
   * @throws SQLException
191
   *           the SQL exception
192
   */
193
  private List getList(int idx, int localPageSize) throws SQLException {
194
    return sqlMapExecutor.queryForList(statementName, parameterObject, idx * pageSize, localPageSize);
1✔
195
  }
196

197
  @Override
198
  public boolean nextPage() {
199
    if (isNextPageAvailable()) {
1✔
200
      index++;
1✔
201
      pageForward();
1✔
202
      return true;
1✔
203
    }
204
    return false;
1✔
205
  }
206

207
  @Override
208
  public boolean previousPage() {
209
    if (isPreviousPageAvailable()) {
1✔
210
      index--;
1✔
211
      pageBack();
1✔
212
      return true;
1✔
213
    }
214
    return false;
1✔
215
  }
216

217
  @Override
218
  public void gotoPage(int pageNumber) {
219
    safePageTo(pageNumber);
1✔
220
  }
1✔
221

222
  @Override
223
  public int getPageSize() {
UNCOV
224
    return pageSize;
×
225
  }
226

227
  @Override
228
  public boolean isFirstPage() {
UNCOV
229
    return index == 0;
×
230
  }
231

232
  @Override
233
  public boolean isMiddlePage() {
UNCOV
234
    return !isFirstPage() && !isLastPage();
×
235
  }
236

237
  @Override
238
  public boolean isLastPage() {
UNCOV
239
    return nextPageList.size() < 1;
×
240
  }
241

242
  @Override
243
  public boolean isNextPageAvailable() {
244
    return nextPageList.size() > 0;
1✔
245
  }
246

247
  @Override
248
  public boolean isPreviousPageAvailable() {
249
    return prevPageList.size() > 0;
1✔
250
  }
251

252
  @Override
253
  public int size() {
254
    return currentPageList.size();
1✔
255
  }
256

257
  @Override
258
  public boolean isEmpty() {
UNCOV
259
    return currentPageList.isEmpty();
×
260
  }
261

262
  @Override
263
  public boolean contains(Object o) {
UNCOV
264
    return currentPageList.contains(o);
×
265
  }
266

267
  @Override
268
  public Iterator iterator() {
UNCOV
269
    return currentPageList.iterator();
×
270
  }
271

272
  @Override
273
  public Object[] toArray() {
UNCOV
274
    return currentPageList.toArray();
×
275
  }
276

277
  @Override
278
  public Object[] toArray(Object a[]) {
UNCOV
279
    return currentPageList.toArray(a);
×
280
  }
281

282
  @Override
283
  public boolean containsAll(Collection c) {
UNCOV
284
    return currentPageList.containsAll(c);
×
285
  }
286

287
  @Override
288
  public Object get(int index) {
289
    return currentPageList.get(index);
1✔
290
  }
291

292
  @Override
293
  public int indexOf(Object o) {
UNCOV
294
    return currentPageList.indexOf(o);
×
295
  }
296

297
  @Override
298
  public int lastIndexOf(Object o) {
UNCOV
299
    return currentPageList.lastIndexOf(o);
×
300
  }
301

302
  @Override
303
  public ListIterator listIterator() {
UNCOV
304
    return currentPageList.listIterator();
×
305
  }
306

307
  @Override
308
  public ListIterator listIterator(int index) {
UNCOV
309
    return currentPageList.listIterator(index);
×
310
  }
311

312
  @Override
313
  public List subList(int fromIndex, int toIndex) {
UNCOV
314
    return currentPageList.subList(fromIndex, toIndex);
×
315
  }
316

317
  @Override
318
  public boolean add(Object o) {
UNCOV
319
    return currentPageList.add(o);
×
320
  }
321

322
  @Override
323
  public boolean remove(Object o) {
UNCOV
324
    return currentPageList.remove(o);
×
325
  }
326

327
  @Override
328
  public boolean addAll(Collection c) {
UNCOV
329
    return currentPageList.addAll(c);
×
330
  }
331

332
  @Override
333
  public boolean addAll(int index, Collection c) {
UNCOV
334
    return currentPageList.addAll(index, c);
×
335
  }
336

337
  @Override
338
  public boolean removeAll(Collection c) {
UNCOV
339
    return currentPageList.removeAll(c);
×
340
  }
341

342
  @Override
343
  public boolean retainAll(Collection c) {
UNCOV
344
    return currentPageList.retainAll(c);
×
345
  }
346

347
  @Override
348
  public void clear() {
UNCOV
349
    currentPageList.clear();
×
UNCOV
350
  }
×
351

352
  @Override
353
  public Object set(int index, Object element) {
UNCOV
354
    return currentPageList.set(index, element);
×
355
  }
356

357
  @Override
358
  public void add(int index, Object element) {
UNCOV
359
    currentPageList.add(index, element);
×
UNCOV
360
  }
×
361

362
  @Override
363
  public Object remove(int index) {
UNCOV
364
    return currentPageList.remove(index);
×
365
  }
366

367
  @Override
368
  public int getPageIndex() {
UNCOV
369
    return index;
×
370
  }
371

372
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc