Java 开发 2.0: 使用 Google App Engine
2009-09-09 00:00:00 来源:WEB开发网清单 3. 为 triathlon JDO 添加一个主键
import java.util.Date;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;
import javax.jdo.annotations.IdentityType;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ReflectionToStringBuilder;
@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class Triathlon {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Long id;
@Persistent
private Date date;
@Persistent
private String name;
@Persistent
private String description;
public Triathlon(Date date, String name, String description) {
super();
this.date = date;
this.name = name;
this.description = description;
}
//...setters and getters left out
public String toString() {
return ReflectionToStringBuilder.toString(this);
}
public int hashCode() {
return HashCodeBuilder.reflectionHashCode(this);
}
public boolean equals(Object obj) {
return EqualsBuilder.reflectionEquals(this, obj);
}
}
更多精彩
赞助商链接