connectionhelper.java

来自「ORACLE AQ sample 演示的如何出列」· Java 代码 · 共 341 行

JAVA
341
字号
package oracle.otnsamples.AQ.Helper;
/**
 * @author  Anupama
 * @version 1.0

 * Development Environment        :  Oracle9i JDeveloper
 * Name of the Application        :  ConnectionHelper.java
 * Creation/Modification History  :
 *
 *    Anupama      30-Jan-2002      Created
 *
 */

import java.util.Hashtable;

/**
 * This class helps to retrieve the details of the database to
 * which the user is connected. All the details of database
 * to which the Computer manufacturer, Printer and the
 * user are connected are stored here.
 */
public class ConnectionHelper {

  /**
   * Host name of the database the Computer Manufacturer is using.
   */
  private static String m_hostName = "incq109b.idc.oracle.com";

  /**
   * SID of the database the Computer Manufacturer is using.
   */
  private static String m_SID= "ora";

  /**
   * Port number of the database the Computer Manufacturer is using.
   */
  private static int m_port = 1521;

  /**
   * Type of the driver used by of the Computer Manufacturer.
   */
  private static String m_computerManuDriver = "thin";

  /**
   * User name of the database to which the Computer Manufacturer
   * is connected.
   */
  private static String m_computerManuUserNm = "aqcomputer";

  /**
   * Password of the database to which the Computer Manufacturer
   * is connected.
   */
  private static String m_computerManuPasswrd = "aqcomputer";

  /**
   * Type of the driver used by of the Printer Manufacturer.
   */
  private static String m_printerManuDriver = "thin";

  /**
   * User name of the database to which the Printer Manufacturer
   * is connected.
   */
  private static String m_printerManuUserNm = "aqprinter";

  /**
   * Password of the database to which the Printer Manufacturer
   * is connected.
   */
  private static String m_printerManuPasswrd = "aqprinter";

  /**
   * User name of the database to which the Retail
   * is connected.
   */
  private static String m_retailUserNm = "aqcustomer";

  /**
   * Password of the database to which the Retail
   * is connected.
   */
  private static String m_retailPasswrd = "aqcustomer";


  /**
   * Empty constructor.
   */
  public ConnectionHelper(){
  }

  /**
   * This method is used to retrieve the details of database
   * to which the Retail is connected.It returns the values present in
   * the private variable. This method calls its overloaded method to
   * gets its work done by passing the string retail to it.
   *
   * @exception Exception Incase of some error or unreported Exception.
   * @return Contains the details of the database
   */
  public static Hashtable getDBUserDetails() throws Exception{
    return getDBUserDetails("Retail");
  }

  /**
   * This method is used to retrieve the details of database
   * to which the user is connected.It returns the value present in
   * the private variable.
   *
   * @param p_userType Type of the user
   * @exception Exception Incase of some error or unreported Exception.
   * @return Contains the details of the database
   */
  public static Hashtable getDBUserDetails(String p_userType) throws Exception{
    String hostName  = "";
    String SID       = "";
    int portNo       = 0;
    String driver    = "";
    String userName  = "";
    String password  = "";
    if(p_userType.equalsIgnoreCase("Computer")){
      hostName =  getComputerManuHostNm();
      SID      =  getComputerManuSID();
      portNo   =  getComputerManuPortNo();
      driver   =  getComputerManuDriver();
      userName =  getComputerManuUserNm();
      password =  getComputerManuPasswrd();
    }else if(p_userType.equalsIgnoreCase("Printer")){
      hostName =  getPrinterManuHostNm();
      SID      =  getPrinterManuSID();
      portNo   =  getPrinterManuPortNo();
      driver   =  getPrinterManuDriver();
      userName =  getPrinterManuUserNm();
      password =  getPrinterManuPasswrd();
    }else{
      hostName =  getRetailHostNm();
      SID      =  getRetailSID();
      portNo   =  getRetailPortNo();
      userName =  getRetailUserNm();
      password =  getRetailPasswrd();
    }
    Hashtable dbUserDetails = new Hashtable();
    dbUserDetails.put("HostName",hostName);
    dbUserDetails.put("SID",SID);
    dbUserDetails.put("PortNo",new Integer(portNo));
    dbUserDetails.put("Driver",driver);
    dbUserDetails.put("UserName",userName);
    dbUserDetails.put("Password",password);
    return dbUserDetails;
  }

  /**
   * Returns the host name of the database the Computer Manufacturer is using.
   * It returns the value present in the private variable.
   *
   * @exception Exception Incase of some error or unreported Exception.
   * @return Host name
   */
  public static String getComputerManuHostNm() throws Exception{
    return m_hostName;
  }

