<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Recent changes to Examples</title><link>https://sourceforge.net/p/openerpjavaapi/wiki/Examples/</link><description>Recent changes to Examples</description><atom:link href="https://sourceforge.net/p/openerpjavaapi/wiki/Examples/feed" rel="self"/><language>en</language><lastBuildDate>Wed, 21 Sep 2011 01:43:09 -0000</lastBuildDate><atom:link href="https://sourceforge.net/p/openerpjavaapi/wiki/Examples/feed" rel="self" type="application/rss+xml"/><item><title>WikiPage Examples modified by Pieter van der Merwe</title><link>https://sourceforge.net/p/openerpjavaapi/wiki/Examples/</link><description>&lt;pre&gt;--- v10 
+++ v11 
@@ -1,71 +1,66 @@
-Creating an OpenERP session
----
-Each of the examples uses a Session object from the OpenERP Java Api.
-
-    :::java
+Creating an OpenERP session and ObjectAdapter
+---
+Each of the examples uses a Session object and ObjectAdapter from the OpenERP Java Api.
+
+    :::java
     Session openERPSession = new Session("openerp1", 8069, "demo_database", "admin", "admin");
     try {
+        // startSession logs into the server and keeps the userid of the logged in user
         openERPSession.startSession();
+        ObjectAdapter partnerAd = openERPSession.getObjectAdapter("res.partner");
         ////// 
         ////// Example code snippet goes here
         //////
     } catch (Exception e) {
         System.out.println("Error while reading data from server:\n\n" + e.getMessage());
     }
 
-Search - Single filter
----
-Searches for all active partners, regardless of type (Customer, Supplier etc)
-
-    :::java
-    Object[] ids = openERPSession.searchObject("res.partner", new Object[][] {new Object[]{"active","=",true}});
-    for (Object id : ids)
-        System.out.println(id.toString());
-
-Search - Multi filter
----
-Searches for all active customers
-
-    :::java
-    Object[] ids = openERPSession.searchObject("res.partner", new Object[][] {new Object[]{"customer","=",true}, new Object[]{"active","=",true}});
-    for (Object id : ids)
-        System.out.println(id.toString());
-
-    
-Read
----
-The following snippet, reads the active customers and displays the name and email fields of those customers.
-
-    :::java
-    Object[] ids = openERPSession.searchObject("res.partner", new Object[][] {new Object[]{"customer","=",true}, new Object[]{"active","=",true}});
-    RowCollection rows = openERPSession.readObject("res.partner", ids, new String[] {"name","email"});
-    for(Row row : rows){
-        System.out.println("---------New Row------------");
-        System.out.println("Id :" + row.get("id"));
-        for (Field f : row.getFields()){
-            Object value = row.get(f.getName());
-            System.out.println(f.getName() + ":" + (value == null ? "Null" : value.toString()));
-        }
-    }
-
-The two calls, search and read, can be combined with one call to searchAndReadObject.
-
-    :::java
-    RowCollection rows = openERPSession.searchAndReadObject("res.partner",new Object[][] {new Object[]{"customer","=",true}, new Object[]{"active","=",true}},new String[] {"name","email"});
-    
-
-Write
----
-In this code snippet, the customer ASUStek's email address is changed to testemail@gmail.com.
-
-    :::java
-    int ASUStekID = Integer.parseInt(openERPSession.searchObject("res.partner", new Object[][] {new Object[]{"name","=","ASUStek"}})[0].toString());
-    
-    // update field 'email' with value testemail@gmail.com 
-    HashMap&lt;String, Object&gt; valueList = new HashMap&lt;String, Object&gt;();
-    valueList.put("email", "testemail@gmail.com");
-			
-    boolean success = openERPSession.writeObject("res.partner", ASUStekID, valueList);
-			
+Simple read of customers
+---
+Reads customer name and email addresses.
+
+    :::java
+    FilterCollection filters = new FilterCollection();
+    filters.add("customer","=",true);
+    RowCollection partners = partnerAd.searchAndReadObject(filters, new String[]{"name","email"});
+
+Displaying values from a RowCollection
+---
+Continuing on from the previous example, you could read the partners like this:
+
+    :::java
+    for (Row row : partners){
+        System.out.println("Row ID: " + row.getID());
+        System.out.println("Name:" + row.get("name"));
+        System.out.println("Email:" + row.get("email"));
+    }
+    
+Update email address of a partner
+---
+In this code snippet, the customer Agrolait's email address is changed to testemail@gmail.com.
+
+    :::java
+    FilterCollection filters = new FilterCollection();
+    filters.add("name","=","Agrolait");
+    RowCollection partners = partnerAd.searchAndReadObject(filters, new String[]{"name","email"});
+    
+    // You could do some validation here to see if the customer was found
+    Row AgrolaitRow = partners.get(0);
+    AgrolaitRow.put("email", "testemail@gmail.com");
+    // Tell writeObject to only write changes ie the name isn't updated because it wasn't changed.
+    boolean success = partnerAd.writeObject(AgrolaitRow, true);
+    
     if (success)
         System.out.println("Update was successful");
