{"id":251,"date":"2013-06-23T09:59:58","date_gmt":"2013-06-23T09:59:58","guid":{"rendered":"http:\/\/www.corrspt.com\/blog\/?p=251"},"modified":"2013-06-23T10:01:41","modified_gmt":"2013-06-23T10:01:41","slug":"xeo-api-loading-listing-and-iterating","status":"publish","type":"post","link":"http:\/\/www.corrspt.com\/blog\/2013\/06\/23\/xeo-api-loading-listing-and-iterating\/","title":{"rendered":"XEO API &#8211; Loading, Listing and Iterating"},"content":{"rendered":"<p>Hi<\/p>\n<p>Today I&#8217;d like to showcase a bit of <a title=\"XEO Framework\" href=\"http:\/\/www.xeoframework.org\" target=\"_blank\">XEO&#8217;s<\/a> API to load, list and iterate instances of XEOModels, which are really basic activities while using the API, so let&#8217;s get started:<\/p>\n<h1>Loading an instance<\/h1>\n<p>You have the following choices when loading an instance<\/p>\n<pre class=\"brush:java\">EboContext ctx = boApplication.currentContext().getEboContext();\r\n\r\n\/\/Load a specific BOUI, bypasses securities\r\nboObject.getBoManager().loadObject(ctx, \"1234\"); \r\n\/\/Load a specific BOUI, respect securities\r\nboObject.getBoSecurityManager().loadObject(ctx,\"1234\");\r\n\/\/Load using a BOQL Query (query must return a single result)\r\nboObject.getBoManager().loadObject(ctx, \"select Example where name = ?\",new Objct[]{\"name\"});\r\n\/\/Load using the BOUI with the ObjectManager\r\nboApplication.getDefaultApplication().getObjectManager().loadObject(ctx, boui);\r\n\/\/Instantiate the ManagerBean and load the object\r\nnew boManagerBean().loadObject(ctx, boui);<\/pre>\n<p>Be aware that usually there are two paths when loading a boObject. Using the SecurityManager (which respects security policies) and the normal Manager (which bypasses security)<\/p>\n<p>For listing you can do the following:<\/p>\n<pre class=\"brush:java\">EboContext ctx = boApplication.currentContext().getEboContext();\r\n\r\n\/\/Select without arguments\r\nboObjectList.list(ctx, \"select Example\");\r\n\/\/Select with arguments\r\nboObjectList.list(ctx, \"select Example where name = ?\", new Object[]{\"name\"});\r\n\/\/Select with multiple options\r\nboObjectList.list(ctx, boql, args, page, pageSize, orderBy, fullText, letter_filter, userQuery, useSecurity, useCache);\r\n\/\/Select using a Builder\r\nnew boObjectListBuilder(ctx, \"select Example where name = ? and other = ?\").argsList(\"arg1\",\"arg2\").cache(false).pageSize(3).build();\r\n\/\/Use the builder without the new\r\nboObjectList.builder(\"select Example where name = ?\").arg(\"name\").build();<\/pre>\n<p>Listing functions also have a parameter to apply security policies or not.<\/p>\n<p>In case you want to iterate a list you do the following.<\/p>\n<pre class=\"brush:java\">boObjectList list = boObjectList.list(ctx, \"select Example\");\r\nlist.beforeFirst();\r\nwhile (list.next()){\r\n\tboObject current = list.getObject();\r\n}<\/pre>\n<p>In case you want to iterate a collection attribute, do one of the following<\/p>\n<pre class=\"brush:java\">bridgeHandler bridge = obj.getBridge(\"collection\"); \r\n\/\/Using a bridge handler directly\r\nbridge.beforeFirst();\r\nwhile (bridge.next()){\r\n\tboObject current = bridge.getObject();\r\n}\r\n\r\n\/\/Using an \"iterator\"\t\t\r\nboBridgeIterator it = bridge.iterator();\r\nwhile (it.next()){\r\n\tboObject current = it.currentRow().getObject();\r\n}<\/pre>\n<p>That will be all, happy coding!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hi Today I&#8217;d like to showcase a bit of XEO&#8217;s API to load, list and iterate instances of XEOModels, which are really basic activities while using the API, so let&#8217;s get started: Loading an instance You have the following choices &hellip; <a href=\"http:\/\/www.corrspt.com\/blog\/2013\/06\/23\/xeo-api-loading-listing-and-iterating\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-251","post","type-post","status-publish","format-standard","hentry","category-xeo"],"_links":{"self":[{"href":"http:\/\/www.corrspt.com\/blog\/wp-json\/wp\/v2\/posts\/251","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.corrspt.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.corrspt.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.corrspt.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.corrspt.com\/blog\/wp-json\/wp\/v2\/comments?post=251"}],"version-history":[{"count":4,"href":"http:\/\/www.corrspt.com\/blog\/wp-json\/wp\/v2\/posts\/251\/revisions"}],"predecessor-version":[{"id":254,"href":"http:\/\/www.corrspt.com\/blog\/wp-json\/wp\/v2\/posts\/251\/revisions\/254"}],"wp:attachment":[{"href":"http:\/\/www.corrspt.com\/blog\/wp-json\/wp\/v2\/media?parent=251"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.corrspt.com\/blog\/wp-json\/wp\/v2\/categories?post=251"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.corrspt.com\/blog\/wp-json\/wp\/v2\/tags?post=251"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}