1 10 11 package com.triactive.jdo.test; 12 13 14 public class DateWidget extends Widget implements HasSCOFields 15 { 16 private java.util.Date dateField; 17 private java.sql.Date sqlDateField; 18 private java.sql.Timestamp sqlTimestampField; 19 20 21 public DateWidget() 22 { 23 super(); 24 } 25 26 27 public java.util.Date getDateField() 28 { 29 return dateField; 30 } 31 32 33 public java.sql.Date getSQLDateField() 34 { 35 return sqlDateField; 36 } 37 38 39 public java.sql.Timestamp getSQLTimestampField() 40 { 41 return sqlTimestampField; 42 } 43 44 45 public Object [] getSCOFieldValues() 46 { 47 return new Object [] { dateField, sqlDateField, sqlTimestampField }; 48 } 49 50 51 56 57 public void fillRandom() 58 { 59 super.fillRandom(); 60 61 70 if (nextNull()) 71 dateField = null; 72 else 73 { 74 long t = r.nextInt() * 1000L; 75 76 if (dateField != null && r.nextBoolean()) 77 dateField.setTime(t); 78 else 79 dateField = new java.util.Date (t); 80 } 81 82 if (nextNull()) 83 sqlDateField = null; 84 else 85 { 86 92 java.sql.Date rndDate = new java.sql.Date (r.nextInt() * 1000L); 93 long t = java.sql.Date.valueOf(rndDate.toString()).getTime(); 94 95 if (sqlDateField != null && r.nextBoolean()) 96 sqlDateField.setTime(t); 97 else 98 sqlDateField = new java.sql.Date (t); 99 } 100 101 if (nextNull()) 102 sqlTimestampField = null; 103 else 104 { 105 long t = r.nextInt() * 1000L; 106 107 if (sqlTimestampField != null && r.nextBoolean()) 108 sqlTimestampField.setTime(t); 109 else 110 sqlTimestampField = new java.sql.Timestamp (t); 111 } 112 } 113 114 115 126 127 public boolean compareTo(Object obj) 128 { 129 if (this == obj) 130 return true; 131 132 if (!(obj instanceof DateWidget) || !super.compareTo(obj)) 133 return false; 134 135 DateWidget w = (DateWidget)obj; 136 137 if (dateField == null) { if (w.dateField != null) return false; } 138 else if (!dateField.equals(w.dateField)) return false; 139 140 if (sqlDateField == null) { if (w.sqlDateField != null) return false; } 141 else if (!sqlDateField.equals(w.sqlDateField)) return false; 142 143 if (sqlTimestampField == null) { if (w.sqlTimestampField != null) return false; } 144 else if (!sqlTimestampField.equals(w.sqlTimestampField)) return false; 145 146 return true; 147 } 148 149 150 156 157 public String toString() 158 { 159 StringBuffer s = new StringBuffer (super.toString()); 160 161 s.append(" dateField = ").append(dateField); 162 if (dateField != null) 163 s.append(" (").append(dateField.getTime()).append(')'); 164 s.append('\n'); 165 166 s.append(" sqlDateField = ").append(sqlDateField); 167 if (sqlDateField != null) 168 s.append(" (").append(sqlDateField.getTime()).append(')'); 169 s.append('\n'); 170 171 s.append(" sqlTimestampField = ").append(sqlTimestampField); 172 if (sqlTimestampField != null) 173 s.append(" (").append(sqlTimestampField.getTime()).append(')'); 174 s.append('\n'); 175 176 return s.toString(); 177 } 178 } 179 | Popular Tags |