KickJava   Java API By Example, From Geeks To Geeks.

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


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.io.*;
25 import oracle.toplink.essentials.queryframework.ObjectBuildingQuery;
26
27 /**
28  * <b>Purpose:</b>Represents The FOR UPDATE pessimistically locking clause.
29  * @author Stephen McRitchie
30  * @since Oracle Toplink 10g AS
31  */

32 public class ForUpdateClause implements Serializable, Cloneable JavaDoc {
33     protected static final ForUpdateClause NO_LOCK_CLAUSE = new ForUpdateClause();
34     short lockMode;
35
36     public ForUpdateClause() {
37         this.lockMode = ObjectBuildingQuery.NO_LOCK;
38     }
39
40     public ForUpdateClause(short lockMode) {
41         this.lockMode = lockMode;
42     }
43
44     public Object JavaDoc clone() {
45         try {
46             return super.clone();
47         } catch (CloneNotSupportedException JavaDoc never) {
48             return null;
49         }
50     }
51
52     public static ForUpdateClause newInstance(short lockMode) {
53         if (lockMode == ObjectBuildingQuery.NO_LOCK) {
54             return NO_LOCK_CLAUSE;
55         } else {
56             return new ForUpdateClause(lockMode);
57         }
58     }
59
60     public boolean isForUpdateOfClause() {
61         return false;
62     }
63
64     public boolean isReferenceClassLocked() {
65         return true;
66     }
67
68     public short getLockMode() {
69         return lockMode;
70     }
71
72     /**
73      * INTERNAL:
74      * Prints the as of clause for an expression inside of the FROM clause.
75      */

76     public void printSQL(ExpressionSQLPrinter printer, SQLSelectStatement statement) {
77         // Append lock strings
78
if (getLockMode() == ObjectBuildingQuery.LOCK) {
79             printer.printString(printer.getSession().getPlatform().getSelectForUpdateString());
80         } else if (lockMode == ObjectBuildingQuery.LOCK_NOWAIT) {
81             printer.printString(printer.getSession().getPlatform().getSelectForUpdateString());
82             printer.printString(printer.getSession().getPlatform().getSelectForUpdateNoWaitString());
83         }
84     }
85 }
86
Popular Tags