package com.tofly.data.sql.dao;

import java.util.List;
import android.database.Cursor;
import android.database.sqlite.SQLiteStatement;

import org.greenrobot.greendao.AbstractDao;
import org.greenrobot.greendao.Property;
import org.greenrobot.greendao.internal.DaoConfig;
import org.greenrobot.greendao.database.Database;
import org.greenrobot.greendao.database.DatabaseStatement;
import org.greenrobot.greendao.query.Query;
import org.greenrobot.greendao.query.QueryBuilder;

import com.tofly.ghrq_route.module.plan.domain.OfflinePathBean;

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/** 
 * DAO for table "DB_OFFLINE_PATH".
*/
public class OfflinePathBeanDao extends AbstractDao<OfflinePathBean, Long> {

    public static final String TABLENAME = "DB_OFFLINE_PATH";

    /**
     * Properties of entity OfflinePathBean.<br/>
     * Can be used for QueryBuilder and for referencing column names.
     */
    public static class Properties {
        public final static Property Id = new Property(0, Long.class, "id", true, "_id");
        public final static Property Temp_id = new Property(1, String.class, "temp_id", false, "TEMP_ID");
        public final static Property Plan_id = new Property(2, String.class, "plan_id", false, "PLAN_ID");
        public final static Property Path_id = new Property(3, String.class, "path_id", false, "PATH_ID");
        public final static Property Type = new Property(4, int.class, "type", false, "TYPE");
        public final static Property Lat = new Property(5, double.class, "lat", false, "LAT");
        public final static Property Lng = new Property(6, double.class, "lng", false, "LNG");
        public final static Property Addr = new Property(7, String.class, "addr", false, "ADDR");
        public final static Property Order = new Property(8, int.class, "order", false, "ORDER");
        public final static Property Isover = new Property(9, int.class, "isover", false, "ISOVER");
        public final static Property State = new Property(10, int.class, "state", false, "STATE");
        public final static Property Isupload = new Property(11, int.class, "isupload", false, "ISUPLOAD");
        public final static Property Ispast = new Property(12, int.class, "ispast", false, "ISPAST");
        public final static Property Check_time = new Property(13, String.class, "check_time", false, "CHECK_TIME");
        public final static Property Isoffupload = new Property(14, int.class, "isoffupload", false, "ISOFFUPLOAD");
        public final static Property First_left_time = new Property(15, String.class, "first_left_time", false, "FIRST_LEFT_TIME");
        public final static Property Gps_speed = new Property(16, String.class, "gps_speed", false, "GPS_SPEED");
        public final static Property Plan_mode = new Property(17, int.class, "plan_mode", false, "PLAN_MODE");
        public final static Property Child_begin_date = new Property(18, String.class, "child_begin_date", false, "CHILD_BEGIN_DATE");
        public final static Property Child_end_date = new Property(19, String.class, "child_end_date", false, "CHILD_END_DATE");
        public final static Property Userid = new Property(20, String.class, "userid", false, "USERID");
        public final static Property Rfid = new Property(21, String.class, "rfid", false, "RFID");
        public final static Property Point_id = new Property(22, String.class, "point_id", false, "POINT_ID");
        public final static Property Trouble_id = new Property(23, String.class, "trouble_id", false, "TROUBLE_ID");
        public final static Property Over_time = new Property(24, String.class, "over_time", false, "OVER_TIME");
        public final static Property Code = new Property(25, String.class, "code", false, "CODE");
        public final static Property Geometry = new Property(26, String.class, "geometry", false, "GEOMETRY");
        public final static Property Finish_time = new Property(27, String.class, "finish_time", false, "FINISH_TIME");
        public final static Property Pageindex = new Property(28, int.class, "pageindex", false, "PAGEINDEX");
    }

    private Query<OfflinePathBean> offlinePointLineBean_PathQuery;

    public OfflinePathBeanDao(DaoConfig config) {
        super(config);
    }
    
    public OfflinePathBeanDao(DaoConfig config, DaoSession daoSession) {
        super(config, daoSession);
    }

