KickJava   Java API By Example, From Geeks To Geeks.

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


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 import oracle.toplink.essentials.internal.sessions.UnitOfWorkImpl;
26
27 /**
28  * <p><b>Purpose</b>:
29  * Concrete class used for executing non selecting SQL strings.
30  *
31  * <p><b>Responsibilities</b>:
32  * <ul>
33  * <li> Execute a non selecting raw SQL string.
34  * </ul>
35  *
36  * @author Yvon Lavoie
37  * @since TOPLink/Java 1.0
38  */

39 public class DataModifyQuery extends ModifyQuery {
40     public DataModifyQuery() {
41         super();
42     }
43
44     public DataModifyQuery(String JavaDoc sqlString) {
45         this();
46
47         setSQLString(sqlString);
48     }
49
50     public DataModifyQuery(Call call) {
51         this();
52         setCall(call);
53     }
54
55     /**
56      * INTERNAL:
57      * Perform the work to execute the SQL call.
58      * Return the row count of the number of rows effected by the SQL call.
59      */

60     public Object JavaDoc executeDatabaseQuery() throws DatabaseException {
61
62         /* Fix to allow executing non-selecting SQL in a UnitOfWork. - RB */
63         if (getSession().isUnitOfWork()) {
64             UnitOfWorkImpl unitOfWork = (UnitOfWorkImpl)getSession();
65             /* bug:4211104 for DataModifyQueries executed during an event, while transaction was started by the uow*/
66             if ( !unitOfWork.getCommitManager().isActive() && !unitOfWork.isInTransaction()) {
67                 unitOfWork.beginEarlyTransaction();
68             }
69             unitOfWork.setWasNonObjectLevelModifyQueryExecuted(true);
70         }
71         return getQueryMechanism().executeNoSelect();
72     }
73
74     /**
75      * PUBLIC:
76      * Return if this is a data modify query.
77      */

78     public boolean isDataModifyQuery() {
79         return true;
80     }
81
82     /**
83      * INTERNAL:
84      * Prepare the receiver for execution in a session.
85      */

86     protected void prepare() {
87         super.prepare();
88
89         getQueryMechanism().prepareExecuteNoSelect();
90     }
91
92     /**
93      * INTERNAL:
94      * Prepare the receiver for execution in a session. In particular,
95      * set the descriptor of the receiver to the Descriptor for the
96      * appropriate class for the receiver's object.
97      */

98     public void prepareForExecution() throws QueryException {
99         super.prepareForExecution();
100
101         setModifyRow(getTranslationRow());
102     }
103 }
104
Popular Tags