1 22 23 package org.xquark.extractor.sql; 24 25 26 public class SqlIfThenElse extends SqlExpression { 27 28 private static final String RCSRevision = "$Revision: 1.4 $"; 29 private static final String RCSName = "$Name: $"; 30 31 32 protected SqlExpression _if; 33 protected SqlExpression _then; 34 protected SqlExpression _else; 35 36 39 public SqlIfThenElse() 40 { 41 42 } 43 44 50 public SqlIfThenElse(SqlExpression iif, SqlExpression tthen, SqlExpression eelse) 51 { 52 setIf(iif); 53 setThen(tthen); 54 setElse(eelse); 55 } 56 57 58 public SqlExpression getIf() 59 { 60 return _if; 61 } 62 63 public void setIf(SqlExpression iif) 64 { 65 _if = iif; 66 } 67 68 public SqlExpression getThen() 69 { 70 return _then; 71 } 72 73 public void setThen(SqlExpression tthen) 74 { 75 _then = tthen; 76 } 77 78 public SqlExpression getElse() 79 { 80 return _else; 81 } 82 83 public void setElse(SqlExpression eelse) 84 { 85 _else = eelse; 86 } 87 88 public String toSql (Context context) 89 { 90 92 StringBuffer retVal = new StringBuffer (); 93 retVal.append("( SELECT "); 94 retVal.append(_then.toSql(context)); 95 retVal.append(" FROM DUAL WHERE "); 96 retVal.append(_if.toSql(context)); 97 98 retVal.append(" UNION ALL SELECT "); 99 retVal.append(_else.toSql(context)); 100 retVal.append(" FROM DUAL WHERE NOT ("); 101 retVal.append(_if.toSql(context)); 102 retVal.append(") )"); 103 104 return retVal.toString(); 106 } 107 } 108 | Popular Tags |