-
Notifications
You must be signed in to change notification settings - Fork 10
Immutable Objects
Siim Kinks edited this page Mar 21, 2017
·
3 revisions
SqliteMagic has built-in support for AutoValue immutable objects. AutoValue objects are treated the same way as POJOs with the key difference where annotations must be added to methods instead of fields.
| AutoValue | Result in SQL |
|---|---|
@Table(persistAll = true)
@AutoValue
public abstract class Author {
@Id(autoIncrement = false)
public abstract long id();
public abstract String firstName();
public abstract String lastName();
...
}
@Table(persistAll = true)
@AutoValue
public abstract class Book {
@Id(autoIncrement = false)
public abstract long id();
public abstract String title();
public abstract Author author();
...
} |
CREATE TABLE IF NOT EXISTS author (
id INTEGER PRIMARY KEY,
first_name TEXT,
last_name TEXT
);
CREATE TABLE IF NOT EXISTS book (
id INTEGER PRIMARY KEY,
title TEXT,
author INTEGER
);
|
Every AutoValue object must have one long or Long type returning method with @Id annotation which represents the primary key .
For more detailed information about AutoValue and its usage see AutoValue Github repository.