I'd like to use an owned List<entity> collection. I ran out of time this 
weekend to figure out how to use an Owned Collection in RequestFactory.

Has anybody else used an owned collection in the Entity with RequestFactory?

source 
location: 
http://code.google.com/p/gwt-examples/source/browse/trunk/WalletInventory/src/com/gonevertical/server/jdo/WalletData.java

@PersistenceCapable
@Version(strategy = VersionStrategy.VERSION_NUMBER, extensions = { 
@Extension(vendorName = "datanucleus", key = "key", value = "version") })
public class WalletData {

@PrimaryKey
  @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
  private Key key;
  
  @Persistent
  private Integer version;
 
  /**
   * entity owner - the person who's logged in
   */
  @Persistent
  private Long userId; 
  
  @Persistent
  private String name;
  
  @Persistent(defaultFetchGroup = "true", dependentElement = "true")  
  private List<WalletItemData> items;
 
  
  public void setId(Long id) {
    if (id == null) {
      return;
    }
    this.key = KeyFactory.createKey(UserData.class.getName(), id);
  }
  public Long getId() {
    Long id = null;
    if (key != null) {
      id = key.getId();
    }
    return id;
  }
  
  public void setVersion(Integer version) {
    this.version = version;
  }
  public Integer getVersion() {
    return version;
  }
  
  public void setUserId(Long userId) {
    this.userId = userId;
  }
  public Long getUserId() {
    return userId;
  }
  
  public void setName(String name) {
    this.name = name;
  }
  public String getName() {
    return name;
  }
  
  public void setItems(List<WalletItemData> items) {
    if (items == null) {
      this.items = null;
      return;
    }
    
    // TODO I'm not sure request factory will do this or not yet.
    ArrayList<WalletItemData> a = new ArrayList<WalletItemData>();
    Iterator<WalletItemData> itr = items.iterator();
    while(itr.hasNext()) {
      WalletItemData d = itr.next();
      if (d.getId() != null && d.getId() > 0) { // null on id to increment
        // need parentKey, to reference the owned entities
        d.setId(key, d.getId());
      }
      a.add(d);
    }
    
    this.items = a;
  }
  public List<WalletItemData> getItems() {
    return items;
  }

}



Thanks
Brandon Donnelson
http://gwt-examples.googlecode.com



-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/google-web-toolkit/-/AKT55OlUMMUJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.

Reply via email to