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