Code reference you may see in project
- Create your model with annotation @Column(type = ColumnType.TYPE), for example:
See all model parameters below in section Model
public class Record {
public transient static final String COLUMN_RECORD_TEXT = "recordText";
public transient static final String COLUMN_ID = "_id";
@Column(name = COLUMN_ID, type = ColumnType.INTEGER, isPrimaryKey = true, isAutoincrement = true)
private int id;
@Column(name = COLUMN_RECORD_TEXT, type = ColumnType.TEXT)
private String recordText;
// also supports ColumnType.NUMERIC, ColumnType.REAL, ColumnType.BLOB
}
- Create class extends Application.
public class MainApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
SQLiteSimple databaseSimple = new SQLiteSimple(this);
databaseSimple.create(Record.class); // enumerate classes Class1.class, Class2.class,...
}
}
- Add to AndroidManifest.xml
<application
android:name=".MainApplication"
...
...
>
- Create «DAO» class extends SQLiteSimpleDAO<YourModelName>
public class RecordsDAO extends SQLiteSimpleDAO<Record> {
public RecordsDAO(Context context) {
super(Record.class, context);
}
}
That's all!
In your activity just create operator, for example:
...
private RecordsDAO recordsDAO;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
recordsDAO = new RecordsDAO(this);
}
@Override
protected void onDestroy() {
super.onDestroy();
recordsDAO.recycle();
}
And you may call all needed methods, if you need more, just override or create new in class RecordsDAO, look above.
Look better this nuance, available annotations:@Table - optional parameter for classes, supports attributes:
name - optional.
@Column - required parameter for variables, also required the type of column, supports attributes:
type - required (ColumnType.TEXT, ColumnType.NUMERIC, ColumnType.REAL, ColumnType.INTEGER, ColumnType.BLOB).
name - optional.
isPrimaryKey - optional (for keys, supports compound key).
isAutoincrement - optional (for key, aka _id).
How use:
public class MainApplication extends Application {
private final static int DATABASE_VERSION = 2;
@Override
public void onCreate() {
super.onCreate();
SQLiteSimple databaseSimple = new SQLiteSimple(this, DATABASE_VERSION); // just write here
databaseSimple.create(Record.class); // if you not specify version
} // library set version 1
}
@Override
public void onCreate() {
super.onCreate();
SQLiteSimple databaseSimple = new SQLiteSimple(this, "example.sqlite");
databaseSimple.create(Example.class);
}
}
<h2>FTS (Full-Text Search)</h2>
```java
...
private SQLiteSimpleFTS simpleFTS;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
simpleFTS = new SQLiteSimpleFTS(this, false); // second parameter is a tables category,
} // search between several tables
@Override
protected void onDestroy() {
super.onDestroy();
simpleFTS.recycle();
}
That's all! Use methods as described below in appropriate places, like in a example.
simpleFTS.search(...), simpleFTS.create(...).
Also may be used:
SimpleConstants
ZERO_RESULT - if, for example, object not found, or not created
SimplePreferencesUtil methods:
getDatabaseVersion() - current local database version.
isVirtualTableCreated() - for FTS.
SimpleDatabaseUtil methods:
getFullDatabasePath() - path to internal database.