KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > oracle > toplink > essentials > queryframework > InsertObjectQuery


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.queryframework;
23
24 import oracle.toplink.essentials.exceptions.*;
25
26 /**
27  * <p><b>Purpose</b>:
28  * Used for inserting new objects into the database.
29  *
30  * <p><b>Description</b>:
31  * This class does not have much behavior.
32  * It inherits most of it's behavior from WriteObjectQuery
33  *
34  * @author Yvon Lavoie
35  * @since TOPLink/Java 1.0
36  */

37 public class InsertObjectQuery extends WriteObjectQuery {
38
39     /**
40      * PUBLIC:
41      * Default constructor.
42      */

43     public InsertObjectQuery() {
44         super();
45     }
46
47     /**
48      * PUBLIC:
49      * Create an insert query with the object being inserted.
50      */

51     public InsertObjectQuery(Object JavaDoc objectToInsert) {
52         this();
53         setObject(objectToInsert);
54     }
55
56     /**
57      * PUBLIC:
58      * Create an insert query with the custom call.
59      */

60     public InsertObjectQuery(Call call) {
61         this();
62         setCall(call);
63     }
64
65     /**
66      * INTERNAL:
67      * Perform an insert.
68      */

69     public void executeCommit() throws DatabaseException {
70         // object will only be null if the transaction is being commited directly from a changeset
71
if (getObject() != null) {
72             // if the object is not null then it is more effecient to build the row from the
73
// object then the changeSet.
74
getQueryMechanism().insertObjectForWrite();
75         } else {
76             // has a changeSet so we must use it in the case that there is no object
77
getQueryMechanism().insertObjectForWriteWithChangeSet();
78         }
79     }
80
81     /**
82      * INTERNAL:
83      * Prepare the receiver for execution in a session.
84      */

85     protected void prepare() {
86         super.prepare();
87
88         getQueryMechanism().prepareInsertObject();
89     }
90
91     /**
92      * PUBLIC:
93      * Return if this is an insert object query.
94      */

95     public boolean isInsertObjectQuery() {
96         return true;
97     }
98 }
99
Popular Tags