otmfaqForumsBlogsRegister
FAQMembers ListCalendarToday's PostsSearch


 Subscribe Blogs:RSS
 Subscribe Forums:RSS
OTMFAQ Home
OTMFAQ Blogs
OTMFAQ Forums
OTMFAQ Tutorials

OTM SIG
MavenWire

Go Back   Oracle OTM / G-Log GC3 Community Support > OTM / G-Log - Functional Topics > Workflow
Reload this Page

Direct SQL Update in Agent. When is it committed?


Workflow Configuring Workflow components - including Agents, Milestones, Notifications Auto Data Assignment and Events.

Tags: , ,

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old January 16th, 2008, 16:41
Junior Member
 
Join Date: Aug 2007
Posts: 9
Thanks: 3
Thanked 4 Times in 3 Posts
Groans: 0
Groaned at 0 Times in 0 Posts
Rep Power: 0
jlgottlieb is on a distinguished road
Question Direct SQL Update in Agent. When is it committed?

Hi,

I have an Shipment Agent that listneing for a ShipmentModQuantitiesChange. In that agent I am recalcuating some shipment refnums. The agent deletes the refnums then re-insert thems. Most of the time this works just fine. Occasionally it throws a DuplicateKeyException.

We thought that the bean cache was not being refreshed fast enough, so there is a WAIT for 5 seconds between the delete and the insert. Note: in the Direct SQL Update, the box is checked to refresh the cache.

The agent terminates when the exception occurs, but when checking the Shipment_Refnum table, I see that all the refnums that I deleted are still there. I would have expected the deleted refnums to be gone and only the ones after the failed insert to be missing. That does not seem to be the case.

When are the Direct Sql Updates persisted to the database? If the agent fails, are all updates rolled back?

I'm thinking of rewriting the agent to either just update, rather than delete and insert or to write this as a stored procedure to be called instead. I would appreciate any comments as to which is the better way to accomplish this.

Note: I am running OTM 5.5 CU3-RU3.

THANKS!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old January 17th, 2008, 07:07
Member and Blogger
 
Join Date: Jan 2007
Location: Haalderen, Netherlands
Posts: 117
Blog Entries: 1
Thanks: 7
Thanked 33 Times in 31 Posts
Groans: 0
Groaned at 0 Times in 0 Posts
Rep Power: 2
bob_romijn is on a distinguished road
Send a message via Skype™ to bob_romijn
Re: Direct SQL Update in Agent. When is it committed?

Hi,

As far as my expirience here goes (5.0), it is committed instantly. I have a few of the same agents as you mention (first delete then insert) and they are working fine.
If an agent fails there is no roll-back. Is the SQL processes, it is processed and not rolled back.

Are you sure that the delete function works for these cases? I had such thing before where I found out that in some instances the delete sql worked but there was no record qualified for deletion.... (that costed me 4 hours...)

Of course that was 5.0

Best regards,

Bob
__________________
Best Regards,

Bob Romijn
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
The Following User Says Thank You to bob_romijn For This Useful Post:
jlgottlieb (January 17th, 2008)
  #3 (permalink)  
Old January 17th, 2008, 13:12
Junior Member
 
Join Date: Jun 2007
Posts: 20
Thanks: 0
Thanked 5 Times in 5 Posts
Groans: 0
Groaned at 0 Times in 0 Posts
Rep Power: 0
oliver is on a distinguished road
Re: Direct SQL Update in Agent. When is it committed?

Hi,
i have seen similar problems in previous versions, so we always used an update-sql;
maybe add another sql to assure the ref you want to update really exists

Rgds
Oliver
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
The Following User Says Thank You to oliver For This Useful Post:
jlgottlieb (January 17th, 2008)
  #4 (permalink)  
Old January 18th, 2008, 06:24
Senior Member and Blogger
 
Join Date: Dec 2006
Location: Singapore
Posts: 147
Blog Entries: 5
Thanks: 5
Thanked 11 Times in 10 Posts
Groans: 0
Groaned at 1 Time in 1 Post
Rep Power: 2
ianlo is on a distinguished road
Send a message via AIM to ianlo Send a message via Skype™ to ianlo
Re: Direct SQL Update in Agent. When is it committed?

Quote:
Originally Posted by jlgottlieb View Post
Hi,

The agent terminates when the exception occurs, but when checking the Shipment_Refnum table, I see that all the refnums that I deleted are still there. I would have expected the deleted refnums to be gone and only the ones after the failed insert to be missing. That does not seem to be the case.

When are the Direct Sql Updates persisted to the database? If the agent fails, are all updates rolled back?

I'm thinking of rewriting the agent to either just update, rather than delete and insert or to write this as a stored procedure to be called instead. I would appreciate any comments as to which is the better way to accomplish this.
Hi jlgottlieb

