Clover coverage report - Replica - 1.0-Alpha
Coverage timestamp: Dom Fev 1 2004 17:00:58 WET
file stats: LOC: 180   Methods: 6
NCLOC: 135   Classes: 1
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover
 
 Source file Conditionals Statements Methods TOTAL
ASTSQLPrimaryExpression.java 0% 0% 0% 0%
coverage
 1   
 /* JJT:    0.2.2 */
 2   
 
 3   
 package    mobisnap.mobile_trx;
 4   
 
 5   
 /**
 6   
  * Implements primary sql expression : variables, numbers, ...
 7   
  */
 8   
 public class ASTSQLPrimaryExpression extends mobisnap.mobile_trx.SimpleNode {
 9   
     public static final byte EXPR_NULL = 1;
 10   
     public static final byte EXPR_FUNCTION = 2;
 11   
     public static final byte EXPR_OUTERJOIN = 3;
 12   
     public static final byte EXPR_VARIABLE = 4;
 13   
     public static final byte EXPR_SYSDATE = 5;
 14   
     public static final byte EXPR_SQLNUMBER = 6;
 15   
     public static final byte EXPR_SQLCHARLITERAL = 7;
 16   
     public static final byte EXPR_SQLBIND = 8;
 17   
     public static final byte EXPR_SQLEXPR = 9;
 18   
     public static final byte EXPR_CURSYSDATE = 10;    //v1 = curdate
 19   
     public static final byte EXPR_NEWUID = 11;        //v1 = uid
 20   
 
 21   
     public byte type;
 22   
     public Object v1, v2;
 23   
 
 24  0
     public ASTSQLPrimaryExpression(int id) {
 25  0
         super(id);
 26   
     }
 27   
 
 28  0
     public ASTSQLPrimaryExpression( MobisnapSQL p, int i) {
 29  0
         super( p, i);
 30  0
         id = i;
 31   
     }
 32   
 
 33   
     /** Accept the visitor. **/
 34  0
     public Object jjtAccept(MobisnapSQLVisitor visitor, Object data) {
 35  0
         return visitor.visit(this, data);
 36   
     }
 37   
     
 38   
     /**
 39   
      * Displays the source code of the node
 40   
      */
 41  0
     public void    sourceCode(    int msql_type, StringBuffer buffer) throws Exception {
 42  0
         if( msql_type == mobisnap.MobisnapConstants.MSQL_ORIGINAL) {
 43  0
             switch( type) {
 44   
             case EXPR_CURSYSDATE:
 45  0
                 buffer.append( "'");
 46  0
                 buffer.append( MSQLTypeUtil.date2String( (java.util.Date)v1));
 47  0
                 buffer.append( "'");
 48  0
                 break;
 49   
             case EXPR_NEWUID:
 50  0
                 buffer.append( "'");
 51  0
                 buffer.append( ((mobisnap.common.MobisnapUID)v1).toString());
 52  0
                 buffer.append( "'");
 53  0
                 break;
 54   
             default:
 55  0
                 super.sourceCode( msql_type, buffer);
 56  0
                 break;
 57   
             }
 58  0
             return;
 59   
         }
 60  0
         switch( type) {
 61   
         case EXPR_VARIABLE:
 62  0
             StringBuffer buf = new StringBuffer();
 63  0
             ((ASTTableColumn)v1).sourceCode( msql_type, buf);
 64  0
             MSQLTName var = null;
 65  0
             try {
 66  0
                 var = MobisnapSQL.names.getName( buf.toString().trim());
 67   
             } catch( Exception e) {
 68  0
                 var = null;
 69   
             }
 70  0
             if( var == null) {
 71  0
                 buffer.append( buf.toString());
 72   
             } else {
 73  0
                 Object obj = var.getValue();
 74  0
                 if( obj instanceof String) {
 75  0
                     buffer.append( "'");
 76  0
                     buffer.append( obj.toString());
 77  0
                     buffer.append( "'");
 78  0
                 } else if( obj instanceof java.sql.Date)
 79  0
                     buffer.append( MSQLTypeUtil.date2String( (java.sql.Date)obj));
 80   
                 else
 81  0
                     buffer.append( obj.toString());
 82   
             }
 83  0
             break;
 84   
         case EXPR_SYSDATE:
 85  0
             buffer.append( "'");
 86  0
             buffer.append( MSQLTypeUtil.date2String( new java.util.Date()));
 87  0
             buffer.append( "'");
 88  0
             break;
 89   
         case EXPR_CURSYSDATE:
 90  0
             buffer.append( "'");
 91  0
             buffer.append( MSQLTypeUtil.date2String( (java.util.Date)v1));
 92  0
             buffer.append( "'");
 93  0
             break;
 94   
         case EXPR_NEWUID:
 95  0
             buffer.append( "'");
 96  0
             buffer.append( ((mobisnap.common.MobisnapUID)v1).toString());
 97  0
             buffer.append( "'");
 98  0
             break;
 99   
         default:
 100  0
             super.sourceCode( msql_type, buffer);
 101  0
             break;
 102   
         }
 103   
     }
 104   
     
 105   
 
 106   
     
 107   
     /**
 108   
      * Returns the value of the expression
 109   
      * 
 110   
      * @param msql_type Specifies which type of processing should be performed
 111   
      *        MobisnapConstants.MSQL_SERVER = 1
 112   
      *        MobisnapConstants.MSQL_TENTATIVE_CLIENT = 2
 113   
      *        MobisnapConstants.MSQL_STABLE_CLIENT = 3
 114   
      *        MobisnapConstants.MSQL_RESERVATION_CLIENT = 4
 115   
      *        MobisnapConstants.MSQL_STATIC = 10
 116   
      * @param cond True if reservations associated iwth transaction should be 
 117   
      * propagated to the current transaction
 118   
      */
 119  0
     public Object value( int msql_type, boolean cond) throws Exception {
 120  0
         switch( type) {
 121   
         case EXPR_NULL:
 122  0
             return new SQLNull();
 123   
         case EXPR_SQLNUMBER:
 124  0
             return MSQLTypeUtil.string2Decimal( (String)v1);
 125   
         case EXPR_VARIABLE:
 126  0
             if( msql_type == mobisnap.MobisnapConstants.MSQL_ORIGINAL)
 127  0
                 return v1;
 128  0
             StringBuffer buf = new StringBuffer();
 129  0
             ((ASTTableColumn)v1).sourceCode( mobisnap.MobisnapConstants.MSQL_SERVER, buf);
 130  0
             MSQLTName var = null;
 131  0
             try {
 132  0
                 var = MobisnapSQL.names.getName( buf.toString().trim());
 133   
             } catch( NoReservationException e) {
 134  0
                 throw e;
 135   
             } catch( Exception e) {
 136  0
                 var = null;
 137   
             }
 138  0
             if( var == null)
 139  0
                 throw new UnknownValueException( "Unknown variable - it should be a column");
 140   
             else
 141  0
                 return var.getValue();
 142   
         case EXPR_SQLCHARLITERAL:
 143  0
             return v1;
 144   
         case EXPR_SQLEXPR:
 145  0
             return ((SimpleNode)v1).value( msql_type, cond);
 146   
         case EXPR_SYSDATE:
 147  0
             return new java.sql.Date( new java.util.Date().getTime());
 148   
         case EXPR_CURSYSDATE:
 149  0
             return v1;
 150   
         case EXPR_NEWUID:
 151  0
             return ((mobisnap.common.MobisnapUID)v1).toString();
 152   
         default:
 153  0
             throw new UnknownValueException( "Unhandled SQLPrimaryExpression");
 154   
         }
 155   
     }
 156   
     
 157   
     /**
 158   
      * Returns a simplified node, if possible (usefull in expressions)
 159   
      * 
 160   
      * @param msql_type Specifies which type of processing should be performed
 161   
      *        MobisnapConstants.MSQL_SERVER = 1
 162   
      *        MobisnapConstants.MSQL_TENTATIVE_CLIENT = 2
 163   
      *        MobisnapConstants.MSQL_STABLE_CLIENT = 3
 164   
      *        MobisnapConstants.MSQL_RESERVATION_CLIENT = 4
 165   
      *        MobisnapConstants.MSQL_STATIC = 10
 166   
      * @param cond True if reservations associated iwth transaction should be 
 167   
      * propagated to the current transaction
 168   
      */
 169  0
     public SimpleNode simplify( int msql_type, boolean cond) {
 170  0
         if( type == EXPR_SQLEXPR)
 171  0
             return ((SimpleNode)v1).simplify( msql_type, cond);
 172  0
         try {
 173  0
             return new SimpleNodeValue( value( msql_type, cond));
 174   
         } catch( Exception e) {
 175  0
             return this;
 176   
         }
 177   
     }
 178   
 
 179   
 }
 180