KickJava   Java API By Example, From Geeks To Geeks.

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


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.api.*;
27 import org.objectweb.jalisto.se.api.internal.InternalPhysicalFileAccess;
28 import org.objectweb.jalisto.se.api.physical.PluggablePhysicalFileAccess;
29 import org.objectweb.jalisto.se.api.internal.*;
30 import org.objectweb.jalisto.se.exception.JalistoException;
31 import org.objectweb.jalisto.se.impl.trace.Trace;
32 import org.objectweb.jalisto.se.impl.InFileAddress;
33 import org.objectweb.jalisto.se.JalistoFactory;
34
35 import java.util.Collection JavaDoc;
36
37 public class InternalPhysicalFileAccessImpl implements InternalPhysicalFileAccess {
38
39     public InternalPhysicalFileAccessImpl(JalistoProperties properties) {
40         InternalFactory internalFactory = JalistoFactory.getInternalFactory();
41         this.tracer = internalFactory.getTracer(properties);
42         this.internalAccess = internalFactory.getPhysicalAccess(properties);
43         this.baseImage = internalFactory.getAInTransactionBaseImage(internalAccess, properties);
44         this.sessionCounter = 0;
45     }
46
47
48     public boolean isNewBase() {
49         return internalAccess.isNewBase();
50     }
51
52
53     public void insertFileObject(JalistoObject fo) {
54         tracer.println(Trace.PHYSICAL, "insertFileObject({0})", fo);
55         try {
56             baseImage.insertFileObject(fo.getIfa(), fo);
57         } catch (Exception JavaDoc e) {
58             throw new JalistoException("could not insert object " + fo, e);
59         }
60     }
61
62     public JalistoObject readFileObjectAt(InFileAddress ifa) {
63         tracer.println(Trace.PHYSICAL, "readFileObjectAt({0})", ifa);
64         try {
65             return baseImage.readFileObjectAt(ifa);
66         } catch (Exception JavaDoc e) {
67             throw new JalistoException("could not read object at " + ifa, e);
68         }
69     }
70
71     public void updateFileObject(JalistoObject fo) {
72         tracer.println(Trace.PHYSICAL, "updateFileObject({0})", fo);
73         try {
74             baseImage.updateFileObject(fo.getIfa(), fo);
75         } catch (Exception JavaDoc e) {
76             throw new JalistoException("could not update object " + fo, e);
77         }
78     }
79
80     public void deleteFileObject(InFileAddress ifa) {
81         tracer.println(Trace.PHYSICAL, "deleteFileObject({0})", ifa);
82         try {
83             baseImage.deleteFileObject(ifa);
84         } catch (Exception JavaDoc e) {
85             throw new JalistoException("could not delete object at " + ifa, e);
86         }
87     }
88
89     public void writeObjectInBase(InFileAddress ifa, Object JavaDoc o, boolean isUpdate) {
90         JalistoObject objectInBase = new JalistoObjectImpl();
91         objectInBase.setIfa(ifa);
92         objectInBase.setData(o);
93         if (isUpdate) {
94             updateFileObject(objectInBase);
95         } else {
96             insertFileObject(objectInBase);
97         }
98     }
99
100
101     public PluggablePhysicalFileAccess getInternalAccess() {
102         return internalAccess;
103     }
104
105
106     public void begin() {
107         tracer.println(Trace.PHYSICAL, "begin()");
108     }
109
110     public void commit() {
111         tracer.println(Trace.PHYSICAL, "commit()");
112         baseImage.commit();
113     }
114
115     public void rollback() {
116         tracer.println(Trace.PHYSICAL, "rollback()");
117         baseImage.rollback();
118     }
119
120     public void open() {
121         if (sessionCounter == 0) {
122             internalAccess.open();
123         }
124         sessionCounter++;
125     }
126
127     public void close() {
128         if (sessionCounter > 0) {
129             sessionCounter--;
130         } else {
131             throw new JalistoException("invalid close call : sessionCounter = " + sessionCounter);
132         }
133         if (sessionCounter == 0) {
134             internalAccess.close();
135         }
136     }
137
138     public Collection JavaDoc getKeysStartingWith(String JavaDoc filter, boolean withOrder) {
139         return baseImage.getKeysStartingWith(filter, withOrder);
140     }
141
142
143     public InTransactionBaseImage getBaseImage() {
144         return baseImage;
145     }
146
147     public String JavaDoc toString() {
148         return internalAccess.toString();
149     }
150
151     private InTransactionBaseImage baseImage;
152     private PluggablePhysicalFileAccess internalAccess;
153     private int sessionCounter;
154     private Trace tracer;
155
156
157 }
158
Popular Tags