It is my practice to always use stored procedures when doing CUD operations. Only for Select statements do I enter it directly in the DirectSQL agent actions.

I found out that although through experience each DirectSQL statement is committed independently, unless we can verify this in the code, it is a risky assumption. Also there is the complexity of multiple agents possibly executing the DirectSQL in parallel...

So at least for me the general rule is this:

1) CUD statements are all executed in stored procedures as a single logical business operation.
2) No COMMITS or ROLLBACKS in the stored procedures
3) Use as few cursors as possible in the stored procedures and when using cursors I always specify EXPLICIT cursors

In addition, to optimise DirectSQL agent actions:
1) If there are multiple SELECT statements with CUD operations needed, all this goes into a single stored procedure
2) Multiple SELECT statements (unless each returning a different result) are collapsed if possible into a SINGLE select statement.
3) Try to push ALL CRUD database operations to the database by way of stored procedures or fuctions - this is to reduce the data round trip required between the application server and DB server.

Hope this helps!

Ian
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old January 18th, 2008, 14:54
Junior Member
 
Join Date: Aug 2007
Posts: 9
Thanks: 3
Thanked 4 Times in 3 Posts
Groans: 0
Groaned at 0 Times in 0 Posts
Rep Power: 0
jlgottlieb is on a distinguished road
Re: Direct SQL Update in Agent. When is it committed?

Ian,

Thank you for your insight. It was just what I was looking for. I have inherited OTM Administration and would like to try to standardize some practices for agents, recurring processes etc. I would appreicate it if you could expand on the following:

Why no COMMITS or ROLLBACKS in the procedure?

Is there a problem using a cursor for loop? Whate are your reasons for only using EXPLICIT cursors?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old January 18th, 2008, 16:30
Senior Member and Blogger
 
Join Date: Dec 2006
Location: Singapore
Posts: 147
Blog Entries: 5
Thanks: 5
Thanked 11 Times in 10 Posts
Groans: 0
Groaned at 1 Time in 1 Post
Rep Power: 2
ianlo is on a distinguished road
Send a message via AIM to ianlo Send a message via Skype™ to ianlo
Re: Direct SQL Update in Agent. When is it committed?

Hi jlgottlieb

Quote:
Originally Posted by jlgottlieb View Post

Why no COMMITS or ROLLBACKS in the procedure?
This is a habit I inherited from my past experience as a developer working with C/C++ and Borland Database Engine libraries. I have found that many developers write code that execute SQL statements without proper transaction control discipline. They inadvertently call CUD SQL statements elsewhere in their code (without transaction blocks) and then call subsequent stored procedures WITH commits / rollbacks in them.

This results in a serious transaction control bug when the stored procedure executes a commit or rollback, and their previous CUD SQL statements also get affected because they are all executed in the same session.

I know I am being paranoid here but without access to the source code, we cannot assume that OTM developers will not make the same mistake. Hence my rule to all my developers - never ever execute a COMMIT or ROLLBACK in PL/SQL code - do it in the calling body of the stored procedure.

Quote:
Originally Posted by jlgottlieb View Post
Ian,
Is there a problem using a cursor for loop? Whate are your reasons for only using EXPLICIT cursors?
There are no problems using a cursor for loop in OTM. However, for me using EXPLICIT cursors is a matter of code discipline where developers looking at my stored procedures for the first time will be aware of all the cursors I am creating in the procedure.

As far as I know in Oracle 10g, there is no performance difference in using EXPLICIT or IMPLICIT cursors - so either one will do. But for the sake of readibility and discipline, I made it a point to ensure that all cursors are EXPLICIT.

Hope this helps! Most of these guidelines are like I said more a result of my personal experience and lessons learnt as a developer. And since I am in the position to enforce it, I made it a rule for all my developers as well ...

Ian
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
The Following User Says Thank You to ianlo For This Useful Post:
jlgottlieb (January 21st, 2008)
Reply



Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Stored Procedure in Direct SQL muthaharotm Workflow 3 April 15th, 2008 11:49
Bulk Plan Vs Direct rj5316 Planning 1 December 3rd, 2007 12:38
Agent Add action fails with nullpointer sknmail@rediffmail.com Workflow 0 October 26th, 2007 21:14
How to Use an Agent to Copy Shipment Pro Number Information to Order Movements? stephen.dilday@volvo.com Workflow 1 October 11th, 2007 15:16
[SOLVED] Agent Event krishna.kk Workflow 6 July 24th, 2007 14:01



All times are GMT. The time now is 15:51.
Copyright © 2008, Open Book Solutions LLC. All rights reserved.

Sponsored by MavenWire - MavenWire.com


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37