0

こんにちは、GWT フレームワークの初心者です。rpc を使用して、ドメイン オブジェクト/エンティティを Google アプリケーション エンジン データストアに保持したいと考えています。複数の rpc 呼び出しを行うことができるかどうかをテストするための簡単な実装 ( greetingServer() 、 saveStudent() )

学生

import javax.jdo.annotations.Extension;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.google.gwt.user.client.rpc.IsSerializable;

@PersistenceCapable
public class Student implements IsSerializable  {

private static final long serialVersionUID = 1L;

 @PrimaryKey
 @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
 @Extension(vendorName = "datanucleus", key = "gae.encoded-pk", value = "true")
 private int studentId;

 @Persistent private String firstName;
 @Persistent private String lastName;

public Student(){}

 public Student(String firstName, String lastName){
  this.firstName = firstName;
  this.lastName  = lastName;
 }

 public void setStudentId(int studentId) {
  this.studentId = studentId;
 }

 public int getStudentId() {
  return studentId;
 }

 public void setFirstName(String firstName) {
  this.firstName = firstName;
 }

 public String getFirstName() {
  return firstName;
 }

 public void setLastName(String lastName) {
  this.lastName = lastName;
 }

 public String getLastName() {
  return lastName;
 }
}

GreetingService (Eclipse IDE によって生成されるデフォルト コード)

import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;

@RemoteServiceRelativePath("greet")
public interface GreetingService extends RemoteService {
 String greetServer(String name) throws IllegalArgumentException;
 **String saveStudent(Student s) throws IllegalArgumentException;**
}

GreetingServiceAsync

import com.google.gwt.user.client.rpc.AsyncCallback;


public interface GreetingServiceAsync {
 void greetServer(String input, AsyncCallback<String> callback)
   throws IllegalArgumentException;
 **void saveStudent(Student s, AsyncCallback<String> callback)
   throws IllegalArgumentException;**
}

GreetingServiceImpl

import javax.jdo.PersistenceManager;

import com.d.client.GreetingService;
import com.d.client.Student;
import com.d.shared.FieldVerifier;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;

@SuppressWarnings("serial")
public class GreetingServiceImpl extends RemoteServiceServlet implements
  GreetingService {

 public String greetServer(String input) throws IllegalArgumentException 

  ...

  String serverInfo = getServletContext().getServerInfo();
  String userAgent = getThreadLocalRequest().getHeader("User-Agent");

  ...

 }


 @Override
 public String saveStudent(Student s) throws IllegalArgumentException {
  PersistenceManager pm = PMF.get().getPersistenceManager();
  pm.makePersistent(s);
  return "student save - ok";
  }

 }

PMF

import javax.jdo.JDOHelper;
import javax.jdo.PersistenceManagerFactory;

public final class PMF {
    private static final PersistenceManagerFactory pmfInstance = JDOHelper
            .getPersistenceManagerFactory("transactions-optional");

    private PMF() {
    }

    public static PersistenceManagerFactory get() {
        return pmfInstance;
    }
}

エントリーポイント

...

private final GreetingServiceAsync greetingService = GWT
    .create(GreetingService.class);

    greetingService.greetServer("greet",
      new AsyncCallback<String>() {
       public void onFailure(Throwable caught) {
        // Show the RPC error message to the user
       }

       public void onSuccess(String result) {
        //Show success message
       }
      });

    greetingService.saveStudent(new Student("kostas","trichas"),
      new AsyncCallback<String>() {
       public void onFailure(Throwable caught) {
        // Show the RPC error message to the user    
       }

       public void onSuccess(String result) {
        //Show success message
       }
      });

   ...

上記の実装は正しいですか?このサンプル アプリケーションを gae にデプロイしましたが、オブジェクト Student が保持されませんでした( gae データストア ビューアーでエンティティを参照できます)。

チェックしてください:

http://gwtgaedatastore.appspot.com

4

2 に答える 2

1

int studentID を Long id に変更して機能させます

于 2010-12-15T17:16:47.007 に答える
0

これは元のコード (つまり、Long id) で機能します。

@Extension (vendorName="jpox", key="key-auto-increment" ,value="true")

または、id を String に変更すると、元のコードが機能します。

gae.pk-id を使用して、Long PK を datanucleus で動作させることができませんでした。

于 2012-01-08T00:50:32.330 に答える