Avatar billede fredand Forsker
16. oktober 2006 - 23:05 Der er 4 kommentarer og
1 løsning

Trigger problem

Hello!

(Sorry to add this in here, since this propably is wrong forum for this)

I'm doing some work with a database application called Matrix.

I guess Matrix is not so common but it look like Hibernate to me.

You have a relation database in the bottom and instead of HQL you use MQL.

How ever we have a problem.

The goal is that we should generate jms-messages when things happens in Matrix.

For this we have a couple of triggers. (Propably Implemented in SQL in underlying the database).

In this case we use create triggers and modify attribute triggers.

The problem is that we generate to much messages.

Create triggers trigger when a object is created, and modify attribute triggres fires when a field on a object is updated.

For eg the Object car might look like:

Car
Car.name
Car.speed

When a car is created not 1 trigger is fired, but 3 triggers is fired.

I guess it works like this

create starts with some scope like:
create{
//In this scope two more trigger is fired
modify{
}
modify{
}
//...before the create is terminated.
}

For eg the jms-message in xml would look like
1
<xml>
    <object type="" name="Volvo" speed=""/>
</xml>

2
<xml>
    <object type="" name="Volvo" speed="150"/>
</xml>

3
<xml>
    <object type="Car" name="Volvo" speed="150"/>
</xml>

This is a bit simplified but in big this is how we adress the problem.

We need to be able to just generate 1 message at the end, and the problem seems to be the triggering.

We of course would like it to be like
create{
}

<xml>
    <object type="Car" name="Volvo" speed="150"/>
</xml>

If you have any input for this do not hesitate to give a input. Or perhaps you see something else we can do.

Best regards
Fredrik
Avatar billede simonvalter Praktikant
23. oktober 2006 - 16:19 #1
Sounds to me like its working as it should, but you don&#8217;t give a lot of information to work with ;-)

- I can't find the framework you are writing about... could you throw a link?
- Is it always 3 triggers fired no matter what object is created?
- Did you figure it out already? :)
Avatar billede simonvalter Praktikant
23. oktober 2006 - 16:28 #2
I'm guessing your problem is setting some default values in the constructor triggers the modify attribute trigger?
Avatar billede fredand Forsker
24. oktober 2006 - 08:48 #3
Hello!

You are very right, Matrix is a Framework with very little of info on the Internet. I guess it depends on that it is a product that just a few big companies buy.

How ever it looks like we can not get rid of the problem that it executes like this. This might be an inbuilt behaviour or some needed configuration that we just need to have unfortunately. (It is a very big application)

create{
//In this scope two more trigger is fired
modify{
}
modify{
}
//...before the create is terminated.
}



There for it seems like we have to build some filtering of our own.

First attempt would be to let the consumer always consume the create messages before modify messages, in this for eg the messages looking like:
<xml>
    <object type="Car" name="Volvo" speed="150"/>
</xml>

We are using a Weblogic 8.13 and we tried to do something like:
TopicPublisher topicPublisher = topicSession.createPublisher(topic);
topicPublisher.publish(CREATEMessage, 2, 7, timeToLive);


TopicPublisher topicPublisher = topicSession.createPublisher(topic);
topicPublisher.publish(MODIFYMessage, 2, 2, timeToLive);

In this code we set the priority for create messages higher (7) then for modify messages (2). But this does not seems to work. The modify messages still seems to be consumed before the create messages.

If this would work we solve a big part of this problem.

Secondly, but at least just as important, is to minimize the traffic. That means that we of course would get rid of all modify messages when they take place during a create. I guess this means that the best way is to build some cache-object and some backgroundprocess that filter out all modify messages that in some how is connected to a create. But the problem here is how to understand which modify that is a standalone message - then it should be sent as a update message - and which one is actually connected to a create?

One way might be to timestamp all messages. All messages that is modifiy messages with the timestamp within for eg 2 sec from a create message would be removed. Not so safe I guess.

An other way might be to see if we could find some transaction id for a create. Unfortunately it does not seems like Matrix provide this or even that the create and the inside modify does not executes in the same transaction.

So if you have any idea how to best attck this problem please let me know!

Best regards
Fredrik
Avatar billede simonvalter Praktikant
24. oktober 2006 - 17:30 #4
Don't think i can be of much help without knowing the product.

best solution would ofcourse be to not fire the trigger for attributes on a create... i would dig into the source of the framework if possible and change the behavior there. You should try to contact the vendor.

The timestamp is not a good idea.
You could create a flag and place it on the message to filter on which is set after create, not pretty and im not sure you would be minimizing traffic.
Avatar billede fredand Forsker
30. december 2006 - 13:38 #5
We needed to create a TimerTask that collects all calls. The timer is set to 5 sec and filter out all calls accept one. Works pretty ok but not the best solution we guess.
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester