1 21 package oracle.toplink.essentials.internal.indirection; 23 24 import java.io.*; 25 import oracle.toplink.essentials.internal.helper.*; 26 import oracle.toplink.essentials.indirection.*; 27 import oracle.toplink.essentials.exceptions.*; 28 import oracle.toplink.essentials.internal.localization.*; 29 import oracle.toplink.essentials.internal.sessions.AbstractRecord; 30 import oracle.toplink.essentials.internal.sessions.AbstractSession; 31 32 40 public abstract class DatabaseValueHolder implements ValueHolderInterface, Cloneable , Serializable { 41 42 43 protected Object value; 44 45 46 protected boolean isInstantiated; 47 48 49 protected transient AbstractSession session; 50 51 52 protected AbstractRecord row; 53 54 public Object clone() { 55 try { 56 return super.clone(); 57 } catch (CloneNotSupportedException exception) { 58 throw new InternalError (); 59 } 60 } 61 62 65 public AbstractRecord getRow() { 66 return row; 67 } 68 69 72 public AbstractSession getSession() { 73 return session; 74 } 75 76 79 public synchronized Object getValue() { 80 if (!isInstantiated()) { 81 privilegedSetValue(instantiate()); 83 setInstantiated(); 84 resetFields(); 85 } 86 return value; 87 } 88 89 92 protected abstract Object instantiate() throws DatabaseException; 93 94 106 public abstract Object instantiateForUnitOfWorkValueHolder(UnitOfWorkValueHolder unitOfWorkValueHolder); 107 108 113 public boolean isEasilyInstantiated() { 114 return isInstantiated(); 115 } 116 117 121 public boolean isInstantiated() { 122 return isInstantiated; 123 } 124 125 134 public abstract boolean isPessimisticLockingValueHolder(); 135 136 147 protected boolean isTransactionalValueHolder() { 148 return ((session != null) && session.isUnitOfWork()); 149 } 150 151 155 public boolean isSerializedRemoteUnitOfWorkValueHolder() { 156 return false; 157 } 158 159 162 public void privilegedSetValue(Object value) { 163 this.value = value; 164 } 165 166 175 public void releaseWrappedValueHolder() { 176 AbstractSession session = getSession(); 177 if ((session != null) && session.isUnitOfWork()) { 178 setSession(session.getRootSession(null)); 179 } 180 } 181 182 185 protected void resetFields() { 186 setRow(null); 187 setSession(null); 188 } 189 190 193 public void setInstantiated() { 194 isInstantiated = true; 195 } 196 197 200 public void setRow(AbstractRecord row) { 201 this.row = row; 202 } 203 204 207 public void setSession(AbstractSession session) { 208 this.session = session; 209 } 210 211 214 public void setUninstantiated() { 215 isInstantiated = false; 216 } 217 218 221 public void setValue(Object value) { 222 this.value = value; 223 setInstantiated(); 224 } 225 226 public String toString() { 227 if (isInstantiated()) { 228 return "{" + getValue() + "}"; 229 } else { 230 return "{" + Helper.getShortClassName(getClass()) + ": " + ToStringLocalization.buildMessage("not_instantiated", (Object [])null) + "}"; 231 } 232 } 233 } 234 | Popular Tags |