1 28 29 package com.caucho.amber.expr.fun; 30 31 import com.caucho.amber.expr.AmberExpr; 32 import com.caucho.amber.query.QueryParser; 33 import com.caucho.util.CharBuffer; 34 import com.caucho.util.L10N; 35 36 import java.util.ArrayList ; 37 38 39 42 public class ConcatFunExpr extends FunExpr { 43 private static final L10N L = new L10N(ConcatFunExpr.class); 44 45 48 protected ConcatFunExpr(QueryParser parser, 49 ArrayList <AmberExpr> args) 50 { 51 super(parser, "concat", args, false); 52 } 53 54 public static FunExpr create(QueryParser parser, 55 ArrayList <AmberExpr> args) 56 { 57 return new ConcatFunExpr(parser, args); 58 } 59 60 63 public void generateWhere(CharBuffer cb) 64 { 65 generateInternalWhere(cb, true); 66 } 67 68 71 public void generateUpdateWhere(CharBuffer cb) 72 { 73 generateInternalWhere(cb, false); 74 } 75 76 79 void generateInternalWhere(CharBuffer cb, 80 boolean select) 81 { 82 ArrayList <AmberExpr> args = getArgs(); 83 84 int n = args.size(); 85 86 90 if (_parser.isDerbyDBMS()) { 91 92 95 98 cb.append("VARCHAR(CAST("); 99 100 if (select) 101 args.get(0).generateWhere(cb); 102 else 103 args.get(0).generateUpdateWhere(cb); 104 105 cb.append("AS VARCHAR(2000)) || CAST("); 106 107 if (select) 108 args.get(1).generateWhere(cb); 109 else 110 args.get(1).generateUpdateWhere(cb); 111 112 cb.append(" AS VARCHAR(2000)))"); 113 114 return; 115 } 116 else if (_parser.isPostgresDBMS()) { 117 generateInternalConcat(cb, true, true, null, select); 119 return; 120 } 121 122 cb.append("concat"); 123 124 generateInternalConcat(cb, true, true, null, select); 125 } 126 127 private void generateInternalConcat(CharBuffer cb, 128 boolean arg0, 129 boolean arg1, 130 String str, 131 boolean select) 132 { 133 ArrayList <AmberExpr> args = getArgs(); 134 135 boolean usesConcatOperator 136 = _parser.isDerbyDBMS() || _parser.isPostgresDBMS(); 137 138 cb.append('('); 139 140 if (arg0) { 141 if (select) 142 args.get(0).generateWhere(cb); 143 else 144 args.get(0).generateUpdateWhere(cb); 145 146 if (usesConcatOperator) 147 cb.append(" || "); 148 else 149 cb.append(','); 150 } 151 152 if (arg1) { 153 if (select) 154 args.get(1).generateWhere(cb); 155 else 156 args.get(1).generateUpdateWhere(cb); 157 158 if (arg0) { 159 cb.append(')'); 160 return; 161 } 162 163 if (usesConcatOperator) 164 cb.append(" || "); 165 else 166 cb.append(','); 167 } 168 169 cb.append('\''); 170 171 cb.append(str); 172 173 cb.append('\''); 174 175 cb.append(')'); 176 } 177 } 178 | Popular Tags |