@Model(schemaVersion = 1)
@Attribute(primaryKey = true)エンティティの識別に用いられる、いわゆるプライマリキーとなる項目です。Slim3のモデルでは、キーにはcom.google.appengine.api.datastoreパッケージのKeyクラスが自動設定されます。これはGAEのデータストアで用いられる標準的なキーです。データストア自体は、Keyだけでなく、例えばID番号を示す整数値などをキーにしたりできますが、Slim3ではKeyが基本だと考えてください。勝手にlong値などにキーを変更したりしないようにしましょう。
private Key key;
@Attribute(version = true)オブジェクトのバージョン情報を示すプロパティです。これも@Attribute(version = true)というSlim3に用意されているアノテーションが自動的に付けられます。
private Long version;
※リストが表示されない場合
AddBlockなどの広告ブロックツールがONになっているとリストなどが表示されない場合があります。これらのツールをOFFにしてみてください。
※MyData.java
package com.tuyano.libro.myslim3app.model;
import java.io.Serializable;
import com.google.appengine.api.datastore.Key;
import org.slim3.datastore.Attribute;
import org.slim3.datastore.Model;
@Model(schemaVersion = 1)
public class MyData implements Serializable {
private static final long serialVersionUID = 1L;
@Attribute(primaryKey = true)
private Key key;
@Attribute(version = true)
private Long version;
public Key getKey() {
return key;
}
public void setKey(Key key) {
this.key = key;
}
public Long getVersion() {
return version;
}
public void setVersion(Long version) {
this.version = version;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((key == null) ? 0 : key.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
MyData other = (MyData) obj;
if (key == null) {
if (other.key != null) {
return false;
}
} else if (!key.equals(other.key)) {
return false;
}
return true;
}
}
| << 前へ | 次へ >> |