Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / edition / EditableAdapter.java @ 4368

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
                int rowCount=getRowCount();
114
            for (int i = 0; i < rowCount; i++) {
115
                IRowEdited rowEdited = getRow(i);
116

    
117
                if (rowEdited != null) {
118
                    writer.process(rowEdited);
119
                }
120
            }
121
        } catch (DriverIOException e) {
122
            e.printStackTrace();
123
            throw new EditionException(e);
124
        } catch (IOException e) {
125
            e.printStackTrace();
126
            throw new EditionException(e);
127
        }
128

    
129
        writer.postProcess();
130
        isEditing = false;
131
    }
132

    
133
    /**
134
     * DOCUMENT ME!
135
     *
136
     * @throws IOException DOCUMENT ME!
137
     */
138
    public void cancelEdition() throws IOException {
139
        isEditing = false;
140
        expansionFile.close();
141
    }
142

    
143
    /* (non-Javadoc)
144
     * @see com.iver.cit.gvsig.fmap.edition.IEditableSource#getRow(int)
145
     */
146
    public IRowEdited getRow(int index) throws DriverIOException, IOException {
147
            int calculatedIndex=getCalculatedIndex(index);
148
            Integer integer = new Integer(calculatedIndex);
149
            DefaultRowEdited edRow = null;
150
        //Si no est? en el fichero de expansi?n
151
        if (!relations.containsKey(integer)) {
152
                try {
153
                    /* edRow = new DefaultRowEdited(new DefaultRow(ods.getRow(calculatedIndex), "" + index),
154
                            DefaultRowEdited.STATUS_ORIGINAL, index); */
155
                    edRow = new DefaultRowEdited(new DefaultRow(ods.getRow(calculatedIndex)),
156
                            DefaultRowEdited.STATUS_ORIGINAL, index);
157
                } catch (DriverException e) {
158
                    throw new DriverIOException(e);
159
                }
160

    
161
                return edRow;
162
        } else {
163
            int num = ((Integer) relations.get(integer)).intValue();
164

    
165
            // return expansionFile.getRow(num);
166
            IRowEdited rowFromExpansion = expansionFile.getRow(num);
167
            // ?Habr?a que hacer aqu? setID(index + "")?
168
            edRow = new DefaultRowEdited(rowFromExpansion.getLinkedRow().cloneRow(), rowFromExpansion.getStatus(), index);
169
            return edRow;
170
        }
171
    }
172

    
173
    /**
174
     * DOCUMENT ME!
175
     *
176
     * @return DOCUMENT ME!
177
     *
178
     * @throws DriverIOException DOCUMENT ME!
179
     * @throws IOException DOCUMENT ME!
180
     */
181
    public int getRowCount() throws DriverIOException, IOException {
182
             try {
183
             return (int) (ods.getRowCount() + numAdd) - delRows.cardinality();// - expansionFile.getInvalidRows().cardinality();
184
         } catch (DriverException e) {
185
                 throw new DriverIOException(e);
186
         }
187

    
188

    
189
    }
190

    
191
    /**
192
     * DOCUMENT ME!
193
     *
194
     * @param row DOCUMENT ME!
195
     *
196
     * @throws DriverIOException DOCUMENT ME!
197
     * @throws IOException DOCUMENT ME!
198
     */
199
    public void addRow(IRow row,String descrip) throws DriverIOException, IOException {
200
        int calculatedIndex = doAddRow(row);
201
        Command command=new AddRowCommand(this, row, calculatedIndex);
202
        command.setDescription(descrip);
203
        if (complex) {
204
            commands.add(command);
205
        } else {
206
            cr.pushCommand(command);
207
        }
208
    }
209

    
210
    /**
211
     * DOCUMENT ME!
212
     *
213
     * @throws DriverIOException DOCUMENT ME!
214
     * @throws IOException DOCUMENT ME!
215
     */
216
    public void undo() throws DriverIOException, IOException {
217
        //seleccion.clear();
218
        if (moreUndoCommands()) {
219
            cr.undoCommand();
220
        }
221
    }
222

    
223
    /**
224
     * DOCUMENT ME!
225
     *
226
     * @throws DriverIOException DOCUMENT ME!
227
     * @throws IOException DOCUMENT ME!
228
     */
229
    public void redo() throws DriverIOException, IOException {
230
        //seleccion.clear();
231
        if (moreRedoCommands()) {
232
            cr.redoCommand();
233
        }
234
    }
