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