1 /* JJT: 0.2.2 */
2
3 package mobisnap.mobile_trx;
4
5 /***
6 * Implements relational expression
7 */
8 public class ASTSQLRelationalExpression extends mobisnap.mobile_trx.SimpleNode {
9 public SimpleNode first;
10 public boolean firstprior = false;
11 public byte type; // 0 -> just first expression; 1 -> first relop(v1) v2
12 // 2 -> in clause; 3 -> between clause
13 // 4 -> like clause; 5 -> is null clause
14 public Object v1, v2;
15 public boolean secondprior = false;
16 public boolean secondquery = false;
17
18 public ASTSQLRelationalExpression(int id) {
19 super(id);
20 }
21
22 public ASTSQLRelationalExpression( MobisnapSQL p, int i) {
23 super( p, i);
24 id = i;
25 }
26
27 /*** Accept the visitor. **/
28 public Object jjtAccept(MobisnapSQLVisitor visitor, Object data) {
29 return visitor.visit(this, data);
30 }
31
32 /***
33 * Returns the value of the expression
34 *
35 * @param msql_type Specifies which type of processing should be performed
36 * MobisnapConstants.MSQL_SERVER = 1
37 * MobisnapConstants.MSQL_TENTATIVE_CLIENT = 2
38 * MobisnapConstants.MSQL_STABLE_CLIENT = 3
39 * MobisnapConstants.MSQL_RESERVATION_CLIENT = 4
40 * @param cond True if reservations associated iwth transaction should be
41 * propagated to the current transaction
42 */
43 public Object value( int msql_type, boolean cond) throws Exception {
44 if( firstprior)
45 throw new UnknownValueException( "Prior not supported in SQLRelationalExpression");
46 if( type == 0)
47 return first.value( msql_type, cond);
48 if( type > 1)
49 throw new UnknownValueException( "Not a simple comparison");
50 if( secondprior)
51 throw new UnknownValueException( "Prior not supported in SQLRelationalExpression");
52 if( secondquery)
53 throw new UnknownValueException( "Subquery not supported in SQLRelationalExpression");
54 ASTRelop op = (ASTRelop)v1;
55 switch( op.type) {
56 case ASTRelop.OP_EQUAL:
57 return MSQLTypeUtil.equal( first.value( msql_type, cond), ((ASTSQLSimpleExpression)v2).value( msql_type, cond));
58 case ASTRelop.OP_NOTEQUAL:
59 return MSQLTypeUtil.notEqual( first.value( msql_type, cond), ((ASTSQLSimpleExpression)v2).value( msql_type, cond));
60 /* case ASTRelop.OP_CARDINAL:
61 return MSQLTypeUtil.cardinal( first.value( msql_type, cond), ((ASTSQLSimpleExpression)v2).value( msql_type, cond));
62 */ case ASTRelop.OP_MOREORLESS:
63 return MSQLTypeUtil.moreOrLess( first.value( msql_type, cond), ((ASTSQLSimpleExpression)v2).value( msql_type, cond));
64 case ASTRelop.OP_MORE:
65 return MSQLTypeUtil.more( first.value( msql_type, cond), ((ASTSQLSimpleExpression)v2).value( msql_type, cond));
66 case ASTRelop.OP_MOREEQUAL:
67 return MSQLTypeUtil.moreEqual( first.value( msql_type, cond), ((ASTSQLSimpleExpression)v2).value( msql_type, cond));
68 case ASTRelop.OP_LESS:
69 return MSQLTypeUtil.less( first.value( msql_type, cond), ((ASTSQLSimpleExpression)v2).value( msql_type, cond));
70 case ASTRelop.OP_LESSEQUAL:
71 return MSQLTypeUtil.lessEqual( first.value( msql_type, cond), ((ASTSQLSimpleExpression)v2).value( msql_type, cond));
72 default:
73 throw new mobisnap.MobisnapException( "Internal error 1 in relational expression");
74 }
75 }
76
77 /***
78 * Returns a simplified node, if possible (usefull in expressions)
79 *
80 * @param msql_type Specifies which type of processing should be performed
81 * MobisnapConstants.MSQL_SERVER = 1
82 * MobisnapConstants.MSQL_TENTATIVE_CLIENT = 2
83 * MobisnapConstants.MSQL_STABLE_CLIENT = 3
84 * MobisnapConstants.MSQL_RESERVATION_CLIENT = 4
85 * @param cond True if reservations associated iwth transaction should be
86 * propagated to the current transaction
87 */
88 public SimpleNode simplify( int msql_type, boolean cond) {
89 first = (SimpleNode)first.simplify( msql_type, cond);
90 if( type > 1 || secondquery || secondprior || firstprior)
91 return this;
92 if( type == 0)
93 return first;
94 v2 = ((SimpleNode)v2).simplify( msql_type, cond);
95 try {
96 return new SimpleNodeValue( value( msql_type, cond));
97 } catch( Exception e) {
98 return this;
99 }
100 }
101
102 }
This page was automatically generated by Maven