KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > perseus > connector > ra > fos > FosConnectionImpl


1 /**
2  * perseus/connector: this is an implementation of some JCA-related technologies
3  * (resource adapters and managers) for the ObjectWeb consortium.
4  * Copyright (C) 2001-2002 France Telecom R&D
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  * Contact: pascal.dechamboux@rd.francetelecom.com
21  *
22  */

23
24 package org.objectweb.perseus.connector.ra.fos;
25
26 import org.objectweb.perseus.fos.api.FosException;
27 import org.objectweb.perseus.fos.api.FosLoggerFactory;
28 import org.objectweb.perseus.fos.api.FosStructure;
29 import org.objectweb.util.monolog.api.BasicLevel;
30 import org.objectweb.util.monolog.api.Logger;
31
32 import java.util.Iterator JavaDoc;
33 import javax.resource.ResourceException JavaDoc;
34 import javax.resource.cci.Connection JavaDoc;
35 import javax.resource.cci.ConnectionMetaData JavaDoc;
36 import javax.resource.cci.Interaction JavaDoc;
37 import javax.resource.cci.LocalTransaction JavaDoc;
38 import javax.resource.cci.ResultSetInfo JavaDoc;
39
40 /**
41  * @author S. Chassande-Barrioz, P. Dechamboux
42  */

43 //public class FosConnectionImpl implements FileAccess, ConnectionMetaData {
44

