Revision 10626 trunk/extensions/extJDBC/src/com/iver/cit/gvsig/fmap/drivers/jdbc/mysql/MySqlFeatureIterator.java

View differences:

MySqlFeatureIterator.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
 */
......
48 48
import java.sql.SQLException;
49 49
import java.sql.Types;
50 50

  
51
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
51 52
import com.hardcode.gdbms.engine.values.Value;
52 53
import com.hardcode.gdbms.engine.values.ValueFactory;
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;
......
73 73
    IGeometry geom;
74 74
    int numColumns;
75 75
    int idFieldID = -1;
76
    
76

  
77 77
    int[] relIds;
78 78
    private DBLayerDefinition lyrDef;
79 79

  
......
81 81
    Value[] regAtt;
82 82
    /**
83 83
     * @throws SQLException
84
     * 
84
     *
85 85
     */
86 86
    public MySqlFeatureIterator(ResultSet rs) {
87 87
        // Debe ser forward only
......
95 95
            e.printStackTrace();
96 96
        }
97 97
    }
98
    
98

  
99 99
    /* (non-Javadoc)
100 100
     * @see com.iver.cit.gvsig.fmap.drivers.jdbc.GeometryIterator#hasNext()
101 101
     */
102
    public boolean hasNext() throws DriverException {
102
    public boolean hasNext() throws ReadDriverException {
103 103
        try {
104 104
			if (rs.next())
105 105
			    return true;
106
			else
107
			{
108
			    closeIterator();
109
			    return false;
110
			}
106
			closeIterator();
107
			return false;
111 108
		} catch (SQLException e) {
112
			SqlDriveExceptionType type = new SqlDriveExceptionType();
113
            type.setDriverName("MySQL Driver");
114
            try {
115
				type.setSql(rs.getStatement().toString());
116
			} catch (SQLException e1) {
117
				e1.printStackTrace();
118
			}
119
            throw new com.iver.cit.gvsig.fmap.DriverException(e, type);
109
//			SqlDriveExceptionType type = new SqlDriveExceptionType();
110
//            type.setDriverName("MySQL Driver");
111
//            try {
112
//				type.setSql(rs.getStatement().toString());
113
//			} catch (SQLException e1) {
114
//				e1.printStackTrace();
115
//			}
116
            throw new ReadDriverException("MySQL Driver",e);
120 117
//			throw new DriverException(e);
121 118
		}
122 119
    }
......
124 121
    /* (non-Javadoc)
125 122
     * @see com.iver.cit.gvsig.fmap.drivers.jdbc.GeometryIterator#next()
126 123
     */
127
    public IFeature next() throws DriverException {
124
    public IFeature next() throws ReadDriverException {
128 125
        byte[] data;
129 126
		try {
130 127
			data = rs.getBytes(1);
131 128
			geom = parser.parse(data);
132
        
129

  
133 130
	        for (int fieldId=2; fieldId <= numColumns; fieldId++ )
134 131
	        {
135 132
	            Value val = null;
......
151 148
	                val = ValueFactory.createValue(rs.getBoolean(fieldId));
152 149
	            if (metaData.getColumnType(fieldId) == Types.DATE)
153 150
	                val = ValueFactory.createValue(rs.getDate(fieldId));
154
	            
151

  
155 152
//	            regAtt[relIds[fieldId-2]] = val;
156 153
	            //TODO No se que hace exactamente relIds[fieldId-2], pero estaba todo a 0
157 154
	            //REVISAR
158 155
	            regAtt[fieldId-2] = val;
159
	            
160
	            
156

  
157

  
161 158
	        }
162
	        
159

  
163 160
	        // TODO: Aqu? habr?a que usar una Factor?a.
164
	        
161

  
165 162
	        IFeature feat = null;
166 163
	        if (idFieldID != -1)
167 164
	        {
......
170 167
	        }
171 168
	        else
172 169
			{
173
				// feat = new DefaultFeature(geom, regAtt);
174
	        	FeatureWithoutIdExceptionType  type = new FeatureWithoutIdExceptionType();
175
	        	type.setSchema(lyrDef);
176
				throw new DriverException("Fallo al crear una Feature sin ID", type);
170
//				// feat = new DefaultFeature(geom, regAtt);
171
//	        	FeatureWithoutIdExceptionType  type = new FeatureWithoutIdExceptionType();
172
//	        	type.setSchema(lyrDef);
173
				throw new ReadDriverException("MySQL Driver",null);
177 174
			}
178 175

  
179
	
180
	        
176

  
177

  
181 178
	        return feat;
182 179
		} catch (SQLException e) {
183
			SqlDriveExceptionType type = new SqlDriveExceptionType();
184
            type.setDriverName("MySQL Driver");
185
            try {
186
				type.setSql(rs.getStatement().toString());
187
			} catch (SQLException e1) {
188
				e1.printStackTrace();
189
			}
190
            throw new com.iver.cit.gvsig.fmap.DriverException(e, type);
180
//			SqlDriveExceptionType type = new SqlDriveExceptionType();
181
//            type.setDriverName("MySQL Driver");
182
//            try {
183
//				type.setSql(rs.getStatement().toString());
184
//			} catch (SQLException e1) {
185
//				e1.printStackTrace();
186
//			}
187
            throw new ReadDriverException("MySQL Driver",e);
191 188
//			throw new DriverException(e);
192
		}	        
189
		}
193 190
    }
194 191

  
195 192
    /* (non-Javadoc)
196 193
     * @see com.iver.cit.gvsig.fmap.drivers.IFeatureIterator#closeIterator()
197 194
     */
198
    public void closeIterator() throws DriverException {
195
    public void closeIterator() throws ReadDriverException {
199 196
        try {
200 197
			rs.close();
201 198
		} catch (SQLException e) {
202
			SqlDriveExceptionType type = new SqlDriveExceptionType();
203
            type.setDriverName("MySQL Driver");
204
            try {
205
				type.setSql(rs.getStatement().toString());
206
			} catch (SQLException e1) {
207
				e1.printStackTrace();
208
			}
209
            throw new com.iver.cit.gvsig.fmap.DriverException(e, type);
199
//			SqlDriveExceptionType type = new SqlDriveExceptionType();
200
//            type.setDriverName("MySQL Driver");
201
//            try {
202
//				type.setSql(rs.getStatement().toString());
203
//			} catch (SQLException e1) {
204
//				e1.printStackTrace();
205
//			}
206
            throw new ReadDriverException("MySQL Driver",e);
210 207
//			throw new DriverException(e);
211 208
		}
212 209
    }
213
    
210

  
214 211
    public void setLyrDef(DBLayerDefinition lyrDef)
215 212
    {
216 213
        this.lyrDef  =lyrDef;
......
219 216
        regAtt = new Value[lyrDef.getFieldNames().length];
220 217
        //no deber?a ser numColums - 2 ??
221 218
        relIds = new int[numColumns-1];
222
        
219

  
223 220
        try {
224 221
//            for (int i=2; i<= metaData.getColumnCount(); i++)
225 222
        	for (int i=2; i <= numColumns; i++)
......
240 237
        } catch (SQLException e) {
241 238
            // Si no est?, no pasa nada
242 239
        }
243
        
240

  
244 241
    }
245 242

  
246 243

  

Also available in: Unified diff