  /**
   * Returns the SID of the database the Computer Manufacturer is using.
   * It returns the value present in the private variable.
   *
   * @exception Exception Incase of some error or unreported Exception.
   * @return SID is returned
   */
  public static String getComputerManuSID() throws Exception{
    return m_SID;
  }

  /**
   * Returns the port number of the database the Computer Manufacturer is using.
   * It returns the value present in the private variable.
   *
   * @exception Exception Incase of some error or unreported Exception.
   * @return Port number
   */
  public static int getComputerManuPortNo() throws Exception{
    return m_port;
  }

  /**
   * Returns the type of the driver used by of the Computer Manufacturer.
   * It returns the value present in the private variable.
   *
   * @exception Exception Incase of some error or unreported Exception.
   * @return Driver type
   */
  public static String getComputerManuDriver() throws Exception{
    return m_computerManuDriver;
  }

  /**
   * Returns the user name of the database to which the Computer Manufacturer
   * is connected. It returns the value present in the private variable.
   *
   * @exception Exception Incase of some error or unreported Exception.
   * @return User name
   */
  public static String getComputerManuUserNm() throws Exception{
    return m_computerManuUserNm;
  }

  /**
   * Returns the password of the database to which the Computer Manufacturer
   * is connected set in the private variable. It returns the value present
   * in the private variable.
   *
   * @exception Exception Incase of some error or unreported Exception.
   * @return Password is returned
   */
  public static String getComputerManuPasswrd() throws Exception{
    return m_computerManuPasswrd;
  }

  /**
   * Returns the host name of the database the Printer Manufacturer is using.
   * It returns the value present in the private variable.
   *
   * @exception Exception Incase of some error or unreported Exception.
   * @return Host name is returned
   */
  public static String getPrinterManuHostNm() throws Exception{
    return m_hostName;
  }

  /**
   * Returns the SID of the database the Printer Manufacturer is using.
   * It returns the value present in the private variable.
   *
   * @exception Exception Incase of some error or unreported Exception.
   * @return SID is returned.
   */
  public static String getPrinterManuSID() throws Exception{
    return m_SID;
  }

  /**
   * Returns the port number of the database the Printer Manufacturer is using.
   * It returns the value present in the private variable.
   *
   * @exception Exception Incase of some error or unreported Exception.
   * @return Post number is returned.
   */
  public static int getPrinterManuPortNo() throws Exception{
    return m_port;
  }

  /**
   * Returns the type of the driver used by of the Printer Manufacturer.
   * It returns the value present in the private variable.
   *
   * @exception Exception Incase of some error or unreported Exception.
   * @return Driver type is returned
   */
  public static String getPrinterManuDriver() throws Exception{
    return m_printerManuDriver;
  }

  /**
   * Retuns the user name of the database to which the Printer Manufacturer
   * is connected.It returns the value present in the private variable.
   *
   * @exception Exception Incase of some error or unreported Exception.
   * @return User name is returned
   */
  public static String getPrinterManuUserNm() throws Exception{
    return m_printerManuUserNm;
  }

  /**
   * Returns the password of the database to which the Printer Manufacturer
   * is connected.It returns the value present in the private variable.
   *
   * @exception Exception Incase of some error or unreported Exception.
   * @return Password is returned.
   */
  public static String getPrinterManuPasswrd() throws Exception{
    return m_printerManuPasswrd;
  }

  /**
   * Returns the host name of the database the Retail is using.
   * It returns the value present in the private variable.
   *
   * @exception Exception Incase of some error or unreported Exception.
   * @return Host name is returned
   */
  public static String getRetailHostNm() throws Exception{
    return m_hostName;
  }

  /**
   * Returns the SID of the database the Retail is using.
   * It returns the value present in the private variable.
   *
   * @exception Exception Incase of some error or unreported Exception.
   * @return SID is returned.
   */
  public static String getRetailSID() throws Exception{
    return m_SID;
  }

  /**
   * Returns the port number of the database the Retail is using.
   * It returns the value present in the private variable.
   *
   * @exception Exception Incase of some error or unreported Exception.
   * @return Post number is returned.
   */
  public static int getRetailPortNo() throws Exception{
    return m_port;
  }

  /**
   * Retuns the user name of the database to which the Retail
   * is connected.It returns the value present in the private variable.
   *
   * @exception Exception Incase of some error or unreported Exception.
   * @return User name is returned
   */
  public static String getRetailUserNm() throws Exception{
    return m_retailUserNm;
  }

  /**
   * Returns the password of the database to which the Retail
   * is connected.It returns the value present in the private variable.
   *
   * @exception Exception Incase of some error or unreported Exception.
   * @return Password is returned.
   */
  public static String getRetailPasswrd() throws Exception{
    return m_retailPasswrd;
  }

}

⌨️ 快捷键说明

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