235

    
236
    /**
237
     * DOCUMENT ME!
238
     *
239
     * @return DOCUMENT ME!
240
     */
241
    public boolean moreUndoCommands() {
242
        return cr.moreUndoCommands();
243
    }
244

    
245
    /**
246
     * DOCUMENT ME!
247
     *
248
     * @return DOCUMENT ME!
249
     */
250
    public boolean moreRedoCommands() {
251
        return cr.moreRedoCommands();
252
    }
253

    
254
    /* (non-Javadoc)
255
     * @see com.iver.cit.gvsig.fmap.edition.IEditableSource#removeRow(int)
256
     */
257
    public void removeRow(int index,String descrip) throws IOException, DriverIOException {
258
            int calculatedIndex = getCalculatedIndex(index);
259
            Command command=new RemoveRowCommand(this, calculatedIndex);
260
            command.setDescription(descrip);
261
            if (complex) {
262
            commands.add(command);
263
        } else {
264
            cr.pushCommand(command);
265
        }
266
        doRemoveRow(calculatedIndex);
267
    }
268

    
269
    /* (non-Javadoc)
270
     * @see com.iver.cit.gvsig.fmap.edition.IEditableSource#modifyRow(int, com.iver.cit.gvsig.fmap.core.IRow)
271
     */
272
    public void modifyRow(int index, IRow row,String descrip)
273
        throws IOException, DriverIOException {
274
            int calculatedIndex = getCalculatedIndex(index);
275
        int pos = doModifyRow(calculatedIndex, row);
276
        Command command=new ModifyRowCommand(this, calculatedIndex, pos, row);
277
        command.setDescription(descrip);
278
        if (complex) {
279
            commands.add(command);
280
        } else {
281
            cr.pushCommand(command);
282
        }
283
    }
284

    
285
    /**
286
     * DOCUMENT ME!
287
     */
288
    public void compact() {
289
        expansionFile.compact(relations);
290
    }
291

    
292
    /**
293
     * DOCUMENT ME!
294
     *
295
     * @param i DOCUMENT ME!
296
     */
297
    public void setImage(Image i) {
298
        selectionImage = i;
299
    }
300

    
301
    /**
302
     * DOCUMENT ME!
303
     *
304
     * @return DOCUMENT ME!
305
     */
306
    public Image getImage() {
307
        return selectionImage;
308
    }
309

    
310
    /**
311
     * DOCUMENT ME!
312
     */
313
    public void startComplexRow() {
314
        complex = true;
315
        commands = new CommandCollection();
316
    }
317

    
318
    /**
319
     * DOCUMENT ME!
320
     *
321
     * @throws IOException DOCUMENT ME!
322
     * @throws DriverIOException DOCUMENT ME!
323
     */
324
    public void endComplexRow() throws IOException, DriverIOException {
325
        cr.pushCommand(commands);
326
        complex = false;
327
    }
328

    
329
    /**
330
     * Actualiza en el mapa de ?ndices, la posici?n en la que estaba la
331
     * geometr?a antes de ser modificada. Se marca como v?lida, en caso de que
332
     * fuera una modificaci?n de una geometr?a que estuviese en el fichero de
333
     * expansi?n antes de ser modificada y se pone el puntero de escritura del
334
     * expansion file a justo despues de la penultima geometr?a
335
     *
336
     * @param geometryIndex ?ndice de la geometr?a que se quiere deshacer su
337
     *        modificaci?n
338
     * @param previousExpansionFileIndex ?ndice que ten?a antes la geometr?a en
339
     *        el expansionFile. Si vale -1 quiere decir que es una
340
     *        modificaci?n de una geometr?a original y por tanto no hay que
341
     *        actualizar el mapa de indices sino eliminar su entrada.
342
     *
343
     * @throws IOException
344
     * @throws DriverIOException
345
     */
346
    public void undoModifyRow(int geometryIndex, int previousExpansionFileIndex)
347
        throws IOException, DriverIOException {
348
        if (previousExpansionFileIndex == -1) {
349
            //Se elimina de las relaciones y del fichero de expansi?n
350
            relations.remove(new Integer(geometryIndex));
351
            expansionFile.deleteLastRow();
352
        } else {
353
            //Se actualiza la relaci?n de ?ndices
354
            relations.put(new Integer(geometryIndex),
355
                new Integer(previousExpansionFileIndex));
356
        }
357
    }
