Setting TTL values

You can set the table level TTL (Time To Live) 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:

Create the Student entity class and set the TTL values to 10 days as follows. 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 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 +
            '}';  
    }
}