-
Notifications
You must be signed in to change notification settings - Fork 14
/
AbstractResultSet.java
117 lines (96 loc) · 2.65 KB
/
AbstractResultSet.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
package cz.cvut.kbss.ontodriver.jena.query;
import cz.cvut.kbss.ontodriver.ResultSet;
import cz.cvut.kbss.ontodriver.Statement;
import cz.cvut.kbss.ontodriver.jena.exception.JenaDriverException;
import java.util.NoSuchElementException;
import java.util.Observer;
abstract class AbstractResultSet implements ResultSet {
private boolean open = true;
private int rowIndex = -1;
private JenaStatement statement;
void setStatement(JenaStatement statement) {
this.statement = statement;
}
void ensureOpen() {
if (!open) {
throw new IllegalStateException("This result set is closed.");
}
}
@Override
public Statement getStatement() {
ensureOpen();
assert statement != null;
return statement;
}
@Override
public boolean isFirst() {
ensureOpen();
return rowIndex == 0;
}
@Override
public void last() {
ensureOpen();
while (hasNext()) {
next();
}
}
@Override
public void first() {
throw new UnsupportedOperationException("This result set does not support returning to the first rowIndex.");
}
void ensureState() {
ensureOpen();
if (getRowIndex() < 0) {
throw new IllegalStateException("Must call next before getting any values.");
}
}
@Override
public boolean hasNext() {
// Intended for overriding
ensureOpen();
return false;
}
@Override
public void next() {
ensureOpen();
if (!hasNext()) {
throw new NoSuchElementException("No more rows found in this result set.");
}
this.rowIndex++;
}
@Override
public void previous() {
throw new UnsupportedOperationException("Moving back is not supported by this result set.");
}
@Override
public void registerObserver(Observer observer) {
throw new UnsupportedOperationException("Not supported by the current version.");
}
@Override
public void relative(int rows) {
ensureOpen();
setRowIndex(rowIndex + rows);
}
@Override
public int getRowIndex() {
return rowIndex;
}
@Override
public void setRowIndex(int newIndex) {
ensureOpen();
if (newIndex < rowIndex) {
throw new UnsupportedOperationException("Moving back is not supported by this result set.");
}
while (rowIndex < newIndex) {
next();
}
}
@Override
public void close() throws JenaDriverException {
this.open = false;
}
@Override
public boolean isOpen() {
return open;
}
}