    /** Creates the underlying database table. */
    public static void createTable(Database db, boolean ifNotExists) {
        String constraint = ifNotExists? "IF NOT EXISTS ": "";
        db.execSQL("CREATE TABLE " + constraint + "\"DB_OFFLINE_PATH\" (" + //
                "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id
                "\"TEMP_ID\" TEXT," + // 1: temp_id
                "\"PLAN_ID\" TEXT," + // 2: plan_id
                "\"PATH_ID\" TEXT," + // 3: path_id
                "\"TYPE\" INTEGER NOT NULL ," + // 4: type
                "\"LAT\" REAL NOT NULL ," + // 5: lat
                "\"LNG\" REAL NOT NULL ," + // 6: lng
                "\"ADDR\" TEXT," + // 7: addr
                "\"ORDER\" INTEGER NOT NULL ," + // 8: order
                "\"ISOVER\" INTEGER NOT NULL ," + // 9: isover
                "\"STATE\" INTEGER NOT NULL ," + // 10: state
                "\"ISUPLOAD\" INTEGER NOT NULL ," + // 11: isupload
                "\"ISPAST\" INTEGER NOT NULL ," + // 12: ispast
                "\"CHECK_TIME\" TEXT," + // 13: check_time
                "\"ISOFFUPLOAD\" INTEGER NOT NULL ," + // 14: isoffupload
                "\"FIRST_LEFT_TIME\" TEXT," + // 15: first_left_time
                "\"GPS_SPEED\" TEXT," + // 16: gps_speed
                "\"PLAN_MODE\" INTEGER NOT NULL ," + // 17: plan_mode
                "\"CHILD_BEGIN_DATE\" TEXT," + // 18: child_begin_date
                "\"CHILD_END_DATE\" TEXT," + // 19: child_end_date
                "\"USERID\" TEXT," + // 20: userid
                "\"RFID\" TEXT," + // 21: rfid
                "\"POINT_ID\" TEXT," + // 22: point_id
                "\"TROUBLE_ID\" TEXT," + // 23: trouble_id
                "\"OVER_TIME\" TEXT," + // 24: over_time
                "\"CODE\" TEXT," + // 25: code
                "\"GEOMETRY\" TEXT," + // 26: geometry
                "\"FINISH_TIME\" TEXT," + // 27: finish_time
                "\"PAGEINDEX\" INTEGER NOT NULL );"); // 28: pageindex
        // Add Indexes
        db.execSQL("CREATE UNIQUE INDEX " + constraint + "IDX_DB_OFFLINE_PATH_TEMP_ID_DESC_PLAN_ID_DESC ON \"DB_OFFLINE_PATH\"" +
                " (\"TEMP_ID\" DESC,\"PLAN_ID\" DESC);");
    }

    /** Drops the underlying database table. */
    public static void dropTable(Database db, boolean ifExists) {
        String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"DB_OFFLINE_PATH\"";
        db.execSQL(sql);
    }

