KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > jdo > api > persistence > model > mapping > MappingClassElement


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  * MappingClassElement.java
26  *
27  * Created on March 3, 2000, 1:11 PM
28  */

29
30 package com.sun.jdo.api.persistence.model.mapping;
31
32 import java.util.List JavaDoc;
33 import java.util.ArrayList JavaDoc;
34
35 import org.netbeans.modules.dbschema.TableElement;
36 import org.netbeans.modules.dbschema.SchemaElement;
37
38 import com.sun.jdo.api.persistence.model.ModelException;
39
40 /**
41  *
42  * @author raccah
43  * @version %I%
44  */

45 public interface MappingClassElement extends MappingElement
46 {
47     /** Constant representing mapping file extension. */
48     public static final String JavaDoc MAPPING_EXTENSION = "mapping"; // NOI18N
49

50     /** Constant representing Consistency level.
51      * NONE_CONSISTENCY implies that no consistency semantics are enforced.
52      */

53     public static final int NONE_CONSISTENCY = 0x0;
54
55     /** Constant representing Consistency level.
56      * CHECK_MODIFIED_AT_COMMIT_CONSISTENCY implies that at commit,
57      * consistency check is enforced for all fetched fields of modified
58      * objects.
59      */

60     public static final int CHECK_MODIFIED_AT_COMMIT_CONSISTENCY = 0x1;
61
62     /** Constant representing Consistency level.
63      * CHECK_ALL_AT_COMMIT_CONSISTENCY implies that at commit, consistency
64      * check is enforced for all the fields of objects at this consistency
65      * level.
66      * Please note that this level is not supported in the current release.
67      */

68     public static final int CHECK_ALL_AT_COMMIT_CONSISTENCY = 0x2;
69
70     /** Constant representing Consistency level.
71      * LOCK_WHEN_MODIFIED_CONSISTENCY implies exclusive lock is obtained for
72      * data corresponding to this object when an attempt to modify the object
73      * is made.
74      * Please note that this level is not supported in the current release.
75      */

76     public static final int LOCK_WHEN_MODIFIED_CONSISTENCY = 0x4;
77
78     /** Constant representing Consistency level.
79      * LOCK_WHEN_MODIFIED_CHECK_ALL_AT_COMMIT_CONSISTENCY implies exclusive
80      * lock is obtained for data corresponding to this object when an attempt
81      * to modify the object is made. Also at commit, consistency check is
82      * enforced for all the fields of objects at this consistency level.
83      * Please note that this level is not supported in the current release.
84      */

85     public static final int LOCK_WHEN_MODIFIED_CHECK_ALL_AT_COMMIT_CONSISTENCY =
86         CHECK_ALL_AT_COMMIT_CONSISTENCY | LOCK_WHEN_MODIFIED_CONSISTENCY;
87
88     /** Constant representing Consistency level.
89      * LOCK_WHEN_LOADED_CONSISTENCY implies that exclusive lock is
90      * obtained for data corresponding to this object before accessing it.
91      */

92     public static final int LOCK_WHEN_LOADED_CONSISTENCY = 0x8;
93
94     /** Constant representing Consistency level.
95      * VERSION_CONSISTENCY implies that no lock is obtained for data
96      * corresponding to this object until it will be updated.
97      */

98     public static final int VERSION_CONSISTENCY = 0x10;
99
100     // TBD
101
// clears out fields -- equiv to new, can take it out
102
// public void clear ();
103
// public boolean mapFieldToTable (MappingFieldElement field,
104
// TableElement table);
105

106     /** Returns the version number of this MappingClassElement object.
107      * Please note, the returned version number reflects the version number at
108      * the last save, NOT the version number of the memory representation.
109      * @return version number
110      */

111     public int getVersionNumber ();
112
113     /** Returns true if the version number of this MappingClassElement object
114      * is older than the current version number of the archiving scheme.
115      * @see #getVersionNumber
116      * @return true if it is in need of updating, false otherwise
117      */

118     public boolean hasOldVersionNumber ();
119
120     /** This method is called after a MappingClassElement is unarchived
121      * from a .mapping file. This method provides a hook to do any checking
122      * (version number checking) and conversion after unarchiving.
123      * @exception ModelException if impossible
124      */

125     public void postUnarchive () throws ModelException;
126     
127     /** This method is called prior to storing a MappingClassElement in a
128      * .mapping file. This method provides a hook to do any conversion
129      * before archiving.
130      * @exception ModelException if impossible
131      */

132     public void preArchive () throws ModelException;
133
134     /** Gets the modified flag for this mapping class.
135      * @return <code>true</code> if there have been (property) changes to this
136      * class, <code>false</code> otherwise.
137      */

138     public boolean isModified ();
139
140     /** Set the modified flag for this mapping class to flag. This is usually
141      * set to <code>true</code> by property changes and <code>false</code>
142      * after a save.
143      * @param flag if <code>true</code>, this class is marked as modified;
144      * if <code>false</code>, it is marked as unmodified.
145      */

146     public void setModified (boolean flag);
147
148     /** Gets the consistency level of this mapping class.
149      * @return the consistency level, one of {@link #NONE_CONSISTENCY},
150      * {@link #CHECK_MODIFIED_AT_COMMIT_CONSISTENCY},
151      * {@link #CHECK_ALL_AT_COMMIT_CONSISTENCY},
152      * {@link #LOCK_WHEN_MODIFIED_CONSISTENCY},
153      * {@link #LOCK_WHEN_MODIFIED_CHECK_ALL_AT_COMMIT_CONSISTENCY},
154      * {@link #LOCK_WHEN_LOADED_CONSISTENCY}, or
155      * {@link #VERSION_CONSISTENCY}.
156      */

157     public int getConsistencyLevel ();
158
159     /** Set the consistency level of this mapping class.
160      * @param level an integer indicating the consistency level, one of:
161      * {@link #NONE_CONSISTENCY},{@link #CHECK_MODIFIED_AT_COMMIT_CONSISTENCY},
162      * {@link #CHECK_ALL_AT_COMMIT_CONSISTENCY},
163      * {@link #LOCK_WHEN_MODIFIED_CONSISTENCY},
164      * {@link #LOCK_WHEN_MODIFIED_CHECK_ALL_AT_COMMIT_CONSISTENCY},
165      * {@link #LOCK_WHEN_LOADED_CONSISTENCY}, or
166      * {@link #VERSION_CONSISTENCY}.
167      * @exception ModelException if impossible.
168      */

169     public void setConsistencyLevel (int level) throws ModelException;
170
171     //======================= schema handling ===========================
172

173     /** Returns the name of the SchemaElement which represents the
174      * database used by the tables mapped to this mapping class element.
175      * @return the name of the database root for this mapping class
176      */

177     public String JavaDoc getDatabaseRoot ();
178
179     /** Set the database root for this MappingClassElement.
180      * The root represents the database used by the tables mapped to
181      * this mapping class.
182      * @param root the new database root
183      * @exception ModelException if impossible
184      */

185     public void setDatabaseRoot (SchemaElement root) throws ModelException;
186
187     //======================= table handling ===========================
188

189     /** Returns the list of tables (MappingTableElements) used by this mapping
190      * class.
191      * @return the meta data tables for this mapping class
192      */

193     public ArrayList JavaDoc getTables ();
194
195     /** Scans through this mapping class looking for a table whose
196      * name matches the name passed in.
197      * @param name name of the table to find.
198      * @return the meta data table whose name matches the name parameter
199      */

200     public MappingTableElement getTable (String JavaDoc name);
201
202     /** Convenience method which accepts a table element and attempts to add
203      * it as either a primary or secondary table depending on the existing list
204      * of tables and the foreign keys for the table.
205      * @param table table element to be added as either a primary or secondary
206      * table.
207      * @exception ModelException if impossible
208      */

209     public void addTable (TableElement table) throws ModelException;
210
211     /** Set the primary table for this mapping class to the supplied table.
212      * @param table table element to be used as the primary table.
213      * @exception ModelException if impossible
214      */

215     public void setPrimaryTable (TableElement table) throws ModelException;
216
217     /** Adds a reference to the supplied table as a secondary table for this
218      * mapping class. It creates a MappingReferenceKeyElement for the supplied
219      * primary/secondary table pair.
220      * @param parent mapping table element which should also be the primary
221      * table.
222      * @param table table element to be used as a secondary table.
223      * @exception ModelException if impossible
224      */

225     public MappingReferenceKeyElement addSecondaryTable (MappingTableElement
226         parentTable, TableElement table) throws ModelException;
227
228     /** Removes the reference to the supplied table as a mapped table for this
229      * mapping class. This works whether the table is the primary table or a
230      * secondary table.
231      * @param table mapping table element to be removed from this mapping class.
232      * @exception ModelException if impossible
233      */

234     public void removeTable (MappingTableElement table) throws ModelException;
235
236     //======================= field handling ===========================
237

238     /** Returns the list of fields (MappingFieldElements) in this mapping
239      * class. This list includes both local and relationship fields.
240      * @return the mapping fields in this mapping class
241      */

242     public ArrayList JavaDoc getFields ();
243
244     /** Scans through this mapping class looking for a field whose
245      * name matches the name passed in.
246      * @param name name of the field to find.
247      * @return the mapping field whose name matches the name parameter
248      */

249     public MappingFieldElement getField (String JavaDoc name);
250
251     /** Adds a field to the list of fields in this mapping class.
252      * @param field field element to be added
253      * @exception ModelException if impossible
254      */

255     public void addField (MappingFieldElement field) throws ModelException;
256
257     /** Removes a field from the list of fields in this mapping class.
258      * @param field field element to be removed
259      * @exception ModelException if impossible
260      */

261     public void removeField (MappingFieldElement field) throws ModelException;
262
263     /** Returns the list of version fields (MappingFieldElements) in this
264      * mapping class. This list only includes fields if the consistency
265      * level is {@link #VERSION_CONSISTENCY}.
266      * @return the version fields in this mapping class
267      */

268     public List JavaDoc getVersionFields ();
269
270     /** Gets the navigable flag for this mapping class.
271      * @return <code>true</code> if lazy initialization will be used,
272      * <code>false</code> if access to a non-fetched field will result in an
273      * exception. The default is <code>true</code>.
274      */

275     public boolean isNavigable ();
276
277     /** Set the navigable flag for this mapping class to flag.
278      * @param flag if <code>true</code>, lazy initialization will be used;
279      * if <code>false</code>, access to a non-fetched field will result in an
280      * exception.
281      * @exception ModelException if impossible
282      */

283     public void setNavigable (boolean flag) throws ModelException;
284 }
285
Popular Tags