oracle.toplink.essentials.tools.schemaframework.ViewDefinition Maven / Gradle / Ivy
/*
* The contents of this file are subject to the terms
* of the Common Development and Distribution License
* (the "License"). You may not use this file except
* in compliance with the License.
*
* You can obtain a copy of the license at
* glassfish/bootstrap/legal/CDDLv1.0.txt or
* https://glassfish.dev.java.net/public/CDDLv1.0.html.
* See the License for the specific language governing
* permissions and limitations under the License.
*
* When distributing Covered Code, include this CDDL
* HEADER in each file and include the License file at
* glassfish/bootstrap/legal/CDDLv1.0.txt. If applicable,
* add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your
* own identifying information: Portions Copyright [yyyy]
* [name of copyright owner]
*/
// Copyright (c) 1998, 2007, Oracle. All rights reserved.
package oracle.toplink.essentials.tools.schemaframework;
import java.io.*;
import oracle.toplink.essentials.exceptions.*;
import oracle.toplink.essentials.internal.sessions.AbstractSession;
/**
*
* Purpose: Allow for creation of views.
*
*/
public class ViewDefinition extends DatabaseObjectDefinition {
protected String selectClause;
public ViewDefinition() {
super();
this.selectClause = "";
}
/**
* INTERNAL:
* Return the DDL to create the view.
*/
public Writer buildCreationWriter(AbstractSession session, Writer writer) throws ValidationException {
try {
writer.write(session.getPlatform().getCreateViewString());
writer.write(getFullName());
writer.write(" AS (");
writer.write(getSelectClause());
writer.write(")");
} catch (IOException ioException) {
throw ValidationException.fileError(ioException);
}
return writer;
}
/**
* INTERNAL:
* Return the DDL to drop the view.
*/
public Writer buildDeletionWriter(AbstractSession session, Writer writer) throws ValidationException {
try {
writer.write("DROP VIEW " + getFullName());
} catch (IOException ioException) {
throw ValidationException.fileError(ioException);
}
return writer;
}
/**
* The select clause is the select statement that is mapped into the view.
* This is database specific SQL code.
*/
public String getSelectClause() {
return selectClause;
}
/**
* The select clause is the select statement that is mapped into the view.
* This is database specific SQL code.
*/
public void setSelectClause(String selectClause) {
this.selectClause = selectClause;
}
}