45 public class FosConnectionImpl
46     implements FosConnection, ConnectionMetaData JavaDoc {
47     /**
48      * The logger into which traces about FosConnectionImpl are produced.
49      */

50     private Logger logger;
51     /**
52      * The name of this storage sub-system.
53      */

54     private final static String JavaDoc EISPRODUCTNAME = "File Object Store (FOS)";
55     /**
56      * The ConnectionFactory that have requested the allocation of this
57      * Connection.
58      */

59     private FosConnectionFactory connectionFactory;
60     /**
61      * The ManagedConnection associated with this Connection.
62      */

63     private FosManagedConnection managedConnection = null;
64
65     /**
66      * Constructs a FosConnectionImpl.
67      * @param el The logger into which to produce Connection-related traces.
68      * @param fcf The ConnectionFactory that has requested the Connection
69      * creation.
70      */

71     FosConnectionImpl(Logger el, FosConnectionFactory fcf) {
72         logger = el;
73         if (FosLoggerFactory.DEBUG)
74             logger.log(BasicLevel.DEBUG, "Constructs a new FosConnectionImpl.");
75         connectionFactory = fcf;
76     }
77
78     /**
79      * Initializes a Connection to be linked with a ManagedConnection.
80      * @param mc The ManagedConnection to be linked to.
81      */

82     void initialize(FosManagedConnection mc) {
83         managedConnection = mc;
84     }
85
86     // IMPLEMENTATION OF METHODS FROM THE (cci)Connection INTERFACE
87

88     /**
89      * No support for Interaction.
90      */

91     public Interaction JavaDoc createInteraction() throws ResourceException JavaDoc {
92         throw new ResourceException JavaDoc("FOS: no support for Interaction.");
93     }
94
95     public LocalTransaction JavaDoc getLocalTransaction() throws ResourceException JavaDoc {
96         if (managedConnection == null)
97             throw new ResourceException JavaDoc("FOS: cannot get a LocalTransaction with no associated ManagedConnection.");
98         return managedConnection;
99     }
100
101     /**
102      * The FosConnectionImpl manages the metadata on its own.
103      */

104     public ConnectionMetaData JavaDoc getMetaData() throws ResourceException JavaDoc {
105         return this;
106     }
107
108     /**
109      * No support for ResultSet.
110      */

111     public ResultSetInfo JavaDoc getResultSetInfo() throws ResourceException JavaDoc {
112         throw new ResourceException JavaDoc("FOS: no support for ResultSet.");
113     }
114
115     /**
116      * Closes this Connection. Dissociates from the ManagedConnection to which
117      * it is linked.
118      */

119     public void close() throws ResourceException JavaDoc {
120         if (managedConnection == null)
121             throw new ResourceException JavaDoc("FOS: cannot close a Connection with no associated ManagedConnection.");
122         if (FosLoggerFactory.DEBUG)
123             logger.log(BasicLevel.DEBUG, "Closes Connection: " + this);
124         managedConnection.dissociateConnection(this);
125         managedConnection = null;
126     }
127
128     /**
129      * Sets the connection to the relevant auto-commit mode.
130      */

131     public void setAutoCommit(boolean b) throws ResourceException JavaDoc {
132         if (managedConnection == null)
133             throw new ResourceException JavaDoc("FOS: no associated ManagedConnection.");
134         managedConnection.setAutoCommit(b);
135     }
136
137     /**
138      * Gets the connection auto-commit mode.
139      */

140     public boolean getAutoCommit() throws ResourceException JavaDoc {
141         if (managedConnection == null)
142             throw new ResourceException JavaDoc("FOS: no associated ManagedConnection.");
143         return managedConnection.getAutoCommit();
144     }
145
146     // IMPLEMENTATION OF METHODS FROM THE (cci)ConnectionMetaData INTERFACE
147

148     /**
149      * Returns the name of this storage sub-system.
150      * @return The storage sub-system name.
151      */

152     public String JavaDoc getEISProductName() throws ResourceException JavaDoc {
153         return EISPRODUCTNAME;
154     }
155
156     /**
157      * This is the same version number as the adapter.
158      * @return The storage sub-system version.
159      */

160     public String JavaDoc getEISProductVersion() throws ResourceException JavaDoc {
161         return connectionFactory.getAdapterVersion();
162     }
163
164     /**
165      * No support for user name.
166      * @return The empty string.
167      */

168     public String JavaDoc getUserName() throws ResourceException JavaDoc {
169         return "";
170     }
171
172     // IMPLEMENTATION OF METHODS FROM THE FosAccess INTERFACE
173
// Delegates execution to the associated ManagedConnection.
174

175     /**
176      * Tests if the file associated to a persistent object exists. This file is
177      * specified by the directory under which it is stored under dbDir, and
178      * its name (or id) within this directory.
179      * @param dirof The directory under dbDir where the file should be located.
180      * @param id The name of the file to test (corresponding to the object
181      * identifier).
182      * @return true if the object file exists, else false.
183      */

184     public boolean exist(String JavaDoc dirof, String JavaDoc id) throws FosException {
185         if (managedConnection == null)
186             throw new FosException("JCA managed level unreachable.",
187                 new ResourceException JavaDoc("FOS: no associated ManagedConnection."));
188         return managedConnection.exist(dirof, id);
189     }
190
191     /**
192      * Tests if a directory that stores persistent objects exists.
193      * @param dirof The directory under dbDir to test the existence.
194      * @return true if the directory exists, else false.
195      */

196     public boolean existDir(String JavaDoc dirof) throws FosException {
197         if (managedConnection == null)
198             throw new FosException("JCA managed level unreachable.",
199                 new ResourceException JavaDoc("FOS: no associated ManagedConnection."));
200         return managedConnection.existDir(dirof);
201     }
202
203     /**
204      * Reads the content of a persistent object from a file. This file is
205      * specified by the directory under which it is stored under dbDir, and
206      * its name (or id) within this directory. The object that actually reads
207      * the file is also given by the user.
208      * @param dirof The directory under dbDir where the read file is located.
209      * @param id The name of the file to read (corresponding to the object
210      * identifier).
211      * @param fs The user object for actually reading the file.
212      */

213     public void read(String JavaDoc dirof, String JavaDoc id, FosStructure fs, Object JavaDoc ctxt)
214         throws FosException {
215         if (managedConnection == null)
216             throw new FosException("JCA managed level unreachable.",
217                 new ResourceException JavaDoc("FOS: no associated ManagedConnection."));
218         managedConnection.read(dirof, id, fs, this, ctxt);
219     }
220
221     /**
222      * Deletes the file associated with a persistent object. This file is
223      * specified by the directory under which it is stored under dbDir, and
224      * its name (or id) within this directory.
225      * @param dirof The directory under dbDir where the deleted file is
226      * located.
227      * @param id The name of the file to delete (corresponding to the object
228      * identifier).
229      */

230     public void delete(String JavaDoc dirof, String JavaDoc id) throws FosException {
231         if (managedConnection == null)
232             throw new FosException("JCA managed level unreachable.",
233                 new ResourceException JavaDoc("FOS: no associated ManagedConnection."));
234         managedConnection.delete(dirof, id);
235     }
236
237     /**
238      * Deletes a directory that stores persistent objects along with all object
239      * files stored under it.
240      * @param dirof The directory under dbDir to be deleted.
241      */

242     public void deleteDir(String JavaDoc dirof) throws FosException {
243         if (managedConnection == null)
244             throw new FosException("JCA managed level unreachable.",
245                 new ResourceException JavaDoc("FOS: no associated ManagedConnection."));
246         managedConnection.deleteDir(dirof);
247     }
248
249     /**
250      * Gets an iterator in order to iterate over the names of the data
251      * object files stored into that sub-directory.
252      * @param dirof The sub-directory from which to scan the data
253      * object file names.
254      * @return The iterator in order to iterate over these names.
255      */

256     public Iterator JavaDoc scan(String JavaDoc dirof) throws FosException {
257         if (managedConnection == null)
258             throw new FosException("JCA managed level unreachable.",
259                 new ResourceException JavaDoc("FOS: no associated ManagedConnection."));
260         return managedConnection.scan(dirof);
261     }
262
263     /**
264      * Writes the content of a persistent object to a file. This file is
265      * specified by the directory under which it is stored under dbDir, and
266      * its name (or id) within this directory. The object that actually writes
267      * the file is also given by the user.
268      * @param dirof The directory under dbDir where the written file is
269      * located.
270      * @param id The name of the file to write (corresponding to the object
271      * identifier).
272      * @param fs The user object for actually writing the file.
273      */

274     public void write(String JavaDoc dirof, String JavaDoc id, FosStructure fs, Object JavaDoc ctxt)
275         throws FosException {
276         if (managedConnection == null)
277             throw new FosException("JCA managed level unreachable.",
278                 new ResourceException JavaDoc("FOS: no associated ManagedConnection."));
279         managedConnection.write(dirof, id, fs, this, ctxt);
280     }
281 }
Popular Tags