358

    
359
    /**
360
     * Elimina una geometria. Si es una geometr?a original de la capa en
361
     * edici?n se marca como eliminada (haya sido modificada o no). Si es una
362
     * geometr?a a?adida posteriormente se invalida en el fichero de
363
     * expansi?n, para que una futura compactaci?n termine con ella.
364
     *
365
     * @param index ?ndice de la geometr?a.
366
     *
367
     * @throws DriverIOException
368
     * @throws IOException
369
     */
370
    public IRow doRemoveRow(int index) throws DriverIOException, IOException {
371
//Llega un calculatedIndex
372
            delRows.set(index, true);
373
            System.err.println("Elimina una Row en la posici?n: " + index);
374
            // TODO: Con tablas no es necesario devolver la anterior feature. Por ahora.
375
            return null;
376
    }
377

    
378
    /**
379
     * Si se intenta modificar una geometr?a original de la capa en edici?n se
380
     * a?ade al fichero de expansi?n y se registra la posici?n en la que se
381
     * a?adi?. Si se intenta modificar una geometria que se encuentra en el
382
     * fichero de expansi?n (por ser nueva o original pero modificada) se
383
     * invoca el m?todo modifyGeometry y se actualiza el ?ndice de la
384
     * geometria en el fichero.
385
     *
386
     * @param index DOCUMENT ME!
387
     * @param feat DOCUMENT ME!
388
     *
389
     * @return DOCUMENT ME!
390
     *
391
     * @throws IOException
392
     * @throws DriverIOException
393
     */
394
    public int doModifyRow(int index, IRow feat)
395
        throws IOException, DriverIOException {
396
        int pos = -1;
397
        Integer integer = new Integer(index);
398
        System.err.println("Modifica una Row en la posici?n: " + index);
399
        //Si la geometr?a no ha sido modificada
400
        if (!relations.containsKey(integer)) {
401
            int expansionIndex = expansionFile.addRow(feat);
402
            relations.put(integer, new Integer(expansionIndex));
403
        } else {
404
            //Obtenemos el ?ndice en el fichero de expansi?n
405
            int num = ((Integer) relations.get(integer)).intValue();
406
            pos = num;
407

    
408
            /*
409
             * Se modifica la geometr?a y nos guardamos el ?ndice dentro del fichero
410
             * de expansi?n en el que se encuentra la geometr?a modificada
411
             */
412
            num = expansionFile.modifyRow(num, feat);
413

    
414
            /*
415
             * Actualiza la relaci?n del ?ndice de la geometr?a al ?ndice en el fichero
416
             * de expansi?n.
417
             */
418
            relations.put(integer, new Integer(num));
419
        }
420

    
421
        return pos;
422
    }
423

    
424
    /**
425
     * A?ade una geometria al fichero de expansi?n y guarda la correspondencia
426
     * en la tabla relations.
427
     *
428
     * @param feat geometr?a a guardar.
429
     *
430
     * @return calculatedIndex
431
     *
432
     * @throws DriverIOException
433
     * @throws IOException
434
     */
435
    public int doAddRow(IRow feat) throws DriverIOException, IOException {
436
        // A?ade la geometr?a
437
        // int virtualIndex = 0;
438
        int calculatedIndex = -1;
439

    
440
        try {
441
            calculatedIndex = (int) ods.getRowCount() + numAdd;
442
                // int externalIndex = getRowCount();
443
                // calculatedIndex = getCalculatedIndex(externalIndex);
444
        } catch (DriverException e) {
445
                throw new DriverIOException(e);
446
        }
447

    
448
        int pos = expansionFile.addRow(feat);
449
        relations.put(new Integer(calculatedIndex), new Integer(pos));
450
        numAdd++;
451
        System.err.println("A?ade una Row en la posici?n: " + calculatedIndex);
452
        return calculatedIndex;
453
    }
454

    
455
    /**
456
     * Se desmarca como invalidada en el fichero de expansion o como eliminada
457
     * en el fichero original
458
     *
459
     * @param index DOCUMENT ME!
460
     *
461
     * @throws IOException
462
     * @throws DriverIOException
463
     */
464
    public void undoRemoveRow(int index) throws IOException, DriverIOException {
465
        delRows.set(index, false);
466
    }
467

    
468
    /**
469
     * Se elimina del final del fichero de expansi?n poniendo el puntero de
470
     * escritura apuntando al final de la pen?ltima geometr?a. Deber? quitar
471
     * la relaci?n del mapa de relaciones
472
     *
473
     * @param index ?ndice de la geometr?a que se a?adi?
474
     *
475
     * @throws DriverIOException
476
     * @throws IOException
477
     */
