KickJava   Java API By Example, From Geeks To Geeks.

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


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.exceptions.*;
26 import oracle.toplink.essentials.internal.sessions.AbstractSession;
27
28 /**
29  * <p>
30  * <b>Purpose</b>: Allow for creation of views.
31  * <p>
32  */

33 public class ViewDefinition extends DatabaseObjectDefinition {
34     protected String JavaDoc selectClause;
35
36     public ViewDefinition() {
37         super();
38         this.selectClause = "";
39     }
40
41     /**
42      * INTERNAL:
43      * Return the DDL to create the view.
44      */

45     public Writer buildCreationWriter(AbstractSession session, Writer writer) throws ValidationException {
46         try {
47             writer.write(session.getPlatform().getCreateViewString());
48             writer.write(getFullName());
49             writer.write(" AS (");
50             writer.write(getSelectClause());
51             writer.write(")");
52         } catch (IOException ioException) {
53             throw ValidationException.fileError(ioException);
54         }
55         return writer;
56     }
57
58     /**
59      * INTERNAL:
60      * Return the DDL to drop the view.
61      */

62     public Writer buildDeletionWriter(AbstractSession session, Writer writer) throws ValidationException {
63         try {
64             writer.write("DROP VIEW " + getFullName());
65         } catch (IOException ioException) {
66             throw ValidationException.fileError(ioException);
67         }
68         return writer;
69     }
70
71     /**
72      * The select clause is the select statement that is mapped into the view.
73      * This is database specific SQL code.
74      */

75     public String JavaDoc getSelectClause() {
76         return selectClause;
77     }
78
79     /**
80      * The select clause is the select statement that is mapped into the view.
81      * This is database specific SQL code.
82      */

83     public void setSelectClause(String JavaDoc selectClause) {
84         this.selectClause = selectClause;
85     }
86 }
87
Popular Tags