svn-gvsig-desktop / branches / Fmap_GisPlanet / libraries / libFMap / src / com / iver / cit / gvsig / fmap / operations / arcview / ArcJoinDataSource.java @ 1848
History | View | Annotate | Download (3.54 KB)
1 | 1828 | fernando | package com.iver.cit.gvsig.fmap.operations.arcview; |
---|---|---|---|
2 | |||
3 | import com.hardcode.gdbms.engine.data.DataSource; |
||
4 | import com.hardcode.gdbms.engine.data.driver.DriverException; |
||
5 | 1836 | fernando | 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 | 1828 | fernando | import com.hardcode.gdbms.engine.strategies.OperationDataSource; |
9 | import com.hardcode.gdbms.engine.values.Value; |
||
10 | |||
11 | |||
12 | /**
|
||
13 | * DOCUMENT ME!
|
||
14 | *
|
||
15 | * @author Fernando Gonz?lez Cort?s
|
||
16 | */
|
||
17 | public class ArcJoinDataSource extends OperationDataSource { |
||
18 | private DataSource source; |
||
19 | private DataSource linked; |
||
20 | private int[] relation; |
||
21 | private int linkFieldindex; |
||
22 | |||
23 | /**
|
||
24 | * DOCUMENT ME!
|
||
25 | *
|
||
26 | * @param result
|
||
27 | * @param source
|
||
28 | * @param linked DOCUMENT ME!
|
||
29 | * @param linkFieldindex DOCUMENT ME!
|
||
30 | */
|
||
31 | public ArcJoinDataSource(int[] result, DataSource source, |
||
32 | DataSource linked, int linkFieldindex) { |
||
33 | this.relation = result;
|
||
34 | this.source = source;
|
||
35 | this.linked = linked;
|
||
36 | this.linkFieldindex = linkFieldindex;
|
||
37 | } |
||
38 | |||
39 | /**
|
||
40 | * @see com.hardcode.gdbms.engine.data.DataSource#start()
|
||
41 | */
|
||
42 | public void start() throws DriverException { |
||
43 | source.start(); |
||
44 | linked.start(); |
||
45 | } |
||
46 | |||
47 | /**
|
||
48 | * @see com.hardcode.gdbms.engine.data.DataSource#stop()
|
||
49 | */
|
||
50 | public void stop() throws DriverException { |
||
51 | source.stop(); |
||
52 | linked.stop(); |
||
53 | } |
||
54 | |||
55 | /**
|
||
56 | * @see com.hardcode.gdbms.engine.data.FieldNameAccess#getFieldIndexByName(java.lang.String)
|
||
57 | */
|
||
58 | public int getFieldIndexByName(String fieldName) throws DriverException { |
||
59 | int ret = source.getFieldIndexByName(fieldName);
|
||
60 | |||
61 | if (ret == -1) { |
||
62 | ret = linked.getFieldIndexByName(fieldName); |
||
63 | |||
64 | if (ret != -1) { |
||
65 | ret += (source.getFieldCount() - 1);
|
||
66 | } |
||
67 | } |
||
68 | |||
69 | return ret;
|
||
70 | } |
||
71 | |||
72 | /**
|
||
73 | * @see com.hardcode.gdbms.engine.data.ReadDriver#getFieldValue(long, int)
|
||
74 | */
|
||
75 | public Value getFieldValue(long rowIndex, int fieldId) |
||
76 | throws DriverException {
|
||
77 | if (fieldId < source.getFieldCount()) {
|
||
78 | return source.getFieldValue(rowIndex, fieldId);
|
||
79 | } else {
|
||
80 | fieldId = fieldId - source.getFieldCount(); |
||
81 | |||
82 | if (fieldId >= linkFieldindex) {
|
||
83 | fieldId++; |
||
84 | } |
||
85 | |||
86 | int index = relation[(int) rowIndex]; |
||
87 | |||
88 | if (index == -1) { |
||
89 | return null; |
||
90 | } |
||
91 | |||
92 | return linked.getFieldValue(index, fieldId);
|
||
93 | } |
||
94 | } |
||
95 | |||
96 | /**
|
||
97 | * @see com.hardcode.gdbms.engine.data.ReadDriver#getFieldCount()
|
||
98 | */
|
||
99 | public int getFieldCount() throws DriverException { |
||
100 | return (source.getFieldCount() + linked.getFieldCount()) - 1; |
||
101 | } |
||
102 | |||
103 | /**
|
||
104 | * @see com.hardcode.gdbms.engine.data.ReadDriver#getFieldName(int)
|
||
105 | */
|
||
106 | public String getFieldName(int fieldId) throws DriverException { |
||
107 | if (fieldId < source.getFieldCount()) {
|
||
108 | return source.getFieldName(fieldId);
|
||
109 | } else {
|
||
110 | fieldId = fieldId - source.getFieldCount(); |
||
111 | |||
112 | if (fieldId >= linkFieldindex) {
|
||
113 | fieldId++; |
||
114 | } |
||
115 | |||
116 | return linked.getFieldName(fieldId);
|
||
117 | } |
||
118 | } |
||
119 | |||
120 | /**
|
||
121 | * @see com.hardcode.gdbms.engine.data.ReadDriver#getRowCount()
|
||
122 | */
|
||
123 | public long getRowCount() throws DriverException { |
||
124 | return source.getRowCount();
|
||
125 | } |
||
126 | |||
127 | /**
|
||
128 | * @see com.hardcode.gdbms.engine.data.ReadDriver#getFieldType(int)
|
||
129 | */
|
||
130 | public int getFieldType(int i) throws DriverException { |
||
131 | if (i < source.getFieldCount()) {
|
||
132 | return source.getFieldType(i);
|
||
133 | } else {
|
||
134 | i = i - source.getFieldCount(); |
||
135 | |||
136 | if (i >= linkFieldindex) {
|
||
137 | i++; |
||
138 | } |
||
139 | |||
140 | return source.getFieldType(i);
|
||
141 | } |
||
142 | } |
||
143 | 1836 | fernando | |
144 | /**
|
||
145 | * @see com.hardcode.gdbms.engine.data.DataSource#getMemento()
|
||
146 | */
|
||
147 | public Memento getMemento() throws MementoException { |
||
148 | return new OperationLayerMemento(getName(), |
||
149 | new Memento[]{source.getMemento(), linked.getMemento()}, getSQL()); |
||
150 | } |
||
151 | 1828 | fernando | } |