1 package xdoclet.modules.ojb.tests; 2 3 17 18 23 public class ModifyInheritedTagForeignkeyAttributeTests extends OjbTestBase 24 { 25 public ModifyInheritedTagForeignkeyAttributeTests(String name) 26 { 27 super(name); 28 } 29 30 public void testForeignkey1() 32 { 33 addClass( 34 "test.A", 35 "package test;\n"+ 36 "/** @ojb.class */\n" + 37 "public class A {\n"+ 38 " /** @ojb.field primarykey=\"true\" */\n"+ 39 " private int id;\n"+ 40 " /** @ojb.collection element-class-ref=\"test.C\"\n"+ 41 " * foreignkey=\"aid\"\n"+ 42 " */\n"+ 43 " private java.util.List attr;\n"+ 44 "}"); 45 addClass( 46 "test.B", 47 "package test;\n"+ 48 "/** @ojb.class\n"+ 49 " * @ojb.modify-inherited name=\"attr\"\n"+ 50 " * foreignkey=\"\"\n"+ 51 " */\n" + 52 "public class B extends A {}"); 53 addClass( 54 "test.C", 55 "package test;\n"+ 56 "/** @ojb.class */\n"+ 57 "public class C {\n"+ 58 " /** @ojb.field */\n"+ 59 " private int aid;\n"+ 60 "}\n"); 61 62 assertNull(runOjbXDoclet(OJB_DEST_FILE)); 63 assertNull(runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 64 } 65 66 public void testForeignkey2() 68 { 69 addClass( 70 "test.A", 71 "package test;\n"+ 72 "/** @ojb.class */\n"+ 73 "public class A {\n"+ 74 " /** @ojb.field */\n"+ 75 " private int attrKey;\n"+ 76 " /** @ojb.reference foreignkey=\"attrKey\" */\n"+ 77 " private test.D attr;\n"+ 78 "}\n"); 79 addClass( 80 "test.B", 81 "package test;\n"+ 82 "/** @ojb.class\n"+ 83 " * @ojb.modify-inherited name=\"attr\"\n"+ 84 " * foreignkey=\"attrKey1,attrKey2\"\n"+ 85 " */\n"+ 86 "public class B extends A {\n"+ 87 " /** @ojb.field */\n"+ 88 " private int attrKey1;\n"+ 89 " /** @ojb.field */\n"+ 90 " private int attrKey2;\n"+ 91 "}\n"); 92 addClass( 93 "test.C", 94 "package test;\n"+ 95 "/** @ojb.class */\n"+ 96 "public class C extends B {}\n"); 97 addClass( 98 "test.D", 99 "package test;\n"+ 100 "/** @ojb.class */\n"+ 101 "public class D {\n"+ 102 " /** @ojb.field primarykey=\"true\" */\n"+ 103 " private int id;\n"+ 104 "}\n"); 105 106 assertNull(runOjbXDoclet(OJB_DEST_FILE)); 107 assertNull(runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 108 } 109 110 public void testForeignkey3() 112 { 113 addClass( 114 "test.A", 115 "package test;\n"+ 116 "/** @ojb.class */\n"+ 117 "public class A {\n"+ 118 " /** @ojb.field */\n"+ 119 " private int attrKey;\n"+ 120 " /** @ojb.reference foreignkey=\"attrKey\" */\n"+ 121 " private test.D attr;\n"+ 122 "}\n"); 123 addClass( 124 "test.B", 125 "package test;\n"+ 126 "/** @ojb.class\n"+ 127 " * @ojb.modify-inherited name=\"attr\"\n"+ 128 " * foreignkey=\"attrKeyB\"\n"+ 129 " */\n"+ 130 "public class B extends A {\n"+ 131 " /** @ojb.field */\n"+ 132 " private int attrKeyB;\n"+ 133 "}\n"); 134 addClass( 135 "test.C", 136 "package test;\n"+ 137 "/** @ojb.class */\n"+ 138 "public class C extends B {}\n"); 139 addClass( 140 "test.D", 141 "package test;\n"+ 142 "/** @ojb.class */\n"+ 143 "public class D {\n"+ 144 " /** @ojb.field primarykey=\"true\" */\n"+ 145 " private int id;\n"+ 146 "}\n"); 147 148 assertEqualsOjbDescriptorFile( 149 "<class-descriptor\n"+ 150 " class=\"test.A\"\n"+ 151 " table=\"A\"\n"+ 152 ">\n"+ 153 " <extent-class class-ref=\"test.B\"/>\n"+ 154 " <field-descriptor\n"+ 155 " name=\"attrKey\"\n"+ 156 " column=\"attrKey\"\n"+ 157 " jdbc-type=\"INTEGER\"\n"+ 158 " >\n"+ 159 " </field-descriptor>\n"+ 160 " <reference-descriptor\n"+ 161 " name=\"attr\"\n"+ 162 " class-ref=\"test.D\"\n"+ 163 " >\n"+ 164 " <foreignkey field-ref=\"attrKey\"/>\n"+ 165 " </reference-descriptor>\n"+ 166 "</class-descriptor>\n"+ 167 "<class-descriptor\n"+ 168 " class=\"test.B\"\n"+ 169 " table=\"B\"\n"+ 170 ">\n"+ 171 " <extent-class class-ref=\"test.C\"/>\n"+ 172 " <field-descriptor\n"+ 173 " name=\"attrKey\"\n"+ 174 " column=\"attrKey\"\n"+ 175 " jdbc-type=\"INTEGER\"\n"+ 176 " >\n"+ 177 " </field-descriptor>\n"+ 178 " <field-descriptor\n"+ 179 " name=\"attrKeyB\"\n"+ 180 " column=\"attrKeyB\"\n"+ 181 " jdbc-type=\"INTEGER\"\n"+ 182 " >\n"+ 183 " </field-descriptor>\n"+ 184 " <reference-descriptor\n"+ 185 " name=\"attr\"\n"+ 186 " class-ref=\"test.D\"\n"+ 187 " >\n"+ 188 " <foreignkey field-ref=\"attrKeyB\"/>\n"+ 189 " </reference-descriptor>\n"+ 190 "</class-descriptor>\n"+ 191 "<class-descriptor\n"+ 192 " class=\"test.C\"\n"+ 193 " table=\"C\"\n"+ 194 ">\n"+ 195 " <field-descriptor\n"+ 196 " name=\"attrKey\"\n"+ 197 " column=\"attrKey\"\n"+ 198 " jdbc-type=\"INTEGER\"\n"+ 199 " >\n"+ 200 " </field-descriptor>\n"+ 201 " <field-descriptor\n"+ 202 " name=\"attrKeyB\"\n"+ 203 " column=\"attrKeyB\"\n"+ 204 " jdbc-type=\"INTEGER\"\n"+ 205 " >\n"+ 206 " </field-descriptor>\n"+ 207 " <reference-descriptor\n"+ 208 " name=\"attr\"\n"+ 209 " class-ref=\"test.D\"\n"+ 210 " >\n"+ 211 " <foreignkey field-ref=\"attrKeyB\"/>\n"+ 212 " </reference-descriptor>\n"+ 213 "</class-descriptor>\n"+ 214 "<class-descriptor\n"+ 215 " class=\"test.D\"\n"+ 216 " table=\"D\"\n"+ 217 ">\n"+ 218 " <field-descriptor\n"+ 219 " name=\"id\"\n"+ 220 " column=\"id\"\n"+ 221 " jdbc-type=\"INTEGER\"\n"+ 222 " primarykey=\"true\"\n"+ 223 " >\n"+ 224 " </field-descriptor>\n"+ 225 "</class-descriptor>", 226 runOjbXDoclet(OJB_DEST_FILE)); 227 assertEqualsTorqueSchemaFile( 228 "<database name=\"ojbtest\">\n"+ 229 " <table name=\"A\">\n"+ 230 " <column name=\"attrKey\"\n"+ 231 " javaName=\"attrKey\"\n"+ 232 " type=\"INTEGER\"\n"+ 233 " />\n"+ 234 " <foreign-key foreignTable=\"D\">\n"+ 235 " <reference local=\"attrKey\" foreign=\"id\"/>\n"+ 236 " </foreign-key>\n"+ 237 " </table>\n"+ 238 " <table name=\"B\">\n"+ 239 " <column name=\"attrKey\"\n"+ 240 " javaName=\"attrKey\"\n"+ 241 " type=\"INTEGER\"\n"+ 242 " />\n"+ 243 " <column name=\"attrKeyB\"\n"+ 244 " javaName=\"attrKeyB\"\n"+ 245 " type=\"INTEGER\"\n"+ 246 " />\n"+ 247 " <foreign-key foreignTable=\"D\">\n"+ 248 " <reference local=\"attrKeyB\" foreign=\"id\"/>\n"+ 249 " </foreign-key>\n"+ 250 " </table>\n"+ 251 " <table name=\"C\">\n"+ 252 " <column name=\"attrKey\"\n"+ 253 " javaName=\"attrKey\"\n"+ 254 " type=\"INTEGER\"\n"+ 255 " />\n"+ 256 " <column name=\"attrKeyB\"\n"+ 257 " javaName=\"attrKeyB\"\n"+ 258 " type=\"INTEGER\"\n"+ 259 " />\n"+ 260 " <foreign-key foreignTable=\"D\">\n"+ 261 " <reference local=\"attrKeyB\" foreign=\"id\"/>\n"+ 262 " </foreign-key>\n"+ 263 " </table>\n"+ 264 " <table name=\"D\">\n"+ 265 " <column name=\"id\"\n"+ 266 " javaName=\"id\"\n"+ 267 " type=\"INTEGER\"\n"+ 268 " primaryKey=\"true\"\n"+ 269 " required=\"true\"\n"+ 270 " />\n"+ 271 " </table>\n"+ 272 "</database>", 273 runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 274 } 275 276 public void testForeignkey4() 278 { 279 addClass( 280 "test.A", 281 "package test;\n"+ 282 "/** @ojb.class */\n" + 283 "public class A {\n"+ 284 " /** @ojb.field primarykey=\"true\" */\n"+ 285 " private int id;\n"+ 286 " /** @ojb.collection element-class-ref=\"test.C\"\n"+ 287 " * foreignkey=\"aid\"\n"+ 288 " */\n"+ 289 " private java.util.List attr;\n"+ 290 "}"); 291 addClass( 292 "test.A", 293 "package test;\n"+ 294 "/** @ojb.class\n"+ 295 " * @ojb.modify-inherited name=\"attr\"\n"+ 296 " * foreignkey=\"id\"\n"+ 297 " */\n" + 298 "public class B extends A {}"); 299 addClass( 300 "test.C", 301 "package test;\n"+ 302 "/** @ojb.class */\n"+ 303 "public class B {\n"+ 304 " /** @ojb.field */\n"+ 305 " private int aid;\n"+ 306 "}\n"); 307 308 assertNull(runOjbXDoclet(OJB_DEST_FILE)); 309 assertNull(runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 310 } 311 312 public void testForeignkey5() 314 { 315 addClass( 316 "test.A", 317 "package test;\n"+ 318 "/** @ojb.class */\n"+ 319 "public class A {\n"+ 320 " /** @ojb.field */\n"+ 321 " private int attrKey;\n"+ 322 " /** @ojb.reference foreignkey=\"attrKey\" */\n"+ 323 " private test.D attr;\n"+ 324 "}\n"); 325 addClass( 326 "test.B", 327 "package test;\n"+ 328 "/** @ojb.class\n"+ 329 " * @ojb.modify-inherited name=\"attr\"\n"+ 330 " * foreignkey=\"attrKeyB\"\n"+ 331 " */\n"+ 332 "public class B extends A {\n"+ 333 " private int attrKeyB;\n"+ 334 "}\n"); 335 addClass( 336 "test.C", 337 "package test;\n"+ 338 "/** @ojb.class */\n"+ 339 "public class C extends B {}\n"); 340 addClass( 341 "test.D", 342 "package test;\n"+ 343 "/** @ojb.class */\n"+ 344 "public class D {\n"+ 345 " /** @ojb.field primarykey=\"true\" */\n"+ 346 " private int id;\n"+ 347 "}\n"); 348 349 assertNull(runOjbXDoclet(OJB_DEST_FILE)); 350 assertNull(runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 351 } 352 353 public void testForeignkey6() 355 { 356 addClass( 357 "test.A", 358 "package test;\n"+ 359 "/** @ojb.class */\n"+ 360 "public class A {\n"+ 361 " /** @ojb.field */\n"+ 362 " private int attrKey;\n"+ 363 " /** @ojb.reference foreignkey=\"attrKey\" */\n"+ 364 " private test.D attr;\n"+ 365 "}\n"); 366 addClass( 367 "test.B", 368 "package test;\n"+ 369 "/** @ojb.class\n"+ 370 " * @ojb.modify-inherited name=\"attr\"\n"+ 371 " * foreignkey=\"attrKeyB\"\n"+ 372 " */\n"+ 373 "public class B extends A {\n"+ 374 " /** @ojb.field jdbc-type=\"DECIMAL\" */\n"+ 375 " private int attrKeyB;\n"+ 376 "}\n"); 377 addClass( 378 "test.C", 379 "package test;\n"+ 380 "/** @ojb.class */\n"+ 381 "public class C extends B {}\n"); 382 addClass( 383 "test.D", 384 "package test;\n"+ 385 "/** @ojb.class */\n"+ 386 "public class D {\n"+ 387 " /** @ojb.field primarykey=\"true\" */\n"+ 388 " private int id;\n"+ 389 "}\n"); 390 391 assertNull(runOjbXDoclet(OJB_DEST_FILE)); 392 assertNull(runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 393 } 394 395 public void testForeignkey7() 397 { 398 addClass( 399 "test.A", 400 "package test;\n"+ 401 "/** @ojb.class */\n"+ 402 "public class A {\n"+ 403 " /** @ojb.field */\n"+ 404 " private int attrKeyA;\n"+ 405 " /** @ojb.field */\n"+ 406 " private String attrKeyB;\n"+ 407 " /** @ojb.reference foreignkey=\"attrKeyA,attrKeyB\" */\n"+ 408 " private test.C attr;\n"+ 409 "}\n"); 410 addClass( 411 "test.B", 412 "package test;\n"+ 413 "/** @ojb.class\n"+ 414 " * @ojb.modify-inherited name=\"attr\"\n"+ 415 " * foreignkey=\"\"\n"+ 416 " */\n"+ 417 "public class B extends A {}\n"); 418 addClass( 419 "test.C", 420 "package test;\n"+ 421 "/** @ojb.class */\n"+ 422 "public class C {\n"+ 423 " /** @ojb.field primarykey=\"true\" */\n"+ 424 " private int idA;\n"+ 425 " /** @ojb.field primarykey=\"true\" */\n"+ 426 " private String idB;\n"+ 427 "}\n"); 428 429 assertNull(runOjbXDoclet(OJB_DEST_FILE)); 430 assertNull(runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 431 } 432 433 public void testForeignkey8() 435 { 436 addClass( 437 "test.A", 438 "package test;\n"+ 439 "/** @ojb.class */\n"+ 440 "public class A {\n"+ 441 " /** @ojb.field */\n"+ 442 " private int attrKeyA;\n"+ 443 " /** @ojb.field */\n"+ 444 " private String attrKeyB;\n"+ 445 " /** @ojb.reference foreignkey=\"attrKeyA,attrKeyB\" */\n"+ 446 " private test.C attr;\n"+ 447 "}\n"); 448 addClass( 449 "test.B", 450 "package test;\n"+ 451 "/** @ojb.class\n"+ 452 " * @ojb.modify-inherited name=\"attr\"\n"+ 453 " * foreignkey=\"attrKey\"\n"+ 454 " */\n"+ 455 "public class B extends A {\n"+ 456 " /** @ojb.field */\n"+ 457 " private int attrKey;\n"+ 458 "}\n"); 459 addClass( 460 "test.C", 461 "package test;\n"+ 462 "/** @ojb.class */\n"+ 463 "public class C {\n"+ 464 " /** @ojb.field primarykey=\"true\" */\n"+ 465 " private int idA;\n"+ 466 " /** @ojb.field primarykey=\"true\" */\n"+ 467 " private String idB;\n"+ 468 "}\n"); 469 470 assertNull(runOjbXDoclet(OJB_DEST_FILE)); 471 assertNull(runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 472 } 473 474 public void testForeignkey9() 476 { 477 addClass( 478 "test.A", 479 "package test;\n"+ 480 "/** @ojb.class */\n" + 481 "public class A {\n"+ 482 " /** @ojb.field primarykey=\"true\" */\n"+ 483 " private int id1;\n"+ 484 " /** @ojb.field primarykey=\"true\" */\n"+ 485 " private String id2;\n"+ 486 " /** @ojb.collection element-class-ref=\"test.D\"\n"+ 487 " * foreignkey=\"aid1,aid2\"\n"+ 488 " * database-foreignkey=\"false\"\n"+ 489 " */\n"+ 490 " private java.util.List attr;\n"+ 491 "}"); 492 addClass( 493 "test.B", 494 "package test;\n"+ 495 "/** @ojb.class */\n" + 496 "public class B extends A {}"); 497 addClass( 498 "test.C", 499 "package test;\n"+ 500 "/** @ojb.class\n"+ 501 " * @ojb.modify-inherited name=\"attr\"\n"+ 502 " * foreignkey=\"aid4,aid3\"\n"+ 503 " */\n" + 504 "public class C extends B {}"); 505 addClass( 506 "test.D", 507 "package test;\n"+ 508 "/** @ojb.class\n"+ 509 " * @ojb.field name=\"aid3\"\n"+ 510 " * jdbc-type=\"VARCHAR\"\n"+ 511 " */\n"+ 512 "public class D {\n"+ 513 " /** @ojb.field */\n"+ 514 " private int aid1;\n"+ 515 " /** @ojb.field */\n"+ 516 " private int aid4;\n"+ 517 " /** @ojb.field */\n"+ 518 " private String aid2;\n"+ 519 "}\n"); 520 521 assertEqualsOjbDescriptorFile( 522 "<class-descriptor\n"+ 523 " class=\"test.A\"\n"+ 524 " table=\"A\"\n"+ 525 ">\n"+ 526 " <extent-class class-ref=\"test.B\"/>\n"+ 527 " <field-descriptor\n"+ 528 " name=\"id1\"\n"+ 529 " column=\"id1\"\n"+ 530 " jdbc-type=\"INTEGER\"\n"+ 531 " primarykey=\"true\"\n"+ 532 " >\n"+ 533 " </field-descriptor>\n"+ 534 " <field-descriptor\n"+ 535 " name=\"id2\"\n"+ 536 " column=\"id2\"\n"+ 537 " jdbc-type=\"VARCHAR\"\n"+ 538 " primarykey=\"true\"\n"+ 539 " length=\"254\"\n"+ 540 " >\n"+ 541 " </field-descriptor>\n"+ 542 " <collection-descriptor\n"+ 543 " name=\"attr\"\n"+ 544 " element-class-ref=\"test.D\"\n"+ 545 " >\n"+ 546 " <inverse-foreignkey field-ref=\"aid1\"/>\n"+ 547 " <inverse-foreignkey field-ref=\"aid2\"/>\n"+ 548 " </collection-descriptor>\n"+ 549 "</class-descriptor>\n"+ 550 "<class-descriptor\n"+ 551 " class=\"test.B\"\n"+ 552 " table=\"B\"\n"+ 553 ">\n"+ 554 " <extent-class class-ref=\"test.C\"/>\n"+ 555 " <field-descriptor\n"+ 556 " name=\"id1\"\n"+ 557 " column=\"id1\"\n"+ 558 " jdbc-type=\"INTEGER\"\n"+ 559 " primarykey=\"true\"\n"+ 560 " >\n"+ 561 " </field-descriptor>\n"+ 562 " <field-descriptor\n"+ 563 " name=\"id2\"\n"+ 564 " column=\"id2\"\n"+ 565 " jdbc-type=\"VARCHAR\"\n"+ 566 " primarykey=\"true\"\n"+ 567 " length=\"254\"\n"+ 568 " >\n"+ 569 " </field-descriptor>\n"+ 570 " <collection-descriptor\n"+ 571 " name=\"attr\"\n"+ 572 " element-class-ref=\"test.D\"\n"+ 573 " >\n"+ 574 " <inverse-foreignkey field-ref=\"aid1\"/>\n"+ 575 " <inverse-foreignkey field-ref=\"aid2\"/>\n"+ 576 " </collection-descriptor>\n"+ 577 "</class-descriptor>\n"+ 578 "<class-descriptor\n"+ 579 " class=\"test.C\"\n"+ 580 " table=\"C\"\n"+ 581 ">\n"+ 582 " <field-descriptor\n"+ 583 " name=\"id1\"\n"+ 584 " column=\"id1\"\n"+ 585 " jdbc-type=\"INTEGER\"\n"+ 586 " primarykey=\"true\"\n"+ 587 " >\n"+ 588 " </field-descriptor>\n"+ 589 " <field-descriptor\n"+ 590 " name=\"id2\"\n"+ 591 " column=\"id2\"\n"+ 592 " jdbc-type=\"VARCHAR\"\n"+ 593 " primarykey=\"true\"\n"+ 594 " length=\"254\"\n"+ 595 " >\n"+ 596 " </field-descriptor>\n"+ 597 " <collection-descriptor\n"+ 598 " name=\"attr\"\n"+ 599 " element-class-ref=\"test.D\"\n"+ 600 " >\n"+ 601 " <inverse-foreignkey field-ref=\"aid4\"/>\n"+ 602 " <inverse-foreignkey field-ref=\"aid3\"/>\n"+ 603 " </collection-descriptor>\n"+ 604 "</class-descriptor>\n"+ 605 "<class-descriptor\n"+ 606 " class=\"test.D\"\n"+ 607 " table=\"D\"\n"+ 608 ">\n"+ 609 " <field-descriptor\n"+ 610 " name=\"aid3\"\n"+ 611 " column=\"aid3\"\n"+ 612 " jdbc-type=\"VARCHAR\"\n"+ 613 " length=\"254\"\n"+ 614 " access=\"anonymous\"\n"+ 615 " >\n"+ 616 " </field-descriptor>\n"+ 617 " <field-descriptor\n"+ 618 " name=\"aid1\"\n"+ 619 " column=\"aid1\"\n"+ 620 " jdbc-type=\"INTEGER\"\n"+ 621 " >\n"+ 622 " </field-descriptor>\n"+ 623 " <field-descriptor\n"+ 624 " name=\"aid4\"\n"+ 625 " column=\"aid4\"\n"+ 626 " jdbc-type=\"INTEGER\"\n"+ 627 " >\n"+ 628 " </field-descriptor>\n"+ 629 " <field-descriptor\n"+ 630 " name=\"aid2\"\n"+ 631 " column=\"aid2\"\n"+ 632 " jdbc-type=\"VARCHAR\"\n"+ 633 " length=\"254\"\n"+ 634 " >\n"+ 635 " </field-descriptor>\n"+ 636 "</class-descriptor>", 637 runOjbXDoclet(OJB_DEST_FILE)); 638 assertEqualsTorqueSchemaFile( 639 "<database name=\"ojbtest\">\n"+ 640 " <table name=\"A\">\n"+ 641 " <column name=\"id1\"\n"+ 642 " javaName=\"id1\"\n"+ 643 " type=\"INTEGER\"\n"+ 644 " primaryKey=\"true\"\n"+ 645 " required=\"true\"\n"+ 646 " />\n"+ 647 " <column name=\"id2\"\n"+ 648 " javaName=\"id2\"\n"+ 649 " type=\"VARCHAR\"\n"+ 650 " primaryKey=\"true\"\n"+ 651 " required=\"true\"\n"+ 652 " size=\"254\"\n"+ 653 " />\n"+ 654 " </table>\n"+ 655 " <table name=\"B\">\n"+ 656 " <column name=\"id1\"\n"+ 657 " javaName=\"id1\"\n"+ 658 " type=\"INTEGER\"\n"+ 659 " primaryKey=\"true\"\n"+ 660 " required=\"true\"\n"+ 661 " />\n"+ 662 " <column name=\"id2\"\n"+ 663 " javaName=\"id2\"\n"+ 664 " type=\"VARCHAR\"\n"+ 665 " primaryKey=\"true\"\n"+ 666 " required=\"true\"\n"+ 667 " size=\"254\"\n"+ 668 " />\n"+ 669 " </table>\n"+ 670 " <table name=\"C\">\n"+ 671 " <column name=\"id1\"\n"+ 672 " javaName=\"id1\"\n"+ 673 " type=\"INTEGER\"\n"+ 674 " primaryKey=\"true\"\n"+ 675 " required=\"true\"\n"+ 676 " />\n"+ 677 " <column name=\"id2\"\n"+ 678 " javaName=\"id2\"\n"+ 679 " type=\"VARCHAR\"\n"+ 680 " primaryKey=\"true\"\n"+ 681 " required=\"true\"\n"+ 682 " size=\"254\"\n"+ 683 " />\n"+ 684 " </table>\n"+ 685 " <table name=\"D\">\n"+ 686 " <column name=\"aid3\"\n"+ 687 " javaName=\"aid3\"\n"+ 688 " type=\"VARCHAR\"\n"+ 689 " size=\"254\"\n"+ 690 " />\n"+ 691 " <column name=\"aid1\"\n"+ 692 " javaName=\"aid1\"\n"+ 693 " type=\"INTEGER\"\n"+ 694 " />\n"+ 695 " <column name=\"aid4\"\n"+ 696 " javaName=\"aid4\"\n"+ 697 " type=\"INTEGER\"\n"+ 698 " />\n"+ 699 " <column name=\"aid2\"\n"+ 700 " javaName=\"aid2\"\n"+ 701 " type=\"VARCHAR\"\n"+ 702 " size=\"254\"\n"+ 703 " />\n"+ 704 " </table>\n"+ 705 "</database>", 706 runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 707 } 708 709 public void testForeignkey10() 711 { 712 addClass( 713 "test.A", 714 "package test;\n"+ 715 "/** @ojb.class */\n"+ 716 "public class A {\n"+ 717 " /** @ojb.field */\n"+ 718 " private int attrKeyA;\n"+ 719 " /** @ojb.field */\n"+ 720 " private String attrKeyB;\n"+ 721 " /** @ojb.reference foreignkey=\"attrKeyA,attrKeyB\" */\n"+ 722 " private test.C attr;\n"+ 723 "}\n"); 724 addClass( 725 "test.B", 726 "package test;\n"+ 727 "/** @ojb.class\n"+ 728 " * @ojb.modify-inherited name=\"attr\"\n"+ 729 " * foreignkey=\"attrKey1,attrKey2\"\n"+ 730 " */\n"+ 731 "public class B extends A {\n"+ 732 " /** @ojb.field */\n"+ 733 " private int attrKey1;\n"+ 734 "}\n"); 735 addClass( 736 "test.C", 737 "package test;\n"+ 738 "/** @ojb.class */\n"+ 739 "public class C {\n"+ 740 " /** @ojb.field primarykey=\"true\" */\n"+ 741 " private int idA;\n"+ 742 " /** @ojb.field primarykey=\"true\" */\n"+ 743 " private String idB;\n"+ 744 "}\n"); 745 746 assertNull(runOjbXDoclet(OJB_DEST_FILE)); 747 assertNull(runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 748 } 749 750 public void testForeignkey11() 752 { 753 addClass( 754 "test.A", 755 "package test;\n"+ 756 "/** @ojb.class */\n" + 757 "public class A {\n"+ 758 " /** @ojb.field primarykey=\"true\" */\n"+ 759 " private int id1;\n"+ 760 " /** @ojb.field primarykey=\"true\" */\n"+ 761 " private String id2;\n"+ 762 " /** @ojb.collection element-class-ref=\"test.C\"\n"+ 763 " * foreignkey=\"aid1,aid2\"\n"+ 764 " */\n"+ 765 " private java.util.List attr;\n"+ 766 "}"); 767 addClass( 768 "test.B", 769 "package test;\n"+ 770 "/** @ojb.class\n"+ 771 " * @ojb.modify-inherited name=\"attr\"\n"+ 772 " * foreignkey=\"aid3,aid4\"\n"+ 773 " */\n" + 774 "public class B extends A {}"); 775 addClass( 776 "test.C", 777 "package test;\n"+ 778 "/** @ojb.class */\n"+ 779 "public class C {\n"+ 780 " /** @ojb.field */\n"+ 781 " private int aid1;\n"+ 782 " /** @ojb.field */\n"+ 783 " private int aid3;\n"+ 784 " /** @ojb.field */\n"+ 785 " private String aid2;\n"+ 786 " private String aid4;\n"+ 787 "}\n"); 788 789 assertNull(runOjbXDoclet(OJB_DEST_FILE)); 790 assertNull(runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 791 } 792 793 public void testForeignkey12() 795 { 796 addClass( 797 "test.A", 798 "package test;\n"+ 799 "/** @ojb.class */\n" + 800 "public class A {\n"+ 801 " /** @ojb.field primarykey=\"true\" */\n"+ 802 " private int id1;\n"+ 803 " /** @ojb.field primarykey=\"true\" */\n"+ 804 " private String id2;\n"+ 805 " /** @ojb.collection element-class-ref=\"test.C\"\n"+ 806 " * foreignkey=\"aid1,aid2\"\n"+ 807 " */\n"+ 808 " private java.util.List attr;\n"+ 809 "}"); 810 addClass( 811 "test.B", 812 "package test;\n"+ 813 "/** @ojb.class\n"+ 814 " * @ojb.modify-inherited name=\"attr\"\n"+ 815 " * foreignkey=\"aid3,aid4\"\n"+ 816 " */\n" + 817 "public class B extends A {}"); 818 addClass( 819 "test.C", 820 "package test;\n"+ 821 "/** @ojb.class */\n"+ 822 "public class C {\n"+ 823 " /** @ojb.field */\n"+ 824 " private int aid1;\n"+ 825 " /** @ojb.field */\n"+ 826 " private int aid3;\n"+ 827 " /** @ojb.field */\n"+ 828 " private String aid2;\n"+ 829 " /** @ojb.field */\n"+ 830 " private int aid4;\n"+ 831 "}\n"); 832 833 assertNull(runOjbXDoclet(OJB_DEST_FILE)); 834 assertNull(runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 835 } 836 837 public void testForeignkey13() 839 { 840 addClass( 841 "test.A", 842 "package test;\n"+ 843 "/** @ojb.class */\n" + 844 "public class A {\n"+ 845 " /** @ojb.field primarykey=\"true\" */\n"+ 846 " private int id;\n"+ 847 " /** @ojb.collection foreignkey=\"AID\"\n"+ 848 " * indirection-table=\"A_B\"\n"+ 849 " */\n"+ 850 " private B[] bs;\n"+ 851 "}"); 852 addClass( 853 "test.B", 854 "package test;\n"+ 855 "/** @ojb.class */\n"+ 856 "public class B {\n"+ 857 " /** @ojb.field primarykey=\"true\" */\n"+ 858 " private int id;\n"+ 859 " /** @ojb.collection element-class-ref=\"test.A\"\n"+ 860 " * foreignkey=\"BID\"\n"+ 861 " * indirection-table=\"A_B\"\n"+ 862 " */\n"+ 863 " private java.util.List as;\n"+ 864 "}\n"); 865 addClass( 866 "test.C", 867 "package test;\n"+ 868 "/** @ojb.class\n"+ 869 " * @ojb.modify-inherited name=\"bs\"\n"+ 870 " * foreignkey=\"CID\"\n"+ 871 " */\n"+ 872 "public class C extends A {}\n"); 873 874 assertNull(runOjbXDoclet(OJB_DEST_FILE)); 875 assertNull(runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 876 } 877 } 878 | Popular Tags |