478
    public void undoAddRow(int calculatedIndex) throws DriverIOException, IOException {
479
        expansionFile.deleteLastRow();
480
        relations.remove(new Integer(calculatedIndex));
481
        numAdd--;
482
    }
483

    
484
    /*
485
     * (non-Javadoc)
486
     *
487
     * @see com.iver.cit.gvsig.fmap.layers.VectorialAdapter#getRecordset()
488
     */
489
    public SelectableDataSource getRecordset() throws DriverLoadException {
490
        if (isEditing) {
491
            if (ds == null) {
492
                String name = LayerFactory.getDataSourceFactory().addDataSource((ObjectDriver) editingDriver);
493

    
494
                try {
495
                    ds = new SelectableDataSource(LayerFactory.getDataSourceFactory()
496
                                                              .createRandomDataSource(name,
497
                                DataSourceFactory.AUTOMATIC_OPENING));
498
                } catch (NoSuchTableException e) {
499
                    throw new RuntimeException(e);
500
                } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
501
                    throw new RuntimeException(e);
502
                }
503
            }
504

    
505
            return ds;
506
        } else {
507
            return ods;
508
        }
509
    }
510

    
511
    /**
512
     * DOCUMENT ME!
513
     *
514
     * @param sds DOCUMENT ME!
515
     */
516
    public void setRecordSet(SelectableDataSource sds) {
517
        this.ods = sds;
518
    }
519

    
520
    /**
521
     * DOCUMENT ME!
522
     *
523
     * @return
524
     */
525
    public FBitSet getSelection() {
526
        /* try {
527
                        return getRecordset().getSelection();
528
                } catch (DriverLoadException e) {
529
                        // TODO Auto-generated catch block
530
                        e.printStackTrace();
531
                }
532
                return null; */
533
            return getRecordset().getSelection();
534
    }
535
    public void setSelection(FBitSet selection) {
536
            /* try {
537
                        getRecordset().setSelection(selection);
538
                } catch (DriverLoadException e) {
539
                        // TODO Auto-generated catch block
540
                        e.printStackTrace();
541
                } */
542
            getRecordset().setSelection(selection);
543
        }
544
    /**
545
     * DOCUMENT ME!
546
     *
547
     * @return DOCUMENT ME!
548
     */
549
    public boolean isEditing() {
550
        return isEditing;
551
    }
552
    protected int getInversedIndex(long rowIndex) {
553
            int intervalNotDeleted=0;
554
        int antDeleted=-1;
555
        int idPedido = (int) rowIndex;
556
        int numNotDeleted=0;
557
        int numBorradosAnt = 0;
558

    
559
            for (int i = delRows.nextSetBit(0); i>=0; i = delRows.nextSetBit(i+1)) {
560
                    intervalNotDeleted = i-antDeleted-1;
561
                    numNotDeleted += intervalNotDeleted;
562
                    if (i > idPedido){
563
                            numNotDeleted = numNotDeleted + (i - idPedido);
564
                            break;
565
                    }
566
                    numBorradosAnt++;
567
                    antDeleted = i;
568
        }
569
                    numNotDeleted =  idPedido-numBorradosAnt;
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
            //System.out.println("Piden Registro : "+ rowIndex + " y devuelvo el " + (calculatedIndex));
601
        return calculatedIndex;
602
    }
603

    
604
    /**
605
     * DOCUMENT ME!
606
     *
607
     * @author Vicente Caballero Navarro
608
     */
