1 /* JJT: 0.2.2 */ 2 3 package mobisnap.mobile_trx; 4 5 import java.util.*; 6 7 /*** 8 * Implements multiplicative expression 9 */ 10 public class ASTSQLMultiplicativeExpression extends mobisnap.mobile_trx.SimpleNode { 11 public static final byte OP_MULTI = 0; 12 public static final byte OP_DIVI = 1; 13 14 public SimpleNode first; 15 public Vector ands; 16 17 public ASTSQLMultiplicativeExpression(int id) { 18 super(id); 19 ands = new Vector(); 20 } 21 22 public ASTSQLMultiplicativeExpression( MobisnapSQL p, int i) { 23 super( p, i); 24 id = i; 25 ands = new Vector(); 26 } 27 28 /*** Accept the visitor. **/ 29 public Object jjtAccept(MobisnapSQLVisitor visitor, Object data) { 30 return visitor.visit(this, data); 31 } 32 33 public class term { 34 public byte opType; 35 public SimpleNode expr; 36 37 public term( byte opType, ASTSQLExpotentExpression expr) { 38 this.opType = opType; 39 this.expr = expr; 40 } 41 }; 42 43 public void insert( byte opType, ASTSQLExpotentExpression expr) { 44 ands.addElement( new term( opType, expr)); 45 } 46 47 /*** 48 * Returns the value of the expression 49 * 50 * @param msql_type Specifies which type of processing should be performed 51 * MobisnapConstants.MSQL_SERVER = 1 52 * MobisnapConstants.MSQL_TENTATIVE_CLIENT = 2 53 * MobisnapConstants.MSQL_STABLE_CLIENT = 3 54 * MobisnapConstants.MSQL_RESERVATION_CLIENT = 4 55 * MobisnapConstants.MSQL_STATIC = 10 56 * @param cond True if reservations associated iwth transaction should be 57 * propagated to the current transaction 58 */ 59 public Object value( int msql_type, boolean cond) throws Exception { 60 Object val = first.value( msql_type, cond); 61 for( int i = 0; i < ands.size(); i++) { 62 term t = (term)ands.elementAt( i); 63 if( t.opType == OP_MULTI) 64 val = MSQLTypeUtil.multiply( val, t.expr.value( msql_type, cond)); 65 else 66 val = MSQLTypeUtil.divide( val, t.expr.value( msql_type, cond)); 67 } 68 return val; 69 } 70 71 /*** 72 * Returns a simplified node, if possible (usefull in expressions) 73 * 74 * @param msql_type Specifies which type of processing should be performed 75 * MobisnapConstants.MSQL_SERVER = 1 76 * MobisnapConstants.MSQL_TENTATIVE_CLIENT = 2 77 * MobisnapConstants.MSQL_STABLE_CLIENT = 3 78 * MobisnapConstants.MSQL_RESERVATION_CLIENT = 4 79 * MobisnapConstants.MSQL_STATIC = 10 80 * @param cond True if reservations associated iwth transaction should be 81 * propagated to the current transaction 82 */ 83 public SimpleNode simplify( int msql_type, boolean cond) { 84 first = (SimpleNode)first.simplify( msql_type, cond); 85 for( int i = 0; i < ands.size(); i++) { 86 term t = (term)ands.elementAt(i); 87 t.expr = t.expr.simplify( msql_type, cond); 88 } 89 if( ands.size() == 0) 90 return first; 91 try { 92 return new SimpleNodeValue( value( msql_type, cond)); 93 } catch( Exception e) { 94 return this; 95 } 96 } 97 }

This page was automatically generated by Maven