All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.caucho.jms.jdbc.JdbcQueue Maven / Gradle / Ivy

/*
 * Copyright (c) 1998-2018 Caucho Technology -- all rights reserved
 *
 * This file is part of Resin(R) Open Source
 *
 * Each copy or derived work must preserve the copyright notice and this
 * notice unmodified.
 *
 * Resin Open Source is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * Resin Open Source is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
 * of NON-INFRINGEMENT.  See the GNU General Public License for more
 * details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Resin Open Source; if not, write to the
 *
 *   Free Software Foundation, Inc.
 *   59 Temple Place, Suite 330
 *   Boston, MA 02111-1307  USA
 *
 * @author Scott Ferguson
 */

package com.caucho.jms.jdbc;

import com.caucho.config.ConfigException;
import com.caucho.jms.JmsExceptionWrapper;
import com.caucho.jms.connection.MessageConsumerImpl;
import com.caucho.jms.connection.JmsSession;
import com.caucho.jms.message.MessageImpl;
import com.caucho.jms.queue.AbstractQueue;
import com.caucho.jms.queue.MessageException;
import com.caucho.jms.queue.PollingQueue;
import com.caucho.util.CurrentTime;
import com.caucho.util.L10N;
import com.caucho.util.Alarm;
import com.caucho.jdbc.*;

import javax.annotation.PostConstruct;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Queue;
import javax.jms.QueueBrowser;
import java.sql.*;
import java.io.*;
import javax.sql.*;
import java.util.logging.*;

/**
 * A jdbc queue.
 */
public class JdbcQueue extends PollingQueue {
  static final Logger log = Logger.getLogger(JdbcQueue.class.getName());
  static final L10N L = new L10N(JdbcQueue.class);
  
  protected JdbcManager _jdbcManager = new JdbcManager();
  
  private String _name;

  private int _id;
  private int _consumerId;

  public JdbcQueue()
  {
  }

  /**
   * Sets the name.
   */
  public void setName(String name)
  {
    _name = name;
  }

  /**
   * Gets the name.
   */
  public String getName()
  {
    return _name;
  }

  /**
   * Returns the queue's name.
   */
  public String getQueueName()
  {
    return getName();
  }

  /**
   * Sets the queue's name.
   */
  public void setQueueName(String name)
  {
    setName(name);
  }

  /**
   * Returns the JDBC id for the queue.
   */
  public int getId()
  {
    return _id;
  }

  /**
   * Sets the jdbc manager
   */
  public void setJdbcManager(JdbcManager jdbcManager)
  {
    _jdbcManager = jdbcManager;
  }

  /**
   * Gets the JDBC manager.
   */
  public JdbcManager getJdbcManager()
  {
    return _jdbcManager;
  }
  
  /**
   * Sets the data source.
   */
  public void setDataSource(DataSource dataSource)
  {
    _jdbcManager.setDataSource(dataSource);
  }

  /**
   * Sets the tablespace for Oracle.
   */
  public void setTablespace(String tablespace)
  {
    _jdbcManager.setTablespace(tablespace);
  }

  /**
   * Initializes the JdbcQueue
   */
  public void init()
    throws ConfigException
  {
    try {
      if (_jdbcManager.getDataSource() == null)
        throw new ConfigException(L.l("JdbcQueue requires a  element."));
    
      if (getName() == null)
        throw new ConfigException(L.l("JdbcQueue requires a  element."));

      _jdbcManager.init();

      _id = createDestination(getName(), false);
    } catch (RuntimeException e) {
      throw e;
    } catch (Exception e) {
      throw ConfigException.create(e);
    }
  }

  /**
   * Creates a consumer.
   */
  /*
  public MessageConsumerImpl createConsumer(JmsSession session,
                                            String selector,
                                            boolean noWait)
    throws JMSException
  {
    return new JdbcQueueConsumer(session, selector, _jdbcManager, this);
  }
  */

  /**
   * Creates a browser.
   */
  /*
  public QueueBrowser createBrowser(SessionImpl session, String selector)
    throws JMSException
  {
    return new JdbcQueueBrowser(session, selector, this);
  }
  */

  /**
   * Sends the message to the queue.
   */
  @Override
  public void send(String msgId,
                   E payload,
                   int priority,
                   long expireTime,
                   String publisherId)
    throws MessageException
  {
    // JdbcMessage jdbcMessage = _jdbcManager.getJdbcMessage();
    //jdbcMessage.send(payload, _id, priority, expireTime);
  }

  /**
   * Receives a message from the queue.
   */
  /*
  @Override
  public MessageImpl receive(boolean isAutoAck)
    throws JMSException
  {
    try {
      long minId = -1;

      DataSource dataSource = _jdbcManager.getDataSource();
      String messageTable = _jdbcManager.getMessageTable();
      JdbcMessage jdbcMessage = _jdbcManager.getJdbcMessage();
    
      Connection conn = dataSource.getConnection();
      try {
        String sql = ("SELECT m_id, msg_type, msg_id, delivered, body, header" +
                      " FROM " + messageTable
                      + " WHERE ?




© 2015 - 2025 Weber Informatics LLC | Privacy Policy