KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > dods > trans > Table


1 /*
2  * Enhydra Java Application Server Project
3  *
4  * The contents of this file are subject to the Enhydra Public License
5  * Version 1.1 (the "License"); you may not use this file except in
6  * compliance with the License. You may obtain a copy of the License on
7  * the Enhydra web site ( http://www.enhydra.org/ ).
8  *
9  * Software distributed under the License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
11  * the License for the specific terms governing rights and limitations
12  * under the License.
13  *
14  * The Initial Developer of the Enhydra Application Server is Lutris
15  * Technologies, Inc. The Enhydra Application Server and portions created
16  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
17  * All Rights Reserved.
18  *
19  * Contributor(s):
20  *
21  * $Id: Table.java,v 1.1 2004/09/03 13:43:13 sinisa Exp $
22  */

23
24 /*
25  *
26  * @author Nenad Vico
27  * @since LBS1.8
28  * @version $Revision: 1.1 $
29  *
30  */

31 package org.enhydra.dods.trans;
32
33 import java.util.*;
34
35 /**
36  * This class represents database table.
37  */

38 public class Table {
39     
40     /**
41      * table package
42      */

43     protected String JavaDoc pckg = null;
44
45     /**
46      * author
47      */

48     protected String JavaDoc author = DefaultTagValues.TABLE_AUTHOR;
49
50     /**
51      * project name
52      */

53     protected String JavaDoc project_name = DefaultTagValues.TABLE_PROJECT_NAME;
54
55     /**
56      * table name
57      */

58     protected String JavaDoc table_name = null;
59
60     /**
61      * class name
62      */

63     protected String JavaDoc class_name = null;
64
65     /**
66      * database vendor
67      */

68     protected String JavaDoc db_vendor = DefaultTagValues.TABLE_DB_VENDOR;
69     private static final String JavaDoc PARVALUE_COMPATIBLE = "Compatible";
70     private static final String JavaDoc PARVALUE_DEPRECATE = "Deprecate";
71     private static final String JavaDoc PARVALUE_OMIT = "Omit";
72
73     /**
74      * How to generate dirty methods.
75      */

76     protected String JavaDoc dirtyDOs = PARVALUE_COMPATIBLE;
77
78     /**
79      * string match (string which represents LIKE in Standard database)
80      */

81     public static final String JavaDoc[] caching_value = {"none", "partial", "full",
82         "lru"};
83     public static final int NONE = 0;
84     public static final int PARTIAL = 1;
85     public static final int FULL = 2;
86     public static final int LRU = 3;
87
88     /**
89      * This variable contains information whether the table is
90      * based on OID primary key.
91      */

92     protected boolean do_is_oid_based = DefaultTagValues.DO_IS_OID_BASED;
93
94     /**
95      * This variable contains information whether the table need security methods.
96      */

97     protected boolean do_secure = DefaultTagValues.DO_SECURITY;
98
99     /**
100      * This variable contains information whether the table need unsecurity methods.
101      */

102     protected boolean do_insecure = DefaultTagValues.DO_NON_SECURITY;
103
104     /**
105      * This variable contains information whether the table can use multidb methods.
106      */

107     protected boolean do_multidb = DefaultTagValues.DO_MULTIDB;
108
109     /**
110      * This variable contains information whether the table is abstarct.
111      */

112     protected boolean is_abstract = false;
113
114     /**
115      * This variable contains information whether the table uses delete cascade capability.
116      */

117     protected boolean delete_cascade = false;
118     
119     /**
120      * This variable contains information whether the table uses class for 'mass-updates'.
121      */

122     protected boolean mass_updates = DefaultTagValues.MASS_UPDATES;
123
124     /**
125      * This variable contains information whether the table uses class for 'mass-deletes'.
126      */

127     protected boolean mass_deletes = DefaultTagValues.MASS_DELETES;
128
129     /**
130      * list of table columns
131      */

132     protected ArrayList columns = new ArrayList();
133
134     /**
135      * list of table referrers
136      */

137     protected HashMap referrers = new HashMap();
138
139     /**
140      * This variable contains information whether is any of table columns has secure methods.
141      */

142     protected boolean isAnyColumnSecure = DefaultTagValues.IS_ANY_COLUMN_SECURE;
143
144     /**
145      * list of table indexes
146      */

147     protected ArrayList indexes = new ArrayList();
148     
149     public Table(boolean genSecure, boolean genInsecure, String JavaDoc dirty) {
150         do_secure = genSecure;
151         do_insecure = genInsecure;
152         if (dirtyDOs != null) {
153             dirtyDOs = dirty;
154         }
155     }
156      
157     public Table() {}
158       
159     // ------------------------- get methodes -----------------------------
160
/**
161      * Get table package.
162      *
163      * @return Table package.
164      */

165     public String JavaDoc pckg() {
166         return pckg;
167     }
168
169     /**
170      * Get author.
171      *
172      * @return Author.
173      */

174     public String JavaDoc author() {
175         return author;
176     }
177    
178     /**
179      * Get project name.
180      *
181      * @return Project name.
182      */

183     public String JavaDoc projectName() {
184         return project_name;
185     }
186
187     /**
188      * Get table name.
189      *
190      * @return Table name.
191      */

192     public String JavaDoc tableName() {
193         return table_name;
194     }
195
196     /**
197      * Get class name.
198      *
199      * @return Class name.
200      */

201     public String JavaDoc className() {
202         return class_name;
203     }
204
205     /**
206      * Get database vendor.
207      *
208      * @return Database vendor.
209      */

210     public String JavaDoc dbVendor() {
211         return db_vendor;
212     }
213
214     /**
215      * Get the information whether DO is OID based.
216      *
217      * @return True if DO is OID based, otherwise false.
218      */

219     public boolean doIsOidBased() {
220         return do_is_oid_based;
221     }
222
223     /**
224      * Get the information whether DO has security methods.
225      *
226      * @return True if DO is security based, otherwise false.
227      */

228     public boolean doSecure() {
229         return do_secure;
230     }
231
232     /**
233      * Get the information whether DO has security methods.
234      *
235      * @return True if DO is unsecurity based, otherwise false.
236      */

237     public boolean doInSecure() {
238         return do_insecure;
239     }
240
241     /**
242      * Get the information whether DO has multidb methods.
243      *
244      * @return True if DO is multidb based, otherwise false.
245      */

246     public boolean doMultidb() {
247         return do_multidb;
248     }
249
250     /**
251      * Get the information whether table has mass-updates class.
252      *
253      * @return True if Update class will be generated, otherwise false.
254      */

255     public boolean doMassUpdates() {
256         return mass_updates;
257     }
258
259     /**
260      * Get the information whether table has mass-deletes class.
261      *
262      * @return True if Delete class will be generated, otherwise false.
263      */

264     public boolean doMassDeletes() {
265         return mass_deletes;
266     }
267
268
269     /**
270      * Get the information whether table is abstarct.
271      *
272      * @return True if table is abstarct, otherwise false.
273      */

274     public boolean isAbstract() {
275         return is_abstract;
276     }
277
278     /**
279      * Get the information is any table column secure based.
280      *
281      * @return True if table is abstarct, otherwise false.
282      */

283     public boolean isAnyColumnSecure() {
284         return isAnyColumnSecure;
285     }
286
287     /**
288      * Get the information whether table uses delete cascade.
289      *
290      * @return True if table uses delete cascade, otherwise false.
291      */

292     public boolean deleteCascade() {
293         return delete_cascade;
294     }
295
296     /**
297      * Get list of columns.
298      *
299      * @return List of columns.
300      */

301     public ArrayList columns() {
302         return columns;
303     }
304
305     /**
306      * Get number of columns.
307      *
308      * @return Number of columns.
309      */

310     public int columnsSize() {
311         return columns.size();
312     }
313
314     /**
315      * Get column with given index.
316      *
317      * @param index Index of desired column.
318      *
319      * @return Column with given index.
320      */

321     public Column column(int index) {
322         return (Column) columns.get(index);
323     }
324
325     /**
326      * Get referrers.
327      *
328      * @return Referrers.
329      */

330     public HashMap referrers() {
331         return referrers;
332     }
333
334     /**
335      * Get number of referrers.
336      *
337      * @return Number of referrers.
338      */

339     public int referrersSize() {
340         return referrers.size();
341     }
342
343     /**
344      * Get entitySet iterator of referrers.
345      *
346      * @return entitySet Iterator of referrers.
347      */

348     public Iterator referrersIterator() {
349         return referrers.entrySet().iterator();
350     }
351
352     /**
353      * Get key iterator of referrers.
354      *
355      * @return key Iterator of referrers.
356      */

357     public Iterator referrersKeyIterator() {
358         return referrers.keySet().iterator();
359     }
360
361     /**
362      * Get value of iterator of referrers.
363      *
364      * @return value Value of iterator of referrers.
365      */

366     public Iterator referrersValueIterator() {
367         return referrers.values().iterator();
368     }
369
370     /**
371      * Get value of collection of referrers.
372      *
373      * @return value Value of iterator of referrers.
374      */

375     public Collection referrersValues() {
376         return referrers.values();
377     }
378
379     /**
380      * Get list of indexes.
381      *
382      * @return List of indexes.
383      */

384     public ArrayList indexes() {
385         return indexes;
386     }
387
388     /**
389      * Get number of indexes.
390      *
391      * @return Number of indexes.
392      */

393     public int indexesSize() {
394         return indexes.size();
395     }
396
397     /**
398      * Get index with given index.
399      *
400      * @return Index with given index.
401      */

402     public Index index(int index) {
403         return (Index) indexes.get(index);
404     }
405
406     // ------------------------- set methodes -----------------------------
407
/**
408      * Set table package.
409      *
410      * @param pckg Table package.
411      */

412     public void pckg(String JavaDoc pckg) {
413         this.pckg = pckg;
414     }
415
416     /**
417      * Set author.
418      *
419      * @param author Author.
420      */

421     public void author(String JavaDoc author) {
422         this.author = author;
423     }
424
425     /**
426      * Set project name.
427      *
428      * @param project_name Project name.
429      */

430     public void projectName(String JavaDoc project_name) {
431         this.project_name = project_name;
432     }
433
434     /**
435      * Set table name.
436      *
437      * @param table_name Table name.
438      */

439     public void tableName(String JavaDoc table_name) {
440         this.table_name = table_name;
441     }
442
443     /**
444      * Set class name.
445      *
446      * @param class_name Class name.
447      */

448     public void className(String JavaDoc class_name) {
449         this.class_name = class_name;
450     }
451
452     /**
453      * Set database vendor.
454      *
455      * @param db_vendor Database vendor.
456      */

457     public void dbVendor(String JavaDoc db_vendor) {
458         this.db_vendor = db_vendor;
459     }
460
461     /**
462      * Set DO to/not to be OID based.
463      *
464      * @param do_is_oid_based True if DO is OID based, otherwise false.
465      */

466     public void doIsOidBased(boolean do_is_oid_based) {
467         this.do_is_oid_based = do_is_oid_based;
468     }
469
470     /**
471      * Set DO to/not to have security methods.
472      *
473      * @param do_secure True if DO need security methods, otherwise false.
474      */

475     public void doSecure(boolean do_secure) {
476         this.do_secure = do_secure;
477     }
478
479     /**
480      * Set DO to/not to have security methods.
481      *
482      * @param do_Insecure True if DO need unsecurity methods, otherwise false.
483      */

484     public void doInSecure(boolean do_Insecure) {
485         this.do_insecure = do_Insecure;
486     }
487
488     /**
489      * Set table to/not to have Update class.
490      *
491      * @param do_mass True if table need mass-updates methods, otherwise false.
492      */

493     public void doMassUpdates(boolean do_mass) {
494         this.mass_updates = do_mass;
495     }
496
497     /**
498      * Set table to/not to have Delete class.
499      *
500      * @param do_mass True if table need mass-deletes methods, otherwise false.
501      */

502     public void doMassDeletes(boolean do_mass) {
503         this.mass_deletes = do_mass;
504     }
505     /**
506      * Set DO to/not to have multidb methods.
507      *
508      * @param do_Multidb True if DO has multidb methods, otherwise false.
509      */

510     public void doMultidb(boolean do_Multidb) {
511         this.do_multidb = do_Multidb;
512     }
513
514     /**
515      * Set table to/not to be abstarct.
516      *
517      * @param is_abstract True if table is abstarct, otherwise false.
518      */

519     public void isAbstract(boolean is_abstract) {
520         this.is_abstract = is_abstract;
521     }
522
523     /**
524      * Set value if any table column secure based.
525      *
526      * @param value True if table is abstarct, otherwise false.
527      */

528     public void anyColumnSecure(boolean value) {
529         this.isAnyColumnSecure = value;
530     }
531
532     /**
533      * Set table to/not use delete cascade.
534      *
535      * @param delete_cascade True if table uses delete cascade, otherwise false.
536      */

537     public void refConstarint(boolean delete_cascade) {
538         this.delete_cascade = delete_cascade;
539     }
540
541     /**
542      * Set list of columns.
543      *
544      * @param columns List of columns.
545      */

546     public void columns(ArrayList columns) {
547         this.columns = columns;
548     }
549
550     /**
551      * Add column into table.
552      *
553      * @param column Column which will be added.
554      */

555     public void addColumn(Column column) {
556         columns.add(column);
557     }
558
559     /**
560      * Set referrers.
561      *
562      * @param referrers New referrers of table.
563      */

564     public void referrers(HashMap referrers) {
565         this.referrers = referrers;
566     }
567
568     /**
569      * Add index into table.
570      *
571      * @param index Index which will be added to table.
572      */

573     public void addIndex(Index index) {
574         indexes.add(index);
575     }
576
577     /**
578      * Set indexes.
579      *
580      * @param indexes New indexes of table.
581      */

582     public void indexes(ArrayList indexes) {
583         this.indexes = indexes;
584     }
585
586     /**
587      * Add referrer into table.
588      *
589      * @param referrer Referrer which will be added.
590      *
591      * @return True if referrer is added, otherwise false.
592      */

593     public boolean addReferrer(Referrer referrer) {
594         String JavaDoc id = referrer.pckg() + "." + referrer.name();
595         boolean inserted = !referrers.containsKey(id);
596
597         if (inserted) {
598             referrers.put(id, referrer);
599         }
600         return inserted;
601     }
602
603     /**
604      * Sets String specifying what to do with dirty DO methods
605      *
606      * @param howToGenerate - can be "Compatble", "Deprecate", "Omit"
607      */

608     public void setDirtyDOs(String JavaDoc howToGenerate)throws InvalidDomlException {
609         if ((0 != howToGenerate.compareTo(PARVALUE_COMPATIBLE))
610                 && (0 != howToGenerate.compareTo(PARVALUE_DEPRECATE))
611                 && (0 != howToGenerate.compareTo(PARVALUE_OMIT))) {
612             throw new InvalidDomlException ("DirtyDOs out of range!");
613         }
614         dirtyDOs = howToGenerate;
615     }
616
617     /**
618      * @return String specifying what to do with dirty DO methods
619      */

620     public String JavaDoc getDirtyDOs() {
621         return dirtyDOs;
622     }
623
624     /**
625      * Get string representation.
626      *
627      * @return String representation.
628      */

629     public String JavaDoc toString() {
630         StringBuffer JavaDoc ret = new StringBuffer JavaDoc("package=").append(pckg).append(" author=").append(author);
631
632         ret.append(" project_name=").append(project_name).append(" table_name=").append(table_name);
633         ret.append(" class_name=").append(class_name).append(" db_vendor=").append(db_vendor);
634         ret.append(" do_is_oid_based=").append(do_is_oid_based).append(" is_abstract=").append(is_abstract);
635         ret.append(" delete_cascade=").append(delete_cascade);
636         ret.append(" do_secure=").append(do_secure);
637         ret.append(" do_insecure=").append(do_insecure);
638         ret.append("\ncolumns:\n");
639         for (int i = 0; i < columns.size(); i++) {
640             ret.append(" column=").append(columns.get(i)).append("\n");
641         }
642         ret.append(":referrers:\n");
643         Iterator iter = referrers.values().iterator();
644
645         while (iter.hasNext()) {
646             ret.append(" referrer=").append(iter.next()).append("\n");
647         }
648         ret.append("\nindexess:\n");
649         for (int i = 0; i < indexes.size(); i++) {
650             ret.append(" index=").append(indexes.get(i)).append("\n");
651         }
652         return ret.toString();
653     }
654
655     public static void main(String JavaDoc[] args) {
656         Table table = new Table();
657
658         table.pckg("packag0.package1");
659         table.tableName("Person");
660         Column column1 = new Column();
661         Column column2 = new Column();
662
663         column1.name("name");
664         column1.name("surname");
665         table.addColumn(column1);
666         table.addColumn(column2);
667         Referrer referrer1 = new Referrer("package0.package1", "Person");
668
669         referrer1.addAttribute("Manager", "package0.package1.Manager", false);
670         referrer1.addAttribute("Employee", "package0.package1.Employee", false);
671         Referrer referrer2 = new Referrer("package0.package1", "Manager");
672
673         referrer2.addAttribute("Employee", "package0.package1.Employee", false);
674         table.addReferrer(referrer1);
675         table.addReferrer(referrer2);
676         System.out.println("Table: \n" + table);
677     }
678 }
679
Popular Tags