001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * // Copyright (c) 1998, 2007, Oracle. All rights reserved.
005: *
006: *
007: * The contents of this file are subject to the terms of either the GNU
008: * General Public License Version 2 only ("GPL") or the Common Development
009: * and Distribution License("CDDL") (collectively, the "License"). You
010: * may not use this file except in compliance with the License. You can obtain
011: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
012: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
013: * language governing permissions and limitations under the License.
014: *
015: * When distributing the software, include this License Header Notice in each
016: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
017: * Sun designates this particular file as subject to the "Classpath" exception
018: * as provided by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the License
020: * Header, with the fields enclosed by brackets [] replaced by your own
021: * identifying information: "Portions Copyrighted [year]
022: * [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * If you wish your version of this file to be governed by only the CDDL or
027: * only the GPL Version 2, indicate your decision by adding "[Contributor]
028: * elects to include this software in this distribution under the [CDDL or GPL
029: * Version 2] license." If you don't indicate a single choice of license, a
030: * recipient has the option to distribute your version of this file under
031: * either the CDDL, the GPL Version 2 or to extend the choice of license to
032: * its licensees as provided above. However, if you add GPL Version 2 code
033: * and therefore, elected the GPL Version 2 license, then the option applies
034: * only if the new code is made subject to such option by the copyright
035: * holder.
036: */
037: package oracle.toplink.essentials.internal.parsing;
038:
039: import oracle.toplink.essentials.queryframework.*;
040: import oracle.toplink.essentials.exceptions.*;
041: import oracle.toplink.essentials.expressions.*;
042: import oracle.toplink.essentials.descriptors.ClassDescriptor;
043:
044: /**
045: * INTERNAL:
046: * ModifyNode is the superclass for UpdateNode and DeleteNode
047: */
048: public abstract class ModifyNode extends QueryNode {
049:
050: private String abstractSchemaIdentifier;
051: private String abstractSchemaName;
052:
053: /**
054: * INTERNAL
055: * Apply this node to the passed query. This node does not change the query.
056: */
057: public void applyToQuery(DatabaseQuery theQuery,
058: GenerationContext context) {
059: }
060:
061: /**
062: * INTERNAL
063: * Validate node and calculate its type.
064: */
065: public void validate(ParseTreeContext context) {
066: // If defined use the abstractSchemaIdentifier as the base variable,
067: // otherwise use the abstractSchemaName
068: String baseVariable = getCanonicalAbstractSchemaIdentifier();
069: context.setBaseVariable(baseVariable);
070: super .validate(context);
071: }
072:
073: /**
074: * INTERNAL
075: */
076: public Expression generateExpression(GenerationContext context) {
077: return null;
078: }
079:
080: /**
081: * INTERNAL
082: */
083: public String getAbstractSchemaName() {
084: return abstractSchemaName;
085: }
086:
087: /**
088: * INTERNAL
089: */
090: public void setAbstractSchemaName(String abstractSchemaName) {
091: this .abstractSchemaName = abstractSchemaName;
092: }
093:
094: /**
095: * INTERNAL
096: */
097: public String getAbstractSchemaIdentifier() {
098: return abstractSchemaIdentifier;
099: }
100:
101: /**
102: * INTERNAL
103: */
104: public void setAbstractSchemaIdentifier(String identifierName) {
105: abstractSchemaIdentifier = identifierName;
106: }
107:
108: /**
109: * INTERNAL:
110: * Returns the canonical name of abstract schema identifier.
111: * If the identifier is not specified(unqualified attribute scenario),
112: * the canonical name of abstract schema is returned.
113: */
114: public String getCanonicalAbstractSchemaIdentifier() {
115: String variable = abstractSchemaIdentifier != null ? abstractSchemaIdentifier
116: : abstractSchemaName;
117: return IdentificationVariableDeclNode
118: .calculateCanonicalName(variable);
119: }
120:
121: /**
122: * resolveClass: Answer the class which corresponds to my variableName. This is the class for
123: * an alias, where the variableName is registered to an alias.
124: */
125: public Class resolveClass(GenerationContext context) {
126: String alias = abstractSchemaName;
127: ClassDescriptor descriptor = context.getSession()
128: .getDescriptorForAlias(alias);
129: if (descriptor == null) {
130: throw EJBQLException.unknownAbstractSchemaType2(context
131: .getParseTreeContext().getQueryInfo(), getLine(),
132: getColumn(), alias);
133: }
134: Class theClass = descriptor.getJavaClass();
135: if (theClass == null) {
136: throw EJBQLException.resolutionClassNotFoundException2(
137: context.getParseTreeContext().getQueryInfo(),
138: getLine(), getColumn(), alias);
139: }
140: return theClass;
141: }
142: }
|