#1 2016-03-21 08:19:29

lele9
Member
Registered: 2011-10-28
Posts: 170

OnUpdateEvent as trigger

Hi ab,
what is the best way to use trigger in mORMot?
i need to update other TSQLRecord on insert/update/delete...
I see OnUpdateEvent, but how can be sure that all trigger operations are atomic with the insert/update/delete that raise?
thanks

Offline

#2 2016-03-21 09:36:33

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,182
Website

Re: OnUpdateEvent as trigger

Put this on your application layer, not at ORM layer.
Use an event-driven mechanism, not a data-driven mechanism.

Offline

#3 2016-03-21 09:49:47

lele9
Member
Registered: 2011-10-28
Posts: 170

Re: OnUpdateEvent as trigger

Excuse me ab but i think i must put this at server-side level. I can't expect that all client appplication know business logic.
I think OnUpdateEvent should be perfect if i can do atomic operation like in a transaction.
Have you different idea about this?what do you suggest?

Offline

#4 2016-03-21 10:01:30

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,182
Website

Re: OnUpdateEvent as trigger

Indeed.
All the business logic should be done on the server side.
You should not have to use the ORM on the client side, if there is some business logic.

I mean "business logic", when you write some information.
For read-only process, we "may" directly access the data via REST/ORM, if it sounds safe enough.

But the best pattern is to define high-level SOA services on the server side, which would use the ORM on the server side, over several tables if needed.

Offline

#5 2016-03-21 16:58:48

lele9
Member
Registered: 2011-10-28
Posts: 170

Re: OnUpdateEvent as trigger

thinking about your suggest i write an interface-based-service to save and delete my TSQLRecord class.
something like this

IServiceCRUD = interface(IInvokable)['{FDD9121B-77A4-4C20-A283-42A80D54D42F}']
   function Delete(aRecord: TSQLRecord; var IDs: TIDDynArray): Integer;
   function Save(aRecord: TSQLRecord): Integer;
end;

and in implementation class (server-side) i write my business logic.
but i see that TSQLRecord is a bad parameter.
How can i do?
thanks for the patience

Offline

#6 2016-03-21 18:03:23

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,182
Website

Re: OnUpdateEvent as trigger

You have to put the exact class type, not an ancestor.

Offline

#7 2016-03-22 07:35:12

lele9
Member
Registered: 2011-10-28
Posts: 170

Re: OnUpdateEvent as trigger

i can define a method based services instead to declare an ancestor class?it works?
i would a service that passing a generic TSQLRecord can store it to the server in atomic operation with business logic if exists.

Offline

#8 2016-03-22 09:53:32

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,182
Website

Re: OnUpdateEvent as trigger

It would work only for a given TSQLRecord class.

The service would always benefit to be specified per-class.
Do not even use TSQLRecord, but value objects, ready to be consumed on client side.
With mORMot SOA, it is easy to write such services.

Offline

Board footer

Powered by FluxBB