svn-gvsig-desktop / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / edition / EditableAdapter.java @ 4193
History | View | Annotate | Download (23.1 KB)
1 | 3940 | caballero | package com.iver.cit.gvsig.fmap.edition; |
---|---|---|---|
2 | |||
3 | 4061 | caballero | import java.awt.Image; |
4 | import java.io.IOException; |
||
5 | import java.util.HashMap; |
||
6 | 3940 | caballero | |
7 | 4061 | caballero | import com.hardcode.driverManager.DriverLoadException; |
8 | 3940 | caballero | import com.hardcode.gdbms.engine.data.DataSourceFactory; |
9 | import com.hardcode.gdbms.engine.data.NoSuchTableException; |
||
10 | import com.hardcode.gdbms.engine.data.driver.DriverException; |
||
11 | import com.hardcode.gdbms.engine.data.driver.ObjectDriver; |
||
12 | import com.hardcode.gdbms.engine.data.edition.DataWare; |
||
13 | import com.hardcode.gdbms.engine.values.Value; |
||
14 | 4026 | caballero | import com.iver.cit.gvsig.fmap.core.DefaultRow; |
15 | 3940 | caballero | import com.iver.cit.gvsig.fmap.core.IRow; |
16 | import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
||
17 | import com.iver.cit.gvsig.fmap.edition.commands.AddRowCommand; |
||
18 | 4120 | caballero | import com.iver.cit.gvsig.fmap.edition.commands.Command; |
19 | 3940 | caballero | import com.iver.cit.gvsig.fmap.edition.commands.CommandCollection; |
20 | import com.iver.cit.gvsig.fmap.edition.commands.CommandRecord; |
||
21 | import com.iver.cit.gvsig.fmap.edition.commands.MemoryCommandRecord; |
||
22 | import com.iver.cit.gvsig.fmap.edition.commands.ModifyRowCommand; |
||
23 | import com.iver.cit.gvsig.fmap.edition.commands.RemoveRowCommand; |
||
24 | import com.iver.cit.gvsig.fmap.layers.FBitSet; |
||
25 | import com.iver.cit.gvsig.fmap.layers.LayerFactory; |
||
26 | import com.iver.cit.gvsig.fmap.layers.SelectableDataSource; |
||
27 | |||
28 | |||
29 | /**
|
||
30 | * DOCUMENT ME!
|
||
31 | *
|
||
32 | * @author Vicente Caballero Navarro
|
||
33 | */
|
||
34 | public class EditableAdapter implements IEditableSource { |
||
35 | 4171 | fjp | protected boolean isEditing = false; |
36 | 3940 | caballero | private SelectableDataSource ds = null; |
37 | protected FBitSet delRows = new FBitSet(); |
||
38 | private CommandRecord cr;
|
||
39 | 3996 | caballero | |
40 | 3940 | caballero | private Image selectionImage; |
41 | |||
42 | /**
|
||
43 | * Flag que indica que hay que tomar las siguientes operaciones como una
|
||
44 | * operaci?n at?mica
|
||
45 | */
|
||
46 | private boolean complex = false; |
||
47 | private CommandCollection commands = null; |
||
48 | |||
49 | /*
|
||
50 | * Establece una relaci?n entre los ?ndices de las geometr?as en el
|
||
51 | * EditableFeatureSource y los ?ndices en el fichero de expansi?n
|
||
52 | 4085 | fjp | * FJP: CAMBIO: NECESITAMOS TRABAJAR CON FEATURE Y FEATUREITERATOR
|
53 | * PARA IR PREPARANDO EL CAMINO, GUARDAMOS EL FEATUREID (STRING)
|
||
54 | * COMO CLAVE, Y COMO VALOR, EL INDICE DENTRO DEL FICHERO
|
||
55 | * DE EXPANSION (Integer).
|
||
56 | * Lo de que FeatureId sea un String es por compatibilidad
|
||
57 | * con OGC. Seg?n OGC, una Feature tiene que tener un Id string
|
||
58 | * En el caso de los randomaccess, ser?n el id de registro
|
||
59 | * En los casos de base de datos espaciales, supongo
|
||
60 | * que siempre ser? num?rico tambi?n, pero lo tendremos
|
||
61 | 4120 | caballero | * que convertir a string. Lo que est? claro es que
|
62 | 4085 | fjp | * NO se puede confiar nunca en que sea algo correlativo
|
63 | * (1, 2, 3, 4, 5, ... => FALSO!!)
|
||
64 | 3940 | caballero | */
|
65 | protected HashMap relations = new HashMap(); |
||
66 | |||
67 | /*
|
||
68 | * Fichero en el que se guardan las nuevas geometr?as, producto de adiciones
|
||
69 | * o de modificaciones
|
||
70 | */
|
||
71 | protected ExpansionFile expansionFile;
|
||
72 | protected int numAdd = 0; |
||
73 | private ObjectDriver editingDriver = new myObjectDriver(); |
||
74 | private SelectableDataSource ods;
|
||
75 | |||
76 | /**
|
||
77 | * Crea un nuevo EditableAdapter.
|
||
78 | */
|
||
79 | public EditableAdapter() {
|
||
80 | expansionFile = new MemoryExpansionFile();
|
||
81 | cr = new MemoryCommandRecord();
|
||
82 | } |
||
83 | |||
84 | /**
|
||
85 | * DOCUMENT ME!
|
||
86 | *
|
||
87 | * @param ds DOCUMENT ME!
|
||
88 | */
|
||
89 | public void setOriginalDataSource(SelectableDataSource ds) { |
||
90 | this.ods = ds;
|
||
91 | } |
||
92 | |||
93 | /**
|
||
94 | * DOCUMENT ME!
|
||
95 | *
|
||
96 | * @throws EditionException DOCUMENT ME!
|
||
97 | */
|
||
98 | public void startEdition() throws EditionException { |
||
99 | isEditing = true;
|
||
100 | } |
||
101 | |||
102 | /**
|
||
103 | * DOCUMENT ME!
|
||
104 | *
|
||
105 | * @param writer DOCUMENT ME!
|
||
106 | *
|
||
107 | * @throws EditionException DOCUMENT ME!
|
||
108 | */
|
||
109 | public void stopEdition(IWriter writer) throws EditionException { |
||
110 | writer.preProcess(); |
||
111 | |||
112 | try {
|
||
113 | for (int i = 0; i < getRowCount(); i++) { |
||
114 | IRowEdited rowEdited = getRow(i); |
||
115 | 3996 | caballero | |
116 | if (rowEdited != null) { |
||
117 | writer.process(rowEdited); |
||
118 | } |
||
119 | 3940 | caballero | } |
120 | } catch (DriverIOException e) {
|
||
121 | e.printStackTrace(); |
||
122 | throw new EditionException(e); |
||
123 | } catch (IOException e) { |
||
124 | e.printStackTrace(); |
||
125 | throw new EditionException(e); |
||
126 | } |
||
127 | |||
128 | writer.postProcess(); |
||
129 | isEditing = false;
|
||
130 | } |
||
131 | |||
132 | /**
|
||
133 | * DOCUMENT ME!
|
||
134 | *
|
||
135 | * @throws IOException DOCUMENT ME!
|
||
136 | */
|
||
137 | public void cancelEdition() throws IOException { |
||
138 | isEditing = false;
|
||
139 | expansionFile.close(); |
||
140 | } |
||
141 | |||
142 | /* (non-Javadoc)
|
||
143 | * @see com.iver.cit.gvsig.fmap.edition.IEditableSource#getRow(int)
|
||
144 | */
|
||
145 | public IRowEdited getRow(int index) throws DriverIOException, IOException { |
||
146 | 3996 | caballero | int calculatedIndex=getCalculatedIndex(index);
|
147 | Integer integer = new Integer(calculatedIndex); |
||
148 | 4191 | fjp | DefaultRowEdited edRow = null;
|
149 | 3940 | caballero | //Si no est? en el fichero de expansi?n
|
150 | 4191 | fjp | if (!relations.containsKey(integer)) {
|
151 | 3996 | caballero | try {
|
152 | 4191 | fjp | /* edRow = new DefaultRowEdited(new DefaultRow(ods.getRow(calculatedIndex), "" + index),
|
153 | DefaultRowEdited.STATUS_ORIGINAL, index); */
|
||
154 | edRow = new DefaultRowEdited(new DefaultRow(ods.getRow(calculatedIndex)), |
||
155 | 4115 | fjp | DefaultRowEdited.STATUS_ORIGINAL, index); |
156 | 3996 | caballero | } catch (DriverException e) {
|
157 | 4061 | caballero | throw new DriverIOException(e); |
158 | 3996 | caballero | } |
159 | |||
160 | 3940 | caballero | return edRow;
|
161 | } else {
|
||
162 | int num = ((Integer) relations.get(integer)).intValue(); |
||
163 | 4191 | fjp | |
164 | // return expansionFile.getRow(num);
|
||
165 | IRowEdited rowFromExpansion = expansionFile.getRow(num); |
||
166 | // ?Habr?a que hacer aqu? setID(index + "")?
|
||
167 | edRow = new DefaultRowEdited(rowFromExpansion.getLinkedRow().cloneRow(), rowFromExpansion.getStatus(), index);
|
||
168 | return edRow;
|
||
169 | 3940 | caballero | } |
170 | } |
||
171 | |||
172 | /**
|
||
173 | * DOCUMENT ME!
|
||
174 | *
|
||
175 | * @return DOCUMENT ME!
|
||
176 | *
|
||
177 | * @throws DriverIOException DOCUMENT ME!
|
||
178 | * @throws IOException DOCUMENT ME!
|
||
179 | */
|
||
180 | public int getRowCount() throws DriverIOException, IOException { |
||
181 | 4061 | caballero | try {
|
182 | return (int) (ods.getRowCount() + numAdd) - delRows.cardinality();// - expansionFile.getInvalidRows().cardinality(); |
||
183 | } catch (DriverException e) {
|
||
184 | throw new DriverIOException(e); |
||
185 | } |
||
186 | 3996 | caballero | |
187 | 4061 | caballero | |
188 | 3940 | caballero | } |
189 | |||
190 | /**
|
||
191 | * DOCUMENT ME!
|
||
192 | *
|
||
193 | * @param row DOCUMENT ME!
|
||
194 | *
|
||
195 | * @throws DriverIOException DOCUMENT ME!
|
||
196 | * @throws IOException DOCUMENT ME!
|
||
197 | */
|
||
198 | 4120 | caballero | public void addRow(IRow row,String descrip) throws DriverIOException, IOException { |
199 | 4193 | fjp | int calculatedIndex = doAddRow(row);
|
200 | Command command=new AddRowCommand(this, row, calculatedIndex); |
||
201 | 4120 | caballero | command.setDescription(descrip); |
202 | 3940 | caballero | if (complex) {
|
203 | 4120 | caballero | commands.add(command); |
204 | 3940 | caballero | } else {
|
205 | 4120 | caballero | cr.pushCommand(command); |
206 | 3940 | caballero | } |
207 | } |
||
208 | |||
209 | /**
|
||
210 | * DOCUMENT ME!
|
||
211 | *
|
||
212 | * @throws DriverIOException DOCUMENT ME!
|
||
213 | * @throws IOException DOCUMENT ME!
|
||
214 | */
|
||
215 | public void undo() throws DriverIOException, IOException { |
||
216 | 3956 | caballero | //seleccion.clear();
|
217 | 3940 | caballero | if (moreUndoCommands()) {
|
218 | cr.undoCommand(); |
||
219 | } |
||
220 | } |
||
221 | |||
222 | /**
|
||
223 | * DOCUMENT ME!
|
||
224 | *
|
||
225 | * @throws DriverIOException DOCUMENT ME!
|
||
226 | * @throws IOException DOCUMENT ME!
|
||
227 | */
|
||
228 | public void redo() throws DriverIOException, IOException { |
||
229 | 3956 | caballero | //seleccion.clear();
|
230 | 3940 | caballero | if (moreRedoCommands()) {
|
231 | cr.redoCommand(); |
||
232 | } |
||
233 | } |
||
234 | |||
235 | /**
|
||
236 | * DOCUMENT ME!
|
||
237 | *
|
||
238 | * @return DOCUMENT ME!
|
||
239 | */
|
||
240 | public boolean moreUndoCommands() { |
||
241 | return cr.moreUndoCommands();
|
||
242 | } |
||
243 | |||
244 | /**
|
||
245 | * DOCUMENT ME!
|
||
246 | *
|
||
247 | * @return DOCUMENT ME!
|
||
248 | */
|
||
249 | public boolean moreRedoCommands() { |
||
250 | return cr.moreRedoCommands();
|
||
251 | } |
||
252 | |||
253 | /* (non-Javadoc)
|
||
254 | * @see com.iver.cit.gvsig.fmap.edition.IEditableSource#removeRow(int)
|
||
255 | */
|
||
256 | 4120 | caballero | public void removeRow(int index,String descrip) throws IOException, DriverIOException { |
257 | 3996 | caballero | int calculatedIndex = getCalculatedIndex(index);
|
258 | 4120 | caballero | Command command=new RemoveRowCommand(this, calculatedIndex); |
259 | command.setDescription(descrip); |
||
260 | 3996 | caballero | if (complex) {
|
261 | 4120 | caballero | commands.add(command); |
262 | 3940 | caballero | } else {
|
263 | 4120 | caballero | cr.pushCommand(command); |
264 | 3940 | caballero | } |
265 | 3996 | caballero | doRemoveRow(calculatedIndex); |
266 | 3940 | caballero | } |
267 | |||
268 | /* (non-Javadoc)
|
||
269 | * @see com.iver.cit.gvsig.fmap.edition.IEditableSource#modifyRow(int, com.iver.cit.gvsig.fmap.core.IRow)
|
||
270 | */
|
||
271 | 4120 | caballero | public void modifyRow(int index, IRow row,String descrip) |
272 | 3940 | caballero | throws IOException, DriverIOException { |
273 | 3996 | caballero | int calculatedIndex = getCalculatedIndex(index);
|
274 | 4026 | caballero | int pos = doModifyRow(calculatedIndex, row);
|
275 | 4120 | caballero | Command command=new ModifyRowCommand(this, calculatedIndex, pos, row); |
276 | command.setDescription(descrip); |
||
277 | 3940 | caballero | if (complex) {
|
278 | 4120 | caballero | commands.add(command); |
279 | 3940 | caballero | } else {
|
280 | 4120 | caballero | cr.pushCommand(command); |
281 | 3940 | caballero | } |
282 | } |
||
283 | |||
284 | /**
|
||
285 | * DOCUMENT ME!
|
||
286 | */
|
||
287 | public void compact() { |
||
288 | expansionFile.compact(relations); |
||
289 | } |
||
290 | |||
291 | /**
|
||
292 | * DOCUMENT ME!
|
||
293 | *
|
||
294 | * @param i DOCUMENT ME!
|
||
295 | */
|
||
296 | public void setImage(Image i) { |
||
297 | selectionImage = i; |
||
298 | } |
||
299 | |||
300 | /**
|
||
301 | * DOCUMENT ME!
|
||
302 | *
|
||
303 | * @return DOCUMENT ME!
|
||
304 | */
|
||
305 | public Image getImage() { |
||
306 | 4061 | caballero | return selectionImage;
|
307 | 3940 | caballero | } |
308 | |||
309 | /**
|
||
310 | * DOCUMENT ME!
|
||
311 | */
|
||
312 | public void startComplexRow() { |
||
313 | complex = true;
|
||
314 | commands = new CommandCollection();
|
||
315 | } |
||
316 | |||
317 | /**
|
||
318 | * DOCUMENT ME!
|
||
319 | *
|
||
320 | * @throws IOException DOCUMENT ME!
|
||
321 | * @throws DriverIOException DOCUMENT ME!
|
||
322 | */
|
||
323 | public void endComplexRow() throws IOException, DriverIOException { |
||
324 | cr.pushCommand(commands); |
||
325 | complex = false;
|
||
326 | } |
||
327 | |||
328 | /**
|
||
329 | * Actualiza en el mapa de ?ndices, la posici?n en la que estaba la
|
||
330 | * geometr?a antes de ser modificada. Se marca como v?lida, en caso de que
|
||
331 | * fuera una modificaci?n de una geometr?a que estuviese en el fichero de
|
||
332 | * expansi?n antes de ser modificada y se pone el puntero de escritura del
|
||
333 | * expansion file a justo despues de la penultima geometr?a
|
||
334 | *
|
||
335 | * @param geometryIndex ?ndice de la geometr?a que se quiere deshacer su
|
||
336 | * modificaci?n
|
||
337 | * @param previousExpansionFileIndex ?ndice que ten?a antes la geometr?a en
|
||
338 | * el expansionFile. Si vale -1 quiere decir que es una
|
||
339 | * modificaci?n de una geometr?a original y por tanto no hay que
|
||
340 | * actualizar el mapa de indices sino eliminar su entrada.
|
||
341 | *
|
||
342 | * @throws IOException
|
||
343 | * @throws DriverIOException
|
||
344 | */
|
||
345 | public void undoModifyRow(int geometryIndex, int previousExpansionFileIndex) |
||
346 | throws IOException, DriverIOException { |
||
347 | if (previousExpansionFileIndex == -1) { |
||
348 | //Se elimina de las relaciones y del fichero de expansi?n
|
||
349 | relations.remove(new Integer(geometryIndex)); |
||
350 | expansionFile.deleteLastRow(); |
||
351 | } else {
|
||
352 | //Se actualiza la relaci?n de ?ndices
|
||
353 | relations.put(new Integer(geometryIndex), |
||
354 | new Integer(previousExpansionFileIndex)); |
||
355 | } |
||
356 | } |
||
357 | |||
358 | /**
|
||
359 | * Elimina una geometria. Si es una geometr?a original de la capa en
|
||
360 | * edici?n se marca como eliminada (haya sido modificada o no). Si es una
|
||
361 | * geometr?a a?adida posteriormente se invalida en el fichero de
|
||
362 | * expansi?n, para que una futura compactaci?n termine con ella.
|
||
363 | *
|
||
364 | * @param index ?ndice de la geometr?a.
|
||
365 | *
|
||
366 | * @throws DriverIOException
|
||
367 | * @throws IOException
|
||
368 | */
|
||
369 | 4191 | fjp | public IRow doRemoveRow(int index) throws DriverIOException, IOException { |
370 | 3996 | caballero | //Llega un calculatedIndex
|
371 | 3940 | caballero | delRows.set(index, true);
|
372 | 3996 | caballero | System.err.println("Elimina una Row en la posici?n: " + index); |
373 | 4191 | fjp | // TODO: Con tablas no es necesario devolver la anterior feature. Por ahora.
|
374 | return null; |
||
375 | 3940 | caballero | } |
376 | |||
377 | /**
|
||
378 | * Si se intenta modificar una geometr?a original de la capa en edici?n se
|
||
379 | * a?ade al fichero de expansi?n y se registra la posici?n en la que se
|
||
380 | * a?adi?. Si se intenta modificar una geometria que se encuentra en el
|
||
381 | * fichero de expansi?n (por ser nueva o original pero modificada) se
|
||
382 | * invoca el m?todo modifyGeometry y se actualiza el ?ndice de la
|
||
383 | * geometria en el fichero.
|
||
384 | *
|
||
385 | * @param index DOCUMENT ME!
|
||
386 | * @param feat DOCUMENT ME!
|
||
387 | *
|
||
388 | * @return DOCUMENT ME!
|
||
389 | *
|
||
390 | * @throws IOException
|
||
391 | * @throws DriverIOException
|
||
392 | */
|
||
393 | public int doModifyRow(int index, IRow feat) |
||
394 | throws IOException, DriverIOException { |
||
395 | int pos = -1; |
||
396 | Integer integer = new Integer(index); |
||
397 | 3996 | caballero | System.err.println("Modifica una Row en la posici?n: " + index); |
398 | 3940 | caballero | //Si la geometr?a no ha sido modificada
|
399 | if (!relations.containsKey(integer)) {
|
||
400 | int expansionIndex = expansionFile.addRow(feat);
|
||
401 | relations.put(integer, new Integer(expansionIndex)); |
||
402 | } else {
|
||
403 | //Obtenemos el ?ndice en el fichero de expansi?n
|
||
404 | int num = ((Integer) relations.get(integer)).intValue(); |
||
405 | pos = num; |
||
406 | 3996 | caballero | |
407 | 3940 | caballero | /*
|
408 | * Se modifica la geometr?a y nos guardamos el ?ndice dentro del fichero
|
||
409 | * de expansi?n en el que se encuentra la geometr?a modificada
|
||
410 | */
|
||
411 | num = expansionFile.modifyRow(num, feat); |
||
412 | |||
413 | /*
|
||
414 | * Actualiza la relaci?n del ?ndice de la geometr?a al ?ndice en el fichero
|
||
415 | * de expansi?n.
|
||
416 | */
|
||
417 | relations.put(integer, new Integer(num)); |
||
418 | } |
||
419 | |||
420 | return pos;
|
||
421 | } |
||
422 | |||
423 | /**
|
||
424 | * A?ade una geometria al fichero de expansi?n y guarda la correspondencia
|
||
425 | * en la tabla relations.
|
||
426 | *
|
||
427 | * @param feat geometr?a a guardar.
|
||
428 | *
|
||
429 | 4193 | fjp | * @return calculatedIndex
|
430 | 3940 | caballero | *
|
431 | * @throws DriverIOException
|
||
432 | * @throws IOException
|
||
433 | */
|
||
434 | public int doAddRow(IRow feat) throws DriverIOException, IOException { |
||
435 | // A?ade la geometr?a
|
||
436 | 4191 | fjp | // int virtualIndex = 0;
|
437 | int calculatedIndex = -1; |
||
438 | 3996 | caballero | |
439 | 4193 | fjp | try {
|
440 | calculatedIndex = (int) ods.getRowCount() + numAdd;
|
||
441 | // int externalIndex = getRowCount();
|
||
442 | // calculatedIndex = getCalculatedIndex(externalIndex);
|
||
443 | } catch (DriverException e) {
|
||
444 | 4061 | caballero | throw new DriverIOException(e); |
445 | 4193 | fjp | } |
446 | 3996 | caballero | |
447 | 3940 | caballero | int pos = expansionFile.addRow(feat);
|
448 | 4191 | fjp | relations.put(new Integer(calculatedIndex), new Integer(pos)); |
449 | 3940 | caballero | numAdd++; |
450 | 4191 | fjp | System.err.println("A?ade una Row en la posici?n: " + calculatedIndex); |
451 | return calculatedIndex;
|
||
452 | 3940 | caballero | } |
453 | |||
454 | /**
|
||
455 | * Se desmarca como invalidada en el fichero de expansion o como eliminada
|
||
456 | * en el fichero original
|
||
457 | *
|
||
458 | * @param index DOCUMENT ME!
|
||
459 | *
|
||
460 | * @throws IOException
|
||
461 | * @throws DriverIOException
|
||
462 | */
|
||
463 | public void undoRemoveRow(int index) throws IOException, DriverIOException { |
||
464 | 4061 | caballero | delRows.set(index, false);
|
465 | 3940 | caballero | } |
466 | |||
467 | /**
|
||
468 | * Se elimina del final del fichero de expansi?n poniendo el puntero de
|
||
469 | * escritura apuntando al final de la pen?ltima geometr?a. Deber? quitar
|
||
470 | * la relaci?n del mapa de relaciones
|
||
471 | *
|
||
472 | * @param index ?ndice de la geometr?a que se a?adi?
|
||
473 | *
|
||
474 | * @throws DriverIOException
|
||
475 | * @throws IOException
|
||
476 | */
|
||
477 | 4191 | fjp | public void undoAddRow(int calculatedIndex) throws DriverIOException, IOException { |
478 | 3940 | caballero | expansionFile.deleteLastRow(); |
479 | 4191 | fjp | relations.remove(new Integer(calculatedIndex)); |
480 | 3940 | caballero | numAdd--; |
481 | } |
||
482 | |||
483 | /*
|
||
484 | * (non-Javadoc)
|
||
485 | *
|
||
486 | * @see com.iver.cit.gvsig.fmap.layers.VectorialAdapter#getRecordset()
|
||
487 | */
|
||
488 | 3956 | caballero | public SelectableDataSource getRecordset() throws DriverLoadException { |
489 | 3940 | caballero | if (isEditing) {
|
490 | if (ds == null) { |
||
491 | String name = LayerFactory.getDataSourceFactory().addDataSource((ObjectDriver) editingDriver);
|
||
492 | |||
493 | try {
|
||
494 | ds = new SelectableDataSource(LayerFactory.getDataSourceFactory()
|
||
495 | 3996 | caballero | .createRandomDataSource(name, |
496 | DataSourceFactory.AUTOMATIC_OPENING)); |
||
497 | 3940 | caballero | } catch (NoSuchTableException e) {
|
498 | throw new RuntimeException(e); |
||
499 | } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
|
||
500 | throw new RuntimeException(e); |
||
501 | } |
||
502 | } |
||
503 | |||
504 | return ds;
|
||
505 | } else {
|
||
506 | return ods;
|
||
507 | } |
||
508 | } |
||
509 | 3996 | caballero | |
510 | /**
|
||
511 | * DOCUMENT ME!
|
||
512 | *
|
||
513 | * @param sds DOCUMENT ME!
|
||
514 | */
|
||
515 | public void setRecordSet(SelectableDataSource sds) { |
||
516 | this.ods = sds;
|
||
517 | 3963 | caballero | } |
518 | 3940 | caballero | |
519 | /**
|
||
520 | * DOCUMENT ME!
|
||
521 | *
|
||
522 | * @return
|
||
523 | */
|
||
524 | public FBitSet getSelection() {
|
||
525 | 4135 | fjp | /* try {
|
526 | return getRecordset().getSelection();
|
||
527 | } catch (DriverLoadException e) {
|
||
528 | // TODO Auto-generated catch block
|
||
529 | e.printStackTrace();
|
||
530 | }
|
||
531 | return null; */
|
||
532 | 4159 | fjp | return getRecordset().getSelection();
|
533 | 3940 | caballero | } |
534 | 4061 | caballero | public void setSelection(FBitSet selection) { |
535 | 4135 | fjp | /* try {
|
536 | getRecordset().setSelection(selection);
|
||
537 | } catch (DriverLoadException e) {
|
||
538 | // TODO Auto-generated catch block
|
||
539 | e.printStackTrace();
|
||
540 | } */
|
||
541 | 4159 | fjp | getRecordset().setSelection(selection); |
542 | 4061 | caballero | } |
543 | 3940 | caballero | /**
|
544 | * DOCUMENT ME!
|
||
545 | *
|
||
546 | 3996 | caballero | * @return DOCUMENT ME!
|
547 | */
|
||
548 | public boolean isEditing() { |
||
549 | return isEditing;
|
||
550 | } |
||
551 | protected int getInversedIndex(long rowIndex) { |
||
552 | int intervalNotDeleted=0; |
||
553 | int antDeleted=-1; |
||
554 | int idPedido = (int) rowIndex; |
||
555 | int numNotDeleted=0; |
||
556 | int numBorradosAnt = 0; |
||
557 | |||
558 | for (int i = delRows.nextSetBit(0); i>=0; i = delRows.nextSetBit(i+1)) { |
||
559 | intervalNotDeleted = i-antDeleted-1;
|
||
560 | numNotDeleted += intervalNotDeleted; |
||
561 | if (i > idPedido){
|
||
562 | numNotDeleted = numNotDeleted + (i - idPedido); |
||
563 | break;
|
||
564 | } |
||
565 | numBorradosAnt++; |
||
566 | antDeleted = i; |
||
567 | } |
||
568 | 4061 | caballero | numNotDeleted = idPedido-numBorradosAnt; |
569 | 4120 | caballero | //System.out.println("Piden Viejo : "+ rowIndex + " y devuelvo como nuevo " + (numNotDeleted));
|
570 | 3996 | caballero | return numNotDeleted;
|
571 | } |
||
572 | |||
573 | /**
|
||
574 | * DOCUMENT ME!
|
||
575 | *
|
||
576 | * @param rowIndex DOCUMENT ME!
|
||
577 | *
|
||
578 | * @return DOCUMENT ME!
|
||
579 | */
|
||
580 | protected int getCalculatedIndex(long rowIndex) { |
||
581 | int numNotDeleted=0; |
||
582 | int intervalNotDeleted=0; |
||
583 | int antDeleted=-1; |
||
584 | int calculatedIndex;
|
||
585 | int idPedido = (int) rowIndex; |
||
586 | int numBorradosAnt = 0; |
||
587 | |||
588 | for (int i = delRows.nextSetBit(0); i>=0; i = delRows.nextSetBit(i+1)) { |
||
589 | intervalNotDeleted = i-antDeleted -1 ;
|
||
590 | numNotDeleted += intervalNotDeleted; |
||
591 | if (numNotDeleted > idPedido)
|
||
592 | { |
||
593 | break;
|
||
594 | } |
||
595 | numBorradosAnt++; |
||
596 | antDeleted = i; |
||
597 | } |
||
598 | calculatedIndex = numBorradosAnt + idPedido; |
||
599 | 4120 | caballero | //System.out.println("Piden Registro : "+ rowIndex + " y devuelvo el " + (calculatedIndex));
|
600 | 3996 | caballero | return calculatedIndex;
|
601 | } |
||
602 | |||
603 | /**
|
||
604 | * DOCUMENT ME!
|
||
605 | *
|
||
606 | 3940 | caballero | * @author Vicente Caballero Navarro
|
607 | */
|
||
608 | private class myObjectDriver implements ObjectDriver { |
||
609 | /*
|
||
610 | * (non-Javadoc)
|
||
611 | *
|
||
612 | * @see com.hardcode.gdbms.engine.data.driver.ObjectDriver#getPrimaryKeys()
|
||
613 | */
|
||
614 | public int[] getPrimaryKeys() throws DriverException { |
||
615 | 4061 | caballero | return ods.getPrimaryKeys();
|
616 | // int[] pk=new int[1];
|
||
617 | /*for (int i=0;i<getRowCount();i++){
|
||
618 | pk[i]=i;
|
||
619 | }*/
|
||
620 | // pk[0]=1;
|
||
621 | // return pk;
|
||
622 | 3940 | caballero | } |
623 | |||
624 | /*
|
||
625 | * (non-Javadoc)
|
||
626 | *
|
||
627 | * @see com.hardcode.gdbms.engine.data.driver.ObjectDriver#write(com.hardcode.gdbms.engine.data.edition.DataWare)
|
||
628 | */
|
||
629 | public void write(DataWare dataWare) throws DriverException { |
||
630 | 4061 | caballero | DataWare dataWareOrig = ods.getDataWare(DataSourceFactory.DATA_WARE_DIRECT_MODE); |
631 | dataWareOrig.commitTrans(); |
||
632 | 3940 | caballero | } |
633 | |||
634 | /*
|
||
635 | * (non-Javadoc)
|
||
636 | *
|
||
637 | * @see com.hardcode.gdbms.engine.data.driver.GDBMSDriver#setDataSourceFactory(com.hardcode.gdbms.engine.data.DataSourceFactory)
|
||
638 | */
|
||
639 | public void setDataSourceFactory(DataSourceFactory dsf) { |
||
640 | 4061 | caballero | ods.setDataSourceFactory(dsf); |
641 | 3940 | caballero | } |
642 | |||
643 | /*
|
||
644 | * (non-Javadoc)
|
||
645 | *
|
||
646 | * @see com.hardcode.driverManager.Driver#getName()
|
||
647 | */
|
||
648 | public String getName() { |
||
649 | 4061 | caballero | return ods.getName();
|
650 | 3940 | caballero | } |
651 | |||
652 | /*
|
||
653 | * (non-Javadoc)
|
||
654 | *
|
||
655 | * @see com.hardcode.gdbms.engine.data.driver.ReadAccess#getFieldValue(long,
|
||
656 | * int)
|
||
657 | */
|
||
658 | public Value getFieldValue(long rowIndex, int fieldId) |
||
659 | throws DriverException {
|
||
660 | // Si no est? en el fichero de expansi?n
|
||
661 | 3996 | caballero | Integer integer = new Integer(getCalculatedIndex(rowIndex)); |
662 | 3940 | caballero | |
663 | try {
|
||
664 | if (!relations.containsKey(integer)) {
|
||
665 | 3996 | caballero | return ods.getFieldValue(rowIndex, fieldId);
|
666 | 3940 | caballero | } else {
|
667 | int num = ((Integer) relations.get(integer)).intValue(); |
||
668 | 3996 | caballero | DefaultRowEdited feat = (DefaultRowEdited) expansionFile.getRow(num); |
669 | 3940 | caballero | |
670 | 3996 | caballero | if (feat == null) { |
671 | return null; |
||
672 | } |
||
673 | |||
674 | 3940 | caballero | return feat.getAttribute(fieldId);
|
675 | } |
||
676 | } catch (DriverException e) {
|
||
677 | e.printStackTrace(); |
||
678 | throw new DriverException(e); |
||
679 | } catch (IOException e) { |
||
680 | e.printStackTrace(); |
||
681 | throw new DriverException(e); |
||
682 | } |
||
683 | 3996 | caballero | |
684 | /**
|
||
685 | * try { if (!relations.containsKey(integer)) { // Si ha sido
|
||
686 | * eliminada if (delRows.get(integer.intValue())) { return null; }
|
||
687 | * else { return ods.getFieldValue(rowIndex, fieldId); }} else {
|
||
688 | * int num = ((Integer) relations.get(integer)).intValue();
|
||
689 | * DefaultRowEdited feat = (DefaultRowEdited)
|
||
690 | * expansionFile.getRow(num); if (feat==null)return null; return
|
||
691 | * feat.getAttribute(fieldId); }} catch (DriverException e) {
|
||
692 | * e.printStackTrace(); throw new DriverException(e); } catch
|
||
693 | * (IOException e) { e.printStackTrace(); throw new
|
||
694 | * DriverException(e); }
|
||
695 | */
|
||
696 | 3940 | caballero | } |
697 | |||
698 | /*
|
||
699 | * (non-Javadoc)
|
||
700 | *
|
||
701 | * @see com.hardcode.gdbms.engine.data.driver.ReadAccess#getFieldCount()
|
||
702 | */
|
||
703 | public int getFieldCount() throws DriverException { |
||
704 | // TODO Por ahora, no dejamos que se a?adan campos
|
||
705 | return ods.getFieldCount();
|
||
706 | } |
||
707 | |||
708 | /*
|
||
709 | * (non-Javadoc)
|
||
710 | *
|
||
711 | * @see com.hardcode.gdbms.engine.data.driver.ReadAccess#getFieldName(int)
|
||
712 | */
|
||
713 | public String getFieldName(int fieldId) throws DriverException { |
||
714 | return ods.getFieldName(fieldId);
|
||
715 | } |
||
716 | |||
717 | /*
|
||
718 | * (non-Javadoc)
|
||
719 | *
|
||
720 | * @see com.hardcode.gdbms.engine.data.driver.ReadAccess#getRowCount()
|
||
721 | */
|
||
722 | public long getRowCount() { |
||
723 | 4061 | caballero | try {
|
724 | return (int) (ods.getRowCount() + numAdd) - delRows.cardinality();// - expansionFile.getInvalidRows().cardinality(); |
||
725 | } catch (DriverException e) {
|
||
726 | // TODO Auto-generated catch block
|
||
727 | e.printStackTrace(); |
||
728 | } |
||
729 | 3996 | caballero | |
730 | 4061 | caballero | return 0; |
731 | 3940 | caballero | } |
732 | |||
733 | /*
|
||
734 | * (non-Javadoc)
|
||
735 | *
|
||
736 | * @see com.hardcode.gdbms.engine.data.driver.ReadAccess#getFieldType(int)
|
||
737 | */
|
||
738 | public int getFieldType(int i) throws DriverException { |
||
739 | 3996 | caballero | return ods.getFieldType(i);
|
740 | 3940 | caballero | } |
741 | } |
||
742 | 4120 | caballero | public CommandRecord getCommandRecord(){
|
743 | return cr;
|
||
744 | } |
||
745 | 3940 | caballero | } |