1 package org.apache.ojb.broker; 2 3 import java.util.ArrayList ; 4 import java.util.Collection ; 5 import java.util.Iterator ; 6 import java.util.List ; 7 8 import org.apache.commons.lang.ClassUtils; 9 import org.apache.commons.lang.builder.EqualsBuilder; 10 import org.apache.commons.lang.builder.HashCodeBuilder; 11 import org.apache.commons.lang.builder.ToStringBuilder; 12 import org.apache.commons.lang.time.StopWatch; 13 import org.apache.ojb.broker.metadata.CollectionDescriptor; 14 import org.apache.ojb.broker.metadata.ObjectReferenceDescriptor; 15 import org.apache.ojb.broker.query.Criteria; 16 import org.apache.ojb.broker.query.Query; 17 import org.apache.ojb.broker.query.QueryFactory; 18 import org.apache.ojb.broker.util.ObjectModification; 19 import org.apache.ojb.junit.PBTestCase; 20 21 31 public class M2NTest extends PBTestCase 32 { 33 static final int NONE = ObjectReferenceDescriptor.CASCADE_NONE; 34 static final int LINK = ObjectReferenceDescriptor.CASCADE_LINK; 35 static final int OBJECT = ObjectReferenceDescriptor.CASCADE_OBJECT; 36 37 int actorCount = 200; 38 int movieCount = 100; 39 40 public static void main(String [] args) 41 { 42 junit.textui.TestRunner.main(new String []{M2NTest.class.getName()}); 43 } 44 45 public void tearDown() throws Exception 46 { 47 super.tearDown(); 48 } 49 50 53 public void testStoreWithSharedIndirectionTableColumn() 54 { 55 ojbChangeReferenceSetting(MovieImpl.class, "producers", true, OBJECT, OBJECT, false); 56 ojbChangeReferenceSetting(Producer.class, "movies", true, OBJECT, OBJECT, false); 57 String timestamp = "" + System.currentTimeMillis(); 58 String postfix = "testStoreWithSharedIndirectionTableColumn_" + timestamp; 59 60 Movie m_1 = new MovieImpl(postfix, postfix + "_1", null); 61 Movie m_2 = new MovieImpl(postfix, postfix + "_2", null); 62 Producer p_1 = new Producer(postfix, "producer_" + timestamp); 63 m_1.addProducer(p_1); 64 p_1.addMovie(m_1); 65 broker.beginTransaction(); 66 broker.store(p_1, ObjectModification.INSERT); 67 broker.commitTransaction(); 68 69 broker.clearCache(); 70 Criteria crit = new Criteria(); 71 crit.addLike("title", postfix + "%"); 72 Query q = QueryFactory.newQuery(Movie.class, crit); 73 Movie new_m_1 = (Movie) broker.getObjectByQuery(q); 74 assertNotNull(new_m_1); 75 assertNotNull(new_m_1.getProducers()); 76 assertEquals(1, new_m_1.getProducers().size()); 77 78 broker.beginTransaction(); 79 p_1.addMovie(m_2); 80 m_2.addProducer(p_1); 81 broker.store(p_1, ObjectModification.UPDATE); 82 broker.commitTransaction(); 85 86 broker.clearCache(); 87 new_m_1 = (Movie) broker.getObjectByQuery(q); 88 assertNotNull(new_m_1); 89 assertNotNull(new_m_1.getProducers()); 90 assertEquals(1, new_m_1.getProducers().size()); 91 Producer new_p_1 = (Producer) new_m_1.getProducers().get(0); 92 assertNotNull(new_p_1); 93 assertNotNull(new_p_1.getMovies()); 94 assertEquals(2, new_p_1.getMovies().size()); 95 96 97 broker.beginTransaction(); 98 broker.delete(p_1); 99 broker.commitTransaction(); 100 101 new_m_1 = (Movie) broker.getObjectByQuery(q); 102 assertNull(new_m_1); 103 104 crit = new Criteria(); 105 crit.addEqualTo("name", "producer_" + timestamp); 106 q = QueryFactory.newQuery(Producer.class, crit); 107 new_p_1 = (Producer) broker.getObjectByQuery(q); 108 assertNull(new_p_1); 109 } 110 111 public void testSimpleStore_1() 112 { 113 ojbChangeReferenceSetting(MovieImpl.class, "actors", true, OBJECT, OBJECT, false); 114 ojbChangeReferenceSetting(MovieImpl.class, "actors2", true, OBJECT, OBJECT, false); 115 ojbChangeReferenceSetting(Actor.class, "movies", true, OBJECT, OBJECT, false); 116 String postfix = "testSimpleStore_1_" + System.currentTimeMillis(); 117 Movie m = new MovieImpl(postfix, postfix, null); 118 Actor a = new Actor(postfix); 119 120 broker.beginTransaction(); 121 broker.store(m); 122 broker.store(a); 123 124 m.addActor(a); 125 broker.store(m); 126 broker.commitTransaction(); 127 128 broker.retrieveAllReferences(a); 129 130 assertNotNull(a.getMovies()); 131 assertEquals(1, a.getMovies().size()); 132 } 133 134 public void testSimpleStore_2() 135 { 136 ojbChangeReferenceSetting(MovieImpl.class, "actors", false, OBJECT, OBJECT, false); 137 ojbChangeReferenceSetting(MovieImpl.class, "actors2", false, OBJECT, OBJECT, false); 138 ojbChangeReferenceSetting(Actor.class, "movies", false, OBJECT, OBJECT, false); 139 String postfix = "testSimpleStore_2_" + System.currentTimeMillis(); 140 Movie m = new MovieImpl(postfix, postfix, null); 141 Actor a = new Actor(postfix); 142 143 broker.beginTransaction(); 144 broker.store(m); 145 broker.store(a); 146 147 m.addActor(a); 148 broker.store(m); 149 broker.commitTransaction(); 150 151 broker.retrieveAllReferences(a); 153 154 assertNotNull(a.getMovies()); 155 assertEquals(1, a.getMovies().size()); 156 } 157 158 161 public void testAutoUpdateDeleteSettings() 162 { 163 ojbChangeReferenceSetting(Actor.class, "movies", false, false, false, false); 164 CollectionDescriptor ord = broker.getClassDescriptor(Actor.class) 165 .getCollectionDescriptorByName("movies"); 166 assertEquals(LINK, ord.getCascadingStore()); 167 assertEquals(LINK, ord.getCascadingDelete()); 168 assertEquals(false, ord.getCascadeStore()); 169 assertEquals(false, ord.getCascadeDelete()); 170 171 ojbChangeReferenceSetting(Actor.class, "movies", false, true, true, false); 172 ord = broker.getClassDescriptor(Actor.class) 173 .getCollectionDescriptorByName("movies"); 174 assertEquals(OBJECT, ord.getCascadingStore()); 175 assertEquals(OBJECT, ord.getCascadingDelete()); 176 assertEquals(true, ord.getCascadeStore()); 177 assertEquals(true, ord.getCascadeDelete()); 178 } 179 180 public void testMassStoreUpdateAutomatic() 181 { 182 183 long testPeriod = 0; 184 185 String postfix = "testMassStoreUpdateAutomatic_" + System.currentTimeMillis(); 186 ojbChangeReferenceSetting(MovieImpl.class, "actors", true, OBJECT, OBJECT, false); 187 ojbChangeReferenceSetting(MovieImpl.class, "actors2", true, OBJECT, OBJECT, false); 188 ojbChangeReferenceSetting(Actor.class, "movies", true, OBJECT, OBJECT, false); 189 190 Movie movie = buildMovieWithActors(postfix, actorCount); 191 Actor actor = buildActorWithMovies(postfix, movieCount); 192 193 List actors = new ArrayList (movie.getActors()); 194 actors.add(actor); 195 movie.setActors(actors); 196 197 MovieManageableCollection movies = actor.getMovies(); 198 movies.add(movie); 199 200 StopWatch watch = new StopWatch(); 201 watch.start(); 202 broker.beginTransaction(); 203 broker.store(movie); 204 broker.commitTransaction(); 205 watch.stop(); 206 System.out.println("[" + ClassUtils.getShortClassName(this.getClass()) 207 + "#testMassStoreUpdateAutomatic] Time to store "+(actorCount + movieCount)+" m:n objects=" + watch.getTime()); 208 testPeriod += watch.getTime(); 209 210 watch.reset(); 211 watch.start(); 212 Query queryMovie = queryMovie(postfix); 213 Collection resultMovie = broker.getCollectionByQuery(queryMovie); 214 assertEquals(movieCount + 1, resultMovie.size()); 215 watch.stop(); 216 System.out.println("[" + ClassUtils.getShortClassName(this.getClass()) 217 + "#testMassStoreUpdateAutomatic] Time to query "+movieCount+" m:n objects=" + watch.getTime()); 218 testPeriod += watch.getTime(); 219 220 watch.reset(); 221 watch.start(); 222 Query queryActor = queryActor(postfix); 223 Collection resultActor = broker.getCollectionByQuery(queryActor); 224 assertEquals(actorCount + 1, resultActor.size()); 225 watch.stop(); 226 System.out.println("[" + ClassUtils.getShortClassName(this.getClass()) 227 + "#testMassStoreUpdateAutomatic] Time to query "+actorCount+" m:n objects=" + watch.getTime()); 228 testPeriod += watch.getTime(); 229 230 Query queryRole = roleQueryActorOrMovieMatch(actor, movie); 231 Collection resultRole = broker.getCollectionByQuery(queryRole); 232 assertEquals(actorCount + movieCount + 1, resultRole.size()); 233 234 movie.setActors(new ArrayList ()); 237 watch.reset(); 238 watch.start(); 239 broker.beginTransaction(); 240 broker.store(movie); 241 broker.commitTransaction(); 242 watch.stop(); 243 System.out.println("[" + ClassUtils.getShortClassName(this.getClass()) 244 + "#testMassStoreUpdateAutomatic] Time to update object with "+actorCount + " m:n objects=" + watch.getTime()); 245 testPeriod += watch.getTime(); 246 248 broker.clearCache(); 249 Identity oid = broker.serviceIdentity().buildIdentity(movie); 250 movie = (Movie) broker.getObjectByIdentity(oid); 251 252 resultMovie = broker.getCollectionByQuery(queryMovie); 253 assertEquals(movieCount + 1, resultMovie.size()); 254 255 resultActor = broker.getCollectionByQuery(queryActor); 256 assertEquals(actorCount + 1, resultActor.size()); 257 258 resultRole = broker.getCollectionByQuery(queryRole); 259 assertEquals(movieCount, resultRole.size()); 260 261 assertNotNull(movie); 262 assertEquals(0, movie.getActors().size()); 263 264 movie.setActors(new ArrayList ()); 267 watch.reset(); 268 watch.start(); 269 broker.beginTransaction(); 270 broker.delete(actor); 271 broker.commitTransaction(); 272 watch.stop(); 273 System.out.println("[" + ClassUtils.getShortClassName(this.getClass()) 274 + "#testMassStoreUpdateAutomatic] Time to remove object with "+ movieCount + " m:n objects=" + watch.getTime()); 275 testPeriod += watch.getTime(); 276 278 broker.clearCache(); 279 oid = broker.serviceIdentity().buildIdentity(actor); 280 actor = (Actor) broker.getObjectByIdentity(oid); 281 282 resultMovie = broker.getCollectionByQuery(queryMovie); 283 assertEquals(0, resultMovie.size()); 284 285 resultActor = broker.getCollectionByQuery(queryActor); 287 assertEquals(actorCount, resultActor.size()); 288 289 resultRole = broker.getCollectionByQuery(queryRole); 290 assertEquals(0, resultRole.size()); 291 292 assertNull(actor); 293 294 broker.beginTransaction(); 295 broker.delete(movie); 296 broker.commitTransaction(); 297 298 resultMovie = broker.getCollectionByQuery(queryMovie); 299 assertEquals(0, resultMovie.size()); 300 System.out.println("[" + ClassUtils.getShortClassName(this.getClass()) 301 + "#testMassStoreUpdateAutomatic] Total test time is "+ testPeriod+" ms"); 302 System.out.println(""); 303 } 304 305 306 public void testMassStoreUpdateLinking() 307 { 308 long testPeriod = 0; 309 310 String postfix = "testMassStoreUpdateLinking" + System.currentTimeMillis(); 311 ojbChangeReferenceSetting(MovieImpl.class, "actors", true, NONE, OBJECT, false); 312 ojbChangeReferenceSetting(MovieImpl.class, "actors2", true, NONE, OBJECT, false); 313 ojbChangeReferenceSetting(Actor.class, "movies", true, NONE, OBJECT, false); 314 315 Movie movie = buildMovieWithActors(postfix, actorCount); 316 Actor actor = buildActorWithMovies(postfix, movieCount); 317 318 List actors = new ArrayList (movie.getActors()); 319 actors.add(actor); 320 movie.setActors(actors); 321 322 MovieManageableCollection movies = actor.getMovies(); 323 movies.add(movie); 324 325 StopWatch watch = new StopWatch(); 326 watch.start(); 327 broker.beginTransaction(); 328 broker.store(movie); 329 for(int i = 0; i < actors.size(); i++) 330 { 331 broker.store(actors.get(i)); 332 } 333 MovieManageableCollection actorMovies = actor.getMovies(); 334 for(int i = 0; i < actorMovies.size(); i++) 335 { 336 broker.store(actorMovies.get(i)); 337 } 338 broker.serviceBrokerHelper().link(movie, true); 339 broker.serviceBrokerHelper().link(actor, true); 340 broker.commitTransaction(); 341 watch.stop(); 342 System.out.println("[" + ClassUtils.getShortClassName(this.getClass()) 343 + "#testMassStoreUpdateLinking] Time to store "+(actorCount + movieCount)+" m:n objects=" + watch.getTime()); 344 testPeriod += watch.getTime(); 345 346 watch.reset(); 347 watch.start(); 348 Query queryMovie = queryMovie(postfix); 349 Collection resultMovie = broker.getCollectionByQuery(queryMovie); 350 assertEquals(movieCount + 1, resultMovie.size()); 351 watch.stop(); 352 System.out.println("[" + ClassUtils.getShortClassName(this.getClass()) 353 + "#testMassStoreUpdateLinking] Time to query "+movieCount+" m:n objects=" + watch.getTime()); 354 testPeriod += watch.getTime(); 355 356 watch.reset(); 357 watch.start(); 358 Query queryActor = queryActor(postfix); 359 Collection resultActor = broker.getCollectionByQuery(queryActor); 360 assertEquals(actorCount + 1, resultActor.size()); 361 watch.stop(); 362 System.out.println("[" + ClassUtils.getShortClassName(this.getClass()) 363 + "#testMassStoreUpdateLinking] Time to query "+actorCount+" m:n objects=" + watch.getTime()); 364 testPeriod += watch.getTime(); 365 366 Query queryRole = roleQueryActorOrMovieMatch(actor, movie); 367 Collection resultRole = broker.getCollectionByQuery(queryRole); 368 assertEquals(actorCount + movieCount + 1, resultRole.size()); 369 370 movie.setActors(new ArrayList ()); 373 watch.reset(); 374 watch.start(); 375 broker.beginTransaction(); 376 broker.serviceBrokerHelper().unlink(movie); 377 broker.store(movie); 378 broker.serviceBrokerHelper().link(movie, false); 379 broker.commitTransaction(); 380 watch.stop(); 381 System.out.println("[" + ClassUtils.getShortClassName(this.getClass()) 382 + "#testMassStoreUpdateLinking] Time to update object with "+actorCount + " m:n objects=" + watch.getTime()); 383 testPeriod += watch.getTime(); 384 386 broker.clearCache(); 387 Identity oid = broker.serviceIdentity().buildIdentity(movie); 388 movie = (Movie) broker.getObjectByIdentity(oid); 389 390 resultMovie = broker.getCollectionByQuery(queryMovie); 391 assertEquals(movieCount + 1, resultMovie.size()); 392 393 resultActor = broker.getCollectionByQuery(queryActor); 394 assertEquals(actorCount + 1, resultActor.size()); 395 396 resultRole = broker.getCollectionByQuery(queryRole); 397 assertEquals(movieCount, resultRole.size()); 398 399 assertNotNull(movie); 400 assertEquals(0, movie.getActors().size()); 401 402 movie.setActors(new ArrayList ()); 405 watch.reset(); 406 watch.start(); 407 broker.beginTransaction(); 408 broker.delete(actor); 409 broker.commitTransaction(); 410 watch.stop(); 411 System.out.println("[" + ClassUtils.getShortClassName(this.getClass()) 412 + "#testMassStoreUpdateLinking] Time to remove object with "+ movieCount + " m:n objects=" + watch.getTime()); 413 testPeriod += watch.getTime(); 414 416 broker.clearCache(); 417 oid = broker.serviceIdentity().buildIdentity(actor); 418 actor = (Actor) broker.getObjectByIdentity(oid); 419 420 resultMovie = broker.getCollectionByQuery(queryMovie); 421 assertEquals(0, resultMovie.size()); 422 423 resultActor = broker.getCollectionByQuery(queryActor); 425 assertEquals(actorCount, resultActor.size()); 426 427 resultRole = broker.getCollectionByQuery(queryRole); 428 assertEquals(0, resultRole.size()); 429 430 assertNull(actor); 431 432 broker.beginTransaction(); 433 broker.delete(movie); 434 broker.commitTransaction(); 435 436 resultMovie = broker.getCollectionByQuery(queryMovie); 437 assertEquals(0, resultMovie.size()); 438 System.out.println("[" + ClassUtils.getShortClassName(this.getClass()) 439 + "#testMassStoreUpdateLinking] Total test time is "+ testPeriod+" ms"); 440 System.out.println(""); 441 } 442 443 public void YYYtestStoreAddUpdateDeleteTLLF() 449 { 450 ojbChangeReferenceSetting(MovieImpl.class, "actors", true, LINK, LINK, false); 451 ojbChangeReferenceSetting(MovieImpl.class, "actors2", true, LINK, LINK, false); 452 ojbChangeReferenceSetting(Actor.class, "movies", true, LINK, LINK, false); 453 String postfix = "_testStoreTLLF_" + System.currentTimeMillis(); 454 Movie movie = buildMovieWithActorsAndBackReferences(postfix); 455 doTestStoreAddUpdateDeleteTLLX(movie, postfix); 456 } 457 458 public void YYYtestStoreAddUpdateDeleteTLLT() 459 { 460 ojbChangeReferenceSetting(MovieImpl.class, "actors", true, LINK, LINK, true); 461 ojbChangeReferenceSetting(MovieImpl.class, "actors2", true, LINK, LINK, true); 462 ojbChangeReferenceSetting(Actor.class, "movies", true, LINK, LINK, false); 463 String postfix = "_testStoreTLLF_" + System.currentTimeMillis(); 464 Movie movie = buildMovieWithActorsAndBackReferences(postfix); 465 doTestStoreAddUpdateDeleteTLLX(movie, postfix); 466 } 467 468 469 public void doTestStoreAddUpdateDeleteTLLX(Movie movie, String postfix) 470 { 471 broker.beginTransaction(); 472 broker.store(movie); 473 broker.commitTransaction(); 474 Identity movieOID = broker.serviceIdentity().buildIdentity(movie); 475 476 479 broker.clearCache(); 480 Query queryMovie = queryMovie(postfix); 481 Collection resultMovie = broker.getCollectionByQuery(queryMovie); 482 assertEquals(3, resultMovie.size()); 483 484 Query queryActor = queryActor(postfix); 485 Collection resultActor = broker.getCollectionByQuery(queryActor); 486 assertEquals(3, resultActor.size()); 487 488 Actor actor = (Actor) movie.getActors().iterator().next(); 490 Query queryRole = queryRole(actor, movie); 491 Collection resultRole = broker.getCollectionByQuery(queryRole); 492 assertEquals(5, resultRole.size()); 493 494 broker.clearCache(); 495 broker.beginTransaction(); 496 Movie newMovie = (Movie) broker.getObjectByIdentity(movieOID); 497 newMovie.setTitle("updated_title_" + postfix); 498 Iterator it = newMovie.getActors().iterator(); 499 while(it.hasNext()) 500 { 501 Actor a = (Actor) it.next(); 502 a.setName("updated_name_" + postfix); 503 } 504 ArrayList list = new ArrayList (newMovie.getActors()); 505 list.add(new Actor("updated_name_" + postfix)); 506 newMovie.setActors(list); 507 broker.store(newMovie); 508 broker.commitTransaction(); 509 510 broker.clearCache(); 511 queryMovie = queryMovie(postfix); 512 resultMovie = broker.getCollectionByQuery(queryMovie); 513 assertEquals(3, resultMovie.size()); 514 515 queryActor = queryActor(postfix); 516 resultActor = broker.getCollectionByQuery(queryActor); 517 assertEquals(4, resultActor.size()); 518 519 actor = (Actor) movie.getActors().iterator().next(); 521 queryRole = queryRole(actor, movie); 522 resultRole = broker.getCollectionByQuery(queryRole); 523 assertEquals(6, resultRole.size()); 524 525 newMovie = (Movie) broker.getObjectByIdentity(movieOID); 526 assertEquals("updated_title_"+postfix, newMovie.getTitle()); 527 it = newMovie.getActors().iterator(); 528 while(it.hasNext()) 529 { 530 Actor a = (Actor) it.next(); 531 assertEquals("updated_name_" + postfix, a.getName()); 532 } 533 534 broker.beginTransaction(); 536 broker.delete(newMovie); 537 broker.commitTransaction(); 538 539 broker.clearCache(); 540 resultMovie = broker.getCollectionByQuery(queryMovie); 541 assertEquals(2, resultMovie.size()); 542 543 resultActor = broker.getCollectionByQuery(queryActor); 544 assertEquals(4, resultActor.size()); 545 546 resultRole = broker.getCollectionByQuery(queryRole); 547 assertEquals(2, resultRole.size()); 548 } 549 550 554 558 public void testStoreFFFF() 559 { 560 ojbChangeReferenceSetting(MovieImpl.class, "actors", false, NONE, NONE, false); 561 ojbChangeReferenceSetting(MovieImpl.class, "actors2", false, NONE, NONE, false); 562 ojbChangeReferenceSetting(Actor.class, "movies", false, NONE, NONE, false); 563 String postfix = "" + System.currentTimeMillis(); 564 Movie movie = buildMovieWithActors(postfix); 565 doTestStoreFFFX(movie, postfix); 566 } 567 568 572 public void testStoreFFFT() 573 { 574 ojbChangeReferenceSetting(MovieImpl.class, "actors", false, NONE, NONE, true); 575 ojbChangeReferenceSetting(MovieImpl.class, "actors2", false, NONE, NONE, true); 576 ojbChangeReferenceSetting(Actor.class, "movies", false, NONE, NONE, false); 577 String postfix = "" + System.currentTimeMillis(); 578 Movie movie = buildMovieWithActors(postfix); 579 doTestStoreFFFX(movie, postfix); 580 } 581 582 587 public void testStoreFFFF_2() 588 { 589 ojbChangeReferenceSetting(MovieImpl.class, "actors", false, NONE, NONE, false); 590 ojbChangeReferenceSetting(MovieImpl.class, "actors2", false, NONE, NONE, false); 591 ojbChangeReferenceSetting(Actor.class, "movies", false, NONE, NONE, false); 592 String postfix = "" + System.currentTimeMillis(); 593 Movie movie = buildMovieWithActorsAndBackReferences(postfix); 594 doTestStoreFFFX(movie, postfix); 595 } 596 597 602 public void testStoreFFFT_2() 603 { 604 ojbChangeReferenceSetting(MovieImpl.class, "actors", false, NONE, NONE, true); 605 ojbChangeReferenceSetting(MovieImpl.class, "actors2", false, NONE, NONE, true); 606 ojbChangeReferenceSetting(Actor.class, "movies", false, NONE, NONE, false); 607 String postfix = "" + System.currentTimeMillis(); 608 Movie movie = buildMovieWithActorsAndBackReferences(postfix); 609 doTestStoreFFFX(movie, postfix); 610 } 611 612 public void doTestStoreFFFX(Movie movie, String postfix) 613 { 614 broker.beginTransaction(); 615 broker.store(movie); 616 broker.commitTransaction(); 617 618 622 Query queryMovie = queryMovie(postfix); 623 Collection resultMovie = broker.getCollectionByQuery(queryMovie); 624 assertEquals(1, resultMovie.size()); 625 626 Query queryActor = queryActor(postfix); 627 Collection resultActor = broker.getCollectionByQuery(queryActor); 628 assertEquals(0, resultActor.size()); 630 631 Query queryRole = queryRole(null, movie); 632 Collection resultRole = broker.getCollectionByQuery(queryRole); 633 assertEquals(0, resultRole.size()); 635 636 broker.beginTransaction(); 637 640 Iterator it = movie.getActors().iterator(); 641 while(it.hasNext()) 642 { 643 Object actor = it.next(); 644 broker.store(actor); 645 } 646 broker.serviceBrokerHelper().link(movie, "actors", true); 648 652 broker.commitTransaction(); 653 654 657 resultMovie = broker.getCollectionByQuery(queryMovie); 658 assertEquals(1, resultMovie.size()); 659 660 resultActor = broker.getCollectionByQuery(queryActor); 661 assertEquals(3, resultActor.size()); 662 663 resultRole = broker.getCollectionByQuery(queryRole); 664 assertEquals(3, resultRole.size()); 665 666 broker.clearCache(); 667 Identity oid = broker.serviceIdentity().buildIdentity(movie); 668 Movie readMovie = (Movie) broker.getObjectByIdentity(oid); 669 assertNotNull(readMovie); 670 assertTrue(readMovie.getActors() == null || readMovie.getActors().size() == 0); 672 673 broker.retrieveAllReferences(readMovie); 674 assertEquals(3, readMovie.getActors().size()); 675 676 resultActor = broker.getCollectionByQuery(queryActor); 677 assertEquals(3, resultActor.size()); 678 Actor readActor = (Actor) resultActor.iterator().next(); 679 assertTrue(readActor.getMovies() == null || readActor.getMovies().size() == 0); 681 broker.retrieveAllReferences(readActor); 682 assertEquals(1, readActor.getMovies().size()); 683 684 broker.beginTransaction(); 687 broker.serviceBrokerHelper().unlink(readMovie, "actors"); 688 692 broker.commitTransaction(); 693 694 broker.clearCache(); 695 resultMovie = broker.getCollectionByQuery(queryMovie); 696 assertEquals(1, resultMovie.size()); 697 698 resultActor = broker.getCollectionByQuery(queryActor); 699 assertEquals(3, resultActor.size()); 700 701 resultRole = broker.getCollectionByQuery(queryRole); 702 assertEquals(0, resultRole.size()); 703 704 broker.beginTransaction(); 706 Iterator iter = movie.getActors().iterator(); 707 while(iter.hasNext()) 708 { 709 broker.delete(iter.next()); 710 } 711 broker.delete(movie); 712 broker.commitTransaction(); 713 714 broker.clearCache(); 715 resultMovie = broker.getCollectionByQuery(queryMovie); 716 assertEquals(0, resultMovie.size()); 717 718 resultActor = broker.getCollectionByQuery(queryActor); 719 assertEquals(0, resultActor.size()); 720 721 resultRole = broker.getCollectionByQuery(queryRole); 722 assertEquals(0, resultRole.size()); 723 } 724 725 732 public void testStoreTFFF() 733 { 734 ojbChangeReferenceSetting(MovieImpl.class, "actors", true, NONE, NONE, false); 735 ojbChangeReferenceSetting(MovieImpl.class, "actors2", true, NONE, NONE, false); 736 ojbChangeReferenceSetting(Actor.class, "movies", true, NONE, NONE, false); 737 doTestStoreTFFX(); 738 } 739 740 744 public void testStoreTFFT() 745 { 746 ojbChangeReferenceSetting(MovieImpl.class, "actors", true, NONE, NONE, true); 747 ojbChangeReferenceSetting(MovieImpl.class, "actors2", true, NONE, NONE, true); 748 ojbChangeReferenceSetting(Actor.class, "movies", true, NONE, NONE, false); 749 doTestStoreTFFX(); 750 } 751 752 public void doTestStoreTFFX() 753 { 754 String postfix = "" + System.currentTimeMillis(); 755 Movie movie = buildMovieWithActorsAndBackReferences(postfix); 756 757 broker.beginTransaction(); 758 broker.store(movie); 759 broker.commitTransaction(); 760 broker.clearCache(); 761 762 766 Query queryMovie = queryMovie(postfix); 767 Collection collMovie = broker.getCollectionByQuery(queryMovie); 768 assertEquals(1, collMovie.size()); 769 770 Query queryActor = queryActor(postfix); 771 Collection resultActor = broker.getCollectionByQuery(queryActor); 772 assertEquals(0, resultActor.size()); 774 775 Query queryRole = queryRole(null, movie); 776 Collection resultRole = broker.getCollectionByQuery(queryRole); 777 assertEquals(0, resultRole.size()); 779 780 broker.beginTransaction(); 781 784 Iterator it = movie.getActors().iterator(); 785 while(it.hasNext()) 786 { 787 Object actor = it.next(); 788 broker.store(actor); 789 } 790 broker.serviceBrokerHelper().link(movie, "actors", true); 792 796 broker.commitTransaction(); 797 798 801 collMovie = broker.getCollectionByQuery(queryMovie); 802 assertEquals(1, collMovie.size()); 803 804 resultActor = broker.getCollectionByQuery(queryActor); 805 assertEquals(3, resultActor.size()); 806 807 resultRole = broker.getCollectionByQuery(queryRole); 808 assertEquals(3, resultRole.size()); 809 810 broker.clearCache(); 811 Identity oid = broker.serviceIdentity().buildIdentity(movie); 812 Movie readMovie = (Movie) broker.getObjectByIdentity(oid); 813 assertNotNull(readMovie); 814 assertTrue(readMovie.getActors() != null); 816 assertEquals(3, readMovie.getActors().size()); 817 818 Actor a1 = new Actor(postfix); 820 Actor a2 = new Actor(postfix); 821 readMovie.addActor(a1); 822 readMovie.addActor(a2); 823 broker.beginTransaction(); 824 broker.store(a1); 825 broker.store(a2); 826 broker.serviceBrokerHelper().unlink(readMovie, "actors"); 827 broker.serviceBrokerHelper().link(readMovie, "actors", true); 828 broker.commitTransaction(); 829 830 collMovie = broker.getCollectionByQuery(queryMovie); 831 assertEquals(1, collMovie.size()); 832 resultActor = broker.getCollectionByQuery(queryActor); 833 assertEquals(5, resultActor.size()); 834 resultRole = broker.getCollectionByQuery(queryRole); 835 assertEquals(5, resultRole.size()); 836 broker.clearCache(); 837 oid = broker.serviceIdentity().buildIdentity(movie); 838 readMovie = (Movie) broker.getObjectByIdentity(oid); 839 assertNotNull(readMovie); 840 assertTrue(readMovie.getActors() != null); 842 assertEquals(5, readMovie.getActors().size()); 843 844 broker.beginTransaction(); 847 broker.serviceBrokerHelper().unlink(readMovie, "actors"); 848 852 broker.commitTransaction(); 853 854 broker.clearCache(); 855 collMovie = broker.getCollectionByQuery(queryMovie); 859 assertEquals(1, collMovie.size()); 860 readMovie = (Movie) collMovie.iterator().next(); 861 assertEquals(0, readMovie.getActors().size()); 862 863 resultActor = broker.getCollectionByQuery(queryActor); 864 assertEquals(5, resultActor.size()); 865 866 resultRole = broker.getCollectionByQuery(queryRole); 867 assertEquals(0, resultRole.size()); 868 869 broker.beginTransaction(); 871 Iterator iter = resultActor.iterator(); 872 while(iter.hasNext()) 873 { 874 broker.delete(iter.next()); 875 } 876 broker.delete(readMovie); 877 broker.commitTransaction(); 878 879 collMovie = broker.getCollectionByQuery(queryMovie); 881 assertEquals(0, collMovie.size()); 882 883 resultActor = broker.getCollectionByQuery(queryActor); 884 assertEquals(0, resultActor.size()); 885 886 resultRole = broker.getCollectionByQuery(queryRole); 887 assertEquals(0, resultRole.size()); 888 } 889 890 891 892 893 897 public void testStoreTTFF() 898 { 899 ojbChangeReferenceSetting(MovieImpl.class, "actors", true, OBJECT, NONE, false); 900 ojbChangeReferenceSetting(MovieImpl.class, "actors2", true, OBJECT, NONE, false); 901 ojbChangeReferenceSetting(Actor.class, "movies", true, OBJECT, NONE, false); 902 doTestStoreTTXX(); 903 } 904 905 public void testStoreTTFT() 906 { 907 ojbChangeReferenceSetting(MovieImpl.class, "actors", true, OBJECT, NONE, true); 908 ojbChangeReferenceSetting(MovieImpl.class, "actors2", true, OBJECT, NONE, true); 909 ojbChangeReferenceSetting(Actor.class, "movies", true, OBJECT, NONE, false); 910 doTestStoreTTXX(); 911 } 912 913 public void doTestStoreTTXX() 914 { 915 String postfix = "" + System.currentTimeMillis(); 916 Movie movie = buildMovieWithActors(postfix); 917 918 broker.beginTransaction(); 919 broker.store(movie); 920 broker.commitTransaction(); 921 broker.clearCache(); 922 923 Query queryMovie = queryMovie(postfix); 924 Collection resultMovie = broker.getCollectionByQuery(queryMovie); 925 assertEquals(1, resultMovie.size()); 926 927 Query queryActor = queryActor(postfix); 928 Collection resultActor = broker.getCollectionByQuery(queryActor); 929 assertEquals(3 + 2, resultActor.size()); 930 931 Query queryRole = queryRole(null, movie); 932 Collection resultRole = broker.getCollectionByQuery(queryRole); 933 assertEquals(3, resultRole.size()); 934 935 broker.clearCache(); 936 Identity oid = broker.serviceIdentity().buildIdentity(movie); 937 Movie readMovie = (Movie) broker.getObjectByIdentity(oid); 938 assertNotNull(readMovie); 939 assertEquals(3, readMovie.getActors().size()); 940 assertEquals(2, readMovie.getActors2().size()); 941 } 942 943 947 public void testStoreTTFT_2() 948 { 949 ojbChangeReferenceSetting(MovieImpl.class, "actors", true, OBJECT, NONE, true); 950 ojbChangeReferenceSetting(MovieImpl.class, "actors2", true, OBJECT, NONE, true); 951 ojbChangeReferenceSetting(Actor.class, "movies", true, OBJECT, NONE, false); 952 doTestStoreTTXX_2(); 953 } 954 955 public void doTestStoreTTXX_2() 956 { 957 String postfix = "" + System.currentTimeMillis(); 958 Movie movie = buildMovieWithActorsAndBackReferences(postfix); 959 960 broker.beginTransaction(); 961 broker.store(movie); 962 broker.commitTransaction(); 963 broker.clearCache(); 964 965 Query queryMovie = queryMovie(postfix); 966 Collection resultMovie = broker.getCollectionByQuery(queryMovie); 967 assertEquals(3, resultMovie.size()); 968 969 Query queryActor = queryActor(postfix); 970 Collection resultActor = broker.getCollectionByQuery(queryActor); 971 assertEquals(3, resultActor.size()); 972 973 Query queryRole = queryRole(null, movie); 974 Collection resultRole = broker.getCollectionByQuery(queryRole); 975 assertEquals(3, resultRole.size()); 976 977 broker.clearCache(); 978 Identity oid = broker.serviceIdentity().buildIdentity(movie); 979 Movie readMovie = (Movie) broker.getObjectByIdentity(oid); 980 assertNotNull(readMovie); 981 assertEquals(3, readMovie.getActors().size()); 982 } 983 984 public void testStoreUpdateTTFF() 985 { 986 ojbChangeReferenceSetting(MovieImpl.class, "actors", true, OBJECT, NONE, false); 987 ojbChangeReferenceSetting(MovieImpl.class, "actors2", true, OBJECT, NONE, false); 988 ojbChangeReferenceSetting(Actor.class, "movies", true, OBJECT, NONE, false); 989 doTestStoreUpdateTTXX(); 990 } 991 992 public void testStoreUpdateTTFF_2() 993 { 994 ojbChangeReferenceSetting(MovieImpl.class, "actors", true, OBJECT, NONE, true); 995 ojbChangeReferenceSetting(MovieImpl.class, "actors2", true, OBJECT, NONE, true); 996 ojbChangeReferenceSetting(Actor.class, "movies", true, OBJECT, NONE, false); 997 doTestStoreUpdateTTXX(); 998 } 999 1000 public void doTestStoreUpdateTTXX() 1001 { 1002 String postfix = "doTestStoreUpdateTTXX_" + System.currentTimeMillis(); 1003 Movie movie = buildMovieWithActors(postfix); 1004 1005 broker.beginTransaction(); 1006 broker.store(movie); 1007 broker.commitTransaction(); 1008 broker.clearCache(); 1009 1010 Query queryMovie = queryMovie(postfix); 1011 Collection resultMovie = broker.getCollectionByQuery(queryMovie); 1012 assertEquals(1, resultMovie.size()); 1013 1014 Query queryActor = queryActor(postfix); 1015 Collection resultActor = broker.getCollectionByQuery(queryActor); 1016 assertEquals(3 + 2, resultActor.size()); 1017 1018 Query queryRole = queryRole(null, movie); 1019 Collection resultRole = broker.getCollectionByQuery(queryRole); 1020 assertEquals(3, resultRole.size()); 1021 1022 movie.setActors(new ArrayList ()); 1025 broker.beginTransaction(); 1026 broker.store(movie); 1027 broker.commitTransaction(); 1028 1030 broker.clearCache(); 1031 Identity oid = broker.serviceIdentity().buildIdentity(movie); 1032 movie = (Movie) broker.getObjectByIdentity(oid); 1033 1034 resultMovie = broker.getCollectionByQuery(queryMovie); 1035 assertEquals(1, resultMovie.size()); 1036 1037 resultActor = broker.getCollectionByQuery(queryActor); 1038 assertEquals(3 + 2, resultActor.size()); 1039 1040 resultRole = broker.getCollectionByQuery(queryRole); 1041 assertEquals(0, resultRole.size()); 1042 1043 assertNotNull(movie); 1044 assertEquals(0, movie.getActors().size()); 1045 } 1046 1047 public void testStoreUpdateActorTTFF() 1048 { 1049 ojbChangeReferenceSetting(MovieImpl.class, "actors", true, OBJECT, NONE, false); 1050 ojbChangeReferenceSetting(MovieImpl.class, "actors2", true, OBJECT, NONE, false); 1051 ojbChangeReferenceSetting(Actor.class, "movies", true, OBJECT, NONE, false); 1052 1053 String postfix = "" + System.currentTimeMillis(); 1054 Actor actor = buildActorWithMovies(postfix); 1055 1056 broker.beginTransaction(); 1057 broker.store(actor); 1058 broker.commitTransaction(); 1059 1060 broker.clearCache(); 1061 Query queryMovie = queryMovie(postfix); 1062 Collection resultMovie = broker.getCollectionByQuery(queryMovie); 1063 assertEquals(3, resultMovie.size()); 1064 1065 Query queryActor = queryActor(postfix); 1066 Collection resultActor = broker.getCollectionByQuery(queryActor); 1067 assertEquals(1, resultActor.size()); 1068 1069 Query queryRole = queryRole(actor, null); 1070 Collection resultRole = broker.getCollectionByQuery(queryRole); 1071 assertEquals(3, resultRole.size()); 1072 1073 broker.clearCache(); 1074 Identity oid = broker.serviceIdentity().buildIdentity(actor); 1075 Actor loadedActor = (Actor) broker.getObjectByIdentity(oid); 1076 assertNotNull(loadedActor); 1077 MovieManageableCollection col = loadedActor.getMovies(); 1078 assertNotNull(col); 1079 col.get(0); 1080 } 1081 1082 public void testAddNewEntriesTTTF() 1083 { 1084 ojbChangeReferenceSetting(MovieImpl.class, "actors", true, OBJECT, OBJECT, false); 1085 ojbChangeReferenceSetting(MovieImpl.class, "actors2", true, OBJECT, OBJECT, false); 1086 ojbChangeReferenceSetting(Actor.class, "movies", true, OBJECT, OBJECT, false); 1087 doTestAddNewEntries(); 1088 } 1089 1090 public void testAddNewEntriesTTTT() 1091 { 1092 ojbChangeReferenceSetting(MovieImpl.class, "actors", true, OBJECT, OBJECT, true); 1093 ojbChangeReferenceSetting(MovieImpl.class, "actors2", true, OBJECT, OBJECT, true); 1094 ojbChangeReferenceSetting(Actor.class, "movies", true, OBJECT, OBJECT, false); 1096 doTestAddNewEntries(); 1097 } 1098 1099 public void doTestAddNewEntries() 1100 { 1101 String postfix = "doTestAddNewEntries_" + System.currentTimeMillis(); 1102 1103 1107 Movie movie = buildMovieWithActorsAndBackReferences(postfix); 1108 Actor a_1 = new Actor("testAddNewEntries_"+postfix); 1109 Actor a_2 = new Actor("testAddNewEntries_"+postfix); 1110 Actor a_3 = new Actor("testAddNewEntries_"+postfix); 1111 Actor a_4 = new Actor("testAddNewEntries_"+postfix); 1112 1116 1117 broker.beginTransaction(); 1118 broker.store(movie); 1119 broker.store(a_1); 1120 broker.store(a_2); 1121 broker.store(a_3); 1122 broker.commitTransaction(); 1123 1124 broker.clearCache(); 1125 1126 Query queryMovie = queryMovie(postfix); 1127 Collection resultMovie = broker.getCollectionByQuery(queryMovie); 1128 assertEquals(3, resultMovie.size()); 1129 1130 Query queryActor = queryActor(postfix); 1131 Collection resultActor = broker.getCollectionByQuery(queryActor); 1132 assertEquals(6, resultActor.size()); 1133 1134 Query queryRole = queryRole(null, movie); 1135 Collection resultRole = broker.getCollectionByQuery(queryRole); 1136 assertEquals(3, resultRole.size()); 1137 1138 broker.clearCache(); 1139 Identity oid = broker.serviceIdentity().buildIdentity(movie); 1140 Movie readMovie = (Movie) broker.getObjectByIdentity(oid); 1141 assertNotNull(readMovie); 1142 assertEquals(3, readMovie.getActors().size()); 1143 assertEquals(0, readMovie.getActors2().size()); 1144 1145 1150 movie.getActors().add(a_1); 1151 movie.getActors().add(a_2); 1152 movie.getActors().add(a_4); 1154 broker.beginTransaction(); 1155 broker.store(movie); 1156 broker.commitTransaction(); 1157 1158 broker.clearCache(); 1159 1160 queryMovie = queryMovie(postfix); 1161 resultMovie = broker.getCollectionByQuery(queryMovie); 1162 assertEquals(3, resultMovie.size()); 1163 1164 queryActor = queryActor(postfix); 1165 resultActor = broker.getCollectionByQuery(queryActor); 1166 assertEquals(7, resultActor.size()); 1167 1168 queryRole = queryRole(null, movie); 1169 resultRole = broker.getCollectionByQuery(queryRole); 1170 assertEquals(6, resultRole.size()); 1171 1172 broker.clearCache(); 1173 oid = broker.serviceIdentity().buildIdentity(movie); 1174 readMovie = (Movie) broker.getObjectByIdentity(oid); 1175 assertNotNull(readMovie); 1176 assertEquals(6, readMovie.getActors().size()); 1177 1178 1182 broker.beginTransaction(); 1183 broker.delete(movie); 1184 broker.commitTransaction(); 1185 1186 broker.clearCache(); 1187 resultMovie = broker.getCollectionByQuery(queryMovie); 1188 assertEquals(0, resultMovie.size()); 1189 1190 resultActor = broker.getCollectionByQuery(queryActor); 1191 assertEquals(1, resultActor.size()); 1192 1193 resultRole = broker.getCollectionByQuery(queryRole); 1194 assertEquals(0, resultRole.size()); 1195 } 1196 1197 Query queryMovie(String postfix) 1201 { 1202 Criteria c = new Criteria(); 1203 c.addLike("idStr", "%" + postfix + "%"); 1204 return QueryFactory.newQuery(Movie.class, c); 1205 } 1206 1207 Query queryActor(String postfix) 1208 { 1209 Criteria c = new Criteria(); 1210 c.addLike("name", "%" + postfix + "%"); 1211 return QueryFactory.newQuery(Actor.class, c); 1212 } 1213 1214 Query queryRole(Actor actor, Movie movie) 1215 { 1216 Criteria c = new Criteria(); 1217 if(actor != null) c.addEqualTo("actorId", actor.getId()); 1218 if(movie != null && actor != null) 1219 { 1220 Criteria c2 = new Criteria(); 1221 c2.addEqualTo("movieIntId", movie.getIdInt()); 1222 c2.addEqualTo("movieStrId", movie.getIdStr()); 1223 c.addOrCriteria(c2); 1224 } 1225 else if(movie != null) 1226 { 1227 c.addEqualTo("movieIntId", movie.getIdInt()); 1228 c.addEqualTo("movieStrId", movie.getIdStr()); 1229 } 1230 return QueryFactory.newQuery(Role.class, c); 1231 } 1232 1233 Query roleQueryActorOrMovieMatch(Actor actor, Movie movie) 1234 { 1235 Criteria c_1 = new Criteria(); 1236 Criteria c_2 = new Criteria(); 1237 if(actor != null) c_1.addEqualTo("actorId", actor.getId()); 1238 if(movie != null) 1239 { 1240 c_2.addEqualTo("movieIntId", movie.getIdInt()); 1241 c_2.addEqualTo("movieStrId", movie.getIdStr()); 1242 } 1243 if(actor != null) 1244 { 1245 c_2.addOrCriteria(c_1); 1246 } 1247 else 1248 { 1249 c_2 = c_1; 1250 } 1251 return QueryFactory.newQuery(Role.class, c_2); 1252 } 1253 1254 1258 Movie buildMovieWithActors(String postfixId) 1259 { 1260 Movie m = new MovieImpl(postfixId, 1261 "Dr. Strangelove or: How I Learned to Stop Worrying and Love the Bomb " + postfixId, 1262 "An insane general starts a process to nuclear holocaust that a war" + 1263 " room of politicians and generals frantically try to stop. " + postfixId); 1264 1265 Actor a1 = new Actor("Peter Sellers " + postfixId); 1266 Actor a2 = new Actor("George C. Scott " + postfixId); 1267 Actor a3 = new Actor("Sterling Hayden " + postfixId); 1268 ArrayList list = new ArrayList (); 1269 list.add(a1); 1270 list.add(a2); 1271 list.add(a3); 1272 m.setActors(list); 1273 1274 Actor a4 = new Actor("Actor 2 A " + postfixId); 1275 Actor a5 = new Actor("Actor 2 B " + postfixId); 1276 ArrayList list2 = new ArrayList (); 1277 list2.add(a4); 1278 list2.add(a5); 1279 m.setActors2(list2); 1280 1281 return m; 1282 } 1283 1284 1287 Movie buildMovieWithActors(String postfixId, int actorCount) 1288 { 1289 Movie m = new MovieImpl(postfixId, "Movie with "+ actorCount+" actors_" + postfixId, "none"); 1290 1291 ArrayList list = new ArrayList (); 1292 for(int i = 0; i < actorCount; i++) 1293 { 1294 Actor a = new Actor("A bad actor_" + postfixId); 1295 list.add(a); 1296 } 1297 m.setActors(list); 1298 return m; 1299 } 1300 1301 1304 Actor buildActorWithMovies(String postfixId, int movieCount) 1305 { 1306 Actor a = new Actor(postfixId+"_Actor play in "+ movieCount+" movies"); 1307 1308 MovieManageableCollection list = new MovieManageableCollection(); 1309 for(int i = 0; i < movieCount; i++) 1310 { 1311 Movie m = new MovieImpl(postfixId, "A bad movie_" + postfixId, "none"); 1312 list.add(m); 1313 } 1314 a.setMovies(list); 1315 return a; 1316 } 1317 1318 1322 Movie buildMovieWithActorsAndBackReferences(String postfixId) 1323 { 1324 Movie m = new MovieImpl(postfixId, 1325 "Dr. Strangelove or: How I Learned to Stop Worrying and Love the Bomb " + postfixId, 1326 "An insane general starts a process to nuclear holocaust that a war" + 1327 " room of politicians and generals frantically try to stop. " + postfixId); 1328 Actor a1 = new Actor("Peter Sellers " + postfixId); 1329 Actor a2 = new Actor("George C. Scott " + postfixId); 1330 Actor a3 = new Actor("Sterling Hayden " + postfixId); 1331 ArrayList list = new ArrayList (); 1332 list.add(a1); 1333 list.add(a2); 1334 list.add(a3); 1335 m.setActors(list); 1336 1337 Movie m1 = new MovieImpl(postfixId + "", "A Shot in the Dark", 1338 "As murder follows murder, beautiful Maria is the obvious suspect..."); 1339 Movie m2 = new MovieImpl(postfixId + "", "The Pink Panther", 1340 " In the first movie starring Peter Sellers as the bumbling Inspector Clouseau..."); 1341 1342 MovieManageableCollection mlist1 = new MovieManageableCollection(); 1343 mlist1.add(m); 1344 mlist1.add(m1); 1345 mlist1.add(m2); 1346 MovieManageableCollection mlist2 = new MovieManageableCollection(); 1347 MovieManageableCollection mlist3 = new MovieManageableCollection(); 1348 a1.setMovies(mlist1); 1349 a2.setMovies(mlist2); 1350 a3.setMovies(mlist3); 1351 1352 return m; 1353 } 1354 1355 Actor buildActorWithMovies(String postfixId) 1356 { 1357 Actor a = new Actor("John Cusack" + postfixId); 1358 MovieManageableCollection list = new MovieManageableCollection(); 1359 list.add(new MovieImpl("a_" + postfixId, "High Fidelity", "A comedy about fear of commitment, hating your job..." + postfixId)); 1360 list.add(new MovieImpl("b_" + postfixId, "Identity", "When a nasty storm hits a hotel, ten strangers are stranded within ..." + postfixId)); 1361 list.add(new MovieImpl("c_" + postfixId, "Grosse Pointe Blank", "Martin Blank is a professional assassin. He is sent on a mission to a small Detroit ..." + postfixId)); 1362 a.setMovies(list); 1363 return a; 1364 } 1365 1366 1367 1368 public static class MovieManageableCollection implements ManageableCollection 1372 { 1373 private ArrayList list = new ArrayList (); 1374 1375 public void ojbAdd(Object anObject) 1376 { 1377 list.add(anObject); 1378 } 1379 1380 public void ojbAddAll(ManageableCollection otherCollection) 1381 { 1382 Iterator it = otherCollection.ojbIterator(); 1383 while(it.hasNext()) 1384 { 1385 list.add(it.next()); 1386 } 1387 } 1388 1389 public Iterator ojbIterator() 1390 { 1391 return list.iterator(); 1392 } 1393 1394 public void afterStore(PersistenceBroker broker) throws PersistenceBrokerException 1395 { 1396 } 1397 1398 public Iterator iterator() 1399 { 1400 return list.iterator(); 1401 } 1402 1403 public int size() 1404 { 1405 return list.size(); 1406 } 1407 1408 public boolean isEmpty() 1409 { 1410 return list.isEmpty(); 1411 } 1412 1413 public void clear() 1414 { 1415 list.clear(); 1416 } 1417 1418 public boolean add(Movie movie) 1419 { 1420 return list.add(movie); 1421 } 1422 1423 public boolean remove(Movie movie) 1424 { 1425 return list.remove(movie); 1426 } 1427 1428 public boolean contains(Movie movie) 1429 { 1430 return list.contains(movie); 1431 } 1432 1433 public Movie get(int index) 1434 { 1435 return (Movie) list.get(index); 1436 } 1437 } 1438 1439 public static class Actor 1443 { 1444 private Integer id; 1445 private Integer id2; 1446 private String name; 1447 private MovieManageableCollection movies; 1448 1449 public Actor() 1450 { 1451 } 1452 1453 public Actor(String name) 1454 { 1455 this.name = name; 1456 } 1457 1458 public MovieManageableCollection getMovies() 1459 { 1460 return movies; 1461 } 1462 1463 public void setMovies(MovieManageableCollection movies) 1464 { 1465 this.movies = movies; 1466 } 1467 1468 public void addMovie(Movie m) 1469 { 1470 if(movies == null) 1471 { 1472 movies = new MovieManageableCollection(); 1473 } 1474 movies.add(m); 1475 } 1476 1477 public Integer getId() 1478 { 1479 return id; 1480 } 1481 1482 public void setId(Integer id) 1483 { 1484 this.id = id; 1485 } 1486 1487 public Integer getId2() 1488 { 1489 return id2; 1490 } 1491 1492 public void setId2(Integer id2) 1493 { 1494 this.id2 = id2; 1495 } 1496 1497 public String getName() 1498 { 1499 return name; 1500 } 1501 1502 public void setName(String name) 1503 { 1504 this.name = name; 1505 } 1506 1507 public String toString() 1508 { 1509 return ToStringBuilder.reflectionToString(this); 1510 } 1511 } 1512 1513 public static interface Movie 1517 { 1518 public Collection getActors(); 1519 public void setActors(Collection actors); 1520 public void addActor(Actor a); 1521 1522 public Collection getActors2(); 1523 public void setActors2(Collection actors); 1524 1525 public List getProducers(); 1526 public void setProducers(List producers); 1527 public void addProducer(Producer p); 1528 1529 public Integer getIdInt2(); 1530 public Integer getIdInt(); 1531 1532 public void setIdInt2(Integer id2Int); 1533 public void setIdInt(Integer idInt); 1534 1535 public String getIdStr(); 1536 public void setIdStr(String idStr); 1537 1538 public String getTitle(); 1539 public void setTitle(String title); 1540 1541 public String getDescription(); 1542 public void setDescription(String description); 1543 } 1544 1545 public static class MovieImpl implements Movie 1549 { 1550 private Integer idInt; 1551 private Integer idInt2; 1552 private String idStr; 1553 1554 private String title; 1555 private String description; 1556 private Collection actors; 1557 private Collection actors2; 1558 private List producers; 1559 1560 public MovieImpl() 1561 { 1562 } 1563 1564 public MovieImpl(String idStr, String title, String description) 1565 { 1566 this.idStr = idStr; 1567 this.title = title; 1568 this.description = description; 1569 } 1570 1571 public List getProducers() 1572 { 1573 return producers; 1574 } 1575 1576 public void setProducers(List producers) 1577 { 1578 this.producers = producers; 1579 } 1580 1581 public void addProducer(Producer p) 1582 { 1583 if(producers == null) 1584 { 1585 producers = new ArrayList (); 1586 } 1587 producers.add(p); 1588 if(p.getMovies() == null || !p.getMovies().contains(this)) 1589 { 1590 p.addMovie(this); 1591 } 1592 } 1593 1594 public Collection getActors() 1595 { 1596 return actors; 1597 } 1598 1599 public void setActors(Collection actors) 1600 { 1601 this.actors = actors; 1602 } 1603 1604 public void addActor(Actor a) 1605 { 1606 if(actors == null) 1607 { 1608 actors = new ArrayList (); 1609 } 1610 actors.add(a); 1611 } 1612 1613 public Collection getActors2() 1614 { 1615 return actors2; 1616 } 1617 1618 public void setActors2(Collection actors) 1619 { 1620 this.actors2 = actors; 1621 } 1622 1623 public Integer getIdInt() 1624 { 1625 return idInt; 1626 } 1627 1628 public void setIdInt(Integer idInt) 1629 { 1630 this.idInt = idInt; 1631 } 1632 1633 public Integer getIdInt2() 1634 { 1635 return idInt2; 1636 } 1637 1638 public void setIdInt2(Integer idInt2) 1639 { 1640 this.idInt2 = idInt2; 1641 } 1642 1643 public String getIdStr() 1644 { 1645 return idStr; 1646 } 1647 1648 public void setIdStr(String idStr) 1649 { 1650 this.idStr = idStr; 1651 } 1652 1653 public String getTitle() 1654 { 1655 return title; 1656 } 1657 1658 public void setTitle(String title) 1659 { 1660 this.title = title; 1661 } 1662 1663 public String getDescription() 1664 { 1665 return description; 1666 } 1667 1668 public void setDescription(String description) 1669 { 1670 this.description = description; 1671 } 1672 1673 public int hashCode() 1674 { 1675 return new HashCodeBuilder().append(idInt).append(idInt2).append(idStr).hashCode(); 1676 } 1677 1678 public boolean equals(Object obj) 1679 { 1680 boolean result = false; 1681 if(obj instanceof MovieImpl) 1682 { 1683 MovieImpl other = (MovieImpl) obj; 1684 result = new EqualsBuilder().append(idInt, other.idInt).append(idInt2, other.idInt2).append(idStr, other.idStr).isEquals(); 1685 } 1686 return result; 1687 } 1688 1689 public String toString() 1690 { 1691 return ToStringBuilder.reflectionToString(this); 1692 } 1693 } 1694 1695 public static class Role 1699 { 1700 private Integer actorId; 1701 private Integer actorId2; 1702 private Integer movieIntId; 1703 private Integer movieIntId2; 1704 private String movieStrId; 1705 1706 public Role() 1707 { 1708 } 1709 1710 public Integer getActorId() 1711 { 1712 return actorId; 1713 } 1714 1715 public void setActorId(Integer actorId) 1716 { 1717 this.actorId = actorId; 1718 } 1719 1720 public Integer getMovieIntId() 1721 { 1722 return movieIntId; 1723 } 1724 1725 public Integer getMovieIntId2() 1726 { 1727 return movieIntId2; 1728 } 1729 1730 public void setMovieIntId2(Integer movieIntId2) 1731 { 1732 this.movieIntId2 = movieIntId2; 1733 } 1734 1735 public Integer getActorId2() 1736 { 1737 return actorId2; 1738 } 1739 1740 public void setActorId2(Integer actorId2) 1741 { 1742 this.actorId2 = actorId2; 1743 } 1744 1745 public void setMovieIntId(Integer movieIntId) 1746 { 1747 this.movieIntId = movieIntId; 1748 } 1749 1750 public String getMovieStrId() 1751 { 1752 return movieStrId; 1753 } 1754 1755 public void setMovieStrId(String movieStrId) 1756 { 1757 this.movieStrId = movieStrId; 1758 } 1759 1760 public String toString() 1761 { 1762 return ToStringBuilder.reflectionToString(this); 1763 } 1764 } 1765 1766 1773 public static class Producer 1774 { 1775 private Integer id; 1776 private String idStr; 1777 private String name; 1778 private List movies; 1779 1780 public Producer() 1781 { 1782 } 1783 1784 public Producer(String idStr, String name) 1785 { 1786 this.idStr = idStr; 1787 this.name = name; 1788 } 1789 1790 public List getMovies() 1791 { 1792 return movies; 1793 } 1794 1795 public void setMovies(List movies) 1796 { 1797 this.movies = movies; 1798 } 1799 1800 public void addMovie(Movie movie) 1801 { 1802 if(movies == null) 1803 { 1804 movies = new ArrayList (); 1805 } 1806 movies.add(movie); 1807 if(movie.getProducers() == null || !movie.getProducers().contains(this)) 1808 { 1809 movie.addProducer(this); 1810 } 1811 } 1812 1813 public Integer getId() 1814 { 1815 return id; 1816 } 1817 1818 public void setId(Integer id) 1819 { 1820 this.id = id; 1821 } 1822 1823 public String getIdStr() 1824 { 1825 return idStr; 1826 } 1827 1828 public void setIdStr(String idStr) 1829 { 1830 this.idStr = idStr; 1831 } 1832 1833 public String getName() 1834 { 1835 return name; 1836 } 1837 1838 public void setName(String name) 1839 { 1840 this.name = name; 1841 } 1842 1843 public int hashCode() 1844 { 1845 return new HashCodeBuilder().append(id).append(idStr).hashCode(); 1846 } 1847 1848 public boolean equals(Object obj) 1849 { 1850 boolean result = false; 1851 if(obj instanceof Producer) 1852 { 1853 Producer other = (Producer) obj; 1854 result = new EqualsBuilder().append(id, other.id).append(idStr, other.idStr).isEquals(); 1855 } 1856 return result; 1857 } 1858 1859 public String toString() 1860 { 1861 return ToStringBuilder.reflectionToString(this); 1862 } 1863 } 1864} | Popular Tags |