Skip to content

Immutable and mutable Pojo

xcesco edited this page May 23, 2019 · 3 revisions

Kripton can works both with Immutable POJO and Mutable POJO. Immutable objects have only readonly properties and a constructor that allows to define all properties. Mutable objects have read/write properties and a empty constructor.

You can work with both type of classes in Java and in Kotlin language.

Kotlin example As example of an immutable object writter in Kotlin, we can write:

@BindSqlType(name = "articles")
data class Article(
  @BindSqlColumn(columnType = ColumnType.PRIMARY_KEY)
  val id: Long,

  val title: String? = "test",
  val description: String?,
  val link: URL?,
  val author: String?,

  @BindSqlColumn(nullable = false, columnType = ColumnType.UNIQUE)
  val guid: String?,

  @BindSqlColumn(parentEntity = Channel::class)
  val channelId: Long,

  @Bind("thumbnail")
  @BindXml(namespace = "media")
  val thumbnail: Thumbnail?,

  val read: Boolean)

And a Java example:

@BindType
public class Person {

  @BindSqlColumn("birth")
  @BindAdapter(adapter = DateAdapter.class)
  private Date birthDate;
 
  private long id;

  private String name;

  private String surname;

  /**
   * Constructor
   */
  public Person(long id, String name, String surname, Date birthDate) {
    super();
    this.id = id;
    this.name = name;
    this.surname = surname;
    this.birthDate = birthDate;
  }

  public Date getBirthDate() {
    return birthDate;
  }

  public long getId() {
    return id;
  }

  public String getName() {
    return name;
  }

  public String getSurname() {
    return surname;
  }

}

You can use an immutable object in ORM and data format conversion. The mutable object (the typical POJO) can be used everywhere.

Table of Contents

Query definition

Features

Relations

Multithread supports

Modularization

Annotations for data convertion

Annotations for SQLite ORM

Annotations for shared preferences

Clone this wiki locally