Based on the encapsulation of the native SDK operating SQLite in Android, the interactive operation between entity objects and local database is greatly simplified and the efficiency of App development is improved

TigerDB is a simple Android ORM framework, which allows you to add, delete, change, and query databases in a single line. It also supports persistent and automatic mapping of entity objects. At the same time, you don’t need to care about table structure changes, because it will automatically detect new fields to update your table structure.

The library mainly includes the following points:

  • Automatically create tables and add new fields based on entity objects (SQLite does not support column deletion)
  • Annotations are supported to configure table names, field names, field defaults, whether primary keys grow automatically, and which fields are not mapped in a data table
  • Directly map entity object to SQLite database, implement a line of code to add, delete, change and check SQLite database
  • Supports the creation of db databases in SDCard
  • Solve in onCreate, onUpgrade other operations performed in the database of abnormal (Java. Lang. An IllegalStateException: getDatabase called recursively)
  • Supports native SQL statements to operate databases

The main classes in the use of ORM library are described as follows:

  • SQLiteDBConfig: used to set the database name, creation path, version number, and listening for data creation and update
  • SQLiteDB: After the database is created, it is used to add, delete, change, and query the database
  • SQLiteDBFactory: This class is mainly used to create an SQLite database and cache the currently created SQLiteDB objects
  • CursorUtil: When querying the database, check whether the Cursor object is normal and parse the Cursor data as entity objects
  • IDBListener: A listener class for database creation and upgrade, providing an empty implementation of SimpleDBListener
  • Column: This annotation is used to set the field name and the field default value
  • PrimaryKey: this annotation sets the PrimaryKey, the PrimaryKey field name, and whether the PrimaryKey is auto-growing
  • Table: This annotation is used to set the Table name. If this is not set, the default class name is the Table name
  • NotDBColumn: This annotation sets which entity attributes are not mapped to the data table

The main uses are as follows:

Public class User {// Set the primary key ID to grow automatically. @primaryKey (isAutoGenerate=true) Private Long ID; private String name; @column (defaultValue="1") private int age; @notdbColumn private String bz; Public User() {} public User(String name) {super(); this.name = name; } public long getId() { return id; } public void setId(long id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } @Override public String toString() { return "{id=" + id + ",name=" + name + "}"; SQLiteDBConfig config = new SQLiteDBConfig(this); // Set the listener when the database is created. SimpleDBListener config.setDbListener(new IDBListener() { @Override public void onUpgradeHandler(SQLiteDatabase db, int oldVersion, Int newVersion) {} @override public void onDbCreateHandler(SQLiteDatabase db) {showLongToast(" database created successfully "); }}); OnDbCreateHandler (); // Create table (); // Create table (); // Create table () At the same time, if there is a new field is automatically updated table structure SQLiteDB db = SQLiteDBFactory. CreateSQLiteDB (config); // save single entity object User User = new User(" add single object "); Int RTN = db.save(user) // Save collection object List List = new ArrayList(); Int RTN = db.save(list) // queryAll data in User list = db.queryall (user.class); User User = db.query(user.class, "1"); // Query User User = db.query(user.class, "1"); Long total = db.queryTotal(user.class); Db.delete (user); // Update the entity object db.update(user); Query db. QueryPage (claxx, curPage, pageSize); Cursor = db.query(SQL, bindArgs);Copy the code