Statistics
| Revision:

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

History | View | Annotate | Download (1.64 KB)

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

    
3
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
4

    
5
import java.util.HashMap;
6

    
7

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

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

    
26
    /**
27
     * @throws ReadDriverException TODO
28
     * @see com.hardcode.gdbms.engine.data.FieldNameAccess#getFieldIndexByName(java.lang.String)
29
     */
30
    public int getFieldIndexByName(String fieldName) throws ReadDriverException {
31
        Integer i = (Integer) getNameIndex().get(fieldName.toUpperCase());
32

    
33
        if (i == null) {
34
            return -1;
35
        }
36

    
37
        return i.intValue();
38
    }
39

    
40
    /**
41
     * Obtiene una referencia a la tabla de indices por nombre, creando dicha
42
     * tabla si es la primera vez que se accede
43
     *
44
     * @return tabla indice-nombre
45
     * @throws ReadDriverException TODO
46
     */
47
    private HashMap getNameIndex() throws ReadDriverException {
48
        if (nameIndex == null || (nameIndex.size() < dataSource.getFieldCount())) {
49
            //Este metodo se invocar? con el DataSource abierto ya
50
            nameIndex = new HashMap();
51

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

    
57
        return nameIndex;
58
    }
59
}