Coverage report

  %line %branch
org.apache.turbine.util.db.map.TurbineMapBuilder
0% 
0% 

 1  
 package org.apache.turbine.util.db.map;
 2  
 
 3  
 /*
 4  
  * Copyright 2001-2005 The Apache Software Foundation.
 5  
  *
 6  
  * Licensed under the Apache License, Version 2.0 (the "License")
 7  
  * you may not use this file except in compliance with the License.
 8  
  * You may obtain a copy of the License at
 9  
  *
 10  
  *     http://www.apache.org/licenses/LICENSE-2.0
 11  
  *
 12  
  * Unless required by applicable law or agreed to in writing, software
 13  
  * distributed under the License is distributed on an "AS IS" BASIS,
 14  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 15  
  * See the License for the specific language governing permissions and
 16  
  * limitations under the License.
 17  
  */
 18  
 
 19  
 import java.util.Date;
 20  
 import java.util.Hashtable;
 21  
 
 22  
 import org.apache.torque.Torque;
 23  
 import org.apache.torque.map.DatabaseMap;
 24  
 import org.apache.torque.map.MapBuilder;
 25  
 import org.apache.torque.map.TableMap;
 26  
 
 27  
 /**
 28  
  * Default Builder for Database/Table/Column Maps within the Turbine
 29  
  * System.  If you decide to use your own table schema, then you
 30  
  * probably will want to implement this class on your own.  It is then
 31  
  * defined within the TurbineResources.properties file.
 32  
  *
 33  
  * @author <a href="mailto:john.mcnally@clearink.com">John D. McNally</a>
 34  
  * @author <a href="mailto:dlr@finemaltcoding.com">Daniel Rall</a>
 35  
  * @version $Id: TurbineMapBuilder.java 264148 2005-08-29 14:21:04Z henning $
 36  
  */
 37  0
 public class TurbineMapBuilder implements MapBuilder
 38  
 {
 39  
     /**
 40  
      * Get the User table.
 41  
      *
 42  
      * @return A String.
 43  
      */
 44  
     public String getTableUser()
 45  
     {
 46  0
         return "TURBINE_USER";
 47  
     }
 48  
 
 49  
     /**
 50  
      * Get the UserRole table.
 51  
      *
 52  
      * @return A String.
 53  
      */
 54  
     public String getTableRole()
 55  
     {
 56  0
         return "TURBINE_ROLE";
 57  
     }
 58  
 
 59  
     /**
 60  
      * Get the Permission table.
 61  
      *
 62  
      * @return A String.
 63  
      */
 64  
     public String getTablePermission()
 65  
     {
 66  0
         return "TURBINE_PERMISSION";
 67  
     }
 68  
 
 69  
     /**
 70  
      * Get the UserGroupRole table.
 71  
      *
 72  
      * @return A String.
 73  
      */
 74  
     public String getTableUserGroupRole()
 75  
     {
 76  0
         return "TURBINE_USER_GROUP_ROLE";
 77  
     }
 78  
 
 79  
     /**
 80  
      * Get the RolePermission table.
 81  
      *
 82  
      * @return A String.
 83  
      */
 84  
     public String getTableRolePermission()
 85  
     {
 86  0
         return "TURBINE_ROLE_PERMISSION";
 87  
     }
 88  
 
 89  
     /**
 90  
      * Get the Group table.
 91  
      *
 92  
      * @return A String.
 93  
      */
 94  
     public String getTableGroup()
 95  
     {
 96  0
         return "TURBINE_GROUP";
 97  
     }
 98  
 
 99  
     /**
 100  
      * Internal Unique key to the visitor table.  Override this if
 101  
      * using your custom table.
 102  
      *
 103  
      * @return A String.
 104  
      */
 105  
     public String getUserId()
 106  
     {
 107  0
         return "USER_ID";
 108  
     }
 109  
 
 110  
     /**
 111  
      * Fully qualified Unique key to the visitor table.  Shouldn't
 112  
      * need to override this as it uses the above methods.
 113  
      *
 114  
      * @return A String.
 115  
      */
 116  
     public String getUser_UserId()
 117  
     {
 118  0
         return getTableUser() + '.' + getUserId();
 119  
     }
 120  
 
 121  
     /**
 122  
      * Column used to record the last login time for visitor.
 123  
      * Override this if using your custom table.
 124  
      *
 125  
      * @return A String.
 126  
      */
 127  
     public String getLastLogin()
 128  
     {
 129  0
         return "LAST_LOGIN";
 130  
     }
 131  
 
 132  
     /**
 133  
      * Fully qualified column used to record the last login time for
 134  
      * visitor.  Shouldn't need to override this as it uses the above
 135  
      * methods.
 136  
      *
 137  
      * @return A String.
 138  
      */
 139  
     public String getUser_LastLogin()
 140  
     {
 141  0
         return getTableUser() + '.' + getLastLogin();
 142  
     }
 143  
 
 144  
     /**
 145  
      * Column used to record the users username.  Override this if
 146  
      * using your custom table.
 147  
      *
 148  
      * @return A String.
 149  
      */
 150  
     public String getUsername()
 151  
     {
 152  0
         return "LOGIN_NAME";
 153  
     }
 154  
 
 155  
     /**
 156  
      * Fully qualified column used to record the visitors username.
 157  
      * Shouldn't need to override this as it uses the above methods.
 158  
      *
 159  
      * @return A String.
 160  
      */
 161  
     public String getUser_Username()
 162  
     {
 163  0
         return getTableUser() + '.' + getUsername();
 164  
     }
 165  
 
 166  
     /**
 167  
      * Column used to record the users password.  Override this if
 168  
      * using your custom table.
 169  
      *
 170  
      * @return A String.
 171  
      */
 172  
     public String getPassword()
 173  
     {
 174  0
         return "PASSWORD_VALUE";
 175  
     }
 176  
 
 177  
     /**
 178  
      * Fully qualified column used to record the visitors password.
 179  
      * Shouldn't need to override this as it uses the above methods.
 180  
      *
 181  
      * @return A String.
 182  
      */
 183  
     public String getUser_Password()
 184  
     {
 185  0
         return getTableUser() + '.' + getPassword();
 186  
     }
 187  
 
 188  
     /**
 189  
      * Column used to record general visitor data from a hashmap.
 190  
      * Override this if using your custom table.
 191  
      *
 192  
      * @return A String.
 193  
      */
 194  
     public String getObjectData()
 195  
     {
 196  0
         return "OBJECTDATA";
 197  
     }
 198  
 
 199  
     /**
 200  
      * Fully qualified column used to record general visitor data from
 201  
      * a hashmap.  Shouldn't need to override this as it uses the
 202  
      * above methods.
 203  
      *
 204  
      * @return A String.
 205  
      */
 206  
     public String getUser_ObjectData()
 207  
     {
 208  0
         return getTableUser() + '.' + getObjectData();
 209  
     }
 210  
 
 211  
     /**
 212  
      * Column used to store the user's first name.
 213  
      * Override this if using your custom table.
 214  
      *
 215  
      * @return A String.
 216  
      */
 217  
     public String getFirstName()
 218  
     {
 219  0
         return "FIRST_NAME";
 220  
     }
 221  
 
 222  
     /**
 223  
      * Fully qualified column used to store the user's last name.
 224  
      * Shouldn't need to override this as it uses the above methods.
 225  
      *
 226  
      * @return A String.
 227  
      */
 228  
     public String getUser_FirstName()
 229  
     {
 230  0
         return getTableUser() + '.' + getFirstName();
 231  
     }
 232  
 
 233  
     /**
 234  
      * Column used to store the user's last name.
 235  
      * Override this if using your custom table.
 236  
      *
 237  
      * @return A String.
 238  
      */
 239  
     public String getLastName()
 240  
     {
 241  0
         return "LAST_NAME";
 242  
     }
 243  
 
 244  
     /**
 245  
      * Fully qualified column used to store the user's last name.
 246  
      * Shouldn't need to override this as it uses the above methods.
 247  
      *
 248  
      * @return A String.
 249  
      */
 250  
     public String getUser_LastName()
 251  
     {
 252  0
         return getTableUser() + '.' + getLastName();
 253  
     }
 254  
 
 255  
     /**
 256  
      * Column used to store the user's data modification time.
 257  
      * Override this if using your custom table.
 258  
      *
 259  
      * @return A String.
 260  
      */
 261  
     public String getModified()
 262  
     {
 263  0
         return "MODIFIED";
 264  
     }
 265  
 
 266  
     /**
 267  
      * Fully qualified column used to store the user's data modification time.
 268  
      * Shouldn't need to override this as it uses the above methods.
 269  
      *
 270  
      * @return A String.
 271  
      */
 272  
     public String getUser_Modified()
 273  
     {
 274  0
         return getTableUser() + '.' + getModified();
 275  
     }
 276  
 
 277  
     /**
 278  
      * Column used to store the user's record cration time.
 279  
      * Override this if using your custom table.
 280  
      *
 281  
      * @return A String.
 282  
      */
 283  
     public String getCreated()
 284  
     {
 285  0
         return "CREATED";
 286  
     }
 287  
 
 288  
     /**
 289  
      * Fully qualified column used to store the user's record cration time.
 290  
      * Shouldn't need to override this as it uses the above methods.
 291  
      *
 292  
      * @return A String.
 293  
      */
 294  
     public String getUser_Created()
 295  
     {
 296  0
         return getTableUser() + '.' + getCreated();
 297  
     }
 298  
 
 299  
     /**
 300  
      * Column used to store the user's email.
 301  
      * Override this if using your custom table.
 302  
      *
 303  
      * @return A String.
 304  
      */
 305  
     public String getEmail()
 306  
     {
 307  0
         return "EMAIL";
 308  
     }
 309  
 
 310  
     /**
 311  
      * Fully qualified column used to store the user's email.
 312  
      * Shouldn't need to override this as it uses the above methods.
 313  
      *
 314  
      * @return A String.
 315  
      */
 316  
     public String getUser_Email()
 317  
     {
 318  0
         return getTableUser() + '.' + getEmail();
 319  
     }
 320  
 
 321  
     /**
 322  
      * Column used to store the user's confirmation flag.
 323  
      * Override this if using your custom table.
 324  
      *
 325  
      * @return A String.
 326  
      */
 327  
     public String getConfirmValue()
 328  
     {
 329  0
         return "CONFIRM_VALUE";
 330  
     }
 331  
 
 332  
     /**
 333  
      * Fully qualified column used to store the user's confirmation flag.
 334  
      * Shouldn't need to override this as it uses the above methods.
 335  
      *
 336  
      * @return A String.
 337  
      */
 338  
     public String getUser_ConfirmValue()
 339  
     {
 340  0
         return getTableUser() + '.' + getConfirmValue();
 341  
     }
 342  
 
 343  
     /**
 344  
      * Column used for the unique id to a Role.  Override this if
 345  
      * using your custom table
 346  
      *
 347  
      * @return A String.
 348  
      */
 349  
     public String getRoleId()
 350  
     {
 351  0
         return "ROLE_ID";
 352  
     }
 353  
 
 354  
     /**
 355  
      * Fully qualified column name for Role unique key.  Shouldn't
 356  
      * need to override this as it uses the above methods.
 357  
      *
 358  
      * @return A String.
 359  
      */
 360  
     public String getRole_RoleId()
 361  
     {
 362  0
         return getTableRole() + '.' + getRoleId();
 363  
     }
 364  
 
 365  
     /**
 366  
      * Column used for the name of Role.  Override this if using
 367  
      * your custom table.
 368  
      *
 369  
      * @return A String.
 370  
      */
 371  
     public String getRoleName()
 372  
     {
 373  0
         return "ROLE_NAME";
 374  
     }
 375  
 
 376  
     /**
 377  
      * Fully qualified column name for Role name.  Shouldn't need
 378  
      * to override this as it uses the above methods.
 379  
      *
 380  
      * @return A String.
 381  
      */
 382  
     public String getRole_Name()
 383  
     {
 384  0
         return getTableRole() + '.' + getRoleName();
 385  
     }
 386  
 
 387  
     /**
 388  
      * Fully qualified column name for ObjectData column.  Shouldn't need
 389  
      * to override this as it uses the above methods.
 390  
      *
 391  
      * @return A String.
 392  
      */
 393  
     public String getRole_ObjectData()
 394  
     {
 395  0
         return getTableRole() + '.' + getObjectData();
 396  
     }
 397  
 
 398  
     /**
 399  
      * Column used for the id of the Permission table.  Override this
 400  
      * if using your custom table.
 401  
      *
 402  
      * @return A String.
 403  
      */
 404  
     public String getPermissionId()
 405  
     {
 406  0
         return "PERMISSION_ID";
 407  
     }
 408  
 
 409  
     /**
 410  
      * Fully qualified column name for Permission table unique key.
 411  
      * Shouldn't need to override this as it uses the above methods.
 412  
      *
 413  
      * @return A String.
 414  
      */
 415  
     public String getPermission_PermissionId()
 416  
     {
 417  0
         return getTablePermission() + '.' + getPermissionId();
 418  
     }
 419  
 
 420  
     /**
 421  
      * Column used for the name of a Permission.  Override this if
 422  
      * using your custom table.
 423  
      *
 424  
      * @return A String.
 425  
      */
 426  
     public String getPermissionName()
 427  
     {
 428  0
         return "PERMISSION_NAME";
 429  
     }
 430  
 
 431  
     /**
 432  
      * Fully qualified column name for Permission table name of the
 433  
      * permission.  Shouldn't need to override this as it uses the
 434  
      * above methods.
 435  
      *
 436  
      * @return A String.
 437  
      */
 438  
     public String getPermission_Name()
 439  
     {
 440  0
         return getTablePermission() + '.' + getPermissionName();
 441  
     }
 442  
 
 443  
     /**
 444  
      * Fully qualified column name for ObjectData column.  Shouldn't need
 445  
      * to override this as it uses the above methods.
 446  
      *
 447  
      * @return A String.
 448  
      */
 449  
     public String getPermission_ObjectData()
 450  
     {
 451  0
         return getTablePermission() + '.' + getObjectData();
 452  
     }
 453  
 
 454  
     /**
 455  
      * Fully qualified column name for UserGroupRole visitor id.
 456  
      * Shouldn't need to override this as it uses the above methods.
 457  
      *
 458  
      * @return A String.
 459  
      */
 460  
     public String getUserGroupRole_UserId()
 461  
     {
 462  0
         return getTableUserGroupRole() + '.' + getUserId();
 463  
     }
 464  
 
 465  
     /**
 466  
      * Fully qualified column name for UserGroupRole group id.  Shouldn't
 467  
      * need to override this as it uses the above methods.
 468  
      *
 469  
      * @return A String.
 470  
      */
 471  
     public String getUserGroupRole_GroupId()
 472  
     {
 473  0
         return getTableUserGroupRole() + '.' + getGroupId();
 474  
     }
 475  
 
 476  
     /**
 477  
      * Fully qualified column name for UserGroupRole role id.  Shouldn't
 478  
      * need to override this as it uses the above methods.
 479  
      *
 480  
      * @return A String.
 481  
      */
 482  
     public String getUserGroupRole_RoleId()
 483  
     {
 484  0
         return getTableUserGroupRole() + '.' + getRoleId();
 485  
     }
 486  
 
 487  
     /**
 488  
      * Fully qualified column name for RolePermission permission id.
 489  
      * Shouldn't need to override this as it uses the above methods.
 490  
      *
 491  
      * @return A String.
 492  
      */
 493  
     public String getRolePermission_PermissionId()
 494  
     {
 495  0
         return getTableRolePermission() + '.' + getPermissionId();
 496  
     }
 497  
 
 498  
     /**
 499  
      * Fully qualified column name for RolePermission role id.
 500  
      * Shouldn't need to override this as it uses the above methods.
 501  
      *
 502  
      * @return A String.
 503  
      */
 504  
     public String getRolePermission_RoleId()
 505  
     {
 506  0
         return getTableRolePermission() + '.' + getRoleId();
 507  
     }
 508  
 
 509  
     /**
 510  
      * Column used for the id of the Group table.  Override this
 511  
      * if using your custom table.
 512  
      *
 513  
      * @return A String.
 514  
      */
 515  
     public String getGroupId()
 516  
     {
 517  0
         return "GROUP_ID";
 518  
     }
 519  
 
 520  
     /**
 521  
      * Fully qualified column name for Group id.  Shouldn't
 522  
      * need to override this as it uses the above methods.
 523  
      *
 524  
      * @return A String.
 525  
      */
 526  
     public String getGroup_GroupId()
 527  
     {
 528  0
         return getTableGroup() + '.' + getGroupId();
 529  
     }
 530  
 
 531  
     /**
 532  
      * Column used for the name of a Group.  Override this if using
 533  
      * your custom table.
 534  
      *
 535  
      * @return A String.
 536  
      */
 537  
     public String getGroupName()
 538  
     {
 539  0
         return "GROUP_NAME";
 540  
     }
 541  
 
 542  
     /**
 543  
      * Fully qualified column name for Group name.  Shouldn't
 544  
      * need to override this as it uses the above methods.
 545  
      *
 546  
      * @return A String.
 547  
      */
 548  
     public String getGroup_Name()
 549  
     {
 550  0
         return getTableGroup() + '.' + getGroupName();
 551  
     }
 552  
 
 553  
     /**
 554  
      * Fully qualified column name for ObjectData column.  Shouldn't need
 555  
      * to override this as it uses the above methods.
 556  
      *
 557  
      * @return A String.
 558  
      */
 559  
     public String getGroup_ObjectData()
 560  
     {
 561  0
         return getTableGroup() + '.' + getObjectData();
 562  
     }
 563  
 
 564  
     /**
 565  
      * GROUP_SEQUENCE.
 566  
      *
 567  
      * @return A String.
 568  
      */
 569  
     public String getSequenceGroup()
 570  
     {
 571  0
         return "GROUP_SEQUENCE";
 572  
     }
 573  
 
 574  
     /**
 575  
      * PERMISSION_SEQUENCE.
 576  
      *
 577  
      * @return A String.
 578  
      */
 579  
     public String getSequencePermission()
 580  
     {
 581  0
         return "PERMISSION_SEQUENCE";
 582  
     }
 583  
 
 584  
     /**
 585  
      * ROLE_SEQUENCE.
 586  
      *
 587  
      * @return A String.
 588  
      */
 589  
     public String getSequenceRole()
 590  
     {
 591  0
         return "ROLE_SEQUENCE";
 592  
     }
 593  
 
 594  
     /**
 595  
      * USER_SEQUENCE.
 596  
      *
 597  
      * @return A String.
 598  
      */
 599  
     public String getSequenceUser()
 600  
     {
 601  0
         return "USER_SEQUENCE";
 602  
     }
 603  
 
 604  
     /** The database map. */
 605  0
     protected DatabaseMap dbMap = null;
 606  
 
 607  
     /**
 608  
      * Tells us if this DatabaseMapBuilder is built so that we don't
 609  
      * have to re-build it every time.
 610  
      *
 611  
      * @return True if DatabaseMapBuilder is built.
 612  
      */
 613  
     public boolean isBuilt()
 614  
     {
 615  0
         return (dbMap != null);
 616  
     }
 617  
 
 618  
     /**
 619  
      * Gets the databasemap this map builder built.
 620  
      *
 621  
      * @return A DatabaseMap.
 622  
      */
 623  
     public DatabaseMap getDatabaseMap()
 624  
     {
 625  0
         return this.dbMap;
 626  
     }
 627  
 
 628  
     /**
 629  
      * Build up the databasemapping.  It should probably be modified
 630  
      * to read a .xml file representation of the database to build
 631  
      * this.
 632  
      *
 633  
      * @exception Exception a generic exception.
 634  
      */
 635  
     public void doBuild()
 636  
             throws Exception
 637  
     {
 638  
         // Reusable TableMap
 639  
         TableMap tMap;
 640  
 
 641  
         // Make some objects.
 642  0
         String string = "";
 643  0
         Integer integer = new Integer(0);
 644  0
         java.util.Date date = new Date();
 645  
 
 646  
         // Get default map.
 647  0
         dbMap = Torque.getDatabaseMap();
 648  
 
 649  
         // Add tables.
 650  0
         dbMap.addTable(getTableUser());
 651  0
         dbMap.addTable(getTableGroup());
 652  0
         dbMap.addTable(getTableRole());
 653  0
         dbMap.addTable(getTablePermission());
 654  0
         dbMap.addTable(getTableUserGroupRole());
 655  0
         dbMap.addTable(getTableRolePermission());
 656  
 
 657  
         // Add User columns.
 658  0
         tMap = dbMap.getTable(getTableUser());
 659  0
         tMap.setPrimaryKeyMethod(TableMap.ID_BROKER);
 660  0
         tMap.setPrimaryKeyMethodInfo(tMap.getName());
 661  0
         tMap.addPrimaryKey(getUserId(), integer);
 662  0
         tMap.addColumn(getUsername(), string);
 663  0
         tMap.addColumn(getPassword(), string);
 664  0
         tMap.addColumn(getFirstName(), string);
 665  0
         tMap.addColumn(getLastName(), string);
 666  0
         tMap.addColumn(getEmail(), string);
 667  0
         tMap.addColumn(getConfirmValue(), string);
 668  0
         tMap.addColumn(getCreated(), date);
 669  0
         tMap.addColumn(getModified(), date);
 670  0
         tMap.addColumn(getLastLogin(), date);
 671  0
         tMap.addColumn(getObjectData(), new Hashtable(1));
 672  
 
 673  
         // Add Group columns.
 674  0
         tMap = dbMap.getTable(getTableGroup());
 675  0
         tMap.setPrimaryKeyMethod(TableMap.ID_BROKER);
 676  0
         tMap.setPrimaryKeyMethodInfo(tMap.getName());
 677  0
         tMap.addPrimaryKey(getGroupId(), integer);
 678  0
         tMap.addColumn(getGroupName(), string);
 679  0
         tMap.addColumn(getObjectData(), new Hashtable(1));
 680  
 
 681  
         // Add Role columns.
 682  0
         tMap = dbMap.getTable(getTableRole());
 683  0
         tMap.setPrimaryKeyMethod(TableMap.ID_BROKER);
 684  0
         tMap.setPrimaryKeyMethodInfo(tMap.getName());
 685  0
         tMap.addPrimaryKey(getRoleId(), integer);
 686  0
         tMap.addColumn(getRoleName(), string);
 687  0
         tMap.addColumn(getObjectData(), new Hashtable(1));
 688  
 
 689  
         // Add Permission columns.
 690  0
         tMap = dbMap.getTable(getTablePermission());
 691  0
         tMap.setPrimaryKeyMethod(TableMap.ID_BROKER);
 692  0
         tMap.setPrimaryKeyMethodInfo(tMap.getName());
 693  0
         tMap.addPrimaryKey(getPermissionId(), integer);
 694  0
         tMap.addColumn(getPermissionName(), string);
 695  0
         tMap.addColumn(getObjectData(), new Hashtable(1));
 696  
 
 697  
         // Add RolePermission columns.
 698  0
         tMap = dbMap.getTable(getTableRolePermission());
 699  0
         tMap.addForeignPrimaryKey(getPermissionId(),
 700  
                 integer,
 701  
                 getTablePermission(),
 702  
                 getPermissionId());
 703  0
         tMap.addForeignPrimaryKey(getRoleId(),
 704  
                 integer,
 705  
                 getTableRole(),
 706  
                 getRoleId());
 707  
 
 708  
         // Add UserGroupRole columns.
 709  0
         tMap = dbMap.getTable(getTableUserGroupRole());
 710  0
         tMap.addForeignPrimaryKey(getUserId(),
 711  
                 integer,
 712  
                 getTableUser(),
 713  
                 getUserId());
 714  0
         tMap.addForeignPrimaryKey(getGroupId(),
 715  
                 integer,
 716  
                 getTableGroup(),
 717  
                 getGroupId());
 718  0
         tMap.addForeignPrimaryKey(getRoleId(),
 719  
                 integer,
 720  
                 getTableRole(),
 721  
                 getRoleId());
 722  0
     }
 723  
 }

This report is generated by jcoverage, Maven and Maven JCoverage Plugin.