Example #1
0
  public Connection getConnection() throws Exception {
    Transaction tx = TransactionCoordination.getInstance().getTransaction();
    if (tx != null) {
      if (tx.hasResource(dataSource)) {
        logger.debug("Retrieving connection from current transaction: " + tx);
        return (Connection) tx.getResource(dataSource);
      }
    }
    logger.debug("Retrieving new connection from data source");

    Connection con;
    try {
      con = dataSource.getConnection();
    } catch (Exception e) {
      throw new ConnectException(e, this);
    }

    if (tx != null) {
      logger.debug("Binding connection " + con + " to current transaction: " + tx);
      try {
        tx.bindResource(dataSource, con);
      } catch (TransactionException e) {
        JdbcUtils.close(con);
        throw new RuntimeException("Could not bind connection to current transaction: " + tx, e);
      }
    }
    return con;
  }
Example #2
0
 public List getMessages() throws Exception {
   Connection con = null;
   try {
     con = this.connector.getConnection();
     Object[] readParams = JdbcUtils.getParams(getEndpointURI(), this.readParams, null);
     Object results =
         new QueryRunner().query(con, this.readStmt, readParams, new MapListHandler());
     return (List) results;
   } finally {
     JdbcUtils.close(con);
   }
 }
Example #3
0
 public void processMessage(Object message) throws Exception {
   Connection con = null;
   UMOTransaction tx = TransactionCoordination.getInstance().getTransaction();
   try {
     con = this.connector.getConnection();
     if (this.ackStmt != null) {
       Object[] ackParams = JdbcUtils.getParams(getEndpointURI(), this.ackParams, message);
       int nbRows = new QueryRunner().update(con, this.ackStmt, ackParams);
       if (nbRows != 1) {
         logger.warn("Row count for ack should be 1 and not " + nbRows);
       }
     }
     UMOMessageAdapter msgAdapter = this.connector.getMessageAdapter(message);
     UMOMessage umoMessage = new MuleMessage(msgAdapter);
     routeMessage(umoMessage, tx, tx != null || endpoint.isSynchronous());
   } finally {
     if (tx == null) {
       JdbcUtils.close(con);
     }
   }
 }