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 LOBConstantNode extends ConstantNode 40 { 41 59 public void init(Object arg1) 60 throws StandardException 61 { 62 if (arg1 instanceof TypeId) 63 { 64 super.init( 65 arg1, 66 Boolean.TRUE, 67 ReuseFactory.getInteger(0)); 68 } 69 else 70 { 71 String val = (String ) arg1; 72 73 super.init( 74 TypeId.CHAR_ID, 75 (val == null) ? Boolean.TRUE : Boolean.FALSE, 76 (val != null) ? 77 ReuseFactory.getInteger(val.length()) : 78 ReuseFactory.getInteger(0)); 79 80 setValue(getDataValueFactory().getCharDataValue(val)); 81 } 82 } 83 84 public void init( 85 Object newValue, 86 Object newLength) 87 throws StandardException 88 { 89 String val = (String ) newValue; 90 int newLen = ((Integer ) newLength).intValue(); 91 92 super.init( 93 TypeId.CHAR_ID, 94 (val == null) ? Boolean.TRUE : Boolean.FALSE, 95 newLength); 96 97 if (val.length() > newLen) 98 { 99 throw StandardException.newException(SQLState.LANG_STRING_TRUNCATION, "CHAR", val, String.valueOf(newLen)); 100 } 101 102 while (val.length() < newLen) 104 { 105 val = val + ' '; 106 } 107 108 setValue(getDataValueFactory().getCharDataValue(val)); 109 } 110 111 118 119 public String getString() throws StandardException 120 { 121 return value.getString(); 122 } 123 124 131 132 137 149 Object getConstantValueAsObject() throws StandardException 150 { 151 return value.getString(); 152 } 153 154 163 void generateConstant(ExpressionClassBuilder acb, MethodBuilder mb) throws StandardException 164 { 165 mb.push(getString()); 168 } 169 } 170 | Popular Tags |