Revision 10627 trunk/libraries/libGDBMS/src/main/java/com/hardcode/gdbms/engine/strategies/FilteredDataSource.java
FilteredDataSource.java | ||
---|---|---|
2 | 2 |
|
3 | 3 |
import java.io.IOException; |
4 | 4 |
|
5 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
|
5 | 6 |
import com.hardcode.gdbms.engine.data.DataSource; |
6 |
import com.hardcode.gdbms.engine.data.driver.DriverException; |
|
7 | 7 |
import com.hardcode.gdbms.engine.data.indexes.IndexFactory; |
8 | 8 |
import com.hardcode.gdbms.engine.data.indexes.VariableIndexSet; |
9 | 9 |
import com.hardcode.gdbms.engine.data.persistence.Memento; |
... | ... | |
39 | 39 |
this.whereExpression = whereExpression; |
40 | 40 |
} |
41 | 41 |
|
42 |
public Value[] aggregatedFilter(Expression[] fields) throws IncompatibleTypesException, DriverException, EvaluationException, IOException {
|
|
42 |
public Value[] aggregatedFilter(Expression[] fields) throws IncompatibleTypesException, EvaluationException, ReadDriverException {
|
|
43 | 43 |
Value[] aggregatedValues = new Value[fields.length]; |
44 | 44 |
indexes = IndexFactory.createVariableIndex(); |
45 |
indexes.open(); |
|
46 |
|
|
47 |
for (long i = 0; i < source.getRowCount(); i++) { |
|
48 |
try { |
|
49 |
if (((BooleanValue) whereExpression.evaluateExpression(i)).getValue()) { |
|
50 |
indexes.addIndex(i); |
|
51 |
for (int j = 0; j < aggregatedValues.length; j++) { |
|
52 |
aggregatedValues[j] = fields[j].evaluate(i); |
|
53 |
} |
|
45 |
try { |
|
46 |
indexes.open(); |
|
47 |
for (long i = 0; i < source.getRowCount(); i++) { |
|
48 |
try { |
|
49 |
if (((BooleanValue) whereExpression.evaluateExpression(i)) |
|
50 |
.getValue()) { |
|
51 |
indexes.addIndex(i); |
|
52 |
for (int j = 0; j < aggregatedValues.length; j++) { |
|
53 |
aggregatedValues[j] = fields[j].evaluate(i); |
|
54 |
} |
|
55 |
} |
|
56 |
} catch (ClassCastException e) { |
|
57 |
throw new IncompatibleTypesException( |
|
58 |
"where expression is not boolean"); |
|
54 | 59 |
} |
55 |
} catch (ClassCastException e) { |
|
56 |
throw new IncompatibleTypesException("where expression is not boolean", |
|
57 |
e); |
|
58 | 60 |
} |
61 |
|
|
62 |
indexes.indexSetComplete(); |
|
63 |
} catch (IOException e1) { |
|
64 |
throw new ReadDriverException(getName(),e1); |
|
59 | 65 |
} |
60 |
|
|
61 |
indexes.indexSetComplete(); |
|
62 |
|
|
63 | 66 |
return aggregatedValues; |
64 | 67 |
} |
65 | 68 |
|
66 | 69 |
/** |
67 | 70 |
* M?todo que construye el array de ?ndices de las posiciones que las filas |
68 | 71 |
* filtradas ocupan en el DataSource origen |
69 |
* |
|
70 |
* @throws DriverException Si se produce un fallo en el driver al acceder a |
|
71 |
* los datos |
|
72 |
* @throws IOException Si se produce un error usando las estructuras de |
|
73 |
* datos internas |
|
74 |
* @throws SemanticException Si se produce alg?n error sem?ntico al evaluar |
|
72 |
* @throws SemanticException Si se produce alg?n error sem?ntico al evaluar |
|
75 | 73 |
* la expresi?n |
76 |
* @throws IncompatibleTypesException Si la expresi?n where no evalua a |
|
74 |
* @throws EvaluationException If the expression evaluation fails |
|
75 |
* @throws ReadDriverException TODO |
|
76 |
* @throws IncompatibleTypesException Si la expresi?n where no evalua a |
|
77 | 77 |
* booleano |
78 |
* @throws EvaluationException If the expression evaluation fails |
|
79 | 78 |
*/ |
80 | 79 |
public void filtrar() |
81 |
throws DriverException, IOException, SemanticException, EvaluationException {
|
|
80 |
throws SemanticException, EvaluationException, ReadDriverException {
|
|
82 | 81 |
indexes = IndexFactory.createVariableIndex(); |
83 |
indexes.open(); |
|
84 |
|
|
85 |
for (long i = 0; i < source.getRowCount(); i++) { |
|
86 |
try { |
|
87 |
if (((BooleanValue) whereExpression.evaluateExpression(i)).getValue()) { |
|
88 |
indexes.addIndex(i); |
|
82 |
try { |
|
83 |
indexes.open(); |
|
84 |
for (long i = 0; i < source.getRowCount(); i++) { |
|
85 |
try { |
|
86 |
if (((BooleanValue) whereExpression.evaluateExpression(i)) |
|
87 |
.getValue()) { |
|
88 |
indexes.addIndex(i); |
|
89 |
} |
|
90 |
} catch (ClassCastException e) { |
|
91 |
throw new IncompatibleTypesException( |
|
92 |
"where expression is not boolean"); |
|
89 | 93 |
} |
90 |
} catch (ClassCastException e) { |
|
91 |
throw new IncompatibleTypesException("where expression is not boolean", |
|
92 |
e); |
|
93 | 94 |
} |
95 |
|
|
96 |
indexes.indexSetComplete(); |
|
97 |
} catch (IOException e1) { |
|
98 |
throw new ReadDriverException(getName(),e1); |
|
94 | 99 |
} |
95 |
|
|
96 |
indexes.indexSetComplete(); |
|
97 | 100 |
} |
98 | 101 |
|
99 | 102 |
/** |
100 | 103 |
* @see com.hardcode.gdbms.engine.data.DataSource#open() |
101 | 104 |
*/ |
102 |
public void start() throws DriverException { |
|
105 |
public void start() throws ReadDriverException {
|
|
103 | 106 |
source.start(); |
104 | 107 |
} |
105 | 108 |
|
106 | 109 |
/** |
107 | 110 |
* @see com.hardcode.gdbms.engine.data.DataSource#close() |
108 | 111 |
*/ |
109 |
public void stop() throws DriverException { |
|
112 |
public void stop() throws ReadDriverException {
|
|
110 | 113 |
source.stop(); |
111 | 114 |
|
112 | 115 |
try { |
113 | 116 |
indexes.close(); |
114 | 117 |
} catch (IOException e) { |
115 |
throw new DriverException(e);
|
|
118 |
throw new ReadDriverException(getName(),e);
|
|
116 | 119 |
} |
117 | 120 |
} |
118 | 121 |
|
119 | 122 |
/** |
120 | 123 |
* @see com.hardcode.gdbms.engine.data.FieldNameAccess#getFieldIndexByName(java.lang.String) |
121 | 124 |
*/ |
122 |
public int getFieldIndexByName(String fieldName) throws DriverException { |
|
125 |
public int getFieldIndexByName(String fieldName) throws ReadDriverException {
|
|
123 | 126 |
return source.getFieldIndexByName(fieldName); |
124 | 127 |
} |
125 | 128 |
|
... | ... | |
128 | 131 |
* int) |
129 | 132 |
*/ |
130 | 133 |
public Value getFieldValue(long rowIndex, int fieldId) |
131 |
throws DriverException { |
|
134 |
throws ReadDriverException {
|
|
132 | 135 |
try { |
133 | 136 |
return source.getFieldValue(indexes.getIndex(rowIndex), fieldId); |
134 | 137 |
} catch (IOException e) { |
135 |
throw new DriverException(e);
|
|
138 |
throw new ReadDriverException(getName(),e);
|
|
136 | 139 |
} |
137 | 140 |
} |
138 | 141 |
|
139 | 142 |
/** |
140 | 143 |
* @see com.hardcode.gdbms.engine.data.driver.ReadAccess#getFieldCount() |
141 | 144 |
*/ |
142 |
public int getFieldCount() throws DriverException { |
|
145 |
public int getFieldCount() throws ReadDriverException {
|
|
143 | 146 |
return source.getFieldCount(); |
144 | 147 |
} |
145 | 148 |
|
146 | 149 |
/** |
147 | 150 |
* @see com.hardcode.gdbms.engine.data.driver.ReadAccess#getFieldName(int) |
148 | 151 |
*/ |
149 |
public String getFieldName(int fieldId) throws DriverException { |
|
152 |
public String getFieldName(int fieldId) throws ReadDriverException {
|
|
150 | 153 |
return source.getFieldName(fieldId); |
151 | 154 |
} |
152 | 155 |
|
153 | 156 |
/** |
154 | 157 |
* @see com.hardcode.gdbms.engine.data.driver.ReadAccess#getRowCount() |
155 | 158 |
*/ |
156 |
public long getRowCount() throws DriverException { |
|
159 |
public long getRowCount() throws ReadDriverException {
|
|
157 | 160 |
return indexes.getIndexCount(); |
158 | 161 |
} |
159 | 162 |
|
... | ... | |
173 | 176 |
/** |
174 | 177 |
* @see com.hardcode.gdbms.engine.data.driver.ObjectDriver#getFieldType(int) |
175 | 178 |
*/ |
176 |
public int getFieldType(int i) throws DriverException { |
|
179 |
public int getFieldType(int i) throws ReadDriverException {
|
|
177 | 180 |
return source.getFieldType(i); |
178 | 181 |
} |
179 | 182 |
|
... | ... | |
185 | 188 |
new Memento[] { source.getMemento() }, getSQL()); |
186 | 189 |
} |
187 | 190 |
|
188 |
public int getFieldWidth(int i) throws DriverException {
|
|
191 |
public int getFieldWidth(int i) throws ReadDriverException {
|
|
189 | 192 |
return source.getFieldWidth(i); |
190 | 193 |
} |
191 | 194 |
} |
Also available in: Unified diff