Code reference you may see in project
- Create your model with annotation @Column, for example:
See all model parameters below in section Model
public class Record {
@Column
private String recordText;
}
- Create class extends Application.
public class MainApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
// also may use isFirstStartOnAppVersion with your version
if (SimpleDatabaseUtil.isFirstApplicationStart(this)) {
SQLiteSimple databaseSimple = new SQLiteSimple(this);
databaseSimple.create(Record.class);
// above need enumerate classes, for example: Class1.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);
}
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, supports attributes:
type - optional (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();
// just write below, if you not specify version, library set version 1
SQLiteSimple databaseSimple = new SQLiteSimple(this, DATABASE_VERSION);
databaseSimple.create(Record.class);
}
}
@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
// need to use tables category,
} // search between several tables
That's all! Use methods as described below in appropriate places, like in a example.
simpleFTS.search(...), simpleFTS.create(...).
If you use proguard, don't forget add
-keep public class your_package.models.** { *; }
-keepattributes Signature
-keepattributes *Annotation*
to proguard-project.txt
Also may be used:
SimpleConstants
ZERO_RESULT - if, for example, object not found, or not created
SimpleDatabaseUtil methods:
getFullDatabasePath - path to internal database.
isFirstApplicationStart - return true if is first application start.
isFirstStartOnAppVersion - return true if is first application start in version ...
SQLiteSimpleDAO methods:
updateDatabases - use this, if you need force update for all databases in application
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.