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 @ 40559
History | View | Annotate | Download (4.31 KB)
1 | 40435 | jjdelcerro | /**
|
---|---|---|---|
2 | 40559 | jjdelcerro | * gvSIG. Desktop Geographic Information System.
|
3 | 40435 | jjdelcerro | *
|
4 | 40559 | jjdelcerro | * 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 | 40435 | jjdelcerro | */
|
24 | 40559 | jjdelcerro | /**
|
25 | *
|
||
26 | */
|
||
27 | 40435 | jjdelcerro | package org.gvsig.fmap.dal.store.dbf; |
28 | |||
29 | import java.util.NoSuchElementException; |
||
30 | |||
31 | import org.gvsig.fmap.dal.exception.DataException; |
||
32 | import org.gvsig.fmap.dal.exception.ReadRuntimeException; |
||
33 | import org.gvsig.fmap.dal.feature.FeatureQuery; |
||
34 | import org.gvsig.fmap.dal.feature.FeatureType; |
||
35 | import org.gvsig.fmap.dal.feature.spi.AbstractFeatureProviderIterator; |
||
36 | import org.gvsig.fmap.dal.feature.spi.AbstractFeatureSetProvider; |
||
37 | import org.gvsig.fmap.dal.feature.spi.FeatureProvider; |
||
38 | import org.gvsig.tools.exception.BaseException; |
||
39 | |||
40 | /**
|
||
41 | * @author jjdelcerro
|
||
42 | *
|
||
43 | */
|
||
44 | public class DBFSetProvider extends AbstractFeatureSetProvider { |
||
45 | |||
46 | public DBFSetProvider(DBFStoreProvider store, FeatureQuery query,
|
||
47 | FeatureType featureType) |
||
48 | throws DataException {
|
||
49 | super(store, query, featureType);
|
||
50 | } |
||
51 | |||
52 | public boolean canFilter() { |
||
53 | return false; |
||
54 | } |
||
55 | |||
56 | public boolean canIterateFromIndex() { |
||
57 | return true; |
||
58 | } |
||
59 | |||
60 | public boolean canOrder() { |
||
61 | return false; |
||
62 | } |
||
63 | |||
64 | public long getSize() throws DataException { |
||
65 | return getStore().getFeatureCount();
|
||
66 | } |
||
67 | |||
68 | public boolean isEmpty() throws DataException { |
||
69 | return getSize() == 0; |
||
70 | } |
||
71 | |||
72 | @Override
|
||
73 | protected void doDispose() throws BaseException { |
||
74 | } |
||
75 | |||
76 | protected AbstractFeatureProviderIterator createIterator(long index) |
||
77 | throws DataException {
|
||
78 | return new DBFIterator((DBFStoreProvider) getStore(), getFeatureType(), |
||
79 | index); |
||
80 | } |
||
81 | |||
82 | protected AbstractFeatureProviderIterator createFastIterator(long index) |
||
83 | throws DataException {
|
||
84 | return new FastDBFIterator((DBFStoreProvider) getStore(), |
||
85 | getFeatureType(), index); |
||
86 | } |
||
87 | |||
88 | protected class DBFIterator extends AbstractFeatureProviderIterator { |
||
89 | protected long index; |
||
90 | protected FeatureType type;
|
||
91 | protected long count; |
||
92 | |||
93 | public DBFIterator(DBFStoreProvider store, FeatureType type,
|
||
94 | long startOn) throws DataException { |
||
95 | super(store);
|
||
96 | this.index = startOn;
|
||
97 | this.type = type;
|
||
98 | this.count = store.getFeatureCount();
|
||
99 | } |
||
100 | |||
101 | protected boolean internalHasNext() { |
||
102 | return this.count > index; |
||
103 | } |
||
104 | |||
105 | protected Object internalNext() { |
||
106 | if (index >= this.count) { |
||
107 | throw new NoSuchElementException(); |
||
108 | } |
||
109 | try {
|
||
110 | |||
111 | FeatureProvider ret = |
||
112 | getDBFStoreProvider().getFeatureProviderByIndex(index, |
||
113 | this.type);
|
||
114 | index++; |
||
115 | return ret;
|
||
116 | } catch (DataException e) {
|
||
117 | throw new ReadRuntimeException(getDBFStoreProvider().getProviderName(), |
||
118 | e); |
||
119 | } |
||
120 | } |
||
121 | |||
122 | public void remove() { |
||
123 | throw new UnsupportedOperationException(); |
||
124 | } |
||
125 | |||
126 | protected void internalDispose() { |
||
127 | type = null;
|
||
128 | } |
||
129 | |||
130 | protected DBFStoreProvider getDBFStoreProvider() {
|
||
131 | return (DBFStoreProvider) getFeatureStoreProvider();
|
||
132 | } |
||
133 | |||
134 | @Override
|
||
135 | protected void doDispose() throws BaseException { |
||
136 | // Nothing to do
|
||
137 | } |
||
138 | } |
||
139 | |||
140 | protected class FastDBFIterator extends DBFIterator { |
||
141 | protected FeatureProvider data;
|
||
142 | |||
143 | public FastDBFIterator(DBFStoreProvider store, FeatureType type,
|
||
144 | long startOn) throws DataException { |
||
145 | super(store, type, startOn);
|
||
146 | this.data = getFeatureStoreProvider().createFeatureProvider(type);
|
||
147 | } |
||
148 | |||
149 | protected Object internalNext() { |
||
150 | if (index >= this.count) { |
||
151 | throw new NoSuchElementException(); |
||
152 | } |
||
153 | |||
154 | try {
|
||
155 | getDBFStoreProvider().initFeatureProviderByIndex(this.data,
|
||
156 | index, type); |
||
157 | } catch (DataException e) {
|
||
158 | throw new ReadRuntimeException("next", e); |
||
159 | } |
||
160 | index++; |
||
161 | return this.data; |
||
162 | } |
||
163 | |||
164 | protected void internalDispose() { |
||
165 | super.internalDispose();
|
||
166 | data = null;
|
||
167 | } |
||
168 | } |
||
169 | } |