Skip to content

Content provider

xcesco edited this page Apr 23, 2018 · 1 revision

As viewed in the introduction, Kripton to generate DAO and data source implementations need the definition of DAOs and data source interfaces. One of the Kripton's big feature is the capability to generate the content provider is an easy way. This goal is achieved with some annotation like @BindContentProvider, @BindContentProviderPath, @BindContentProviderEntry.

We can take the previous Person example to see how to generate a content provider too.

@BindTable(name="persons")
public class Person{
  public long id;
  public String name;
  public String surname;
  public String email;
  public Date birthDate;
}

The DAO interface definition is:

@BindContentProviderPath(path = "persons")
@BindDao(Person.class)
public interface PersonDao {

  @BindContentProviderEntry
  @BindSqlSelect(orderBy="name")
  List<Person> selectAll();

  @BindSqlSelect(jql="select * from person order by name")
  List<Person> selectTwo();

  @BindSqlSelect()
  List<Person> selectThree(@BindSqlDynamicOrderBy String orderBy);

  @BindSqlSelect(where = "id=${work.id}")
  List<E> selectById(@BindSqlParam("work") E bean);

  @BindContentProviderEntry
  @BindSqlInsert
  void insert(Person bean);

  @BindContentProviderEntry  
  @BindSqlUpdate(where = "id=${work.id}")
  boolean update(@BindSqlParam("work") Person bean);
  
  @BindContentProviderEntry  
  @BindSqlDelete(where = "id=${work.id}")
  boolean delete(@BindSqlParam("work") Person bean);
}

The data source definition:

@BindContentProvider(authority="com.abubusoft.kripton")
@BindDataSource(daoSet= { PersonDao.class }, fileName = "person.db", log=true)
public interface PersonDataSource {
}

As you notice in the source code there are other used annotations, needed if you want to generate a Content Provider too:

Given a data source definition, Kripton can generate a content provider just with a couple of extra annotations. In your application, to use generated an implementation of data-source you can use code like this:

Table of Contents

Query definition

Features

Relations

Multithread supports

Modularization

Annotations for data convertion

Annotations for SQLite ORM

Annotations for shared preferences

Clone this wiki locally