1 2 12 package com.versant.core.jdo.sco; 13 14 import com.versant.core.common.Debug; 15 import com.versant.core.jdo.VersantStateManager; 16 import com.versant.core.common.VersantFieldMetaData; 17 18 import javax.jdo.spi.PersistenceCapable; 19 import java.io.*; 20 21 24 public class Date extends java.util.Date implements SCODate { 25 26 private transient PersistenceCapable owner; 27 private final transient VersantFieldMetaData fmd; 28 private transient VersantStateManager stateManager; 29 30 36 public Date(PersistenceCapable owner, 37 VersantStateManager stateManager, VersantFieldMetaData fmd, 38 long date) { 39 super(date); 40 this.owner = owner; 41 this.stateManager = stateManager; 42 this.fmd = fmd; 43 } 44 45 52 public void setTime(long time) { 53 this.makeDirty(); 54 super.setTime(time); 55 } 56 57 65 public Object clone() { 66 Object obj = super.clone(); 67 if (obj instanceof VersantSimpleSCO) { 68 ((VersantSimpleSCO) obj).makeTransient(); 69 } 70 return obj; 71 } 72 73 74 75 85 public void setYear(int year) { 86 this.makeDirty(); 87 super.setYear(year); 88 } 89 90 99 public void setMonth(int month) { 100 this.makeDirty(); 101 super.setMonth(month); 102 } 103 104 114 public void setDate(int date) { 115 this.makeDirty(); 116 super.setDate(date); 117 } 118 119 128 public void setHours(int hours) { 129 this.makeDirty(); 130 super.setHours(hours); 131 } 132 133 142 public void setMinutes(int minutes) { 143 this.makeDirty(); 144 super.setMinutes(minutes); 145 } 146 147 156 public void setSeconds(int seconds) { 157 this.makeDirty(); 158 super.setSeconds(seconds); 159 } 160 161 162 163 170 public void setTimeInternal(long time) { 171 super.setTime(time); 172 } 173 174 177 public void makeTransient() { 178 this.owner = null; 179 this.stateManager = null; 180 } 181 182 187 public Object getOwner() { 188 return this.owner; 189 } 190 191 194 public void makeDirty() { 195 if (stateManager != null) { 196 stateManager.makeDirty(owner, fmd.getManagedFieldNo()); 197 } 198 } 199 200 public void reset() { 201 } 202 203 public void writeExternal(ObjectOutput out) throws IOException { 204 out.writeLong(super.getTime()); 205 } 206 207 public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { 208 super.setTime(in.readLong()); 209 } 210 211 public static void main(String [] args) throws Exception { 212 Date d = new Date(null, null, null, System.currentTimeMillis()); 213 final long time = System.currentTimeMillis() - 5000; 214 d.setTime(time); 215 ByteArrayOutputStream bout = new ByteArrayOutputStream(); 216 ObjectOutputStream out = new ObjectOutputStream(bout); 217 out.writeObject(d); 218 219 ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(bout.toByteArray())); 220 Object o = in.readObject(); 221 Debug.OUT.println("####### o.type = " + o.getClass().getName()); 222 Debug.OUT.println("####### equal = " + d.equals(o)); 223 } 224 225 } 226 227 | Popular Tags |