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