KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jalisto > se > impl > multi > OidTableMultiImpl


1 /*
2  * Jalisto - JAva LIght STOrage
3  * Copyright (C) 2000-2005 Xcalia http://www.xcalia.com
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
18  *
19  * Xcalia
20  * 71, rue Desnouettes
21  * 75014 Paris - France
22  * http://www.xcalia.com
23  */

24 package org.objectweb.jalisto.se.impl.multi;
25
26 import org.objectweb.jalisto.se.impl.LogicalOid;
27 import org.objectweb.jalisto.se.api.internal.OidTable;
28 import org.objectweb.jalisto.se.api.internal.InternalPhysicalFileAccess;
29 import org.objectweb.jalisto.se.api.JalistoProperties;
30 import org.objectweb.jalisto.se.exception.IdentityException;
31 import org.objectweb.jalisto.se.impl.ExtentImpl;
32 import org.objectweb.jalisto.se.impl.server.PhysicalOid;
33 import org.objectweb.jalisto.se.impl.server.oid.OidInfo;
34 import org.objectweb.jalisto.se.impl.server.oid.OidTableImpl;
35
36 import java.util.*;
37
38 public class OidTableMultiImpl extends OidTableImpl {
39
40     private OidTableMultiImpl(InternalPhysicalFileAccess physicalAccess, JalistoProperties properties) {
41         super(physicalAccess, properties);
42         transactionnalOidsMap = new HashMap();
43     }
44
45     public synchronized void setUpdate(Object JavaDoc sessionId, LogicalOid floid, short value) {
46         // info must be here because method is called just after modification during commit phase
47
OidInfo info = (OidInfo) getTransactionnalOids(sessionId).get(floid);
48         if (info == null) {
49             info = (OidInfo) floidTable.get(floid);
50             if (info == null) {
51                 if (loadOidPage(sessionId, floid)) {
52                     info = (OidInfo) floidTable.get(floid);
53                 } else {
54                     throw new IdentityException();
55                 }
56             }
57         }
58         info.setUpdate(value);
59     }
60
61     public synchronized short getUpdate(Object JavaDoc sessionId, LogicalOid floid, boolean transactionnal) {
62         OidInfo info = null;
63         if (transactionnal) {
64             info = (OidInfo) getTransactionnalOids(sessionId).get(floid);
65         }
66         if (info == null) {
67             info = (OidInfo) floidTable.get(floid);
68             if (info == null) {
69                 if (loadOidPage(sessionId, floid)) {
70                     info = (OidInfo) floidTable.get(floid);
71                 } else {
72                     return -1;
73                 }
74             }
75         }
76         return info.getUpdate();
77     }
78
79     protected Map getTransactionnalOids(Object JavaDoc sessionId) {
80         return (Map) transactionnalOidsMap.get(sessionId);
81     }
82
83     public void open(Object JavaDoc sessionId) {
84         transactionnalOidsMap.put(sessionId, new TreeMap());
85     }
86
87     public void close(Object JavaDoc sessionId) {
88         transactionnalOidsMap.remove(sessionId);
89     }
90
91     /**
92      * ***************************** synchronized methods ***********************************
93      */

94
95     public synchronized LogicalOid allocateNewFloid(short clid) {
96         return super.allocateNewFloid(clid);
97     }
98
99     public synchronized Collection getFloidsFromClid(Object JavaDoc sessionId, Object JavaDoc clid, boolean fullyTransactionnal) {
100         return super.getFloidsFromClid(sessionId, clid, fullyTransactionnal);
101     }
102
103     public synchronized Collection getFloidsFromClid(Object JavaDoc sessionId, Object JavaDoc clid, ExtentImpl extent, int number) {
104         return super.getFloidsFromClid(sessionId, clid, extent, number);
105     }
106
107     public synchronized PhysicalOid getFpoid(Object JavaDoc sessionId, LogicalOid floid) {
108         return super.getFpoid(sessionId, floid);
109     }
110
111     public synchronized PhysicalOid getDeletedFpoid(Object JavaDoc sessionId, LogicalOid floid) {
112         return super.getDeletedFpoid(sessionId, floid);
113     }
114
115     public synchronized void removeFloid(Object JavaDoc sessionId, LogicalOid floid) {
116         super.removeFloid(sessionId, floid);
117     }
118
119     public synchronized void updatePoid(Object JavaDoc sessionId, LogicalOid floid, PhysicalOid newFpoid) {
120         super.updatePoid(sessionId, floid, newFpoid);
121     }
122
123     private Map transactionnalOidsMap;
124
125     /**
126      * ******************************* STATIC *******************************************
127      */

128
129     public static OidTable getAnOidTable(InternalPhysicalFileAccess physicalAccess, JalistoProperties properties) {
130         OidTableMultiImpl oidTable;
131         try {
132             oidTable = new OidTableMultiImpl(physicalAccess, properties);
133             oidTable.readAtTable();
134         } catch (Exception JavaDoc e) {
135             oidTable = new OidTableMultiImpl(physicalAccess, properties);
136         }
137         oidTable.oidPageSize = properties.getOidPageSize();
138         return oidTable;
139     }
140
141 }
142
Popular Tags