1 23 24 28 29 package com.sun.jdo.spi.persistence.support.sqlstore.sco; 30 31 import java.io.ObjectStreamException ; 32 33 import com.sun.jdo.spi.persistence.support.sqlstore.PersistenceCapable; 34 import com.sun.jdo.spi.persistence.support.sqlstore.StateManager; 35 import com.sun.jdo.spi.persistence.support.sqlstore.SCO; 36 import com.sun.jdo.spi.persistence.support.sqlstore.SCODate; 37 import com.sun.jdo.spi.persistence.support.sqlstore.PersistenceManager; 38 39 45 public class SqlDate 46 extends java.sql.Date 47 implements SCODate 48 { 49 private transient PersistenceCapable owner; 50 51 private transient String fieldName; 52 53 59 public SqlDate(Object owner, String fieldName) 60 { 61 super(0); 62 if (owner instanceof PersistenceCapable) 63 { 64 this.owner = (PersistenceCapable)owner; 65 this.fieldName = fieldName; 66 } 67 } 68 69 76 public SqlDate(Object owner, String fieldName, long date) 77 { 78 super(date); 79 if (owner instanceof PersistenceCapable) 80 { 81 this.owner = (PersistenceCapable)owner; 82 this.fieldName = fieldName; 83 } 84 } 85 86 93 public void setTime(long time) { 94 this.makeDirty(); 95 super.setTime(time); 96 } 97 98 106 public Object clone() 107 { 108 SqlDate obj = (SqlDate) super.clone(); 109 110 obj.owner = null; 111 obj.fieldName = null; 112 113 return obj; 114 } 115 116 117 118 128 public void setYear(int year) { 129 this.makeDirty(); 130 super.setYear(year); 131 } 132 133 141 public void setMonth(int month) { 142 this.makeDirty(); 143 super.setMonth(month); 144 } 145 146 156 public void setDate(int date) { 157 this.makeDirty(); 158 super.setDate(date); 159 } 160 161 162 163 167 public Object cloneInternal() 168 { 169 return super.clone(); 170 } 171 172 179 public void setTimeInternal(long time) { 180 super.setTime(time); 181 } 182 183 188 public void unsetOwner() 189 { 190 this.owner = null; 191 this.fieldName = null; 192 } 193 194 199 public Object getOwner() 200 { 201 return this.owner; 202 } 203 204 209 public String getFieldName() 210 { 211 return this.fieldName; 212 } 213 214 217 public StateManager makeDirty() 218 { 219 if (owner != null) 220 { 221 StateManager stateManager = owner.jdoGetStateManager(); 222 223 if (stateManager != null) 224 { 225 PersistenceManager pm = (PersistenceManager) stateManager.getPersistenceManagerInternal(); 226 227 pm.acquireShareLock(); 228 229 try 230 { 231 synchronized (stateManager) 232 { 233 if (owner != null) 238 { 239 stateManager.makeDirty(fieldName); 240 return stateManager; 241 } 242 } 243 } 244 finally 245 { 246 pm.releaseShareLock(); 247 } 248 } 249 } 250 return null; 251 } 252 255 public void applyUpdates(StateManager sm, boolean modified) 256 { 257 } 258 259 266 Object writeReplace() throws ObjectStreamException 267 { 268 return new java.sql.Date (getTime()); 269 } 270 271 } 272 | Popular Tags |