In this article, below scenarios are considered to see how values are updated in database and at what point.
Case 1 : What happens if setPropertyValue is called on an item - without calling updateItem and without any parent transaction?
Case 2 : What happens if setPropertyValue is called on an item - calling updateItem and without any parent transaction?
Case 3 : What happens if setPropertyValue is called on item - with parent transaction and without updateItem call?
Case 4 : What happens if setPropertyValue is called on item - With Transaction, with UpdateItem call?
=============================================================================================
Case 1 : What happens if setPropertyValue is called on an item - without calling updateItem and without any parent transaction?
for every item.setPropertyValue - update sql query is fired, commit is called, value is updated in database.
For example -
UPDATE www_addr_verify_req_log
SET CITY=?
WHERE REQUEST_LOG_ID=?
-- Parameters --
p[1] = {pd: city} Des Plaines2 (java.lang.String)
p[2] = {pd} 900001 (java.lang.String)
updateItem(addressValidation_req_log:900001) (changes applied: {city=Des Plaines2})
=============================================================================================
Case 2 : What happens if setPropertyValue is called on an item - calling updateItem and without any parent transaction?
Even though updateItem is called it does'nt mean that changes in database will get updated only after updateItem is called.
In this case too, for every item.setPropertyValue - update sql query is fired, commit is called, value is updated in database.
Note: When updateItem is called seperately - Since no changes nothing is done.
For example -
UPDATE www_addr_verify_req_log
SET CITY=?
WHERE REQUEST_LOG_ID=?
-- Parameters --
p[1] = {pd: city} Des Plaines2 (java.lang.String)
p[2] = {pd} 900001 (java.lang.String)
updateItem(addressValidation_req_log:900001) (changes applied: {city=Des Plaines2})
UPDATE www_addr_verify_req_log
SET STREET_ADDR2=?
WHERE REQUEST_LOG_ID=?
-- Parameters --
p[1] = {pd: streetAddr2} Des 2 (java.lang.String)
p[2] = {pd} 900001 (java.lang.String)
updateItem(addressValidation_req_log:900001) (changes applied: {streetAddr2=Des 2})
updateItem(addressValidation_req_log:900001) (no changes)
=============================================================================================
Case 3 : What happens if setPropertyValue is called on item - with parent transaction and without updateItem call?
If transaction is in place, then only one update query is fired for all property changes for that item.
A single update query is fired at for EACH item (even if there are many properties changed) at the end of transaction.
For example:
UPDATE www_addr_verify_req_log
SET STREET_ADDR2=?,CITY=?
WHERE REQUEST_LOG_ID=?
-- Parameters --
p[1] = {pd: streetAddr2} Des 2 (java.lang.String)
p[2] = {pd: city} Des Plaines2 (java.lang.String)
p[3] = {pd} 900001 (java.lang.String)
updateItem(addressValidation_req_log:900001) (changes applied: {streetAddr2=Des 2,city=Des Plaines2})
updateItem(categorytier3info:1335) (changes applied: {createUser=mktg-team1,updateUser=mktg-team1})
UPDATE WWW_CONTACTUS_DTL
SET CREATE_USER=?,UPDATE_USER=?
WHERE SUB_CATEGORY_ID=?
-- Parameters --
p[1] = {pd: createUser} mktg-team1 (java.lang.String)
p[2] = {pd: updateUser} mktg-team1 (java.lang.String)
p[3] = {pd} 1335 (java.lang.Integer)
=============================================================================================
Case 4: What happens if setPropertyValue is called on item - With Transaction, with UpdateItem?
update query is fired for each item when updateItem is called, but changes got updated in database only
when transaction is commited.
Note: The difference between case 3 and case 4 is, in case 3 all update queries are fired and committed when transaction ends. In case 4 update queries are fired during updateItem call and commit will be done only at the end of the transaction.
For example:
setPropertyValue(addressValidation_req_log:900001.city,Des Plaines2)
setPropertyValue(addressValidation_req_log:900001.streetAddr2,Des 2)
UPDATE www_addr_verify_req_log
SET STREET_ADDR2=?,CITY=?
WHERE REQUEST_LOG_ID=?
-- Parameters --
p[1] = {pd: streetAddr2} Des 2 (java.lang.String)
p[2] = {pd: city} Des Plaines2 (java.lang.String)
p[3] = {pd} 900001 (java.lang.String)
updateItem(addressValidation_req_log:900001) (changes applied: {streetAddr2=Des 2,city=Des Plaines2})
setPropertyValue(categorytier3info:1335.createUser,mktg-team1)
setPropertyPD{categorytier3info,1335,updateUser} = mktg-team1 (java.lang.String)
UPDATE WWW_CONTACTUS_DTL
SET CREATE_USER=?,UPDATE_USER=?
WHERE SUB_CATEGORY_ID=?
-- Parameters --
p[1] = {pd: createUser} mktg-team1 (java.lang.String)
p[2] = {pd: updateUser} mktg-team1 (java.lang.String)
p[3] = {pd} 1335 (java.lang.Integer)
updateItem(categorytier3info:1335) (changes applied: {createUser=mktg-team1,updateUser=mktg-team1})
=============================================================================================
Hope this helps!!
Case 1 : What happens if setPropertyValue is called on an item - without calling updateItem and without any parent transaction?
Case 2 : What happens if setPropertyValue is called on an item - calling updateItem and without any parent transaction?
Case 3 : What happens if setPropertyValue is called on item - with parent transaction and without updateItem call?
Case 4 : What happens if setPropertyValue is called on item - With Transaction, with UpdateItem call?
=============================================================================================
Case 1 : What happens if setPropertyValue is called on an item - without calling updateItem and without any parent transaction?
for every item.setPropertyValue - update sql query is fired, commit is called, value is updated in database.
For example -
MutableRepositoryItem mutItem = repo.getItemForUpdate("900001", "addressValidation_req_log");
mutItem.setPropertyValue("city", "Des Plaines2");
In logs - mutItem.setPropertyValue("city", "Des Plaines2");
UPDATE www_addr_verify_req_log
SET CITY=?
WHERE REQUEST_LOG_ID=?
-- Parameters --
p[1] = {pd: city} Des Plaines2 (java.lang.String)
p[2] = {pd} 900001 (java.lang.String)
updateItem(addressValidation_req_log:900001) (changes applied: {city=Des Plaines2})
=============================================================================================
Case 2 : What happens if setPropertyValue is called on an item - calling updateItem and without any parent transaction?
Even though updateItem is called it does'nt mean that changes in database will get updated only after updateItem is called.
In this case too, for every item.setPropertyValue - update sql query is fired, commit is called, value is updated in database.
Note: When updateItem is called seperately - Since no changes nothing is done.
For example -
mutItem.setPropertyValue("city", "Des Plaines2");
mutItem.setPropertyValue("streetAddr2", "Des 2");
repo.updateItem(mutItem);
MutableRepositoryItem mutItem = repo.getItemForUpdate("900001", "addressValidation_req_log");
mutItem.setPropertyValue("city", "Des Plaines2");
In logs - mutItem.setPropertyValue("streetAddr2", "Des 2");
repo.updateItem(mutItem);
MutableRepositoryItem mutItem = repo.getItemForUpdate("900001", "addressValidation_req_log");
mutItem.setPropertyValue("city", "Des Plaines2");
UPDATE www_addr_verify_req_log
SET CITY=?
WHERE REQUEST_LOG_ID=?
-- Parameters --
p[1] = {pd: city} Des Plaines2 (java.lang.String)
p[2] = {pd} 900001 (java.lang.String)
updateItem(addressValidation_req_log:900001) (changes applied: {city=Des Plaines2})
UPDATE www_addr_verify_req_log
SET STREET_ADDR2=?
WHERE REQUEST_LOG_ID=?
-- Parameters --
p[1] = {pd: streetAddr2} Des 2 (java.lang.String)
p[2] = {pd} 900001 (java.lang.String)
updateItem(addressValidation_req_log:900001) (changes applied: {streetAddr2=Des 2})
updateItem(addressValidation_req_log:900001) (no changes)
=============================================================================================
Case 3 : What happens if setPropertyValue is called on item - with parent transaction and without updateItem call?
If transaction is in place, then only one update query is fired for all property changes for that item.
A single update query is fired at for EACH item (even if there are many properties changed) at the end of transaction.
For example:
MutableRepositoryItem mutItem = repo.getItemForUpdate("900001", "addressValidation_req_log");
mutItem.setPropertyValue("city", "Des Plaines2");
mutItem.setPropertyValue("streetAddr2", "Des 2");
setPropertyValue(addressValidation_req_log:900001.city,Des Plaines2)
setPropertyValue(addressValidation_req_log:900001.streetAddr2,Des 2)
MutableRepositoryItem mutItem1 = repo1.getItemForUpdate("1335", "categorytier3info");
mutItem1.setPropertyValue("createUser", "mktg-team1");
mutItem1.setPropertyValue("updateUser", "mktg-team1");
setPropertyValue(categorytier3info:1335.createUser,mktg-team1)
setPropertyValue(categorytier3info:1335.updateUser,mktg-team1)
td.end(true);
In logs - mutItem.setPropertyValue("city", "Des Plaines2");
mutItem.setPropertyValue("streetAddr2", "Des 2");
setPropertyValue(addressValidation_req_log:900001.city,Des Plaines2)
setPropertyValue(addressValidation_req_log:900001.streetAddr2,Des 2)
MutableRepositoryItem mutItem1 = repo1.getItemForUpdate("1335", "categorytier3info");
mutItem1.setPropertyValue("createUser", "mktg-team1");
mutItem1.setPropertyValue("updateUser", "mktg-team1");
setPropertyValue(categorytier3info:1335.createUser,mktg-team1)
setPropertyValue(categorytier3info:1335.updateUser,mktg-team1)
td.end(true);
UPDATE www_addr_verify_req_log
SET STREET_ADDR2=?,CITY=?
WHERE REQUEST_LOG_ID=?
-- Parameters --
p[1] = {pd: streetAddr2} Des 2 (java.lang.String)
p[2] = {pd: city} Des Plaines2 (java.lang.String)
p[3] = {pd} 900001 (java.lang.String)
updateItem(addressValidation_req_log:900001) (changes applied: {streetAddr2=Des 2,city=Des Plaines2})
updateItem(categorytier3info:1335) (changes applied: {createUser=mktg-team1,updateUser=mktg-team1})
UPDATE WWW_CONTACTUS_DTL
SET CREATE_USER=?,UPDATE_USER=?
WHERE SUB_CATEGORY_ID=?
-- Parameters --
p[1] = {pd: createUser} mktg-team1 (java.lang.String)
p[2] = {pd: updateUser} mktg-team1 (java.lang.String)
p[3] = {pd} 1335 (java.lang.Integer)
=============================================================================================
Case 4: What happens if setPropertyValue is called on item - With Transaction, with UpdateItem?
update query is fired for each item when updateItem is called, but changes got updated in database only
when transaction is commited.
Note: The difference between case 3 and case 4 is, in case 3 all update queries are fired and committed when transaction ends. In case 4 update queries are fired during updateItem call and commit will be done only at the end of the transaction.
For example:
MutableRepositoryItem mutItem = repo.getItemForUpdate("900001", "addressValidation_req_log");
mutItem.setPropertyValue("city", "Des Plaines2");
mutItem.setPropertyValue("streetAddr2", "Des 2");
repo.updateItem(mutItem);
MutableRepositoryItem mutItem1 = repo1.getItemForUpdate("1335", "categorytier3info");
mutItem1.setPropertyValue("createUser", "mktg-team1");
mutItem1.setPropertyValue("updateUser", "mktg-team1");
repo1.updateItem(mutItem1);
In logs - mutItem.setPropertyValue("city", "Des Plaines2");
mutItem.setPropertyValue("streetAddr2", "Des 2");
repo.updateItem(mutItem);
MutableRepositoryItem mutItem1 = repo1.getItemForUpdate("1335", "categorytier3info");
mutItem1.setPropertyValue("createUser", "mktg-team1");
mutItem1.setPropertyValue("updateUser", "mktg-team1");
repo1.updateItem(mutItem1);
setPropertyValue(addressValidation_req_log:900001.city,Des Plaines2)
setPropertyValue(addressValidation_req_log:900001.streetAddr2,Des 2)
UPDATE www_addr_verify_req_log
SET STREET_ADDR2=?,CITY=?
WHERE REQUEST_LOG_ID=?
-- Parameters --
p[1] = {pd: streetAddr2} Des 2 (java.lang.String)
p[2] = {pd: city} Des Plaines2 (java.lang.String)
p[3] = {pd} 900001 (java.lang.String)
updateItem(addressValidation_req_log:900001) (changes applied: {streetAddr2=Des 2,city=Des Plaines2})
setPropertyValue(categorytier3info:1335.createUser,mktg-team1)
setPropertyPD{categorytier3info,1335,updateUser} = mktg-team1 (java.lang.String)
UPDATE WWW_CONTACTUS_DTL
SET CREATE_USER=?,UPDATE_USER=?
WHERE SUB_CATEGORY_ID=?
-- Parameters --
p[1] = {pd: createUser} mktg-team1 (java.lang.String)
p[2] = {pd: updateUser} mktg-team1 (java.lang.String)
p[3] = {pd} 1335 (java.lang.Integer)
updateItem(categorytier3info:1335) (changes applied: {createUser=mktg-team1,updateUser=mktg-team1})
=============================================================================================
Hope this helps!!
Good one..i have a doubt Raja, we have 16 front instances and 4 jboss servers in this case , what cache mode i can choose for my order repository ? what do you suggest ?
ReplyDeleteAwesome analysis and useful for debugging and implementing db calls!
ReplyDeletevery good analysis. gave insight on how to analyze such type of exceptions as well
ReplyDeleteAwesome Explanation .. Very Nice Insight to Repository Item Update
ReplyDeleteVery good explanation, really helpful.
ReplyDeleteRecently I am facing issue where we are updating 1000 of mutable repository item at time but in that few where not updated there is no any exception at backend. Can you help me on this?
ReplyDeleteI dont know why insert query is called for updateItem() call.Does anyone know why ?
ReplyDelete