Skip to content
Himanshu Soni edited this page Aug 18, 2015 · 1 revision

Setup

Installation Types:

Gradle:

compile 'info.quantumflux:library:0.9.0'

Maven:

<dependency>
    <groupId>info.quantumflux</groupId>
    <artifactId>library</artifactId>
    <version>0.9.0</version>
</dependency>

As a library

You can also download the source (zip) and import as library project or module.

Add jar file

See releases page to download jar for latest version directly.

Setup

  1. Extend Application class and override attachBaseContext 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"
            ...
            >
  2. 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 -->
    
  3. 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

Use

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 as save(), update(), delete(), etc. and If you are using @Table annotation, you can use those methods from QuantumFlux 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 become book_name in database.

  • If you want to keep different authorities for different tables, you can use @Authority on a table model.

Column Constraint annotations

  • @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