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 SqlTimestamp 46 extends java.sql.Timestamp 47 implements SCODate 48 { 49 50 private transient PersistenceCapable owner; 51 52 private transient String fieldName; 53 54 60 public SqlTimestamp(Object owner, String fieldName) 61 { 62 super(0); 63 if (owner instanceof PersistenceCapable) 64 { 65 this.owner = (PersistenceCapable)owner; 66 this.fieldName = fieldName; 67 } 68 } 69 70 77 public SqlTimestamp(Object owner, String fieldName, long date) 78 { 79 super(date); 80 if (owner instanceof PersistenceCapable) 81 { 82 this.owner = (PersistenceCapable)owner; 83 this.fieldName = fieldName; 84 } 85 } 86 87 94 public void setTime(long time) { 95 this.makeDirty(); 96 super.setTime(time); 97 } 98 99 108 public void setNanos(int n) { 109 this.makeDirty(); 110 try { 111 super.setNanos(n); 112 } catch (IllegalArgumentException e) { 113 throw e; 114 } 115 } 116 117 118 126 public Object clone() 127 { 128 SqlTimestamp obj = (SqlTimestamp) super.clone(); 129 130 obj.owner = null; 131 obj.fieldName = null; 132 133 return obj; 134 } 135 136 137 138 148 public void setYear(int year) { 149 this.makeDirty(); 150 super.setYear(year); 151 } 152 153 161 public void setMonth(int month) { 162 this.makeDirty(); 163 super.setMonth(month); 164 } 165 166 176 public void setDate(int date) { 177 this.makeDirty(); 178 super.setDate(date); 179 } 180 181 182 191 public void setHours(int hours) { 192 this.makeDirty(); 193 super.setHours(hours); 194 } 195 196 205 public void setMinutes(int minutes) { 206 this.makeDirty(); 207 super.setMinutes(minutes); 208 } 209 210 219 public void setSeconds(int seconds) { 220 this.makeDirty(); 221 super.setSeconds(seconds); 222 } 223 224 225 226 230 public Object cloneInternal() 231 { 232 return super.clone(); 233 } 234 235 242 public void setTimeInternal(long time) { 243 super.setTime(time); 244 } 245 246 255 public void setNanosInternal(int n) { 256 super.setNanos(n); 257 } 258 259 264 public void unsetOwner() 265 { 266 this.owner = null; 267 this.fieldName = null; 268 } 269 270 275 public Object getOwner() 276 { 277 return this.owner; 278 } 279 280 285 public String getFieldName() 286 { 287 return this.fieldName; 288 } 289 290 293 public StateManager makeDirty() 294 { 295 if (owner != null) 296 { 297 StateManager stateManager = owner.jdoGetStateManager(); 298 299 if (stateManager != null) 300 { 301 PersistenceManager pm = (PersistenceManager) stateManager.getPersistenceManagerInternal(); 302 303 pm.acquireShareLock(); 304 305 try 306 { 307 synchronized (stateManager) 308 { 309 if (owner != null) 314 { 315 stateManager.makeDirty(fieldName); 316 return stateManager; 317 } 318 } 319 } 320 finally 321 { 322 pm.releaseShareLock(); 323 } 324 } 325 } 326 return null; 327 } 328 329 332 public void applyUpdates(StateManager sm, boolean modified) 333 { 334 } 335 336 343 Object writeReplace() throws ObjectStreamException 344 { 345 java.sql.Timestamp t = new java.sql.Timestamp (getTime()); 346 t.setNanos(this.getNanos()); 347 return t; 348 } 349 } 350 | Popular Tags |