1 package org.tigris.scarab.om; 2 3 48 49 import java.util.List ; 50 51 import org.apache.torque.TorqueException; 53 import org.apache.torque.om.Persistent; 54 import org.apache.torque.util.Criteria; 55 import java.sql.Connection ; 56 57 import org.tigris.scarab.om.Attachment; 58 import org.tigris.scarab.services.cache.ScarabCache; 59 60 67 public class Activity 68 extends BaseActivity 69 implements Persistent 70 { 71 private AttributeOption oldAttributeOption; 72 private AttributeOption newAttributeOption; 73 74 protected static final String GET_ATTACHMENT = 75 "getAttachment"; 76 77 81 public Attachment getAttachment() 82 { 83 Attachment attachment = null; 84 Object obj = ScarabCache.get(this, GET_ATTACHMENT); 85 if (obj == null) 86 { 87 try 88 { 89 Criteria crit = new Criteria(); 90 crit.add(ActivityPeer.ACTIVITY_ID, this.getActivityId()); 91 crit.addJoin(AttachmentPeer.ATTACHMENT_ID, ActivityPeer.ATTACHMENT_ID); 92 List results = AttachmentPeer.doSelect(crit); 93 if (!results.isEmpty()) 94 { 95 attachment = (Attachment) results.get(0); 96 ScarabCache.put(attachment, this, GET_ATTACHMENT); 97 } 98 } 99 catch (Exception e) 100 { 101 getLog().error("Activity.getAttachment(): ", e); 102 } 103 } 104 else 105 { 106 attachment = (Attachment)obj; 107 } 108 return attachment; 109 } 110 111 115 public AttributeOption getOldAttributeOption() throws Exception 116 { 117 if (oldAttributeOption==null && (getOldValue() != null)) 118 { 119 oldAttributeOption = AttributeOptionManager 120 .getInstance(new Integer (getOldValue())); 121 } 122 return oldAttributeOption; 123 } 124 125 129 public AttributeOption getNewAttributeOption() throws Exception 130 { 131 if (newAttributeOption==null && (getNewValue() != null)) 132 { 133 newAttributeOption = AttributeOptionManager 134 .getInstance(new Integer (getNewValue())); 135 } 136 return newAttributeOption; 137 } 138 139 public void save(Connection dbCon) 140 throws TorqueException 141 { 142 if (isNew()) 143 { 144 Criteria crit = new Criteria(); 145 if (this.getOldValue() != null) 148 { 149 crit.add(ActivityPeer.ISSUE_ID, getIssueId()); 150 crit.add(ActivityPeer.ATTRIBUTE_ID, getAttributeId()); 151 crit.add(ActivityPeer.END_DATE, null); 152 crit.add(ActivityPeer.NEW_VALUE, this.getOldValue()); 153 List result = ActivityPeer.doSelect(crit); 154 int resultSize = result.size(); 155 if (resultSize > 0) 156 { 157 for (int i=0; i<resultSize;i++) 158 { 159 Activity a = (Activity)result.get(i); 160 a.setEndDate(getActivitySet().getCreatedDate()); 161 a.save(dbCon); 162 } 163 } 164 } 165 } 166 if (getAttribute().isUserAttribute() && this.getNewUserId() == null && this.getOldUserId() != null) 168 { 169 this.setEndDate(getActivitySet().getCreatedDate()); 170 } 171 super.save(dbCon); 172 } 173 174 public String getDescription() 175 { 176 String desc = super.getDescription(); 177 if (desc != null && desc.length() > 255) 178 { 179 char[] chDesc = new char[255]; 180 desc.getChars(0, 251, chDesc, 0); 181 chDesc[252] = chDesc[253] = chDesc[254] = '.'; 182 desc = new String (chDesc); 183 } 184 return desc; 185 } 186 187 public Activity copy(Issue issue, ActivitySet activitySet) 188 throws Exception 189 { 190 Activity newA = new Activity(); 191 newA.setIssueId(issue.getIssueId()); 192 newA.setDescription(getDescription()); 193 newA.setAttributeId(getAttributeId()); 194 newA.setTransactionId(activitySet.getActivitySetId()); 195 newA.setOldNumericValue(getOldNumericValue()); 196 newA.setNewNumericValue(getNewNumericValue()); 197 newA.setOldUserId(getOldUserId()); 198 newA.setNewUserId(getNewUserId()); 199 newA.setOldValue(getOldValue()); 200 newA.setNewValue(getNewValue()); 201 newA.setDependId(getDependId()); 202 newA.setEndDate(getEndDate()); 203 newA.setAttachmentId(getAttachmentId()); 204 newA.save(); 205 return newA; 206 } 207 } 208 | Popular Tags |