Skip to content

Generate schemas

xcesco edited this page May 2, 2018 · 1 revision

Especially when an application upgrade need to upgrade its data source schema version, it can useful to obtain schema definition generated by Kripton for a specific data-source. It can be done simply setting to true the attribute schema of @BindDataSource used to define SQLite database.

Given a data-source named SchoolDataSource so defined (DAOs definition is omitted for simplicity):

public class Entity {
  public long id;
  public String name;
}

@BindType
public class Person extends Entity {
  public String surname;
  public String email;
}

@BindType
@BindTable(indexes=@BindIndex({"surname"}))
public class Professor extends Entity {
  public Date birthDate;
  
  @BindColumn(nullable=false)
  public String surname;
}

@BindType
public class Seminar extends Entity  {
  public String location;
}

@BindDataSource(
  fileName = "school", 
  version = 2, 
  daoSet = {
     DaoProfessor.class, DaoSeminar.class,DaoSeminar2Student.class, DaoStudent.class },
  schema=true)
public interface SchoolDataSource {

}

With schema=true will generate in <project-root-directory>/schemas folder a file like this:

/*
 * school.schema.2.sql

 * This class is generated by Kripton Annotation Processor (2.0.0)</strong></p>
 * 
 * since Thu Aug 03 17:41:02 CEST 2017
 */
CREATE TABLE seminar (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, location TEXT);
CREATE TABLE student (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, location TEXT);
CREATE TABLE seminar_2_student (id INTEGER PRIMARY KEY AUTOINCREMENT, student_id INTEGER, seminar_id INTEGER, FOREIGN KEY(student_id) REFERENCES student(id), FOREIGN KEY(seminar_id) REFERENCES seminar(id)); CREATE UNIQUE INDEX idx_seminar_2_student_0 on seminar_2_student (student_id asc, seminar_id desc);
CREATE TABLE professor (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, birth_date TEXT, surname TEXT NOT NULL); CREATE INDEX idx_professor_0 on professor (surname);

The schema can be useful to test migration plan from a version to another.

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