// Path: database/src/main/java/com/simple/database/listeners/DbListener.java
// public interface DbListener<T> {
//     void onComplete(T result);
// }
// 
// Path: app/src/main/java/com/simple/simpledatabase/dao/BookDao.java
// public class BookDao extends AbsDAO<Book> {
// 
//     public BookDao() {
//         super("books");
//     }
// 
//     @Override
//     protected ContentValues convert(Book item) {
//         ContentValues newValues = new ContentValues();
//         newValues.put("id", item.id);
//         newValues.put("name", item.name);
//         return newValues;
//     }
// 
// 
//     @Override
//     protected Book parseOneItem(Cursor cursor) {
//         Book item = new Book();
//         item.id = cursor.getString(0);
//         item.name = cursor.getString(1) ;
//         return item;
//     }
// 
// }
// 
// Path: app/src/main/java/com/simple/simpledatabase/domain/Book.java
// public class Book {
//     public String id ;
//     public String name ;
// }
// 
// Path: database/src/main/java/com/simple/database/DatabaseHelper.java
// public static <T> DeleteBuilder<T> deleteFrom(Class<? extends AbsDAO<T>> daoClass) {
//     return new DeleteBuilder<>(daoClass);
// }
// 
// Path: database/src/main/java/com/simple/database/DatabaseHelper.java
// public static <T> InsertBuilder<T> insertInto(Class<? extends AbsDAO<T>> daoClass) {
//     return new InsertBuilder<T>(daoClass);
// }
// 
// Path: database/src/main/java/com/simple/database/DatabaseHelper.java
// public static <T> QueryBuilder<T> selectFrom(Class<? extends AbsDAO<T>> daoClass) {
//     return new QueryBuilder<>(daoClass);
// }
// 
// Path: database/src/main/java/com/simple/database/DatabaseHelper.java
// public static <T> UpdateBuilder<T> updateFrom(Class<? extends AbsDAO<T>> daoClass) {
//     return new UpdateBuilder<>(daoClass);
// }


import com.simple.database.listeners.DbListener;
import com.simple.simpledatabase.dao.BookDao;
import com.simple.simpledatabase.domain.Book;
import java.util.List;
import static com.simple.database.DatabaseHelper.deleteFrom;
import static com.simple.database.DatabaseHelper.insertInto;
import static com.simple.database.DatabaseHelper.selectFrom;
import static com.simple.database.DatabaseHelper.updateFrom;
package com.simple.simpledatabase.model;




/**
 * 接口使用
 * Created by mrsimple on 13/8/16.
 */
public class BookModel {
    /**
     * 插入数据
     *
     * @param aBook
     */
    public void insertBook(Book aBook) {
        insertInto(BookDao.class).withItem(aBook).execute();
    }

    /**
     * 删除图书
     *
     * @param aBook
     */
    public void deleteBook(Book aBook) {
        // 根据Id 删除图书
        deleteFrom(BookDao.class).where("id=?", new String[]{aBook.id}).execute();
    }


    public void updateBook(Book aBook) {
        // 更新数据
        updateFrom(BookDao.class).withItem(aBook).where("id=?", new String[]{aBook.id});
    }

    /**
     * 查询所有书籍
     *
     * @param listener
     */
    public void queryAllBook(DbListener<List<Book>> listener) {
// Path: database/src/main/java/com/simple/database/listeners/DbListener.java
// public interface DbListener<T> {
//     void onComplete(T result);
// }
// 
// Path: app/src/main/java/com/simple/simpledatabase/dao/BookDao.java
// public class BookDao extends AbsDAO<Book> {
// 
//     public BookDao() {
//         super("books");
//     }
// 
//     @Override
//     protected ContentValues convert(Book item) {
//         ContentValues newValues = new ContentValues();
//         newValues.put("id", item.id);
//         newValues.put("name", item.name);
//         return newValues;
//     }
// 
// 
//     @Override
//     protected Book parseOneItem(Cursor cursor) {
//         Book item = new Book();
//         item.id = cursor.getString(0);
//         item.name = cursor.getString(1) ;
//         return item;
//     }
// 
// }
// 
// Path: app/src/main/java/com/simple/simpledatabase/domain/Book.java
// public class Book {
//     public String id ;
//     public String name ;
// }
// 
// Path: database/src/main/java/com/simple/database/DatabaseHelper.java
// public static <T> DeleteBuilder<T> deleteFrom(Class<? extends AbsDAO<T>> daoClass) {
//     return new DeleteBuilder<>(daoClass);
// }
// 
// Path: database/src/main/java/com/simple/database/DatabaseHelper.java
// public static <T> InsertBuilder<T> insertInto(Class<? extends AbsDAO<T>> daoClass) {
//     return new InsertBuilder<T>(daoClass);
// }
// 
// Path: database/src/main/java/com/simple/database/DatabaseHelper.java
// public static <T> QueryBuilder<T> selectFrom(Class<? extends AbsDAO<T>> daoClass) {
//     return new QueryBuilder<>(daoClass);
// }
// 
// Path: database/src/main/java/com/simple/database/DatabaseHelper.java
// public static <T> UpdateBuilder<T> updateFrom(Class<? extends AbsDAO<T>> daoClass) {
//     return new UpdateBuilder<>(daoClass);
// }


// Path: app/src/main/java/com/simple/simpledatabase/model/BookModel.java
import com.simple.database.listeners.DbListener;
import com.simple.simpledatabase.dao.BookDao;
import com.simple.simpledatabase.domain.Book;
import java.util.List;
import static com.simple.database.DatabaseHelper.deleteFrom;
import static com.simple.database.DatabaseHelper.insertInto;
import static com.simple.database.DatabaseHelper.selectFrom;
import static com.simple.database.DatabaseHelper.updateFrom;

package com.simple.simpledatabase.model;




/**
 * 接口使用
 * Created by mrsimple on 13/8/16.
 */
public class BookModel {
    /**
     * 插入数据
     *
     * @param aBook
     */
    public void insertBook(Book aBook) {
        insertInto(BookDao.class).withItem(aBook).execute();
    }

    /**
     * 删除图书
     *
     * @param aBook
     */
    public void deleteBook(Book aBook) {
        // 根据Id 删除图书
        deleteFrom(BookDao.class).where("id=?", new String[]{aBook.id}).execute();
    }


    public void updateBook(Book aBook) {
        // 更新数据
        updateFrom(BookDao.class).withItem(aBook).where("id=?", new String[]{aBook.id});
    }

    /**
     * 查询所有书籍
     *
     * @param listener
     */
    public void queryAllBook(DbListener<List<Book>> listener) {
        selectFrom(BookDao.class).listener(listener).execute();