KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jalisto > se > storage > memory > PhysicalFileAccessMemoryImpl


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.storage.memory;
25
26 import org.objectweb.jalisto.se.api.internal.JalistoObject;
27 import org.objectweb.jalisto.se.api.physical.PluggablePhysicalFileAccess;
28 import org.objectweb.jalisto.se.api.JalistoProperties;
29 import org.objectweb.jalisto.se.exception.JalistoException;
30 import org.objectweb.jalisto.se.impl.InFileAddress;
31 import org.objectweb.jalisto.se.JalistoFactory;
32 import org.objectweb.jalisto.se.impl.trace.Trace;
33
34 import java.util.*;
35
36 public class PhysicalFileAccessMemoryImpl implements PluggablePhysicalFileAccess {
37
38     public PhysicalFileAccessMemoryImpl() {
39     }
40
41     public void init(JalistoProperties properties) {
42         file = new HashMap();
43         this.trace = JalistoFactory.getInternalFactory().getTracer(properties);
44         trace.println(Trace.TRACE_ON, "USE IN MEMORY PHYSICAL IMPLEMENTATION");
45     }
46
47     public boolean isNewBase() {
48         return true;
49     }
50
51     public void reorganize() {
52     }
53
54     public void deleteFileObject(InFileAddress ifa) {
55         trace.println(Trace.PHYSICAL, "memory deleteFileObject : ifa = {0}", ifa);
56         if (!file.containsKey(ifa.getAddress())) {
57             throw new JalistoException("could not delete object at " + ifa);
58         }
59         file.remove(ifa.getAddress());
60     }
61
62     public void insertFileObject(InFileAddress ifa, JalistoObject fo) {
63         trace.println(Trace.PHYSICAL, "memory insertFileObject : ifa = {0}", ifa);
64         if (file.containsKey(ifa.getAddress())) {
65             throw new JalistoException("already contains object at " + ifa + " : could not insert value");
66         }
67         file.put(ifa.getAddress(), fo);
68     }
69
70     public JalistoObject readFileObjectAt(InFileAddress ifa) {
71         trace.println(Trace.PHYSICAL, "memory readFileObjectAt : ifa = {0}", ifa);
72         if (file.containsKey(ifa.getAddress())) {
73             return (JalistoObject) file.get(ifa.getAddress());
74         }
75         throw new JalistoException("could not read object at " + ifa);
76     }
77
78     public void updateFileObject(InFileAddress ifa, JalistoObject fo) {
79         trace.println(Trace.PHYSICAL, "memory updateFileObject : ifa = {0}", ifa);
80         if (!file.containsKey(ifa.getAddress())) {
81             throw new JalistoException("could not update object " + fo);
82         }
83         file.put(ifa.getAddress(), fo);
84     }
85
86     public void startCommit() {
87     }
88
89     public void commit() {
90     }
91
92     public void rollback() {
93         throw new JalistoException("don't support rollback with Memory physical access");
94     }
95
96     public void close() {
97     }
98
99     public void open() {
100     }
101
102     public Collection getKeysStartingWith(String JavaDoc filter) {
103         trace.println(Trace.PHYSICAL, "memory getKeysStartingWith : filter = {0}", filter);
104         Collection result = new ArrayList();
105         Iterator keys = file.keySet().iterator();
106         while (keys.hasNext()) {
107             String JavaDoc key = (String JavaDoc) keys.next();
108             if (key.startsWith(filter)) {
109                 result.add(key);
110             }
111         }
112         return result;
113     }
114
115
116     private Map file;
117     private Trace trace;
118 }
119
Popular Tags