svn-gvsig-desktop / trunk / libraries / libGDBMS / src / com / hardcode / gdbms / engine / instruction / TermAdapter.java @ 466
History | View | Annotate | Download (2.55 KB)
1 |
/* Generated by Together */
|
---|---|
2 |
package com.hardcode.gdbms.engine.instruction; |
3 |
|
4 |
import com.hardcode.gdbms.engine.data.DriverException; |
5 |
import com.hardcode.gdbms.engine.values.Value; |
6 |
import com.hardcode.gdbms.parser.ASTSQLColRef; |
7 |
import com.hardcode.gdbms.parser.ASTSQLFunction; |
8 |
import com.hardcode.gdbms.parser.ASTSQLLiteral; |
9 |
import com.hardcode.gdbms.parser.ASTSQLOrExpr; |
10 |
import com.hardcode.gdbms.parser.SimpleNode; |
11 |
|
12 |
|
13 |
/**
|
14 |
* Wrapper sobre el nodo Term del arbol sint?ctico
|
15 |
*
|
16 |
* @author Fernando Gonz?lez Cort?s
|
17 |
*/
|
18 |
public class TermAdapter extends AbstractExpression implements Expression { |
19 |
/**
|
20 |
* @see com.hardcode.gdbms.engine.instruction.Expression#evaluate(long)
|
21 |
*/
|
22 |
public Value evaluate(long row) throws SemanticException, DriverException { |
23 |
Adapter[] hijos = getChilds();
|
24 |
|
25 |
if (hijos[0] instanceof Expression) { |
26 |
return ((Expression) hijos[0]).evaluateExpression(row); |
27 |
} else {
|
28 |
return null; |
29 |
} |
30 |
} |
31 |
|
32 |
/**
|
33 |
* @see com.hardcode.gdbms.engine.instruction.Expression#getFieldName()
|
34 |
*/
|
35 |
public String getFieldName() { |
36 |
SimpleNode child = (SimpleNode) getEntity().jjtGetChild(0);
|
37 |
|
38 |
if (child.first_token.image.equals("(")) { |
39 |
child = (SimpleNode) getEntity().jjtGetChild(0);
|
40 |
} |
41 |
|
42 |
if (child.getClass() == ASTSQLColRef.class) {
|
43 |
return Utilities.getText(child); |
44 |
} else {
|
45 |
return null; |
46 |
} |
47 |
} |
48 |
|
49 |
/**
|
50 |
* @see com.hardcode.gdbms.engine.instruction.Expression#isLiteral()
|
51 |
*/
|
52 |
public boolean isLiteral() { |
53 |
return literal;
|
54 |
} |
55 |
|
56 |
/**
|
57 |
* @see com.hardcode.gdbms.engine.instruction.Expression#simplify()
|
58 |
*/
|
59 |
public void simplify() { |
60 |
getParent().replaceChild(this, getChilds()[0]); |
61 |
} |
62 |
|
63 |
/**
|
64 |
* @see com.hardcode.gdbms.engine.instruction.Expression#calculateLiteralCondition()
|
65 |
*/
|
66 |
public void calculateLiteralCondition() { |
67 |
SimpleNode child = (SimpleNode) getEntity().jjtGetChild(0);
|
68 |
|
69 |
if (child.first_token.image.equals("(")) { |
70 |
child = (SimpleNode) getEntity().jjtGetChild(0);
|
71 |
} |
72 |
|
73 |
if (child.getClass() == ASTSQLColRef.class) {
|
74 |
literal = false;
|
75 |
} else if (child.getClass() == ASTSQLFunction.class) { |
76 |
literal = false;
|
77 |
} else if (child.getClass() == ASTSQLLiteral.class) { |
78 |
literal = true;
|
79 |
} else if (child.getClass() == ASTSQLOrExpr.class) { |
80 |
literal = ((Expression) getChilds()[0]).isLiteral(); |
81 |
} else {
|
82 |
throw new RuntimeException("really passed the parse???"); |
83 |
} |
84 |
} |
85 |
} |