1 23 24 29 30 package com.sun.jdo.api.persistence.model.jdo; 31 32 import com.sun.jdo.api.persistence.model.Model; 33 import com.sun.jdo.api.persistence.model.ModelException; 34 import com.sun.jdo.spi.persistence.utility.I18NHelper; 35 36 46 47 52 public class RelationshipElement extends PersistenceFieldElement 53 { 54 55 public static final int NONE_ACTION = 0; 56 57 58 public static final int NULLIFY_ACTION = 1; 59 60 61 public static final int RESTRICT_ACTION = 2; 62 63 64 public static final int CASCADE_ACTION = 3; 65 66 67 public static final int AGGREGATE_ACTION = 4; 68 69 72 public RelationshipElement () 73 { 74 this(null, null); 75 } 76 77 82 public RelationshipElement (RelationshipElement.Impl impl, 83 PersistenceClassElement declaringClass) 84 { 85 super(impl, declaringClass); 86 } 87 88 90 final Impl getRelationshipImpl () { return (Impl)getImpl(); } 91 92 94 99 public int getUpdateAction () 100 { 101 return getRelationshipImpl().getUpdateAction(); 102 } 103 104 110 public void setUpdateAction (int action) throws ModelException 111 { 112 if ((action < NONE_ACTION) || (action > AGGREGATE_ACTION)) 113 { 114 throw new ModelException(I18NHelper.getMessage(getMessages(), 115 "jdo.relationship.update_action_invalid", action)); } 117 118 getRelationshipImpl().setUpdateAction(action); 119 } 120 121 126 public int getDeleteAction () 127 { 128 return getRelationshipImpl().getDeleteAction(); 129 } 130 131 137 public void setDeleteAction (int action) throws ModelException 138 { 139 if ((action < NONE_ACTION) || (action > AGGREGATE_ACTION)) 140 { 141 throw new ModelException(I18NHelper.getMessage(getMessages(), 142 "jdo.relationship.delete_action_invalid", action)); } 144 145 getRelationshipImpl().setDeleteAction(action); 146 } 147 148 152 public boolean isPrefetch () 153 { 154 return getRelationshipImpl().isPrefetch(); 155 } 156 157 162 public void setPrefetch (boolean flag) throws ModelException 163 { 164 getRelationshipImpl().setPrefetch(flag); 165 } 166 167 169 172 public int getLowerBound () 173 { 174 return getRelationshipImpl().getLowerBound(); 175 } 176 177 181 public void setLowerBound (int lowerBound) throws ModelException 182 { 183 if ((lowerBound > getUpperBound()) || (lowerBound < 0)) 184 { 185 throw new ModelException(I18NHelper.getMessage(getMessages(), 186 "jdo.relationship.lower_cardinality_invalid")); } 188 189 getRelationshipImpl().setLowerBound(lowerBound); 190 } 191 192 196 public int getUpperBound () 197 { 198 return getRelationshipImpl().getUpperBound(); 199 } 200 201 206 public void setUpperBound (int upperBound) throws ModelException 207 { 208 if ((upperBound < getLowerBound()) || (upperBound <= 0)) 209 { 210 throw new ModelException(I18NHelper.getMessage(getMessages(), 211 "jdo.relationship.upper_cardinality_invalid")); } 213 214 getRelationshipImpl().setUpperBound(upperBound); 215 } 216 217 219 223 public String getCollectionClass () 224 { 225 return getRelationshipImpl().getCollectionClass(); 226 } 227 228 233 public void setCollectionClass (String collectionClass) 234 throws ModelException 235 { 236 getRelationshipImpl().setCollectionClass(collectionClass); 237 } 238 239 244 public String getElementClass () 245 { 246 return getRelationshipImpl().getElementClass(); 247 } 248 249 255 public void setElementClass (String elementClass) throws ModelException 256 { 257 getRelationshipImpl().setElementClass(elementClass); 258 } 259 260 262 268 279 public String getInverseRelationshipName () 280 { 281 return getRelationshipImpl().getInverseRelationshipName(); 282 } 283 284 296 public RelationshipElement getInverseRelationship (Model model) 297 { 298 String inverseName = getInverseRelationshipName(); 299 RelationshipElement inverse = null; 300 301 if ((model != null) && (inverseName != null)) 302 { 303 String relatedClass = model.getRelatedClass(this); 304 305 if (relatedClass != null) 306 { 307 PersistenceClassElement relatedElement = 308 model.getPersistenceClass(relatedClass); 309 310 if (relatedElement != null) 311 inverse = relatedElement.getRelationship(inverseName); 312 } 313 } 314 315 return inverse; 316 } 317 318 328 public void setInverseRelationship (RelationshipElement inverseRelationship, 329 Model model) throws ModelException 330 { 331 RelationshipElement old = getInverseRelationship(model); 332 333 if ((old != inverseRelationship) || ((inverseRelationship == null) && 334 (getInverseRelationshipName() != null))) 335 { 336 if (old != null) 338 { 339 RelationshipElement oldInverse = 340 old.getInverseRelationship(model); 341 342 if (this.equals(oldInverse)) 343 old.changeInverseRelationship(null); 344 } 345 346 changeInverseRelationship(inverseRelationship); 348 349 if (inverseRelationship != null) 351 inverseRelationship.changeInverseRelationship(this); 352 } 353 } 354 355 365 public void changeInverseRelationship ( 366 RelationshipElement inverseRelationship) throws ModelException 367 { 368 getRelationshipImpl().changeInverseRelationship(inverseRelationship); 369 } 370 371 375 public interface Impl extends PersistenceFieldElement.Impl 376 { 377 382 public int getUpdateAction (); 383 384 391 public void setUpdateAction (int action) throws ModelException; 392 393 398 public int getDeleteAction (); 399 400 407 public void setDeleteAction (int action) throws ModelException; 408 409 413 public boolean isPrefetch (); 414 415 420 public void setPrefetch (boolean flag) throws ModelException; 421 422 425 public int getLowerBound (); 426 427 431 public void setLowerBound (int lowerBound) throws ModelException; 432 433 437 public int getUpperBound (); 438 439 444 public void setUpperBound (int upperBound) throws ModelException; 445 446 450 public String getCollectionClass (); 451 452 457 public void setCollectionClass (String collectionClass) 458 throws ModelException; 459 460 465 public String getElementClass (); 466 467 473 public void setElementClass (String elementClass) throws ModelException; 474 475 486 public String getInverseRelationshipName (); 487 488 499 public void changeInverseRelationship ( 500 RelationshipElement inverseRelationship) throws ModelException; 501 } 502 } 503 | Popular Tags |