Google App Engine - JAVA - 資料類別繼承


基礎類別: class1
package mypackage;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.Inheritance;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

@PersistenceCapable(identityType = IdentityType.APPLICATION)
@Inheritance(customStrategy = "complete-table") //重要的一行
public class class1{
  @PrimaryKey
  @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
  public Long id;

  @Persistent
  protected String name;

  public class1(String name) {
    SetName(name);
  }

  public void SetName(String s){
    this.name=s;
  }

  public String GetName(){
    return this.name;
  }
}

繼承類別 class2
package mypackage;

import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;

import javax.jdo.annotations.Persistent;
@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class class2 extends class1{
  @Persistent
  public String address;

  public class2(String name, String address) {
    super(name);
    this.address=address;
  }
}

留言

熱門文章