1 28 29 package com.caucho.amber.expr.fun; 30 31 import com.caucho.amber.expr.*; 32 import com.caucho.amber.query.*; 33 import com.caucho.amber.table.*; 34 import com.caucho.util.CharBuffer; 35 import com.caucho.util.L10N; 36 37 import java.util.ArrayList ; 38 39 40 43 public class SizeFunExpr extends FunExpr { 44 private static final L10N L = new L10N(SizeFunExpr.class); 45 46 49 protected SizeFunExpr(QueryParser parser, 50 ArrayList <AmberExpr> args) 51 { 52 super(parser, "size", args, false); 53 } 54 55 public static FunExpr create(QueryParser parser, 56 ArrayList <AmberExpr> args) 57 { 58 return new SizeFunExpr(parser, args); 59 } 60 61 64 public void generateWhere(CharBuffer cb) 65 { 66 generateInternalWhere(cb, true); 67 } 68 69 72 public void generateUpdateWhere(CharBuffer cb) 73 { 74 generateInternalWhere(cb, false); 75 } 76 77 80 void generateInternalWhere(CharBuffer cb, 81 boolean select) 82 { 83 cb.append("count("); 84 85 AmberExpr arg = _args.get(0); 86 87 if (arg instanceof OneToManyExpr) { 88 89 91 OneToManyExpr oneToMany = (OneToManyExpr) arg; 92 93 FromItem fromItem = oneToMany.getChildFromItem(); 94 95 cb.append(fromItem.getName()); 96 cb.append('.'); 97 98 LinkColumns linkColumns = oneToMany.getLinkColumns(); 99 ForeignColumn fkColumn = linkColumns.getColumns().get(0); 100 101 cb.append(fkColumn.getName()); 102 } 103 else { 104 if (select) 105 arg.generateWhere(cb); 106 else 107 arg.generateUpdateWhere(cb); 108 } 109 110 cb.append(')'); 111 } 112 } 113 | Popular Tags |