• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to implement sql command one by one

 
identita smart
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to implement two sql command in the one methods;

public void saveDataTracnsaction() {
deleteReportDatat(); -----------(1)
saveRawData(); -----------(2)
}

First one is to delete some records from one big of table. Second one is to save one record into small of table. When I call the methods saveDataTracnsaction(), seem second one is completed first because first one need to take some time. So this result will cause the issues, there are another application will process this saved raw data, and save it into report table, then will be removed together.

May I know how to prevent this happen? how do I implement this code, only after finish deleteReportDatat(), then go to saveRawData()? Is there any Listener function to detect finishing executing SQL command?


Thanks
 
kv ruby
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You will have to lock the rows when one operation is performed.
 
identita smart
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I try to prevent the new record to be readied by another application during persist this new record, and using following codes:

em.lock(gps, LockModeType.READ);
em.persist(gps);


But it throw exception, and cannot save data, may i know what happened

Thanks,
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"identita smart", My request that you change your display name to adhere to JavaRanch standards was not a suggestion. Valid display names are mandatory for participation on the Ranch. Please change your display name as instructed prior to your next post.

Be aware that accounts with invalid display names are disabled.

bear
JavaRanch Sheriff
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!