KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > jdo > spi > persistence > support > sqlstore > model > TableDesc


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /*
25  * TableDesc.java
26  *
27  * Created on March 3, 2000
28  *
29  */

30
31 package com.sun.jdo.spi.persistence.support.sqlstore.model;
32
33 import org.netbeans.modules.dbschema.TableElement;
34 import com.sun.jdo.api.persistence.model.mapping.MappingClassElement;
35 import java.util.ArrayList JavaDoc;
36
37 /**
38  * This class is used to represent a database table.
39  */

40 public class TableDesc {
41
42     /** primary key for the table */
43     private KeyDesc key;
44
45     /** array of ReferenceKeyDescs referencing secondary tables */
46     private ArrayList JavaDoc secondaryTableKeys;
47
48     /** ReferenceKeyDesc referencing the primary table */
49     private ReferenceKeyDesc primaryTableKey;
50
51     /** actual TableElement from the dbmodel */
52     private TableElement tableElement;
53
54     /** Consistency level for this table defined in the model */
55     private int consistencyLevel;
56
57     /** indicates this table is a join table */
58     private boolean isJoinTable;
59
60     /** Name of the table */
61     private String JavaDoc name;
62
63     /** Version field used for version consistency */
64     private LocalFieldDesc versionField;
65
66     public TableDesc(TableElement tableElement) {
67         this.tableElement = tableElement;
68
69         name = tableElement.getName().getName();
70         consistencyLevel = MappingClassElement.NONE_CONSISTENCY;
71     }
72
73     /** Return all secondary table keys.
74      * @return an ArrayList of ReferenceKeyDescs for secondary tables
75      */

76     public ArrayList JavaDoc getSecondaryTableKeys() {
77         return secondaryTableKeys;
78     }
79
80     /** Add a new reference key to the list of secondary table keys.
81      * @param key - ReferenceKeyDesc to be added
82      */

83     void addSecondaryTableKey(ReferenceKeyDesc key) {
84         if (secondaryTableKeys == null)
85             secondaryTableKeys = new ArrayList JavaDoc();
86
87         secondaryTableKeys.add(key);
88     }
89
90     /** Return the reference key referencing the primary table.
91      * @return the ReferenceKeyDesc referencing the primary table
92      */

93     public ReferenceKeyDesc getPrimaryTableKey() {
94         return primaryTableKey;
95     }
96
97     /** Set the reference key referencing the primary table.
98      * @param key - ReferenceKeyDesc to be added
99      */

100     void setPrimaryTableKey(ReferenceKeyDesc key) {
101         this.primaryTableKey = key;
102     }
103
104     /** Return the primary key for the table.
105      * @return the KeyDesc representing the primary key for the table
106      */

107     public KeyDesc getKey() {
108         return key;
109     }
110
111     /** Set the primary key for the table.
112      * @param key - KeyDesc to be set as the primary key
113      */

114     void setKey(KeyDesc key) {
115         this.key = key;
116     }
117
118     /** Return the actual dbmodel TableElement for this table.
119      * @return TableElement associated with this table
120      */

121     public TableElement getTableElement() {
122         return tableElement;
123     }
124
125     /** Return the name of the table.
126      * @return the name of the table.
127      */

128     public String JavaDoc getName() {
129         return name;
130     }
131
132     /** Return true if this table is a join table. */
133     public boolean isJoinTable() {
134         return isJoinTable;
135     }
136
137     /** Set consistencyLevel to value. */
138     void setConsistencyLevel(int value) {
139         consistencyLevel = value;
140         //TODO :
141
//if(isUpdateLockRequired() )
142
//Check for DBVendorType.isUpdateLockSupported()
143
//Log to trace if !DBVendorType.isUpdateLockSupported()
144
//If this table is ever used, user would get an exception
145

146     }
147
148     /** Determins if an update lock is required on this table. */
149     public boolean isUpdateLockRequired() {
150         return consistencyLevel == MappingClassElement.LOCK_WHEN_LOADED_CONSISTENCY;
151     }
152
153     /** Set isJoinTable to value */
154     void setJoinTable(boolean value) {
155         isJoinTable = value;
156     }
157
158     void setVersionField(LocalFieldDesc field) {
159         versionField = field;
160     }
161
162     /**
163      * Returns the field representing the version column for this
164      * table. The version column is used for verification with version
165      * consistency. Each table can have only one version column.
166      *
167      * @return Version field.
168      */

169     public LocalFieldDesc getVersionField() {
170         return versionField;
171     }
172
173 }
174
175
176
177
178
179
Popular Tags