[seam-commits] Seam SVN: r11901 - in modules/remoting/trunk: examples/model/src/main/java/org/jboss/seam/remoting/examples/model and 5 other directories.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Sun Jan 3 07:03:46 EST 2010


Author: shane.bryzak at jboss.com
Date: 2010-01-03 07:03:45 -0500 (Sun, 03 Jan 2010)
New Revision: 11901

Removed:
   modules/remoting/trunk/examples/model/src/main/java/org/jboss/seam/remoting/examples/model/Customer.java
   modules/remoting/trunk/examples/model/src/main/java/org/jboss/seam/remoting/examples/model/CustomerAction.java
Modified:
   modules/remoting/trunk/examples/model/pom.xml
   modules/remoting/trunk/examples/model/src/main/resources/META-INF/persistence.xml
   modules/remoting/trunk/examples/model/src/main/resources/import.sql
   modules/remoting/trunk/examples/model/src/main/webapp/model.html
   modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/model/ModelHandler.java
   modules/remoting/trunk/src/main/resources/org/jboss/seam/remoting/remote.js
Log:
updated example to demonstrate lazy loading model expansion


Modified: modules/remoting/trunk/examples/model/pom.xml
===================================================================
--- modules/remoting/trunk/examples/model/pom.xml	2010-01-03 11:47:13 UTC (rev 11900)
+++ modules/remoting/trunk/examples/model/pom.xml	2010-01-03 12:03:45 UTC (rev 11901)
@@ -35,6 +35,12 @@
          <version>1.0</version>
          <scope>provided</scope>
       </dependency>
+      <dependency>
+      	<groupId>javax.transaction</groupId>
+      	<artifactId>jta</artifactId>
+      	<version>1.1</version>
+      	<scope>provided</scope>
+      </dependency>
    </dependencies>
    
    <build>

Deleted: modules/remoting/trunk/examples/model/src/main/java/org/jboss/seam/remoting/examples/model/Customer.java
===================================================================
--- modules/remoting/trunk/examples/model/src/main/java/org/jboss/seam/remoting/examples/model/Customer.java	2010-01-03 11:47:13 UTC (rev 11900)
+++ modules/remoting/trunk/examples/model/src/main/java/org/jboss/seam/remoting/examples/model/Customer.java	2010-01-03 12:03:45 UTC (rev 11901)
@@ -1,92 +0,0 @@
-package org.jboss.seam.remoting.examples.model;
-
-import java.io.Serializable;
-import java.util.Date;
-
-import javax.persistence.Entity;
-//import javax.persistence.EnumType;
-//import javax.persistence.Enumerated;
-import javax.persistence.GeneratedValue;
-import javax.persistence.Id;
-import javax.persistence.Table;
-import javax.persistence.Temporal;
-import javax.persistence.TemporalType;
-
-/**
- * Customer entity bean.  This class exposes a variety of property types for the
- * purpose of the example.
- *  
- * @author Shane Bryzak
- */
- at Entity
- at Table(name = "customer")
-public class Customer implements Serializable
-{
-   private static final long serialVersionUID = 4289723352398788625L;
-
-//   public static enum Gender { male, female }
-   
-   
-   private Integer customerId;
-   
-   private String firstName;
-   private String lastName;
-   
-   
-   private Date dateOfBirth;
-   
-   //@Enumerated(EnumType.STRING)
-   //private Gender gender;
-   
-   @Id @GeneratedValue
-   public Integer getCustomerId()
-   {
-      return customerId;
-   }
-   
-   public void setCustomerId(Integer customerId)
-   {
-      this.customerId = customerId;
-   }
-      
-   public String getFirstName()
-   {
-      return firstName;
-   }
-   
-   public void setFirstName(String firstName)
-   {
-      this.firstName = firstName;
-   }
-   
-   public String getLastName()
-   {
-      return lastName;
-   }
-   
-   public void setLastName(String lastName)
-   {
-      this.lastName = lastName;
-   }
-   
-   @Temporal(TemporalType.DATE)
-   public Date getDateOfBirth()
-   {
-      return dateOfBirth;
-   }
-   
-   public void setDateOfBirth(Date dateOfBirth)
-   {
-      this.dateOfBirth = dateOfBirth;
-   }
-   
-/*   public Gender getGender()
-   {
-      return gender;
-   }
-   
-   public void setGender(Gender gender)
-   {
-      this.gender = gender;
-   }*/
-}

