Replication with Infosphere CDC : IBM InfoSphere CDC for solidDB® reference : User exits for IBM InfoSphere CDC : Example of a stored procedure user exit
  
Example of a stored procedure user exit
The following code snippet is an example of a stored procedure user exit.
Code
 
create or replace procedure
   PROD.AUDIT_STPROC (
   result       OUT INT,
   returnMsg    OUT CHAR,
   s$entry      IN NUMBER,
   s$srcSysId   IN CHAR
   s$srcTabId   IN CHAR,
   s$tgtTabId   IN CHAR,
   j$ENTT       IN CHAR,
   a$IDNO       IN NUMBER,
   a$PRICE      IN NUMBER,
   a$DESC       IN CHAR,
   a$LONGDESC   IN CHAR,
   a$TRANSDATE  IN DATE,
   d$IDNO       IN NUMBER,
   d$PRICE      IN NUMBER,
   d$DESC       IN CHAR,
   d$LONGDESC   IN CHAR,
   d$TRANSDATE  IN DATE
)
The parameters you declare and want to pass to your stored procedure must be valid data types.
The following parameters are mandatory and must be declared in your stored procedure:
result—Returns a value of '0' which indicates the stored procedure was successful or an error which may be an integer.
returnMsg—Returns an error message in the Event Log.
The following parameters have been declared in this stored procedure:
s$entry—retrieves the entry point at which the stored procedure was called. In this example, IBM InfoSphere CDC calls the user exit at every entry point.
s$srcSysId—retrieves the location of source data
s$srcSysId—retrieves the location of source data
s$srcTabId—retrieves the name of the source table
s$srcTabId—retrieves the name of the source table
s$tgtTabId—retrieves the name of the target table
s$tgtTabId—retrieves the name of the target table
j$ENTT—retrieves the journal code that indicates the type of operation that took place on the source table
j$ENTT—retrieves the journal code that indicates the type of operation that took place on the source table
a$—retrieves the after image of the IDNO, PRICE, DESC, LONGDESC, and TRANSDATE source columns
a$—retrieves the after image of the IDNO, PRICE, DESC, LONGDESC, and TRANSDATE source columns
d$—retrieves the transformed data of the IDNO, PRICE, DESC, LONGDESC, and TRANSDATE target columns
d$—retrieves the transformed data of the IDNO, PRICE, DESC, LONGDESC, and TRANSDATE target columns
IS
ENTRYPOINT VARCHAR(50);
BEGIN
CASE s$entry
WHEN 16 THEN ENTRYPOINT := ’User Exit program called Before Insert’;
WHEN 1048576 THEN ENTRYPOINT := ’User Exit program called After Insert’;
WHEN 64 THEN ENTRYPOINT := ’User Exit program called Before Update’;
WHEN 4194304 THEN ENTRYPOINT := ’User Exit program called After Update’;
END CASE;
This stored procedure user exit can be invoked from these entry points.
insert into PROD.AUDIT_TABLE1 values (
s$entry, s$srcSysId, s$srcTabId, s$tgtTabId, j$ENTT, a$IDNO, a$PRICE, a$DESC, a$LONGDESC, a$TRANSDATE, d$IDNO, d$PRICE, d$DESC, d$LONGDESC, d$TRANSDATE, ENTRYPOINT);
This stored procedure user exit will INSERT these values into PROD.AUDIT_TABLE1.
result := 1;
returnMsg :=
’OK’; END AUDIT_STPROC;
This stored procedure user exit was successful.
Note If your stored procedure returns a '0', then a message is generated to the event log.
See also
Sample user exits for IBM InfoSphere CDC
User exits for IBM InfoSphere CDC
Sample user exits for IBM InfoSphere CDC
IBM InfoSphere CDC provides sample user exits that you can extend or modify to suit your environment. The samples are found in samples.jar which is located in the samples directory in your IBM InfoSphere CDC installation directory. The Java file contains the following samples:
ArchiveLogPathUserExitSample.java — returns the fully qualified path (including file name and extension) to the archive log file. This sample is located in com.datamirror.ts.target.publication.userexit.sample.
CRUserExitSample.java—a conflict resolution user exit that can be used with tables having a primary key column of any data type or a numeric column with any data type. This sample is located in com.datamirror.ts.target.publication.userexit.cdr.
DEUserExitSample.java — used in expressions using the %USERFUNC column function. It calculates the sum of the user-supplied parameters (in the expression) and returns the sum incremented by 1. This sample is located in com.datamirror.ts.derivedexpressionmanager.
SPUserExitSample.java — calls a stored procedure with the image coming from the source. This sample is located in com.datamirror.ts.target.publication.userexit.sample.
UserExitSample.java — subscribes to replication events to retrieve the details of the events which took place. This sample is located in com.datamirror.ts.target.publication.userexit.sample.
UserExitSample1.java — records new rows inserted into a table on the target and stores them in a text file. The user specifies the name of the text file as a parameter. This sample is located in com.datamirror.ts.target.publication.userexit.sample.
Note the following:
To run the sample user exits without modifying them, you must specify the fully qualified path to the compiled user exit in Management Console. For example, com.datamirror.ts.target.publication.userexit.sample.UserExitSample.
Compiled sample user exits are located in the ts.jar file which is found in the lib directory in your IBM InfoSphere CDC installation directory. Note that the compiled user exits in the ts.jar file have a *.class extension.
If you want to modify the sample user exits, you must compile the user exit after you make changes to the source code.
The user exit class must also be in your classpath.
For more information about how to specify Java class or Stored Procedure user exits in Management Console, see your Management Console documentation.
To compile the sample user exits (Windows) Procedure
1 Stop IBM InfoSphere CDC.
2 Unzip the samples.jar file into the lib folder in your IBM InfoSphere CDC installation folder. Make sure you maintain the folder structure when unzipping the jar file.
After unzipping the jar file, you will have a folder structure like the following:
<IBM InfoSphere CDC installation folder>\lib\com\datamirror\ts\target \publication\userexit\sample
3 Make your changes to the sample user exit.
4 Compile the modified user exit. For example, if you want to compile UserExitSample.java, open a command window, navigate to the lib folder and issue the following command:
javac -classpath ts.jar;. com\datamirror\ts\target\publication\userexit\sample \UserExitSample.java
If this command runs successfully, there will be no output on your screen.
Note Your system must have the Java JDK to run this command.
5 After running the command successfully, navigate to the following directory and confirm that you have created a UserExitSample.class file:
<IBM InfoSphere CDC installation directory>\lib\com\datamirror\ts\target \publication\userexit\sample
6 Start IBM InfoSphere CDC.
7 The final step to configure the user exit is to specify the fully qualified path to UserExitSample in Management Console. For example: com.datamirror.ts.target.publication.userexit.sample.UserExitSample
Note Do not specify the .class extension.
What to do next
For more information about how to specify Java class user exits in Management Console, see your Management Console documentation.
If you plan to use the sample user exits in production environments, you will have to test the samples before they are deployed. UNICOM Systems, Inc. does not assume responsibility for adverse results caused by modified or customized user exit classes.
To compile the sample user exits (UNIX and Linux)
1 Stop IBM InfoSphere CDC.
2 Unzip the samples.jar file into the lib directory in your IBM InfoSphere CDC installation directory. Make sure you maintain the directory structure when unzipping the jar file.
After unzipping the jar file, you will have a directory structure like the following:
<IBM InfoSphere CDC installation directory>/lib/com/datamirror/ts/target /publication/userexit/sample
3 Make your changes to the sample user exit.
4 Compile the modified user exit. For example, if you want to compile UserExitSample.java, open a command window, navigate to the lib directory and issue the following command:
javac -classpath ts.jar:. com/datamirror/ts/target/publication/userexit/sample /UserExitSample.java
If this command runs successfully, there will be no output on your screen.
Your system must have the Java JDK to run this command.
5 After running the command successfully, navigate to the following directory
and confirm that you have created a UserExitSample.class file:
<IBM InfoSphere CDC installation directory>/lib/com/datamirror/ts/target /publication/userexit/sample
6 Start IBM InfoSphere CDC.
7 The final step to configure the user exit is to specify the fully qualified path to UserExitSample in Management Console. For example: com.datamirror.ts.target.publication.userexit.sample.UserExitSample
Do not specify the .class extension.
What to do next
For more information about how to specify Java class user exits in Management Console, see your Management Console documentation.
If you plan to use the sample user exits in production environments, you will have to test the samples before they are deployed. UNICOM Systems, Inc. does not assume responsibility for adverse results caused by modified or customized user exit classes.
See also
Example of a stored procedure user exit