ADO Events in ADO/WFC

See Also   

To use ADO Events in ADO/WFC

  1. Define your own event handler method to process an event. For example, if you wanted to process the ConnectComplete event in the ConnectionEvent family, you might use this code:
    public void onConnectComplete(Object sender,ConnectionEvent e)
    {
    System.out.println("onConnectComplete:" + e);
    }
    
  2. Define a handler object to represent your event handler method. The handler object should be of data type ConnectEventHandler for an event of type ConnectionEvent, or data type RecordsetEventHandler for an event of type  RecordsetEvent. For example, code the following for your ConnectComplete event handler:
    ConnectionEventHandler handler = 
    new ConnectionEventHandler(this, "onConnectComplete");
    

    The first argument of the ConnectionEventHandler constructor is a reference to the class that contains the method named in the second argument.

    The Microsoft Visual J++ compiler also supports an equivalent syntax:

    ConnectionEventHandler handler = 
    new ConnectionEventHandler(this.onConnectComplete);

    The single argument is a reference to the desired class (that is, this) and method within the class (that is, onConnectComplete).

  3. Add your event handler to a list of handlers designated to process a particular type of event. Use the method with a name such as addOnEventName(handler).

  4. ADO/WFC internally implements all the ADO Event handlers. Therefore, an event caused by a Connection or Recordset operation is intercepted by an ADO/WFC event handler.

    The ADO/WFC event handler passes ADO ConnectionEvent parameters in an instance of the ADO/WFC ConnectionEvent class, or ADO RecordsetEvent parameters in an instance of the ADO/WFC RecordsetEvent class. These ADO/WFC classes consolidate the ADO event parameters; that is, each ADO/WFC class contains one data member for each unique parameter in all the ADO ConnectionEvent or RecordsetEvent methods. 

  5. ADO/WFC then calls your event handler with the ADO/WFC event object. For example, your onConnectComplete handler has a signature like this:
    public void onConnectComplete(Object sender,ConnectionEvent e)

The first argument is the type of object that sent the event (Connection or Recordset), and the second argument is the ADO/WFC event object (ConnectionEvent or RecordsetEvent).

The signature of your event handler is simpler than an ADO event. However, you must still understand the ADO Event model to know what parameters apply to an event and how to respond.

  1. Return from your event handler to the ADO/WFC handler for the ADO Event. ADO/WFC copies pertinent ADO/WFC event data members back to the ADO event parameters, then the ADO Event handler returns.

  2. When you are finished processing, remove your handler from the list of ADO/WFC event handlers. Use the method with a name such as removeOnEventName(handler).