KickJava   Java API By Example, From Geeks To Geeks.

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


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  * ConcurrencyCheckDirty.java
26  *
27  * Created on March 19, 2002
28  *
29  */

30
31 package com.sun.jdo.spi.persistence.support.sqlstore.sql.concurrency;
32
33 import org.netbeans.modules.dbschema.ColumnElement;
34 import com.sun.jdo.spi.persistence.support.sqlstore.SQLStateManager;
35 import com.sun.jdo.spi.persistence.support.sqlstore.UpdateObjectDesc;
36 import com.sun.jdo.spi.persistence.support.sqlstore.model.FieldDesc;
37 import com.sun.jdo.spi.persistence.support.sqlstore.model.LocalFieldDesc;
38 import com.sun.jdo.spi.persistence.support.sqlstore.sql.generator.QueryTable;
39 import com.sun.jdo.spi.persistence.support.sqlstore.sql.generator.Statement;
40 import com.sun.jdo.spi.persistence.support.sqlstore.sql.generator.UpdateQueryPlan;
41
42 import java.util.ArrayList JavaDoc;
43 import java.util.BitSet JavaDoc;
44 import java.util.Iterator JavaDoc;
45
46 /**
47  */

48 public class ConcurrencyCheckDirty extends ConcurrencyDBNative {
49
50     public void commit(UpdateObjectDesc updateDesc,
51                        SQLStateManager beforeImage,
52                        SQLStateManager afterImage,
53                        int logReason) {
54         this.beforeImage = beforeImage;
55         this.afterImage = afterImage;
56     }
57
58     public void update(UpdateQueryPlan plan) {
59         boolean debug = logger.isLoggable();
60
61         if (debug) {
62             logger.fine("sqlstore.sql.concurrency.concurrencychkdirty", beforeImage); // NOI18N
63
}
64
65         if (beforeImage != null) {
66             ArrayList JavaDoc fields = plan.getConfig().fields;
67             BitSet JavaDoc verifyGroupMask = prepareVerifyGroupMask(plan);
68
69             for (int i = 0; i < 2; i++) {
70
71                 if (i == 0) {
72                     fields = plan.getConfig().fields;
73                 } else if (i == 1) {
74                     fields = plan.getConfig().hiddenFields;
75                 }
76
77                 if (fields == null) {
78                     continue;
79                 }
80
81                 for (int j = 0; j < fields.size(); j++) {
82                     FieldDesc f = (FieldDesc) fields.get(j);
83
84                     if (f instanceof LocalFieldDesc) {
85                         LocalFieldDesc lf = (LocalFieldDesc) f;
86
87                         // Make sure the field is marked for concurrency check and is present
88
// Also, skip all fields that are marked as secondary tracked fields.
89
//
90
// RESOLVE: we need to fetch the fields that are not present.
91
if (((lf.sqlProperties & FieldDesc.PROP_IN_CONCURRENCY_CHECK) > 0) &&
92                                 ((lf.sqlProperties & FieldDesc.PROP_SECONDARY_TRACKED_FIELD) == 0) &&
93                                 beforeImage.getPresenceMaskBit(lf.absoluteID)) {
94
95                             if (isFieldVerificationRequired(lf, verifyGroupMask)) {
96                                 Object JavaDoc val = null;
97                                 val = lf.getValue(this.beforeImage);
98                                 addConstraint(plan, lf, val);
99                             }
100                         }
101                     }
102                 }
103             }
104         }
105
106         if (debug) {
107             logger.fine("sqlstore.sql.concurrency.concurrencychkdirty.exit"); // NOI18N
108
}
109     }
110
111     protected BitSet JavaDoc prepareVerifyGroupMask(UpdateQueryPlan plan) {
112         return null;
113     }
114
115     protected boolean isFieldVerificationRequired(LocalFieldDesc lf,
116                                                   BitSet JavaDoc verifyGroupMask) {
117          return true;
118     }
119
120     /**
121      * Adds a comparison for local field <CODE>lf</CODE> and value <CODE>val</CODE>
122      * to the corresponding statements in UpdateQueryPlan <CODE>plan</CODE>.
123      */

124     private static void addConstraint(UpdateQueryPlan plan, LocalFieldDesc lf, Object JavaDoc val) {
125         for (Iterator JavaDoc iter = lf.getColumnElements(); iter.hasNext(); ) {
126             ColumnElement c = (ColumnElement) iter.next();
127
128             for (int i = 0; i < plan.statements.size(); i++) {
129                 Statement s = (Statement) plan.statements.get(i);
130
131                 for (int j = 0; j < s.tableList.size(); j++) {
132                     QueryTable t = (QueryTable) s.tableList.get(j);
133
134                     if (t.getTableDesc().getTableElement() == c.getDeclaringTable()) {
135                         s.addConstraint(lf, val);
136                     }
137                 }
138             }
139         }
140     }
141
142     public Object JavaDoc clone() {
143         return new ConcurrencyCheckDirty();
144     }
145 }
146
147
148
149
150
151
152
Popular Tags