1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package com.fatwire.gst.foundation.facade.sql;
18
19 import java.util.Iterator;
20
21 import COM.FutureTense.Interfaces.IList;
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39 public class IListIterable implements Iterable<Row> {
40 private final IList list;
41
42 private final int numRows;
43
44 public IListIterable(final IList list) {
45 super();
46 this.list = list;
47 if (list != null) {
48 numRows = list.numRows();
49 } else {
50 numRows = 0;
51 }
52 }
53
54 public Iterator<Row> iterator() {
55 if (list == null || !list.hasData()) {
56 return new Iterator<Row>() {
57
58 public boolean hasNext() {
59 return false;
60 }
61
62 public Row next() {
63 return null;
64 }
65
66 public void remove() {
67 throw new RuntimeException("Can not remove");
68 }
69
70 };
71 }
72 return new Iterator<Row>() {
73 private int rowNum = 0;
74
75 public boolean hasNext() {
76 return rowNum < numRows;
77 }
78
79 public Row next() {
80 rowNum++;
81 list.moveTo(rowNum);
82 return new SingleRow(list);
83 }
84
85 public void remove() {
86 throw new RuntimeException("Can not remove");
87 }
88 };
89 }
90
91 public int size() {
92 return numRows;
93 }
94
95 public void flush() {
96 if (list != null) {
97 list.flush();
98 }
99 }
100
101 public String getColumnName(final int i) {
102 if (list != null) {
103 return list.getColumnName(i);
104 }
105 return "";
106 }
107
108 public String getIndirectColumnName(final int index) {
109 if (list != null) {
110 return list.getIndirectColumnName(index);
111 }
112 return "";
113 }
114
115 public int numColumns() {
116 if (list != null) {
117 return list.numColumns();
118 }
119 return 0;
120 }
121
122 public int numIndirectColumns() {
123 if (list != null) {
124 return list.numIndirectColumns();
125 }
126 return 0;
127 }
128
129 }