1 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 ; 33 import javax.resource.ResourceException ; 34 import javax.resource.cci.Connection ; 35 import javax.resource.cci.ConnectionMetaData ; 36 import javax.resource.cci.Interaction ; 37 import javax.resource.cci.LocalTransaction ; 38 import javax.resource.cci.ResultSetInfo ; 39 40 43 45 public class FosConnectionImpl 46 implements FosConnection, ConnectionMetaData { 47 50 private Logger logger; 51 54 private final static String EISPRODUCTNAME = "File Object Store (FOS)"; 55 59 private FosConnectionFactory connectionFactory; 60 63 private FosManagedConnection managedConnection = null; 64 65 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 82 void initialize(FosManagedConnection mc) { 83 managedConnection = mc; 84 } 85 86 88 91 public Interaction createInteraction() throws ResourceException { 92 throw new ResourceException ("FOS: no support for Interaction."); 93 } 94 95 public LocalTransaction getLocalTransaction() throws ResourceException { 96 if (managedConnection == null) 97 throw new ResourceException ("FOS: cannot get a LocalTransaction with no associated ManagedConnection."); 98 return managedConnection; 99 } 100 101 104 public ConnectionMetaData getMetaData() throws ResourceException { 105 return this; 106 } 107 108 111 public ResultSetInfo getResultSetInfo() throws ResourceException { 112 throw new ResourceException ("FOS: no support for ResultSet."); 113 } 114 115 119 public void close() throws ResourceException { 120 if (managedConnection == null) 121 throw new ResourceException ("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 131 public void setAutoCommit(boolean b) throws ResourceException { 132 if (managedConnection == null) 133 throw new ResourceException ("FOS: no associated ManagedConnection."); 134 managedConnection.setAutoCommit(b); 135 } 136 137 140 public boolean getAutoCommit() throws ResourceException { 141 if (managedConnection == null) 142 throw new ResourceException ("FOS: no associated ManagedConnection."); 143 return managedConnection.getAutoCommit(); 144 } 145 146 148 152 public String getEISProductName() throws ResourceException { 153 return EISPRODUCTNAME; 154 } 155 156 160 public String getEISProductVersion() throws ResourceException { 161 return connectionFactory.getAdapterVersion(); 162 } 163 164 168 public String getUserName() throws ResourceException { 169 return ""; 170 } 171 172 175 184 public boolean exist(String dirof, String id) throws FosException { 185 if (managedConnection == null) 186 throw new FosException("JCA managed level unreachable.", 187 new ResourceException ("FOS: no associated ManagedConnection.")); 188 return managedConnection.exist(dirof, id); 189 } 190 191 196 public boolean existDir(String dirof) throws FosException { 197 if (managedConnection == null) 198 throw new FosException("JCA managed level unreachable.", 199 new ResourceException ("FOS: no associated ManagedConnection.")); 200 return managedConnection.existDir(dirof); 201 } 202 203 213 public void read(String dirof, String id, FosStructure fs, Object ctxt) 214 throws FosException { 215 if (managedConnection == null) 216 throw new FosException("JCA managed level unreachable.", 217 new ResourceException ("FOS: no associated ManagedConnection.")); 218 managedConnection.read(dirof, id, fs, this, ctxt); 219 } 220 221 230 public void delete(String dirof, String id) throws FosException { 231 if (managedConnection == null) 232 throw new FosException("JCA managed level unreachable.", 233 new ResourceException ("FOS: no associated ManagedConnection.")); 234 managedConnection.delete(dirof, id); 235 } 236 237 242 public void deleteDir(String dirof) throws FosException { 243 if (managedConnection == null) 244 throw new FosException("JCA managed level unreachable.", 245 new ResourceException ("FOS: no associated ManagedConnection.")); 246 managedConnection.deleteDir(dirof); 247 } 248 249 256 public Iterator scan(String dirof) throws FosException { 257 if (managedConnection == null) 258 throw new FosException("JCA managed level unreachable.", 259 new ResourceException ("FOS: no associated ManagedConnection.")); 260 return managedConnection.scan(dirof); 261 } 262 263 274 public void write(String dirof, String id, FosStructure fs, Object ctxt) 275 throws FosException { 276 if (managedConnection == null) 277 throw new FosException("JCA managed level unreachable.", 278 new ResourceException ("FOS: no associated ManagedConnection.")); 279 managedConnection.write(dirof, id, fs, this, ctxt); 280 } 281 } | Popular Tags |