KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > daffodilwoods > daffodildb > server > sessionsystem > ForUpdateTableHandler


1 package com.daffodilwoods.daffodildb.server.sessionsystem;
2
3 import java.util.HashMap JavaDoc;
4 import com.daffodilwoods.daffodildb.server.sql99.utils._Reference;
5 import com.daffodilwoods.daffodildb.server.sql99.expression.booleanvalueexpression.booleanvalueexpression;
6 import java.util.ArrayList JavaDoc;
7 import com.daffodilwoods.database.resource.DException;
8 import com.daffodilwoods.daffodildb.server.datasystem.utility._Record;
9 import java.lang.ref.WeakReference JavaDoc;
10
11 public class ForUpdateTableHandler {
12
13   private HashMap JavaDoc sessionFUV;
14   private int count = 0;
15
16   public ForUpdateTableHandler() {
17     sessionFUV = new HashMap JavaDoc();
18   }
19
20   public void addForUpdateVariableValues(Object JavaDoc sessionId, ConditionReferenceValues crv0, WeakReference JavaDoc serverSession) {
21     synchronized (sessionFUV) {
22       ForUpdateValues fuv = (ForUpdateValues) sessionFUV.get(sessionId);
23       if(fuv == null) {
24         ArrayList JavaDoc list = new ArrayList JavaDoc();
25         list.add(crv0);
26         count++;
27         sessionFUV.put(sessionId,new ForUpdateValues( list, serverSession));
28         return;
29       }
30       ((ArrayList JavaDoc) fuv.getConditionReferenceValuesList()).add(crv0);
31     }
32   }
33
34   public void checkRowValidity(Object JavaDoc sessionId, _Record record) throws DException {
35     ArrayList JavaDoc fuvs = getForUpdateValues(sessionId);
36     if(fuvs == null)
37       return;
38     for (int i = 0, sz = fuvs.size(); i < sz ; i++) {
39       Object JavaDoc[] val = (Object JavaDoc[] ) fuvs.get(i);
40       ArrayList JavaDoc crvlist = (ArrayList JavaDoc) val[1];
41       for (int j = 0, size = crvlist.size(); j < size; j++) {
42         ConditionReferenceValues cvv = (ConditionReferenceValues) crvlist.get(j);
43         RecordVariableValues rvv = new RecordVariableValues((WeakReference JavaDoc)val[0],record,cvv.getReferences(),cvv.getValues());
44         if(cvv.getBVE().run(rvv).hashCode() == 0){
45          ;//// Removed By Program ** System.out.println(" Every thing is fine Good work ");
46
throw new DException("DSE879", null);
47         }
48       }
49     }
50 /* Object[] keys = sessionFUV.keySet().toArray();
51     for (int i = 0 ; i < keys.length; i++) {
52       if(!keys[i].equals(sessionId)) {
53         ForUpdateValues fuv = (ForUpdateValues) sessionFUV.get(keys[i]);
54         ArrayList list = fuv.getConditionReferenceValuesList();
55         for (int j = 0, sixe = list.size(); j < sixe; j++) {
56           ConditionReferenceValues cvv = (ConditionReferenceValues) list.get(j);
57           RecordVariableValues rvv = new RecordVariableValues(fuv.getServerSession(),record,cvv.getReferences(),cvv.getValues());
58           if(cvv.getBVE().run(rvv).hashCode() == 0){
59          ;//// Removed By Program ** System.out.println(" Every thing is fine Good work ");
60             throw new DException("DSE879", null);
61           }
62         }
63       }
64     }*/

65   }
66
67   private ArrayList JavaDoc getForUpdateValues(Object JavaDoc sessionId) {
68     synchronized (sessionFUV) {
69       if(count ==0 )
70           return null;
71       Object JavaDoc[] keys = sessionFUV.keySet().toArray();
72       ArrayList JavaDoc toRet = new ArrayList JavaDoc();
73       for (int i = 0 ; i < keys.length; i++) {
74         if(!keys[i].equals(sessionId)) {
75           ForUpdateValues fuv = (ForUpdateValues) sessionFUV.get(keys[i]);
76           toRet.add(new Object JavaDoc [] {fuv.getServerSession(),
77             fuv.getConditionReferenceValuesList()});
78         }
79       }
80       return toRet;
81     }
82   }
83
84   public void removeSession(Object JavaDoc sessionId) {
85     synchronized (sessionFUV) {
86       if(count > 0){
87       Object JavaDoc rmvSession = sessionFUV.remove(sessionId);
88       if(rmvSession != null)
89         count--;
90       }
91     }
92   }
93
94   public void showAll() {
95     if(sessionFUV.size() == 0)
96       return;
97     Object JavaDoc[] keys = (Object JavaDoc[]) sessionFUV.keySet().toArray();
98     StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
99     sb.append(" FORUPDATETABLEHANDLER IS ====== ");
100     for (int i = 0; i < keys.length; i++) {
101       ForUpdateValues fuv = (ForUpdateValues) sessionFUV.get(keys[i]);
102       sb.append(" \nkey"+(i+1)+" ["+keys[i]+"] ").append(" Value[ ");
103       sb.append(" FOR UPDATE VALUES >>>>> ");
104       ArrayList JavaDoc list = fuv.getConditionReferenceValuesList();
105       for (int j = 0, s = list.size(); j < s ; j++) {
106         ConditionReferenceValues crv = (ConditionReferenceValues) list.get(j);
107         sb.append(" ######CRV"+(j+1)+ "###### BVE ["+crv.getBVE().toString()+"] References [" + com.daffodilwoods.database.utility.P.print(crv.getReferences()) + "] VALUES [" + com.daffodilwoods.database.utility.P.print(crv.getReferences()) + "]");
108       }
109       sb.append("]");
110     }
111   }
112
113 }
114
Popular Tags