Skip to content

Data Types Examples

xamry edited this page Mar 26, 2013 · 1 revision

This examples illustrates working with all data types supported by Kundera. It uses cassandra as persistence store.

Data Types supported:

data-types-supported

Entity Class:

@Entity
@Table(name = "STUDENT", schema = "KunderaExamples@cassandraPU")
public class Student {
	// Primitive Types
	@Id
	@Column(name = "STUDENT_ID")
	private long studentId;

	@Column(name = "UNIQUE_ID")
	private long uniqueId;

	@Column(name = "STUDENT_NAME")
	private String studentName;

	@Column(name = "IS_EXCEPTIONAL")
	private boolean isExceptional;

	@Column(name = "AGE")
	private int age;

	@Column(name = "SEMESTER")
	private char semester; // A,B,C,D,E,F for i to vi

	@Column(name = "DIGITAL_SIGNATURE")
	private byte digitalSignature;

	@Column(name = "CGPA")
	private short cgpa; // 1-10

	@Column(name = "PERCENTAGE")
	private float percentage;

	@Column(name = "HEIGHT")
	private double height;

	// Date-time types
	@Column(name = "ENROLMENT_DATE")
	@Temporal(TemporalType.DATE)
	private java.util.Date enrolmentDate;

	@Column(name = "ENROLMENT_TIME")
	@Temporal(TemporalType.TIME)
	private java.util.Date enrolmentTime;

	@Column(name = "JOINING_DATE_TIME")
	@Temporal(TemporalType.TIMESTAMP)
	private java.util.Date joiningDateAndTime;

	// Wrapper types
	@Column(name = "YEARS_SPENT")
	private Integer yearsSpent;

	@Column(name = "ROLL_NUMBER")
	private Long rollNumber;

	@Column(name = "MONTHLY_FEE")
	private Double monthlyFee;

	@Column(name = "SQL_DATE")
	private java.sql.Date sqlDate;

	@Column(name = "SQL_TIMESTAMP")
	private java.sql.Timestamp sqlTimestamp;

	@Column(name = "SQL_TIME")
	private java.sql.Time sqlTime;

	@Column(name = "BIG_INT")
	private BigInteger bigInteger;

	@Column(name = "BIG_DECIMAL")
	private BigDecimal bigDecimal;

	@Column(name = "CALENDAR")
	private Calendar calendar;

        //Constructors and getters/ setters here
}

DDL Script for Cassandra:

create column family STUDENT 
   with comparator=AsciiType and key_validation_class=LongType 
     and column_metadata=[
        {column_name: STUDENT_NAME, validation_class:UTF8Type, index_type: KEYS},
        {column_name: AGE, validation_class:IntegerType, index_type: KEYS},
        {column_name: UNIQUE_ID, validation_class:IntegerType, index_type: KEYS},
        {column_name: IS_EXCEPTIONAL, validation_class:IntegerType, index_type: KEYS},
        {column_name: SEMESTER, validation_class:IntegerType, index_type: KEYS},
        {column_name: DIGITAL_SIGNATURE, validation_class:IntegerType, index_type: KEYS},
        {column_name: CGPA, validation_class:IntegerType, index_type: KEYS},
        {column_name: PERCENTAGE, validation_class:IntegerType, index_type: KEYS},
        {column_name: HEIGHT, validation_class:IntegerType, index_type: KEYS},
        {column_name: ENROLMENT_DATE, validation_class:IntegerType, index_type: KEYS},
        {column_name: ENROLMENT_TIME, validation_class:IntegerType, index_type: KEYS},
        {column_name: JOINING_DATE_TIME, validation_class:IntegerType, index_type: KEYS},
        {column_name: YEARS_SPENT, validation_class:IntegerType, index_type: KEYS},
        {column_name: ROLL_NUMBER, validation_class:IntegerType, index_type: KEYS},
        {column_name: MONTHLY_FEE, validation_class:IntegerType, index_type: KEYS},
        {column_name: SQL_DATE, validation_class:IntegerType, index_type: KEYS},
        {column_name: SQL_TIMESTAMP, validation_class:IntegerType, index_type: KEYS},
        {column_name: SQL_TIME, validation_class:IntegerType, index_type: KEYS},
        {column_name: BIG_INT, validation_class:IntegerType, index_type: KEYS},
        {column_name: BIG_DECIMAL, validation_class:IntegerType, index_type: KEYS},
        {column_name: CALENDAR, validation_class:UTF8Type, index_type: KEYS}
    ];
Clone this wiki locally