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

mybatis / ibatis-2 / 730

28 Dec 2025 10:16PM UTC coverage: 65.615% (+0.5%) from 65.146%
730

push

github

web-flow
Update README.md

1602 of 2802 branches covered (57.17%)

5053 of 7701 relevant lines covered (65.61%)

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 {
154
      if (idx < 1) {
1✔
155
        prevPageList = new ArrayList<>(0);
1✔
156
        if (list.size() <= pageSize) {
1✔
157
          currentPageList = list.subList(0, list.size());
1✔
158
          nextPageList = new ArrayList<>(0);
1✔
159
        } else {
160
          currentPageList = list.subList(0, pageSize);
1✔
161
          nextPageList = list.subList(pageSize, list.size());
1✔
162
        }
163
      } else {
164
        if (list.size() <= pageSize) {
1✔
165
          prevPageList = list.subList(0, list.size());
1✔
166
          currentPageList = new ArrayList<>(0);
1✔
167
          nextPageList = new ArrayList<>(0);
1✔
168
        } else if (list.size() <= pageSize * 2) {
1✔
169
          prevPageList = list.subList(0, pageSize);
1✔
170
          currentPageList = list.subList(pageSize, list.size());
1✔
171
          nextPageList = new ArrayList<>(0);
1✔
172
        } else {
173
          prevPageList = list.subList(0, pageSize);
1✔
174
          currentPageList = list.subList(pageSize, pageSize * 2);
1✔
175
          nextPageList = list.subList(pageSize * 2, list.size());
1✔
176
        }
177
      }
178
    }
179

180
  }
1✔
181

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

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

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

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

224
  @Override
225
  public int getPageSize() {
226
    return pageSize;
×
227
  }
228

229
  @Override
230
  public boolean isFirstPage() {
231
    return index == 0;
×
232
  }
233

234
  @Override
235
  public boolean isMiddlePage() {
236
    return !isFirstPage() && !isLastPage();
×
237
  }
238

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

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

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

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

259
  @Override
260
  public boolean isEmpty() {
261
    return currentPageList.isEmpty();
×
262
  }
263

264
  @Override
265
  public boolean contains(Object o) {
266
    return currentPageList.contains(o);
×
267
  }
268

269
  @Override
270
  public Iterator iterator() {
271
    return currentPageList.iterator();
×
272
  }
273

274
  @Override
275
  public Object[] toArray() {
276
    return currentPageList.toArray();
×
277
  }
278

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

284
  @Override
285
  public boolean containsAll(Collection c) {
286
    return currentPageList.containsAll(c);
×
287
  }
288

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

294
  @Override
295
  public int indexOf(Object o) {
296
    return currentPageList.indexOf(o);
×
297
  }
298

299
  @Override
300
  public int lastIndexOf(Object o) {
301
    return currentPageList.lastIndexOf(o);
×
302
  }
303

304
  @Override
305
  public ListIterator listIterator() {
306
    return currentPageList.listIterator();
×
307
  }
308

309
  @Override
310
  public ListIterator listIterator(int index) {
311
    return currentPageList.listIterator(index);
×
312
  }
313

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

319
  @Override
320
  public boolean add(Object o) {
321
    return currentPageList.add(o);
×
322
  }
323

324
  @Override
325
  public boolean remove(Object o) {
326
    return currentPageList.remove(o);
×
327
  }
328

329
  @Override
330
  public boolean addAll(Collection c) {
331
    return currentPageList.addAll(c);
×
332
  }
333

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

339
  @Override
340
  public boolean removeAll(Collection c) {
341
    return currentPageList.removeAll(c);
×
342
  }
343

344
  @Override
345
  public boolean retainAll(Collection c) {
346
    return currentPageList.retainAll(c);
×
347
  }
348

349
  @Override
350
  public void clear() {
351
    currentPageList.clear();
×
352
  }
×
353

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

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

364
  @Override
365
  public Object remove(int index) {
366
    return currentPageList.remove(index);
×
367
  }
368

369
  @Override
370
  public int getPageIndex() {
371
    return index;
×
372
  }
373

374
}
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