KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > oracle > toplink > essentials > internal > expressions > ForUpdateOfClause


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, 2006, Oracle. All rights reserved.
22
package oracle.toplink.essentials.internal.expressions;
23
24 import java.util.*;
25 import oracle.toplink.essentials.expressions.*;
26 import oracle.toplink.essentials.queryframework.ObjectBuildingQuery;
27
28 /**
29  * <b>Purpose:</b>Represents The FOR UPDATE OF fine-grained pessimistically
30  * locking clause.
31  * @author Stephen McRitchie
32  * @since Oracle Toplink 10g AS
33  */

34 public class ForUpdateOfClause extends ForUpdateClause {
35     protected Vector lockedExpressions;
36
37     public ForUpdateOfClause() {
38     }
39
40     public void addLockedExpression(ObjectExpression expression) {
41         getLockedExpressions().addElement(expression);
42     }
43
44     public Vector getLockedExpressions() {
45         if (lockedExpressions == null) {
46             lockedExpressions = oracle.toplink.essentials.internal.helper.NonSynchronizedVector.newInstance();
47         }
48         return lockedExpressions;
49     }
50
51     public boolean isForUpdateOfClause() {
52         return true;
53     }
54
55     public boolean isReferenceClassLocked() {
56         if (lockedExpressions == null) {
57             return false;
58         }
59
60         // Normally the expressionBuilder is stored first but not necessarily
61
// when a child ForUpdateOfClause is built for a nested query, or if a
62
//user made this clause.
63
for (int i = 0; i < lockedExpressions.size(); i++) {
64             if (((Expression)lockedExpressions.elementAt(i)).isExpressionBuilder()) {
65                 return true;
66             }
67         }
68         return false;
69     }
70
71     public void setLockedExpressions(Vector lockedExpressions) {
72         this.lockedExpressions = lockedExpressions;
73     }
74
75     public void setLockMode(short lockMode) {
76         this.lockMode = lockMode;
77     }
78
79     /**
80      * INTERNAL:
81      * Prints the as of clause for an expression inside of the FROM clause.
82      */

83     public void printSQL(ExpressionSQLPrinter printer, SQLSelectStatement statement) {
84         // assert(lockedExpressions != null && lockedExpressions.size() > 0);
85
// assert( getLockMode() == ObjectBuildingQuery.LOCK ||
86
// getLockMode() == ObjectBuildingQuery.LOCK_NOWAIT);
87
ExpressionBuilder clonedBuilder = statement.getBuilder();
88
89         printer.printString(printer.getSession().getPlatform().getSelectForUpdateOfString());
90
91         printer.setIsFirstElementPrinted(false);
92         for (Enumeration enumtr = getLockedExpressions().elements(); enumtr.hasMoreElements();) {
93             ObjectExpression next = (ObjectExpression)enumtr.nextElement();
94
95             // Neccessary as this was determined in query framework.
96
next = (ObjectExpression)next.rebuildOn(clonedBuilder);
97             next.writeForUpdateOfFields(printer, statement);
98         }
99         if (lockMode == ObjectBuildingQuery.LOCK_NOWAIT) {
100             printer.printString(printer.getSession().getPlatform().getSelectForUpdateNoWaitString());
101         }
102     }
103 }
104
Popular Tags