+
+Creating a new partner
+---
+
+    :::java
+    Row newPartner = partnerAd.getNewRow(new String[]{"name", "ref"});
+    newPartner.put("name", "New Customer");
+    newPartner.put("ref", "Reference Number1");
+    partnerAd.createObject(newPartner);
+    
+    System.out.println("New Row ID: " + newPartner.getID());
+
&lt;/pre&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Pieter van der Merwe</dc:creator><pubDate>Wed, 21 Sep 2011 01:43:09 -0000</pubDate><guid>https://sourceforge.net1c451527cbf4da54077657c94390de26f0f5529f</guid></item><item><title>WikiPage Examples modified by Pieter van der Merwe</title><link>https://sourceforge.net/p/openerpjavaapi/wiki/Examples/</link><description>&lt;pre&gt;--- v9 
+++ v10 
@@ -1,29 +1,29 @@
 Creating an OpenERP session
 ---
-Each of the examples uses an Session object from the OpenERP Java Api.
-
-    :::java
+Each of the examples uses a Session object from the OpenERP Java Api.
+
+    :::java
     Session openERPSession = new Session("openerp1", 8069, "demo_database", "admin", "admin");
     try {
         openERPSession.startSession();
         ////// 
         ////// Example code snippet goes here
         //////
     } catch (Exception e) {
         System.out.println("Error while reading data from server:\n\n" + e.getMessage());
     }
 
 Search - Single filter
 ---
 Searches for all active partners, regardless of type (Customer, Supplier etc)
 
     :::java
     Object[] ids = openERPSession.searchObject("res.partner", new Object[][] {new Object[]{"active","=",true}});
     for (Object id : ids)
         System.out.println(id.toString());
 
 Search - Multi filter
 ---
 Searches for all active customers
 
     :::java
@@ -32,29 +32,29 @@
         System.out.println(id.toString());
 
     
-Read example
+Read
 ---
 The following snippet, reads the active customers and displays the name and email fields of those customers.
 
     :::java
     Object[] ids = openERPSession.searchObject("res.partner", new Object[][] {new Object[]{"customer","=",true}, new Object[]{"active","=",true}});
     RowCollection rows = openERPSession.readObject("res.partner", ids, new String[] {"name","email"});
     for(Row row : rows){
         System.out.println("---------New Row------------");
         System.out.println("Id :" + row.get("id"));
         for (Field f : row.getFields()){
             Object value = row.get(f.getName());
             System.out.println(f.getName() + ":" + (value == null ? "Null" : value.toString()));
         }
     }
 
 The two calls, search and read, can be combined with one call to searchAndReadObject.
 
     :::java
     RowCollection rows = openERPSession.searchAndReadObject("res.partner",new Object[][] {new Object[]{"customer","=",true}, new Object[]{"active","=",true}},new String[] {"name","email"});
     
 
