| Oracle9i Lite Developer’s Guide for AQ Lite Release 5.0 Part Number A90251-01 |
|
This document describes the use and development of the Oracle AQ Lite sample application. Topics include:
To set up the AQ Lite sample application, perform the following procedures:
See the Oracle8i Lite Installation Guide for instructions on installing AQ Lite. After you install AQ Lite, the sample application is available in the ORACLE_HOME\Mobile\SDK\\AQLite\AQLSAMP directory.
|
Warning: Running the SQL script AQLiteO8.sql removes any existing AQ Lite information from the Oracle8i database. |
java setupDeplMsg [o8UserID] [o8Passwd] [o8ConnStr] e.g., java setupDeplMsgQ AQUSER AQUSER my_machine.mydomain.com:1521:orcl
| Argument | Description | Example |
|---|---|---|
|
o8UserId |
Oracle8i user ID |
"system" |
|
o8Passwd |
Oracle8i user password |
"manager" |
|
o8ConnStr |
Oracle8i connection string |
"my_machine.mydomain.com:1521:orcl" |
java setupServer [o8UserId] [o8Passwd] [o8ConnStr] e.g., java setupServer AQUSER AQUSER my_machine.my domain.com:1521:orcl
| Argument | Description | Example |
|---|---|---|
|
o8UserId |
Oracle8i user ID |
"system" |
|
o8Passwd |
Oracle8i user password |
"manager" |
|
o8ConnStr |
Oracle8i connection string |
"my_machine.mydomain.com:1521:orcl " |
java SetupClient [o8UserId] [o8Passwd] [o8ConnStr] [option] [oliteSiteName] e.g., java setup client AQUSER AQUSER my_machine.mydomain.com:1521:orcl ORD C:\ORANT\OLDB40\politeProc.odb oliteSite 1 or java setupClient AQUSER AQUSER my_machine.mydomain.com:1521:orcl PROC C:\ORANT\OLDB40\politeProc.odb oliteSite 2
If you do not have Java Foundation Class (JFC) Swing package installed, inclde the jar file swing.jar (located in the AQLiteSamp directory) to your CLASSPATH.
The AQ Lite Sample Application consists of the following modules:
The New Order and View Order modules represent two components of an order entry application residing on an AQ Lite client. Using the New Order module, you can create sales orders and send them to the data center (Oracle8i server) and for retrieval from the Process Order module. Using the View Order module you can view information in processed orders.
The Process Order module represents an order processing application residing on another AQLite client. This module retrieves new orders from the data center (Oracle8i server) and processes them.
To start the sample application, run AQLiteSample.class by typing java AQLiteSample. The main screen displays .
To open the New Order module:
|
Note:: Users must type in the correct Oracle Lite connection string for New Order (e.g., c:\ORANT\OLDB\politeORD.odb). |
To create a new order:
|
Note: Users must enter the correct Oracle8i server database connect string in the format [hostname] : [port number] : [SID] (e.g., mymachine.mydomain.com:1521:orcl). |
To open the Process Order module:
|
Note:: Users must enter the correct database connect string for Process Order (e.g., c:\ORANT\OLDB40\politePROC.odb). |
|
Note: Users must enter the correct Oracle8i server database connect string in the format [hostname] : [port number] : [SID] (e.g., mymachine.mydomain.com:1521:orcl). |
When the Process Order module starts, it dequeues any new order messages, and displays the information in the Process Order screen.
To process an order:
To open the View Order module:
|
Note:: For View Order, users must enter the same database connect string as New Order (e.g., c:\ORANT\OLDB40\politeORD.odb). |
|
Note: Users must enter the correct Oracle8i server database connect string in the format [hostname] : [port number] : [SID] (e.g., mymachine.mydomain.com:1521:orcl). |
When the View Order module is launched, AQ Lite propagates the processed order messages from the master queue (the Oracle8i server at the data center) to the client queue (Oracle Lite Database 1 at the sales/order-entry department). The View Order module dequeues the processed order messages and displays the information.
Removing an order:
Click on the order you wish to remove and then click the Remove Entry button. The order will be dequeued from the local database.
This section contains source code used to implement the AQ Lite sample application. Developers may use this code as an example in developing their own queueing applications in Oracle AQ Lite. The complete sample application source code is located in ORACLE_HOME/Mobile/SDK//AQLite/AQLSAMP directory.
/* DESCRIPTION Main class - draws AQLite Sample App's main window NOTES Other files in the sample app: AQLiteSampQUtil.java - all AQLite queue operations AQLiteSampUtil.java - miscellaneous GUI and other operations AQLiteSampNewOrder.java - handles "New Order" operations AQLiteSampProcOrder.java - handles "Process Order" operations AQLiteSampViewOrder.java - handles "View Order" operations */ import javax.swing.*; import java.awt.*; import java.awt.event.*; public class AQLiteSample implements ActionListener{ static JFrame frame = null; // Create Components public Component createComponents() { // GUI initialization final JLabel label = new JLabel("AQLite Sample Application"); // create buttons JButton button1 = new JButton("New Order"); JButton button2 = new JButton("View Order"); JButton button3 = new JButton("Process Order"); JButton button4 = new JButton("Exit"); label.setFont(AQLiteSampUtil.fontb); button1.setFont(AQLiteSampUtil.fonts); button2.setFont(AQLiteSampUtil.fonts); button3.setFont(AQLiteSampUtil.fonts); button4.setFont(AQLiteSampUtil.fonts); // set mnemonic keys for users to stimulate button click. button1.setMnemonic(KeyEvent.VK_N); //(Alt-n) button2.setMnemonic(KeyEvent.VK_V); //(Alt-v) button3.setMnemonic(KeyEvent.VK_P); //(Alt-p) button4.setMnemonic(KeyEvent.VK_E); //(Alt-e) // set unique identifier to button button1.setActionCommand(AQLiteSampUtil.bn_main_NO); button2.setActionCommand(AQLiteSampUtil.bn_main_VO); button3.setActionCommand(AQLiteSampUtil.bn_main_PO); button4.setActionCommand(AQLiteSampUtil.bn_main_EX); button1.addActionListener(this); button2.addActionListener(this); button3.addActionListener(this); button4.addActionListener(this); // set button colours //button1.setOpaque(true); //button1.setBackground(Color.blue); // put the contents in a JPanel that has an "empty" border // to put space between a top-level container and its contents JPanel pane = new JPanel(); pane.setOpaque(true); pane.setBackground(Color.white); pane.setBorder(BorderFactory.createEmptyBorder(30, //top 30 pixels 30, //left 30 pixels 30, //bottom 30) //right ); // set layout manager pane.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.gridx = 0; c.gridy = 0; c.gridwidth = 3; c.gridheight = 1; c.insets = new Insets(3,2,5,2); c.weightx = 1.0; c.weighty = 1.0; // add label to panel pane.add(label, c); c.gridy = GridBagConstraints.RELATIVE; c.fill = GridBagConstraints.HORIZONTAL; c.gridx = 2; c.anchor = GridBagConstraints.CENTER; c.gridwidth = 1; c.weightx = 0.0; c.weighty = 1.0; c.insets = new Insets(3,2,3,2); // add buttons to panel pane.add(button1, c); pane.add(button2, c); pane.add(button3, c); pane.add(button4, c); return pane; } public void actionPerformed (ActionEvent evt) { String cmd = evt.getActionCommand(); // "New Order" button click if (cmd.equals(AQLiteSampUtil.bn_main_NO)) { AQLiteSampNewOrder newOrder = new AQLiteSampNewOrder(); newOrder.start(); } // "View Order" button click else if (cmd.equals(AQLiteSampUtil.bn_main_VO)) { AQLiteSampViewOrder viewOrder = new AQLiteSampViewOrder(); viewOrder.start(); } // "Process Order" button click else if (cmd.equals(AQLiteSampUtil.bn_main_PO)) { AQLiteSampProcOrder procOrder = new AQLiteSampProcOrder(); procOrder.start(); } // "Exit" button click else if (cmd.equals(AQLiteSampUtil.bn_main_EX)) { String dialog_txt = "Do you really want to quit?"; String dialog_title = "AQlite Sample Application - Quit"; int response = JOptionPane.showConfirmDialog(frame, dialog_txt, dialog_title, JOptionPane.YES_NO_OPTION); switch (response) { case JOptionPane.YES_OPTION: System.exit(0); break; case JOptionPane.NO_OPTION: break; case JOptionPane.CLOSED_OPTION: break; } } } ///////////////////////////////////////////////// public static void main(String[] args) { try { // Set Look and Feel UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName()); } catch (Exception e) { } frame = new JFrame("AQLite Sample Application"); AQLiteSample app = new AQLiteSample(); // create the components to go into the frame // and stick them in a container named contents Component contents = app.createComponents(); frame.getContentPane().add(contents, BorderLayout.CENTER); // Window close frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) {System.exit(0);} }); // Size frame.pack(); //Finish setting up the frame, and show it. frame.setVisible(true); } }
The following code is used to prepare the message queues for deployment of the sample application.
import oracle.AQ.*; import oracle.lite.AQ.*; import java.util.*; import java.sql.*; import java.math.*; public class setupDeplMsgQ { public static final String AQLDeplMsgQT = "AQLITE$_DeplMsgQT"; public static final String AQLDeplMessages = "AQLITE$_DeplMessages"; public static void main(String[] args) { if (args.length !=3 || args[0] == null || args[1] == null || args[2] == null) { System.err.println("Usage: java setupDeplMsgQ [o8UserId] [o8Passwd] [o8ConnStr]"); System.err.println("\n\n Example:"); System.err.println("java setupDeplMsgQ AQUSER AQUSER my_machine.my_ domain.com:1521:orcl"); System.exit(0); } String orauser = args[0]; String orapswd = args[1]; String connstr = "jdbc:oracle:thin:@" + args[2]; AQSession aqConn = null; try { // JDBC Thin Driver DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver()); Connection conn = DriverManager.getConnection(connstr,orauser, orapswd); conn.setAutoCommit(false); AQOracleDriver aqD = new AQOracleDriver(); // get connection to Olite database aqConn = aqD.createAQSession((Object) conn); //prepare a queuetable property AQQueueTableProperty AQqtp = new AQQueueTableProperty("RAW"); AQqtp.setStorageClause(""); //AQqtp.setAutoCommit(false); AQqtp.setComment("AQLITE Queue for deployment messages"); AQqtp.setCompatible(""); AQqtp.setMessageGrouping(AQqtp.NONE); AQqtp.setMultiConsumer(true); AQqtp.setPrimaryInstance(1); AQqtp.setSecondaryInstance(0); AQqtp.setSortOrder("ENQ_TIME"); //createQT AQQueueTable tqt = null; try { tqt = aqConn.getQueueTable(orauser, AQLDeplMsgQT); } catch (AQException e) { //System.out.println(e); } try { if (tqt != null) tqt.drop(true); } catch (AQException e) { System.err.println("Ooops: " + e.getMessage()); e.printStackTrace(); } tqt = aqConn.createQueueTable(orauser, AQLDeplMsgQT, AQqtp); //prepare a queue property AQQueueProperty AQqp = new AQQueueProperty(); //AQqp.setAutoCommit(false); AQqp.setComment("test Queue"); //AQqp.setDepTracking(false); //AQqp.setMaxRetries(100); AQqp.setQueueType(AQqp.NORMAL_QUEUE); AQqp.setRetentionTime(0.0) ; //AQqp.setRetryInterval(0.0); // create Q on the QT AQQueue q = aqConn.createQueue(tqt, AQLDeplMessages, AQqp); q.start(); // commit changes conn.commit(); } catch (AQException e) { System.err.println("Ooops: " + e.getMessage()); e.printStackTrace(); } catch (SQLException e) { System.err.println("Ooops: " + e.getMessage()); e.printStackTrace(); } } }
The following code is used to prepare the Oracle Lite server device for deployment of the sample application.
import java.util.*; import java.sql.*; //import java.math.*; import oracle.AQ.*; import oracle.lite.AQ.*; public class setupServer{ public static void main(String[] args) { if (args.length !=3 || args[0] == null || args[1] == null || args[2] == null) { System.err.println("Usage: java setupServer [o8UserId] [o8Passwd] [o8ConnStr]"); System.err.println("\n\n Example:"); System.err.println("java setupServer AQUSER AQUSER my_machine.my_ domain.com:1521:orcl"); System.exit(0); } String o8UserID = args[0]; String o8Passwd = args[1]; String o8ConnStr = "jdbc:oracle:thin:@" + args[2]; AQSession aqConn; try { // connect to O8 via JDBC DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver()); Connection conn = DriverManager.getConnection(o8ConnStr,o8UserID,o8Passwd); conn.setAutoCommit(false); // do not change the following if you are not sure String[] qn = new String[1]; qn[0] = "AQLite_SampOrderQ"; String[] qo = new String[1]; qo[0] = o8UserID; String qt = "AQLite_SampOrderQT"; //create Queue Table and Queue AQOracleDriver aqD = new AQOracleDriver(); aqConn = aqD.createAQSession((Object) conn); //prepare a queuetable property AQQueueTableProperty AQqtp = new AQQueueTableProperty("RAW"); AQqtp.setStorageClause(""); //AQqtp.setAutoCommit(false); AQqtp.setComment("AQLite Sample Application"); AQqtp.setCompatible(""); AQqtp.setMessageGrouping(AQqtp.NONE); AQqtp.setMultiConsumer(true); AQqtp.setPrimaryInstance(1); AQqtp.setSecondaryInstance(0); AQqtp.setSortOrder("ENQ_TIME"); //createQT AQQueueTable tqt = null; try { tqt = aqConn.getQueueTable(qo[0], qt); } catch (AQException e) { System.err.println("Oooops. " + e.getMessage()); e.printStackTrace(); } try { if (tqt != null) { //cleaning AQLiteDeploymentAdmin admin = new AQLiteDeploymentAdmin(conn); AQLiteDeploymentOliteSite os =admin.getOliteSite("OliteSite1", "sampUser"); //os.deInstantiate("AQLSampQG1"); try {//test here AQLiteDeploymentQueueGroup qg = os.getQueueGroup("AQLSampQG1"); qg.drop(); } catch (AQException e){} tqt.drop(true); } } catch (AQException e) { System.err.println("Oooops. " + e.getMessage()); e.printStackTrace(); } tqt = aqConn.createQueueTable(qo[0], qt, AQqtp); //prepare a queue property AQQueueProperty AQqp = new AQQueueProperty(); //AQqp.setAutoCommit(false); AQqp.setComment("AQLite Sample Application"); //AQqp.setDepTracking(false); AQqp.setQueueType(AQqp.NORMAL_QUEUE); AQqp.setRetentionTime(0.0) ; // create Q on the QT AQQueue q = aqConn.createQueue(tqt, qn[0], AQqp); q.start(); //deployment AQLiteDeploymentAdmin admin = new AQLiteDeploymentAdmin(conn); AQLiteDeploymentQueueGroup qg = admin.createQueueGroup("AQLSampQG1", "order queue", qo, qn); AQLiteDeploymentOliteSite os = admin.createOliteSite("OliteSite1", "sampUser", null, null, true, "AQLite Sample Application"); os.defineQueueGroup(qg); os.instantiate(); /* AQLiteDeploymentAdmin admin = new AQLiteDeploymentAdmin(conn); AQLiteDeploymentOliteSite os = admin.getOliteSite("OliteSite2", "sampProc"); //os.deInstantiate(); os.instantiate(); */ os =admin.createOliteSite("OliteSite2", "sampProc", null, null, true, "AQLite Sample Application"); os.defineQueueGroup(qg); os.instantiate(); // commit changes conn.commit(); }//try catch (AQException e) { System.out.println("Oooops. " + e.getMessage()); e.printStackTrace(); } catch (java.sql.SQLException e) { System.out.println("Oooops. " + e.getMessage()); e.printStackTrace(); } } }
The following code is used to prepare the Oracle Lite client device for deployment of the sample application.
import oracle.AQ.*; import oracle.lite.jac.*; import oracle.lite.AQ.*; public class setupClient{ public static void main(String[] args) { if (args.length !=6 || args[0] == null || args[1] == null || args[2] == null || args[3] == null || args[4] == null || args[5] == null) { show_usage(); } String o8UserID = args[0]; String o8Passwd = args[1]; String o8ConnStr = args[2]; boolean newDB = true; String o8lConnStr = args[4]; String deqConsumer = null; if (args[3].toUpperCase().equals ("ORD")) deqConsumer = "sampUser"; else if (args[3].toUpperCase().equals ("PROC")) deqConsumer = "sampProc"; else { System.err.println("ERROR: option must be either 'ORD' or 'PROC'!!\n\n"); show_usage(); } String olitesite = args[5]; AQSession aqConn; try { // connect to Olite via Jac POLConnection pConn = POLConnection.getConnection(o8lConnStr, POLConnection.CONNECT_READ_WRITE); AQDriver aqD = (AQDriver) new AQLiteDriver(); // get connection to Olite database aqConn = aqD.createAQSession((Object) pConn); //make an O8 connection Object AQLitePropOraConn o8_conn = new AQLitePropOraConn("O8AQ", o8UserID, o8Passwd, o8ConnStr); AQLitePropagator propagator = new AQLitePropagator(); //make a deployment object AQLiteDeploymentClient dc = new AQLiteDeploymentClient((AQSession) aqConn, deqConsumer, o8_conn, propagator, olitesite ) ; //do a deploymnet dc.execDeployment(newDB, false); // commit changes pConn.commit(); } catch (AQException e) { System.err.println("Oooops. " + e.getMessage()); e.printStackTrace(); } catch (POLException e) { System.err.println("Oooops. " + e.getMessage()); e.printStackTrace(); } } static void show_usage() { System.err.println("Usage: java setupClient [o8UserId] [o8Passwd] [o8ConnStr] [option] [oliteConnStr] [oliteSiteName]"); System.err.println(""); System.err.println("option - 'ORD' for Order entry db, 'PROC' for Process order db"); System.err.println("\n\n Example:"); System.err.println("java setupClient AQUSER AQUSER my_machine.my_ domain.com:1521:orcl ORD C:\\ORANT\\OLDB40\\PoliteOrd.odb OliteSite1\n"); System.err.println("java setupClient AQUSER AQUSER my_machine.my_ domain.com:1521:orcl PROC C:\\ORANT\\OLDB40\\PoliteProc.odb OliteSite2"); System.err.println(""); System.exit(0); } }
|
|
![]() Copyright © 2001 Oracle Corporation. All Rights Reserved. |
|