package com.gingersoft.gsa.cloud.database.greendao;

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 com.gingersoft.gsa.cloud.database.bean.PrinterDeviceBean;

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

    public static final String TABLENAME = "PRINTER_DEVICE_BEAN";

    /**
     * Properties of entity PrinterDeviceBean.<br/>
     * Can be used for QueryBuilder and for referencing column names.
     */
    public static class Properties {
        public final static Property Id = new Property(0, int.class, "id", false, "ID");
        public final static Property Dbid = new Property(1, Long.class, "dbid", true, "_id");
        public final static Property RestaurantId = new Property(2, Integer.class, "restaurantId", false, "RESTAURANT_ID");
        public final static Property Ip = new Property(3, String.class, "ip", false, "IP");
        public final static Property Port = new Property(4, int.class, "port", false, "PORT");
        public final static Property Type = new Property(5, int.class, "type", false, "TYPE");
    }


    public PrinterDeviceBeanDao(DaoConfig config) {
        super(config);
    }
    
    public PrinterDeviceBeanDao(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 + "\"PRINTER_DEVICE_BEAN\" (" + //
                "\"ID\" INTEGER NOT NULL ," + // 0: id
                "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 1: dbid
                "\"RESTAURANT_ID\" INTEGER," + // 2: restaurantId
                "\"IP\" TEXT," + // 3: ip
                "\"PORT\" INTEGER NOT NULL ," + // 4: port
                "\"TYPE\" INTEGER NOT NULL );"); // 5: type
    }

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

    @Override
    protected final void bindValues(DatabaseStatement stmt, PrinterDeviceBean entity) {
        stmt.clearBindings();
        stmt.bindLong(1, entity.getId());
 
        Long dbid = entity.getDbid();
        if (dbid != null) {
            stmt.bindLong(2, dbid);
        }
 
        Integer restaurantId = entity.getRestaurantId();
        if (restaurantId != null) {
            stmt.bindLong(3, restaurantId);
        }
 
        String ip = entity.getIp();
        if (ip != null) {
            stmt.bindString(4, ip);
        }
        stmt.bindLong(5, entity.getPort());
        stmt.bindLong(6, entity.getType());
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, PrinterDeviceBean entity) {
        stmt.clearBindings();
        stmt.bindLong(1, entity.getId());
 
        Long dbid = entity.getDbid();
        if (dbid != null) {
            stmt.bindLong(2, dbid);
        }
 
        Integer restaurantId = entity.getRestaurantId();
        if (restaurantId != null) {
            stmt.bindLong(3, restaurantId);
        }
 
        String ip = entity.getIp();
        if (ip != null) {
            stmt.bindString(4, ip);
        }
        stmt.bindLong(5, entity.getPort());
        stmt.bindLong(6, entity.getType());
    }

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

    @Override
    public PrinterDeviceBean readEntity(Cursor cursor, int offset) {
        PrinterDeviceBean entity = new PrinterDeviceBean( //
            cursor.getInt(offset + 0), // id
            cursor.isNull(offset + 1) ? null : cursor.getLong(offset + 1), // dbid
            cursor.isNull(offset + 2) ? null : cursor.getInt(offset + 2), // restaurantId
            cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // ip
            cursor.getInt(offset + 4), // port
            cursor.getInt(offset + 5) // type
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, PrinterDeviceBean entity, int offset) {
        entity.setId(cursor.getInt(offset + 0));
        entity.setDbid(cursor.isNull(offset + 1) ? null : cursor.getLong(offset + 1));
        entity.setRestaurantId(cursor.isNull(offset + 2) ? null : cursor.getInt(offset + 2));
        entity.setIp(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3));
        entity.setPort(cursor.getInt(offset + 4));
        entity.setType(cursor.getInt(offset + 5));
     }
    
    @Override
    protected final Long updateKeyAfterInsert(PrinterDeviceBean entity, long rowId) {
        entity.setDbid(rowId);
        return rowId;
    }
    
    @Override
    public Long getKey(PrinterDeviceBean entity) {
        if(entity != null) {
            return entity.getDbid();
        } else {
            return null;
        }
    }

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

    @Override
    protected final boolean isEntityUpdateable() {
        return true;
    }
    
}
