Statistics
| Revision:

svn-gvsig-desktop / tags / J2ME_compat_v1_2_Build_1209 / libraries / libFMap / src / com / iver / cit / gvsig / fmap / operations / arcview / ArcJoinDataSource.java @ 19509

History | View | Annotate | Download (4.34 KB)

1
package com.iver.cit.gvsig.fmap.operations.arcview;
2

    
3
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
4
import com.hardcode.gdbms.engine.data.DataSource;
5
import com.hardcode.gdbms.engine.data.persistence.Memento;
6
import com.hardcode.gdbms.engine.data.persistence.MementoException;
7
import com.hardcode.gdbms.engine.data.persistence.OperationLayerMemento;
8
import com.hardcode.gdbms.engine.strategies.OperationDataSource;
9
import com.hardcode.gdbms.engine.values.Value;
10
import com.hardcode.gdbms.engine.values.ValueFactory;
11

    
12

    
13
/**
14
 * DOCUMENT ME!
15
 *
16
 * @author Fernando Gonz?lez Cort?s
17
 */
18
public class ArcJoinDataSource extends OperationDataSource {
19
        private DataSource source;
20
        private DataSource linked;
21
        private int[] relation;
22
        private int linkFieldindex;
23

    
24
        /**
25
         * DOCUMENT ME!
26
         *
27
         * @param result
28
         * @param source
29
         * @param linked DOCUMENT ME!
30
         * @param linkFieldindex DOCUMENT ME!
31
         */
32
        public ArcJoinDataSource(int[] result, DataSource source,
33
                DataSource linked, int linkFieldindex) {
34
                this.relation = result;
35
                this.source = source;
36
                this.linked = linked;
37
                this.linkFieldindex = linkFieldindex;
38
        }
39

    
40
        /**
41
         * @throws ReadDriverException
42
         * @see com.hardcode.gdbms.engine.data.DataSource#start()
43
         */
44
        public void start() throws ReadDriverException {
45
                source.start();
46
                linked.start();
47
        }
48

    
49
        /**
50
         * @see com.hardcode.gdbms.engine.data.DataSource#stop()
51
         */
52
        public void stop() throws ReadDriverException {
53
                source.stop();
54
                linked.stop();
55
        }
56

    
57
        /**
58
         * @see com.hardcode.gdbms.engine.data.FieldNameAccess#getFieldIndexByName(java.lang.String)
59
         */
60
        public int getFieldIndexByName(String fieldName) throws ReadDriverException {
61
        for (int i = 0; i < getFieldCount(); i++) {
62
            if (getFieldName(i).equals(fieldName)){
63
                return i;
64
            }
65
        }
66

    
67
        return -1;
68
    }
69

    
70
        /**
71
         * @see com.hardcode.gdbms.engine.data.ReadDriver#getFieldValue(long, int)
72
         */
73
        public Value getFieldValue(long rowIndex, int fieldId)
74
                throws ReadDriverException {
75
                if (fieldId < source.getFieldCount()) {
76
                        return source.getFieldValue(rowIndex, fieldId);
77
                }
78
                fieldId = fieldId - source.getFieldCount();
79

    
80
                if (fieldId >= linkFieldindex) {
81
                        fieldId++;
82
                }
83

    
84
                int index = relation[(int) rowIndex];
85

    
86
                if (index == -1) {
87
                        return ValueFactory.createNullValue();
88
                }
89

    
90
                return linked.getFieldValue(index, fieldId);
91
        }
92

    
93
        /**
94
         * @see com.hardcode.gdbms.engine.data.ReadDriver#getFieldCount()
95
         */
96
        public int getFieldCount() throws ReadDriverException {
97
                return (source.getFieldCount() + linked.getFieldCount()) - 1;
98
        }
99

    
100
        /**
101
         * @see com.hardcode.gdbms.engine.data.ReadDriver#getFieldName(int)
102
         */
103
        public String getFieldName(int fieldId) throws ReadDriverException {
104
                if (fieldId < source.getFieldCount()) {
105
                        return source.getFieldName(fieldId);
106
                }
107
                fieldId = fieldId - source.getFieldCount();
108

    
109
                if (fieldId >= linkFieldindex) {
110
                        fieldId++;
111
                }
112

    
113
                return "link_"+linked.getFieldName(fieldId);
114
        }
115

    
116
        /**
117
         * @see com.hardcode.gdbms.engine.data.ReadDriver#getRowCount()
118
         */
119
        public long getRowCount() throws ReadDriverException {
120
                return source.getRowCount();
121
        }
122

    
123
        /**
124
         * @see com.hardcode.gdbms.engine.data.ReadDriver#getFieldType(int)
125
         */
126
        public int getFieldType(int i) throws ReadDriverException {
127
                if (i < source.getFieldCount()) {
128
                        return source.getFieldType(i);
129
                }
130
                i = i - source.getFieldCount();
131

    
132
                if (i >= linkFieldindex) {
133
                        i++;
134
                }
135

    
136
                return linked.getFieldType(i);
137
        }
138

    
139
        /**
140
         * @see com.hardcode.gdbms.engine.data.DataSource#getMemento()
141
         */
142
        public Memento getMemento() throws MementoException {
143
                return new OperationLayerMemento(getName(),
144
                                new Memento[]{source.getMemento(), linked.getMemento()}, getSQL());
145
        }
146

    
147
        public int getFieldWidth(int i) throws ReadDriverException {
148
                if (i < source.getFieldCount()) {
149
                        return source.getFieldWidth(i);
150
                }
151
                i = i - source.getFieldCount();
152

    
153
                if (i >= linkFieldindex) {
154
                        i++;
155
                }
156

    
157
                return linked.getFieldWidth(i);
158
        }
159

    
160
    public boolean isVirtualField(int fieldId) throws ReadDriverException  {
161
                if (fieldId < source.getFieldCount()) {
162
                        return source.isVirtualField(fieldId);
163
                }
164
                fieldId = fieldId - source.getFieldCount();
165

    
166
                if (fieldId >= linkFieldindex) {
167
                        fieldId++;
168
                }
169

    
170
                return linked.isVirtualField(fieldId);
171
    }
172
}