KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > oracle > toplink > essentials > tools > schemaframework > DatabaseObjectDefinition


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
5  * in compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * glassfish/bootstrap/legal/CDDLv1.0.txt or
9  * https://glassfish.dev.java.net/public/CDDLv1.0.html.
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 in each file and include the License file at
15  * glassfish/bootstrap/legal/CDDLv1.0.txt. If applicable,
16  * add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your
18  * own identifying information: Portions Copyright [yyyy]
19  * [name of copyright owner]
20  */

21 // Copyright (c) 1998, 2005, Oracle. All rights reserved.
22
package oracle.toplink.essentials.tools.schemaframework;
23
24 import java.io.*;
25 import oracle.toplink.essentials.internal.helper.*;
26 import oracle.toplink.essentials.exceptions.*;
27 import oracle.toplink.essentials.queryframework.*;
28 import oracle.toplink.essentials.internal.sessions.AbstractSession;
29
30 /**
31  * <p>
32  * <b>Purpose</b>: Define a database object for the purpose of creation and deletion.
33  * A database object is an entity such as a table, view, proc, sequence...
34  * <p>
35  * <b>Responsibilities</b>:
36  * <ul>
37  * <li> Be able to create and drop the object from the database.
38  * </ul>
39  */

40 public abstract class DatabaseObjectDefinition implements Cloneable JavaDoc, Serializable {
41     public String JavaDoc name;
42     public String JavaDoc qualifier;
43
44     public DatabaseObjectDefinition() {
45         this.name = "";
46         this.qualifier = "";
47     }
48
49     /**
50      * INTERNAL:
51      * Returns the writer used for creation of this object.
52      */

53     public abstract Writer buildCreationWriter(AbstractSession session, Writer writer) throws ValidationException;
54
55     /**
56      * INTERNAL:
57      * Returns the writer used for creation of this object.
58      */

59     public abstract Writer buildDeletionWriter(AbstractSession session, Writer writer) throws ValidationException;
60
61     /**
62      * PUBLIC:
63      */

64     public Object JavaDoc clone() {
65         try {
66             return super.clone();
67         } catch (CloneNotSupportedException JavaDoc impossible) {
68             return null;
69         }
70     }
71
72     /**
73      * INTERNAL:
74      * Either drop from the database directly or write the statement to a file.
75      * Database objects are root level entities such as tables, views, procs, sequences...
76      */

77     public void createObject(AbstractSession session, Writer schemaWriter) throws TopLinkException {
78         if (schemaWriter == null) {
79             this.createOnDatabase(session);
80         } else {
81             this.buildCreationWriter(session, schemaWriter);
82         }
83     }
84
85     /**
86      * INTERNAL:
87      * Execute the DDL to create the varray.
88      */

89     public void createOnDatabase(AbstractSession session) throws TopLinkException {
90         session.executeNonSelectingCall(new SQLCall(buildCreationWriter(session, new StringWriter()).toString()));
91     }
92
93     /**
94      * INTERNAL:
95      * Execute the DDL to drop the varray.
96      */

97     public void dropFromDatabase(AbstractSession session) throws TopLinkException {
98         session.executeNonSelectingCall(new SQLCall(buildDeletionWriter(session, new StringWriter()).toString()));
99     }
100
101     /**
102      * INTERNAL:
103      * Execute the DDL to drop the varray. Either directly from the database
104      * of write out the statement to a file.
105      */

106     public void dropObject(AbstractSession session, Writer schemaWriter) throws TopLinkException {
107         if (schemaWriter == null) {
108             this.dropFromDatabase(session);
109         } else {
110             buildDeletionWriter(session, schemaWriter);
111         }
112     }
113
114     /**
115      * INTERNAL:
116      * Most major databases support a creator name scope.
117      * This means whenever the database object is referecned, it must be qualified.
118      */

119     public String JavaDoc getFullName() {
120         if (getQualifier().equals("")) {
121             return getName();
122         } else {
123             return getQualifier() + "." + getName();
124         }
125     }
126
127     /**
128      * PUBLIC:
129      * Return the name of the object.
130      * i.e. the table name or the sequence name.
131      */

132     public String JavaDoc getName() {
133         return name;
134     }
135
136     /**
137      * PUBLIC:
138      * Most major databases support a creator name scope.
139      * This means whenever the database object is referecned, it must be qualified.
140      */

141     public String JavaDoc getQualifier() {
142         return qualifier;
143     }
144
145     /**
146      * PUBLIC:
147      * Set the name of the object.
148      * i.e. the table name or the sequence name.
149      */

150     public void setName(String JavaDoc name) {
151         this.name = name;
152     }
153
154     /**
155      * PUBLIC:
156      * Most major databases support a creator name scope.
157      * This means whenever the database object is referecned, it must be qualified.
158      */

159     public void setQualifier(String JavaDoc qualifier) {
160         this.qualifier = qualifier;
161     }
162
163     public String JavaDoc toString() {
164         return Helper.getShortClassName(getClass()) + "(" + getFullName() + ")";
165     }
166 }
167
Popular Tags