1 package xdoclet.modules.ojb.tests; 2 3 17 18 23 public class CollectionTagForeignkeyAttributeTests extends OjbTestBase 24 { 25 public CollectionTagForeignkeyAttributeTests(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.B\" */\n"+ 41 " private java.util.List attr;\n"+ 42 "}"); 43 addClass( 44 "test.B", 45 "package test;\n"+ 46 "/** @ojb.class */\n"+ 47 "public class B {\n"+ 48 " /** @ojb.field */\n"+ 49 " private int aid;\n"+ 50 "}\n"); 51 52 assertNull(runOjbXDoclet(OJB_DEST_FILE)); 53 assertNull(runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 54 } 55 56 public void testForeignkey2() 58 { 59 addClass( 60 "test.A", 61 "package test;\n"+ 62 "/** @ojb.class */\n" + 63 "public class A {\n"+ 64 " /** @ojb.field primarykey=\"true\" */\n"+ 65 " private int id;\n"+ 66 " /** @ojb.collection element-class-ref=\"test.B\"\n"+ 67 " * foreignkey=\"\"\n"+ 68 " */\n"+ 69 " private java.util.List attr;\n"+ 70 "}"); 71 addClass( 72 "test.B", 73 "package test;\n"+ 74 "/** @ojb.class */\n"+ 75 "public class B {\n"+ 76 " /** @ojb.field */\n"+ 77 " private int aid;\n"+ 78 "}\n"); 79 80 assertNull(runOjbXDoclet(OJB_DEST_FILE)); 81 assertNull(runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 82 } 83 84 public void testForeignkey3() 86 { 87 addClass( 88 "test.A", 89 "package test;\n"+ 90 "/** @ojb.class */\n" + 91 "public class A {\n"+ 92 " /** @ojb.field primarykey=\"true\" */\n"+ 93 " private int id;\n"+ 94 " /** @ojb.collection element-class-ref=\"test.B\"\n"+ 95 " * foreignkey=\"aid\"\n"+ 96 " */\n"+ 97 " private java.util.List attr;\n"+ 98 "}"); 99 addClass( 100 "test.B", 101 "package test;\n"+ 102 "/** @ojb.class */\n"+ 103 "public class B {\n"+ 104 " /** @ojb.field */\n"+ 105 " private int id;\n"+ 106 "}\n"); 107 108 assertNull(runOjbXDoclet(OJB_DEST_FILE)); 109 assertNull(runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 110 } 111 112 public void testForeignkey4() 114 { 115 addClass( 116 "test.A", 117 "package test;\n"+ 118 "/** @ojb.class */\n" + 119 "public class A {\n"+ 120 " /** @ojb.field primarykey=\"true\" */\n"+ 121 " private int id;\n"+ 122 " /** @ojb.collection element-class-ref=\"test.B\"\n"+ 123 " * foreignkey=\"aid\"\n"+ 124 " */\n"+ 125 " private java.util.List attr;\n"+ 126 "}"); 127 addClass( 128 "test.B", 129 "package test;\n"+ 130 "/** @ojb.class */\n"+ 131 "public class B {\n"+ 132 " private int aid;\n"+ 133 "}\n"); 134 135 assertNull(runOjbXDoclet(OJB_DEST_FILE)); 136 assertNull(runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 137 } 138 139 public void testForeignkey6() 141 { 142 addClass( 143 "test.A", 144 "package test;\n"+ 145 "/** @ojb.class */\n" + 146 "public class A {\n"+ 147 " /** @ojb.field primarykey=\"true\" */\n"+ 148 " private int id;\n"+ 149 " /** @ojb.collection element-class-ref=\"test.B\"\n"+ 150 " * foreignkey=\"aid\"\n"+ 151 " * database-foreignkey=\"true\"\n"+ 152 " */\n"+ 153 " private java.util.List attr;\n"+ 154 "}"); 155 addClass( 156 "test.B", 157 "package test;\n"+ 158 "/** @ojb.class */\n"+ 159 "public class B {\n"+ 160 " /** @ojb.field */\n"+ 161 " private int aid;\n"+ 162 "}\n"); 163 164 assertEqualsOjbDescriptorFile( 165 "<class-descriptor\n"+ 166 " class=\"test.A\"\n"+ 167 " table=\"A\"\n"+ 168 ">\n"+ 169 " <field-descriptor\n"+ 170 " name=\"id\"\n"+ 171 " column=\"id\"\n"+ 172 " jdbc-type=\"INTEGER\"\n"+ 173 " primarykey=\"true\"\n"+ 174 " >\n"+ 175 " </field-descriptor>\n"+ 176 " <collection-descriptor\n"+ 177 " name=\"attr\"\n"+ 178 " element-class-ref=\"test.B\"\n"+ 179 " >\n"+ 180 " <inverse-foreignkey field-ref=\"aid\"/>\n"+ 181 " </collection-descriptor>\n"+ 182 "</class-descriptor>\n"+ 183 "<class-descriptor\n"+ 184 " class=\"test.B\"\n"+ 185 " table=\"B\"\n"+ 186 ">\n"+ 187 " <field-descriptor\n"+ 188 " name=\"aid\"\n"+ 189 " column=\"aid\"\n"+ 190 " jdbc-type=\"INTEGER\"\n"+ 191 " >\n"+ 192 " </field-descriptor>\n"+ 193 "</class-descriptor>", 194 runOjbXDoclet(OJB_DEST_FILE)); 195 assertEqualsTorqueSchemaFile( 196 "<database name=\"ojbtest\">\n"+ 197 " <table name=\"A\">\n"+ 198 " <column name=\"id\"\n"+ 199 " javaName=\"id\"\n"+ 200 " type=\"INTEGER\"\n"+ 201 " primaryKey=\"true\"\n"+ 202 " required=\"true\"\n"+ 203 " />\n"+ 204 " </table>\n"+ 205 " <table name=\"B\">\n"+ 206 " <column name=\"aid\"\n"+ 207 " javaName=\"aid\"\n"+ 208 " type=\"INTEGER\"\n"+ 209 " />\n"+ 210 " <foreign-key foreignTable=\"A\">\n"+ 211 " <reference local=\"aid\" foreign=\"id\"/>\n"+ 212 " </foreign-key>\n"+ 213 " </table>\n"+ 214 "</database>", 215 runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 216 } 217 218 public void testForeignkey7() 220 { 221 addClass( 222 "test.A", 223 "package test;\n"+ 224 "/** @ojb.class */\n" + 225 "public class A {\n"+ 226 " /** @ojb.field primarykey=\"true\" */\n"+ 227 " private String id;\n"+ 228 " /** @ojb.collection element-class-ref=\"test.B\"\n"+ 229 " * foreignkey=\"aid\"\n"+ 230 " */\n"+ 231 " private java.util.List attr;\n"+ 232 "}"); 233 addClass( 234 "test.B", 235 "package test;\n"+ 236 "/** @ojb.class */\n"+ 237 "public class B {\n"+ 238 " /** @ojb.field */\n"+ 239 " private int aid;\n"+ 240 "}\n"); 241 242 assertNull(runOjbXDoclet(OJB_DEST_FILE)); 243 assertNull(runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 244 } 245 246 public void testForeignkey8() 248 { 249 addClass( 250 "test.A", 251 "package test;\n"+ 252 "/** @ojb.class */\n" + 253 "public class A {\n"+ 254 " /** @ojb.field primarykey=\"true\" */\n"+ 255 " private int id;\n"+ 256 " /** @ojb.collection element-class-ref=\"test.B\"\n"+ 257 " * foreignkey=\"aid\"\n"+ 258 " * database-foreignkey=\"false\"\n"+ 259 " */\n"+ 260 " private java.util.List attr;\n"+ 261 "}"); 262 addClass( 263 "test.B", 264 "package test;\n"+ 265 "/** @ojb.class\n"+ 266 " * @ojb.field name=\"aid\"\n"+ 267 " * jdbc-type=\"INTEGER\"\n"+ 268 " */\n"+ 269 "public class B {}\n"); 270 271 assertEqualsOjbDescriptorFile( 272 "<class-descriptor\n"+ 273 " class=\"test.A\"\n"+ 274 " table=\"A\"\n"+ 275 ">\n"+ 276 " <field-descriptor\n"+ 277 " name=\"id\"\n"+ 278 " column=\"id\"\n"+ 279 " jdbc-type=\"INTEGER\"\n"+ 280 " primarykey=\"true\"\n"+ 281 " >\n"+ 282 " </field-descriptor>\n"+ 283 " <collection-descriptor\n"+ 284 " name=\"attr\"\n"+ 285 " element-class-ref=\"test.B\"\n"+ 286 " >\n"+ 287 " <inverse-foreignkey field-ref=\"aid\"/>\n"+ 288 " </collection-descriptor>\n"+ 289 "</class-descriptor>\n"+ 290 "<class-descriptor\n"+ 291 " class=\"test.B\"\n"+ 292 " table=\"B\"\n"+ 293 ">\n"+ 294 " <field-descriptor\n"+ 295 " name=\"aid\"\n"+ 296 " column=\"aid\"\n"+ 297 " jdbc-type=\"INTEGER\"\n"+ 298 " access=\"anonymous\"\n"+ 299 " >\n"+ 300 " </field-descriptor>\n"+ 301 "</class-descriptor>", 302 runOjbXDoclet(OJB_DEST_FILE)); 303 assertEqualsTorqueSchemaFile( 304 "<database name=\"ojbtest\">\n"+ 305 " <table name=\"A\">\n"+ 306 " <column name=\"id\"\n"+ 307 " javaName=\"id\"\n"+ 308 " type=\"INTEGER\"\n"+ 309 " primaryKey=\"true\"\n"+ 310 " required=\"true\"\n"+ 311 " />\n"+ 312 " </table>\n"+ 313 " <table name=\"B\">\n"+ 314 " <column name=\"aid\"\n"+ 315 " javaName=\"aid\"\n"+ 316 " type=\"INTEGER\"\n"+ 317 " />\n"+ 318 " </table>\n"+ 319 "</database>", 320 runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 321 } 322 323 public void testForeignkey9() 325 { 326 addClass( 327 "test.A", 328 "package test;\n"+ 329 "/** @ojb.class\n"+ 330 " * @ojb.field name=\"id\"\n"+ 331 " * jdbc-type=\"INTEGER\"\n"+ 332 " * primarykey=\"true\"\n"+ 333 " */\n" + 334 "public class A {\n"+ 335 " /** @ojb.collection element-class-ref=\"test.B\"\n"+ 336 " * foreignkey=\"aid\"\n"+ 337 " */\n"+ 338 " private java.util.List attr;\n"+ 339 "}"); 340 addClass( 341 "test.B", 342 "package test;\n"+ 343 "/** @ojb.class */\n"+ 344 "public class B {\n"+ 345 " /** @ojb.field */\n"+ 346 " private int aid;\n"+ 347 "}\n"); 348 349 assertEqualsOjbDescriptorFile( 350 "<class-descriptor\n"+ 351 " class=\"test.A\"\n"+ 352 " table=\"A\"\n"+ 353 ">\n"+ 354 " <field-descriptor\n"+ 355 " name=\"id\"\n"+ 356 " column=\"id\"\n"+ 357 " jdbc-type=\"INTEGER\"\n"+ 358 " primarykey=\"true\"\n"+ 359 " access=\"anonymous\"\n"+ 360 " >\n"+ 361 " </field-descriptor>\n"+ 362 " <collection-descriptor\n"+ 363 " name=\"attr\"\n"+ 364 " element-class-ref=\"test.B\"\n"+ 365 " >\n"+ 366 " <inverse-foreignkey field-ref=\"aid\"/>\n"+ 367 " </collection-descriptor>\n"+ 368 "</class-descriptor>\n"+ 369 "<class-descriptor\n"+ 370 " class=\"test.B\"\n"+ 371 " table=\"B\"\n"+ 372 ">\n"+ 373 " <field-descriptor\n"+ 374 " name=\"aid\"\n"+ 375 " column=\"aid\"\n"+ 376 " jdbc-type=\"INTEGER\"\n"+ 377 " >\n"+ 378 " </field-descriptor>\n"+ 379 "</class-descriptor>", 380 runOjbXDoclet(OJB_DEST_FILE)); 381 assertEqualsTorqueSchemaFile( 382 "<database name=\"ojbtest\">\n"+ 383 " <table name=\"A\">\n"+ 384 " <column name=\"id\"\n"+ 385 " javaName=\"id\"\n"+ 386 " type=\"INTEGER\"\n"+ 387 " primaryKey=\"true\"\n"+ 388 " required=\"true\"\n"+ 389 " />\n"+ 390 " </table>\n"+ 391 " <table name=\"B\">\n"+ 392 " <column name=\"aid\"\n"+ 393 " javaName=\"aid\"\n"+ 394 " type=\"INTEGER\"\n"+ 395 " />\n"+ 396 " <foreign-key foreignTable=\"A\">\n"+ 397 " <reference local=\"aid\" foreign=\"id\"/>\n"+ 398 " </foreign-key>\n"+ 399 " </table>\n"+ 400 "</database>", 401 runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 402 } 403 404 public void testForeignkey10() 406 { 407 addClass( 408 "test.A", 409 "package test;\n"+ 410 "/** @ojb.class */\n" + 411 "public class A {\n"+ 412 " /** @ojb.field primarykey=\"true\" */\n"+ 413 " private int id1;\n"+ 414 " /** @ojb.field primarykey=\"true\" */\n"+ 415 " private String id2;\n"+ 416 " /** @ojb.collection element-class-ref=\"test.B\"\n"+ 417 " * foreignkey=\"aid1,aid2\"\n"+ 418 " */\n"+ 419 " private java.util.List attr;\n"+ 420 "}"); 421 addClass( 422 "test.B", 423 "package test;\n"+ 424 "/** @ojb.class */\n"+ 425 "public class B {\n"+ 426 " /** @ojb.field */\n"+ 427 " private int aid1;\n"+ 428 " /** @ojb.field */\n"+ 429 " private String aid2;\n"+ 430 "}\n"); 431 432 assertEqualsOjbDescriptorFile( 433 "<class-descriptor\n"+ 434 " class=\"test.A\"\n"+ 435 " table=\"A\"\n"+ 436 ">\n"+ 437 " <field-descriptor\n"+ 438 " name=\"id1\"\n"+ 439 " column=\"id1\"\n"+ 440 " jdbc-type=\"INTEGER\"\n"+ 441 " primarykey=\"true\"\n"+ 442 " >\n"+ 443 " </field-descriptor>\n"+ 444 " <field-descriptor\n"+ 445 " name=\"id2\"\n"+ 446 " column=\"id2\"\n"+ 447 " jdbc-type=\"VARCHAR\"\n"+ 448 " primarykey=\"true\"\n"+ 449 " length=\"254\"\n"+ 450 " >\n"+ 451 " </field-descriptor>\n"+ 452 " <collection-descriptor\n"+ 453 " name=\"attr\"\n"+ 454 " element-class-ref=\"test.B\"\n"+ 455 " >\n"+ 456 " <inverse-foreignkey field-ref=\"aid1\"/>\n"+ 457 " <inverse-foreignkey field-ref=\"aid2\"/>\n"+ 458 " </collection-descriptor>\n"+ 459 "</class-descriptor>\n"+ 460 "<class-descriptor\n"+ 461 " class=\"test.B\"\n"+ 462 " table=\"B\"\n"+ 463 ">\n"+ 464 " <field-descriptor\n"+ 465 " name=\"aid1\"\n"+ 466 " column=\"aid1\"\n"+ 467 " jdbc-type=\"INTEGER\"\n"+ 468 " >\n"+ 469 " </field-descriptor>\n"+ 470 " <field-descriptor\n"+ 471 " name=\"aid2\"\n"+ 472 " column=\"aid2\"\n"+ 473 " jdbc-type=\"VARCHAR\"\n"+ 474 " length=\"254\"\n"+ 475 " >\n"+ 476 " </field-descriptor>\n"+ 477 "</class-descriptor>", 478 runOjbXDoclet(OJB_DEST_FILE)); 479 assertEqualsTorqueSchemaFile( 480 "<database name=\"ojbtest\">\n"+ 481 " <table name=\"A\">\n"+ 482 " <column name=\"id1\"\n"+ 483 " javaName=\"id1\"\n"+ 484 " type=\"INTEGER\"\n"+ 485 " primaryKey=\"true\"\n"+ 486 " required=\"true\"\n"+ 487 " />\n"+ 488 " <column name=\"id2\"\n"+ 489 " javaName=\"id2\"\n"+ 490 " type=\"VARCHAR\"\n"+ 491 " primaryKey=\"true\"\n"+ 492 " required=\"true\"\n"+ 493 " size=\"254\"\n"+ 494 " />\n"+ 495 " </table>\n"+ 496 " <table name=\"B\">\n"+ 497 " <column name=\"aid1\"\n"+ 498 " javaName=\"aid1\"\n"+ 499 " type=\"INTEGER\"\n"+ 500 " />\n"+ 501 " <column name=\"aid2\"\n"+ 502 " javaName=\"aid2\"\n"+ 503 " type=\"VARCHAR\"\n"+ 504 " size=\"254\"\n"+ 505 " />\n"+ 506 " <foreign-key foreignTable=\"A\">\n"+ 507 " <reference local=\"aid1\" foreign=\"id1\"/>\n"+ 508 " <reference local=\"aid2\" foreign=\"id2\"/>\n"+ 509 " </foreign-key>\n"+ 510 " </table>\n"+ 511 "</database>", 512 runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 513 } 514 515 public void testForeignkey11() 517 { 518 addClass( 519 "test.A", 520 "package test;\n"+ 521 "/** @ojb.class */\n" + 522 "public class A {\n"+ 523 " /** @ojb.field primarykey=\"true\" */\n"+ 524 " private int id1;\n"+ 525 " /** @ojb.field primarykey=\"true\" */\n"+ 526 " private String id2;\n"+ 527 " /** @ojb.collection element-class-ref=\"test.B\"\n"+ 528 " * foreignkey=\"aid2,aid1\"\n"+ 529 " */\n"+ 530 " private java.util.List attr;\n"+ 531 "}"); 532 addClass( 533 "test.B", 534 "package test;\n"+ 535 "/** @ojb.class */\n"+ 536 "public class B {\n"+ 537 " /** @ojb.field */\n"+ 538 " private int aid1;\n"+ 539 " /** @ojb.field */\n"+ 540 " private String aid2;\n"+ 541 "}\n"); 542 543 assertNull(runOjbXDoclet(OJB_DEST_FILE)); 544 assertNull(runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 545 } 546 547 public void testForeignkey12() 549 { 550 addClass( 551 "test.A", 552 "package test;\n"+ 553 "/** @ojb.class */\n" + 554 "public class A {\n"+ 555 " /** @ojb.field primarykey=\"true\" */\n"+ 556 " private int id;\n"+ 557 " /** @ojb.collection element-class-ref=\"test.B\"\n"+ 558 " * foreignkey=\"aid1,aid2\"\n"+ 559 " */\n"+ 560 " private java.util.List attr;\n"+ 561 "}"); 562 addClass( 563 "test.B", 564 "package test;\n"+ 565 "/** @ojb.class */\n"+ 566 "public class B {\n"+ 567 " /** @ojb.field */\n"+ 568 " private int aid1;\n"+ 569 " /** @ojb.field */\n"+ 570 " private String aid2;\n"+ 571 "}\n"); 572 573 assertNull(runOjbXDoclet(OJB_DEST_FILE)); 574 assertNull(runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 575 } 576 577 public void testForeignkey13() 579 { 580 addClass( 581 "test.A", 582 "package test;\n"+ 583 "/** @ojb.class */\n" + 584 "public class A {\n"+ 585 " /** @ojb.field primarykey=\"true\" */\n"+ 586 " private int id1;\n"+ 587 " /** @ojb.field primarykey=\"true\" */\n"+ 588 " private String id2;\n"+ 589 " /** @ojb.collection element-class-ref=\"test.B\"\n"+ 590 " * foreignkey=\"aid1,aid2\"\n"+ 591 " */\n"+ 592 " private java.util.List attr;\n"+ 593 "}"); 594 addClass( 595 "test.B", 596 "package test;\n"+ 597 "/** @ojb.class\n"+ 598 " * @ojb.field name=\"aid2\"\n"+ 599 " * jdbc-type=\"VARCHAR\"\n"+ 600 " */\n"+ 601 "public class B {\n"+ 602 " /** @ojb.field id=\"1\" */\n"+ 603 " private int aid1;\n"+ 604 "}\n"); 605 606 assertEqualsOjbDescriptorFile( 607 "<class-descriptor\n"+ 608 " class=\"test.A\"\n"+ 609 " table=\"A\"\n"+ 610 ">\n"+ 611 " <field-descriptor\n"+ 612 " name=\"id1\"\n"+ 613 " column=\"id1\"\n"+ 614 " jdbc-type=\"INTEGER\"\n"+ 615 " primarykey=\"true\"\n"+ 616 " >\n"+ 617 " </field-descriptor>\n"+ 618 " <field-descriptor\n"+ 619 " name=\"id2\"\n"+ 620 " column=\"id2\"\n"+ 621 " jdbc-type=\"VARCHAR\"\n"+ 622 " primarykey=\"true\"\n"+ 623 " length=\"254\"\n"+ 624 " >\n"+ 625 " </field-descriptor>\n"+ 626 " <collection-descriptor\n"+ 627 " name=\"attr\"\n"+ 628 " element-class-ref=\"test.B\"\n"+ 629 " >\n"+ 630 " <inverse-foreignkey field-ref=\"aid1\"/>\n"+ 631 " <inverse-foreignkey field-ref=\"aid2\"/>\n"+ 632 " </collection-descriptor>\n"+ 633 "</class-descriptor>\n"+ 634 "<class-descriptor\n"+ 635 " class=\"test.B\"\n"+ 636 " table=\"B\"\n"+ 637 ">\n"+ 638 " <field-descriptor\n"+ 639 " name=\"aid1\"\n"+ 640 " column=\"aid1\"\n"+ 641 " jdbc-type=\"INTEGER\"\n"+ 642 " >\n"+ 643 " </field-descriptor>\n"+ 644 " <field-descriptor\n"+ 645 " name=\"aid2\"\n"+ 646 " column=\"aid2\"\n"+ 647 " jdbc-type=\"VARCHAR\"\n"+ 648 " length=\"254\"\n"+ 649 " access=\"anonymous\"\n"+ 650 " >\n"+ 651 " </field-descriptor>\n"+ 652 "</class-descriptor>", 653 runOjbXDoclet(OJB_DEST_FILE)); 654 assertEqualsTorqueSchemaFile( 655 "<database name=\"ojbtest\">\n"+ 656 " <table name=\"A\">\n"+ 657 " <column name=\"id1\"\n"+ 658 " javaName=\"id1\"\n"+ 659 " type=\"INTEGER\"\n"+ 660 " primaryKey=\"true\"\n"+ 661 " required=\"true\"\n"+ 662 " />\n"+ 663 " <column name=\"id2\"\n"+ 664 " javaName=\"id2\"\n"+ 665 " type=\"VARCHAR\"\n"+ 666 " primaryKey=\"true\"\n"+ 667 " required=\"true\"\n"+ 668 " size=\"254\"\n"+ 669 " />\n"+ 670 " </table>\n"+ 671 " <table name=\"B\">\n"+ 672 " <column name=\"aid1\"\n"+ 673 " javaName=\"aid1\"\n"+ 674 " type=\"INTEGER\"\n"+ 675 " />\n"+ 676 " <column name=\"aid2\"\n"+ 677 " javaName=\"aid2\"\n"+ 678 " type=\"VARCHAR\"\n"+ 679 " size=\"254\"\n"+ 680 " />\n"+ 681 " <foreign-key foreignTable=\"A\">\n"+ 682 " <reference local=\"aid1\" foreign=\"id1\"/>\n"+ 683 " <reference local=\"aid2\" foreign=\"id2\"/>\n"+ 684 " </foreign-key>\n"+ 685 " </table>\n"+ 686 "</database>", 687 runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 688 } 689 690 public void testForeignkey14() 693 { 694 addClass( 695 "test.A", 696 "package test;\n"+ 697 "/** @ojb.class */\n" + 698 "public class A {\n"+ 699 " /** @ojb.field primarykey=\"true\" */\n"+ 700 " private int id;\n"+ 701 " /** @ojb.collection element-class-ref=\"test.B\"\n"+ 702 " * foreignkey=\"aid\"\n"+ 703 " * database-foreignkey=\"false\"\n"+ 704 " */\n"+ 705 " private java.util.List attr;\n"+ 706 "}"); 707 addClass( 708 "test.B", 709 "package test;\n"+ 710 "/** @ojb.class */\n"+ 711 "public class B {\n"+ 712 " /** @ojb.field */\n"+ 713 " private int aid;\n"+ 714 "}\n"); 715 addClass( 716 "test.C", 717 "package test;\n"+ 718 "/** @ojb.class */\n"+ 719 "public class C extends A {}\n"); 720 721 assertEqualsOjbDescriptorFile( 722 "<class-descriptor\n"+ 723 " class=\"test.A\"\n"+ 724 " table=\"A\"\n"+ 725 ">\n"+ 726 " <extent-class class-ref=\"test.C\"/>\n"+ 727 " <field-descriptor\n"+ 728 " name=\"id\"\n"+ 729 " column=\"id\"\n"+ 730 " jdbc-type=\"INTEGER\"\n"+ 731 " primarykey=\"true\"\n"+ 732 " >\n"+ 733 " </field-descriptor>\n"+ 734 " <collection-descriptor\n"+ 735 " name=\"attr\"\n"+ 736 " element-class-ref=\"test.B\"\n"+ 737 " >\n"+ 738 " <inverse-foreignkey field-ref=\"aid\"/>\n"+ 739 " </collection-descriptor>\n"+ 740 "</class-descriptor>\n"+ 741 "<class-descriptor\n"+ 742 " class=\"test.B\"\n"+ 743 " table=\"B\"\n"+ 744 ">\n"+ 745 " <field-descriptor\n"+ 746 " name=\"aid\"\n"+ 747 " column=\"aid\"\n"+ 748 " jdbc-type=\"INTEGER\"\n"+ 749 " >\n"+ 750 " </field-descriptor>\n"+ 751 "</class-descriptor>\n"+ 752 "<class-descriptor\n"+ 753 " class=\"test.C\"\n"+ 754 " table=\"C\"\n"+ 755 ">\n"+ 756 " <field-descriptor\n"+ 757 " name=\"id\"\n"+ 758 " column=\"id\"\n"+ 759 " jdbc-type=\"INTEGER\"\n"+ 760 " primarykey=\"true\"\n"+ 761 " >\n"+ 762 " </field-descriptor>\n"+ 763 " <collection-descriptor\n"+ 764 " name=\"attr\"\n"+ 765 " element-class-ref=\"test.B\"\n"+ 766 " >\n"+ 767 " <inverse-foreignkey field-ref=\"aid\"/>\n"+ 768 " </collection-descriptor>\n"+ 769 "</class-descriptor>", 770 runOjbXDoclet(OJB_DEST_FILE)); 771 assertEqualsTorqueSchemaFile( 772 "<database name=\"ojbtest\">\n"+ 773 " <table name=\"A\">\n"+ 774 " <column name=\"id\"\n"+ 775 " javaName=\"id\"\n"+ 776 " type=\"INTEGER\"\n"+ 777 " primaryKey=\"true\"\n"+ 778 " required=\"true\"\n"+ 779 " />\n"+ 780 " </table>\n"+ 781 " <table name=\"B\">\n"+ 782 " <column name=\"aid\"\n"+ 783 " javaName=\"aid\"\n"+ 784 " type=\"INTEGER\"\n"+ 785 " />\n"+ 786 " </table>\n"+ 787 " <table name=\"C\">\n"+ 788 " <column name=\"id\"\n"+ 789 " javaName=\"id\"\n"+ 790 " type=\"INTEGER\"\n"+ 791 " primaryKey=\"true\"\n"+ 792 " required=\"true\"\n"+ 793 " />\n"+ 794 " </table>\n"+ 795 "</database>", 796 runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 797 } 798 799 public void testForeignkey15() 801 { 802 addClass( 803 "test.A", 804 "package test;\n"+ 805 "/** @ojb.class */\n" + 806 "public class A {\n"+ 807 " /** @ojb.field primarykey=\"true\" */\n"+ 808 " private int id1;\n"+ 809 " /** @ojb.field primarykey=\"true\" */\n"+ 810 " private String id2;\n"+ 811 " /** @ojb.collection element-class-ref=\"test.B\"\n"+ 812 " * foreignkey=\"aid1,aid2\"\n"+ 813 " */\n"+ 814 " private java.util.List attr;\n"+ 815 "}"); 816 addClass( 817 "test.B", 818 "package test;\n"+ 819 "/** @ojb.class generate-table-info=\"false\" */\n"+ 820 "public interface B {}\n"); 821 addClass( 822 "test.C", 823 "package test;\n"+ 824 "/** @ojb.class */\n"+ 825 "public class C implements B {\n"+ 826 " /** @ojb.field */\n"+ 827 " private int aid1;\n"+ 828 " /** @ojb.field */\n"+ 829 " private String aid2;\n"+ 830 "}\n"); 831 832 assertEqualsOjbDescriptorFile( 833 "<class-descriptor\n"+ 834 " class=\"test.A\"\n"+ 835 " table=\"A\"\n"+ 836 ">\n"+ 837 " <field-descriptor\n"+ 838 " name=\"id1\"\n"+ 839 " column=\"id1\"\n"+ 840 " jdbc-type=\"INTEGER\"\n"+ 841 " primarykey=\"true\"\n"+ 842 " >\n"+ 843 " </field-descriptor>\n"+ 844 " <field-descriptor\n"+ 845 " name=\"id2\"\n"+ 846 " column=\"id2\"\n"+ 847 " jdbc-type=\"VARCHAR\"\n"+ 848 " primarykey=\"true\"\n"+ 849 " length=\"254\"\n"+ 850 " >\n"+ 851 " </field-descriptor>\n"+ 852 " <collection-descriptor\n"+ 853 " name=\"attr\"\n"+ 854 " element-class-ref=\"test.B\"\n"+ 855 " >\n"+ 856 " <inverse-foreignkey field-ref=\"aid1\"/>\n"+ 857 " <inverse-foreignkey field-ref=\"aid2\"/>\n"+ 858 " </collection-descriptor>\n"+ 859 "</class-descriptor>\n"+ 860 "<class-descriptor\n"+ 861 " class=\"test.B\"\n"+ 862 ">\n"+ 863 " <extent-class class-ref=\"test.C\"/>\n"+ 864 " <field-descriptor\n"+ 865 " name=\"aid1\"\n"+ 866 " column=\"aid1\"\n"+ 867 " jdbc-type=\"INTEGER\"\n"+ 868 " >\n"+ 869 " </field-descriptor>\n"+ 870 " <field-descriptor\n"+ 871 " name=\"aid2\"\n"+ 872 " column=\"aid2\"\n"+ 873 " jdbc-type=\"VARCHAR\"\n"+ 874 " length=\"254\"\n"+ 875 " >\n"+ 876 " </field-descriptor>\n"+ 877 "</class-descriptor>\n"+ 878 "<class-descriptor\n"+ 879 " class=\"test.C\"\n"+ 880 " table=\"C\"\n"+ 881 ">\n"+ 882 " <field-descriptor\n"+ 883 " name=\"aid1\"\n"+ 884 " column=\"aid1\"\n"+ 885 " jdbc-type=\"INTEGER\"\n"+ 886 " >\n"+ 887 " </field-descriptor>\n"+ 888 " <field-descriptor\n"+ 889 " name=\"aid2\"\n"+ 890 " column=\"aid2\"\n"+ 891 " jdbc-type=\"VARCHAR\"\n"+ 892 " length=\"254\"\n"+ 893 " >\n"+ 894 " </field-descriptor>\n"+ 895 "</class-descriptor>", 896 runOjbXDoclet(OJB_DEST_FILE)); 897 assertEqualsTorqueSchemaFile( 898 "<database name=\"ojbtest\">\n"+ 899 " <table name=\"A\">\n"+ 900 " <column name=\"id1\"\n"+ 901 " javaName=\"id1\"\n"+ 902 " type=\"INTEGER\"\n"+ 903 " primaryKey=\"true\"\n"+ 904 " required=\"true\"\n"+ 905 " />\n"+ 906 " <column name=\"id2\"\n"+ 907 " javaName=\"id2\"\n"+ 908 " type=\"VARCHAR\"\n"+ 909 " primaryKey=\"true\"\n"+ 910 " required=\"true\"\n"+ 911 " size=\"254\"\n"+ 912 " />\n"+ 913 " </table>\n"+ 914 " <table name=\"C\">\n"+ 915 " <column name=\"aid1\"\n"+ 916 " javaName=\"aid1\"\n"+ 917 " type=\"INTEGER\"\n"+ 918 " />\n"+ 919 " <column name=\"aid2\"\n"+ 920 " javaName=\"aid2\"\n"+ 921 " type=\"VARCHAR\"\n"+ 922 " size=\"254\"\n"+ 923 " />\n"+ 924 " <foreign-key foreignTable=\"A\">\n"+ 925 " <reference local=\"aid1\" foreign=\"id1\"/>\n"+ 926 " <reference local=\"aid2\" foreign=\"id2\"/>\n"+ 927 " </foreign-key>\n"+ 928 " </table>\n"+ 929 "</database>", 930 runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 931 } 932 933 public void testForeignkey16() 935 { 936 addClass( 937 "test.A", 938 "package test;\n"+ 939 "/** @ojb.class */\n" + 940 "public class A {\n"+ 941 " /** @ojb.field primarykey=\"true\" */\n"+ 942 " private int id;\n"+ 943 " /** @ojb.collection element-class-ref=\"test.B\"\n"+ 944 " * foreignkey=\"aid\"\n"+ 945 " */\n"+ 946 " private java.util.List attr;\n"+ 947 "}"); 948 addClass( 949 "test.B", 950 "package test;\n"+ 951 "/** @ojb.class generate-table-info=\"false\" */\n"+ 952 "public interface B {}\n"); 953 addClass( 954 "test.C", 955 "package test;\n"+ 956 "/** @ojb.class */\n"+ 957 "public class C implements B {\n"+ 958 " /** @ojb.field */\n"+ 959 " private int aid;\n"+ 960 "}\n"); 961 addClass( 962 "test.D", 963 "package test;\n"+ 964 "/** @ojb.class */\n"+ 965 "public class D implements B {\n"+ 966 " /** @ojb.field */\n"+ 967 " private String aid;\n"+ 968 "}\n"); 969 970 assertNull(runOjbXDoclet(OJB_DEST_FILE)); 971 assertNull(runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 972 } 973 974 public void testForeignkey17() 976 { 977 addClass( 978 "test.A", 979 "package test;\n"+ 980 "/** @ojb.class */\n" + 981 "public class A {\n"+ 982 " /** @ojb.field primarykey=\"true\" */\n"+ 983 " private int id;\n"+ 984 " /** @ojb.collection element-class-ref=\"test.B\"\n"+ 985 " * foreignkey=\"aid\"\n"+ 986 " */\n"+ 987 " private java.util.List attr;\n"+ 988 "}"); 989 addClass( 990 "test.B", 991 "package test;\n"+ 992 "/** @ojb.class generate-table-info=\"false\" */\n"+ 993 "public interface B {}\n"); 994 addClass( 995 "test.C", 996 "package test;\n"+ 997 "/** @ojb.class */\n"+ 998 "public class C implements B {\n"+ 999 " /** @ojb.field */\n"+ 1000 " private int bid;\n"+ 1001 "}\n"); 1002 1003 assertNull(runOjbXDoclet(OJB_DEST_FILE)); 1004 assertNull(runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 1005 } 1006 1007 public void testForeignkey18() 1009 { 1010 addClass( 1011 "test.A", 1012 "package test;\n"+ 1013 "/** @ojb.class */\n" + 1014 "public class A {\n"+ 1015 " /** @ojb.field primarykey=\"true\" */\n"+ 1016 " private int id;\n"+ 1017 " /** @ojb.field length=\"256\" */\n"+ 1018 " private String ojbConcreteClass;\n"+ 1019 " /** @ojb.collection element-class-ref=\"test.B\"\n"+ 1020 " * foreignkey=\"aid\"\n"+ 1021 " */\n"+ 1022 " private java.util.List attr;\n"+ 1023 "}"); 1024 addClass( 1025 "test.B", 1026 "package test;\n"+ 1027 "/** @ojb.class */\n"+ 1028 "public class B {\n"+ 1029 " /** @ojb.field */\n"+ 1030 " private int aid;\n"+ 1031 "}\n"); 1032 addClass( 1033 "test.C", 1034 "package test;\n"+ 1035 "/** @ojb.class table=\"A\" */\n"+ 1036 "public class C extends A {}\n"); 1037 1038 assertEqualsOjbDescriptorFile( 1039 "<class-descriptor\n"+ 1040 " class=\"test.A\"\n"+ 1041 " table=\"A\"\n"+ 1042 ">\n"+ 1043 " <extent-class class-ref=\"test.C\"/>\n"+ 1044 " <field-descriptor\n"+ 1045 " name=\"id\"\n"+ 1046 " column=\"id\"\n"+ 1047 " jdbc-type=\"INTEGER\"\n"+ 1048 " primarykey=\"true\"\n"+ 1049 " >\n"+ 1050 " </field-descriptor>\n"+ 1051 " <field-descriptor\n"+ 1052 " name=\"ojbConcreteClass\"\n"+ 1053 " column=\"ojbConcreteClass\"\n"+ 1054 " jdbc-type=\"VARCHAR\"\n"+ 1055 " length=\"256\"\n"+ 1056 " >\n"+ 1057 " </field-descriptor>\n"+ 1058 " <collection-descriptor\n"+ 1059 " name=\"attr\"\n"+ 1060 " element-class-ref=\"test.B\"\n"+ 1061 " >\n"+ 1062 " <inverse-foreignkey field-ref=\"aid\"/>\n"+ 1063 " </collection-descriptor>\n"+ 1064 "</class-descriptor>\n"+ 1065 "<class-descriptor\n"+ 1066 " class=\"test.B\"\n"+ 1067 " table=\"B\"\n"+ 1068 ">\n"+ 1069 " <field-descriptor\n"+ 1070 " name=\"aid\"\n"+ 1071 " column=\"aid\"\n"+ 1072 " jdbc-type=\"INTEGER\"\n"+ 1073 " >\n"+ 1074 " </field-descriptor>\n"+ 1075 "</class-descriptor>\n"+ 1076 "<class-descriptor\n"+ 1077 " class=\"test.C\"\n"+ 1078 " table=\"A\"\n"+ 1079 ">\n"+ 1080 " <field-descriptor\n"+ 1081 " name=\"id\"\n"+ 1082 " column=\"id\"\n"+ 1083 " jdbc-type=\"INTEGER\"\n"+ 1084 " primarykey=\"true\"\n"+ 1085 " >\n"+ 1086 " </field-descriptor>\n"+ 1087 " <field-descriptor\n"+ 1088 " name=\"ojbConcreteClass\"\n"+ 1089 " column=\"ojbConcreteClass\"\n"+ 1090 " jdbc-type=\"VARCHAR\"\n"+ 1091 " length=\"256\"\n"+ 1092 " >\n"+ 1093 " </field-descriptor>\n"+ 1094 " <collection-descriptor\n"+ 1095 " name=\"attr\"\n"+ 1096 " element-class-ref=\"test.B\"\n"+ 1097 " >\n"+ 1098 " <inverse-foreignkey field-ref=\"aid\"/>\n"+ 1099 " </collection-descriptor>\n"+ 1100 "</class-descriptor>", 1101 runOjbXDoclet(OJB_DEST_FILE)); 1102 assertEqualsTorqueSchemaFile( 1103 "<database name=\"ojbtest\">\n"+ 1104 " <table name=\"A\">\n"+ 1105 " <column name=\"id\"\n"+ 1106 " javaName=\"id\"\n"+ 1107 " type=\"INTEGER\"\n"+ 1108 " primaryKey=\"true\"\n"+ 1109 " required=\"true\"\n"+ 1110 " />\n"+ 1111 " <column name=\"ojbConcreteClass\"\n"+ 1112 " javaName=\"ojbConcreteClass\"\n"+ 1113 " type=\"VARCHAR\"\n"+ 1114 " size=\"256\"\n"+ 1115 " />\n"+ 1116 " </table>\n"+ 1117 " <table name=\"B\">\n"+ 1118 " <column name=\"aid\"\n"+ 1119 " javaName=\"aid\"\n"+ 1120 " type=\"INTEGER\"\n"+ 1121 " />\n"+ 1122 " <foreign-key foreignTable=\"A\">\n"+ 1123 " <reference local=\"aid\" foreign=\"id\"/>\n"+ 1124 " </foreign-key>\n"+ 1125 " </table>\n"+ 1126 "</database>", 1127 runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 1128 } 1129 1130 public void testForeignkey19() 1132 { 1133 addClass( 1134 "test.A", 1135 "package test;\n"+ 1136 "/** @ojb.class */\n" + 1137 "public class A {\n"+ 1138 " /** @ojb.field primarykey=\"true\" */\n"+ 1139 " private int id1;\n"+ 1140 " /** @ojb.field primarykey=\"true\" */\n"+ 1141 " private String id2;\n"+ 1142 " /** @ojb.collection element-class-ref=\"test.B\"\n"+ 1143 " * foreignkey=\"aid1,aid2\"\n"+ 1144 " */\n"+ 1145 " private java.util.List attr;\n"+ 1146 "}"); 1147 addClass( 1148 "test.B", 1149 "package test;\n"+ 1150 "/** @ojb.class */\n"+ 1151 "public class B {\n"+ 1152 " /** @ojb.field */\n"+ 1153 " private int aid1;\n"+ 1154 " /** @ojb.field */\n"+ 1155 " private String aid2;\n"+ 1156 "}\n"); 1157 addClass( 1158 "test.C", 1159 "package test;\n"+ 1160 "/** @ojb.class */\n"+ 1161 "public class C extends B {}\n"); 1162 1163 assertEqualsOjbDescriptorFile( 1164 "<class-descriptor\n"+ 1165 " class=\"test.A\"\n"+ 1166 " table=\"A\"\n"+ 1167 ">\n"+ 1168 " <field-descriptor\n"+ 1169 " name=\"id1\"\n"+ 1170 " column=\"id1\"\n"+ 1171 " jdbc-type=\"INTEGER\"\n"+ 1172 " primarykey=\"true\"\n"+ 1173 " >\n"+ 1174 " </field-descriptor>\n"+ 1175 " <field-descriptor\n"+ 1176 " name=\"id2\"\n"+ 1177 " column=\"id2\"\n"+ 1178 " jdbc-type=\"VARCHAR\"\n"+ 1179 " primarykey=\"true\"\n"+ 1180 " length=\"254\"\n"+ 1181 " >\n"+ 1182 " </field-descriptor>\n"+ 1183 " <collection-descriptor\n"+ 1184 " name=\"attr\"\n"+ 1185 " element-class-ref=\"test.B\"\n"+ 1186 " >\n"+ 1187 " <inverse-foreignkey field-ref=\"aid1\"/>\n"+ 1188 " <inverse-foreignkey field-ref=\"aid2\"/>\n"+ 1189 " </collection-descriptor>\n"+ 1190 "</class-descriptor>\n"+ 1191 "<class-descriptor\n"+ 1192 " class=\"test.B\"\n"+ 1193 " table=\"B\"\n"+ 1194 ">\n"+ 1195 " <extent-class class-ref=\"test.C\"/>\n"+ 1196 " <field-descriptor\n"+ 1197 " name=\"aid1\"\n"+ 1198 " column=\"aid1\"\n"+ 1199 " jdbc-type=\"INTEGER\"\n"+ 1200 " >\n"+ 1201 " </field-descriptor>\n"+ 1202 " <field-descriptor\n"+ 1203 " name=\"aid2\"\n"+ 1204 " column=\"aid2\"\n"+ 1205 " jdbc-type=\"VARCHAR\"\n"+ 1206 " length=\"254\"\n"+ 1207 " >\n"+ 1208 " </field-descriptor>\n"+ 1209 "</class-descriptor>\n"+ 1210 "<class-descriptor\n"+ 1211 " class=\"test.C\"\n"+ 1212 " table=\"C\"\n"+ 1213 ">\n"+ 1214 " <field-descriptor\n"+ 1215 " name=\"aid1\"\n"+ 1216 " column=\"aid1\"\n"+ 1217 " jdbc-type=\"INTEGER\"\n"+ 1218 " >\n"+ 1219 " </field-descriptor>\n"+ 1220 " <field-descriptor\n"+ 1221 " name=\"aid2\"\n"+ 1222 " column=\"aid2\"\n"+ 1223 " jdbc-type=\"VARCHAR\"\n"+ 1224 " length=\"254\"\n"+ 1225 " >\n"+ 1226 " </field-descriptor>\n"+ 1227 "</class-descriptor>", 1228 runOjbXDoclet(OJB_DEST_FILE)); 1229 assertEqualsTorqueSchemaFile( 1230 "<database name=\"ojbtest\">\n"+ 1231 " <table name=\"A\">\n"+ 1232 " <column name=\"id1\"\n"+ 1233 " javaName=\"id1\"\n"+ 1234 " type=\"INTEGER\"\n"+ 1235 " primaryKey=\"true\"\n"+ 1236 " required=\"true\"\n"+ 1237 " />\n"+ 1238 " <column name=\"id2\"\n"+ 1239 " javaName=\"id2\"\n"+ 1240 " type=\"VARCHAR\"\n"+ 1241 " primaryKey=\"true\"\n"+ 1242 " required=\"true\"\n"+ 1243 " size=\"254\"\n"+ 1244 " />\n"+ 1245 " </table>\n"+ 1246 " <table name=\"B\">\n"+ 1247 " <column name=\"aid1\"\n"+ 1248 " javaName=\"aid1\"\n"+ 1249 " type=\"INTEGER\"\n"+ 1250 " />\n"+ 1251 " <column name=\"aid2\"\n"+ 1252 " javaName=\"aid2\"\n"+ 1253 " type=\"VARCHAR\"\n"+ 1254 " size=\"254\"\n"+ 1255 " />\n"+ 1256 " <foreign-key foreignTable=\"A\">\n"+ 1257 " <reference local=\"aid1\" foreign=\"id1\"/>\n"+ 1258 " <reference local=\"aid2\" foreign=\"id2\"/>\n"+ 1259 " </foreign-key>\n"+ 1260 " </table>\n"+ 1261 " <table name=\"C\">\n"+ 1262 " <column name=\"aid1\"\n"+ 1263 " javaName=\"aid1\"\n"+ 1264 " type=\"INTEGER\"\n"+ 1265 " />\n"+ 1266 " <column name=\"aid2\"\n"+ 1267 " javaName=\"aid2\"\n"+ 1268 " type=\"VARCHAR\"\n"+ 1269 " size=\"254\"\n"+ 1270 " />\n"+ 1271 " <foreign-key foreignTable=\"A\">\n"+ 1272 " <reference local=\"aid1\" foreign=\"id1\"/>\n"+ 1273 " <reference local=\"aid2\" foreign=\"id2\"/>\n"+ 1274 " </foreign-key>\n"+ 1275 " </table>\n"+ 1276 "</database>", 1277 runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 1278 } 1279 1280 public void testForeignkey20() 1282 { 1283 addClass( 1284 "test.A", 1285 "package test;\n"+ 1286 "/** @ojb.class */\n" + 1287 "public class A {\n"+ 1288 " /** @ojb.field primarykey=\"true\" */\n"+ 1289 " private int id;\n"+ 1290 " /** @ojb.collection element-class-ref=\"test.B\"\n"+ 1291 " * foreignkey=\"aid\"\n"+ 1292 " * database-foreignkey=\"true\"\n"+ 1293 " */\n"+ 1294 " private java.util.List attr;\n"+ 1295 "}"); 1296 addClass( 1297 "test.B", 1298 "package test;\n"+ 1299 "/** @ojb.class */\n"+ 1300 "public class B {\n"+ 1301 " /** @ojb.field */\n"+ 1302 " private int aid;\n"+ 1303 " /** @ojb.reference foreignkey=\"aid\" */\n"+ 1304 " private A a;\n"+ 1305 "}\n"); 1306 1307 assertEqualsOjbDescriptorFile( 1308 "<class-descriptor\n"+ 1309 " class=\"test.A\"\n"+ 1310 " table=\"A\"\n"+ 1311 ">\n"+ 1312 " <field-descriptor\n"+ 1313 " name=\"id\"\n"+ 1314 " column=\"id\"\n"+ 1315 " jdbc-type=\"INTEGER\"\n"+ 1316 " primarykey=\"true\"\n"+ 1317 " >\n"+ 1318 " </field-descriptor>\n"+ 1319 " <collection-descriptor\n"+ 1320 " name=\"attr\"\n"+ 1321 " element-class-ref=\"test.B\"\n"+ 1322 " >\n"+ 1323 " <inverse-foreignkey field-ref=\"aid\"/>\n"+ 1324 " </collection-descriptor>\n"+ 1325 "</class-descriptor>\n"+ 1326 "<class-descriptor\n"+ 1327 " class=\"test.B\"\n"+ 1328 " table=\"B\"\n"+ 1329 ">\n"+ 1330 " <field-descriptor\n"+ 1331 " name=\"aid\"\n"+ 1332 " column=\"aid\"\n"+ 1333 " jdbc-type=\"INTEGER\"\n"+ 1334 " >\n"+ 1335 " </field-descriptor>\n"+ 1336 " <reference-descriptor\n"+ 1337 " name=\"a\"\n"+ 1338 " class-ref=\"test.A\"\n"+ 1339 " >\n"+ 1340 " <foreignkey field-ref=\"aid\"/>\n"+ 1341 " </reference-descriptor>\n"+ 1342 "</class-descriptor>", 1343 runOjbXDoclet(OJB_DEST_FILE)); 1344 assertEqualsTorqueSchemaFile( 1345 "<database name=\"ojbtest\">\n"+ 1346 " <table name=\"A\">\n"+ 1347 " <column name=\"id\"\n"+ 1348 " javaName=\"id\"\n"+ 1349 " type=\"INTEGER\"\n"+ 1350 " primaryKey=\"true\"\n"+ 1351 " required=\"true\"\n"+ 1352 " />\n"+ 1353 " </table>\n"+ 1354 " <table name=\"B\">\n"+ 1355 " <column name=\"aid\"\n"+ 1356 " javaName=\"aid\"\n"+ 1357 " type=\"INTEGER\"\n"+ 1358 " />\n"+ 1359 " <foreign-key foreignTable=\"A\">\n"+ 1360 " <reference local=\"aid\" foreign=\"id\"/>\n"+ 1361 " </foreign-key>\n"+ 1362 " </table>\n"+ 1363 "</database>", 1364 runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 1365 } 1366 1367 public void testForeignkey21() 1369 { 1370 addClass( 1371 "test.A", 1372 "package test;\n"+ 1373 "/** @ojb.class */\n" + 1374 "public class A {\n"+ 1375 " /** @ojb.field primarykey=\"true\" */\n"+ 1376 " private int id;\n"+ 1377 " /** @ojb.collection element-class-ref=\"test.C\"\n"+ 1378 " * foreignkey=\"aid\"\n"+ 1379 " */\n"+ 1380 " private java.util.List attr;\n"+ 1381 "}"); 1382 addClass( 1383 "test.B", 1384 "package test;\n"+ 1385 "/** @ojb.class */\n"+ 1386 "public class B extends A {}\n"); 1387 addClass( 1388 "test.C", 1389 "package test;\n"+ 1390 "/** @ojb.class */\n"+ 1391 "public class C {\n"+ 1392 " /** @ojb.field */\n"+ 1393 " private int aid;\n"+ 1394 "}\n"); 1395 1396 assertEqualsOjbDescriptorFile( 1397 "<class-descriptor\n"+ 1398 " class=\"test.A\"\n"+ 1399 " table=\"A\"\n"+ 1400 ">\n"+ 1401 " <extent-class class-ref=\"test.B\"/>\n"+ 1402 " <field-descriptor\n"+ 1403 " name=\"id\"\n"+ 1404 " column=\"id\"\n"+ 1405 " jdbc-type=\"INTEGER\"\n"+ 1406 " primarykey=\"true\"\n"+ 1407 " >\n"+ 1408 " </field-descriptor>\n"+ 1409 " <collection-descriptor\n"+ 1410 " name=\"attr\"\n"+ 1411 " element-class-ref=\"test.C\"\n"+ 1412 " >\n"+ 1413 " <inverse-foreignkey field-ref=\"aid\"/>\n"+ 1414 " </collection-descriptor>\n"+ 1415 "</class-descriptor>\n"+ 1416 "<class-descriptor\n"+ 1417 " class=\"test.B\"\n"+ 1418 " table=\"B\"\n"+ 1419 ">\n"+ 1420 " <field-descriptor\n"+ 1421 " name=\"id\"\n"+ 1422 " column=\"id\"\n"+ 1423 " jdbc-type=\"INTEGER\"\n"+ 1424 " primarykey=\"true\"\n"+ 1425 " >\n"+ 1426 " </field-descriptor>\n"+ 1427 " <collection-descriptor\n"+ 1428 " name=\"attr\"\n"+ 1429 " element-class-ref=\"test.C\"\n"+ 1430 " >\n"+ 1431 " <inverse-foreignkey field-ref=\"aid\"/>\n"+ 1432 " </collection-descriptor>\n"+ 1433 "</class-descriptor>\n"+ 1434 "<class-descriptor\n"+ 1435 " class=\"test.C\"\n"+ 1436 " table=\"C\"\n"+ 1437 ">\n"+ 1438 " <field-descriptor\n"+ 1439 " name=\"aid\"\n"+ 1440 " column=\"aid\"\n"+ 1441 " jdbc-type=\"INTEGER\"\n"+ 1442 " >\n"+ 1443 " </field-descriptor>\n"+ 1444 "</class-descriptor>", 1445 runOjbXDoclet(OJB_DEST_FILE)); 1446 assertEqualsTorqueSchemaFile( 1447 "<database name=\"ojbtest\">\n"+ 1448 " <table name=\"A\">\n"+ 1449 " <column name=\"id\"\n"+ 1450 " javaName=\"id\"\n"+ 1451 " type=\"INTEGER\"\n"+ 1452 " primaryKey=\"true\"\n"+ 1453 " required=\"true\"\n"+ 1454 " />\n"+ 1455 " </table>\n"+ 1456 " <table name=\"B\">\n"+ 1457 " <column name=\"id\"\n"+ 1458 " javaName=\"id\"\n"+ 1459 " type=\"INTEGER\"\n"+ 1460 " primaryKey=\"true\"\n"+ 1461 " required=\"true\"\n"+ 1462 " />\n"+ 1463 " </table>\n"+ 1464 " <table name=\"C\">\n"+ 1465 " <column name=\"aid\"\n"+ 1466 " javaName=\"aid\"\n"+ 1467 " type=\"INTEGER\"\n"+ 1468 " />\n"+ 1469 " </table>\n"+ 1470 "</database>", 1471 runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 1472 } 1473 1474 public void testForeignkey22() 1476 { 1477 addClass( 1478 "test.A", 1479 "package test;\n"+ 1480 "/** @ojb.class */\n" + 1481 "public class A {\n"+ 1482 " /** @ojb.field primarykey=\"true\" */\n"+ 1483 " private int id;\n"+ 1484 " /** @ojb.collection element-class-ref=\"test.C\"\n"+ 1485 " * foreignkey=\"aid\"\n"+ 1486 " */\n"+ 1487 " private java.util.List attr;\n"+ 1488 "}"); 1489 addClass( 1490 "test.B", 1491 "package test;\n"+ 1492 "/** @ojb.class */\n"+ 1493 "public class B extends A {}\n"); 1494 addClass( 1495 "test.C", 1496 "package test;\n"+ 1497 "/** @ojb.class generate-repository-info=\"false\" */\n"+ 1498 "public interface C {}\n"); 1499 addClass( 1500 "test.D", 1501 "package test;\n"+ 1502 "/** @ojb.class */\n"+ 1503 "public class D implements C {\n"+ 1504 " /** @ojb.field */\n"+ 1505 " private int aid;\n"+ 1506 "}\n"); 1507 1508 assertEqualsOjbDescriptorFile( 1509 "<class-descriptor\n"+ 1510 " class=\"test.A\"\n"+ 1511 " table=\"A\"\n"+ 1512 ">\n"+ 1513 " <extent-class class-ref=\"test.B\"/>\n"+ 1514 " <field-descriptor\n"+ 1515 " name=\"id\"\n"+ 1516 " column=\"id\"\n"+ 1517 " jdbc-type=\"INTEGER\"\n"+ 1518 " primarykey=\"true\"\n"+ 1519 " >\n"+ 1520 " </field-descriptor>\n"+ 1521 " <collection-descriptor\n"+ 1522 " name=\"attr\"\n"+ 1523 " element-class-ref=\"test.C\"\n"+ 1524 " >\n"+ 1525 " <inverse-foreignkey field-ref=\"aid\"/>\n"+ 1526 " </collection-descriptor>\n"+ 1527 "</class-descriptor>\n"+ 1528 "<class-descriptor\n"+ 1529 " class=\"test.B\"\n"+ 1530 " table=\"B\"\n"+ 1531 ">\n"+ 1532 " <field-descriptor\n"+ 1533 " name=\"id\"\n"+ 1534 " column=\"id\"\n"+ 1535 " jdbc-type=\"INTEGER\"\n"+ 1536 " primarykey=\"true\"\n"+ 1537 " >\n"+ 1538 " </field-descriptor>\n"+ 1539 " <collection-descriptor\n"+ 1540 " name=\"attr\"\n"+ 1541 " element-class-ref=\"test.C\"\n"+ 1542 " >\n"+ 1543 " <inverse-foreignkey field-ref=\"aid\"/>\n"+ 1544 " </collection-descriptor>\n"+ 1545 "</class-descriptor>\n"+ 1546 "<class-descriptor\n"+ 1547 " class=\"test.C\"\n"+ 1548 ">\n"+ 1549 " <extent-class class-ref=\"test.D\"/>\n"+ 1550 " <field-descriptor\n"+ 1551 " name=\"aid\"\n"+ 1552 " column=\"aid\"\n"+ 1553 " jdbc-type=\"INTEGER\"\n"+ 1554 " >\n"+ 1555 " </field-descriptor>\n"+ 1556 "</class-descriptor>\n"+ 1557 "<class-descriptor\n"+ 1558 " class=\"test.D\"\n"+ 1559 " table=\"D\"\n"+ 1560 ">\n"+ 1561 " <field-descriptor\n"+ 1562 " name=\"aid\"\n"+ 1563 " column=\"aid\"\n"+ 1564 " jdbc-type=\"INTEGER\"\n"+ 1565 " >\n"+ 1566 " </field-descriptor>\n"+ 1567 "</class-descriptor>", 1568 runOjbXDoclet(OJB_DEST_FILE)); 1569 assertEqualsTorqueSchemaFile( 1570 "<database name=\"ojbtest\">\n"+ 1571 " <table name=\"A\">\n"+ 1572 " <column name=\"id\"\n"+ 1573 " javaName=\"id\"\n"+ 1574 " type=\"INTEGER\"\n"+ 1575 " primaryKey=\"true\"\n"+ 1576 " required=\"true\"\n"+ 1577 " />\n"+ 1578 " </table>\n"+ 1579 " <table name=\"B\">\n"+ 1580 " <column name=\"id\"\n"+ 1581 " javaName=\"id\"\n"+ 1582 " type=\"INTEGER\"\n"+ 1583 " primaryKey=\"true\"\n"+ 1584 " required=\"true\"\n"+ 1585 " />\n"+ 1586 " </table>\n"+ 1587 " <table name=\"D\">\n"+ 1588 " <column name=\"aid\"\n"+ 1589 " javaName=\"aid\"\n"+ 1590 " type=\"INTEGER\"\n"+ 1591 " />\n"+ 1592 " </table>\n"+ 1593 "</database>", 1594 runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 1595 } 1596} 1597 | Popular Tags |