Trigger and Server Event Functions

Hello,

another question on tamino server extensions.

I have an agent waiting for an message sended by a message queue.
When I make an update of the database, i want to use a trigger (onInsert) to notify the agent by the message queue.
The problem is, i have a lot of documents to put in the database and the agent will receive the message of new documents to early, because not all documents had been stored. The search of the agent will fail.
Now I thought of using Server Event Functions in order to send the message after the transaction have finished.
Assume that the trigger which acts on Insert is like the trigger of the example SXSJTrigger.
How do I use the Server Event Functions within the trigger or is there another way to solve the problem.

Thanks in advance.

Best regards.

Tobias

Hello Tobias,

I would say that you don’t need to do anything in the Trigger function, just to put your code into the Event function.

The Tamino kernel will call your Event function and pass one of these values to it (depending on the outcome of the operation):

   XML_REQUEST_END 0 
   XML_COMMIT 1 
   XML_ROLLBACK 2 
   XML_CONNECTION_END 3 
   XML_SUB_COMMIT 4 
   XML_SUB_ROLLBACK 5</pre><BR>(Extract from:<BR><pre class="ip-ubbcode-code-pre">  C:\Program Files\Software AG\Tamino\Tamino 4.1.4.1\Documentation\servext\setypes.htm#seev


)

So you can have a simple “if” statement in the event function and send a message to the agent if it is necessary.

An alternative is to check the result of the Tamino operation inside your application, and take the appropriate action from there.

The Server Event function approach has the advantage of being “application agnostic”, so the code there will be called whenever a document is inserted (not just when a document is inserted through your application).

I hope that helps,
Trevor.

Hi Tobias,

If you need information about which documents have actually been stored during the transaction you should look at the technique used in the Java_Mapping example: information is stored in static ArrayLists, which are analyzed in the event function.

Best Regards,

Julius Geppert
Software AG

Hello Trevor,

thanks for your help.

I have another problem. The database is loaded with a mass of xml-files through the JavaLoader.
For each document the Java Loader is called.
I think each call will open a connection to the database and i cannot question for XML_CONNECTION_END or something else.
Do you have another idea?

Thanks in advance.

Best regards

Tobias

Hello Tobias,

The Java Loader is using sessions. Unless you enter another value via option -m, 10 documents are loading in each session. But even in sessionless transactions not only XML_REQUEST_END, but also XML_COMMIT/XML_ROLLBACK and XML_CONNECTION_END should be raised.

Docu says:



There is one precondition to remember: event functions are only called, if there has been a call to another function of the same Tamino Server Extension in the same request (for XML_REQUEST_END), the same transaction (for XML_COMMIT/XML_ROLLBACK) resp. the same session (for XML_CONNECTION_END). So you should use e.g. an insert trigger function on the doctype you are interested in.

Best regards,

Julius Geppert
Software AG