⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 enqueueprdhelper.java

📁 ORACLE AQ sample 演示的如何出列
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
   * @param dbUserDetails Contains the database user to which the
   *     manufacturer should connect
   * @exception JMSException Unable to get the topic for the specified queue
   * @exception Exception Incase of some error or unreported Exception.
   * @return Topic for the queue table in the database user specified
   */
  public static Topic getProductsTopic(Session p_jmsSession,
                    Hashtable p_dbUserDetails) throws JMSException,Exception{
    try{
      // Topic maps to multi consumer queue in AQ.
     // Gets the topic for the queue using the Session object.
     // The syntax of this method is
     // getTopic(String userName, String queueName)
     Topic productsTopic =
        ((AQjmsSession)p_jmsSession).getTopic(
                (String)p_dbUserDetails.get("UserName"), "adminproductqueue");

     return productsTopic;
    }catch(JMSException p_JmsExp){
      p_JmsExp.printStackTrace();
      throw new Exception("AQ-1014");
    }
  }

   /**
    * This method is called when only one product has to
    * enqueued. It then converts the single product sent
    * to product array and sends in turn to its overloaded
    * method.
    *
    * @exception JMSException This is the exception raised when the queue is
    *     disabled for enqueuing or when there are no receipts for the message
    * @exception SQLException Incase of some error or unreported
    *     Exception.
    * @exception Exception Incase of some error or unreported Exception.
    * @param jmsSession Session object in which messages are published.
    * @param topic Topic to the queue thru which messages are published.
    * @param p_addedProductInfo Details of the product to be added to
    *     queue
    * @param p_user Type of the user
    * @param p_action It tells if the product is being added or updated
    *      or deleted
    * @see ProductDat.java
    */
   private static void publishManufacturerPrd(Session p_jmsSession,
        Topic p_topic,Product p_addedProductInfo, String p_user,String p_action)
                        throws JMSException,SQLException,Exception{
      // The Product details sent is changed into array of Product details and
      // the corresponding overloaded method is called.
      publishManufacturerPrd(p_jmsSession, p_topic,
                          new Product[]{p_addedProductInfo}, p_user, p_action);
   }

   /**
    * This method is called after the multiple products selected for deletion
    * are deleted. First a publisher to the topic sent is created.Then the
    * ADTMessage is created. This ADTMessagemaps the oracle object type
    * with the Java Object ProductDat created using JPublisher. The Java object
    * is filled using the setter methods present in the
    * object and is then assigned to the payload of the ADTMessage and published.
    *
    *
    * @exception JMSException This is the exception raised when the queue is
    *     disabled for enqueuing or when there are no receipts for the message
    * @exception SQLException Incase of some error or unreported
    *     Exception.
    * @exception Exception Incase of some error or unreported Exception.
    * @param jmsSession Session object in which messages are published.
    * @param topic Topic to the queue through which messages are published.
    * @param p_changedPrdArr Details of all the products to be added to
    *      queue
    * @param p_user Type of the user
    * @param p_action It tells if the product is being added or updated
    *      or deleted
    * @see ProductDat.java
    */
   private static void publishManufacturerPrd(Session p_jmsSession,
          Topic p_topic,Product[] p_changedPrdArr, String p_user,String p_action)
                        throws JMSException,SQLException,Exception{
      try{
        // Publisher is created to publish the messages for a particular topic.
        // The syntax of this method is
        // createPublisher(Topic topicName)
        // where topicName tells the name of the topic for which messages are
        // published.
        TopicPublisher publisher =
                          ((TopicSession)p_jmsSession).createPublisher(p_topic);

        // An AdtMessage is a message whose body contains an Oracle ADT type
        // object. It is used to send a message that contains a Java object
        // that maps to an Oracle Object type. Queue table
        // with payload type as the Oracle Object Type can be filled using this.
        // The AdtMessage payload can be read and written using
        // the getAdtPayload and setAdtPayload methods.
        // Along with the payload an ADTMessage can contain additional header
        // fields called properties and a header. These properties can then be
        // used in message selectors to select specific messages.
        AdtMessage adtMsg = ((AQjmsSession)p_jmsSession).createAdtMessage() ;

        // It is the Java class corresponding to the Oracle object type.
        // It helps to store or get values in a Oracle object using it
        // setter and getter methods.
        ProductDat prdMsg = new ProductDat() ;

        // Number of products to be changed.
        int noOfPrds=p_changedPrdArr.length;
        for(int i=0;i<noOfPrds;i++){
         // Set the values of the object type(ProductDat.java) using the getter
         // methods in Product.java
         prdMsg.setProductId(p_changedPrdArr[i].getProductID());
         prdMsg.setManufacturerId(p_changedPrdArr[i].getManufactureID());
         prdMsg.setProductName(p_changedPrdArr[i].getProductName());
         prdMsg.setProductDesc(p_changedPrdArr[i].getProductDesc());

         // Fields of type NUMBER in Oracle are mapped to BigDecimal. So convert
         // the variable into Big decimal and then send it to the Java object.
         java.math.BigDecimal id = new java.math.BigDecimal(
                                        p_changedPrdArr[i].getProductPrice()) ;
         prdMsg.setPrice(id);
         prdMsg.setCategoryDesc(p_changedPrdArr[i].getCategoryDesc());
         java.math.BigDecimal quan = new java.math.BigDecimal(
                                      p_changedPrdArr[i].getQuantityOnHand()) ;
         prdMsg.setQuantityOnHand(quan);
         prdMsg.setUserName(p_user);
         prdMsg.setAction(p_action);

         // Clears a message's properties. The message header fields and body
         // are not cleared.Property values are set prior to sending a message.
         // When a client receives a message, its properties are in read-only
         // mode. If a client attempts to set properties at this point, an
         // Exception is thrown. If clearProperties is called, the properties
         // can now be both read from and written to.
         adtMsg.clearProperties() ;

         // Assigns the Java object to the ADT Message.
         // The syntax of this method is
         // setAdtPayload(ORAData payload)
         // where payload object must implement ORAData.It must be a Java object
         // that represents the ADT that is defined as the
         // queue /topic payload type
         adtMsg.setAdtPayload(prdMsg);

         // Set the priority of the ADT message. The permitted values for
         // priority are 0, 1, 2, 3...9, 9 being the highest priority.
         adtMsg.setJMSPriority(1+(i%3)) ;

         // The publisher created publishes the message. All the subscribers
         // who have subscribed to this topic will receive the message.
         // The syntax of this method is
         // publish(Topic topicName, Message messName,int deliveryMode,
         //         int priority, long timeToLive)
         // where topicName gives the name of the topic to which the publisher
         // is publishing the message
         // messName gives the name of the message
         // deliveryMode can be either PERSISTENT or NON_PERSISTENT.
         // Oracle AQ support persistent message delivery.
         // priority tells the priority of the message in integer and
         // timeToLive helps to calculate the expiration period of the message.
         // When a message is sent, its expiration time is calculated as the
         // sum of the time-to-live value specified on the send method and the
         // current GMT. If the time-to-live is specified as zero, expiration
         // is set to zero, which is to say, the message does not expire.
         publisher.publish(p_topic,adtMsg, DeliveryMode.PERSISTENT,
              1+(i%3),AQjmsConstants.EXPIRATION_NEVER);
        }

        // Commit the JMS session.
        p_jmsSession.commit() ;

        Thread.sleep(500);
     }catch(JMSException p_jmsExp){
       p_jmsExp.printStackTrace();
       throw new Exception("AQ-1015");
     }catch(Exception p_exp) {
       p_exp.printStackTrace();
       throw new Exception("AQ-1016");
     }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -