Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libGDBMS / src / com / hardcode / gdbms / engine / data / FieldNameAccessSupport.java @ 466

History | View | Annotate | Download (1.51 KB)

1
package com.hardcode.gdbms.engine.data;
2

    
3
import java.util.HashMap;
4

    
5

    
6
/**
7
 * Implementaci?n del soporte para acceso a campos por nombre
8
 *
9
 * @author Fernando Gonz?lez Cort?s
10
 */
11
public class FieldNameAccessSupport implements FieldNameAccess {
12
    private HashMap nameIndex = null;
13
    private DataSource dataSource;
14

    
15
    /**
16
     * Creates a new FieldNameAccessSupport object.
17
     *
18
     * @param ds DataSource con los campos sobre los que se accede
19
     */
20
    public FieldNameAccessSupport(DataSource ds) {
21
        dataSource = ds;
22
    }
23

    
24
    /**
25
     * @see com.hardcode.gdbms.engine.data.FieldNameAccess#getFieldIndexByName(java.lang.String)
26
     */
27
    public int getFieldIndexByName(String fieldName) throws DriverException {
28
        Integer i = (Integer) getNameIndex().get(fieldName);
29

    
30
        if (i == null) {
31
            return -1;
32
        }
33

    
34
        return i.intValue();
35
    }
36

    
37
    /**
38
     * Obtiene una referencia a la tabla de indices por nombre, creando dicha
39
     * tabla si es la primera vez que se accede
40
     *
41
     * @return tabla indice-nombre
42
     *
43
     * @throws DriverException Si hay error accediendo al DataSource
44
     */
45
    private HashMap getNameIndex() throws DriverException {
46
        if (nameIndex == null) {
47
            //Este metodo se invocar? con el DataSource abierto ya
48
            nameIndex = new HashMap();
49

    
50
            for (int i = 0; i < dataSource.getFieldCount(); i++) {
51
                nameIndex.put(dataSource.getFieldName(i), new Integer(i));
52
            }
53
        }
54

    
55
        return nameIndex;
56
    }
57
}