Eclipse plugin - Generate SQLite model for Android based on JSON schema file
Update site: http://romkuapps.com/Apps/SQLite/update
- Schema has
name
and tables table
hasname
,description
and columnscolumn
hasname
andcolumnType
columnType
can beTEXT
orINTEGER
only
Example:
Two tables: STUDENT
and COURSE
{
"name": "SQL_PRIVATE_DB",
"tables": [
{
"name": "STUDENT",
"description": "Student details",
"columns": [
{
"name": "FIRSTNAME",
"columnType": "TEXT"
},
{
"name": "LASTNAME",
"columnType": "TEXT"
},
{
"name": "AGE",
"columnType": "INTEGER"
}
]
},
{
"name": "COURSE",
"description": "Course details",
"columns": [
{
"name": "NAME",
"columnType": "TEXT"
},
{
"name": "COURSENUMBER",
"columnType": "INTEGER"
},
{
"name": "DESCRIPTION",
"columnType": "TEXT"
},
{
"name": "POINTS",
"columnType": "INTEGER"
}
]
}
]
}
Each table is converted to Java entity and is generated under 'entities' package
| - entities
Each entity can be creates, updated, deleted or retrieved from the database. The support for CRUD actions is located under 'actions' package
| - actions
| - create
| - delete
| - read
| - update
The entry point for all operations above SQLite database are done via Model.java class, which is located under 'model' package
| - model
For each defined table in the JSON file you can create a new entity which will be saved in the SQLite table
Student student = new Student();
student.setFirstname("John");
student.setLastname("Smith");
student.setAge(30);
Model model = Model.getInstance(context);
model.createStudent(student);
For each defined table in the JSON file you can retrieve all entities from that SQLite table
Model model = Model.getInstance(context);
List<Student> students = model.readStudent();
For each defined table in the JSON file you can update existing entity from the SQLite table
student.setAge(31);
Model model = Model.getInstance(context);
model.updateStudent(student);
For each defined table in the JSON file you can delete existing entity from the SQLite table
Model model = Model.getInstance(context);
model.deleteStudent(student);
- The first time the singleton instance of the model is created
Model model = Model.getInstance(context)
, all the SQLite database content is loaded into the memory. - Each of CRUD commands works directly with the cached data and SQLite database. For example,
model.update...(Object object)
will update the entity in the memory and then update the raw in the database. Thus, the database is always synced.