1 21 package oracle.toplink.essentials.internal.expressions; 23 24 import java.io.*; 25 import java.util.*; 26 import oracle.toplink.essentials.queryframework.*; 27 import oracle.toplink.essentials.expressions.*; 28 import oracle.toplink.essentials.internal.helper.*; 29 import oracle.toplink.essentials.internal.sessions.AbstractRecord; 30 import oracle.toplink.essentials.internal.sessions.AbstractSession; 31 32 35 public class ConstantExpression extends Expression { 36 protected Object value; 37 protected Expression localBase; 38 39 public ConstantExpression() { 40 super(); 41 } 42 43 public ConstantExpression(Object newValue, Expression baseExpression) { 44 super(); 45 value = newValue; 46 localBase = baseExpression; 47 } 48 49 53 public String descriptionOfNodeType() { 54 return "Constant"; 55 } 56 57 61 public ExpressionBuilder getBuilder() { 62 return getLocalBase().getBuilder(); 63 } 64 65 protected Expression getLocalBase() { 66 return localBase; 67 } 68 69 public Object getValue() { 70 return value; 71 } 72 73 public boolean isConstantExpression() { 74 return true; 75 } 76 77 80 public boolean isValueExpression() { 81 return true; 82 } 83 84 88 protected void postCopyIn(Dictionary alreadyDone) { 89 super.postCopyIn(alreadyDone); 90 localBase = localBase.copiedVersionFrom(alreadyDone); 91 } 92 93 97 public void printSQL(ExpressionSQLPrinter printer) { 98 Object value = getLocalBase().getFieldValue(getValue()); 99 printer.printPrimitive(value); 100 } 101 102 106 public void printSQLWithoutConversion(ExpressionSQLPrinter printer) { 107 printer.printPrimitive(getValue()); 108 } 109 110 114 public void printJava(ExpressionJavaPrinter printer) { 115 printer.printJava(getValue()); 116 } 117 118 123 public Expression rebuildOn(Expression newBase) { 124 Expression result = (ConstantExpression)clone(); 125 result.setLocalBase(getLocalBase().rebuildOn(newBase)); 126 return result; 127 } 128 129 public void setLocalBase(Expression e) { 130 localBase = e; 131 } 132 133 140 public Expression twistedForBaseAndContext(Expression newBase, Expression context) { 141 return (Expression)this.clone(); 142 } 143 144 149 public Object valueFromObject(Object object, AbstractSession session, AbstractRecord translationRow, InMemoryQueryIndirectionPolicy valueHolderPolicy, boolean isObjectUnregistered) { 150 return getLocalBase().getFieldValue(getValue()); 151 } 152 153 157 public void writeDescriptionOn(BufferedWriter writer) throws IOException { 158 writer.write(String.valueOf(getValue())); 159 } 160 161 165 public void writeFields(ExpressionSQLPrinter printer, Vector newFields, SQLSelectStatement statement) { 166 if (printer.isFirstElementPrinted()) { 168 printer.printString(", "); 169 } else { 170 printer.setIsFirstElementPrinted(true); 171 } 172 173 newFields.addElement(new DatabaseField("*")); 175 printSQL(printer); 176 } 177 } 178 | Popular Tags |