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.queryframework;
038:
039: import oracle.toplink.essentials.exceptions.*;
040:
041: /**
042: * <p><b>Purpose</b>:
043: * Used for inserting new objects into the database.
044: *
045: * <p><b>Description</b>:
046: * This class does not have much behavior.
047: * It inherits most of it's behavior from WriteObjectQuery
048: *
049: * @author Yvon Lavoie
050: * @since TOPLink/Java 1.0
051: */
052: public class InsertObjectQuery extends WriteObjectQuery {
053:
054: /**
055: * PUBLIC:
056: * Default constructor.
057: */
058: public InsertObjectQuery() {
059: super ();
060: }
061:
062: /**
063: * PUBLIC:
064: * Create an insert query with the object being inserted.
065: */
066: public InsertObjectQuery(Object objectToInsert) {
067: this ();
068: setObject(objectToInsert);
069: }
070:
071: /**
072: * PUBLIC:
073: * Create an insert query with the custom call.
074: */
075: public InsertObjectQuery(Call call) {
076: this ();
077: setCall(call);
078: }
079:
080: /**
081: * INTERNAL:
082: * Perform an insert.
083: */
084: public void executeCommit() throws DatabaseException {
085: // object will only be null if the transaction is being commited directly from a changeset
086: if (getObject() != null) {
087: // if the object is not null then it is more effecient to build the row from the
088: // object then the changeSet.
089: getQueryMechanism().insertObjectForWrite();
090: } else {
091: // has a changeSet so we must use it in the case that there is no object
092: getQueryMechanism().insertObjectForWriteWithChangeSet();
093: }
094: }
095:
096: /**
097: * INTERNAL:
098: * Perform a shallow insert.
099: */
100: public void executeShallowWrite() {
101: getQueryMechanism().shallowInsertObjectForWrite(getObject(),
102: this , getSession().getCommitManager());
103: }
104:
105: /**
106: * INTERNAL:
107: * Prepare the receiver for execution in a session.
108: */
109: protected void prepare() {
110: super .prepare();
111:
112: getQueryMechanism().prepareInsertObject();
113: }
114:
115: /**
116: * PUBLIC:
117: * Return if this is an insert object query.
118: */
119: public boolean isInsertObjectQuery() {
120: return true;
121: }
122: }
|