1 21 22 package org.apache.derby.iapi.types; 23 24 import org.apache.derby.iapi.types.DataTypeDescriptor; 25 import org.apache.derby.iapi.types.DataValueDescriptor; 26 import org.apache.derby.iapi.types.TypeId; 27 import org.apache.derby.iapi.types.DataValueDescriptor; 28 import org.apache.derby.iapi.types.StringDataValue; 29 import org.apache.derby.iapi.reference.SQLState; 30 import org.apache.derby.iapi.error.StandardException; 31 32 import org.apache.derby.iapi.services.io.FormatIdUtil; 33 import org.apache.derby.iapi.services.io.StoredFormatIds; 34 35 import org.apache.derby.iapi.services.sanity.SanityManager; 36 import org.apache.derby.iapi.util.StringUtil; 37 38 53 public class SQLVarchar 54 extends SQLChar 55 { 56 57 61 62 public String getTypeName() 63 { 64 return TypeId.VARCHAR_NAME; 65 } 66 67 70 71 72 public DataValueDescriptor getClone() 73 { 74 try 75 { 76 return new SQLVarchar(getString()); 77 } 78 catch (StandardException se) 79 { 80 if (SanityManager.DEBUG) 81 SanityManager.THROWASSERT("Unexpected exception " + se); 82 return null; 83 } 84 } 85 86 90 public DataValueDescriptor getNewNull() 91 { 92 return new SQLVarchar(); 93 } 94 95 96 99 100 105 public int getTypeFormatId() { 106 return StoredFormatIds.SQL_VARCHAR_ID; 107 } 108 109 112 113 public SQLVarchar() 114 { 115 } 116 117 public SQLVarchar(String val) 118 { 119 super(val); 120 } 121 122 135 136 public void normalize( 137 DataTypeDescriptor desiredType, 138 DataValueDescriptor source) 139 throws StandardException 140 { 141 normalize(desiredType, source.getString()); 142 } 143 144 protected void normalize(DataTypeDescriptor desiredType, String sourceValue) 145 throws StandardException 146 { 147 148 int desiredWidth = desiredType.getMaximumWidth(); 149 150 int sourceWidth = sourceValue.length(); 151 152 161 162 if (sourceWidth > desiredWidth) { 163 164 hasNonBlankChars(sourceValue, desiredWidth, sourceWidth); 165 166 170 sourceValue = sourceValue.substring(0, desiredWidth); 171 } 172 173 setValue(sourceValue); 174 } 175 176 177 180 181 182 public int typePrecedence() 183 { 184 return TypeId.VARCHAR_PRECEDENCE; 185 } 186 187 195 protected final int growBy() 196 { 197 return RETURN_SPACE_THRESHOLD; } 199 } 200 | Popular Tags |