KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > turbine > util > db > map > TurbineMapBuilder


1 package org.apache.turbine.util.db.map;
2
3 /*
4  * Copyright 2001-2004 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 JavaDoc;
20 import java.util.Hashtable JavaDoc;
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,v 1.8.2.2 2004/05/20 03:20:18 seade Exp $
36  */

37 public class TurbineMapBuilder implements MapBuilder
38 {
39     /**
40      * Get the User table.
41      *
42      * @return A String.
43      */

44     public String JavaDoc getTableUser()
45     {
46         return "TURBINE_USER";
47     }
48
49     /**
50      * Get the UserRole table.
51      *
52      * @return A String.
53      */

54     public String JavaDoc getTableRole()
55     {
56         return "TURBINE_ROLE";
57     }
58
59     /**
60      * Get the Permission table.
61      *
62      * @return A String.
63      */

64     public String JavaDoc getTablePermission()
65     {
66         return "TURBINE_PERMISSION";
67     }
68
69     /**
70      * Get the UserGroupRole table.
71      *
72      * @return A String.
73      */

74     public String JavaDoc getTableUserGroupRole()
75     {
76         return "TURBINE_USER_GROUP_ROLE";
77     }
78
79     /**
80      * Get the RolePermission table.
81      *
82      * @return A String.
83      */

84     public String JavaDoc getTableRolePermission()
85     {
86         return "TURBINE_ROLE_PERMISSION";
87     }
88
89     /**
90      * Get the Group table.
91      *
92      * @return A String.
93      */

94     public String JavaDoc getTableGroup()
95     {
96         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 JavaDoc getUserId()
106     {
107         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 JavaDoc getUser_UserId()
117     {
118         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 JavaDoc getLastLogin()
128     {
129         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 JavaDoc getUser_LastLogin()
140     {
141         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 JavaDoc getUsername()
151     {
152         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 JavaDoc getUser_Username()
162     {
163         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 JavaDoc getPassword()
173     {
174         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 JavaDoc getUser_Password()
184     {
185         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 JavaDoc getObjectData()
195     {
196         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 JavaDoc getUser_ObjectData()
207     {
208         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 JavaDoc getFirstName()
218     {
219         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 JavaDoc getUser_FirstName()
229     {
230         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 JavaDoc getLastName()
240     {
241         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 JavaDoc getUser_LastName()
251     {
252         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 JavaDoc getModified()
262     {
263         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 JavaDoc getUser_Modified()
273     {
274         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 JavaDoc getCreated()
284     {
285         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 JavaDoc getUser_Created()
295     {
296         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 JavaDoc getEmail()
306     {
307         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 JavaDoc getUser_Email()
317     {
318         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 JavaDoc getConfirmValue()
328     {
329         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 JavaDoc getUser_ConfirmValue()
339     {
340         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 JavaDoc getRoleId()
350     {
351         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 JavaDoc getRole_RoleId()
361     {
362         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 JavaDoc getRoleName()
372     {
373         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 JavaDoc getRole_Name()
383     {
384         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 JavaDoc getRole_ObjectData()
394     {
395         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 JavaDoc getPermissionId()
405     {
406         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 JavaDoc getPermission_PermissionId()
416     {
417         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 JavaDoc getPermissionName()
427     {
428         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 JavaDoc getPermission_Name()
439     {
440         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 JavaDoc getPermission_ObjectData()
450     {
451         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 JavaDoc getUserGroupRole_UserId()
461     {
462         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 JavaDoc getUserGroupRole_GroupId()
472     {
473         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 JavaDoc getUserGroupRole_RoleId()
483     {
484         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 JavaDoc getRolePermission_PermissionId()
494     {
495         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 JavaDoc getRolePermission_RoleId()
505     {
506         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 JavaDoc getGroupId()
516     {
517         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 JavaDoc getGroup_GroupId()
527     {
528         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 JavaDoc getGroupName()
538     {
539         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 JavaDoc getGroup_Name()
549     {
550         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 JavaDoc getGroup_ObjectData()
560     {
561         return getTableGroup() + '.' + getObjectData();
562     }
563
564     /**
565      * GROUP_SEQUENCE.
566      *
567      * @return A String.
568      */

569     public String JavaDoc getSequenceGroup()
570     {
571         return "GROUP_SEQUENCE";
572     }
573
574     /**
575      * PERMISSION_SEQUENCE.
576      *
577      * @return A String.
578      */

579     public String JavaDoc getSequencePermission()
580     {
581         return "PERMISSION_SEQUENCE";
582     }
583
584     /**
585      * ROLE_SEQUENCE.
586      *
587      * @return A String.
588      */

589     public String JavaDoc getSequenceRole()
590     {
591         return "ROLE_SEQUENCE";
592     }
593
594     /**
595      * USER_SEQUENCE.
596      *
597      * @return A String.
598      */

599     public String JavaDoc getSequenceUser()
600     {
601         return "USER_SEQUENCE";
602     }
603
604     /** The database map. */
605     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         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         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 JavaDoc
637     {
638         // Reusable TableMap
639
TableMap tMap;
640
641         // Make some objects.
642
String JavaDoc string = new String JavaDoc("");
643         Integer JavaDoc integer = new Integer JavaDoc(0);
644         java.util.Date JavaDoc date = new Date JavaDoc();
645
646         // Get default map.
647
dbMap = Torque.getDatabaseMap();
648
649         // Add tables.
650
dbMap.addTable(getTableUser());
651         dbMap.addTable(getTableGroup());
652         dbMap.addTable(getTableRole());
653         dbMap.addTable(getTablePermission());
654         dbMap.addTable(getTableUserGroupRole());
655         dbMap.addTable(getTableRolePermission());
656
657         // Add User columns.
658
tMap = dbMap.getTable(getTableUser());
659         tMap.setPrimaryKeyMethod(TableMap.ID_BROKER);
660         tMap.setPrimaryKeyMethodInfo(tMap.getName());
661         tMap.addPrimaryKey(getUserId(), integer);
662         tMap.addColumn(getUsername(), string);
663         tMap.addColumn(getPassword(), string);
664         tMap.addColumn(getFirstName(), string);
665         tMap.addColumn(getLastName(), string);
666         tMap.addColumn(getEmail(), string);
667         tMap.addColumn(getConfirmValue(), string);
668         tMap.addColumn(getCreated(), date);
669         tMap.addColumn(getModified(), date);
670         tMap.addColumn(getLastLogin(), date);
671         tMap.addColumn(getObjectData(), new Hashtable JavaDoc(1));
672
673         // Add Group columns.
674
tMap = dbMap.getTable(getTableGroup());
675         tMap.setPrimaryKeyMethod(TableMap.ID_BROKER);
676         tMap.setPrimaryKeyMethodInfo(tMap.getName());
677         tMap.addPrimaryKey(getGroupId(), integer);
678         tMap.addColumn(getGroupName(), string);
679         tMap.addColumn(getObjectData(), new Hashtable JavaDoc(1));
680
681         // Add Role columns.
682
tMap = dbMap.getTable(getTableRole());
683         tMap.setPrimaryKeyMethod(TableMap.ID_BROKER);
684         tMap.setPrimaryKeyMethodInfo(tMap.getName());
685         tMap.addPrimaryKey(getRoleId(), integer);
686         tMap.addColumn(getRoleName(), string);
687         tMap.addColumn(getObjectData(), new Hashtable JavaDoc(1));
688
689         // Add Permission columns.
690
tMap = dbMap.getTable(getTablePermission());
691         tMap.setPrimaryKeyMethod(TableMap.ID_BROKER);
692         tMap.setPrimaryKeyMethodInfo(tMap.getName());
693         tMap.addPrimaryKey(getPermissionId(), integer);
694         tMap.addColumn(getPermissionName(), string);
695         tMap.addColumn(getObjectData(), new Hashtable JavaDoc(1));
696
697         // Add RolePermission columns.
698
tMap = dbMap.getTable(getTableRolePermission());
699         tMap.addForeignPrimaryKey(getPermissionId(),
700                 integer,
701                 getTablePermission(),
702                 getPermissionId());
703         tMap.addForeignPrimaryKey(getRoleId(),
704                 integer,
705                 getTableRole(),
706                 getRoleId());
707
708         // Add UserGroupRole columns.
709
tMap = dbMap.getTable(getTableUserGroupRole());
710         tMap.addForeignPrimaryKey(getUserId(),
711                 integer,
712                 getTableUser(),
713                 getUserId());
714         tMap.addForeignPrimaryKey(getGroupId(),
715                 integer,
716                 getTableGroup(),
717                 getGroupId());
718         tMap.addForeignPrimaryKey(getRoleId(),
719                 integer,
720                 getTableRole(),
721                 getRoleId());
722     }
723 }
724
Popular Tags