1 21 22 package org.apache.derby.impl.sql.compile; 23 24 import org.apache.derby.iapi.types.StringDataValue; 25 import org.apache.derby.iapi.types.TypeId; 26 27 28 import org.apache.derby.iapi.error.StandardException; 29 30 import org.apache.derby.iapi.services.compiler.MethodBuilder; 31 32 import org.apache.derby.impl.sql.compile.ExpressionClassBuilder; 33 import org.apache.derby.iapi.reference.SQLState; 34 35 import org.apache.derby.iapi.util.ReuseFactory; 36 37 import java.sql.Types ; 38 39 public final class CharConstantNode extends ConstantNode 40 { 41 48 public void init( 49 Object arg1) 50 throws StandardException 51 { 52 if (arg1 instanceof TypeId) 53 { 54 super.init( 55 arg1, 56 Boolean.TRUE, 57 ReuseFactory.getInteger(0)); 58 } 59 else 60 { 61 String val = (String ) arg1; 62 63 super.init( 64 TypeId.CHAR_ID, 65 (val == null) ? Boolean.TRUE : Boolean.FALSE, 66 (val != null) ? 67 ReuseFactory.getInteger(val.length()) : 68 ReuseFactory.getInteger(0)); 69 70 setValue(getDataValueFactory().getCharDataValue(val)); 71 } 72 } 73 74 82 public void init( 83 Object newValue, 84 Object newLength) 85 throws StandardException 86 { 87 String val = (String ) newValue; 88 int newLen = ((Integer ) newLength).intValue(); 89 90 super.init( 91 TypeId.CHAR_ID, 92 (val == null) ? Boolean.TRUE : Boolean.FALSE, 93 newLength); 94 95 if (val.length() > newLen) 96 { 97 throw StandardException.newException(SQLState.LANG_STRING_TRUNCATION, "CHAR", val, String.valueOf(newLen)); 98 } 99 100 while (val.length() < newLen) 102 { 103 val = val + ' '; 104 } 105 106 setValue(getDataValueFactory().getCharDataValue(val)); 107 } 108 109 116 117 public String getString() throws StandardException 118 { 119 return value.getString(); 120 } 121 122 129 130 135 147 Object getConstantValueAsObject() throws StandardException 148 { 149 return value.getString(); 150 } 151 152 161 void generateConstant(ExpressionClassBuilder acb, MethodBuilder mb) throws StandardException 162 { 163 mb.push(getString()); 166 } 167 } 168 | Popular Tags |