-Write example
+Write
 ---
 In this code snippet, the customer ASUStek's email address is changed to testemail@gmail.com.
 
&lt;/pre&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Pieter van der Merwe</dc:creator><pubDate>Thu, 08 Sep 2011 23:00:50 -0000</pubDate><guid>https://sourceforge.netb72850a9139ec5d23c3ad4e75fe18f8a1c2751b9</guid></item><item><title>WikiPage Examples modified by Pieter van der Merwe</title><link>https://sourceforge.net/p/openerpjavaapi/wiki/Examples/</link><description>&lt;pre&gt;--- v8 
+++ v9 
@@ -15,15 +15,15 @@
 
 Search - Single filter
 ---
-Searches for all active partners, regardless of type (Customer, Cupplier etc)
-
-    :::java
+Searches for all active partners, regardless of type (Customer, Supplier etc)
+
+    :::java
     Object[] ids = openERPSession.searchObject("res.partner", new Object[][] {new Object[]{"active","=",true}});
     for (Object id : ids)
         System.out.println(id.toString());
 
 Search - Multi filter
 ---
 Searches for all active customers
 
     :::java
@@ -32,32 +32,27 @@
         System.out.println(id.toString());
 
     
 Read example
 ---
 The following snippet, reads the active customers and displays the name and email fields of those customers.
 
     :::java
     Object[] ids = openERPSession.searchObject("res.partner", new Object[][] {new Object[]{"customer","=",true}, new Object[]{"active","=",true}});
     RowCollection rows = openERPSession.readObject("res.partner", ids, new String[] {"name","email"});
     for(Row row : rows){
         System.out.println("---------New Row------------");
-	System.out.println("Id :" + row.get("id"));
-	for (Field f : row.getFields()){
-	    Object value = row.get(f.getName());
-	    System.out.println(f.getName() + ":" + (value == null ? "Null" : value.toString()));
-	}
+        System.out.println("Id :" + row.get("id"));
+        for (Field f : row.getFields()){
+            Object value = row.get(f.getName());
+            System.out.println(f.getName() + ":" + (value == null ? "Null" : value.toString()));
+        }
     }
 
-The two calls to fetch the ID's and the
-
-The following code snippet reads the ir.model object and displays the 'model' and 'name' fields.
-
-    :::java
-    RowCollection rows = openERPSession.searchAndReadObject("ir.model",null,new String[] {"model","name"});
-    for(Row row : rows)
-        System.out.println(row.get("model").toString() + " " + row.get("name").toString());
-    
- 
+The two calls, search and read, can be combined with one call to searchAndReadObject.
+
+    :::java
+    RowCollection rows = openERPSession.searchAndReadObject("res.partner",new Object[][] {new Object[]{"customer","=",true}, new Object[]{"active","=",true}},new String[] {"name","email"});
+    
 
 Write example
 ---
&lt;/pre&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Pieter van der Merwe</dc:creator><pubDate>Thu, 08 Sep 2011 06:59:05 -0000</pubDate><guid>https://sourceforge.netb44ada03439c3254421385f89983366f10e224a4</guid></item><item><title>WikiPage Examples modified by Pieter van der Merwe</title><link>https://sourceforge.net/p/openerpjavaapi/wiki/Examples/</link><description>&lt;pre&gt;--- v7 
+++ v8 
@@ -1,16 +1,76 @@
+Creating an OpenERP session
+---
+Each of the examples uses an Session object from the OpenERP Java Api.
+
+    :::java
+    Session openERPSession = new Session("openerp1", 8069, "demo_database", "admin", "admin");
+    try {
+        openERPSession.startSession();
+        ////// 
+        ////// Example code snippet goes here
+        //////
+    } catch (Exception e) {
+        System.out.println("Error while reading data from server:\n\n" + e.getMessage());
+    }
+
+Search - Single filter
+---
+Searches for all active partners, regardless of type (Customer, Cupplier etc)
+
+    :::java
+    Object[] ids = openERPSession.searchObject("res.partner", new Object[][] {new Object[]{"active","=",true}});
+    for (Object id : ids)
+        System.out.println(id.toString());
+
+Search - Multi filter
+---
+Searches for all active customers
+
+    :::java
+    Object[] ids = openERPSession.searchObject("res.partner", new Object[][] {new Object[]{"customer","=",true}, new Object[]{"active","=",true}});
+    for (Object id : ids)
+        System.out.println(id.toString());
+
+    
 Read example
 ---
