Revision 10626 trunk/extensions/extJDBC/src/com/iver/cit/gvsig/fmap/drivers/jdbc/postgis/PostGisFeatureIterator.java
PostGisFeatureIterator.java | ||
---|---|---|
2 | 2 |
* Created on 11-mar-2005 |
3 | 3 |
* |
4 | 4 |
* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
5 |
*
|
|
5 |
* |
|
6 | 6 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
7 |
*
|
|
7 |
* |
|
8 | 8 |
* This program is free software; you can redistribute it and/or |
9 | 9 |
* modify it under the terms of the GNU General Public License |
10 | 10 |
* as published by the Free Software Foundation; either version 2 |
11 | 11 |
* of the License, or (at your option) any later version. |
12 |
*
|
|
12 |
* |
|
13 | 13 |
* This program is distributed in the hope that it will be useful, |
14 | 14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | 15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | 16 |
* GNU General Public License for more details. |
17 |
*
|
|
17 |
* |
|
18 | 18 |
* You should have received a copy of the GNU General Public License |
19 | 19 |
* along with this program; if not, write to the Free Software |
20 | 20 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21 |
*
|
|
21 |
* |
|
22 | 22 |
* For more information, contact: |
23 | 23 |
* |
24 | 24 |
* Generalitat Valenciana |
... | ... | |
30 | 30 |
* +34 963862235 |
31 | 31 |
* gvsig@gva.es |
32 | 32 |
* www.gvsig.gva.es |
33 |
*
|
|
33 |
* |
|
34 | 34 |
* or |
35 |
*
|
|
35 |
* |
|
36 | 36 |
* IVER T.I. S.A |
37 | 37 |
* Salamanca 50 |
38 | 38 |
* 46005 Valencia |
39 | 39 |
* Spain |
40 |
*
|
|
40 |
* |
|
41 | 41 |
* +34 963163400 |
42 | 42 |
* dac@iver.es |
43 | 43 |
*/ |
... | ... | |
49 | 49 |
import java.sql.SQLException; |
50 | 50 |
import java.sql.Statement; |
51 | 51 |
|
52 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
|
52 | 53 |
import com.hardcode.gdbms.engine.values.Value; |
53 |
import com.iver.cit.gvsig.fmap.DriverException; |
|
54 | 54 |
import com.iver.cit.gvsig.fmap.SqlDriveExceptionType; |
55 | 55 |
import com.iver.cit.gvsig.fmap.core.DefaultFeature; |
56 | 56 |
import com.iver.cit.gvsig.fmap.core.IFeature; |
... | ... | |
63 | 63 |
|
64 | 64 |
/** |
65 | 65 |
* @author FJP |
66 |
*
|
|
66 |
* |
|
67 | 67 |
* TODO To change the template for this generated type comment go to Window - |
68 | 68 |
* Preferences - Java - Code Generation - Code and Comments |
69 | 69 |
*/ |
... | ... | |
103 | 103 |
/** |
104 | 104 |
* @throws SQLException |
105 | 105 |
* @throws SQLException |
106 |
*
|
|
106 |
* |
|
107 | 107 |
*/ |
108 | 108 |
public PostGisFeatureIterator(Connection conn, String cursorName, String sql) |
109 | 109 |
throws SQLException { |
... | ... | |
127 | 127 |
|
128 | 128 |
/* |
129 | 129 |
* (non-Javadoc) |
130 |
*
|
|
130 |
* |
|
131 | 131 |
* @see com.iver.cit.gvsig.fmap.drivers.jdbc.GeometryIterator#hasNext() |
132 | 132 |
*/ |
133 |
public boolean hasNext() throws DriverException { |
|
133 |
public boolean hasNext() throws ReadDriverException {
|
|
134 | 134 |
try { |
135 | 135 |
if (numReg > 0) |
136 | 136 |
if ((numReg % FETCH_SIZE) == 0) { |
... | ... | |
146 | 146 |
return false; |
147 | 147 |
} |
148 | 148 |
} catch (SQLException e) { |
149 |
SqlDriveExceptionType type = new SqlDriveExceptionType(); |
|
150 |
type.setDriverName("PostGIS Driver"); |
|
151 |
try { |
|
152 |
type.setSql(rs.getStatement().toString()); |
|
153 |
} catch (SQLException e1) { |
|
154 |
e1.printStackTrace(); |
|
155 |
} |
|
156 |
throw new com.iver.cit.gvsig.fmap.DriverException(e, type);
|
|
149 |
// SqlDriveExceptionType type = new SqlDriveExceptionType();
|
|
150 |
// type.setDriverName("PostGIS Driver");
|
|
151 |
// try {
|
|
152 |
// type.setSql(rs.getStatement().toString());
|
|
153 |
// } catch (SQLException e1) {
|
|
154 |
// e1.printStackTrace();
|
|
155 |
// }
|
|
156 |
throw new ReadDriverException("PostGIS Driver",e);
|
|
157 | 157 |
// throw new DriverException(e); |
158 | 158 |
} |
159 | 159 |
|
... | ... | |
161 | 161 |
|
162 | 162 |
/* |
163 | 163 |
* (non-Javadoc) |
164 |
*
|
|
164 |
* |
|
165 | 165 |
* @see com.iver.cit.gvsig.fmap.drivers.jdbc.GeometryIterator#next() |
166 | 166 |
*/ |
167 |
public IFeature next() throws DriverException { |
|
167 |
public IFeature next() throws ReadDriverException {
|
|
168 | 168 |
byte[] data; |
169 | 169 |
try { |
170 | 170 |
data = rs.getBytes(1); |
... | ... | |
173 | 173 |
Value val = XTypes.getValue(rs, fieldId); |
174 | 174 |
regAtt[relIds[fieldId - 2]] = val; |
175 | 175 |
} |
176 |
|
|
176 |
|
|
177 | 177 |
// TODO: Aqu? habr?a que usar una Factor?a. |
178 | 178 |
IFeature feat = null; |
179 | 179 |
if (idFieldID != -1) { |
... | ... | |
182 | 182 |
} |
183 | 183 |
else |
184 | 184 |
{ |
185 |
// feat = new DefaultFeature(geom, regAtt); |
|
186 |
FeatureWithoutIdExceptionType type = new FeatureWithoutIdExceptionType(); |
|
187 |
type.setSchema(lyrDef); |
|
188 |
throw new DriverException("Fallo al crear una Feature sin ID", type);
|
|
185 |
// // feat = new DefaultFeature(geom, regAtt);
|
|
186 |
// FeatureWithoutIdExceptionType type = new FeatureWithoutIdExceptionType();
|
|
187 |
// type.setSchema(lyrDef);
|
|
188 |
throw new ReadDriverException("PostGIS Driver",null);
|
|
189 | 189 |
} |
190 | 190 |
numReg++; |
191 | 191 |
return feat; |
192 | 192 |
} catch (SQLException e) { |
193 |
SqlDriveExceptionType type = new SqlDriveExceptionType(); |
|
194 |
type.setDriverName("PostGIS Driver"); |
|
195 |
try { |
|
196 |
type.setSql(rs.getStatement().toString()); |
|
197 |
} catch (SQLException e1) { |
|
198 |
e1.printStackTrace(); |
|
199 |
} |
|
200 |
throw new com.iver.cit.gvsig.fmap.DriverException(e, type);
|
|
193 |
// SqlDriveExceptionType type = new SqlDriveExceptionType();
|
|
194 |
// type.setDriverName("PostGIS Driver");
|
|
195 |
// try {
|
|
196 |
// type.setSql(rs.getStatement().toString());
|
|
197 |
// } catch (SQLException e1) {
|
|
198 |
// e1.printStackTrace();
|
|
199 |
// }
|
|
200 |
throw new ReadDriverException("PostGIS Driver",e);
|
|
201 | 201 |
// throw new DriverException(e); |
202 | 202 |
} |
203 | 203 |
|
... | ... | |
206 | 206 |
|
207 | 207 |
/* |
208 | 208 |
* (non-Javadoc) |
209 |
*
|
|
209 |
* |
|
210 | 210 |
* @see com.iver.cit.gvsig.fmap.drivers.IFeatureIterator#closeIterator() |
211 | 211 |
*/ |
212 |
public void closeIterator() throws DriverException { |
|
212 |
public void closeIterator() throws ReadDriverException {
|
|
213 | 213 |
try { |
214 | 214 |
numReg = 0; |
215 | 215 |
|
... | ... | |
217 | 217 |
// st.execute("COMMIT"); |
218 | 218 |
rs.close(); |
219 | 219 |
} catch (SQLException e) { |
220 |
SqlDriveExceptionType type = new SqlDriveExceptionType(); |
|
221 |
type.setDriverName("PostGIS Driver"); |
|
222 |
try { |
|
223 |
type.setSql(rs.getStatement().toString()); |
|
224 |
} catch (SQLException e1) { |
|
225 |
e1.printStackTrace(); |
|
226 |
} |
|
227 |
throw new com.iver.cit.gvsig.fmap.DriverException(e, type);
|
|
220 |
// SqlDriveExceptionType type = new SqlDriveExceptionType();
|
|
221 |
// type.setDriverName("PostGIS Driver");
|
|
222 |
// try {
|
|
223 |
// type.setSql(rs.getStatement().toString());
|
|
224 |
// } catch (SQLException e1) {
|
|
225 |
// e1.printStackTrace();
|
|
226 |
// }
|
|
227 |
throw new ReadDriverException("PostGIS Driver",e);
|
|
228 | 228 |
// throw new DriverException(e); |
229 | 229 |
} |
230 | 230 |
// st.execute("COMMIT"); |
Also available in: Unified diff