Revision 1956 trunk/libraries/libGDBMS/src/com/hardcode/gdbms/engine/instruction/AndExprAdapter.java
AndExprAdapter.java | ||
---|---|---|
1 | 1 |
package com.hardcode.gdbms.engine.instruction; |
2 | 2 |
|
3 |
import com.hardcode.gdbms.engine.data.DriverException; |
|
3 |
import com.hardcode.gdbms.engine.data.driver.DriverException;
|
|
4 | 4 |
import com.hardcode.gdbms.engine.values.Value; |
5 |
import com.hardcode.gdbms.parser.Node; |
|
6 | 5 |
|
7 | 6 |
|
8 | 7 |
/** |
... | ... | |
11 | 10 |
* @author Fernando Gonz?lez Cort?s |
12 | 11 |
*/ |
13 | 12 |
public class AndExprAdapter extends AbstractExpression implements Expression { |
14 |
|
|
15 | 13 |
/** |
16 |
* @see com.hardcode.gdbms.engine.instruction.Adapter#setEntity(com.hardcode.gdbms.parser.Node) |
|
14 |
* Evalua expresi?n invocando el m?todo adecuado en funci?n del tipo de |
|
15 |
* expresion (suma, producto, ...) de los objetos Value de la expresion, |
|
16 |
* de las subexpresiones y de los objetos Field |
|
17 |
* |
|
18 |
* @param row Fila en la que se eval?a la expresi?n, en este caso no es |
|
19 |
* necesario, pero las subexpresiones sobre las que se opera pueden |
|
20 |
* ser campos de una tabla, en cuyo caso si es necesario |
|
21 |
* |
|
22 |
* @return Objeto Value resultado de la operaci?n AND de la expresi?n |
|
23 |
* representada por el nodo sobre el cual ?ste objeto es adaptador |
|
24 |
* |
|
25 |
* @throws SemanticException Si se produce un error sem?ntico |
|
26 |
* @throws DriverException Si se produce un error de I/O |
|
17 | 27 |
*/ |
18 |
public void setEntity(Node o) { |
|
19 |
super.setEntity(o); |
|
20 |
} |
|
21 |
/** |
|
22 |
* Evalua expresi?n invocando el m?todo adecuado en funci?n del tipo de |
|
23 |
* expresion (suma, producto, ...) de los objetos Value de la expresion, |
|
24 |
* de las subexpresiones y de los objetos Field |
|
25 |
* |
|
26 |
* @param row Fila en la que se eval?a la expresi?n, en este caso no es |
|
27 |
* necesario, pero las subexpresiones sobre las que se opera pueden |
|
28 |
* ser campos de una tabla, en cuyo caso si es necesario |
|
29 |
* |
|
30 |
* @return Objeto Value resultado de la operaci?n AND de la expresi?n |
|
31 |
* representada por el nodo sobre el cual ?ste objeto es adaptador |
|
32 |
* |
|
33 |
* @throws SemanticException Si se produce un error sem?ntico |
|
34 |
* @throws DriverException Si se produce un error de I/O |
|
35 |
*/ |
|
36 |
public Value evaluate(long row) throws SemanticException, DriverException { |
|
37 |
Value ret = null; |
|
28 |
public Value evaluate(long row) throws SemanticException, DriverException { |
|
29 |
Value ret = null; |
|
38 | 30 |
|
39 |
Adapter[] expr = (Adapter[]) getChilds();
|
|
31 |
Adapter[] expr = (Adapter[]) getChilds();
|
|
40 | 32 |
|
41 |
if (expr.length > 0) {
|
|
42 |
ret = ((Expression) expr[0]).evaluateExpression(row);
|
|
33 |
if (expr.length > 0) {
|
|
34 |
ret = ((Expression) expr[0]).evaluateExpression(row);
|
|
43 | 35 |
|
44 |
for (int i = 1; i < expr.length; i++) {
|
|
45 |
ret = ret.and(((Expression) expr[i]).evaluateExpression(row));
|
|
46 |
}
|
|
47 |
}
|
|
36 |
for (int i = 1; i < expr.length; i++) {
|
|
37 |
ret = ret.and(((Expression) expr[i]).evaluateExpression(row));
|
|
38 |
}
|
|
39 |
}
|
|
48 | 40 |
|
49 |
return ret;
|
|
50 |
}
|
|
41 |
return ret;
|
|
42 |
}
|
|
51 | 43 |
|
52 |
/**
|
|
53 |
* @see com.hardcode.gdbms.engine.instruction.Expression#getFieldName()
|
|
54 |
*/
|
|
55 |
public String getFieldName() {
|
|
56 |
return null;
|
|
57 |
}
|
|
44 |
/**
|
|
45 |
* @see com.hardcode.gdbms.engine.instruction.Expression#getFieldName()
|
|
46 |
*/
|
|
47 |
public String getFieldName() {
|
|
48 |
return null;
|
|
49 |
}
|
|
58 | 50 |
|
59 |
/**
|
|
60 |
* @see com.hardcode.gdbms.engine.instruction.Expression#isLiteral()
|
|
61 |
*/
|
|
62 |
public boolean isLiteral() {
|
|
63 |
return literal;
|
|
64 |
}
|
|
51 |
/**
|
|
52 |
* @see com.hardcode.gdbms.engine.instruction.Expression#isLiteral()
|
|
53 |
*/
|
|
54 |
public boolean isLiteral() {
|
|
55 |
return literal;
|
|
56 |
}
|
|
65 | 57 |
|
66 |
/**
|
|
67 |
* @see com.hardcode.gdbms.engine.instruction.Expression#simplify()
|
|
68 |
*/
|
|
69 |
public void simplify() {
|
|
70 |
Adapter[] childs = getChilds();
|
|
58 |
/**
|
|
59 |
* @see com.hardcode.gdbms.engine.instruction.Expression#simplify()
|
|
60 |
*/
|
|
61 |
public void simplify() {
|
|
62 |
Adapter[] childs = getChilds();
|
|
71 | 63 |
|
72 |
if (childs.length == 1) { |
|
73 |
getParent().replaceChild(this, childs[0]); |
|
74 |
} |
|
75 |
} |
|
64 |
if (childs.length == 1) { |
|
65 |
getParent().replaceChild(this, childs[0]); |
|
66 |
} |
|
67 |
} |
|
68 |
|
|
76 | 69 |
/** |
77 | 70 |
* @see com.hardcode.gdbms.engine.instruction.Expression#calculateLiteralCondition() |
78 | 71 |
*/ |
79 | 72 |
public void calculateLiteralCondition() { |
80 |
literal = Utilities.checkExpressions(getChilds());
|
|
73 |
literal = Utilities.checkExpressions(getChilds());
|
|
81 | 74 |
} |
82 | 75 |
} |
Also available in: Unified diff