1 23 24 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 ; 43 import java.util.BitSet ; 44 import java.util.Iterator ; 45 46 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); } 64 65 if (beforeImage != null) { 66 ArrayList fields = plan.getConfig().fields; 67 BitSet 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 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 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"); } 109 } 110 111 protected BitSet prepareVerifyGroupMask(UpdateQueryPlan plan) { 112 return null; 113 } 114 115 protected boolean isFieldVerificationRequired(LocalFieldDesc lf, 116 BitSet verifyGroupMask) { 117 return true; 118 } 119 120 124 private static void addConstraint(UpdateQueryPlan plan, LocalFieldDesc lf, Object val) { 125 for (Iterator 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 clone() { 143 return new ConcurrencyCheckDirty(); 144 } 145 } 146 147 148 149 150 151 152 | Popular Tags |