svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.file / org.gvsig.fmap.dal.file.dbf / src / main / java / org / gvsig / fmap / dal / store / dbf / DBFSetProvider.java @ 40435
History | View | Annotate | Download (3.37 KB)
1 |
/**
|
---|---|
2 |
*
|
3 |
*/
|
4 |
package org.gvsig.fmap.dal.store.dbf; |
5 |
|
6 |
import java.util.NoSuchElementException; |
7 |
|
8 |
import org.gvsig.fmap.dal.exception.DataException; |
9 |
import org.gvsig.fmap.dal.exception.ReadRuntimeException; |
10 |
import org.gvsig.fmap.dal.feature.FeatureQuery; |
11 |
import org.gvsig.fmap.dal.feature.FeatureType; |
12 |
import org.gvsig.fmap.dal.feature.spi.AbstractFeatureProviderIterator; |
13 |
import org.gvsig.fmap.dal.feature.spi.AbstractFeatureSetProvider; |
14 |
import org.gvsig.fmap.dal.feature.spi.FeatureProvider; |
15 |
import org.gvsig.tools.exception.BaseException; |
16 |
|
17 |
/**
|
18 |
* @author jjdelcerro
|
19 |
*
|
20 |
*/
|
21 |
public class DBFSetProvider extends AbstractFeatureSetProvider { |
22 |
|
23 |
public DBFSetProvider(DBFStoreProvider store, FeatureQuery query,
|
24 |
FeatureType featureType) |
25 |
throws DataException {
|
26 |
super(store, query, featureType);
|
27 |
} |
28 |
|
29 |
public boolean canFilter() { |
30 |
return false; |
31 |
} |
32 |
|
33 |
public boolean canIterateFromIndex() { |
34 |
return true; |
35 |
} |
36 |
|
37 |
public boolean canOrder() { |
38 |
return false; |
39 |
} |
40 |
|
41 |
public long getSize() throws DataException { |
42 |
return getStore().getFeatureCount();
|
43 |
} |
44 |
|
45 |
public boolean isEmpty() throws DataException { |
46 |
return getSize() == 0; |
47 |
} |
48 |
|
49 |
@Override
|
50 |
protected void doDispose() throws BaseException { |
51 |
} |
52 |
|
53 |
protected AbstractFeatureProviderIterator createIterator(long index) |
54 |
throws DataException {
|
55 |
return new DBFIterator((DBFStoreProvider) getStore(), getFeatureType(), |
56 |
index); |
57 |
} |
58 |
|
59 |
protected AbstractFeatureProviderIterator createFastIterator(long index) |
60 |
throws DataException {
|
61 |
return new FastDBFIterator((DBFStoreProvider) getStore(), |
62 |
getFeatureType(), index); |
63 |
} |
64 |
|
65 |
protected class DBFIterator extends AbstractFeatureProviderIterator { |
66 |
protected long index; |
67 |
protected FeatureType type;
|
68 |
protected long count; |
69 |
|
70 |
public DBFIterator(DBFStoreProvider store, FeatureType type,
|
71 |
long startOn) throws DataException { |
72 |
super(store);
|
73 |
this.index = startOn;
|
74 |
this.type = type;
|
75 |
this.count = store.getFeatureCount();
|
76 |
} |
77 |
|
78 |
protected boolean internalHasNext() { |
79 |
return this.count > index; |
80 |
} |
81 |
|
82 |
protected Object internalNext() { |
83 |
if (index >= this.count) { |
84 |
throw new NoSuchElementException(); |
85 |
} |
86 |
try {
|
87 |
|
88 |
FeatureProvider ret = |
89 |
getDBFStoreProvider().getFeatureProviderByIndex(index, |
90 |
this.type);
|
91 |
index++; |
92 |
return ret;
|
93 |
} catch (DataException e) {
|
94 |
throw new ReadRuntimeException(getDBFStoreProvider().getProviderName(), |
95 |
e); |
96 |
} |
97 |
} |
98 |
|
99 |
public void remove() { |
100 |
throw new UnsupportedOperationException(); |
101 |
} |
102 |
|
103 |
protected void internalDispose() { |
104 |
type = null;
|
105 |
} |
106 |
|
107 |
protected DBFStoreProvider getDBFStoreProvider() {
|
108 |
return (DBFStoreProvider) getFeatureStoreProvider();
|
109 |
} |
110 |
|
111 |
@Override
|
112 |
protected void doDispose() throws BaseException { |
113 |
// Nothing to do
|
114 |
} |
115 |
} |
116 |
|
117 |
protected class FastDBFIterator extends DBFIterator { |
118 |
protected FeatureProvider data;
|
119 |
|
120 |
public FastDBFIterator(DBFStoreProvider store, FeatureType type,
|
121 |
long startOn) throws DataException { |
122 |
super(store, type, startOn);
|
123 |
this.data = getFeatureStoreProvider().createFeatureProvider(type);
|
124 |
} |
125 |
|
126 |
protected Object internalNext() { |
127 |
if (index >= this.count) { |
128 |
throw new NoSuchElementException(); |
129 |
} |
130 |
|
131 |
try {
|
132 |
getDBFStoreProvider().initFeatureProviderByIndex(this.data,
|
133 |
index, type); |
134 |
} catch (DataException e) {
|
135 |
throw new ReadRuntimeException("next", e); |
136 |
} |
137 |
index++; |
138 |
return this.data; |
139 |
} |
140 |
|
141 |
protected void internalDispose() { |
142 |
super.internalDispose();
|
143 |
data = null;
|
144 |
} |
145 |
} |
146 |
} |