Deleted: modules/remoting/trunk/examples/model/src/main/java/org/jboss/seam/remoting/examples/model/CustomerAction.java
===================================================================
--- modules/remoting/trunk/examples/model/src/main/java/org/jboss/seam/remoting/examples/model/CustomerAction.java	2010-01-03 11:47:13 UTC (rev 11900)
+++ modules/remoting/trunk/examples/model/src/main/java/org/jboss/seam/remoting/examples/model/CustomerAction.java	2010-01-03 12:03:45 UTC (rev 11901)
@@ -1,55 +0,0 @@
-package org.jboss.seam.remoting.examples.model;
-
-import java.io.Serializable;
-
-import javax.enterprise.context.Conversation;
-import javax.enterprise.context.ConversationScoped;
-import javax.inject.Inject;
-import javax.persistence.EntityManager;
-import javax.persistence.PersistenceContext;
-
-import org.jboss.seam.remoting.annotations.WebRemote;
-
- at ConversationScoped
-public class CustomerAction implements Serializable
-{
-   private static final long serialVersionUID = 8350706339578435242L;
-   
-   @PersistenceContext EntityManager entityManager;
-   @Inject Conversation conversation;
-   
-   private Customer customer;
-      
-   @WebRemote
-   public void createCustomer()
-   {
-      conversation.begin();
-      customer = new Customer();
-   }
-   
-   @WebRemote
-   public void editCustomer(Integer customerId)
-   {
-      conversation.begin();
-      customer = entityManager.find(Customer.class, customerId);
-   }
-   
-   @WebRemote
-   public void saveCustomer()
-   {
-      if (customer.getCustomerId() == null)
-      {
-         entityManager.persist(customer);
-      }
-      else
-      {
-         customer = entityManager.merge(customer);
-      }
-      conversation.end();
-   }
-   
-   public Customer getCustomer()
-   {
-      return customer;
-   }
-}

Modified: modules/remoting/trunk/examples/model/src/main/resources/META-INF/persistence.xml
===================================================================
--- modules/remoting/trunk/examples/model/src/main/resources/META-INF/persistence.xml	2010-01-03 11:47:13 UTC (rev 11900)
+++ modules/remoting/trunk/examples/model/src/main/resources/META-INF/persistence.xml	2010-01-03 12:03:45 UTC (rev 11901)
@@ -5,7 +5,8 @@
    version="1.0">
    <persistence-unit name="model">
       <jta-data-source>modelDatasource</jta-data-source>
-      <class>org.jboss.seam.remoting.examples.model.Customer</class>
+      <class>org.jboss.seam.remoting.examples.model.Person</class>
+      <class>org.jboss.seam.remoting.examples.model.Address</class>
       <properties>
          <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
          <property name="hibernate.show_sql" value="true"/>

Modified: modules/remoting/trunk/examples/model/src/main/resources/import.sql
===================================================================
--- modules/remoting/trunk/examples/model/src/main/resources/import.sql	2010-01-03 11:47:13 UTC (rev 11900)
+++ modules/remoting/trunk/examples/model/src/main/resources/import.sql	2010-01-03 12:03:45 UTC (rev 11901)
@@ -1,3 +1,3 @@
-insert into customer (customerid, firstname, lastname, dateofbirth) values (1, 'Shane', 'Bryzak', '1901-01-01');
-
-
+insert into person (personid, firstname, lastname, dateofbirth) values (1, 'Shane', 'Bryzak', '1901-01-01');
+insert into address (addressid, person_id, streetno, streetname, suburb, postcode, country) values (1, 1, 100, 'Main', 'Pleasantville', '32123', 'Australia');
+insert into address (addressid, person_id, streetno, streetname, suburb, postcode, country) values (2, 1, 57, '1st Avenue', 'Pittsville', '32411', 'Australia');
\ No newline at end of file

Modified: modules/remoting/trunk/examples/model/src/main/webapp/model.html
===================================================================
--- modules/remoting/trunk/examples/model/src/main/webapp/model.html	2010-01-03 11:47:13 UTC (rev 11900)
+++ modules/remoting/trunk/examples/model/src/main/webapp/model.html	2010-01-03 12:03:45 UTC (rev 11901)
@@ -19,40 +19,47 @@
     
     var model = null;
   
