TTL値の設定

Oracle NoSQL Database SDK for Spring Dataから表レベルのTime To Live (TTL)を設定する方法について学習します。

表レベルのTTLを設定するには、エンティティ・クラスの@NosqlTable注釈に次のパラメータを設定します。
  • ttl(): 表レベルのTTL値をDAYSまたはHOURSに設定します。指定しない場合、デフォルト値は0 (TTL値が設定されない)に設定されます。
  • ttlUnit(): TTL単位をDAYSまたはHOURSに設定します。指定しない場合、デフォルト値はDAYSに設定されます。

例2-2 Spring Data Frameworkを使用した表レベルのTTL値の設定

次の例は、Studentエンティティ・クラスを作成し、TTL値を10日に設定する方法を示しています。

@NosqlTable注釈にttl()値が指定されている場合、Spring Dataドライバは、指定された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 autogenerated 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 +
            '}';  
    }
}