    @Override
    protected final void bindValues(DatabaseStatement stmt, OfflinePathBean entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
 
        String temp_id = entity.getTemp_id();
        if (temp_id != null) {
            stmt.bindString(2, temp_id);
        }
 
        String plan_id = entity.getPlan_id();
        if (plan_id != null) {
            stmt.bindString(3, plan_id);
        }
 
        String path_id = entity.getPath_id();
        if (path_id != null) {
            stmt.bindString(4, path_id);
        }
        stmt.bindLong(5, entity.getType());
        stmt.bindDouble(6, entity.getLat());
        stmt.bindDouble(7, entity.getLng());
 
        String addr = entity.getAddr();
        if (addr != null) {
            stmt.bindString(8, addr);
        }
        stmt.bindLong(9, entity.getOrder());
        stmt.bindLong(10, entity.getIsover());
        stmt.bindLong(11, entity.getState());
        stmt.bindLong(12, entity.getIsupload());
        stmt.bindLong(13, entity.getIspast());
 
        String check_time = entity.getCheck_time();
        if (check_time != null) {
            stmt.bindString(14, check_time);
        }
        stmt.bindLong(15, entity.getIsoffupload());
 
        String first_left_time = entity.getFirst_left_time();
        if (first_left_time != null) {
            stmt.bindString(16, first_left_time);
        }
 
        String gps_speed = entity.getGps_speed();
        if (gps_speed != null) {
            stmt.bindString(17, gps_speed);
        }
        stmt.bindLong(18, entity.getPlan_mode());
 
        String child_begin_date = entity.getChild_begin_date();
        if (child_begin_date != null) {
            stmt.bindString(19, child_begin_date);
        }
 
        String child_end_date = entity.getChild_end_date();
        if (child_end_date != null) {
            stmt.bindString(20, child_end_date);
        }
 
        String userid = entity.getUserid();
        if (userid != null) {
            stmt.bindString(21, userid);
        }
 
        String rfid = entity.getRfid();
        if (rfid != null) {
            stmt.bindString(22, rfid);
        }
 
        String point_id = entity.getPoint_id();
        if (point_id != null) {
            stmt.bindString(23, point_id);
        }
 
        String trouble_id = entity.getTrouble_id();
        if (trouble_id != null) {
            stmt.bindString(24, trouble_id);
        }
 
        String over_time = entity.getOver_time();
        if (over_time != null) {
            stmt.bindString(25, over_time);
        }
 
        String code = entity.getCode();
        if (code != null) {
            stmt.bindString(26, code);
        }
 
        String geometry = entity.getGeometry();
        if (geometry != null) {
            stmt.bindString(27, geometry);
        }
 
        String finish_time = entity.getFinish_time();
        if (finish_time != null) {
            stmt.bindString(28, finish_time);
        }
        stmt.bindLong(29, entity.getPageindex());
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, OfflinePathBean entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
 
        String temp_id = entity.getTemp_id();
        if (temp_id != null) {
            stmt.bindString(2, temp_id);
        }
 
        String plan_id = entity.getPlan_id();
        if (plan_id != null) {
            stmt.bindString(3, plan_id);
        }
 
        String path_id = entity.getPath_id();
        if (path_id != null) {
            stmt.bindString(4, path_id);
        }
        stmt.bindLong(5, entity.getType());
        stmt.bindDouble(6, entity.getLat());
        stmt.bindDouble(7, entity.getLng());
 
        String addr = entity.getAddr();
        if (addr != null) {
            stmt.bindString(8, addr);
        }
        stmt.bindLong(9, entity.getOrder());
        stmt.bindLong(10, entity.getIsover());
        stmt.bindLong(11, entity.getState());
        stmt.bindLong(12, entity.getIsupload());
        stmt.bindLong(13, entity.getIspast());
 
        String check_time = entity.getCheck_time();
        if (check_time != null) {
            stmt.bindString(14, check_time);
        }
        stmt.bindLong(15, entity.getIsoffupload());
 
        String first_left_time = entity.getFirst_left_time();
        if (first_left_time != null) {
            stmt.bindString(16, first_left_time);
        }
 
        String gps_speed = entity.getGps_speed();
        if (gps_speed != null) {
            stmt.bindString(17, gps_speed);
        }
        stmt.bindLong(18, entity.getPlan_mode());
 
        String child_begin_date = entity.getChild_begin_date();
        if (child_begin_date != null) {
            stmt.bindString(19, child_begin_date);
        }
 
        String child_end_date = entity.getChild_end_date();
        if (child_end_date != null) {
            stmt.bindString(20, child_end_date);
        }
 
        String userid = entity.getUserid();
        if (userid != null) {
            stmt.bindString(21, userid);
        }
 
        String rfid = entity.getRfid();
        if (rfid != null) {
            stmt.bindString(22, rfid);
        }
 
        String point_id = entity.getPoint_id();
        if (point_id != null) {
            stmt.bindString(23, point_id);
        }
 
        String trouble_id = entity.getTrouble_id();
        if (trouble_id != null) {
            stmt.bindString(24, trouble_id);
        }
 
        String over_time = entity.getOver_time();
        if (over_time != null) {
            stmt.bindString(25, over_time);
        }
 
        String code = entity.getCode();
        if (code != null) {
            stmt.bindString(26, code);
        }
 
        String geometry = entity.getGeometry();
        if (geometry != null) {
            stmt.bindString(27, geometry);
        }
 
        String finish_time = entity.getFinish_time();
        if (finish_time != null) {
            stmt.bindString(28, finish_time);
        }
        stmt.bindLong(29, entity.getPageindex());
    }

