Hi Randell,

I'm guessing this is an App Engine project, in which case your server-side
questions will likely get more response on the App Engine forum:

http://groups.google.com/group/google-appengine/topics

HTH,
/dmc

On Thu, May 26, 2011 at 11:09 AM, Randell Schneider <
randellschnei...@gmail.com> wrote:

> Hi There,
>
> I'm Starting a Web Project with GWT  and some problems about datastore
> delete by ID.
>
> do not know why having this problem. I think it should be the primary
> key generation.
>
> OBS: getters and setters were not placed in this post
>
> Class GRUPO:
>
>    import javax.jdo.PersistenceManager;
>    import javax.jdo.annotations.Extension;
>    import javax.jdo.annotations.IdGeneratorStrategy;
>    import javax.jdo.annotations.IdentityType;
>    import javax.jdo.annotations.PersistenceCapable;
>    import javax.jdo.annotations.Persistent;
>    import javax.jdo.annotations.PrimaryKey;
>    import javax.jdo.listener.StoreCallback;
>
>    import com.metadot.book.connectr.shared.GrupoDTO;
>
>    @PersistenceCapable(identityType = IdentityType.APPLICATION,
> detachable = "true")
>    public class Grupo implements StoreCallback {
>
>         @PrimaryKey
>         @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
>         @Extension(vendorName = "datanucleus", key = "gae.encoded-
> pk", value = "true")
>         private String id;
>
>         @Persistent
>         private String GrupoNome;
>
>
>         @SuppressWarnings("unused")
>         @Persistent
>         private UserAccount userAccount;
>
>         public Grupo() {
>            }
>
>         public Grupo(GrupoDTO grupoDTO) {
>            this();
>            this.setBasicInfo(grupoDTO.getGrupoNome());
>         }
>    }
>
>
>
> Class GrupoList.java:
>
>    import com.google.gwt.core.client.GWT;
>    import com.google.gwt.uibinder.client.UiBinder;
>    import com.google.gwt.uibinder.client.UiField;
>    import com.google.gwt.user.client.Window;
>    import com.google.gwt.user.client.rpc.AsyncCallback;
>    import com.google.gwt.user.client.ui.Composite;
>    import com.google.gwt.user.client.ui.VerticalPanel;
>    import com.google.gwt.user.client.ui.Widget;
>    import com.metadot.book.connectr.shared.GrupoDTO;
>
>    public class GrupoList extends Composite {
>
>      private static GrupoListUiBinder uiBinder = GWT
>          .create(GrupoListUiBinder.class);
>
>      interface GrupoListUiBinder extends UiBinder<Widget, GrupoList>
> {
>      }
>
>      @UiField
>      VerticalPanel gruposPanel;
>
>      private List<GrupoDTO> grupoDTOs;
>
>      private final static GrupoServiceAsync grupoService = GWT
>      .create(GrupoService.class);
>
>      public GrupoList() {
>        initWidget(uiBinder.createAndBindUi(this));
>      }
>
>      public GrupoList(List<GrupoDTO> grupoDTOs) {
>        this();
>        this.grupoDTOs = grupoDTOs;
>        displayGrupos();
>      }
>
>      public void showGrupos() {
>           grupoService
>               .getGrupos(new AsyncCallback<List<GrupoDTO>>() {
>                 public void onFailure(Throwable caught) {
>                   Window.alert("An error occurred");
>                 }
>
>                 public void onSuccess(List<GrupoDTO> result) {
>                    grupoDTOs = result;
>                    displayGrupos();
>                 }
>               });
>         }
>
>      private void displayGrupos() {
>        for (final GrupoDTO grupo: grupoDTOs) {
>          gruposPanel.add(new GrupoItem(grupo));
>        }
>      }
>
>    }
>
>
>
>  Class GrupoItem.java:
>
>    import com.google.gwt.core.client.GWT;
>    import com.google.gwt.event.dom.client.ClickEvent;
>    import com.google.gwt.uibinder.client.UiBinder;
>    import com.google.gwt.uibinder.client.UiField;
>    import com.google.gwt.uibinder.client.UiHandler;
>    import com.google.gwt.user.client.Window;
>    import com.google.gwt.user.client.rpc.AsyncCallback;
>    import com.google.gwt.user.client.ui.Button;
>    import com.google.gwt.user.client.ui.Composite;
>    import com.google.gwt.user.client.ui.Label;
>    import com.google.gwt.user.client.ui.Widget;
>    import com.metadot.book.connectr.shared.GrupoDTO;
>
>    public class GrupoItem extends Composite {
>
>      private static GrupoItemUiBinder uiBinder = GWT
>          .create(GrupoItemUiBinder.class);
>
>      interface GrupoItemUiBinder extends UiBinder<Widget, GrupoItem>
> {
>      }
>
>      @UiField
>      Label title;
>      @UiField
>      Button delete, edit;
>
>      GrupoDTO grupo;
>
>      private final static GrupoServiceAsync grupoService = GWT
>      .create(GrupoService.class);
>
>      public GrupoItem() {
>        initWidget(uiBinder.createAndBindUi(this));
>      }
>
>      public GrupoItem(String title, String id) {
>        this();
>        this.title.setText(title);
>      }
>
>      public GrupoItem(GrupoDTO grupoDTO) {
>           this();
>           this.grupo = grupoDTO;
>           this.title.setText(grupo.getGrupoNome());
>      }
>
>      public GrupoItem(String title) {
>           this();
>           this.title.setText(title);
>         }
>
>      private static void deleteGrupo(GrupoDTO grupo) {
>          grupoService.deleteGrupo(grupo.getId(),
>              new AsyncCallback<Boolean>() {
>                public void onFailure(Throwable caught) {
>                  Window.alert("An error occurred");
>                }
>
>                public void onSuccess(Boolean result) {
>                  ConnectrApp.get().cancelEditFriend();
>                }
>              });
>
>        }
>
>      @UiHandler("delete")
>      void onDeleteClick(ClickEvent e) {
>        if (Window.confirm("Deseja mesmo cancelar?")) {
>          deleteGrupo(grupo);
>        }
>      }
>
>      @UiHandler("edit")
>      void onEditClick(ClickEvent e) {
>        // handle click
>        ConnectrApp.get().showEditGrupo(grupo.getId());
>      }
>
>    }
>
>
>
> at last the class GrupoServiceImpl.Java:
>
>    import java.util.ArrayList;
>    import java.util.List;
>    import java.util.Set;
>
>    import javax.jdo.PersistenceManager;
>
>    import com.google.gwt.user.server.rpc.RemoteServiceServlet;
>    import com.metadot.book.connectr.client.GrupoService;
>    import com.metadot.book.connectr.server.domain.Grupo;
>    import com.metadot.book.connectr.server.domain.UserAccount;
>    import com.metadot.book.connectr.shared.GrupoDTO;
>
>    @SuppressWarnings("serial")
>    public class GrupoServiceImpl extends RemoteServiceServlet
> implements GrupoService{
>
>       public GrupoServiceImpl() {
>           AppMisc.populateDataStoreOnce();
>         }
>
>         public GrupoDTO updateGrupo(GrupoDTO grupoDTO) {
>           if (grupoDTO.getId() == null){
>              Grupo newGrupo = addGrupo(grupoDTO);
>             return newGrupo.toDTO();
>           }
>
>           PersistenceManager pm =
> PMF.get().getPersistenceManager();
>           Grupo grupo = null;
>           try {
>             grupo = pm.getObjectById(Grupo.class,
> grupoDTO.getId());
>             grupo.updateFromDTO(grupoDTO);
>           } catch (Exception e) {
>             e.printStackTrace();
>           } finally {
>             pm.close();
>           }
>           return grupoDTO;
>         }
>
>
>              //AQUI E O DELETE
>         public Boolean deleteGrupo(String id) {
>           PersistenceManager pm =
> PMF.get().getPersistenceManager();
>           try {
>             Grupo grupo = pm.getObjectById(Grupo.class, id);
>             if (grupo != null) {
>               pm.deletePersistent(pm.getObjectById(Grupo.class,
> id));
>             }
>           } finally {
>             pm.close();
>           }
>           return true;
>         }
>
>         // criando novo Grupo object no Datastore
>         private Grupo addGrupo(GrupoDTO grupoDTO) {
>
>           PersistenceManager pm =
> PMF.get().getPersistenceManager();
>           Grupo grupo = null;
>           try {
>             //usando um user default
>             UserAccount currentUser =
> UserAccount.getDefaultUser(); // detached object
>             currentUser = pm.makePersistent(currentUser); // attach
>             grupo = new Grupo(grupoDTO);
>             currentUser.getGrupos().add(grupo);
>           } finally {
>             pm.close();
>           }
>           return grupo;
>         }
>
>
>         public List<GrupoDTO> getGrupos() {
>
>           List<GrupoDTO> listaGrupos = new ArrayList<GrupoDTO>();
>           PersistenceManager pm =
> PMF.get().getPersistenceManager();
>
>           try {
>             UserAccount user = UserAccount.getDefaultUser(pm);
>             Set<Grupo> grupos = user.getGrupos();
>             for (Grupo grupo : grupos) {
>               listaGrupos.add(grupo.getGrupoNomeObj());
>             }
>           } finally {
>             pm.close();
>           }
>
>           return listaGrupos;
>         }
>    }
>
> I do not know if I let go of some information. let me know anything
> I'll post here
>
> Grateful now!
>
> --
> You received this message because you are subscribed to the Google Groups
> "Google Web Toolkit" group.
> To post to this group, send email to google-web-toolkit@googlegroups.com.
> To unsubscribe from this group, send email to
> google-web-toolkit+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/google-web-toolkit?hl=en.
>
>


-- 
David Chandler
Developer Programs Engineer, Google Web Toolkit
w: http://code.google.com/
b: http://googlewebtoolkit.blogspot.com/
t: @googledevtools

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.

Reply via email to