+The following snippet, reads the active customers and displays the name and email fields of those customers.
+
+    :::java
+    Object[] ids = openERPSession.searchObject("res.partner", new Object[][] {new Object[]{"customer","=",true}, new Object[]{"active","=",true}});
+    RowCollection rows = openERPSession.readObject("res.partner", ids, new String[] {"name","email"});
+    for(Row row : rows){
+        System.out.println("---------New Row------------");
+	System.out.println("Id :" + row.get("id"));
+	for (Field f : row.getFields()){
+	    Object value = row.get(f.getName());
+	    System.out.println(f.getName() + ":" + (value == null ? "Null" : value.toString()));
+	}
+    }
+
+The two calls to fetch the ID's and the
+
 The following code snippet reads the ir.model object and displays the 'model' and 'name' fields.
 
     :::java
-    public static void main(String[] args) {
-		Session openERPSession = new Session("openerp1", 8069, "demo_database", "admin", "admin");
-		try {
-			openERPSession.startSession();
-			RowCollection rows = openERPSession.searchAndReadObject("ir.model",null,new String[] {"model","name"});
-			for(Row row : rows)
-				System.out.println(row.get("model").toString() + " " + row.get("name").toString());
-		} catch (Exception e) {
-			System.out.println("Error while reading data from server:\n\n" + e.getMessage());
-		}
-	}
+    RowCollection rows = openERPSession.searchAndReadObject("ir.model",null,new String[] {"model","name"});
+    for(Row row : rows)
+        System.out.println(row.get("model").toString() + " " + row.get("name").toString());
+    
+ 
+
+Write example
+---
+In this code snippet, the customer ASUStek's email address is changed to testemail@gmail.com.
+
+    :::java
+    int ASUStekID = Integer.parseInt(openERPSession.searchObject("res.partner", new Object[][] {new Object[]{"name","=","ASUStek"}})[0].toString());
+    
+    // update field 'email' with value testemail@gmail.com 
+    HashMap&lt;String, Object&gt; valueList = new HashMap&lt;String, Object&gt;();
+    valueList.put("email", "testemail@gmail.com");
+			
+    boolean success = openERPSession.writeObject("res.partner", ASUStekID, valueList);
+			
+    if (success)
+        System.out.println("Update was successful");
&lt;/pre&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Pieter van der Merwe</dc:creator><pubDate>Thu, 08 Sep 2011 06:41:30 -0000</pubDate><guid>https://sourceforge.net4744fc2bca4a1ad2be1bff5854e1fbb66195674c</guid></item><item><title>WikiPage Examples modified by Pieter van der Merwe</title><link>https://sourceforge.net/p/openerpjavaapi/wiki/Examples/</link><description>&lt;pre&gt;--- v6 
+++ v7 
@@ -7,7 +7,7 @@
 		Session openERPSession = new Session("openerp1", 8069, "demo_database", "admin", "admin");
 		try {
 			openERPSession.startSession();
-			RowCollection rows = openERPSession.searchAndReadObject("ir.model",new Object[][]{},new String[] {"model","name"});
+			RowCollection rows = openERPSession.searchAndReadObject("ir.model",null,new String[] {"model","name"});
 			for(Row row : rows)
 				System.out.println(row.get("model").toString() + " " + row.get("name").toString());
 		} catch (Exception e) {
&lt;/pre&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Pieter van der Merwe</dc:creator><pubDate>Thu, 08 Sep 2011 05:33:46 -0000</pubDate><guid>https://sourceforge.net5225540ce2f69f6aff8cb12737b5442f925efa88</guid></item><item><title>WikiPage Examples modified by Pieter van der Merwe</title><link>https://sourceforge.net/p/openerpjavaapi/wiki/Examples/</link><description>&lt;pre&gt;--- v5 
+++ v6 
@@ -11,6 +11,6 @@
 			for(Row row : rows)
 				System.out.println(row.get("model").toString() + " " + row.get("name").toString());
 		} catch (Exception e) {
-			e.printStackTrace();
+			System.out.println("Error while reading data from server:\n\n" + e.getMessage());
 		}
 	}