609
    private class myObjectDriver implements ObjectDriver {
610
        /*
611
         * (non-Javadoc)
612
         *
613
         * @see com.hardcode.gdbms.engine.data.driver.ObjectDriver#getPrimaryKeys()
614
         */
615
        public int[] getPrimaryKeys() throws DriverException {
616
                return ods.getPrimaryKeys();
617
        //        int[] pk=new int[1];
618
                /*for (int i=0;i<getRowCount();i++){
619
                        pk[i]=i;
620
                }*/
621
        //        pk[0]=1;
622
        //    return pk;
623
        }
624

    
625
        /*
626
         * (non-Javadoc)
627
         *
628
         * @see com.hardcode.gdbms.engine.data.driver.ObjectDriver#write(com.hardcode.gdbms.engine.data.edition.DataWare)
629
         */
630
        public void write(DataWare dataWare) throws DriverException {
631
                DataWare dataWareOrig = ods.getDataWare(DataSourceFactory.DATA_WARE_DIRECT_MODE);
632
                dataWareOrig.commitTrans();
633
        }
634

    
635
        /*
636
         * (non-Javadoc)
637
         *
638
         * @see com.hardcode.gdbms.engine.data.driver.GDBMSDriver#setDataSourceFactory(com.hardcode.gdbms.engine.data.DataSourceFactory)
639
         */
640
        public void setDataSourceFactory(DataSourceFactory dsf) {
641
           ods.setDataSourceFactory(dsf);
642
        }
643

    
644
        /*
645
         * (non-Javadoc)
646
         *
647
         * @see com.hardcode.driverManager.Driver#getName()
648
         */
649
        public String getName() {
650
           return ods.getName();
651
        }
652

    
653
        /*
654
         * (non-Javadoc)
655
         *
656
         * @see com.hardcode.gdbms.engine.data.driver.ReadAccess#getFieldValue(long,
657
         *      int)
658
         */
659
        public Value getFieldValue(long rowIndex, int fieldId)
660
            throws DriverException {
661
            // Si no est? en el fichero de expansi?n
662
            Integer integer = new Integer(getCalculatedIndex(rowIndex));
663

    
664
            try {
665
                if (!relations.containsKey(integer)) {
666
                    return ods.getFieldValue(rowIndex, fieldId);
667
                } else {
668
                    int num = ((Integer) relations.get(integer)).intValue();
669
                    DefaultRowEdited feat = (DefaultRowEdited) expansionFile.getRow(num);
670

    
671
                    if (feat == null) {
672
                        return null;
673
                    }
674

    
675
                    return feat.getAttribute(fieldId);
676
                }
677
            } catch (DriverException e) {
678
                e.printStackTrace();
679
                throw new DriverException(e);
680
            } catch (IOException e) {
681
                e.printStackTrace();
682
                throw new DriverException(e);
683
            }
684

    
685
            /**
686
             * try { if (!relations.containsKey(integer)) { // Si ha sido
687
             * eliminada if (delRows.get(integer.intValue())) { return null; }
688
             * else { return ods.getFieldValue(rowIndex, fieldId); }} else {
689
             * int num = ((Integer) relations.get(integer)).intValue();
690
             * DefaultRowEdited feat = (DefaultRowEdited)
691
             * expansionFile.getRow(num); if (feat==null)return null; return
692
             * feat.getAttribute(fieldId); }} catch (DriverException e) {
693
             * e.printStackTrace(); throw new DriverException(e); } catch
694
             * (IOException e) { e.printStackTrace(); throw new
695
             * DriverException(e); }
696
             */
697
        }
698

    
699
        /*
700
         * (non-Javadoc)
701
         *
702
         * @see com.hardcode.gdbms.engine.data.driver.ReadAccess#getFieldCount()
703
         */
704
        public int getFieldCount() throws DriverException {
705
            // TODO Por ahora, no dejamos que se a?adan campos
706
            return ods.getFieldCount();
707
        }
708

    
709
        /*
710
         * (non-Javadoc)
711
         *
712
         * @see com.hardcode.gdbms.engine.data.driver.ReadAccess#getFieldName(int)
713
         */
714
        public String getFieldName(int fieldId) throws DriverException {
715
            return ods.getFieldName(fieldId);
716
        }
717

    
718
        /*
719
         * (non-Javadoc)
720
         *
721
         * @see com.hardcode.gdbms.engine.data.driver.ReadAccess#getRowCount()
722
         */
723
        public long getRowCount() {
724
                 try {
725
                 return (int) (ods.getRowCount() + numAdd) - delRows.cardinality();// - expansionFile.getInvalidRows().cardinality();
726
             } catch (DriverException e) {
727
                 // TODO Auto-generated catch block
728
                 e.printStackTrace();
729
             }
730

    
731
             return 0;
732
        }
733

    
734
        /*
735
         * (non-Javadoc)
736
         *
737
         * @see com.hardcode.gdbms.engine.data.driver.ReadAccess#getFieldType(int)
738
         */
739
        public int getFieldType(int i) throws DriverException {
740
            return ods.getFieldType(i);
741
        }
742
    }
743
    public CommandRecord getCommandRecord(){
744
            return cr;
745
    }
746
}