1 /* JJT: 0.2.2 */ 2 3 package mobisnap.mobile_trx; 4 5 6 /*** 7 * Implements primary sql expression : variables, numbers, ... 8 */ 9 public class ASTPlSqlPrimaryExpression extends mobisnap.mobile_trx.SimpleNode { 10 public static final byte EXPR_NULL = 0; 11 public static final byte EXPR_CURSORFOUND = 1; 12 public static final byte EXPR_CURSORNOTFOUND = 2; 13 public static final byte EXPR_CURSORISOPEN = 3; 14 public static final byte EXPR_CURSORROWCOUNT = 4; 15 public static final byte EXPR_FUNCTION = 5; 16 public static final byte EXPR_VARIABLE = 6; 17 public static final byte EXPR_SQLCURSOR = 7; 18 public static final byte EXPR_SQLNUMBER = 8; 19 public static final byte EXPR_SQLCHARLITERAL = 9; 20 public static final byte EXPR_SQLBIND = 10; 21 public static final byte EXPR_SQLEXPR = 11; 22 public static final byte EXPR_SYSDATE = 12; 23 public static final byte EXPR_CURSYSDATE = 13; //v1 = curdate 24 public static final byte EXPR_NEWUID = 14; //v1 = uid 25 26 public byte type; 27 public Object v1, v2; 28 29 public ASTPlSqlPrimaryExpression(int id) { 30 super(id); 31 } 32 33 public ASTPlSqlPrimaryExpression( MobisnapSQL p, int i) { 34 super( p, i); 35 id = i; 36 } 37 38 /*** Accept the visitor. **/ 39 public Object jjtAccept(MobisnapSQLVisitor visitor, Object data) { 40 return visitor.visit(this, data); 41 } 42 43 /*** 44 * Displays the source code of the node 45 */ 46 public void sourceCode( int msql_type, StringBuffer buffer) throws Exception { 47 if( msql_type == mobisnap.MobisnapConstants.MSQL_ORIGINAL) { 48 switch( type) { 49 case EXPR_CURSYSDATE: 50 buffer.append( "'"); 51 buffer.append( MSQLTypeUtil.date2String( (java.util.Date)v1)); 52 buffer.append( "'"); 53 break; 54 case EXPR_NEWUID: 55 buffer.append( "'"); 56 buffer.append( ((mobisnap.common.MobisnapUID)v1).toString()); 57 buffer.append( "'"); 58 break; 59 default: 60 super.sourceCode( msql_type, buffer); 61 break; 62 } 63 return; 64 } 65 66 switch( type) { 67 case EXPR_VARIABLE: 68 Object obj = MobisnapSQL.names.getName( (String)v1).getValue(); 69 if( obj instanceof String) { 70 buffer.append( "'"); 71 buffer.append( obj.toString()); 72 buffer.append( "'"); 73 } else if( obj instanceof java.sql.Date) 74 buffer.append( MSQLTypeUtil.date2String( (java.sql.Date)obj)); 75 else 76 buffer.append( obj.toString()); 77 break; 78 case EXPR_SQLCHARLITERAL: 79 buffer.append( "'"); 80 buffer.append( v1); 81 buffer.append( "'"); 82 break; 83 case EXPR_SYSDATE: 84 buffer.append( "'"); 85 buffer.append( MSQLTypeUtil.date2String( new java.util.Date())); 86 buffer.append( "'"); 87 break; 88 case EXPR_CURSYSDATE: 89 buffer.append( "'"); 90 buffer.append( MSQLTypeUtil.date2String( (java.util.Date)v1)); 91 buffer.append( "'"); 92 break; 93 case EXPR_NEWUID: 94 buffer.append( "'"); 95 buffer.append( ((mobisnap.common.MobisnapUID)v1).toString()); 96 buffer.append( "'"); 97 break; 98 default: 99 super.sourceCode( msql_type, buffer); 100 break; 101 } 102 } 103 104 105 106 /*** 107 * Returns the value of the expression 108 * 109 * @param msql_type Specifies which type of processing should be performed 110 * MobisnapConstants.MSQL_SERVER = 1 111 * MobisnapConstants.MSQL_TENTATIVE_CLIENT = 2 112 * MobisnapConstants.MSQL_STABLE_CLIENT = 3 113 * MobisnapConstants.MSQL_RESERVATION_CLIENT = 4 114 * @param cond True if reservations associated iwth transaction should be 115 * propagated to the current transaction 116 */ 117 public Object value( int msql_type, boolean cond) throws Exception { 118 switch( type) { 119 case EXPR_NULL: 120 return new SQLNull(); 121 case EXPR_SQLNUMBER: 122 return MSQLTypeUtil.string2Decimal( (String)v1); 123 case EXPR_VARIABLE: 124 if( msql_type == mobisnap.MobisnapConstants.MSQL_ORIGINAL) 125 return v1; 126 MSQLTName var = null; 127 try { 128 var = MobisnapSQL.names.getName( (String)v1); 129 } catch( NoReservationException e) { 130 throw e; 131 } catch( Exception e) { 132 var = null; 133 } 134 if( var == null) 135 throw new UnknownValueException( "Unknown variable"); 136 else 137 return var.getValue(); 138 case EXPR_SQLCHARLITERAL: 139 return v1; 140 case EXPR_SQLEXPR: 141 return ((ASTPlSqlExpression)v1).value( msql_type, cond); 142 case EXPR_SYSDATE: 143 return new java.sql.Date( new java.util.Date().getTime()); 144 case EXPR_CURSYSDATE: 145 return v1; 146 case EXPR_NEWUID: 147 return ((mobisnap.common.MobisnapUID)v1).toString(); 148 default: 149 throw new mobisnap.MobisnapException( "SqlPrimaryExpression error"); 150 } 151 } 152 153 154 }

This page was automatically generated by Maven