KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > jdo > spi > persistence > support > sqlstore > sql > concurrency > ConcurrencyOptVerify


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 in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
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 Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /*
25  * ConcurrencyOptVerify.java
26  *
27  * Created on March 3, 2000
28  *
29  */

30
31 package com.sun.jdo.spi.persistence.support.sqlstore.sql.concurrency;
32
33 import com.sun.jdo.spi.persistence.support.sqlstore.model.FieldDesc;
34 import com.sun.jdo.spi.persistence.support.sqlstore.model.LocalFieldDesc;
35 import com.sun.jdo.spi.persistence.support.sqlstore.sql.generator.QueryPlan;
36 import com.sun.jdo.spi.persistence.support.sqlstore.sql.generator.UpdateQueryPlan;
37
38 import java.util.ArrayList JavaDoc;
39 import java.util.BitSet JavaDoc;
40
41 /**
42  */

43 public class ConcurrencyOptVerify extends ConcurrencyCheckDirty {
44
45     /**
46      * Find all the local fields that have been updated
47      * and use their concurrencyGroup to set the verifyGroupMask.
48      */

49     protected BitSet JavaDoc prepareVerifyGroupMask(UpdateQueryPlan plan) {
50         ArrayList JavaDoc fields;
51         BitSet JavaDoc verifyGroupMask = new BitSet JavaDoc();
52         int action = plan.getAction();
53
54         for (int i = 0; i <= 1; i++) {
55             if (i == 0) {
56                 fields = plan.getConfig().fields;
57             } else {
58                 fields = plan.getConfig().hiddenFields;
59             }
60
61             if (fields == null) {
62                 continue;
63             }
64
65             for (int j = 0; j < fields.size(); j++) {
66                 FieldDesc f = (FieldDesc) fields.get(j);
67
68                 if ((f instanceof LocalFieldDesc) &&
69                         (f.sqlProperties & FieldDesc.PROP_IN_CONCURRENCY_CHECK) > 0) {
70  
71                     // In the case of a deleted instance with no modified fields
72
// we use the present fields in the before image to perform
73
// the concurrency check.
74
if (afterImage.getSetMaskBit(f.absoluteID) ||
75                             ((action == QueryPlan.ACT_DELETE) &&
76                             beforeImage.getPresenceMaskBit(f.absoluteID))) {
77                         if (f.concurrencyGroup != -1) {
78                             verifyGroupMask.set(f.concurrencyGroup);
79                         }
80                     }
81                 }
82             }
83         }
84
85         return verifyGroupMask;
86     }
87
88     protected boolean isFieldVerificationRequired(LocalFieldDesc lf,
89                                                   BitSet JavaDoc verifyGroupMask) {
90         boolean fieldVerificationRequired = true;
91
92         if (lf.concurrencyGroup == -1) {
93             if (!afterImage.getSetMaskBit(lf.absoluteID)) {
94                 fieldVerificationRequired = false;
95             }
96         } else {
97             if (!verifyGroupMask.get(lf.concurrencyGroup)) {
98                 fieldVerificationRequired = false;
99             }
100         }
101
102         return fieldVerificationRequired;
103     }
104
105     public Object JavaDoc clone() {
106         return new ConcurrencyOptVerify();
107     }
108 }
109
110
111
112
113
114
115
Popular Tags