Setting TTL values

Learn to set table level Time To Live (TTL) from Oracle NoSQL Database SDK for Spring Data.

You can set the table level TTL by setting the following parameters in the @NosqlTable annotation of an entity class:
  • ttl(): Sets the table level TTL value in either DAYS or HOURS. If not specified, the default value is set to 0, which means the TTL value is not set.
  • ttlUnit(): Sets the TTL unit to either DAYS or HOURS. If not specified, the default value is set to DAYS.

Example 2-2 Setting table level TTL value using Spring Data Framework

The following example shows how to create the Student entity class and set the TTL value to 10 days.

When the ttl() value is provided in the @NosqlTable annotation, the Spring Data driver creates the Student table with the specified TTL value.
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 +
            '}';  
    }
}