svn-gvsig-desktop / branches / gvSIG_1.11.0_Mejoras_gvSIG-EIEL / libraries / libFMap / src / com / iver / cit / gvsig / fmap / layers / SelectableDataSource.java @ 35647
History | View | Annotate | Download (17.4 KB)
1 | 1100 | fjp | /* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|---|---|
2 | *
|
||
3 | * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
||
4 | *
|
||
5 | * This program is free software; you can redistribute it and/or
|
||
6 | * modify it under the terms of the GNU General Public License
|
||
7 | * as published by the Free Software Foundation; either version 2
|
||
8 | * of the License, or (at your option) any later version.
|
||
9 | *
|
||
10 | * This program is distributed in the hope that it will be useful,
|
||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
13 | * GNU General Public License for more details.
|
||
14 | *
|
||
15 | * You should have received a copy of the GNU General Public License
|
||
16 | * along with this program; if not, write to the Free Software
|
||
17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
||
18 | *
|
||
19 | * For more information, contact:
|
||
20 | *
|
||
21 | * Generalitat Valenciana
|
||
22 | * Conselleria d'Infraestructures i Transport
|
||
23 | * Av. Blasco Ib??ez, 50
|
||
24 | * 46010 VALENCIA
|
||
25 | * SPAIN
|
||
26 | *
|
||
27 | * +34 963862235
|
||
28 | * gvsig@gva.es
|
||
29 | * www.gvsig.gva.es
|
||
30 | *
|
||
31 | * or
|
||
32 | *
|
||
33 | * IVER T.I. S.A
|
||
34 | * Salamanca 50
|
||
35 | * 46005 Valencia
|
||
36 | * Spain
|
||
37 | *
|
||
38 | * +34 963163400
|
||
39 | * dac@iver.es
|
||
40 | */
|
||
41 | 460 | fernando | package com.iver.cit.gvsig.fmap.layers; |
42 | |||
43 | 1828 | fernando | import java.io.IOException; |
44 | |||
45 | import org.apache.log4j.Logger; |
||
46 | 1836 | fernando | import org.xml.sax.SAXException; |
47 | 1828 | fernando | |
48 | 5569 | jmvivo | import com.hardcode.driverManager.Driver; |
49 | 1828 | fernando | import com.hardcode.driverManager.DriverLoadException; |
50 | 10627 | caballero | import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
51 | import com.hardcode.gdbms.driver.exceptions.ReloadDriverException; |
||
52 | import com.hardcode.gdbms.driver.exceptions.WriteDriverException; |
||
53 | 460 | fernando | import com.hardcode.gdbms.engine.data.DataSource; |
54 | 546 | fernando | import com.hardcode.gdbms.engine.data.DataSourceFactory; |
55 | 6323 | fjp | import com.hardcode.gdbms.engine.data.IDataSourceListener; |
56 | 546 | fernando | import com.hardcode.gdbms.engine.data.NoSuchTableException; |
57 | 4863 | fjp | import com.hardcode.gdbms.engine.data.SourceInfo; |
58 | 1828 | fernando | import com.hardcode.gdbms.engine.data.driver.DriverException; |
59 | 2217 | fernando | import com.hardcode.gdbms.engine.data.edition.DataWare; |
60 | 1836 | fernando | import com.hardcode.gdbms.engine.data.persistence.Memento; |
61 | import com.hardcode.gdbms.engine.data.persistence.MementoContentHandler; |
||
62 | import com.hardcode.gdbms.engine.data.persistence.MementoException; |
||
63 | 2217 | fernando | import com.hardcode.gdbms.engine.instruction.EvaluationException; |
64 | 460 | fernando | import com.hardcode.gdbms.engine.instruction.FieldNotFoundException; |
65 | 1828 | fernando | import com.hardcode.gdbms.engine.instruction.SemanticException; |
66 | 460 | fernando | import com.hardcode.gdbms.engine.values.Value; |
67 | 2183 | fernando | import com.hardcode.gdbms.engine.values.ValueCollection; |
68 | 1828 | fernando | import com.hardcode.gdbms.parser.ParseException; |
69 | 4875 | fjp | import com.iver.cit.gvsig.fmap.drivers.FieldDescription; |
70 | 3963 | caballero | import com.iver.cit.gvsig.fmap.layers.layerOperations.Selectable; |
71 | 4875 | fjp | import com.iver.utiles.NumberUtilities; |
72 | 581 | vcaballero | import com.iver.utiles.XMLEntity; |
73 | 460 | fernando | |
74 | |||
75 | 527 | vcaballero | /**
|
76 | 1034 | vcaballero | * DataSource seleccionable.
|
77 | 527 | vcaballero | *
|
78 | 546 | fernando | * @author Fernando Gonz?lez Cort?s
|
79 | 527 | vcaballero | */
|
80 | 3963 | caballero | public class SelectableDataSource implements DataSource,Selectable { |
81 | 527 | vcaballero | private static Logger logger = Logger.getLogger(SelectableDataSource.class.getName()); |
82 | 460 | fernando | private SelectionSupport selectionSupport = new SelectionSupport(); |
83 | private DataSource dataSource; |
||
84 | 10627 | caballero | |
85 | 4863 | fjp | private int[] mapping = null; |
86 | 31155 | fpenarrubia | private String[] alias = null; |
87 | 527 | vcaballero | |
88 | 460 | fernando | /**
|
89 | 1034 | vcaballero | * Crea un nuevo SelectableDataSource.
|
90 | 527 | vcaballero | *
|
91 | 1034 | vcaballero | * @param name
|
92 | 460 | fernando | * @param ds
|
93 | 10627 | caballero | * @throws ReadDriverException TODO
|
94 | 460 | fernando | */
|
95 | 10627 | caballero | public SelectableDataSource(DataSource ds) throws ReadDriverException { |
96 | 460 | fernando | dataSource = ds; |
97 | 5663 | fjp | dataSource.start(); |
98 | 4863 | fjp | // Creamos el mapping de campos externos que no muestran el PK.
|
99 | 6259 | fjp | mapExternalFields(); |
100 | 31155 | fpenarrubia | alias = new String[mapping.length]; |
101 | for (int i=0; i < mapping.length; i++) |
||
102 | { |
||
103 | alias[i] = getFieldName(i); |
||
104 | } |
||
105 | 6259 | fjp | |
106 | |||
107 | 31225 | vcaballero | |
108 | 6259 | fjp | } |
109 | |||
110 | /**
|
||
111 | 6335 | fjp | * Maps real fields or "external" fields. We don't want to see virtual fields.
|
112 | 10665 | caballero | * @throws ReadDriverException
|
113 | 6259 | fjp | */
|
114 | 10627 | caballero | public void mapExternalFields() throws ReadDriverException { |
115 | 4863 | fjp | int numExternalFields = 0; |
116 | 31024 | vcaballero | // this.dataSource.start();
|
117 | 30943 | vcaballero | int fieldCount=dataSource.getFieldCount();
|
118 | for (int i=0; i < fieldCount; i++) |
||
119 | 4863 | fjp | { |
120 | if (!dataSource.isVirtualField(i))
|
||
121 | numExternalFields++; |
||
122 | 10627 | caballero | |
123 | 4863 | fjp | } |
124 | 3963 | caballero | |
125 | 4863 | fjp | mapping = new int[numExternalFields]; |
126 | 31235 | vcaballero | |
127 | 4863 | fjp | int j=0; |
128 | 30943 | vcaballero | for (int i=0; i < fieldCount; i++) |
129 | 4863 | fjp | { |
130 | 31155 | fpenarrubia | if (!dataSource.isVirtualField(i)) {
|
131 | mapping[j] = i; |
||
132 | j++; |
||
133 | } |
||
134 | 10627 | caballero | |
135 | 4863 | fjp | } |
136 | 31235 | vcaballero | |
137 | 31024 | vcaballero | // this.dataSource.stop();
|
138 | 460 | fernando | } |
139 | 527 | vcaballero | |
140 | 10627 | caballero | public static SelectableDataSource createSelectableDataSource(XMLEntity xml) throws DriverLoadException, XMLException{ |
141 | 3963 | caballero | |
142 | 1828 | fernando | SelectionSupport ss = new SelectionSupport();
|
143 | ss.setXMLEntity(xml.getChild(0));
|
||
144 | XMLEntity xmlDS = xml.getChild(1);
|
||
145 | 1836 | fernando | GDBMSParser parser = new GDBMSParser(xmlDS);
|
146 | MementoContentHandler gdbmsHandler = new MementoContentHandler();
|
||
147 | parser.setContentHandler(gdbmsHandler); |
||
148 | try {
|
||
149 | parser.parse(); |
||
150 | } catch (SAXException e) {
|
||
151 | throw new XMLException(e); |
||
152 | 1828 | fernando | } |
153 | 2217 | fernando | SelectableDataSource sds; |
154 | try {
|
||
155 | 14588 | vcaballero | sds = new SelectableDataSource(gdbmsHandler.getDataSource(LayerFactory.getDataSourceFactory(), DataSourceFactory.AUTOMATIC_OPENING));
|
156 | 2217 | fernando | } catch (EvaluationException e1) {
|
157 | throw new XMLException(e1); |
||
158 | 10627 | caballero | } catch (ReadDriverException e) {
|
159 | throw new XMLException(e); |
||
160 | } catch (DriverLoadException e) {
|
||
161 | throw new XMLException(e); |
||
162 | } catch (SemanticException e) {
|
||
163 | throw new XMLException(e); |
||
164 | } catch (ParseException e) { |
||
165 | throw new XMLException(e); |
||
166 | } catch (NoSuchTableException e) {
|
||
167 | throw new XMLException(e); |
||
168 | } |
||
169 | 2217 | fernando | sds.selectionSupport=ss; |
170 | 2183 | fernando | return sds;
|
171 | 1828 | fernando | } |
172 | 1836 | fernando | |
173 | 1828 | fernando | public void setDataSourceFactory(DataSourceFactory dsf) { |
174 | dataSource.setDataSourceFactory(dsf); |
||
175 | } |
||
176 | 2217 | fernando | public void setSourceInfo(SourceInfo sourceInfo) { |
177 | 1828 | fernando | dataSource.setSourceInfo(sourceInfo); |
178 | } |
||
179 | 460 | fernando | /**
|
180 | 1034 | vcaballero | * A?ade el soporte para la selecci?n.
|
181 | 527 | vcaballero | *
|
182 | 460 | fernando | * @param selectionSupport
|
183 | */
|
||
184 | public void setSelectionSupport(SelectionSupport selectionSupport) { |
||
185 | this.selectionSupport = selectionSupport;
|
||
186 | } |
||
187 | |||
188 | 527 | vcaballero | /**
|
189 | 1034 | vcaballero | * Devuelve el n?mero de campos.
|
190 | 527 | vcaballero | *
|
191 | 1034 | vcaballero | * @return N?mero de campos.
|
192 | 527 | vcaballero | *
|
193 | 1034 | vcaballero | * @throws DriverException
|
194 | 527 | vcaballero | */
|
195 | 10627 | caballero | public int getFieldCount() throws ReadDriverException { |
196 | 4863 | fjp | // return dataSource.getFieldCount()-numVirtual;
|
197 | 6478 | fjp | // if (mapping.length != dataSource.getFieldCount())
|
198 | // {
|
||
199 | // mapExternalFields();
|
||
200 | // RuntimeException e = new RuntimeException("Recalculamos los campos de recordset!!");
|
||
201 | // e.printStackTrace();
|
||
202 | // }
|
||
203 | 30637 | vcaballero | if (mapping.length!=dataSource.getFieldCount()){
|
204 | mapExternalFields(); |
||
205 | } |
||
206 | 4863 | fjp | return mapping.length;
|
207 | 460 | fernando | } |
208 | 527 | vcaballero | |
209 | /**
|
||
210 | 7631 | fjp | * Return index field searching by its name
|
211 | 527 | vcaballero | *
|
212 | 7631 | fjp | * @param arg0 field name.
|
213 | 527 | vcaballero | *
|
214 | 7631 | fjp | * @return field index. -1 if not found
|
215 | 527 | vcaballero | *
|
216 | 1034 | vcaballero | * @throws DriverException
|
217 | * @throws FieldNotFoundException
|
||
218 | 527 | vcaballero | */
|
219 | public int getFieldIndexByName(String arg0) |
||
220 | 10627 | caballero | throws ReadDriverException {
|
221 | 31228 | fpenarrubia | // int internal = dataSource.getFieldIndexByName(arg0);
|
222 | // for (int i=0; i < mapping.length; i++)
|
||
223 | // {
|
||
224 | // if (mapping[i] == internal)
|
||
225 | // return i;
|
||
226 | // }
|
||
227 | // //OJO Parche para rodear poblema de gdbms + FileDriver
|
||
228 | // // Cuando en le fichero existe un campo de nombre 'PK'
|
||
229 | // if (arg0.equalsIgnoreCase("pk")){
|
||
230 | // for (int i=0; i < mapping.length; i++)
|
||
231 | // {
|
||
232 | // if (dataSource.getFieldName(mapping[i]).equalsIgnoreCase(arg0)){
|
||
233 | // return i;
|
||
234 | // }
|
||
235 | // }
|
||
236 | //
|
||
237 | // }
|
||
238 | for (int i=0; i < getFieldCount(); i++) { |
||
239 | // Buscamos en los alias. Si no hay alias, cada alias es igual al fieldname
|
||
240 | 31514 | fpenarrubia | if (getFieldAlias(i).compareToIgnoreCase(arg0) == 0) |
241 | 4863 | fjp | return i;
|
242 | } |
||
243 | 31228 | fpenarrubia | for (int i=0; i < getFieldCount(); i++) { |
244 | 31235 | vcaballero | // Por compatibilidad con posibles leyendas guardadas
|
245 | 31514 | fpenarrubia | if (getFieldName(i).compareToIgnoreCase(arg0) == 0) |
246 | 31228 | fpenarrubia | return i;
|
247 | 14577 | jmvivo | } |
248 | 31235 | vcaballero | |
249 | 4863 | fjp | return -1; |
250 | 460 | fernando | } |
251 | 527 | vcaballero | |
252 | /**
|
||
253 | 1034 | vcaballero | * Devuelve el nombre del campo a partir del ?ndice.
|
254 | 527 | vcaballero | *
|
255 | 1034 | vcaballero | * @param arg0 ?ndice.
|
256 | 527 | vcaballero | *
|
257 | 1034 | vcaballero | * @return nombre del campo.
|
258 | 527 | vcaballero | *
|
259 | 1034 | vcaballero | * @throws DriverException
|
260 | 527 | vcaballero | */
|
261 | 10627 | caballero | public String getFieldName(int arg0) throws ReadDriverException { |
262 | 4863 | fjp | // return dataSource.getFieldName(arg0);
|
263 | return dataSource.getFieldName(mapping[arg0]);
|
||
264 | 460 | fernando | } |
265 | 527 | vcaballero | |
266 | /**
|
||
267 | 1034 | vcaballero | * Devuelve el valor a partir del n?mro de fila y columna.
|
268 | 527 | vcaballero | *
|
269 | 1034 | vcaballero | * @param arg0 n?mero de registro.
|
270 | * @param arg1 n?mero de campo.
|
||
271 | 527 | vcaballero | *
|
272 | 1034 | vcaballero | * @return Valor.
|
273 | 527 | vcaballero | *
|
274 | 1034 | vcaballero | * @throws DriverException
|
275 | 527 | vcaballero | */
|
276 | 10627 | caballero | public Value getFieldValue(long arg0, int arg1) throws ReadDriverException { |
277 | 29465 | vcaballero | if (arg1==-1) |
278 | return null; |
||
279 | 4863 | fjp | return dataSource.getFieldValue(arg0, mapping[arg1]);
|
280 | // return dataSource.getFieldValue(arg0, arg1);
|
||
281 | 460 | fernando | } |
282 | 527 | vcaballero | |
283 | /**
|
||
284 | 1034 | vcaballero | * Devuelve el nombre del DataSource.
|
285 | 527 | vcaballero | *
|
286 | 1034 | vcaballero | * @return Nombre.
|
287 | 527 | vcaballero | */
|
288 | 460 | fernando | public String getName() { |
289 | return dataSource.getName();
|
||
290 | } |
||
291 | 527 | vcaballero | |
292 | /**
|
||
293 | 2565 | fernando | * Devuelve el n?mero de filas en total.
|
294 | 527 | vcaballero | *
|
295 | 1034 | vcaballero | * @return n?mero de filas.
|
296 | 527 | vcaballero | *
|
297 | 1034 | vcaballero | * @throws DriverException
|
298 | 527 | vcaballero | */
|
299 | 10627 | caballero | public long getRowCount() throws ReadDriverException { |
300 | 460 | fernando | return dataSource.getRowCount();
|
301 | } |
||
302 | 527 | vcaballero | |
303 | /**
|
||
304 | 1034 | vcaballero | * Inicializa el dataSource.
|
305 | 527 | vcaballero | *
|
306 | 1034 | vcaballero | * @throws DriverException
|
307 | 527 | vcaballero | */
|
308 | 10627 | caballero | public void start() throws ReadDriverException { |
309 | 3076 | fjp | // logger.debug("dataSource.start()");
|
310 | 460 | fernando | dataSource.start(); |
311 | } |
||
312 | 527 | vcaballero | |
313 | /**
|
||
314 | 1034 | vcaballero | * Finaliza el DataSource.
|
315 | 527 | vcaballero | *
|
316 | 1034 | vcaballero | * @throws DriverException
|
317 | 527 | vcaballero | */
|
318 | 10627 | caballero | public void stop() throws ReadDriverException { |
319 | 3076 | fjp | // logger.debug("dataSource.stop()");
|
320 | 460 | fernando | dataSource.stop(); |
321 | } |
||
322 | |||
323 | /**
|
||
324 | 2183 | fernando | * A partir del XMLEntity se rellenan los atributos del DataSource.
|
325 | *
|
||
326 | * @param child
|
||
327 | */
|
||
328 | public void setXMLEntity03(XMLEntity child) { |
||
329 | selectionSupport.setXMLEntity(child.getChild(0));
|
||
330 | } |
||
331 | |||
332 | /**
|
||
333 | 527 | vcaballero | * Cuando ocurre un evento de cambio en la selecci?n, ?ste puede ser uno de
|
334 | * una gran cantidad de eventos. Con el fin de no propagar todos estos
|
||
335 | * eventos, se realiza la propagaci?n de manera manual al final de la
|
||
336 | * "r?faga" de eventos
|
||
337 | 460 | fernando | */
|
338 | public void fireSelectionEvents() { |
||
339 | selectionSupport.fireSelectionEvents(); |
||
340 | } |
||
341 | |||
342 | 527 | vcaballero | /**
|
343 | 1034 | vcaballero | * A?ade un nuevo Listener al SelectionSupport.
|
344 | 527 | vcaballero | *
|
345 | 1034 | vcaballero | * @param listener SelectionListener.
|
346 | 527 | vcaballero | */
|
347 | 460 | fernando | public void addSelectionListener(SelectionListener listener) { |
348 | selectionSupport.addSelectionListener(listener); |
||
349 | } |
||
350 | |||
351 | 527 | vcaballero | /**
|
352 | 1034 | vcaballero | * Borra un Listener al SelectionSupport.
|
353 | 527 | vcaballero | *
|
354 | 1034 | vcaballero | * @param listener Listener a borrar.
|
355 | 527 | vcaballero | */
|
356 | 460 | fernando | public void removeSelectionListener(SelectionListener listener) { |
357 | selectionSupport.removeSelectionListener(listener); |
||
358 | } |
||
359 | 527 | vcaballero | |
360 | /**
|
||
361 | 1034 | vcaballero | * Borra la selecci?n.
|
362 | 527 | vcaballero | */
|
363 | 460 | fernando | public void clearSelection() { |
364 | selectionSupport.clearSelection(); |
||
365 | } |
||
366 | 527 | vcaballero | |
367 | /**
|
||
368 | 1034 | vcaballero | * Develve un FBitSet con los ?ndices de los elementos seleccionados.
|
369 | 527 | vcaballero | *
|
370 | 1034 | vcaballero | * @return FBitset con los elementos seleccionados.
|
371 | 527 | vcaballero | */
|
372 | 884 | fernando | public FBitSet getSelection() {
|
373 | 460 | fernando | return selectionSupport.getSelection();
|
374 | } |
||
375 | 1034 | vcaballero | |
376 | /**
|
||
377 | * Devuelve el SelectionSupport.
|
||
378 | *
|
||
379 | * @return SelectinSuport.
|
||
380 | */
|
||
381 | public SelectionSupport getSelectionSupport() {
|
||
382 | 581 | vcaballero | return selectionSupport;
|
383 | } |
||
384 | 1034 | vcaballero | |
385 | 527 | vcaballero | /**
|
386 | 1034 | vcaballero | * Devuelve true si el elemento est? seleccionado.
|
387 | 527 | vcaballero | *
|
388 | 1034 | vcaballero | * @param recordIndex ?ndice del registro.
|
389 | 527 | vcaballero | *
|
390 | 1034 | vcaballero | * @return True si el registro est? seleccionado.
|
391 | 527 | vcaballero | */
|
392 | 460 | fernando | public boolean isSelected(int recordIndex) { |
393 | return selectionSupport.isSelected(recordIndex);
|
||
394 | } |
||
395 | 527 | vcaballero | |
396 | /**
|
||
397 | 1034 | vcaballero | * Inserta una nueva selecci?n.
|
398 | 527 | vcaballero | *
|
399 | 1034 | vcaballero | * @param selection FBitSet.
|
400 | 527 | vcaballero | */
|
401 | 683 | fernando | public void setSelection(FBitSet selection) { |
402 | 460 | fernando | selectionSupport.setSelection(selection); |
403 | } |
||
404 | 546 | fernando | |
405 | 1828 | fernando | private void putMemento(XMLEntity xml) throws XMLException { |
406 | try {
|
||
407 | 1836 | fernando | GDBMSHandler handler = new GDBMSHandler();
|
408 | Memento m = getMemento(); |
||
409 | m.setContentHandler(handler); |
||
410 | m.getXML(); |
||
411 | XMLEntity child = handler.getXMLEntity(); |
||
412 | 3963 | caballero | |
413 | 1828 | fernando | xml.addChild(child); |
414 | } catch (MementoException e) {
|
||
415 | throw new XMLException(e); |
||
416 | 1836 | fernando | } catch (SAXException e) {
|
417 | throw new XMLException(e); |
||
418 | 1828 | fernando | } |
419 | } |
||
420 | |||
421 | 1034 | vcaballero | /**
|
422 | * Devuelve el XMLEntity con la informaci?n necesaria para reproducir el
|
||
423 | * DataSource.
|
||
424 | *
|
||
425 | * @return XMLEntity.
|
||
426 | 1828 | fernando | * @throws XMLException
|
427 | 1034 | vcaballero | */
|
428 | 1828 | fernando | public XMLEntity getXMLEntity() throws XMLException { |
429 | 1034 | vcaballero | XMLEntity xml = new XMLEntity();
|
430 | 1094 | vcaballero | xml.putProperty("className",this.getClass().getName()); |
431 | 581 | vcaballero | xml.addChild(selectionSupport.getXMLEntity()); |
432 | 1828 | fernando | putMemento(xml); |
433 | 1034 | vcaballero | |
434 | 581 | vcaballero | return xml;
|
435 | } |
||
436 | 732 | fernando | |
437 | /**
|
||
438 | 884 | fernando | * @see com.hardcode.gdbms.engine.data.DataSource#getWhereFilter()
|
439 | */
|
||
440 | public long[] getWhereFilter() throws IOException { |
||
441 | return dataSource.getWhereFilter();
|
||
442 | } |
||
443 | 1653 | fernando | |
444 | 16184 | jdominguez | /*
|
445 | 1653 | fernando | * @see com.hardcode.gdbms.engine.data.ReadDriver#getFieldType(int)
|
446 | */
|
||
447 | 10627 | caballero | public int getFieldType(int i) throws ReadDriverException { |
448 | 4863 | fjp | // return dataSource.getFieldType(i);
|
449 | 28975 | vcaballero | if (i>mapping.length-1) |
450 | return dataSource.getFieldType(i);
|
||
451 | 4863 | fjp | return dataSource.getFieldType(mapping[i]);
|
452 | 1653 | fernando | } |
453 | 1828 | fernando | |
454 | 16184 | jdominguez | /*
|
455 | 1828 | fernando | * @see com.hardcode.gdbms.engine.data.DataSource#getDataSourceFactory()
|
456 | */
|
||
457 | public DataSourceFactory getDataSourceFactory() {
|
||
458 | return dataSource.getDataSourceFactory();
|
||
459 | } |
||
460 | |||
461 | 16184 | jdominguez | /*
|
462 | 1828 | fernando | * @see com.hardcode.gdbms.engine.data.DataSource#getAsString()
|
463 | */
|
||
464 | 10627 | caballero | public String getAsString() throws ReadDriverException { |
465 | 1828 | fernando | return dataSource.getAsString();
|
466 | } |
||
467 | 1831 | fernando | |
468 | 16184 | jdominguez | /*
|
469 | 2183 | fernando | * @throws DriverException
|
470 | 1831 | fernando | * @see com.hardcode.gdbms.engine.data.DataSource#remove()
|
471 | */
|
||
472 | 10627 | caballero | public void remove() throws WriteDriverException { |
473 | 1831 | fernando | dataSource.remove(); |
474 | } |
||
475 | 1836 | fernando | |
476 | 16184 | jdominguez | /*
|
477 | 1836 | fernando | * @see com.hardcode.gdbms.engine.data.DataSource#getMemento()
|
478 | */
|
||
479 | public Memento getMemento() throws MementoException { |
||
480 | return dataSource.getMemento();
|
||
481 | } |
||
482 | |||
483 | 16184 | jdominguez | /*
|
484 | 1836 | fernando | * @see com.hardcode.gdbms.engine.data.DataSource#getSourceInfo()
|
485 | */
|
||
486 | 2217 | fernando | public SourceInfo getSourceInfo() {
|
487 | 1836 | fernando | return dataSource.getSourceInfo();
|
488 | } |
||
489 | 2183 | fernando | |
490 | 16184 | jdominguez | /*
|
491 | 2183 | fernando | * @see com.hardcode.gdbms.engine.data.DataSource#getPrimaryKeys()
|
492 | */
|
||
493 | 10627 | caballero | public int[] getPrimaryKeys() throws ReadDriverException { |
494 | 2183 | fernando | return dataSource.getPrimaryKeys();
|
495 | } |
||
496 | |||
497 | 16184 | jdominguez | /*
|
498 | 2183 | fernando | * @see com.hardcode.gdbms.engine.data.DataSource#getPKValue(long)
|
499 | */
|
||
500 | 10627 | caballero | public ValueCollection getPKValue(long rowIndex) throws ReadDriverException { |
501 | 2183 | fernando | return dataSource.getPKValue(rowIndex);
|
502 | } |
||
503 | |||
504 | 16184 | jdominguez | /*
|
505 | 2183 | fernando | * @see com.hardcode.gdbms.engine.data.DataSource#getPKName(int)
|
506 | */
|
||
507 | 10627 | caballero | public String getPKName(int fieldId) throws ReadDriverException { |
508 | 2183 | fernando | return dataSource.getPKName(fieldId);
|
509 | } |
||
510 | |||
511 | 16184 | jdominguez | /*
|
512 | 2183 | fernando | * @see com.hardcode.gdbms.engine.data.DataSource#getPKType(int)
|
513 | */
|
||
514 | 10627 | caballero | public int getPKType(int i) throws ReadDriverException { |
515 | 2183 | fernando | return dataSource.getPKType(i);
|
516 | } |
||
517 | |||
518 | 16184 | jdominguez | /*
|
519 | 2183 | fernando | * @throws DriverException
|
520 | * @see com.hardcode.gdbms.engine.data.DataSource#getPKCardinality()
|
||
521 | */
|
||
522 | 10627 | caballero | public int getPKCardinality() throws ReadDriverException { |
523 | 2183 | fernando | return dataSource.getPKCardinality();
|
524 | } |
||
525 | |||
526 | 16184 | jdominguez | /*
|
527 | 2183 | fernando | * @see com.hardcode.gdbms.engine.data.DataSource#getRow(long)
|
528 | */
|
||
529 | 10627 | caballero | public Value[] getRow(long rowIndex) throws ReadDriverException { |
530 | 4863 | fjp | Value[] withoutVirtuals = new Value[mapping.length]; |
531 | Value[] internal = dataSource.getRow(rowIndex);
|
||
532 | for (int i=0; i < mapping.length; i++) |
||
533 | { |
||
534 | 31040 | fpenarrubia | if (mapping[i] < internal.length)
|
535 | withoutVirtuals[i] = internal[mapping[i]]; |
||
536 | 10627 | caballero | |
537 | 4863 | fjp | } |
538 | return withoutVirtuals;
|
||
539 | 2183 | fernando | } |
540 | |||
541 | 16184 | jdominguez | /*
|
542 | 2183 | fernando | * @see com.hardcode.gdbms.engine.data.DataSource#getFieldNames()
|
543 | */
|
||
544 | 10627 | caballero | public String[] getFieldNames() throws ReadDriverException { |
545 | 31228 | fpenarrubia | int fieldCount=getFieldCount();
|
546 | String[] fieldNames = new String[fieldCount]; |
||
547 | // int j=0;
|
||
548 | // int fieldCount=dataSource.getFieldCount();
|
||
549 | // for (int i=0; i < fieldCount; i++)
|
||
550 | // {
|
||
551 | // if (!dataSource.isVirtualField(i))
|
||
552 | // fieldNames[j++] = dataSource.getFieldName(i);
|
||
553 | //
|
||
554 | // }
|
||
555 | 30943 | vcaballero | for (int i=0; i < fieldCount; i++) |
556 | 4863 | fjp | { |
557 | 31228 | fpenarrubia | fieldNames[i] = getFieldAlias(i); |
558 | 10627 | caballero | |
559 | 4863 | fjp | } |
560 | 31235 | vcaballero | |
561 | 4863 | fjp | return fieldNames;
|
562 | 2183 | fernando | } |
563 | |||
564 | 16184 | jdominguez | /*
|
565 | 2183 | fernando | * @see com.hardcode.gdbms.engine.data.DataSource#getPKNames()
|
566 | */
|
||
567 | 10627 | caballero | public String[] getPKNames() throws ReadDriverException { |
568 | 2183 | fernando | return dataSource.getPKNames();
|
569 | } |
||
570 | |||
571 | public void removeLinksSelectionListener() { |
||
572 | selectionSupport.removeLinkSelectionListener(); |
||
573 | } |
||
574 | 2217 | fernando | |
575 | 16184 | jdominguez | /*
|
576 | 10627 | caballero | * @throws DriverException
|
577 | 2217 | fernando | * @see com.hardcode.gdbms.engine.data.DataSource#getDataWare(int)
|
578 | */
|
||
579 | 10627 | caballero | public DataWare getDataWare(int arg0) throws ReadDriverException { |
580 | 2217 | fernando | return dataSource.getDataWare(arg0);
|
581 | } |
||
582 | 4863 | fjp | |
583 | 10627 | caballero | public int getFieldWidth(int i) throws ReadDriverException { |
584 | 4863 | fjp | return dataSource.getFieldWidth(mapping[i]);
|
585 | // return dataSource.getFieldWidth(i);
|
||
586 | } |
||
587 | |||
588 | 10627 | caballero | public boolean isVirtualField(int fieldId) throws ReadDriverException { |
589 | 4863 | fjp | return dataSource.isVirtualField(fieldId);
|
590 | } |
||
591 | 10627 | caballero | |
592 | 4875 | fjp | /**
|
593 | * Useful to writers, to know the field definitions.
|
||
594 | * NOTE: Maximun precision: 6 decimals. (We may need to change this)
|
||
595 | * @return Description of non virtual fields
|
||
596 | * @throws DriverException
|
||
597 | */
|
||
598 | 10627 | caballero | public FieldDescription[] getFieldsDescription() throws ReadDriverException{ |
599 | 4875 | fjp | int numFields = getFieldCount();
|
600 | FieldDescription[] fieldsDescrip = new FieldDescription[numFields]; |
||
601 | for (int i = 0; i < numFields; i++) { |
||
602 | fieldsDescrip[i] = new FieldDescription();
|
||
603 | int type = getFieldType(i);
|
||
604 | fieldsDescrip[i].setFieldType(type); |
||
605 | fieldsDescrip[i].setFieldName(getFieldName(i)); |
||
606 | fieldsDescrip[i].setFieldLength(getFieldWidth(i)); |
||
607 | 31235 | vcaballero | try{
|
608 | fieldsDescrip[i].setFieldAlias(getFieldAlias(i)); |
||
609 | }catch (Exception e) { |
||
610 | fieldsDescrip[i].setFieldAlias(getFieldName(i)); |
||
611 | } |
||
612 | 6483 | fjp | if (NumberUtilities.isNumeric(type))
|
613 | { |
||
614 | if (!NumberUtilities.isNumericInteger(type))
|
||
615 | // TODO: If there is a lost in precision, this should be changed.
|
||
616 | fieldsDescrip[i].setFieldDecimalCount(6);
|
||
617 | } |
||
618 | else
|
||
619 | 4875 | fjp | fieldsDescrip[i].setFieldDecimalCount(0);
|
620 | 6628 | fjp | // TODO: ?DEFAULTVALUE?
|
621 | // fieldsDescrip[i].setDefaultValue(get)
|
||
622 | 4875 | fjp | } |
623 | return fieldsDescrip;
|
||
624 | } |
||
625 | 5569 | jmvivo | |
626 | 31155 | fpenarrubia | public String getFieldAlias(int i) { |
627 | 31235 | vcaballero | try{
|
628 | return alias[i];
|
||
629 | }catch (ArrayIndexOutOfBoundsException e) { |
||
630 | try {
|
||
631 | return getFieldName(i);
|
||
632 | } catch (ReadDriverException e1) {
|
||
633 | return null; |
||
634 | } |
||
635 | } |
||
636 | 31155 | fpenarrubia | } |
637 | public void setFieldAlias(int idField, String aliasName) { |
||
638 | alias[idField] = aliasName; |
||
639 | } |
||
640 | |||
641 | 31235 | vcaballero | |
642 | 10627 | caballero | public Driver getDriver() { |
643 | 5569 | jmvivo | return this.dataSource.getDriver(); |
644 | } |
||
645 | 6323 | fjp | |
646 | 10627 | caballero | public void reload() throws ReloadDriverException { |
647 | 6323 | fjp | dataSource.reload(); |
648 | 10627 | caballero | try {
|
649 | mapExternalFields(); |
||
650 | } catch (ReadDriverException e) {
|
||
651 | throw new ReloadDriverException(getDriver().getName(),e); |
||
652 | } |
||
653 | |||
654 | 6323 | fjp | } |
655 | |||
656 | public void addDataSourceListener(IDataSourceListener listener) { |
||
657 | dataSource.addDataSourceListener(listener); |
||
658 | 10627 | caballero | |
659 | 6323 | fjp | } |
660 | |||
661 | public void removeDataSourceListener(IDataSourceListener listener) { |
||
662 | dataSource.removeDataSourceListener(listener); |
||
663 | 10627 | caballero | |
664 | 6323 | fjp | } |
665 | 460 | fernando | } |