KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jalisto > se > impl > server > LogicalPageAccessImpl


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.server;
25
26 import org.objectweb.jalisto.se.JalistoFactory;
27 import org.objectweb.jalisto.se.api.JalistoProperties;
28 import org.objectweb.jalisto.se.api.internal.*;
29 import org.objectweb.jalisto.se.api.query.FieldDescription;
30 import org.objectweb.jalisto.se.impl.InFileAddress;
31 import org.objectweb.jalisto.se.impl.server.page.*;
32 import org.objectweb.jalisto.se.impl.server.page.info.InMemoryPageInfo;
33 import org.objectweb.jalisto.se.impl.server.page.info.IndexPageInfo;
34 import org.objectweb.jalisto.se.impl.server.page.info.PageInfo;
35 import org.objectweb.jalisto.se.impl.trace.Trace;
36
37 import java.util.*;
38
39 public class LogicalPageAccessImpl implements LogicalSystemPageAccess {
40
41     public LogicalPageAccessImpl(JalistoProperties properties) {
42         InternalFactory internalFactory = JalistoFactory.getInternalFactory();
43         tracer = internalFactory.getTracer(properties);
44         tracer.println(Trace.LOGICAL, "LogicalPageAccessImpl : create new instance");
45         physicalAccess = internalFactory.getInternalPhysicalAccess(properties);
46         ifaIndex = IfaIndex.getAnIfaIndex(physicalAccess, properties);
47         oidProvider = internalFactory.getIdentityProvider(properties);
48         workingSessions = new ArrayList();
49         instancePageSize = properties.getInstancePageSize();
50         systemPageSize = properties.getSystemPageSize();
51         instancePageNumber = properties.getInstanceDbFileNumber();
52         isMonoImplementation = properties.isMonoImplementation();
53         getInMemoryInfos();
54     }
55
56     public String JavaDoc toString() {
57         return physicalAccess.toString();
58     }
59
60     public InternalPhysicalFileAccess getPhysicalAccess() {
61         return physicalAccess;
62     }
63
64     public synchronized void begin(Object JavaDoc sessionId) {
65         tracer.println(Trace.LOGICAL, "{0} : LogicalPageAccessImpl : begin() : nothing to do", sessionId);
66         workingSessions.add(sessionId);
67         physicalAccess.begin();
68         beginInfos(instancePageInfos, sessionId);
69         beginIndexInfos(leafPageInfos, sessionId);
70         beginIndexInfos(nodePageInfos, sessionId);
71     }
72
73     private void beginInfos(Map infos, Object JavaDoc sessionId) {
74         synchronized (infos) {
75             Iterator values = infos.values().iterator();
76             while (values.hasNext()) {
77                 InMemoryPageInfo memoryInfo = (InMemoryPageInfo) values.next();
78                 memoryInfo.begin(sessionId);
79             }
80         }
81     }
82
83     private void beginIndexInfos(Map infos, Object JavaDoc sessionId) {
84         synchronized (infos) {
85             Iterator mapByClasse = infos.values().iterator();
86             while (mapByClasse.hasNext()) {
87                 Iterator values = ((Map) mapByClasse.next()).values().iterator();
88                 while (values.hasNext()) {
89                     InMemoryPageInfo memoryInfo = (InMemoryPageInfo) values.next();
90                     memoryInfo.begin(sessionId);
91                 }
92             }
93         }
94     }
95
96     public synchronized void commit(Object JavaDoc sessionId) {
97         tracer.println(Trace.LOGICAL, "{0} : LogicalPageAccessImpl : commit()", sessionId);
98         workingSessions.remove(sessionId);
99         ifaIndex.updateStateInBase(true);
100         physicalAccess.commit();
101     }
102
103     public synchronized void rollback(Object JavaDoc sessionId) {
104         tracer.println(Trace.LOGICAL, "{0} : LogicalPageAccessImpl : rollback()", sessionId);
105         workingSessions.remove(sessionId);
106         if (isMonoImplementation) {
107             physicalAccess.rollback();
108             ifaIndex.getStateFromBase();
109         } else {
110             // we have to commit changes done by unitary rollbacking operations from lockmanager and session
111
physicalAccess.commit();
112         }
113 // ifaIndex.getStateFromBase();
114
rollbackInfos(sessionId);
115         rollbackIndexInfos(leafPageInfos, sessionId);
116         rollbackIndexInfos(nodePageInfos, sessionId);
117     }
118
119     private void rollbackInfos(Object JavaDoc sessionId) {
120         synchronized (instancePageInfos) {
121             Iterator values = instancePageInfos.values().iterator();
122             ArrayList toDelete = new ArrayList();
123             while (values.hasNext()) {
124                 InMemoryPageInfo memoryInfo = (InMemoryPageInfo) values.next();
125                 if (!memoryInfo.rollback(sessionId)) {
126                     toDelete.add(memoryInfo);
127                 }
128             }
129             for (short i = 0; i < toDelete.size(); i++) {
130                 Object JavaDoc pid = ((InMemoryPageInfo) toDelete.get(i)).getPid();
131                 instancePageInfos.remove(pid);
132                 instanceFreePagePidList.remove(pid);
133             }
134         }
135     }
136
137     private void rollbackIndexInfos(Map infos, Object JavaDoc sessionId) {
138         synchronized (infos) {
139             Iterator valuesByClasses = infos.values().iterator();
140             ArrayList toDelete = new ArrayList();
141             while (valuesByClasses.hasNext()) {
142                 Iterator values = ((Map) valuesByClasses.next()).values().iterator();
143                 while (values.hasNext()) {
144                     InMemoryPageInfo memoryInfo = (InMemoryPageInfo) values.next();
145                     if (!memoryInfo.rollback(sessionId)) {
146                         toDelete.add(memoryInfo);
147                     }
148                 }
149             }
150             for (short i = 0; i < toDelete.size(); i++) {
151                 infos.remove(((InMemoryPageInfo) toDelete.get(i)).getPid());
152             }
153         }
154     }
155
156     public void cleanAllNullValue() {
157         tracer.println(Trace.LOGICAL, "LogicalPageAccessImpl : cleanAllNullValue()");
158         Iterator pidIfas = ifaIndex.getAllPidIfa().iterator();
159         while (pidIfas.hasNext()) {
160             InFileAddress ifa = (InFileAddress) pidIfas.next();
161             SystemPage systemPage = (SystemPage) physicalAccess.readFileObjectAt(ifa);
162             PageInfo pageInfo = (PageInfo) systemPage.getDataAt(ifa);
163             InFileAddress instanceIfa = pageInfo.getPageIfa();
164             UserPage dataPage = (UserPage) physicalAccess.readFileObjectAt(instanceIfa);
165             Iterator freePlaces = pageInfo.getAllFreePlace();
166             while (freePlaces.hasNext()) {
167                 instanceIfa.setIndex(((Integer JavaDoc) freePlaces.next()).intValue());
168                 dataPage.setDataAt(instanceIfa, null);
169             }
170             physicalAccess.updateFileObject(dataPage);
171         }
172     }
173
174     /**
175      * ******************************** INSTANCE *********************************************
176      */

177
178     public PhysicalOid allocateNewFpoid(Object JavaDoc sessionId, Object JavaDoc clid) {
179         tracer.println(Trace.LOGICAL, "{1} : LogicalPageAccessImpl : allocateNewFpoid({0})", clid, sessionId);
180         synchronized (instancePageInfos) {
181             // find the next instance page to use
182
InFileAddress availableSystemIfa = getFreeSystemIfaIn(instanceFreePagePidList, instancePageInfos);
183             PageInfo infos;
184             SystemPage systemPage;
185             if (availableSystemIfa != null) {
186                 systemPage = (SystemPage) physicalAccess.readFileObjectAt(availableSystemIfa);
187                 infos = (PageInfo) systemPage.getDataAt(availableSystemIfa);
188             } else {
189                 systemPage = getOrCreateAvailableSystemPage();
190                 infos = buildNewInstancePage(sessionId, oidProvider.getNewPid(), systemPage.getIfa());
191                 systemPage.setDataAt(systemPage.getIfa(), infos);
192             }
193             Object JavaDoc iid = infos.getAFreePlace();
194             InMemoryPageInfo memInfos = (InMemoryPageInfo) instancePageInfos.get(infos.getPid());
195             memInfos.getAFreeSpace(sessionId);
196             if (memInfos.getFreeSpaceSize() == 0) {
197                 instanceFreePagePidList.remove(infos.getPid());
198             }
199             physicalAccess.updateFileObject(systemPage);
200             PhysicalOid fpoid = new PhysicalOid(clid, infos.getPid(), iid);
201
202             InFileAddress instanceIfa = infos.getPageIfa();
203             instanceIfa.setIndex(fpoid.getIidAsInteger().intValue());
204             InstancePage dataPage = (InstancePage) physicalAccess.readFileObjectAt(instanceIfa);
205             if (dataPage.getDataAt(instanceIfa) != null) {
206                 dataPage.setDataAt(instanceIfa, null);
207                 physicalAccess.updateFileObject(dataPage);
208             }
209
210             return fpoid;
211         }
212     }
213
214     public void desallocateFpoid(Object JavaDoc sessionId, PhysicalOid fpoid) {
215         tracer.println(Trace.LOGICAL, "{1} : LogicalPageAccessImpl : desallocateFpoid({0})", fpoid, sessionId);
216         deleteDatas(sessionId, fpoid);
217     }
218
219     // allocation is done
220
public void insertDatas(Object JavaDoc sessionId, PhysicalOid fpoid, DataWrapper datas) {
221         tracer.println(Trace.LOGICAL, "{2} : LogicalPageAccessImpl : insertDatas({0}, {1})", fpoid, datas, sessionId);
222         InFileAddress instanceIfa = getInstanceIfa(fpoid);
223         InstancePage dataPage = (InstancePage) physicalAccess.readFileObjectAt(instanceIfa);
224         dataPage.setDataAt(instanceIfa, datas);
225         physicalAccess.updateFileObject(dataPage);
226     }
227
228     public DataWrapper readDatas(Object JavaDoc sessionId, PhysicalOid fpoid) {
229         tracer.println(Trace.LOGICAL, "{2} : LogicalPageAccessImpl : readDatas({0})", fpoid);
230         InFileAddress ifa = getInstanceIfa(fpoid);
231         InstancePage dataPage = (InstancePage) physicalAccess.readFileObjectAt(ifa);
232         return (DataWrapper) dataPage.getDataAt(ifa);
233     }
234
235     public PhysicalOid updateDatas(Object JavaDoc sessionId, PhysicalOid fpoid, DataWrapper datas) {
236         tracer.println(Trace.LOGICAL, "{2} : LogicalPageAccessImpl : updateDatas({0}, {1})", fpoid, datas, sessionId);
237         InFileAddress ifa = getInstanceIfa(fpoid);
238         InstancePage dataPage = (InstancePage) physicalAccess.readFileObjectAt(ifa);
239         dataPage.setDataAt(ifa, datas);
240         physicalAccess.updateFileObject(dataPage);
241         return fpoid;
242     }
243
244     public void deleteDatas(Object JavaDoc sessionId, PhysicalOid fpoid) {
245         tracer.println(Trace.LOGICAL, "{1} : LogicalPageAccessImpl : deleteDatas({0})", fpoid, sessionId);
246         // get ifa of the system page
247
InFileAddress systemIfa = ifaIndex.getPidIfa(fpoid.getPid());
248         // get the page
249
SystemPage systemPage = (SystemPage) physicalAccess.readFileObjectAt(systemIfa);
250         synchronized (instancePageInfos) {
251             // get the page info
252
PageInfo infos = (PageInfo) systemPage.getDataAt(systemIfa);
253             infos.allocateFreeSpaceAt(fpoid.getIidAsInteger());
254             InMemoryPageInfo memInfos = (InMemoryPageInfo) instancePageInfos.get(infos.getPid());
255             memInfos.freeASpace(sessionId);
256             if (memInfos.getFreeSpaceSize() == 1) {
257                 instanceFreePagePidList.addFirst(memInfos.getPid());
258             }
259             // update page where modifications has been done
260
physicalAccess.updateFileObject(systemPage);
261         }
262     }
263
264
265     /**
266      * ************************************ INDEX ************************************************
267      */

268
269     public InFileAddress allocateNodeAddressAndInsert(Object JavaDoc sessionId, FieldDescription meta, DataWrapper node) {
270         tracer.println(Trace.LOGICAL, "{0} : LogicalPageAccessImpl : allocateNodeAddressAndInsert()", sessionId);
271         synchronized (nodePageInfos) {
272             String JavaDoc fieldKey = meta.getClassMeta().getClassName() + "-" + meta.getFieldName();
273             Map m = (Map) nodePageInfos.get(fieldKey);
274             if (m == null) {
275                 m = new HashMap();
276                 nodePageInfos.put(fieldKey, m);
277             }
278             InFileAddress availableSystemIfa = getFreeSystemIfaIn(null, m);
279             PageInfo infos;
280             SystemPage systemPage;
281             if (availableSystemIfa != null) {
282                 availableSystemIfa = availableSystemIfa.getClone();
283                 systemPage = (SystemPage) physicalAccess.readFileObjectAt(availableSystemIfa);
284                 infos = (PageInfo) systemPage.getDataAt(availableSystemIfa);
285             } else {
286                 systemPage = getOrCreateAvailableSystemPage();
287                 infos = buildNewNodePage(sessionId, meta, oidProvider.getNewPid(), systemPage.getIfa());
288                 systemPage.setDataAt(systemPage.getIfa(), infos);
289             }
290             Integer JavaDoc iid = infos.getAFreePlace();
291             ((InMemoryPageInfo) m.get(infos.getPid())).getAFreeSpace(sessionId);
292             InFileAddress pageIfa = infos.getPageIfa();
293             pageIfa.setIndex(iid.intValue());
294             node.setIfa(pageIfa);
295             NodePage nodePage = (NodePage) physicalAccess.readFileObjectAt(pageIfa);
296             nodePage.setDataAt(pageIfa, node);
297             physicalAccess.updateFileObject(systemPage);
298             physicalAccess.updateFileObject(nodePage);
299             return pageIfa.getClone();
300         }
301     }
302
303     public Object JavaDoc readNode(Object JavaDoc sessionId, InFileAddress ifa) {
304         NodePage page = (NodePage) physicalAccess.readFileObjectAt(ifa);
305         return page.getDataAt(ifa);
306     }
307
308     public void updateNode(Object JavaDoc sessionId, InFileAddress ifa, DataWrapper node) {
309         updateIndexObject(ifa, node);
310     }
311
312     public void removeNode(Object JavaDoc sessionId, InFileAddress ifa) {
313         tracer.println(Trace.LOGICAL, "{1} : LogicalPageAccessImpl : removeNode({0})", ifa, sessionId);
314         NodePage nodePage = (NodePage) physicalAccess.readFileObjectAt(ifa);
315         InFileAddress systemIfa = ifaIndex.getPidIfa(nodePage.getPid());
316         SystemPage systemPage = (SystemPage) physicalAccess.readFileObjectAt(systemIfa);
317         synchronized (nodePageInfos) {
318             IndexPageInfo indexInfos = (IndexPageInfo) systemPage.getDataAt(systemIfa);
319             indexInfos.allocateFreeSpaceAt(new Integer JavaDoc(ifa.getIndex()));
320             Map m = (Map) nodePageInfos.get(indexInfos.getFieldKey());
321             ((InMemoryPageInfo) m.get(nodePage.getPid())).getAFreeSpace(sessionId);
322             physicalAccess.updateFileObject(systemPage);
323         }
324     }
325
326     public InFileAddress allocateLeafAddressAndInsert(Object JavaDoc sessionId, FieldDescription meta, DataWrapper oids) {
327         tracer.println(Trace.LOGICAL, "{0} : LogicalPageAccessImpl : allocateLeafAddressAndInsert()");
328         synchronized (leafPageInfos) {
329             String JavaDoc fieldKey = meta.getClassMeta().getClassName() + "-" + meta.getFieldName();
330             Map m = (Map) leafPageInfos.get(fieldKey);
331             if (m == null) {
332                 m = new HashMap();
333                 leafPageInfos.put(fieldKey, m);
334             }
335             InFileAddress availableSystemIfa = getFreeSystemIfaIn(null, m);
336             PageInfo infos;
337             SystemPage systemPage;
338             if (availableSystemIfa != null) {
339                 availableSystemIfa = availableSystemIfa.getClone();
340                 systemPage = (SystemPage) physicalAccess.readFileObjectAt(availableSystemIfa);
341                 infos = (PageInfo) systemPage.getDataAt(availableSystemIfa);
342             } else {
343                 systemPage = getOrCreateAvailableSystemPage();
344                 infos = buildNewLeafPage(sessionId, meta, oidProvider.getNewPid(), systemPage.getIfa());
345                 systemPage.setDataAt(systemPage.getIfa(), infos);
346             }
347             Integer JavaDoc iid = infos.getAFreePlace();
348             ((InMemoryPageInfo) m.get(infos.getPid())).getAFreeSpace(sessionId);
349             InFileAddress pageIfa = infos.getPageIfa();
350             pageIfa.setIndex(iid.intValue());
351             oids.setIfa(pageIfa);
352             LeafPage leafPage = (LeafPage) physicalAccess.readFileObjectAt(pageIfa);
353             leafPage.setDataAt(pageIfa, oids);
354             physicalAccess.updateFileObject(systemPage);
355             physicalAccess.updateFileObject(leafPage);
356             return pageIfa.getClone();
357         }
358     }
359
360     public Object JavaDoc readLeaf(Object JavaDoc sessionId, InFileAddress ifa) {
361         LeafPage page = (LeafPage) physicalAccess.readFileObjectAt(ifa);
362         return page.getDataAt(ifa);
363     }
364
365     public void updateLeaf(Object JavaDoc sessionId, InFileAddress ifa, DataWrapper oids) {
366         updateIndexObject(ifa, oids);
367     }
368
369     public void removeLeaf(Object JavaDoc sessionId, InFileAddress ifa) {
370         tracer.println(Trace.LOGICAL, "{1} : LogicalPageAccessImpl : removeNode({0})", ifa, sessionId);
371         LeafPage leafPage = (LeafPage) physicalAccess.readFileObjectAt(ifa);
372         InFileAddress systemIfa = ifaIndex.getPidIfa(leafPage.getPid());
373         SystemPage systemPage = (SystemPage) physicalAccess.readFileObjectAt(systemIfa);
374         synchronized (leafPageInfos) {
375             IndexPageInfo indexInfos = (IndexPageInfo) systemPage.getDataAt(systemIfa);
376             indexInfos.allocateFreeSpaceAt(new Integer JavaDoc(ifa.getIndex()));
377             Map m = (Map) leafPageInfos.get(indexInfos.getFieldKey());
378             ((InMemoryPageInfo) m.get(leafPage.getPid())).getAFreeSpace(sessionId);
379             physicalAccess.updateFileObject(systemPage);
380         }
381     }
382
383     /**
384      * ******************************** PRIVATE ********************************************
385      */

386
387     private InFileAddress getInstanceIfa(PhysicalOid fpoid) {
388         InFileAddress systemIfa = ifaIndex.getPidIfa(fpoid.getPid());
389         SystemPage systemPage = null;
390         systemPage = (SystemPage) physicalAccess.readFileObjectAt(systemIfa);
391         PageInfo infos = (PageInfo) systemPage.getDataAt(systemIfa);
392         InFileAddress instanceIfa = infos.getPageIfa();
393         instanceIfa.setIndex(fpoid.getIidAsInteger().intValue());
394         return instanceIfa;
395     }
396
397     private void getInMemoryInfos() {
398         instancePageInfos = Collections.synchronizedMap(new HashMap());
399         instanceFreePagePidList = new LinkedList();
400         leafPageInfos = Collections.synchronizedMap(new HashMap());
401         nodePageInfos = Collections.synchronizedMap(new HashMap());
402
403         Iterator pids = ifaIndex.getAllPid().iterator();
404         while (pids.hasNext()) {
405             Object JavaDoc pid = pids.next();
406             InFileAddress ifa = ifaIndex.getPidIfa(pid);
407             SystemPage systemPage = (SystemPage) physicalAccess.readFileObjectAt(ifa);
408             PageInfo pageInfo = (PageInfo) systemPage.getDataAt(ifa);
409             InMemoryPageInfo memoryPageInfo = InMemoryPageInfo.createNewInstance(
410                     null, isMonoImplementation, pageInfo);
411             if (pageInfo.getPageType() == Page.INSTANCEPAGE_TYPE) {
412                 instancePageInfos.put(pid, memoryPageInfo);
413                 if (memoryPageInfo.getFreeSpaceSize() > 0) {
414                     instanceFreePagePidList.add(pid);
415                 }
416             } else {
417                 String JavaDoc fieldKey = ((IndexPageInfo) pageInfo).getFieldKey();
418                 if (pageInfo.getPageType() == Page.LEAFPAGE_TYPE) {
419                     Map m = (Map) leafPageInfos.get(fieldKey);
420                     if (m == null) {
421                         m = new HashMap();
422                         leafPageInfos.put(fieldKey, m);
423                     }
424                     m.put(pid, memoryPageInfo);
425                 } else {
426                     Map m = (Map) nodePageInfos.get(fieldKey);
427                     if (m == null) {
428                         m = new HashMap();
429                         nodePageInfos.put(fieldKey, m);
430                     }
431                     m.put(pid, memoryPageInfo);
432                 }
433             }
434         }
435     }
436
437     private int getInstanceFileIndex() {
438         fileIndex = (fileIndex + 1) % instancePageNumber;
439         return (fileIndex + 2);
440     }
441
442     private int getLeafFileIndex() {
443         fileIndex = (fileIndex + 1) % instancePageNumber;
444         return (fileIndex + 2);
445     }
446
447     private int getNodeFileIndex() {
448         fileIndex = (fileIndex + 1) % instancePageNumber;
449         return (fileIndex + 2);
450     }
451
452     private InFileAddress getFreeSystemIfaIn(LinkedList pids, Map infos) {
453         synchronized (infos) {
454             if (pids != null) {
455                 while (!pids.isEmpty()) {
456                     Object JavaDoc pid = pids.getFirst();
457                     InMemoryPageInfo memoryInfo = (InMemoryPageInfo) infos.get(pid);
458                     if (memoryInfo.getFreeSpaceSize() > 0) {
459                         return ifaIndex.getPidIfa(pid);
460                     }
461                     pids.removeFirst();
462                 }
463             } else {
464                 Iterator pidsIterator = infos.keySet().iterator();
465                 while (pidsIterator.hasNext()) {
466                     Object JavaDoc pid = pidsIterator.next();
467                     InMemoryPageInfo memoryInfo = (InMemoryPageInfo) infos.get(pid);
468                     if (memoryInfo.getFreeSpaceSize() > 0) {
469                         return ifaIndex.getPidIfa(pid);
470                     }
471                 }
472             }
473         }
474         return null;
475     }
476
477     private synchronized PageInfo buildNewInstancePage(Object JavaDoc sessionId, Object JavaDoc pid, InFileAddress systemIfa) {
478         InstancePage page = new InstancePage(instancePageSize, pid);
479         InFileAddress pageIfa = new InFileAddress(ifaIndex.getNewInstancePageAddress());
480         pageIfa.setFileIndex(getInstanceFileIndex());
481         page.setIfa(pageIfa);
482         physicalAccess.insertFileObject(page);
483
484         PageInfo pageInfo = new PageInfo(instancePageSize, Page.INSTANCEPAGE_TYPE);
485         pageInfo.setPageIfa(pageIfa);
486         pageInfo.setPid(pid);
487
488         InMemoryPageInfo inMemoryPageInfo =
489                 InMemoryPageInfo.createNewInstance(workingSessions, isMonoImplementation, pageInfo);
490         instancePageInfos.put(pid, inMemoryPageInfo);
491         instanceFreePagePidList.addFirst(pid);
492         ifaIndex.putPidIfa(pid, systemIfa.getClone());
493
494         return pageInfo;
495     }
496
497     private synchronized PageInfo buildNewLeafPage(
498             Object JavaDoc sessionId, FieldDescription meta, Object JavaDoc pid, InFileAddress systemIfa) {
499         String JavaDoc fieldKey = meta.getClassMeta().getClassName() + "-" + meta.getFieldName();
500         short size = meta.getIndexDescription().getLeafPageSize();
501         LeafPage page = new LeafPage(size, pid);
502         InFileAddress pageIfa = new InFileAddress(ifaIndex.getNewLeafPageAddress());
503         pageIfa.setFileIndex(getLeafFileIndex());
504         page.setIfa(pageIfa);
505         physicalAccess.insertFileObject(page);
506
507         IndexPageInfo pageInfo = new IndexPageInfo(size, Page.LEAFPAGE_TYPE, fieldKey);
508         pageInfo.setPageIfa(pageIfa);
509         pageInfo.setPid(pid);
510
511         Map m = (Map) leafPageInfos.get(fieldKey);
512         m.put(pid, InMemoryPageInfo.createNewInstance(workingSessions, isMonoImplementation, pageInfo));
513         ifaIndex.putPidIfa(pid, systemIfa.getClone());
514
515         return pageInfo;
516     }
517
518     private synchronized PageInfo buildNewNodePage(
519             Object JavaDoc sessionId, FieldDescription meta, Object JavaDoc pid, InFileAddress systemIfa) {
520         String JavaDoc fieldKey = meta.getClassMeta().getClassName() + "-" + meta.getFieldName();
521         short size = meta.getIndexDescription().getNodePageSize();
522         NodePage page = new NodePage(size, pid);
523         InFileAddress pageIfa = new InFileAddress(ifaIndex.getNewNodePageAddress());
524         pageIfa.setFileIndex(getNodeFileIndex());
525         page.setIfa(pageIfa);
526         physicalAccess.insertFileObject(page);
527
528         IndexPageInfo pageInfo = new IndexPageInfo(size, Page.NODEPAGE_TYPE, fieldKey);
529         pageInfo.setPageIfa(pageIfa);
530         pageInfo.setPid(pid);
531
532         Map m = (Map) nodePageInfos.get(fieldKey);
533         m.put(pid, InMemoryPageInfo.createNewInstance(workingSessions, isMonoImplementation, pageInfo));
534         ifaIndex.putPidIfa(pid, systemIfa.getClone());
535
536         return pageInfo;
537     }
538
539     public void updateIndexObject(InFileAddress ifa, DataWrapper indexObject) {
540         tracer.println(Trace.LOGICAL, "LogicalPageAccessImpl : updateIndexObject({0}, {1})", ifa, indexObject);
541         UserPage page = (UserPage) physicalAccess.readFileObjectAt(ifa);
542         page.setDataAt(ifa, indexObject);
543         physicalAccess.updateFileObject(page);
544     }
545
546     private synchronized SystemPage getOrCreateAvailableSystemPage() {
547         InFileAddress availableSystemPageIfa = ifaIndex.getCurrentAvalaibleSystemPage().getClone();
548         SystemPage systemPage;
549         if (availableSystemPageIfa.getIndex() == (systemPageSize - 1)) {
550             availableSystemPageIfa = new InFileAddress(ifaIndex.getNewSystemPageAddress());
551             systemPage = new SystemPage(systemPageSize);
552             systemPage.setIfa(availableSystemPageIfa);
553             physicalAccess.insertFileObject(systemPage);
554         } else {
555             availableSystemPageIfa.setIndex(availableSystemPageIfa.getIndex() + 1);
556             systemPage = (SystemPage) physicalAccess.readFileObjectAt(availableSystemPageIfa);
557             systemPage.setIfa(availableSystemPageIfa);
558         }
559         ifaIndex.setCurrentAvalaibleSystemPage(availableSystemPageIfa);
560         return systemPage;
561     }
562
563
564     private ArrayList workingSessions;
565     private IfaIndex ifaIndex;
566     private IdentityProvider oidProvider;
567     private InternalPhysicalFileAccess physicalAccess;
568
569     private Map instancePageInfos;
570     private LinkedList instanceFreePagePidList;
571     private Map leafPageInfos;
572     private Map nodePageInfos;
573
574     private int fileIndex = 0;
575     private int instancePageNumber;
576     private short instancePageSize;
577     private short systemPageSize;
578
579     private boolean isMonoImplementation;
580
581     private Trace tracer;
582 }
583
Popular Tags