Coverage Report - org.mule.module.jca.DefaultConnectionManager
 
Classes in this File Line Coverage Branch Coverage Complexity
DefaultConnectionManager
0%
0/32
N/A
1.5
 
 1  
 /*
 2  
  * $Id: DefaultConnectionManager.java 19191 2010-08-25 21:05:23Z tcarlson $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
 5  
  *
 6  
  * The software in this package is published under the terms of the CPAL v1.0
 7  
  * license, a copy of which has been included with this distribution in the
 8  
  * LICENSE.txt file.
 9  
  */
 10  
 
 11  
 package org.mule.module.jca;
 12  
 
 13  
 import java.io.IOException;
 14  
 import java.io.ObjectInputStream;
 15  
 
 16  
 import javax.resource.ResourceException;
 17  
 import javax.resource.spi.ConnectionEvent;
 18  
 import javax.resource.spi.ConnectionEventListener;
 19  
 import javax.resource.spi.ConnectionManager;
 20  
 import javax.resource.spi.ConnectionRequestInfo;
 21  
 import javax.resource.spi.ManagedConnection;
 22  
 import javax.resource.spi.ManagedConnectionFactory;
 23  
 import javax.security.auth.Subject;
 24  
 
 25  
 import org.apache.commons.logging.Log;
 26  
 import org.apache.commons.logging.LogFactory;
 27  
 
 28  
 /**
 29  
  * <code>DefaultConnectionManager</code> TODO
 30  
  */
 31  
 public class DefaultConnectionManager implements ConnectionManager, ConnectionEventListener
 32  
 {
 33  
     /**
 34  
      * Serial version
 35  
      */
 36  
     private static final long serialVersionUID = 1967602190602154760L;
 37  
 
 38  0
     private transient Log logger = LogFactory.getLog(this.getClass());
 39  
 
 40  
     public DefaultConnectionManager()
 41  
     {
 42  0
         super();
 43  0
     }
 44  
 
 45  
     private void readObject(ObjectInputStream ois) throws ClassNotFoundException, IOException
 46  
     {
 47  0
         ois.defaultReadObject();
 48  0
         this.logger = LogFactory.getLog(this.getClass());
 49  0
     }
 50  
 
 51  
     /**
 52  
      * @see javax.resource.spi.ConnectionManager#allocateConnection(javax.resource.spi.ManagedConnectionFactory,
 53  
      *      javax.resource.spi.ConnectionRequestInfo)
 54  
      */
 55  
     public Object allocateConnection(ManagedConnectionFactory connectionFactory, ConnectionRequestInfo info)
 56  
         throws ResourceException
 57  
     {
 58  0
         Subject subject = null;
 59  0
         ManagedConnection connection = connectionFactory.createManagedConnection(subject, info);
 60  0
         connection.addConnectionEventListener(this);
 61  0
         return connection.getConnection(subject, info);
 62  
     }
 63  
 
 64  
     /**
 65  
      * @see javax.resource.spi.ConnectionEventListener#connectionClosed(javax.resource.spi.ConnectionEvent)
 66  
      */
 67  
     public void connectionClosed(ConnectionEvent event)
 68  
     {
 69  
         try
 70  
         {
 71  0
             ((ManagedConnection)event.getSource()).cleanup();
 72  
         }
 73  0
         catch (ResourceException e)
 74  
         {
 75  0
             logger.warn("Error occured during the cleanup of a managed connection: ", e);
 76  0
         }
 77  
         try
 78  
         {
 79  0
             ((ManagedConnection)event.getSource()).destroy();
 80  
         }
 81  0
         catch (ResourceException e)
 82  
         {
 83  0
             logger.warn("Error occured during the destruction of a managed connection: ", e);
 84  0
         }
 85  0
     }
 86  
 
 87  
     /**
 88  
      * @see javax.resource.spi.ConnectionEventListener#localTransactionStarted(javax.resource.spi.ConnectionEvent)
 89  
      */
 90  
     public void localTransactionStarted(ConnectionEvent event)
 91  
     {
 92  
         // TODO maybe later?
 93  0
     }
 94  
 
 95  
     /**
 96  
      * @see javax.resource.spi.ConnectionEventListener#localTransactionCommitted(javax.resource.spi.ConnectionEvent)
 97  
      */
 98  
     public void localTransactionCommitted(ConnectionEvent event)
 99  
     {
 100  
         // TODO maybe later?
 101  0
     }
 102  
 
 103  
     /**
 104  
      * @see javax.resource.spi.ConnectionEventListener#localTransactionRolledback(javax.resource.spi.ConnectionEvent)
 105  
      */
 106  
     public void localTransactionRolledback(ConnectionEvent event)
 107  
     {
 108  
         // TODO maybe later?
 109  0
     }
 110  
 
 111  
     /**
 112  
      * @see javax.resource.spi.ConnectionEventListener#connectionErrorOccurred(javax.resource.spi.ConnectionEvent)
 113  
      */
 114  
     public void connectionErrorOccurred(ConnectionEvent event)
 115  
     {
 116  0
         logger.warn("Managed connection experiened an error: ", event.getException());
 117  
         try
 118  
         {
 119  0
             ((ManagedConnection)event.getSource()).cleanup();
 120  
         }
 121  0
         catch (ResourceException e)
 122  
         {
 123  0
             logger.warn("Error occured during the cleanup of a managed connection: ", e);
 124  0
         }
 125  
         try
 126  
         {
 127  0
             ((ManagedConnection)event.getSource()).destroy();
 128  
         }
 129  0
         catch (ResourceException e)
 130  
         {
 131  0
             logger.warn("Error occured during the destruction of a managed connection: ", e);
 132  0
         }
 133  0
     }
 134  
 
 135  
 }