View Javadoc

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