-
Notifications
You must be signed in to change notification settings - Fork 8
setup
compile 'info.quantumflux:library:0.9.0'
<dependency>
<groupId>info.quantumflux</groupId>
<artifactId>library</artifactId>
<version>0.9.0</version>
</dependency>
You can also download the source (zip) and import as library project or module.
See releases page to download jar for latest version directly.
-
Extend
Application
class and overrideattachBaseContext
as following:public class SampleApplication extends Application { @Override protected void attachBaseContext(Context base) { super.attachBaseContext(base); QuantumFlux.initialize(this); } ... }
and then register this application class in Manifest file:
<application android:name="info.quantumflux.sample.SampleApplication" ... >
-
add following meta data in
<application>
tag of AndroidManifest.xml- Authority for the content provider
<meta-data android:name="AUTHORITY" android:value="info.quantumflux.sample" />
- Database name
<meta-data android:name="DATABASE_NAME" android:value="QuantumFluxSample.sqlite" />
- Database version
<meta-data android:name="DATABASE_VERSION" android:value="1" />
- Package name of the application
<meta-data android:name="PACKAGE_NAME" android:value="info.quantumflux.sample" />
- Logging the queries (for debugging, optional)
<meta-data android:name="QUERY_LOG" android:value="true" /> <!-- Optional -->
-
register content provider:
<provider android:name="info.quantumflux.provider.QuantumFluxContentProvider" android:authorities="info.quantumflux.sample" android:exported="false" />
Note: Authority name must be same for content provider and meta data name
To use create tables in QuantumFlux content provider databse, you have to either extend QuantumFluxRecord
or use @Table
annotation or both.
Default name of the table will be name of the class. Though you can change name of the table using '@Table' annotation with tableName
property.
public class Book extends QuantumFluxRecord {
public String name;
public String isbn;
...
}
@Table
public class Author {
public String name;
...
}
@Table(tableName = "book_publisher")
public class Publisher extends QuantumFluxRecord {
public String name;
...
}
Notes:
-
When you extend
QuantumFluxRecord
you have access to all default access methods such assave()
,update()
,delete()
, etc. and If you are using@Table
annotation, you can use those methods fromQuantumFlux
class. for e.g.QuantumFlux.insert(authorObject);
. -
When you extend
QuantumFluxRecord
you have already a auto increment primary key with name '_id'. So while using@Table
annotation, consider creating a primary key. -
Name of columns and tables will convert from camelCasing to under_score. for e.g. fielf
bookName
in a model will becomebook_name
in database. -
If you want to keep different authorities for different tables, you can use
@Authority
on a table model.
-
@Column
will allow to change name of column and allow to make it NOT NULL. Default values for not null is false. for e.g.
@Column(columnName = "cover_name")
private String bookName;
@Column(required = true)
private String isbn;
-
@PrimaryKey
will allow to make a column as primary key, and auto increment. Default value for autoIncrement is true. for e.g.
@PrimaryKey
private String isbn;
@PrimaryKey(autoIncrement = false)
private String isbn;
-
@Unique
will allow you to make a column value unique.
==================
for accessing data and content provider, see Access