1 package xdoclet.modules.ojb.tests; 2 3 17 18 23 public class ModifyInheritedTagDatabaseForeignkeyAttributeTests extends OjbTestBase 24 { 25 public ModifyInheritedTagDatabaseForeignkeyAttributeTests(String name) 26 { 27 super(name); 28 } 29 30 public void testDatabaseForeignkey1() 32 { 33 addClass( 34 "test.A", 35 "package test;\n"+ 36 "/** @ojb.class */\n"+ 37 "public class A {\n"+ 38 " /** @ojb.field */\n"+ 39 " private int attrKey;\n"+ 40 " /** @ojb.reference foreignkey=\"attrKey\" */\n"+ 41 " private test.D attr;\n"+ 42 "}\n"); 43 addClass( 44 "test.B", 45 "package test;\n"+ 46 "/** @ojb.class\n"+ 47 " * @ojb.modify-inherited name=\"attr\"\n"+ 48 " * database-foreignkey=\"false\"\n"+ 49 " */\n"+ 50 "public class B extends A {}\n"); 51 addClass( 52 "test.C", 53 "package test;\n"+ 54 "/** @ojb.class */\n"+ 55 "public class C extends B {}\n"); 56 addClass( 57 "test.D", 58 "package test;\n"+ 59 "/** @ojb.class */\n"+ 60 "public class D {\n"+ 61 " /** @ojb.field primarykey=\"true\" */\n"+ 62 " private int id;\n"+ 63 "}\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.B\"/>\n"+ 71 " <field-descriptor\n"+ 72 " name=\"attrKey\"\n"+ 73 " column=\"attrKey\"\n"+ 74 " jdbc-type=\"INTEGER\"\n"+ 75 " >\n"+ 76 " </field-descriptor>\n"+ 77 " <reference-descriptor\n"+ 78 " name=\"attr\"\n"+ 79 " class-ref=\"test.D\"\n"+ 80 " >\n"+ 81 " <foreignkey field-ref=\"attrKey\"/>\n"+ 82 " </reference-descriptor>\n"+ 83 "</class-descriptor>\n"+ 84 "<class-descriptor\n"+ 85 " class=\"test.B\"\n"+ 86 " table=\"B\"\n"+ 87 ">\n"+ 88 " <extent-class class-ref=\"test.C\"/>\n"+ 89 " <field-descriptor\n"+ 90 " name=\"attrKey\"\n"+ 91 " column=\"attrKey\"\n"+ 92 " jdbc-type=\"INTEGER\"\n"+ 93 " >\n"+ 94 " </field-descriptor>\n"+ 95 " <reference-descriptor\n"+ 96 " name=\"attr\"\n"+ 97 " class-ref=\"test.D\"\n"+ 98 " >\n"+ 99 " <foreignkey field-ref=\"attrKey\"/>\n"+ 100 " </reference-descriptor>\n"+ 101 "</class-descriptor>\n"+ 102 "<class-descriptor\n"+ 103 " class=\"test.C\"\n"+ 104 " table=\"C\"\n"+ 105 ">\n"+ 106 " <field-descriptor\n"+ 107 " name=\"attrKey\"\n"+ 108 " column=\"attrKey\"\n"+ 109 " jdbc-type=\"INTEGER\"\n"+ 110 " >\n"+ 111 " </field-descriptor>\n"+ 112 " <reference-descriptor\n"+ 113 " name=\"attr\"\n"+ 114 " class-ref=\"test.D\"\n"+ 115 " >\n"+ 116 " <foreignkey field-ref=\"attrKey\"/>\n"+ 117 " </reference-descriptor>\n"+ 118 "</class-descriptor>\n"+ 119 "<class-descriptor\n"+ 120 " class=\"test.D\"\n"+ 121 " table=\"D\"\n"+ 122 ">\n"+ 123 " <field-descriptor\n"+ 124 " name=\"id\"\n"+ 125 " column=\"id\"\n"+ 126 " jdbc-type=\"INTEGER\"\n"+ 127 " primarykey=\"true\"\n"+ 128 " >\n"+ 129 " </field-descriptor>\n"+ 130 "</class-descriptor>", 131 runOjbXDoclet(OJB_DEST_FILE)); 132 assertEqualsTorqueSchemaFile( 133 "<database name=\"ojbtest\">\n"+ 134 " <table name=\"A\">\n"+ 135 " <column name=\"attrKey\"\n"+ 136 " javaName=\"attrKey\"\n"+ 137 " type=\"INTEGER\"\n"+ 138 " />\n"+ 139 " <foreign-key foreignTable=\"D\">\n"+ 140 " <reference local=\"attrKey\" foreign=\"id\"/>\n"+ 141 " </foreign-key>\n"+ 142 " </table>\n"+ 143 " <table name=\"B\">\n"+ 144 " <column name=\"attrKey\"\n"+ 145 " javaName=\"attrKey\"\n"+ 146 " type=\"INTEGER\"\n"+ 147 " />\n"+ 148 " </table>\n"+ 149 " <table name=\"C\">\n"+ 150 " <column name=\"attrKey\"\n"+ 151 " javaName=\"attrKey\"\n"+ 152 " type=\"INTEGER\"\n"+ 153 " />\n"+ 154 " </table>\n"+ 155 " <table name=\"D\">\n"+ 156 " <column name=\"id\"\n"+ 157 " javaName=\"id\"\n"+ 158 " type=\"INTEGER\"\n"+ 159 " primaryKey=\"true\"\n"+ 160 " required=\"true\"\n"+ 161 " />\n"+ 162 " </table>\n"+ 163 "</database>", 164 runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 165 } 166 167 public void testDatabaseForeignkey2() 170 { 171 addClass( 172 "test.A", 173 "package test;\n"+ 174 "/** @ojb.class generate-repository-info=\"false\" */\n"+ 175 "public class A {\n"+ 176 " /** @ojb.field */\n"+ 177 " private int attrKey;\n"+ 178 " /** @ojb.reference foreignkey=\"attrKey\"\n"+ 179 " * database-foreignkey=\"false\"\n"+ 180 " */"+ 181 " private test.C attr;\n"+ 182 "}\n"); 183 addClass( 184 "test.B", 185 "package test;\n"+ 186 "/** @ojb.class\n"+ 187 " * @ojb.modify-inherited name=\"attr\"\n"+ 188 " * database-foreignkey=\"true\"\n"+ 189 " */\n"+ 190 "public class B extends A {}\n"); 191 addClass( 192 "test.C", 193 "package test;\n"+ 194 "/** @ojb.class */\n"+ 195 "public class C {\n"+ 196 " /** @ojb.field primarykey=\"true\" */\n"+ 197 " private int id;\n"+ 198 "}\n"); 199 200 assertEqualsOjbDescriptorFile( 201 "<class-descriptor\n"+ 202 " class=\"test.A\"\n"+ 203 ">\n"+ 204 " <extent-class class-ref=\"test.B\"/>\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=\"attrKey\"\n"+ 212 " column=\"attrKey\"\n"+ 213 " jdbc-type=\"INTEGER\"\n"+ 214 " >\n"+ 215 " </field-descriptor>\n"+ 216 " <reference-descriptor\n"+ 217 " name=\"attr\"\n"+ 218 " class-ref=\"test.C\"\n"+ 219 " >\n"+ 220 " <foreignkey field-ref=\"attrKey\"/>\n"+ 221 " </reference-descriptor>\n"+ 222 "</class-descriptor>\n"+ 223 "<class-descriptor\n"+ 224 " class=\"test.C\"\n"+ 225 " table=\"C\"\n"+ 226 ">\n"+ 227 " <field-descriptor\n"+ 228 " name=\"id\"\n"+ 229 " column=\"id\"\n"+ 230 " jdbc-type=\"INTEGER\"\n"+ 231 " primarykey=\"true\"\n"+ 232 " >\n"+ 233 " </field-descriptor>\n"+ 234 "</class-descriptor>", 235 runOjbXDoclet(OJB_DEST_FILE)); 236 assertEqualsTorqueSchemaFile( 237 "<database name=\"ojbtest\">\n"+ 238 " <table name=\"B\">\n"+ 239 " <column name=\"attrKey\"\n"+ 240 " javaName=\"attrKey\"\n"+ 241 " type=\"INTEGER\"\n"+ 242 " />\n"+ 243 " <foreign-key foreignTable=\"C\">\n"+ 244 " <reference local=\"attrKey\" foreign=\"id\"/>\n"+ 245 " </foreign-key>\n"+ 246 " </table>\n"+ 247 " <table name=\"C\">\n"+ 248 " <column name=\"id\"\n"+ 249 " javaName=\"id\"\n"+ 250 " type=\"INTEGER\"\n"+ 251 " primaryKey=\"true\"\n"+ 252 " required=\"true\"\n"+ 253 " />\n"+ 254 " </table>\n"+ 255 "</database>", 256 runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 257 } 258 259 public void testDatabaseForeignkey3() 262 { 263 addClass( 264 "test.A", 265 "package test;\n"+ 266 "/** @ojb.class generate-repository-info=\"false\" */\n" + 267 "public class A {\n"+ 268 " /** @ojb.field primarykey=\"true\" */\n"+ 269 " private int id;\n"+ 270 " /** @ojb.collection element-class-ref=\"test.C\"\n"+ 271 " * foreignkey=\"aid\"\n"+ 272 " */\n"+ 273 " private java.util.List attr;\n"+ 274 "}"); 275 addClass( 276 "test.B", 277 "package test;\n"+ 278 "/** @ojb.class\n"+ 279 " * @ojb.modify-inherited name=\"attr\"\n"+ 280 " * database-foreignkey=\"false\"\n"+ 281 " */\n" + 282 "public class B extends A {}"); 283 addClass( 284 "test.C", 285 "package test;\n"+ 286 "/** @ojb.class */\n"+ 287 "public class C {\n"+ 288 " /** @ojb.field */\n"+ 289 " private int aid;\n"+ 290 " /** @ojb.field */\n"+ 291 "}\n"); 292 293 assertEqualsOjbDescriptorFile( 294 "<class-descriptor\n"+ 295 " class=\"test.A\"\n"+ 296 ">\n"+ 297 " <extent-class class-ref=\"test.B\"/>\n"+ 298 "</class-descriptor>\n"+ 299 "<class-descriptor\n"+ 300 " class=\"test.B\"\n"+ 301 " table=\"B\"\n"+ 302 ">\n"+ 303 " <field-descriptor\n"+ 304 " name=\"id\"\n"+ 305 " column=\"id\"\n"+ 306 " jdbc-type=\"INTEGER\"\n"+ 307 " primarykey=\"true\"\n"+ 308 " >\n"+ 309 " </field-descriptor>\n"+ 310 " <collection-descriptor\n"+ 311 " name=\"attr\"\n"+ 312 " element-class-ref=\"test.C\"\n"+ 313 " >\n"+ 314 " <inverse-foreignkey field-ref=\"aid\"/>\n"+ 315 " </collection-descriptor>\n"+ 316 "</class-descriptor>\n"+ 317 "<class-descriptor\n"+ 318 " class=\"test.C\"\n"+ 319 " table=\"C\"\n"+ 320 ">\n"+ 321 " <field-descriptor\n"+ 322 " name=\"aid\"\n"+ 323 " column=\"aid\"\n"+ 324 " jdbc-type=\"INTEGER\"\n"+ 325 " >\n"+ 326 " </field-descriptor>\n"+ 327 "</class-descriptor>", 328 runOjbXDoclet(OJB_DEST_FILE)); 329 assertEqualsTorqueSchemaFile( 330 "<database name=\"ojbtest\">\n"+ 331 " <table name=\"B\">\n"+ 332 " <column name=\"id\"\n"+ 333 " javaName=\"id\"\n"+ 334 " type=\"INTEGER\"\n"+ 335 " primaryKey=\"true\"\n"+ 336 " required=\"true\"\n"+ 337 " />\n"+ 338 " </table>\n"+ 339 " <table name=\"C\">\n"+ 340 " <column name=\"aid\"\n"+ 341 " javaName=\"aid\"\n"+ 342 " type=\"INTEGER\"\n"+ 343 " />\n"+ 344 " </table>\n"+ 345 "</database>", 346 runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 347 } 348 349 public void testDatabaseForeignkey4() 352 { 353 addClass( 354 "test.A", 355 "package test;\n"+ 356 "/** @ojb.class */\n" + 357 "public class A {\n"+ 358 " /** @ojb.field primarykey=\"true\" */\n"+ 359 " private int id1;\n"+ 360 " /** @ojb.field primarykey=\"true\" */\n"+ 361 " private String id2;\n"+ 362 " /** @ojb.collection element-class-ref=\"test.C\"\n"+ 363 " * foreignkey=\"aid1,aid2\"\n"+ 364 " * database-foreignkey=\"false\"\n"+ 365 " */\n"+ 366 " private java.util.List attr;\n"+ 367 "}"); 368 addClass( 369 "test.B", 370 "package test;\n"+ 371 "/** @ojb.class\n"+ 372 " * @ojb.modify-inherited name=\"attr\"\n"+ 373 " * database-foreignkey=\"true\"\n"+ 374 " */\n" + 375 "public class B extends A {}"); 376 addClass( 377 "test.C", 378 "package test;\n"+ 379 "/** @ojb.class\n"+ 380 " * @ojb.field name=\"aid3\"\n"+ 381 " * jdbc-type=\"VARCHAR\"\n"+ 382 " */\n"+ 383 "public class C {\n"+ 384 " /** @ojb.field */\n"+ 385 " private int aid1;\n"+ 386 " /** @ojb.field */\n"+ 387 " private int aid4;\n"+ 388 " /** @ojb.field */\n"+ 389 " private String aid2;\n"+ 390 "}\n"); 391 392 assertEqualsOjbDescriptorFile( 393 "<class-descriptor\n"+ 394 " class=\"test.A\"\n"+ 395 " table=\"A\"\n"+ 396 ">\n"+ 397 " <extent-class class-ref=\"test.B\"/>\n"+ 398 " <field-descriptor\n"+ 399 " name=\"id1\"\n"+ 400 " column=\"id1\"\n"+ 401 " jdbc-type=\"INTEGER\"\n"+ 402 " primarykey=\"true\"\n"+ 403 " >\n"+ 404 " </field-descriptor>\n"+ 405 " <field-descriptor\n"+ 406 " name=\"id2\"\n"+ 407 " column=\"id2\"\n"+ 408 " jdbc-type=\"VARCHAR\"\n"+ 409 " primarykey=\"true\"\n"+ 410 " length=\"254\"\n"+ 411 " >\n"+ 412 " </field-descriptor>\n"+ 413 " <collection-descriptor\n"+ 414 " name=\"attr\"\n"+ 415 " element-class-ref=\"test.C\"\n"+ 416 " >\n"+ 417 " <inverse-foreignkey field-ref=\"aid1\"/>\n"+ 418 " <inverse-foreignkey field-ref=\"aid2\"/>\n"+ 419 " </collection-descriptor>\n"+ 420 "</class-descriptor>\n"+ 421 "<class-descriptor\n"+ 422 " class=\"test.B\"\n"+ 423 " table=\"B\"\n"+ 424 ">\n"+ 425 " <field-descriptor\n"+ 426 " name=\"id1\"\n"+ 427 " column=\"id1\"\n"+ 428 " jdbc-type=\"INTEGER\"\n"+ 429 " primarykey=\"true\"\n"+ 430 " >\n"+ 431 " </field-descriptor>\n"+ 432 " <field-descriptor\n"+ 433 " name=\"id2\"\n"+ 434 " column=\"id2\"\n"+ 435 " jdbc-type=\"VARCHAR\"\n"+ 436 " primarykey=\"true\"\n"+ 437 " length=\"254\"\n"+ 438 " >\n"+ 439 " </field-descriptor>\n"+ 440 " <collection-descriptor\n"+ 441 " name=\"attr\"\n"+ 442 " element-class-ref=\"test.C\"\n"+ 443 " >\n"+ 444 " <inverse-foreignkey field-ref=\"aid1\"/>\n"+ 445 " <inverse-foreignkey field-ref=\"aid2\"/>\n"+ 446 " </collection-descriptor>\n"+ 447 "</class-descriptor>\n"+ 448 "<class-descriptor\n"+ 449 " class=\"test.C\"\n"+ 450 " table=\"C\"\n"+ 451 ">\n"+ 452 " <field-descriptor\n"+ 453 " name=\"aid3\"\n"+ 454 " column=\"aid3\"\n"+ 455 " jdbc-type=\"VARCHAR\"\n"+ 456 " length=\"254\"\n"+ 457 " access=\"anonymous\"\n"+ 458 " >\n"+ 459 " </field-descriptor>\n"+ 460 " <field-descriptor\n"+ 461 " name=\"aid1\"\n"+ 462 " column=\"aid1\"\n"+ 463 " jdbc-type=\"INTEGER\"\n"+ 464 " >\n"+ 465 " </field-descriptor>\n"+ 466 " <field-descriptor\n"+ 467 " name=\"aid4\"\n"+ 468 " column=\"aid4\"\n"+ 469 " jdbc-type=\"INTEGER\"\n"+ 470 " >\n"+ 471 " </field-descriptor>\n"+ 472 " <field-descriptor\n"+ 473 " name=\"aid2\"\n"+ 474 " column=\"aid2\"\n"+ 475 " jdbc-type=\"VARCHAR\"\n"+ 476 " length=\"254\"\n"+ 477 " >\n"+ 478 " </field-descriptor>\n"+ 479 "</class-descriptor>", 480 runOjbXDoclet(OJB_DEST_FILE)); 481 assertEqualsTorqueSchemaFile( 482 "<database name=\"ojbtest\">\n"+ 483 " <table name=\"A\">\n"+ 484 " <column name=\"id1\"\n"+ 485 " javaName=\"id1\"\n"+ 486 " type=\"INTEGER\"\n"+ 487 " primaryKey=\"true\"\n"+ 488 " required=\"true\"\n"+ 489 " />\n"+ 490 " <column name=\"id2\"\n"+ 491 " javaName=\"id2\"\n"+ 492 " type=\"VARCHAR\"\n"+ 493 " primaryKey=\"true\"\n"+ 494 " required=\"true\"\n"+ 495 " size=\"254\"\n"+ 496 " />\n"+ 497 " </table>\n"+ 498 " <table name=\"B\">\n"+ 499 " <column name=\"id1\"\n"+ 500 " javaName=\"id1\"\n"+ 501 " type=\"INTEGER\"\n"+ 502 " primaryKey=\"true\"\n"+ 503 " required=\"true\"\n"+ 504 " />\n"+ 505 " <column name=\"id2\"\n"+ 506 " javaName=\"id2\"\n"+ 507 " type=\"VARCHAR\"\n"+ 508 " primaryKey=\"true\"\n"+ 509 " required=\"true\"\n"+ 510 " size=\"254\"\n"+ 511 " />\n"+ 512 " </table>\n"+ 513 " <table name=\"C\">\n"+ 514 " <column name=\"aid3\"\n"+ 515 " javaName=\"aid3\"\n"+ 516 " type=\"VARCHAR\"\n"+ 517 " size=\"254\"\n"+ 518 " />\n"+ 519 " <column name=\"aid1\"\n"+ 520 " javaName=\"aid1\"\n"+ 521 " type=\"INTEGER\"\n"+ 522 " />\n"+ 523 " <column name=\"aid4\"\n"+ 524 " javaName=\"aid4\"\n"+ 525 " type=\"INTEGER\"\n"+ 526 " />\n"+ 527 " <column name=\"aid2\"\n"+ 528 " javaName=\"aid2\"\n"+ 529 " type=\"VARCHAR\"\n"+ 530 " size=\"254\"\n"+ 531 " />\n"+ 532 " </table>\n"+ 533 "</database>", 534 runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest")); 535 } 536 } 537 | Popular Tags |