1 21 22 package org.apache.derby.iapi.types; 23 24 import org.apache.derby.iapi.services.io.ArrayInputStream; 25 26 import org.apache.derby.iapi.error.StandardException; 27 28 import org.apache.derby.iapi.types.DataTypeDescriptor; 29 import org.apache.derby.iapi.types.DataValueDescriptor; 30 import org.apache.derby.iapi.types.TypeId; 31 import org.apache.derby.iapi.reference.SQLState; 32 33 import org.apache.derby.iapi.types.DataValueDescriptor; 34 35 import org.apache.derby.iapi.types.RowLocation; 36 import org.apache.derby.iapi.types.Orderable; 37 38 import org.apache.derby.iapi.services.io.StoredFormatIds; 39 40 import org.apache.derby.iapi.services.sanity.SanityManager; 41 42 import org.apache.derby.catalog.TypeDescriptor; 43 44 import org.apache.derby.iapi.types.DataType; 45 import org.apache.derby.iapi.types.RefDataValue; 46 import org.apache.derby.iapi.services.cache.ClassSize; 47 48 import java.io.ObjectOutput ; 49 import java.io.ObjectInput ; 50 import java.io.IOException ; 51 52 import java.sql.ResultSet ; 53 import java.sql.PreparedStatement ; 54 55 public class SQLRef extends DataType implements RefDataValue 56 { 57 protected RowLocation value; 58 59 private static final int BASE_MEMORY_USAGE = ClassSize.estimateBaseFromCatalog( SQLRef.class); 60 61 public int estimateMemoryUsage() 62 { 63 int sz = BASE_MEMORY_USAGE; 64 if( null != value) 65 sz += value.estimateMemoryUsage(); 66 return sz; 67 } 69 73 74 public String getString() 75 { 76 if (value != null) 77 { 78 return value.toString(); 79 } 80 else 81 { 82 return null; 83 } 84 } 85 86 public Object getObject() 87 { 88 return value; 89 } 90 91 protected void setFrom(DataValueDescriptor theValue) throws StandardException { 92 93 if (theValue.isNull()) 94 setToNull(); 95 else 96 value = (RowLocation) theValue.getObject(); 97 } 98 99 public int getLength() 100 { 101 return TypeDescriptor.MAXIMUM_WIDTH_UNKNOWN; 102 } 103 104 105 public String getTypeName() 106 { 107 return TypeId.REF_NAME; 108 } 109 110 113 114 115 120 public int getTypeFormatId() { 121 return StoredFormatIds.SQL_REF_ID; 122 } 123 124 public boolean isNull() 125 { 126 return (value == null); 127 } 128 129 public void writeExternal(ObjectOutput out) throws IOException { 130 131 if (SanityManager.DEBUG) 132 SanityManager.ASSERT(value != null, "writeExternal() is not supposed to be called for null values."); 133 134 out.writeObject(value); 135 } 136 137 146 public void readExternal(ObjectInput in) throws IOException , ClassNotFoundException 147 { 148 value = (RowLocation) in.readObject(); 149 } 150 public void readExternalFromArray(ArrayInputStream in) throws IOException , ClassNotFoundException 151 { 152 value = (RowLocation) in.readObject(); 153 } 154 155 158 159 public void restoreToNull() 160 { 161 value = null; 162 } 163 164 167 168 169 public boolean compare(int op, 170 DataValueDescriptor other, 171 boolean orderedNulls, 172 boolean unknownRV) 173 throws StandardException 174 { 175 return value.compare(op, 176 ((SQLRef) other).value, 177 orderedNulls, 178 unknownRV); 179 } 180 181 182 public int compare(DataValueDescriptor other) throws StandardException 183 { 184 return value.compare(((SQLRef) other).value); 185 } 186 187 190 191 192 public DataValueDescriptor getClone() 193 { 194 200 if (value == null) 201 return new SQLRef(); 202 else 203 return new SQLRef((RowLocation) value.cloneObject()); 204 } 205 206 209 public DataValueDescriptor getNewNull() 210 { 211 return new SQLRef(); 212 } 213 214 218 public void setValueFromResultSet(ResultSet resultSet, int colNumber, 219 boolean isNullable) 220 { 221 if (SanityManager.DEBUG) 222 SanityManager.THROWASSERT( 223 "setValueFromResultSet() is not supposed to be called for SQLRef."); 224 } 225 public void setInto(PreparedStatement ps, int position) { 226 if (SanityManager.DEBUG) 227 SanityManager.THROWASSERT( 228 "setValueInto(PreparedStatement) is not supposed to be called for SQLRef."); 229 } 230 231 234 235 238 239 public SQLRef() 240 { 241 } 242 243 public SQLRef(RowLocation rowLocation) 244 { 245 value = rowLocation; 246 } 247 248 public void setValue(RowLocation rowLocation) 249 { 250 value = rowLocation; 251 } 252 253 256 257 public String toString() 258 { 259 if (value == null) 260 return "NULL"; 261 else 262 return value.toString(); 263 } 264 } 265 | Popular Tags |