{"id":203,"date":"2015-11-26T14:49:43","date_gmt":"2015-11-26T14:49:43","guid":{"rendered":"https:\/\/maximoconcepts.wordpress.com\/?p=203"},"modified":"2015-11-26T14:49:43","modified_gmt":"2015-11-26T14:49:43","slug":"when-using-mxserver-for-fetching-mboset","status":"publish","type":"post","link":"https:\/\/maximoconcepts.com\/2015\/11\/26\/when-using-mxserver-for-fetching-mboset\/","title":{"rendered":"When using MXServer for fetching MboSet"},"content":{"rendered":"
There are two ways of fetching a MboSet in java code, either using a relationship or through MXserver. There are different benefits for using either of these and different scenarios may need one of these ways to be used. For now, we are going to talk about MboSet fetched from MXServer.<\/p>\n
When fetching a MboSet from MXServer, there are a few things that one needs to be careful about. Poor knowledge of these may result in performance issues, poor memory management and undesirable outcomes.<\/p>\n
There are six simple rules to keep in mind when fetching MboSet from MXserver. These rules are as follows \u2013<\/p>\n
\nMboSetRemote assetSet = MXServer.getMXServer().getMboSet(\"ASSET\", getUserInfo());\n<\/em>assetSet.setWhere(\"LOCATION = 'BEDFORD'\");\n<\/em>assetSet.reset();<\/em><\/pre>\n<\/blockquote>\n\n
- If the set is being fetched just to add new MBOs and not for traversing then use 1=0 as where clause in the setWhere. This will fetch an empty set.<\/li>\n<\/ol>\n
\nassetSet.setWhere(\"1=0\");\n<\/em>assetSet.reset();<\/em><\/pre>\n<\/blockquote>\n\n
- If the set is being fetched just for traversing and not for any addition or updates set DISCARDABLE flag as true on the MboSet. Discardable MboSets are not cached in memory, they can only be traversed in forward direction and cannot be saved.<\/li>\n<\/ol>\n
\nassetSet.setFlag(DISCARDABLE, true);<\/em><\/pre>\n<\/blockquote>\n\n
- If MboSet is fetched for readonly purpose, set NOSAVE flag as true. This way the MboSet won\u2019t be added to the MXTransaction which would shortens the looping time of the transaction.<\/li>\n<\/ol>\n
\nassetSet.setFlag(NOSAVE, true);<\/em><\/pre>\n<\/blockquote>\n\n
- If an add or update transaction is being performed on an MboSet, do not forget to call save(). Contrary to popular belief that save shouldn\u2019t be called explicitly in java code, MboSet fetched from MXServer must be saved before the set is closed otherwise the changes would be lost. MboSets fetched from relationship do not require a save to be called explicitly because their save is called when their parent is saved. Hence the belief.<\/li>\n<\/ol>\n
\n
- Always call clear() and close() on the MboSet fetched from MXServer once it is certain that it is not required anymore. This releases the memory and the database resources. If the set is not closed, it will remain in memory till it is collected by the garbage collector which could be a long time.<\/li>\n<\/ol>\n
\nassetSet.clear();\n<\/em>assetSet.close();<\/em>\u00a0<\/em><\/pre>\n<\/blockquote>\nclear and close shouldn\u2019t be called on an MBOSet fetched from a relationship. This will give undesirable results.<\/p>\n
So keep in mind these simple rules next time when you are fetching a set from MXServer.<\/p>\n
In my next post I will try to explain you the difference between clear(), cleanup() & close(). Stay tuned.. \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"
There are two ways of fetching a MboSet in java code, either using a relationship or through MXserver. There are different benefits for using either of these and different scenarios may need one of these ways to be used. For now, we are going to talk about MboSet fetched from MXServer. When fetching a MboSet … Continue reading When using MXServer for fetching MboSet<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[13,5],"tags":[],"yoast_head":"\n
When using MXServer for fetching MboSet - Maximo Concepts<\/title>\n\n\n\n\n\n\n\n\n\n\n\n\n\t\n\t\n\t\n