    @Override
    public Long readKey(Cursor cursor, int offset) {
        return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0);
    }    

    @Override
    public OfflinePathBean readEntity(Cursor cursor, int offset) {
        OfflinePathBean entity = new OfflinePathBean( //
            cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id
            cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // temp_id
            cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // plan_id
            cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // path_id
            cursor.getInt(offset + 4), // type
            cursor.getDouble(offset + 5), // lat
            cursor.getDouble(offset + 6), // lng
            cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // addr
            cursor.getInt(offset + 8), // order
            cursor.getInt(offset + 9), // isover
            cursor.getInt(offset + 10), // state
            cursor.getInt(offset + 11), // isupload
            cursor.getInt(offset + 12), // ispast
            cursor.isNull(offset + 13) ? null : cursor.getString(offset + 13), // check_time
            cursor.getInt(offset + 14), // isoffupload
            cursor.isNull(offset + 15) ? null : cursor.getString(offset + 15), // first_left_time
            cursor.isNull(offset + 16) ? null : cursor.getString(offset + 16), // gps_speed
            cursor.getInt(offset + 17), // plan_mode
            cursor.isNull(offset + 18) ? null : cursor.getString(offset + 18), // child_begin_date
            cursor.isNull(offset + 19) ? null : cursor.getString(offset + 19), // child_end_date
            cursor.isNull(offset + 20) ? null : cursor.getString(offset + 20), // userid
            cursor.isNull(offset + 21) ? null : cursor.getString(offset + 21), // rfid
            cursor.isNull(offset + 22) ? null : cursor.getString(offset + 22), // point_id
            cursor.isNull(offset + 23) ? null : cursor.getString(offset + 23), // trouble_id
            cursor.isNull(offset + 24) ? null : cursor.getString(offset + 24), // over_time
            cursor.isNull(offset + 25) ? null : cursor.getString(offset + 25), // code
            cursor.isNull(offset + 26) ? null : cursor.getString(offset + 26), // geometry
            cursor.isNull(offset + 27) ? null : cursor.getString(offset + 27), // finish_time
            cursor.getInt(offset + 28) // pageindex
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, OfflinePathBean entity, int offset) {
        entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
        entity.setTemp_id(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
        entity.setPlan_id(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
        entity.setPath_id(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3));
        entity.setType(cursor.getInt(offset + 4));
        entity.setLat(cursor.getDouble(offset + 5));
        entity.setLng(cursor.getDouble(offset + 6));
        entity.setAddr(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7));
        entity.setOrder(cursor.getInt(offset + 8));
        entity.setIsover(cursor.getInt(offset + 9));
        entity.setState(cursor.getInt(offset + 10));
        entity.setIsupload(cursor.getInt(offset + 11));
        entity.setIspast(cursor.getInt(offset + 12));
        entity.setCheck_time(cursor.isNull(offset + 13) ? null : cursor.getString(offset + 13));
        entity.setIsoffupload(cursor.getInt(offset + 14));
        entity.setFirst_left_time(cursor.isNull(offset + 15) ? null : cursor.getString(offset + 15));
        entity.setGps_speed(cursor.isNull(offset + 16) ? null : cursor.getString(offset + 16));
        entity.setPlan_mode(cursor.getInt(offset + 17));
        entity.setChild_begin_date(cursor.isNull(offset + 18) ? null : cursor.getString(offset + 18));
        entity.setChild_end_date(cursor.isNull(offset + 19) ? null : cursor.getString(offset + 19));
        entity.setUserid(cursor.isNull(offset + 20) ? null : cursor.getString(offset + 20));
        entity.setRfid(cursor.isNull(offset + 21) ? null : cursor.getString(offset + 21));
        entity.setPoint_id(cursor.isNull(offset + 22) ? null : cursor.getString(offset + 22));
        entity.setTrouble_id(cursor.isNull(offset + 23) ? null : cursor.getString(offset + 23));
        entity.setOver_time(cursor.isNull(offset + 24) ? null : cursor.getString(offset + 24));
        entity.setCode(cursor.isNull(offset + 25) ? null : cursor.getString(offset + 25));
        entity.setGeometry(cursor.isNull(offset + 26) ? null : cursor.getString(offset + 26));
        entity.setFinish_time(cursor.isNull(offset + 27) ? null : cursor.getString(offset + 27));
        entity.setPageindex(cursor.getInt(offset + 28));
     }
    
    @Override
    protected final Long updateKeyAfterInsert(OfflinePathBean entity, long rowId) {
        entity.setId(rowId);
        return rowId;
    }
    
    @Override
    public Long getKey(OfflinePathBean entity) {
        if(entity != null) {
            return entity.getId();
        } else {
            return null;
        }
    }

    @Override
    public boolean hasKey(OfflinePathBean entity) {
        return entity.getId() != null;
    }

    @Override
    protected final boolean isEntityUpdateable() {
        return true;
    }
    
    /** Internal query to resolve the "path" to-many relationship of OfflinePointLineBean. */
    public List<OfflinePathBean> _queryOfflinePointLineBean_Path(String temp_id) {
        synchronized (this) {
            if (offlinePointLineBean_PathQuery == null) {
                QueryBuilder<OfflinePathBean> queryBuilder = queryBuilder();
                queryBuilder.where(Properties.Temp_id.eq(null));
                offlinePointLineBean_PathQuery = queryBuilder.build();
            }
        }
        Query<OfflinePathBean> query = offlinePointLineBean_PathQuery.forCurrentThread();
        query.setParameter(0, temp_id);
        return query.list();
    }

}
