TTL値の設定
表レベルのTTL (Time To Live)を設定するには、エンティティ・クラスの
@NosqlTable注釈に次のパラメータを設定します。
ttl(): 表レベルのTTL値をDAYSまたはHOURSに設定します。指定しない場合、デフォルト値は0 (TTL値が設定されない)に設定されます。ttlUnit(): TTL単位をDAYSまたはHOURSに設定します。指定しない場合、デフォルト値はDAYSに設定されます。
例:
Studentエンティティ・クラスを作成し、次のようにTTL値を10日間に設定します。@NosqlTable注釈にttl()値が指定されている場合、Springデータ・ドライバは、指定されたTTL値を使用してStudent表を作成します。import com.oracle.nosql.spring.data.core.mapping.NosqlId;
import com.oracle.nosql.spring.data.core.mapping.NosqlTable;
/* The @NosqlTable annotation specifies that this class will be mapped to an Oracle NoSQL Database table. */
/* Sets the table level TTL to 10 Days. */
@NosqlTable(ttl = 10, ttlUnit = NosqlTable.TtlUnit.DAYS)
public class Student {
/* The @NosqlId annotation specifies that this field will act as the ID field.
The generated=true attribute specifies that this ID will be auto-generated by a sequence. */
@NosqlId(generated = true)
long id;
String firstName;
String lastName;
/* public or package protected constructor required when retrieving from database. */
public Student() {
}
/* This method overrides the toString() method, and then concatenates id, firstname, lastname,
and then returns a String. */
@Override
public String toString() {
return "Student{" +
"id=" + id + ", " +
"firstName=" + firstName + ", " +
"lastName=" + lastName +
'}';
}
}