title: Object does not close\return connections into pool if work in Proxy EJB container
body: <p>I've integration solution based on weblogic application server. (Oracle Retail Integration Bus). Each adapter of solution is a EJB component.
  <a href="http://i.stack.imgur.com/DvDju.jpg" rel="nofollow">Weblogic Console Application view</a></p>
  
  <p>There are two types of Adapters, first one is for XA Transactions, and second one is for NONXA transactions. (NONXA needed when in PLSQL API function used External proc procedures).</p>
  
  <ol>
  <li><p>XA - OracleObjectSubscriberComponentImpl</p>
  
  <pre><code>        public class OracleObjectSubscriberComponentImpl
        extends DefaultAdaptorComponentImpl
        implements SubscriberComponent
      {
        ....
        protected void performSubscribe(RibContext ribContext, RibMessage inRibMessage, RibMessages outRibMsg)
          throws RibAPIException
        {
          boolean success = false;
  
          Connection connection = null;
          try
          {
            setRibContext(ribContext);
            setRibMessagesOut(outRibMsg);
            connection = getNewConnection();
            initCallableStatement(connection, null);
            registerOutParams();
            if (setInParams(inRibMessage))
            {
              execute();
              processResult();
              success = true;
            }
          }
          finally
          {
            end(success);
            cleanup();
  
            super.closeConnection(connection);
          }
        }
  
        public void performSubscribe(RibContext ribContext, RibMessage inRibMessage)
          throws RibAPIException
        {
          performSubscribe(ribContext, inRibMessage, null);
        }
  
        public void subscribe(RibContext ribContext, RibMessage inRibMessage)
          throws RibAPIException
        {
          performSubscribe(ribContext, inRibMessage);
        }
        ...
      }
  </code></pre></li>
  <li><p>NonXA - OracleObjectSubscriberComponentNonXAImpl extends OracleObjectSubscriberComponentImpl.</p>
  
  <pre><code>public class OracleObjectSubscriberComponentNonXAImpl
        extends OracleObjectSubscriberComponentImpl
      {
        public void initCallableStatement(Connection c, String msgType)
          throws RibAPIException
        {
          try
          {
            c.setAutoCommit(false);
          }
          catch (SQLException e)
          {
            this.LOG.error("Could not turn off AutoCommit", e);
            throw createRibAPIException("initStmt", e);
          }
          super.initCallableStatement(c, msgType);
        }
  
        public void end(boolean successful)
        {
          super.end(successful);
          try
          {
            if (successful) {
              this.conn.commit();
            } else {
              this.conn.rollback();
            }
            this.conn.setAutoCommit(true);
          }
                  catch (SQLException sqle)
          {
            String errorString = "Error occurred during commit/rollback";
            this.LOG.error(errorString, sqle);
            throw new RuntimeException(errorString, sqle);
          }
        }
  
        public void subscribe(RibContext ribContext, RibMessage inRibMessage)
          throws RibAPIException
        {
          NonTransactionalSubscriberCoreService nonTransactionalSubscriberCoreService =         (NonTransactionalSubscriberCoreService)RetailServiceFactory.getService(NonTransactionalSubscriberCoreService.class);
  
         nonTransactionalSubscriberCoreService.subscribe(this, ribContext, inRibMessage);
        }
      }
  </code></pre></li>
  </ol>
  
  <p>Differences between them is:</p>
  
  <ol>
  <li>NonXA Autocommit = false, and this.conn.commit(); and this.conn.rollback(); used instead of XA Autocommit = true.</li>
  <li>NonXA got overrided method subscribe, where new Proxy service created, and NonXA object goes into Proxy, where it will execute Perform Subscribe.</li>
  </ol>
  
  <p>Non XA class uses NonTransactionalSubscriberCoreServiceEjb class, this is a Proxy service:</p>
  
  <pre><code>    public class NonTransactionalSubscriberCoreServiceEjb
        implements NonTransactionalSubscriberCoreService, SessionBean
      {
        ...
      public void subscribe(OracleObjectSubscriberComponentNonXAImpl subscriber, RibContext ribContext, RibMessage inRibMessage)
          throws RibAPIException
        {
          RibContextFactory.setCurrentRibContext(ribContext);
          subscriber.performSubscribe(ribContext, inRibMessage);
          RibContextFactory.clearCurrentRibContext();
        }
        ...
      }
  </code></pre>
  
  <p>All Adapters does not parrallel, each adapter get messages one by one, from JMS Topic. XA component works fine, it get connection in weblogic datasource and return it back when work finished. NonXA does not working as expected, it take connection from datasourse and do not release it, connection hold up until timeout came.</p>
  
  <p>If i change NonXA class, subscribe method to this:</p>
  
  <pre><code>      public void subscribe(RibContext ribContext, RibMessage inRibMessage)
          throws RibAPIException
        {
            this.performSubscribe(ribContext, inRibMessage);
        }
  </code></pre>
  
  <p>Connections will be released after work finished, but i can't use External Proc in API, because ORA-xxx (this feature is not supported in XA) raised. I need keep NonXA functionality and release connections.</p>