1 64 65 package com.jcorporate.expresso.core.dataobjects.jdbc; 66 67 import com.jcorporate.expresso.core.dataobjects.DataException; 68 import com.jcorporate.expresso.core.dataobjects.DataField; 69 import com.jcorporate.expresso.core.dataobjects.DataFieldMetaData; 70 import com.jcorporate.expresso.core.dataobjects.DataObject; 71 import com.jcorporate.expresso.core.db.DBException; 72 import org.apache.log4j.Logger; 73 74 import java.io.InputStream ; 75 import java.math.BigDecimal ; 76 import java.util.Date ; 77 import java.util.Map ; 78 79 85 86 public class JoinedDataField implements DataField { 87 88 private static final Logger log = Logger.getLogger(JoinedDataField.class); 89 90 93 private JoinedDataObject myOwner; 94 95 98 private DataObject localObj; 99 100 103 private String localField; 104 105 108 private DataObject foreignObj; 109 110 113 private String foreignField; 114 115 118 protected JoinedDataField() { 119 } 120 121 131 public static JoinedDataField getInstance(JoinedDataObject owner, 132 DataObject localObj, String localField, 133 DataObject remoteObj, String foreignField) { 134 135 JoinedDataField returnValue = new JoinedDataField(); 136 137 returnValue.myOwner = owner; 138 returnValue.localObj = localObj; 139 returnValue.localField = localField; 140 returnValue.foreignObj = remoteObj; 141 returnValue.foreignField = foreignField; 142 return returnValue; 143 } 144 145 151 public Object getValue() { 152 try { 153 return localObj.getDataField(localField).getValue(); 154 } catch (DBException ex) { 155 log.error("Error getting embedded data field", ex); 156 return null; 157 } 158 } 159 160 161 public String asString() { 162 try { 163 return localObj.getDataField(localField).asString(); 164 } catch (DBException ex) { 165 log.error("Error getting embedded data field", ex); 166 return null; 167 } 168 } 169 170 public Boolean asBoolean() { 171 try { 172 return localObj.getDataField(localField).asBoolean(); 173 } catch (DBException ex) { 174 log.error("Error getting embedded data field", ex); 175 return null; 176 } 177 } 178 179 180 public Integer asInteger() { 181 try { 182 return localObj.getDataField(localField).asInteger(); 183 } catch (DBException ex) { 184 log.error("Error getting embedded data field", ex); 185 return null; 186 } 187 } 188 189 public Date asDate() { 190 try { 191 return localObj.getDataField(localField).asDate(); 192 } catch (DBException ex) { 193 log.error("Error getting embedded data field", ex); 194 return null; 195 } 196 } 197 198 public BigDecimal asBigDecimal() { 199 try { 200 return localObj.getDataField(localField).asBigDecimal(); 201 } catch (DBException ex) { 202 log.error("Error getting embedded data field", ex); 203 return null; 204 } 205 } 206 207 public Double asDouble() { 208 try { 209 return localObj.getDataField(localField).asDouble(); 210 } catch (DBException ex) { 211 log.error("Error getting embedded data field", ex); 212 return null; 213 } 214 } 215 216 219 public Object getOriginalValue() { 220 try { 221 return localObj.getDataField(localField).getOriginalValue(); 222 } catch (DBException ex) { 223 log.error("Error getting embedded data field", ex); 224 return null; 225 } 226 } 227 228 public InputStream asStream() { 229 try { 230 return localObj.getDataField(localField).asStream(); 231 } catch (DBException ex) { 232 log.error("Error getting embedded data field", ex); 233 return null; 234 } 235 } 236 237 public boolean isChanged() { 238 try { 239 return localObj.getDataField(localField).isChanged(); 240 } catch (DBException ex) { 241 log.error("Error getting embedded data field", ex); 242 return false; 243 } 244 } 245 246 public boolean isValueSet() { 247 try { 248 return localObj.getDataField(localField).isValueSet(); 249 } catch (DBException ex) { 250 log.error("Error getting embedded data field", ex); 251 return false; 252 } 253 } 254 255 public void checkValue() throws DataException { 256 try { 257 localObj.getDataField(localField).checkValue(); 258 foreignObj.getDataField(foreignField).checkValue(); 259 } catch (DBException ex) { 260 log.error("Error getting embedded data field", ex); 261 throw new DataException("Error getting embedded data field", ex); 262 } 263 } 264 265 public void resetChanged() { 266 try { 267 localObj.getDataField(localField).resetChanged(); 268 foreignObj.getDataField(foreignField).resetChanged(); 269 } catch (DBException ex) { 270 log.error("Error getting embedded data field", ex); 271 return; 272 } 273 } 274 275 public void setValue(Object newValue) { 276 try { 277 localObj.getDataField(localField).setValue(newValue); 278 foreignObj.getDataField(foreignField).setValue(newValue); 279 } catch (DBException ex) { 280 log.error("Error getting embedded data field", ex); 281 return; 282 } 283 } 284 285 public boolean isNull() { 286 try { 287 return localObj.getDataField(localField).isNull(); 288 } catch (DBException ex) { 289 log.error("Error getting embedded data field", ex); 290 return true; 291 } 292 } 293 294 public void setAttribute(String attributeName, Object value) { 295 try { 296 localObj.getDataField(localField).setAttribute(attributeName, value); 297 foreignObj.getDataField(foreignField).setAttribute(attributeName, value); 298 } catch (DBException ex) { 299 log.error("Error getting embedded data field", ex); 300 return; 301 } 302 } 303 304 public Object getAttribute(String attributeName) { 305 try { 306 return localObj.getDataField(localField).getAttribute(attributeName); 307 } catch (DBException ex) { 308 log.error("Error getting embedded data field", ex); 309 return null; 310 } 311 } 312 313 public Map getAllAttributes() { 314 try { 315 return localObj.getDataField(localField).getAllAttributes(); 316 } catch (DBException ex) { 317 log.error("Error getting embedded data field", ex); 318 return null; 319 } 320 } 321 322 public DataObject getOwner() { 323 return this.myOwner; 324 } 325 326 public void setOwner(DataObject newOwner) { 327 if (!(newOwner instanceof JoinedDataObject)) { 328 throw new IllegalArgumentException ("New Owner must be of type: JoinedDataObject"); 329 } 330 this.myOwner = (JoinedDataObject) newOwner; 331 } 332 333 public DataFieldMetaData getFieldMetaData() { 334 try { 335 return localObj.getDataField(localField).getFieldMetaData(); 336 } catch (DBException ex) { 337 log.error("Error getting embedded data field", ex); 338 return null; 339 } 340 } 341 342 public void setFieldMetaData(DataFieldMetaData newMetadata) { 343 try { 344 localObj.getDataField(localField).setFieldMetaData(newMetadata); 345 } catch (DBException ex) { 346 log.error("Error getting embedded data field", ex); 347 return; 348 } 349 } 350 351 354 public void cacheIsChangedComparison() { 355 try { 356 localObj.getDataField(localField).cacheIsChangedComparison(); 357 } catch (DBException e) { 358 log.error("Error setting orig value", e); 359 } 360 } 361 362 } | Popular Tags |