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 @ 40767
History | View | Annotate | Download (4.3 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 3
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.fmap.dal.store.dbf; |
25 |
|
26 |
import java.util.NoSuchElementException; |
27 |
|
28 |
import org.gvsig.fmap.dal.exception.DataException; |
29 |
import org.gvsig.fmap.dal.exception.ReadRuntimeException; |
30 |
import org.gvsig.fmap.dal.feature.FeatureQuery; |
31 |
import org.gvsig.fmap.dal.feature.FeatureType; |
32 |
import org.gvsig.fmap.dal.feature.spi.AbstractFeatureProviderIterator; |
33 |
import org.gvsig.fmap.dal.feature.spi.AbstractFeatureSetProvider; |
34 |
import org.gvsig.fmap.dal.feature.spi.FeatureProvider; |
35 |
import org.gvsig.tools.exception.BaseException; |
36 |
|
37 |
/**
|
38 |
* @author jjdelcerro
|
39 |
*
|
40 |
*/
|
41 |
public class DBFSetProvider extends AbstractFeatureSetProvider { |
42 |
|
43 |
public DBFSetProvider(DBFStoreProvider store, FeatureQuery query,
|
44 |
FeatureType featureType) |
45 |
throws DataException {
|
46 |
super(store, query, featureType);
|
47 |
} |
48 |
|
49 |
public boolean canFilter() { |
50 |
return false; |
51 |
} |
52 |
|
53 |
public boolean canIterateFromIndex() { |
54 |
return true; |
55 |
} |
56 |
|
57 |
public boolean canOrder() { |
58 |
return false; |
59 |
} |
60 |
|
61 |
public long getSize() throws DataException { |
62 |
return getStore().getFeatureCount();
|
63 |
} |
64 |
|
65 |
public boolean isEmpty() throws DataException { |
66 |
return getSize() == 0; |
67 |
} |
68 |
|
69 |
@Override
|
70 |
protected void doDispose() throws BaseException { |
71 |
} |
72 |
|
73 |
protected AbstractFeatureProviderIterator createIterator(long index) |
74 |
throws DataException {
|
75 |
return new DBFIterator((DBFStoreProvider) getStore(), getFeatureType(), |
76 |
index); |
77 |
} |
78 |
|
79 |
protected AbstractFeatureProviderIterator createFastIterator(long index) |
80 |
throws DataException {
|
81 |
return new FastDBFIterator((DBFStoreProvider) getStore(), |
82 |
getFeatureType(), index); |
83 |
} |
84 |
|
85 |
protected class DBFIterator extends AbstractFeatureProviderIterator { |
86 |
protected long index; |
87 |
protected FeatureType type;
|
88 |
protected long count; |
89 |
|
90 |
public DBFIterator(DBFStoreProvider store, FeatureType type,
|
91 |
long startOn) throws DataException { |
92 |
super(store);
|
93 |
this.index = startOn;
|
94 |
this.type = type;
|
95 |
this.count = store.getFeatureCount();
|
96 |
} |
97 |
|
98 |
protected boolean internalHasNext() { |
99 |
return this.count > index; |
100 |
} |
101 |
|
102 |
protected Object internalNext() { |
103 |
if (index >= this.count) { |
104 |
throw new NoSuchElementException(); |
105 |
} |
106 |
try {
|
107 |
|
108 |
FeatureProvider ret = |
109 |
getDBFStoreProvider().getFeatureProviderByIndex(index, |
110 |
this.type);
|
111 |
index++; |
112 |
return ret;
|
113 |
} catch (DataException e) {
|
114 |
throw new ReadRuntimeException(getDBFStoreProvider().getProviderName(), |
115 |
e); |
116 |
} |
117 |
} |
118 |
|
119 |
public void remove() { |
120 |
throw new UnsupportedOperationException(); |
121 |
} |
122 |
|
123 |
protected void internalDispose() { |
124 |
type = null;
|
125 |
} |
126 |
|
127 |
protected DBFStoreProvider getDBFStoreProvider() {
|
128 |
return (DBFStoreProvider) getFeatureStoreProvider();
|
129 |
} |
130 |
|
131 |
@Override
|
132 |
protected void doDispose() throws BaseException { |
133 |
// Nothing to do
|
134 |
} |
135 |
} |
136 |
|
137 |
protected class FastDBFIterator extends DBFIterator { |
138 |
protected FeatureProvider data;
|
139 |
|
140 |
public FastDBFIterator(DBFStoreProvider store, FeatureType type,
|
141 |
long startOn) throws DataException { |
142 |
super(store, type, startOn);
|
143 |
this.data = getFeatureStoreProvider().createFeatureProvider(type);
|
144 |
} |
145 |
|
146 |
protected Object internalNext() { |
147 |
if (index >= this.count) { |
148 |
throw new NoSuchElementException(); |
149 |
} |
150 |
|
151 |
try {
|
152 |
getDBFStoreProvider().initFeatureProviderByIndex(this.data,
|
153 |
index, type); |
154 |
} catch (DataException e) {
|
155 |
throw new ReadRuntimeException("next", e); |
156 |
} |
157 |
index++; |
158 |
return this.data; |
159 |
} |
160 |
|
161 |
protected void internalDispose() { |
162 |
super.internalDispose();
|
163 |
data = null;
|
164 |
} |
165 |
} |
166 |
} |