-
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)
{
println("onConnectComplete:" + e);
}
-
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.
-
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 addEventNameHandler(handler).
-
JADO internally implements all the ADO Event handlers. Therefore, an event caused by a Connection or Recordset operation is intercepted by a JADO event handler.
The JADO event handler passes ADO ConnectionEvent parameters in an instance of the JADO ConnectionEvent class, or ADO RecordsetEvent parameters in an instance of the JADO RecordsetEvent class. These JADO classes consolidate the ADO event parameters; that is, each JADO class contains one data member for each unique parameter in all the ADO ConnectionEvent or RecordsetEvent methods.
-
JADO then calls your event handler with the JADO 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 JADO 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.
-
Return from your event handler to the JADO handler for the ADO Event. JADO copies pertinent JADO event data members back to the ADO event parameters, then the ADO Event handler returns.
-
When you are finished processing, remove your handler from the list of JADO event handlers. Use the method with a name such as removeEventNameHandler(handler).