-    function loadCustomer() {
-      var customerId = document.getElementById("customerId").value;
+    function loadPerson() {
+      var personId = document.getElementById("personId").value;
       
       model = new Seam.Model();
 
-      var callback = function(model) { alert(model.getValue("customer").getFirstName()); };
+      var callback = function(model) { var p = model.getValue("person"); alert(p.getFirstName() + " " + p.getLastName()); };
               
-      model.addBeanProperty("customer", "org.jboss.seam.remoting.examples.model.CustomerAction", "customer");
+      model.addBeanProperty("person", "org.jboss.seam.remoting.examples.model.PersonAction", "person");
       model.fetch(new Seam.Action()
-        .setBeanType("org.jboss.seam.remoting.examples.model.CustomerAction")
-        .setMethod("editCustomer")
-        .addParam(customerId), callback);
+        .setBeanType("org.jboss.seam.remoting.examples.model.PersonAction")
+        .setMethod("editPerson")
+        .addParam(personId), callback);
     }
     
-    function modifyCustomer() {
-      model.getValue("customer").setFirstName("bob");
+    function expandModel() {
+      var callback = function(model) { alert("Got addresses: " + model.getValue("person").getAddresses().length); };
+      
+      model.expand(model.getValue("person"), "addresses", callback); 
     }
     
+    function modifyPerson() {
+      model.getValue("person").setFirstName("bob");
+    }
+    
     function applyUpdates() {
       var callback = function(model) { alert("updates applied"); };
       
       model.applyUpdates(new Seam.Action()
-        .setBeanType("org.jboss.seam.remoting.examples.model.CustomerAction")
-        .setMethod("saveCustomer"),
+        .setBeanType("org.jboss.seam.remoting.examples.model.PersonAction")
+        .setMethod("savePerson"),
         callback);
     }
 
     // ]]>
   </script> 
   
-  <label for="customerId">Customer ID</label><input type="text" id="customerId" value="1"/>
+  <label for="personId">Person ID</label><input type="text" id="personId" value="1"/>
   
-  <button onclick="javascript:loadCustomer()">Load customer</button> 
-  <button onclick="javascript:modifyCustomer()">Modify customer</button>
+  <button onclick="javascript:loadPerson()">Load person</button> 
+  <button onclick="javascript:expandModel()">expand model</button>
+  <button onclick="javascript:modifyPerson()">Modify person</button>
   <button onclick="javascript:applyUpdates()">Apply updates</button>
 
 

Modified: modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/model/ModelHandler.java
===================================================================
--- modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/model/ModelHandler.java	2010-01-03 11:47:13 UTC (rev 11900)
+++ modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/model/ModelHandler.java	2010-01-03 12:03:45 UTC (rev 11901)
@@ -339,7 +339,7 @@
          throw new IllegalStateException("Invalid request state - no object ref found");
       }
       
-      int refId = Integer.parseInt(refElement.attributeValue("refid"));
+      int refId = Integer.parseInt(refElement.attributeValue("id"));
       Wrapper target = model.getCallContext().getOutRefs().get(refId);
       
       int newRefIdx = model.getCallContext().getOutRefs().size();

Modified: modules/remoting/trunk/src/main/resources/org/jboss/seam/remoting/remote.js
===================================================================
--- modules/remoting/trunk/src/main/resources/org/jboss/seam/remoting/remote.js	2010-01-03 11:47:13 UTC (rev 11900)
+++ modules/remoting/trunk/src/main/resources/org/jboss/seam/remoting/remote.js	2010-01-03 12:03:45 UTC (rev 11901)
@@ -624,14 +624,16 @@
 
 Seam.validateRefs = function(refsNode) {
   var unknowns = [];
-  var cn = Seam.Xml.childNodes(refsNode, "ref");
-  for (var i=0; i<cn.length; i++) {
-    var n = cn[i].firstChild;
-    if (n.tagName == "bean") {
-      var name = n.getAttribute("type");
-      if (!Seam.isBeanRegistered(name)) unknowns.push(name);
-    } 
-  } 
+  if (refsNode) {
+    var cn = Seam.Xml.childNodes(refsNode, "ref");
+    for (var i=0; i<cn.length; i++) {
+      var n = cn[i].firstChild;
+      if (n.tagName == "bean") {
+        var name = n.getAttribute("type");
+        if (!Seam.isBeanRegistered(name)) unknowns.push(name);
+      }
+    }
+  }
   return unknowns;
 }
 



More information about the seam-commits mailing list