1 package xdoclet.modules.ojb.tests; 2 3 17 18 23 public class CollectionTagIndirectionTablePrimarykeysAttributeTests extends OjbTestBase 24 { 25 public CollectionTagIndirectionTablePrimarykeysAttributeTests(String name) 26 { 27 super(name); 28 } 29 30 public void testIndirectionTable1() 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 foreignkey=\"AID\"\n"+ 41 " * indirection-table=\"A_B\"\n"+ 42 " * indirection-table-primarykeys=\"true\"\n"+ 43 " */\n"+ 44 " private B[] bs;\n"+ 45 "}"); 46 addClass( 47 "test.B", 48 "package test;\n"+ 49 "/** @ojb.class\n"+ 50 " * @ojb.field name=\"id\"\n"+ 51 " * jdbc-type=\"INTEGER\"\n"+ 52 " * primarykey=\"true\"\n"+ 53 " */\n"+ 54 "public class B {\n"+ 55 " /** @ojb.collection element-class-ref=\"test.A\"\n"+ 56 " * foreignkey=\"BID\"\n"+ 57 " * indirection-table=\"A_B\"\n"+ 58 " */\n"+ 59 " private org.apache.ojb.odmg.collections.DListImpl as;\n"+ 60 "}\n"); 61 62 assertEqualsOjbDescriptorFile( 63 "<class-descriptor\n"+ 64 " class=\"test.A\"\n"+ 65 " table=\"A\"\n"+ 66 ">\n"+ 67 " <field-descriptor\n"+ 68 " name=\"id\"\n"+ 69 " column=\"id\"\n"+ 70 " jdbc-type=\"INTEGER\"\n"+ 71 " primarykey=\"true\"\n"+ 72 " >\n"+ 73 " </field-descriptor>\n"+ 74 " <collection-descriptor\n"+ 75 " name=\"bs\"\n"+ 76 " element-class-ref=\"test.B\"\n"+ 77 " indirection-table=\"A_B\"\n"+ 78 " >\n"+ 79 " <fk-pointing-to-this-class column=\"AID\"/>\n"+ 80 " <fk-pointing-to-element-class column=\"BID\"/>\n"+ 81 " </collection-descriptor>\n"+ 82 "</class-descriptor>\n"+ 83 "<class-descriptor\n"+ 84 " class=\"test.B\"\n"+ 85 " table=\"B\"\n"+ 86 ">\n"+ 87 " <field-descriptor\n"+ 88 " name=\"id\"\n"+ 89 " column=\"id\"\n"+ 90 " jdbc-type=\"INTEGER\"\n"+ 91 " primarykey=\"true\"\n"+ 92 " access=\"anonymous\"\n"+ 93 " >\n"+ 94 " </field-descriptor>\n"+ 95 " <collection-descriptor\n"+ 96 " name=\"as\"\n"+ 97 " collection-class=\"org.apache.ojb.odmg.collections.DListImpl\"\n"+ 98 " element-class-ref=\"test.A\"\n"+ 99 " indirection-table=\"A_B\"\n"+ 100 " >\n"+ 101 " <fk-pointing-to-this-class column=\"BID\"/>\n"+ 102 " <fk-pointing-to-element-class column=\"AID\"/>\n"+ 103 " </collection-descriptor>\n"+ 104 "</class-descriptor>", 105 runOjbXDoclet(OJB_DEST_FILE)); 106 assertEqualsTorqueSchemaFile( 107 "<database name=\"ojbtest\">\n"+ 108 " <table name=\"A\">\n"+ 109 " <column name=\"id\"\n"+ 110 " javaName=\"id\"\n"+ 111 " type=\"INTEGER\"\n"+ 112 " primaryKey=\"true\"\n"+ 113 " required=\"true\"\n"+ 114 " />\n"+ 115 " </table>\n"+ 116 " <table name=\"A_B\">\n"+ 117 " <column name=\"AID\"\n"+ 118 " type=\"INTEGER\"\n"+ 119 " primaryKey=\"true\"\n"+ 120 " required=\"true\"\n"+ 121 " />\n"+ 122 " <column name=\"BID\"\n"+ 123 " type=\"INTEGER\"\n"+ 124 " primaryKey=\"true\"\n"+ 125 " required=\"true\"\n"+ 126 " />\n"+ 127 " <foreign-key foreignTable=\"A\">\n"+ 128 " <reference local=\"AID\" foreign=\"id\"/>\n"+ 129 " </foreign-key>\n"+ 130 " <foreign-key foreignTable=\"B\">\n"+ 131 " <reference local=\"BID\" foreign=\"id\"/>\n"+ 132 " </foreign-key>\n"+ 133 " </table>\n"+ 134 " <table name=\"B\">\n"+ 135 " <column name=\"id\"\n"+ 136 " javaName=\"id\"\n"+ 137 " type=\"INTEGER\"\n"+ 138 " primaryKey=\"true\"\n"+ 139 " required=\"true\"\n"+ 140 " />\n"+ 141 " </table>\n"+ 142 "</database>", 143 runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 144 } 145 146 public void testIndirectionTable2() 148 { 149 addClass( 150 "test.A", 151 "package test;\n"+ 152 "/** @ojb.class */\n" + 153 "public class A {\n"+ 154 " /** @ojb.field primarykey=\"true\" */\n"+ 155 " private org.apache.ojb.broker.util.GUID id;\n"+ 156 " /** @ojb.collection element-class-ref=\"test.B\"\n"+ 157 " * foreignkey=\"AID\"\n"+ 158 " * indirection-table=\"A_B\"\n"+ 159 " * indirection-table-primarykeys=\"true\"\n"+ 160 " */\n"+ 161 " private java.util.List bs;\n"+ 162 "}"); 163 addClass( 164 "test.B", 165 "package test;\n"+ 166 "/** @ojb.class */\n"+ 167 "public class B {\n"+ 168 " /** @ojb.field primarykey=\"true\" */\n"+ 169 " private java.util.Date id;\n"+ 170 " /** @ojb.collection element-class-ref=\"test.A\"\n"+ 171 " * foreignkey=\"BID\"\n"+ 172 " * indirection-table=\"A_B\"\n"+ 173 " * indirection-table-primarykeys=\"false\"\n"+ 174 " */\n"+ 175 " private "+TestCollectionClass.class.getName()+" as;\n"+ 176 "}\n"); 177 178 assertEqualsOjbDescriptorFile( 179 "<class-descriptor\n"+ 180 " class=\"test.A\"\n"+ 181 " table=\"A\"\n"+ 182 ">\n"+ 183 " <field-descriptor\n"+ 184 " name=\"id\"\n"+ 185 " column=\"id\"\n"+ 186 " jdbc-type=\"VARCHAR\"\n"+ 187 " primarykey=\"true\"\n"+ 188 " conversion=\"org.apache.ojb.broker.accesslayer.conversions.GUID2StringFieldConversion\"\n"+ 189 " length=\"254\"\n"+ 190 " >\n"+ 191 " </field-descriptor>\n"+ 192 " <collection-descriptor\n"+ 193 " name=\"bs\"\n"+ 194 " element-class-ref=\"test.B\"\n"+ 195 " indirection-table=\"A_B\"\n"+ 196 " >\n"+ 197 " <fk-pointing-to-this-class column=\"AID\"/>\n"+ 198 " <fk-pointing-to-element-class column=\"BID\"/>\n"+ 199 " </collection-descriptor>\n"+ 200 "</class-descriptor>\n"+ 201 "<class-descriptor\n"+ 202 " class=\"test.B\"\n"+ 203 " table=\"B\"\n"+ 204 ">\n"+ 205 " <field-descriptor\n"+ 206 " name=\"id\"\n"+ 207 " column=\"id\"\n"+ 208 " jdbc-type=\"DATE\"\n"+ 209 " primarykey=\"true\"\n"+ 210 " >\n"+ 211 " </field-descriptor>\n"+ 212 " <collection-descriptor\n"+ 213 " name=\"as\"\n"+ 214 " collection-class=\""+TestCollectionClass.class.getName()+"\"\n"+ 215 " element-class-ref=\"test.A\"\n"+ 216 " indirection-table=\"A_B\"\n"+ 217 " >\n"+ 218 " <fk-pointing-to-this-class column=\"BID\"/>\n"+ 219 " <fk-pointing-to-element-class column=\"AID\"/>\n"+ 220 " </collection-descriptor>\n"+ 221 "</class-descriptor>", 222 runOjbXDoclet(OJB_DEST_FILE)); 223 assertEqualsTorqueSchemaFile( 224 "<database name=\"ojbtest\">\n"+ 225 " <table name=\"A\">\n"+ 226 " <column name=\"id\"\n"+ 227 " javaName=\"id\"\n"+ 228 " type=\"VARCHAR\"\n"+ 229 " primaryKey=\"true\"\n"+ 230 " required=\"true\"\n"+ 231 " size=\"254\"\n"+ 232 " />\n"+ 233 " </table>\n"+ 234 " <table name=\"A_B\">\n"+ 235 " <column name=\"AID\"\n"+ 236 " type=\"VARCHAR\"\n"+ 237 " primaryKey=\"true\"\n"+ 238 " required=\"true\"\n"+ 239 " size=\"254\"\n"+ 240 " />\n"+ 241 " <column name=\"BID\"\n"+ 242 " type=\"DATE\"\n"+ 243 " primaryKey=\"true\"\n"+ 244 " required=\"true\"\n"+ 245 " />\n"+ 246 " <foreign-key foreignTable=\"A\">\n"+ 247 " <reference local=\"AID\" foreign=\"id\"/>\n"+ 248 " </foreign-key>\n"+ 249 " <foreign-key foreignTable=\"B\">\n"+ 250 " <reference local=\"BID\" foreign=\"id\"/>\n"+ 251 " </foreign-key>\n"+ 252 " </table>\n"+ 253 " <table name=\"B\">\n"+ 254 " <column name=\"id\"\n"+ 255 " javaName=\"id\"\n"+ 256 " type=\"DATE\"\n"+ 257 " primaryKey=\"true\"\n"+ 258 " required=\"true\"\n"+ 259 " />\n"+ 260 " </table>\n"+ 261 "</database>", 262 runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 263 } 264 265 public void testIndirectionTable3() 267 { 268 addClass( 269 "test.A", 270 "package test;\n"+ 271 "/** @ojb.class */\n" + 272 "public class A {\n"+ 273 " /** @ojb.field primarykey=\"true\" */\n"+ 274 " private int id;\n"+ 275 " /** @ojb.collection element-class-ref=\"test.B\"\n"+ 276 " * foreignkey=\"AID\"\n"+ 277 " * remote-foreignkey=\"BID\"\n"+ 278 " * indirection-table=\"A_B\"\n"+ 279 " * indirection-table-primarykeys=\"false\"\n"+ 280 " */\n"+ 281 " private java.util.List bs;\n"+ 282 "}"); 283 addClass( 284 "test.B", 285 "package test;\n"+ 286 "/** @ojb.class */\n"+ 287 "public class B {\n"+ 288 " /** @ojb.field primarykey=\"true\" */\n"+ 289 " private String id;\n"+ 290 "}\n"); 291 292 assertEqualsOjbDescriptorFile( 293 "<class-descriptor\n"+ 294 " class=\"test.A\"\n"+ 295 " table=\"A\"\n"+ 296 ">\n"+ 297 " <field-descriptor\n"+ 298 " name=\"id\"\n"+ 299 " column=\"id\"\n"+ 300 " jdbc-type=\"INTEGER\"\n"+ 301 " primarykey=\"true\"\n"+ 302 " >\n"+ 303 " </field-descriptor>\n"+ 304 " <collection-descriptor\n"+ 305 " name=\"bs\"\n"+ 306 " element-class-ref=\"test.B\"\n"+ 307 " indirection-table=\"A_B\"\n"+ 308 " >\n"+ 309 " <fk-pointing-to-this-class column=\"AID\"/>\n"+ 310 " <fk-pointing-to-element-class column=\"BID\"/>\n"+ 311 " </collection-descriptor>\n"+ 312 "</class-descriptor>\n"+ 313 "<class-descriptor\n"+ 314 " class=\"test.B\"\n"+ 315 " table=\"B\"\n"+ 316 ">\n"+ 317 " <field-descriptor\n"+ 318 " name=\"id\"\n"+ 319 " column=\"id\"\n"+ 320 " jdbc-type=\"VARCHAR\"\n"+ 321 " primarykey=\"true\"\n"+ 322 " length=\"254\"\n"+ 323 " >\n"+ 324 " </field-descriptor>\n"+ 325 "</class-descriptor>", 326 runOjbXDoclet(OJB_DEST_FILE)); 327 assertEqualsTorqueSchemaFile( 328 "<database name=\"ojbtest\">\n"+ 329 " <table name=\"A\">\n"+ 330 " <column name=\"id\"\n"+ 331 " javaName=\"id\"\n"+ 332 " type=\"INTEGER\"\n"+ 333 " primaryKey=\"true\"\n"+ 334 " required=\"true\"\n"+ 335 " />\n"+ 336 " </table>\n"+ 337 " <table name=\"A_B\">\n"+ 338 " <column name=\"AID\"\n"+ 339 " type=\"INTEGER\"\n"+ 340 " />\n"+ 341 " <column name=\"BID\"\n"+ 342 " type=\"VARCHAR\"\n"+ 343 " size=\"254\"\n"+ 344 " />\n"+ 345 " <foreign-key foreignTable=\"A\">\n"+ 346 " <reference local=\"AID\" foreign=\"id\"/>\n"+ 347 " </foreign-key>\n"+ 348 " <foreign-key foreignTable=\"B\">\n"+ 349 " <reference local=\"BID\" foreign=\"id\"/>\n"+ 350 " </foreign-key>\n"+ 351 " </table>\n"+ 352 " <table name=\"B\">\n"+ 353 " <column name=\"id\"\n"+ 354 " javaName=\"id\"\n"+ 355 " type=\"VARCHAR\"\n"+ 356 " primaryKey=\"true\"\n"+ 357 " required=\"true\"\n"+ 358 " size=\"254\"\n"+ 359 " />\n"+ 360 " </table>\n"+ 361 "</database>", 362 runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 363 } 364 365 public void testIndirectionTable4() 367 { 368 addClass( 369 "test.A", 370 "package test;\n"+ 371 "/** @ojb.class */\n" + 372 "public class A {\n"+ 373 " /** @ojb.field primarykey=\"true\" */\n"+ 374 " private int id1;\n"+ 375 " /** @ojb.field primarykey=\"true\" */\n"+ 376 " private String id2;\n"+ 377 " /** @ojb.field primarykey=\"true\" */\n"+ 378 " private int id3;\n"+ 379 " /** @ojb.collection element-class-ref=\"test.B\"\n"+ 380 " * foreignkey=\"AID1,AID2,AID3\"\n"+ 381 " * remote-foreignkey=\"BID1,BID2\"\n"+ 382 " * indirection-table=\"A_B\"\n"+ 383 " * indirection-table-primarykeys=\"true\"\n"+ 384 " */\n"+ 385 " private java.util.List bs;\n"+ 386 "}"); 387 addClass( 388 "test.B", 389 "package test;\n"+ 390 "/** @ojb.class */\n"+ 391 "public class B {\n"+ 392 " /** @ojb.field primarykey=\"true\" */\n"+ 393 " private String id1;\n"+ 394 " /** @ojb.field primarykey=\"true\" */\n"+ 395 " private int id2;\n"+ 396 "}\n"); 397 398 assertEqualsOjbDescriptorFile( 399 "<class-descriptor\n"+ 400 " class=\"test.A\"\n"+ 401 " table=\"A\"\n"+ 402 ">\n"+ 403 " <field-descriptor\n"+ 404 " name=\"id1\"\n"+ 405 " column=\"id1\"\n"+ 406 " jdbc-type=\"INTEGER\"\n"+ 407 " primarykey=\"true\"\n"+ 408 " >\n"+ 409 " </field-descriptor>\n"+ 410 " <field-descriptor\n"+ 411 " name=\"id2\"\n"+ 412 " column=\"id2\"\n"+ 413 " jdbc-type=\"VARCHAR\"\n"+ 414 " primarykey=\"true\"\n"+ 415 " length=\"254\"\n"+ 416 " >\n"+ 417 " </field-descriptor>\n"+ 418 " <field-descriptor\n"+ 419 " name=\"id3\"\n"+ 420 " column=\"id3\"\n"+ 421 " jdbc-type=\"INTEGER\"\n"+ 422 " primarykey=\"true\"\n"+ 423 " >\n"+ 424 " </field-descriptor>\n"+ 425 " <collection-descriptor\n"+ 426 " name=\"bs\"\n"+ 427 " element-class-ref=\"test.B\"\n"+ 428 " indirection-table=\"A_B\"\n"+ 429 " >\n"+ 430 " <fk-pointing-to-this-class column=\"AID1\"/>\n"+ 431 " <fk-pointing-to-this-class column=\"AID2\"/>\n"+ 432 " <fk-pointing-to-this-class column=\"AID3\"/>\n"+ 433 " <fk-pointing-to-element-class column=\"BID1\"/>\n"+ 434 " <fk-pointing-to-element-class column=\"BID2\"/>\n"+ 435 " </collection-descriptor>\n"+ 436 "</class-descriptor>\n"+ 437 "<class-descriptor\n"+ 438 " class=\"test.B\"\n"+ 439 " table=\"B\"\n"+ 440 ">\n"+ 441 " <field-descriptor\n"+ 442 " name=\"id1\"\n"+ 443 " column=\"id1\"\n"+ 444 " jdbc-type=\"VARCHAR\"\n"+ 445 " primarykey=\"true\"\n"+ 446 " length=\"254\"\n"+ 447 " >\n"+ 448 " </field-descriptor>\n"+ 449 " <field-descriptor\n"+ 450 " name=\"id2\"\n"+ 451 " column=\"id2\"\n"+ 452 " jdbc-type=\"INTEGER\"\n"+ 453 " primarykey=\"true\"\n"+ 454 " >\n"+ 455 " </field-descriptor>\n"+ 456 "</class-descriptor>", 457 runOjbXDoclet(OJB_DEST_FILE)); 458 assertEqualsTorqueSchemaFile( 459 "<database name=\"ojbtest\">\n"+ 460 " <table name=\"A\">\n"+ 461 " <column name=\"id1\"\n"+ 462 " javaName=\"id1\"\n"+ 463 " type=\"INTEGER\"\n"+ 464 " primaryKey=\"true\"\n"+ 465 " required=\"true\"\n"+ 466 " />\n"+ 467 " <column name=\"id2\"\n"+ 468 " javaName=\"id2\"\n"+ 469 " type=\"VARCHAR\"\n"+ 470 " primaryKey=\"true\"\n"+ 471 " required=\"true\"\n"+ 472 " size=\"254\"\n"+ 473 " />\n"+ 474 " <column name=\"id3\"\n"+ 475 " javaName=\"id3\"\n"+ 476 " type=\"INTEGER\"\n"+ 477 " primaryKey=\"true\"\n"+ 478 " required=\"true\"\n"+ 479 " />\n"+ 480 " </table>\n"+ 481 " <table name=\"A_B\">\n"+ 482 " <column name=\"AID1\"\n"+ 483 " type=\"INTEGER\"\n"+ 484 " primaryKey=\"true\"\n"+ 485 " required=\"true\"\n"+ 486 " />\n"+ 487 " <column name=\"AID2\"\n"+ 488 " type=\"VARCHAR\"\n"+ 489 " primaryKey=\"true\"\n"+ 490 " required=\"true\"\n"+ 491 " size=\"254\"\n"+ 492 " />\n"+ 493 " <column name=\"AID3\"\n"+ 494 " type=\"INTEGER\"\n"+ 495 " primaryKey=\"true\"\n"+ 496 " required=\"true\"\n"+ 497 " />\n"+ 498 " <column name=\"BID1\"\n"+ 499 " type=\"VARCHAR\"\n"+ 500 " primaryKey=\"true\"\n"+ 501 " required=\"true\"\n"+ 502 " size=\"254\"\n"+ 503 " />\n"+ 504 " <column name=\"BID2\"\n"+ 505 " type=\"INTEGER\"\n"+ 506 " primaryKey=\"true\"\n"+ 507 " required=\"true\"\n"+ 508 " />\n"+ 509 " <foreign-key foreignTable=\"A\">\n"+ 510 " <reference local=\"AID1\" foreign=\"id1\"/>\n"+ 511 " <reference local=\"AID2\" foreign=\"id2\"/>\n"+ 512 " <reference local=\"AID3\" foreign=\"id3\"/>\n"+ 513 " </foreign-key>\n"+ 514 " <foreign-key foreignTable=\"B\">\n"+ 515 " <reference local=\"BID1\" foreign=\"id1\"/>\n"+ 516 " <reference local=\"BID2\" foreign=\"id2\"/>\n"+ 517 " </foreign-key>\n"+ 518 " </table>\n"+ 519 " <table name=\"B\">\n"+ 520 " <column name=\"id1\"\n"+ 521 " javaName=\"id1\"\n"+ 522 " type=\"VARCHAR\"\n"+ 523 " primaryKey=\"true\"\n"+ 524 " required=\"true\"\n"+ 525 " size=\"254\"\n"+ 526 " />\n"+ 527 " <column name=\"id2\"\n"+ 528 " javaName=\"id2\"\n"+ 529 " type=\"INTEGER\"\n"+ 530 " primaryKey=\"true\"\n"+ 531 " required=\"true\"\n"+ 532 " />\n"+ 533 " </table>\n"+ 534 "</database>", 535 runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 536 } 537 538 public void testIndirectionTable5() 540 { 541 addClass( 542 "test.A", 543 "package test;\n"+ 544 "/** @ojb.class */\n" + 545 "public class A {\n"+ 546 " /** @ojb.field primarykey=\"true\" */\n"+ 547 " private int id;\n"+ 548 " /** @ojb.collection foreignkey=\"AID\"\n"+ 549 " * indirection-table=\"A_B\"\n"+ 550 " * indirection-table-primarykeys=\"\"\n"+ 551 " */\n"+ 552 " private B[] bs;\n"+ 553 "}"); 554 addClass( 555 "test.B", 556 "package test;\n"+ 557 "/** @ojb.class */\n"+ 558 "public class B {\n"+ 559 " /** @ojb.field primarykey=\"true\" */\n"+ 560 " private int id;\n"+ 561 " /** @ojb.collection element-class-ref=\"test.A\"\n"+ 562 " * foreignkey=\"BID\"\n"+ 563 " * indirection-table=\"A_B\"\n"+ 564 " */\n"+ 565 " private java.util.List as;\n"+ 566 "}\n"); 567 568 assertNull(runOjbXDoclet(OJB_DEST_FILE)); 569 assertNull(runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 570 } 571 572 public void testIndirectionTable6() 574 { 575 addClass( 576 "test.A", 577 "package test;\n"+ 578 "/** @ojb.class */\n" + 579 "public class A {\n"+ 580 " /** @ojb.field primarykey=\"true\" */\n"+ 581 " private int id;\n"+ 582 " /** @ojb.collection foreignkey=\"AID\"\n"+ 583 " * indirection-table=\"A_B\"\n"+ 584 " * indirection-table-primarykeys=\"yes\"\n"+ 585 " */\n"+ 586 " private B[] bs;\n"+ 587 "}"); 588 addClass( 589 "test.B", 590 "package test;\n"+ 591 "/** @ojb.class */\n"+ 592 "public class B {\n"+ 593 " /** @ojb.field primarykey=\"true\" */\n"+ 594 " private int id;\n"+ 595 " /** @ojb.collection element-class-ref=\"test.A\"\n"+ 596 " * foreignkey=\"BID\"\n"+ 597 " * indirection-table=\"A_B\"\n"+ 598 " */\n"+ 599 " private java.util.List as;\n"+ 600 "}\n"); 601 602 assertNull(runOjbXDoclet(OJB_DEST_FILE)); 603 assertNull(runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 604 } 605 } 606 | Popular Tags |