1 23 24 package org.objectweb.jorm.lib; 25 26 import org.objectweb.jorm.api.PException; 27 import org.objectweb.jorm.api.PExceptionProtocol; 28 import org.objectweb.jorm.api.JormConfigurator; 29 30 import javax.resource.cci.ConnectionFactory ; 31 import javax.resource.cci.Connection ; 32 import javax.resource.cci.ConnectionSpec ; 33 import javax.resource.ResourceException ; 34 35 39 public class MapperJCA extends Mapper { 40 private ConnectionFactory connectionFactory; 41 42 public MapperJCA() throws PException { 43 super(); 44 } 45 46 public MapperJCA(JormConfigurator jc) { 47 super(jc); 48 } 49 50 55 public void closeConnection(Object conn) throws PException { 56 try { 57 ((Connection ) conn).close(); 58 } catch (ResourceException re) { 59 throw new PException(re, "Problem while closing connection."); 60 } 61 } 62 63 66 public Object getConnection() throws PException { 67 try { 68 return connectionFactory.getConnection(); 69 } catch (ResourceException re) { 70 throw new PException(re, "Problem while allocating connection."); 71 } 72 } 73 74 79 public Object getConnection(Object ctxt) throws PException { 80 try { 81 return connectionFactory.getConnection((ConnectionSpec ) ctxt); 82 } catch (ResourceException re) { 83 throw new PException(re, "Problem while allocating connection with SPEC."); 84 } 85 } 86 87 public Object getConnection(Object connectionContext, Object user) throws PException { 88 try { 89 return connectionFactory.getConnection((ConnectionSpec ) connectionContext); 90 } catch (ResourceException re) { 91 throw new PException(re, "Problem while allocating connection with SPEC."); 92 } 93 } 94 95 100 public void setConnectionFactory(Object cf) throws PException { 101 if (!(cf instanceof ConnectionFactory )) 102 throw new PException("Requires a JCA connection factory."); 103 if (connectionFactory != null) 104 throw new PExceptionProtocol("Connection factory assigned once."); 105 connectionFactory = (ConnectionFactory ) cf; 106 } 107 108 111 public Object getConnectionFactory() { 112 return connectionFactory; 113 } 114 } 115 | Popular Tags |