&lt;/pre&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Pieter van der Merwe</dc:creator><pubDate>Tue, 30 Aug 2011 04:19:13 -0000</pubDate><guid>https://sourceforge.netab09fba0ff559e795704ec9a53b0a228eb1b85ac</guid></item><item><title>WikiPage Examples modified by Pieter van der Merwe</title><link>https://sourceforge.net/p/openerpjavaapi/wiki/Examples/</link><description>&lt;pre&gt;--- v4 
+++ v5 
@@ -2,7 +2,7 @@
 ---
 The following code snippet reads the ir.model object and displays the 'model' and 'name' fields.
 
-    #!/usr/bin/java
+    :::java
     public static void main(String[] args) {
 		Session openERPSession = new Session("openerp1", 8069, "demo_database", "admin", "admin");
 		try {
&lt;/pre&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Pieter van der Merwe</dc:creator><pubDate>Tue, 30 Aug 2011 04:16:30 -0000</pubDate><guid>https://sourceforge.net1086c8fe6b416ab7a1ba0a0bc653a3f2b202249f</guid></item><item><title>WikiPage Examples modified by Pieter van der Merwe</title><link>https://sourceforge.net/p/openerpjavaapi/wiki/Examples/</link><description>&lt;pre&gt;--- v3 
+++ v4 
@@ -1,3 +1,5 @@
+Read example
+---
 The following code snippet reads the ir.model object and displays the 'model' and 'name' fields.
 
     #!/usr/bin/java
&lt;/pre&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Pieter van der Merwe</dc:creator><pubDate>Tue, 30 Aug 2011 04:00:49 -0000</pubDate><guid>https://sourceforge.netaf7c05192c110159bb058a246f4240645971dbf1</guid></item><item><title>WikiPage Read data example modified by Pieter van der Merwe</title><link>https://sourceforge.net/p/openerpjavaapi/wiki/Read%2520data%2520example/</link><description>&lt;pre&gt;--- v2 
+++ v3 
@@ -1,4 +1,5 @@
 The following code snippet reads the ir.model object and displays the 'model' and 'name' fields.
+
     #!/usr/bin/java
     public static void main(String[] args) {
 		Session openERPSession = new Session("openerp1", 8069, "demo_database", "admin", "admin");
&lt;/pre&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Pieter van der Merwe</dc:creator><pubDate>Tue, 30 Aug 2011 03:59:42 -0000</pubDate><guid>https://sourceforge.net638ec1d9e743f0a9fa68e5c0feaa51d318839d86</guid></item><item><title>WikiPage Read data example modified by Pieter van der Merwe</title><link>https://sourceforge.net/p/openerpjavaapi/wiki/Read%2520data%2520example/</link><description>&lt;pre&gt;--- v1 
+++ v2 
@@ -1,5 +1,4 @@
 The following code snippet reads the ir.model object and displays the 'model' and 'name' fields.
-
     #!/usr/bin/java
     public static void main(String[] args) {
 		Session openERPSession = new Session("openerp1", 8069, "demo_database", "admin", "admin");
&lt;/pre&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Pieter van der Merwe</dc:creator><pubDate>Tue, 30 Aug 2011 03:59:23 -0000</pubDate><guid>https://sourceforge.net53c077980d4ba9a8146a1b11ec770d8ecb9d4d56</guid></item></channel></rss>