svn-gvsig-desktop / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / edition / EditableAdapter.java @ 4193
History | View | Annotate | Download (23.1 KB)
1 |
package com.iver.cit.gvsig.fmap.edition; |
---|---|
2 |
|
3 |
import java.awt.Image; |
4 |
import java.io.IOException; |
5 |
import java.util.HashMap; |
6 |
|
7 |
import com.hardcode.driverManager.DriverLoadException; |
8 |
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 |
import com.iver.cit.gvsig.fmap.core.DefaultRow; |
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.Command; |
19 |
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 |
protected boolean isEditing = false; |
36 |
private SelectableDataSource ds = null; |
37 |
protected FBitSet delRows = new FBitSet(); |
38 |
private CommandRecord cr;
|
39 |
|
40 |
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 |
* 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 |
* que convertir a string. Lo que est? claro es que
|
62 |
* NO se puede confiar nunca en que sea algo correlativo
|
63 |
* (1, 2, 3, 4, 5, ... => FALSO!!)
|
64 |
*/
|
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 |
|
116 |
if (rowEdited != null) { |
117 |
writer.process(rowEdited); |
118 |
} |
119 |
} |
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 |
int calculatedIndex=getCalculatedIndex(index);
|
147 |
Integer integer = new Integer(calculatedIndex); |
148 |
DefaultRowEdited edRow = null;
|
149 |
//Si no est? en el fichero de expansi?n
|
150 |
if (!relations.containsKey(integer)) {
|
151 |
try {
|
152 |
/* edRow = new DefaultRowEdited(new DefaultRow(ods.getRow(calculatedIndex), "" + index),
|
153 |
DefaultRowEdited.STATUS_ORIGINAL, index); */
|
154 |
edRow = new DefaultRowEdited(new DefaultRow(ods.getRow(calculatedIndex)), |
155 |
DefaultRowEdited.STATUS_ORIGINAL, index); |
156 |
} catch (DriverException e) {
|
157 |
throw new DriverIOException(e); |
158 |
} |
159 |
|
160 |
return edRow;
|
161 |
} else {
|
162 |
int num = ((Integer) relations.get(integer)).intValue(); |
163 |
|
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 |
} |
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 |
try {
|
182 |
return (int) (ods.getRowCount() + numAdd) - delRows.cardinality();// - expansionFile.getInvalidRows().cardinality(); |
183 |
} catch (DriverException e) {
|
184 |
throw new DriverIOException(e); |
185 |
} |
186 |
|
187 |
|
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,String descrip) throws DriverIOException, IOException { |
199 |
int calculatedIndex = doAddRow(row);
|
200 |
Command command=new AddRowCommand(this, row, calculatedIndex); |
201 |
command.setDescription(descrip); |
202 |
if (complex) {
|
203 |
commands.add(command); |
204 |
} else {
|
205 |
cr.pushCommand(command); |
206 |
} |
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 |
//seleccion.clear();
|
217 |
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 |
//seleccion.clear();
|
230 |
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 |
public void removeRow(int index,String descrip) throws IOException, DriverIOException { |
257 |
int calculatedIndex = getCalculatedIndex(index);
|
258 |
Command command=new RemoveRowCommand(this, calculatedIndex); |
259 |
command.setDescription(descrip); |
260 |
if (complex) {
|
261 |
commands.add(command); |
262 |
} else {
|
263 |
cr.pushCommand(command); |
264 |
} |
265 |
doRemoveRow(calculatedIndex); |
266 |
} |
267 |
|
268 |
/* (non-Javadoc)
|
269 |
* @see com.iver.cit.gvsig.fmap.edition.IEditableSource#modifyRow(int, com.iver.cit.gvsig.fmap.core.IRow)
|
270 |
*/
|
271 |
public void modifyRow(int index, IRow row,String descrip) |
272 |
throws IOException, DriverIOException { |
273 |
int calculatedIndex = getCalculatedIndex(index);
|
274 |
int pos = doModifyRow(calculatedIndex, row);
|
275 |
Command command=new ModifyRowCommand(this, calculatedIndex, pos, row); |
276 |
command.setDescription(descrip); |
277 |
if (complex) {
|
278 |
commands.add(command); |
279 |
} else {
|
280 |
cr.pushCommand(command); |
281 |
} |
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 |
return selectionImage;
|
307 |
} |
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 |
public IRow doRemoveRow(int index) throws DriverIOException, IOException { |
370 |
//Llega un calculatedIndex
|
371 |
delRows.set(index, true);
|
372 |
System.err.println("Elimina una Row en la posici?n: " + index); |
373 |
// TODO: Con tablas no es necesario devolver la anterior feature. Por ahora.
|
374 |
return null; |
375 |
} |
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 |
System.err.println("Modifica una Row en la posici?n: " + index); |
398 |
//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 |
|
407 |
/*
|
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 |
* @return calculatedIndex
|
430 |
*
|
431 |
* @throws DriverIOException
|
432 |
* @throws IOException
|
433 |
*/
|
434 |
public int doAddRow(IRow feat) throws DriverIOException, IOException { |
435 |
// A?ade la geometr?a
|
436 |
// int virtualIndex = 0;
|
437 |
int calculatedIndex = -1; |
438 |
|
439 |
try {
|
440 |
calculatedIndex = (int) ods.getRowCount() + numAdd;
|
441 |
// int externalIndex = getRowCount();
|
442 |
// calculatedIndex = getCalculatedIndex(externalIndex);
|
443 |
} catch (DriverException e) {
|
444 |
throw new DriverIOException(e); |
445 |
} |
446 |
|
447 |
int pos = expansionFile.addRow(feat);
|
448 |
relations.put(new Integer(calculatedIndex), new Integer(pos)); |
449 |
numAdd++; |
450 |
System.err.println("A?ade una Row en la posici?n: " + calculatedIndex); |
451 |
return calculatedIndex;
|
452 |
} |
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 |
delRows.set(index, false);
|
465 |
} |
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 |
public void undoAddRow(int calculatedIndex) throws DriverIOException, IOException { |
478 |
expansionFile.deleteLastRow(); |
479 |
relations.remove(new Integer(calculatedIndex)); |
480 |
numAdd--; |
481 |
} |
482 |
|
483 |
/*
|
484 |
* (non-Javadoc)
|
485 |
*
|
486 |
* @see com.iver.cit.gvsig.fmap.layers.VectorialAdapter#getRecordset()
|
487 |
*/
|
488 |
public SelectableDataSource getRecordset() throws DriverLoadException { |
489 |
if (isEditing) {
|
490 |
if (ds == null) { |
491 |
String name = LayerFactory.getDataSourceFactory().addDataSource((ObjectDriver) editingDriver);
|
492 |
|
493 |
try {
|
494 |
ds = new SelectableDataSource(LayerFactory.getDataSourceFactory()
|
495 |
.createRandomDataSource(name, |
496 |
DataSourceFactory.AUTOMATIC_OPENING)); |
497 |
} 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 |
|
510 |
/**
|
511 |
* DOCUMENT ME!
|
512 |
*
|
513 |
* @param sds DOCUMENT ME!
|
514 |
*/
|
515 |
public void setRecordSet(SelectableDataSource sds) { |
516 |
this.ods = sds;
|
517 |
} |
518 |
|
519 |
/**
|
520 |
* DOCUMENT ME!
|
521 |
*
|
522 |
* @return
|
523 |
*/
|
524 |
public FBitSet getSelection() {
|
525 |
/* try {
|
526 |
return getRecordset().getSelection();
|
527 |
} catch (DriverLoadException e) {
|
528 |
// TODO Auto-generated catch block
|
529 |
e.printStackTrace();
|
530 |
}
|
531 |
return null; */
|
532 |
return getRecordset().getSelection();
|
533 |
} |
534 |
public void setSelection(FBitSet selection) { |
535 |
/* try {
|
536 |
getRecordset().setSelection(selection);
|
537 |
} catch (DriverLoadException e) {
|
538 |
// TODO Auto-generated catch block
|
539 |
e.printStackTrace();
|
540 |
} */
|
541 |
getRecordset().setSelection(selection); |
542 |
} |
543 |
/**
|
544 |
* DOCUMENT ME!
|
545 |
*
|
546 |
* @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 |
numNotDeleted = idPedido-numBorradosAnt; |
569 |
//System.out.println("Piden Viejo : "+ rowIndex + " y devuelvo como nuevo " + (numNotDeleted));
|
570 |
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 |
//System.out.println("Piden Registro : "+ rowIndex + " y devuelvo el " + (calculatedIndex));
|
600 |
return calculatedIndex;
|
601 |
} |
602 |
|
603 |
/**
|
604 |
* DOCUMENT ME!
|
605 |
*
|
606 |
* @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 |
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 |
} |
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 |
DataWare dataWareOrig = ods.getDataWare(DataSourceFactory.DATA_WARE_DIRECT_MODE); |
631 |
dataWareOrig.commitTrans(); |
632 |
} |
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 |
ods.setDataSourceFactory(dsf); |
641 |
} |
642 |
|
643 |
/*
|
644 |
* (non-Javadoc)
|
645 |
*
|
646 |
* @see com.hardcode.driverManager.Driver#getName()
|
647 |
*/
|
648 |
public String getName() { |
649 |
return ods.getName();
|
650 |
} |
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 |
Integer integer = new Integer(getCalculatedIndex(rowIndex)); |
662 |
|
663 |
try {
|
664 |
if (!relations.containsKey(integer)) {
|
665 |
return ods.getFieldValue(rowIndex, fieldId);
|
666 |
} else {
|
667 |
int num = ((Integer) relations.get(integer)).intValue(); |
668 |
DefaultRowEdited feat = (DefaultRowEdited) expansionFile.getRow(num); |
669 |
|
670 |
if (feat == null) { |
671 |
return null; |
672 |
} |
673 |
|
674 |
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 |
|
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 |
} |
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 |
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 |
|
730 |
return 0; |
731 |
} |
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 |
return ods.getFieldType(i);
|
740 |
} |
741 |
} |
742 |
public CommandRecord getCommandRecord(){
|
743 |
return cr;
|
744 |
} |
745 |
} |