|
|||||||||||||||||||
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 | |||||||||||||||
ASTSQLExpression.java | 0% | 0% | 0% | 0% |
|
1 |
/* JJT: 0.2.2 */
|
|
2 |
|
|
3 |
package mobisnap.mobile_trx;
|
|
4 |
|
|
5 |
import java.util.*;
|
|
6 |
|
|
7 |
/**
|
|
8 |
* Implements sql expression
|
|
9 |
*/
|
|
10 |
public class ASTSQLExpression extends mobisnap.mobile_trx.SimpleNode { |
|
11 |
public Vector ors;
|
|
12 |
|
|
13 | 0 |
public ASTSQLExpression(int id) { |
14 | 0 |
super(id);
|
15 | 0 |
ors = new Vector();
|
16 |
} |
|
17 |
|
|
18 | 0 |
public ASTSQLExpression( MobisnapSQL p, int i) { |
19 | 0 |
super( p, i);
|
20 | 0 |
id = i; |
21 | 0 |
ors = new Vector();
|
22 |
} |
|
23 |
|
|
24 |
/** Accept the visitor. **/
|
|
25 | 0 |
public Object jjtAccept(MobisnapSQLVisitor visitor, Object data) {
|
26 | 0 |
return visitor.visit(this, data); |
27 |
} |
|
28 |
|
|
29 |
/**
|
|
30 |
* Returns the value of the expression
|
|
31 |
*
|
|
32 |
* @param msql_type Specifies which type of processing should be performed
|
|
33 |
* MobisnapConstants.MSQL_SERVER = 1
|
|
34 |
* MobisnapConstants.MSQL_TENTATIVE_CLIENT = 2
|
|
35 |
* MobisnapConstants.MSQL_STABLE_CLIENT = 3
|
|
36 |
* MobisnapConstants.MSQL_RESERVATION_CLIENT = 4
|
|
37 |
* @param cond True if reservations associated iwth transaction should be
|
|
38 |
* propagated to the current transaction
|
|
39 |
*/
|
|
40 | 0 |
public Object value( int msql_type, boolean cond) throws Exception { |
41 | 0 |
int n = ors.size();
|
42 | 0 |
if( n == 0)
|
43 | 0 |
throw new mobisnap.MobisnapException( "Internal error in expotent expression"); |
44 | 0 |
Object val = ((SimpleNode)ors.elementAt(0)).value( msql_type, cond); |
45 | 0 |
for( int i = 1; i < n; i++) { |
46 | 0 |
Object aux = ((SimpleNode)ors.elementAt( i)).value( msql_type, cond); |
47 | 0 |
val = MSQLTypeUtil.or( val, aux); |
48 |
} |
|
49 | 0 |
return val;
|
50 |
} |
|
51 |
|
|
52 |
/**
|
|
53 |
* Displays the source code of the node
|
|
54 |
*/
|
|
55 | 0 |
public void sourceCode( int msql_type, StringBuffer buffer) throws Exception { |
56 | 0 |
if( msql_type == mobisnap.MobisnapConstants.MSQL_ORIGINAL) {
|
57 | 0 |
super.sourceCode( msql_type, buffer);
|
58 | 0 |
return;
|
59 |
} |
|
60 | 0 |
try {
|
61 | 0 |
Object obj = value( msql_type, false);
|
62 | 0 |
if( obj instanceof String) { |
63 | 0 |
buffer.append( "'");
|
64 | 0 |
buffer.append( obj.toString()); |
65 | 0 |
buffer.append( "'");
|
66 | 0 |
} else if( obj instanceof java.sql.Date) { |
67 | 0 |
buffer.append( "'");
|
68 | 0 |
buffer.append( MSQLTypeUtil.date2String( (java.sql.Date)obj)); |
69 | 0 |
buffer.append( "'");
|
70 |
} else
|
|
71 | 0 |
buffer.append( obj.toString()); |
72 |
} catch( Exception e) {
|
|
73 | 0 |
super.sourceCode( msql_type, buffer);
|
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 | 0 |
public SimpleNode simplify( int msql_type, boolean cond) { |
89 | 0 |
for( int i = 0; i < ors.size(); i++) |
90 | 0 |
ors.setElementAt( ((SimpleNode)ors.elementAt(i)).simplify( msql_type, cond), i); |
91 | 0 |
if( ors.size() == 1)
|
92 | 0 |
return (SimpleNode)ors.elementAt( 0);
|
93 | 0 |
try {
|
94 | 0 |
return new SimpleNodeValue( value( msql_type, cond)); |
95 |
} catch( Exception e) {
|
|
96 | 0 |
return this; |
97 |
} |
|
98 |
} |
|
99 |
|
|
100 |
|
|
101 |
|
|
102 |
|
|
103 |
} |
|
104 |
|
|