1 28 29 package com.caucho.amber.expr; 30 31 import com.caucho.amber.query.QueryParser; 32 import com.caucho.amber.type.PrimitiveIntType; 33 import com.caucho.amber.type.Type; 34 import com.caucho.util.CharBuffer; 35 36 37 40 public class EnumExpr extends AbstractAmberExpr { 41 private Class _javaType; 42 43 private String _name; 45 46 private int _ordinal; 48 49 private boolean _isOrdinal = true; 50 51 58 public EnumExpr(Class javaType, 59 String name, 60 int ordinal) 61 { 62 _javaType = javaType; 63 _name = name; 64 _ordinal = ordinal; 65 } 66 67 70 public Type getType() 71 { 72 return PrimitiveIntType.create(); 73 } 74 75 78 public Class getJavaType() 79 { 80 return _javaType; 81 } 82 83 86 public int getOrdinal() 87 { 88 return _ordinal; 89 } 90 91 94 public boolean isOrdinal() 95 { 96 return _isOrdinal; 97 } 98 99 102 public void setOrdinal(boolean isOrdinal) 103 { 104 _isOrdinal = isOrdinal; 105 } 106 107 110 public AmberExpr bindSelect(QueryParser parser) 111 { 112 return this; 113 } 114 115 118 public void generateWhere(CharBuffer cb) 119 { 120 if (_isOrdinal) 121 cb.append(_ordinal); 122 else { 123 cb.append('\''); 124 cb.append(_name); 125 cb.append('\''); 126 } 127 } 128 129 132 public void generateUpdateWhere(CharBuffer cb) 133 { 134 generateWhere(cb); 135 } 136 137 140 public void generateHaving(CharBuffer cb) 141 { 142 generateWhere(cb); 143 } 144 145 public String toString() 146 { 147 return "EnumExpr[" + _javaType.getName() + "." + _name + "(" + _ordinal + ")]"; 148 } 149 } 150 | Popular Tags |