@SuppressWarnings("ALL")
public class HistoryDao extends AbstractDao<History, Long> {

    public static final String TABLENAME = "HISTORY";

    /**
     * Properties of entity History.<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 DateFrom = new Property(1, java.util.Date.class, "dateFrom", false, "DATE_FROM");
        public final static Property BillType = new Property(2, String.class, "billType", false, "BILL_TYPE");
        public final static Property BillId = new Property(3, Long.class, "billId", false, "BILL_ID");
    }


    public HistoryDao(DaoConfig config) {
        super(config);
    }
    
    public HistoryDao(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 + "\"HISTORY\" (" + //
                "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id
                "\"DATE_FROM\" INTEGER," + // 1: dateFrom
                "\"BILL_TYPE\" TEXT," + // 2: billType
                "\"BILL_ID\" INTEGER);"); // 3: billId
    }

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

    @Override
    protected final void bindValues(DatabaseStatement stmt, History entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
 
        java.util.Date dateFrom = entity.getDateFrom();
        if (dateFrom != null) {
            stmt.bindLong(2, dateFrom.getTime());
        }
 
        String billType = entity.getBillType();
        if (billType != null) {
            stmt.bindString(3, billType);
        }
 
        Long billId = entity.getBillId();
        if (billId != null) {
            stmt.bindLong(4, billId);
        }
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, History entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
 
        java.util.Date dateFrom = entity.getDateFrom();
        if (dateFrom != null) {
            stmt.bindLong(2, dateFrom.getTime());
        }
 
        String billType = entity.getBillType();
        if (billType != null) {
            stmt.bindString(3, billType);
        }
 
        Long billId = entity.getBillId();
        if (billId != null) {
            stmt.bindLong(4, billId);
        }
    }

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

    @Override
    public History readEntity(Cursor cursor, int offset) {
        History entity = new History( //
            cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id
            cursor.isNull(offset + 1) ? null : new java.util.Date(cursor.getLong(offset + 1)), // dateFrom
            cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // billType
            cursor.isNull(offset + 3) ? null : cursor.getLong(offset + 3) // billId
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, History entity, int offset) {
        entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
        entity.setDateFrom(cursor.isNull(offset + 1) ? null : new java.util.Date(cursor.getLong(offset + 1)));
        entity.setBillType(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
        entity.setBillId(cursor.isNull(offset + 3) ? null : cursor.getLong(offset + 3));
     }
    
    @Override
    protected final Long updateKeyAfterInsert(History entity, long rowId) {
        entity.setId(rowId);
        return rowId;
    }
    
    @Override
    public Long getKey(History entity) {
        if(entity != null) {
            return entity.getId();
        } else {
            return null;
        }
    }

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

    @Override
    protected final boolean isEntityUpdateable() {
        return true;
    }
    
} @SuppressWarnings("ALL")
public class PgeG11BillDao extends AbstractDao<PgeG11Bill, Long> {

    public static final String TABLENAME = "PGE_G11_BILL";

    /**
     * Properties of entity PgeG11Bill.<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 ReadingFrom = new Property(1, Integer.class, "readingFrom", false, "READING_FROM");
        public final static Property ReadingTo = new Property(2, Integer.class, "readingTo", false, "READING_TO");
        public final static Property DateFrom = new Property(3, java.util.Date.class, "dateFrom", false, "DATE_FROM");
        public final static Property DateTo = new Property(4, java.util.Date.class, "dateTo", false, "DATE_TO");
        public final static Property AmountToPay = new Property(5, Double.class, "amountToPay", false, "AMOUNT_TO_PAY");
        public final static Property PricesId = new Property(6, Long.class, "pricesId", false, "PRICES_ID");
    }

    private DaoSession daoSession;


    public PgeG11BillDao(DaoConfig config) {
        super(config);
    }
    
    public PgeG11BillDao(DaoConfig config, DaoSession daoSession) {
        super(config, daoSession);
        this.daoSession = 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 + "\"PGE_G11_BILL\" (" + //
                "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id
                "\"READING_FROM\" INTEGER," + // 1: readingFrom
                "\"READING_TO\" INTEGER," + // 2: readingTo
                "\"DATE_FROM\" INTEGER," + // 3: dateFrom
                "\"DATE_TO\" INTEGER," + // 4: dateTo
                "\"AMOUNT_TO_PAY\" REAL," + // 5: amountToPay
                "\"PRICES_ID\" INTEGER);"); // 6: pricesId
    }

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

    @Override
    protected final void bindValues(DatabaseStatement stmt, PgeG11Bill entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
 
        Integer readingFrom = entity.getReadingFrom();
        if (readingFrom != null) {
            stmt.bindLong(2, readingFrom);
        }
 
        Integer readingTo = entity.getReadingTo();
        if (readingTo != null) {
            stmt.bindLong(3, readingTo);
        }
 
        java.util.Date dateFrom = entity.getDateFrom();
        if (dateFrom != null) {
            stmt.bindLong(4, dateFrom.getTime());
        }
 
        java.util.Date dateTo = entity.getDateTo();
        if (dateTo != null) {
            stmt.bindLong(5, dateTo.getTime());
        }
 
        Double amountToPay = entity.getAmountToPay();
        if (amountToPay != null) {
            stmt.bindDouble(6, amountToPay);
        }
 
        Long pricesId = entity.getPricesId();
        if (pricesId != null) {
            stmt.bindLong(7, pricesId);
        }
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, PgeG11Bill entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
 
        Integer readingFrom = entity.getReadingFrom();
        if (readingFrom != null) {
            stmt.bindLong(2, readingFrom);
        }
 
        Integer readingTo = entity.getReadingTo();
        if (readingTo != null) {
            stmt.bindLong(3, readingTo);
        }
 
        java.util.Date dateFrom = entity.getDateFrom();
        if (dateFrom != null) {
            stmt.bindLong(4, dateFrom.getTime());
        }
 
        java.util.Date dateTo = entity.getDateTo();
        if (dateTo != null) {
            stmt.bindLong(5, dateTo.getTime());
        }
 
        Double amountToPay = entity.getAmountToPay();
        if (amountToPay != null) {
            stmt.bindDouble(6, amountToPay);
        }
 
        Long pricesId = entity.getPricesId();
        if (pricesId != null) {
            stmt.bindLong(7, pricesId);
        }
    }

    @Override
    protected final void attachEntity(PgeG11Bill entity) {
        super.attachEntity(entity);
        entity.__setDaoSession(daoSession);
    }

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

    @Override
    public PgeG11Bill readEntity(Cursor cursor, int offset) {
        PgeG11Bill entity = new PgeG11Bill( //
            cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id
            cursor.isNull(offset + 1) ? null : cursor.getInt(offset + 1), // readingFrom
            cursor.isNull(offset + 2) ? null : cursor.getInt(offset + 2), // readingTo
            cursor.isNull(offset + 3) ? null : new java.util.Date(cursor.getLong(offset + 3)), // dateFrom
            cursor.isNull(offset + 4) ? null : new java.util.Date(cursor.getLong(offset + 4)), // dateTo
            cursor.isNull(offset + 5) ? null : cursor.getDouble(offset + 5), // amountToPay
            cursor.isNull(offset + 6) ? null : cursor.getLong(offset + 6) // pricesId
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, PgeG11Bill entity, int offset) {
        entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
        entity.setReadingFrom(cursor.isNull(offset + 1) ? null : cursor.getInt(offset + 1));
        entity.setReadingTo(cursor.isNull(offset + 2) ? null : cursor.getInt(offset + 2));
        entity.setDateFrom(cursor.isNull(offset + 3) ? null : new java.util.Date(cursor.getLong(offset + 3)));
        entity.setDateTo(cursor.isNull(offset + 4) ? null : new java.util.Date(cursor.getLong(offset + 4)));
        entity.setAmountToPay(cursor.isNull(offset + 5) ? null : cursor.getDouble(offset + 5));
        entity.setPricesId(cursor.isNull(offset + 6) ? null : cursor.getLong(offset + 6));
     }
    
    @Override
    protected final Long updateKeyAfterInsert(PgeG11Bill entity, long rowId) {
        entity.setId(rowId);
        return rowId;
    }
    
    @Override
    public Long getKey(PgeG11Bill entity) {
        if(entity != null) {
            return entity.getId();
        } else {
            return null;
        }
    }

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

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

    protected String getSelectDeep() {
        if (selectDeep == null) {
            StringBuilder builder = new StringBuilder("SELECT ");
            SqlUtils.appendColumns(builder, "T", getAllColumns());
            builder.append(',');
            SqlUtils.appendColumns(builder, "T0", daoSession.getPgePricesDao().getAllColumns());
            builder.append(" FROM PGE_G11_BILL T");
            builder.append(" LEFT JOIN PGE_PRICES T0 ON T.\"PRICES_ID\"=T0.\"_id\"");
            builder.append(' ');
            selectDeep = builder.toString();
        }
        return selectDeep;
    }
    
    protected PgeG11Bill loadCurrentDeep(Cursor cursor, boolean lock) {
        PgeG11Bill entity = loadCurrent(cursor, 0, lock);
        int offset = getAllColumns().length;

        PgePrices pgePrices = loadCurrentOther(daoSession.getPgePricesDao(), cursor, offset);
        entity.setPgePrices(pgePrices);

        return entity;    
    }

    public PgeG11Bill loadDeep(Long key) {
        assertSinglePk();
        if (key == null) {
            return null;
        }

        StringBuilder builder = new StringBuilder(getSelectDeep());
        builder.append("WHERE ");
        SqlUtils.appendColumnsEqValue(builder, "T", getPkColumns());
        String sql = builder.toString();
        
        String[] keyArray = new String[] { key.toString() };
        Cursor cursor = db.rawQuery(sql, keyArray);
        
        try {
            boolean available = cursor.moveToFirst();
            if (!available) {
                return null;
            } else if (!cursor.isLast()) {
                throw new IllegalStateException("Expected unique result, but count was " + cursor.getCount());
            }
            return loadCurrentDeep(cursor, true);
        } finally {
            cursor.close();
        }
    }
    
    /** Reads all available rows from the given cursor and returns a list of new ImageTO objects. */
    public List<PgeG11Bill> loadAllDeepFromCursor(Cursor cursor) {
        int count = cursor.getCount();
        List<PgeG11Bill> list = new ArrayList<PgeG11Bill>(count);
        
        if (cursor.moveToFirst()) {
            if (identityScope != null) {
                identityScope.lock();
                identityScope.reserveRoom(count);
            }
            try {
                do {
                    list.add(loadCurrentDeep(cursor, false));
                } while (cursor.moveToNext());
            } finally {
                if (identityScope != null) {
                    identityScope.unlock();
                }
            }
        }
        return list;
    }
    
    protected List<PgeG11Bill> loadDeepAllAndCloseCursor(Cursor cursor) {
        try {
            return loadAllDeepFromCursor(cursor);
        } finally {
            cursor.close();
        }
    }
    

    /** A raw-style query where you can pass any WHERE clause and arguments. */
    public List<PgeG11Bill> queryDeep(String where, String... selectionArg) {
        Cursor cursor = db.rawQuery(getSelectDeep() + where, selectionArg);
        return loadDeepAllAndCloseCursor(cursor);
    }
 
} @SuppressWarnings("ALL")
public class PgeG12BillDao extends AbstractDao<PgeG12Bill, Long> {

    public static final String TABLENAME = "PGE_G12_BILL";

    /**
     * Properties of entity PgeG12Bill.<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 ReadingDayFrom = new Property(1, Integer.class, "readingDayFrom", false, "READING_DAY_FROM");
        public final static Property ReadingDayTo = new Property(2, Integer.class, "readingDayTo", false, "READING_DAY_TO");
        public final static Property ReadingNightFrom = new Property(3, Integer.class, "readingNightFrom", false, "READING_NIGHT_FROM");
        public final static Property ReadingNightTo = new Property(4, Integer.class, "readingNightTo", false, "READING_NIGHT_TO");
        public final static Property DateFrom = new Property(5, java.util.Date.class, "dateFrom", false, "DATE_FROM");
        public final static Property DateTo = new Property(6, java.util.Date.class, "dateTo", false, "DATE_TO");
        public final static Property AmountToPay = new Property(7, Double.class, "amountToPay", false, "AMOUNT_TO_PAY");
        public final static Property PricesId = new Property(8, Long.class, "pricesId", false, "PRICES_ID");
    }

    private DaoSession daoSession;


    public PgeG12BillDao(DaoConfig config) {
        super(config);
    }
    
    public PgeG12BillDao(DaoConfig config, DaoSession daoSession) {
        super(config, daoSession);
        this.daoSession = 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 + "\"PGE_G12_BILL\" (" + //
                "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id
                "\"READING_DAY_FROM\" INTEGER," + // 1: readingDayFrom
                "\"READING_DAY_TO\" INTEGER," + // 2: readingDayTo
                "\"READING_NIGHT_FROM\" INTEGER," + // 3: readingNightFrom
                "\"READING_NIGHT_TO\" INTEGER," + // 4: readingNightTo
                "\"DATE_FROM\" INTEGER," + // 5: dateFrom
                "\"DATE_TO\" INTEGER," + // 6: dateTo
                "\"AMOUNT_TO_PAY\" REAL," + // 7: amountToPay
                "\"PRICES_ID\" INTEGER);"); // 8: pricesId
    }

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

    @Override
    protected final void bindValues(DatabaseStatement stmt, PgeG12Bill entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
 
        Integer readingDayFrom = entity.getReadingDayFrom();
        if (readingDayFrom != null) {
            stmt.bindLong(2, readingDayFrom);
        }
 
        Integer readingDayTo = entity.getReadingDayTo();
        if (readingDayTo != null) {
            stmt.bindLong(3, readingDayTo);
        }
 
        Integer readingNightFrom = entity.getReadingNightFrom();
        if (readingNightFrom != null) {
            stmt.bindLong(4, readingNightFrom);
        }
 
        Integer readingNightTo = entity.getReadingNightTo();
        if (readingNightTo != null) {
            stmt.bindLong(5, readingNightTo);
        }
 
        java.util.Date dateFrom = entity.getDateFrom();
        if (dateFrom != null) {
            stmt.bindLong(6, dateFrom.getTime());
        }
 
        java.util.Date dateTo = entity.getDateTo();
        if (dateTo != null) {
            stmt.bindLong(7, dateTo.getTime());
        }
 
        Double amountToPay = entity.getAmountToPay();
        if (amountToPay != null) {
            stmt.bindDouble(8, amountToPay);
        }
 
        Long pricesId = entity.getPricesId();
        if (pricesId != null) {
            stmt.bindLong(9, pricesId);
        }
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, PgeG12Bill entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
 
        Integer readingDayFrom = entity.getReadingDayFrom();
        if (readingDayFrom != null) {
            stmt.bindLong(2, readingDayFrom);
        }
 
        Integer readingDayTo = entity.getReadingDayTo();
        if (readingDayTo != null) {
            stmt.bindLong(3, readingDayTo);
        }
 
        Integer readingNightFrom = entity.getReadingNightFrom();
        if (readingNightFrom != null) {
            stmt.bindLong(4, readingNightFrom);
        }
 
        Integer readingNightTo = entity.getReadingNightTo();
        if (readingNightTo != null) {
            stmt.bindLong(5, readingNightTo);
        }
 
        java.util.Date dateFrom = entity.getDateFrom();
        if (dateFrom != null) {
            stmt.bindLong(6, dateFrom.getTime());
        }
 
        java.util.Date dateTo = entity.getDateTo();
        if (dateTo != null) {
            stmt.bindLong(7, dateTo.getTime());
        }
 
        Double amountToPay = entity.getAmountToPay();
        if (amountToPay != null) {
            stmt.bindDouble(8, amountToPay);
        }
 
        Long pricesId = entity.getPricesId();
        if (pricesId != null) {
            stmt.bindLong(9, pricesId);
        }
    }

    @Override
    protected final void attachEntity(PgeG12Bill entity) {
        super.attachEntity(entity);
        entity.__setDaoSession(daoSession);
    }

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

    @Override
    public PgeG12Bill readEntity(Cursor cursor, int offset) {
        PgeG12Bill entity = new PgeG12Bill( //
            cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id
            cursor.isNull(offset + 1) ? null : cursor.getInt(offset + 1), // readingDayFrom
            cursor.isNull(offset + 2) ? null : cursor.getInt(offset + 2), // readingDayTo
            cursor.isNull(offset + 3) ? null : cursor.getInt(offset + 3), // readingNightFrom
            cursor.isNull(offset + 4) ? null : cursor.getInt(offset + 4), // readingNightTo
            cursor.isNull(offset + 5) ? null : new java.util.Date(cursor.getLong(offset + 5)), // dateFrom
            cursor.isNull(offset + 6) ? null : new java.util.Date(cursor.getLong(offset + 6)), // dateTo
            cursor.isNull(offset + 7) ? null : cursor.getDouble(offset + 7), // amountToPay
            cursor.isNull(offset + 8) ? null : cursor.getLong(offset + 8) // pricesId
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, PgeG12Bill entity, int offset) {
        entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
        entity.setReadingDayFrom(cursor.isNull(offset + 1) ? null : cursor.getInt(offset + 1));
        entity.setReadingDayTo(cursor.isNull(offset + 2) ? null : cursor.getInt(offset + 2));
        entity.setReadingNightFrom(cursor.isNull(offset + 3) ? null : cursor.getInt(offset + 3));
        entity.setReadingNightTo(cursor.isNull(offset + 4) ? null : cursor.getInt(offset + 4));
        entity.setDateFrom(cursor.isNull(offset + 5) ? null : new java.util.Date(cursor.getLong(offset + 5)));
        entity.setDateTo(cursor.isNull(offset + 6) ? null : new java.util.Date(cursor.getLong(offset + 6)));
        entity.setAmountToPay(cursor.isNull(offset + 7) ? null : cursor.getDouble(offset + 7));
        entity.setPricesId(cursor.isNull(offset + 8) ? null : cursor.getLong(offset + 8));
     }
    
    @Override
    protected final Long updateKeyAfterInsert(PgeG12Bill entity, long rowId) {
        entity.setId(rowId);
        return rowId;
    }
    
    @Override
    public Long getKey(PgeG12Bill entity) {
        if(entity != null) {
            return entity.getId();
        } else {
            return null;
        }
    }

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

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

    protected String getSelectDeep() {
        if (selectDeep == null) {
            StringBuilder builder = new StringBuilder("SELECT ");
            SqlUtils.appendColumns(builder, "T", getAllColumns());
            builder.append(',');
            SqlUtils.appendColumns(builder, "T0", daoSession.getPgePricesDao().getAllColumns());
            builder.append(" FROM PGE_G12_BILL T");
            builder.append(" LEFT JOIN PGE_PRICES T0 ON T.\"PRICES_ID\"=T0.\"_id\"");
            builder.append(' ');
            selectDeep = builder.toString();
        }
        return selectDeep;
    }
    
    protected PgeG12Bill loadCurrentDeep(Cursor cursor, boolean lock) {
        PgeG12Bill entity = loadCurrent(cursor, 0, lock);
        int offset = getAllColumns().length;

        PgePrices pgePrices = loadCurrentOther(daoSession.getPgePricesDao(), cursor, offset);
        entity.setPgePrices(pgePrices);

        return entity;    
    }

    public PgeG12Bill loadDeep(Long key) {
        assertSinglePk();
        if (key == null) {
            return null;
        }

        StringBuilder builder = new StringBuilder(getSelectDeep());
        builder.append("WHERE ");
        SqlUtils.appendColumnsEqValue(builder, "T", getPkColumns());
        String sql = builder.toString();
        
        String[] keyArray = new String[] { key.toString() };
        Cursor cursor = db.rawQuery(sql, keyArray);
        
        try {
            boolean available = cursor.moveToFirst();
            if (!available) {
                return null;
            } else if (!cursor.isLast()) {
                throw new IllegalStateException("Expected unique result, but count was " + cursor.getCount());
            }
            return loadCurrentDeep(cursor, true);
        } finally {
            cursor.close();
        }
    }
    
    /** Reads all available rows from the given cursor and returns a list of new ImageTO objects. */
    public List<PgeG12Bill> loadAllDeepFromCursor(Cursor cursor) {
        int count = cursor.getCount();
        List<PgeG12Bill> list = new ArrayList<PgeG12Bill>(count);
        
        if (cursor.moveToFirst()) {
            if (identityScope != null) {
                identityScope.lock();
                identityScope.reserveRoom(count);
            }
            try {
                do {
                    list.add(loadCurrentDeep(cursor, false));
                } while (cursor.moveToNext());
            } finally {
                if (identityScope != null) {
                    identityScope.unlock();
                }
            }
        }
        return list;
    }
    
    protected List<PgeG12Bill> loadDeepAllAndCloseCursor(Cursor cursor) {
        try {
            return loadAllDeepFromCursor(cursor);
        } finally {
            cursor.close();
        }
    }
    

    /** A raw-style query where you can pass any WHERE clause and arguments. */
    public List<PgeG12Bill> queryDeep(String where, String... selectionArg) {
        Cursor cursor = db.rawQuery(getSelectDeep() + where, selectionArg);
        return loadDeepAllAndCloseCursor(cursor);
    }
 
} @SuppressWarnings("ALL")
public class PgnigBillDao extends AbstractDao<PgnigBill, Long> {

    public static final String TABLENAME = "PGNIG_BILL";

    /**
     * Properties of entity PgnigBill.<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 ReadingFrom = new Property(1, Integer.class, "readingFrom", false, "READING_FROM");
        public final static Property ReadingTo = new Property(2, Integer.class, "readingTo", false, "READING_TO");
        public final static Property DateFrom = new Property(3, java.util.Date.class, "dateFrom", false, "DATE_FROM");
        public final static Property DateTo = new Property(4, java.util.Date.class, "dateTo", false, "DATE_TO");
        public final static Property AmountToPay = new Property(5, Double.class, "amountToPay", false, "AMOUNT_TO_PAY");
        public final static Property PricesId = new Property(6, Long.class, "pricesId", false, "PRICES_ID");
    }

    private DaoSession daoSession;


    public PgnigBillDao(DaoConfig config) {
        super(config);
    }
    
    public PgnigBillDao(DaoConfig config, DaoSession daoSession) {
        super(config, daoSession);
        this.daoSession = 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 + "\"PGNIG_BILL\" (" + //
                "\"_id\" INTEGER PRIMARY KEY ," + // 0: id
                "\"READING_FROM\" INTEGER," + // 1: readingFrom
                "\"READING_TO\" INTEGER," + // 2: readingTo
                "\"DATE_FROM\" INTEGER," + // 3: dateFrom
                "\"DATE_TO\" INTEGER," + // 4: dateTo
                "\"AMOUNT_TO_PAY\" REAL," + // 5: amountToPay
                "\"PRICES_ID\" INTEGER);"); // 6: pricesId
    }

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

    @Override
    protected final void bindValues(DatabaseStatement stmt, PgnigBill entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
 
        Integer readingFrom = entity.getReadingFrom();
        if (readingFrom != null) {
            stmt.bindLong(2, readingFrom);
        }
 
        Integer readingTo = entity.getReadingTo();
        if (readingTo != null) {
            stmt.bindLong(3, readingTo);
        }
 
        java.util.Date dateFrom = entity.getDateFrom();
        if (dateFrom != null) {
            stmt.bindLong(4, dateFrom.getTime());
        }
 
        java.util.Date dateTo = entity.getDateTo();
        if (dateTo != null) {
            stmt.bindLong(5, dateTo.getTime());
        }
 
        Double amountToPay = entity.getAmountToPay();
        if (amountToPay != null) {
            stmt.bindDouble(6, amountToPay);
        }
 
        Long pricesId = entity.getPricesId();
        if (pricesId != null) {
            stmt.bindLong(7, pricesId);
        }
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, PgnigBill entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
 
        Integer readingFrom = entity.getReadingFrom();
        if (readingFrom != null) {
            stmt.bindLong(2, readingFrom);
        }
 
        Integer readingTo = entity.getReadingTo();
        if (readingTo != null) {
            stmt.bindLong(3, readingTo);
        }
 
        java.util.Date dateFrom = entity.getDateFrom();
        if (dateFrom != null) {
            stmt.bindLong(4, dateFrom.getTime());
        }
 
        java.util.Date dateTo = entity.getDateTo();
        if (dateTo != null) {
            stmt.bindLong(5, dateTo.getTime());
        }
 
        Double amountToPay = entity.getAmountToPay();
        if (amountToPay != null) {
            stmt.bindDouble(6, amountToPay);
        }
 
        Long pricesId = entity.getPricesId();
        if (pricesId != null) {
            stmt.bindLong(7, pricesId);
        }
    }

    @Override
    protected final void attachEntity(PgnigBill entity) {
        super.attachEntity(entity);
        entity.__setDaoSession(daoSession);
    }

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

    @Override
    public PgnigBill readEntity(Cursor cursor, int offset) {
        PgnigBill entity = new PgnigBill( //
            cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id
            cursor.isNull(offset + 1) ? null : cursor.getInt(offset + 1), // readingFrom
            cursor.isNull(offset + 2) ? null : cursor.getInt(offset + 2), // readingTo
            cursor.isNull(offset + 3) ? null : new java.util.Date(cursor.getLong(offset + 3)), // dateFrom
            cursor.isNull(offset + 4) ? null : new java.util.Date(cursor.getLong(offset + 4)), // dateTo
            cursor.isNull(offset + 5) ? null : cursor.getDouble(offset + 5), // amountToPay
            cursor.isNull(offset + 6) ? null : cursor.getLong(offset + 6) // pricesId
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, PgnigBill entity, int offset) {
        entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
        entity.setReadingFrom(cursor.isNull(offset + 1) ? null : cursor.getInt(offset + 1));
        entity.setReadingTo(cursor.isNull(offset + 2) ? null : cursor.getInt(offset + 2));
        entity.setDateFrom(cursor.isNull(offset + 3) ? null : new java.util.Date(cursor.getLong(offset + 3)));
        entity.setDateTo(cursor.isNull(offset + 4) ? null : new java.util.Date(cursor.getLong(offset + 4)));
        entity.setAmountToPay(cursor.isNull(offset + 5) ? null : cursor.getDouble(offset + 5));
        entity.setPricesId(cursor.isNull(offset + 6) ? null : cursor.getLong(offset + 6));
     }
    
    @Override
    protected final Long updateKeyAfterInsert(PgnigBill entity, long rowId) {
        entity.setId(rowId);
        return rowId;
    }
    
    @Override
    public Long getKey(PgnigBill entity) {
        if(entity != null) {
            return entity.getId();
        } else {
            return null;
        }
    }

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

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

    protected String getSelectDeep() {
        if (selectDeep == null) {
            StringBuilder builder = new StringBuilder("SELECT ");
            SqlUtils.appendColumns(builder, "T", getAllColumns());
            builder.append(',');
            SqlUtils.appendColumns(builder, "T0", daoSession.getPgnigPricesDao().getAllColumns());
            builder.append(" FROM PGNIG_BILL T");
            builder.append(" LEFT JOIN PGNIG_PRICES T0 ON T.\"PRICES_ID\"=T0.\"_id\"");
            builder.append(' ');
            selectDeep = builder.toString();
        }
        return selectDeep;
    }
    
    protected PgnigBill loadCurrentDeep(Cursor cursor, boolean lock) {
        PgnigBill entity = loadCurrent(cursor, 0, lock);
        int offset = getAllColumns().length;

        PgnigPrices pgnigPrices = loadCurrentOther(daoSession.getPgnigPricesDao(), cursor, offset);
        entity.setPgnigPrices(pgnigPrices);

        return entity;    
    }

    public PgnigBill loadDeep(Long key) {
        assertSinglePk();
        if (key == null) {
            return null;
        }

        StringBuilder builder = new StringBuilder(getSelectDeep());
        builder.append("WHERE ");
        SqlUtils.appendColumnsEqValue(builder, "T", getPkColumns());
        String sql = builder.toString();
        
        String[] keyArray = new String[] { key.toString() };
        Cursor cursor = db.rawQuery(sql, keyArray);
        
        try {
            boolean available = cursor.moveToFirst();
            if (!available) {
                return null;
            } else if (!cursor.isLast()) {
                throw new IllegalStateException("Expected unique result, but count was " + cursor.getCount());
            }
            return loadCurrentDeep(cursor, true);
        } finally {
            cursor.close();
        }
    }
    
    /** Reads all available rows from the given cursor and returns a list of new ImageTO objects. */
    public List<PgnigBill> loadAllDeepFromCursor(Cursor cursor) {
        int count = cursor.getCount();
        List<PgnigBill> list = new ArrayList<PgnigBill>(count);
        
        if (cursor.moveToFirst()) {
            if (identityScope != null) {
                identityScope.lock();
                identityScope.reserveRoom(count);
            }
            try {
                do {
                    list.add(loadCurrentDeep(cursor, false));
                } while (cursor.moveToNext());
            } finally {
                if (identityScope != null) {
                    identityScope.unlock();
                }
            }
        }
        return list;
    }
    
    protected List<PgnigBill> loadDeepAllAndCloseCursor(Cursor cursor) {
        try {
            return loadAllDeepFromCursor(cursor);
        } finally {
            cursor.close();
        }
    }
    

    /** A raw-style query where you can pass any WHERE clause and arguments. */
    public List<PgnigBill> queryDeep(String where, String... selectionArg) {
        Cursor cursor = db.rawQuery(getSelectDeep() + where, selectionArg);
        return loadDeepAllAndCloseCursor(cursor);
    }
 
} @SuppressWarnings("ALL")
public class TauronG11BillDao extends AbstractDao<TauronG11Bill, Long> {

    public static final String TABLENAME = "TAURON_G11_BILL";

    /**
     * Properties of entity TauronG11Bill.<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 ReadingFrom = new Property(1, Integer.class, "readingFrom", false, "READING_FROM");
        public final static Property ReadingTo = new Property(2, Integer.class, "readingTo", false, "READING_TO");
        public final static Property DateFrom = new Property(3, java.util.Date.class, "dateFrom", false, "DATE_FROM");
        public final static Property DateTo = new Property(4, java.util.Date.class, "dateTo", false, "DATE_TO");
        public final static Property AmountToPay = new Property(5, Double.class, "amountToPay", false, "AMOUNT_TO_PAY");
        public final static Property PricesId = new Property(6, Long.class, "pricesId", false, "PRICES_ID");
    }

    private DaoSession daoSession;


    public TauronG11BillDao(DaoConfig config) {
        super(config);
    }
    
    public TauronG11BillDao(DaoConfig config, DaoSession daoSession) {
        super(config, daoSession);
        this.daoSession = 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 + "\"TAURON_G11_BILL\" (" + //
                "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id
                "\"READING_FROM\" INTEGER," + // 1: readingFrom
                "\"READING_TO\" INTEGER," + // 2: readingTo
                "\"DATE_FROM\" INTEGER," + // 3: dateFrom
                "\"DATE_TO\" INTEGER," + // 4: dateTo
                "\"AMOUNT_TO_PAY\" REAL," + // 5: amountToPay
                "\"PRICES_ID\" INTEGER);"); // 6: pricesId
    }

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

    @Override
    protected final void bindValues(DatabaseStatement stmt, TauronG11Bill entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
 
        Integer readingFrom = entity.getReadingFrom();
        if (readingFrom != null) {
            stmt.bindLong(2, readingFrom);
        }
 
        Integer readingTo = entity.getReadingTo();
        if (readingTo != null) {
            stmt.bindLong(3, readingTo);
        }
 
        java.util.Date dateFrom = entity.getDateFrom();
        if (dateFrom != null) {
            stmt.bindLong(4, dateFrom.getTime());
        }
 
        java.util.Date dateTo = entity.getDateTo();
        if (dateTo != null) {
            stmt.bindLong(5, dateTo.getTime());
        }
 
        Double amountToPay = entity.getAmountToPay();
        if (amountToPay != null) {
            stmt.bindDouble(6, amountToPay);
        }
 
        Long pricesId = entity.getPricesId();
        if (pricesId != null) {
            stmt.bindLong(7, pricesId);
        }
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, TauronG11Bill entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
 
        Integer readingFrom = entity.getReadingFrom();
        if (readingFrom != null) {
            stmt.bindLong(2, readingFrom);
        }
 
        Integer readingTo = entity.getReadingTo();
        if (readingTo != null) {
            stmt.bindLong(3, readingTo);
        }
 
        java.util.Date dateFrom = entity.getDateFrom();
        if (dateFrom != null) {
            stmt.bindLong(4, dateFrom.getTime());
        }
 
        java.util.Date dateTo = entity.getDateTo();
        if (dateTo != null) {
            stmt.bindLong(5, dateTo.getTime());
        }
 
        Double amountToPay = entity.getAmountToPay();
        if (amountToPay != null) {
            stmt.bindDouble(6, amountToPay);
        }
 
        Long pricesId = entity.getPricesId();
        if (pricesId != null) {
            stmt.bindLong(7, pricesId);
        }
    }

    @Override
    protected final void attachEntity(TauronG11Bill entity) {
        super.attachEntity(entity);
        entity.__setDaoSession(daoSession);
    }

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

    @Override
    public TauronG11Bill readEntity(Cursor cursor, int offset) {
        TauronG11Bill entity = new TauronG11Bill( //
            cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id
            cursor.isNull(offset + 1) ? null : cursor.getInt(offset + 1), // readingFrom
            cursor.isNull(offset + 2) ? null : cursor.getInt(offset + 2), // readingTo
            cursor.isNull(offset + 3) ? null : new java.util.Date(cursor.getLong(offset + 3)), // dateFrom
            cursor.isNull(offset + 4) ? null : new java.util.Date(cursor.getLong(offset + 4)), // dateTo
            cursor.isNull(offset + 5) ? null : cursor.getDouble(offset + 5), // amountToPay
            cursor.isNull(offset + 6) ? null : cursor.getLong(offset + 6) // pricesId
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, TauronG11Bill entity, int offset) {
        entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
        entity.setReadingFrom(cursor.isNull(offset + 1) ? null : cursor.getInt(offset + 1));
        entity.setReadingTo(cursor.isNull(offset + 2) ? null : cursor.getInt(offset + 2));
        entity.setDateFrom(cursor.isNull(offset + 3) ? null : new java.util.Date(cursor.getLong(offset + 3)));
        entity.setDateTo(cursor.isNull(offset + 4) ? null : new java.util.Date(cursor.getLong(offset + 4)));
        entity.setAmountToPay(cursor.isNull(offset + 5) ? null : cursor.getDouble(offset + 5));
        entity.setPricesId(cursor.isNull(offset + 6) ? null : cursor.getLong(offset + 6));
     }
    
    @Override
    protected final Long updateKeyAfterInsert(TauronG11Bill entity, long rowId) {
        entity.setId(rowId);
        return rowId;
    }
    
    @Override
    public Long getKey(TauronG11Bill entity) {
        if(entity != null) {
            return entity.getId();
        } else {
            return null;
        }
    }

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

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

    protected String getSelectDeep() {
        if (selectDeep == null) {
            StringBuilder builder = new StringBuilder("SELECT ");
            SqlUtils.appendColumns(builder, "T", getAllColumns());
            builder.append(',');
            SqlUtils.appendColumns(builder, "T0", daoSession.getTauronPricesDao().getAllColumns());
            builder.append(" FROM TAURON_G11_BILL T");
            builder.append(" LEFT JOIN TAURON_PRICES T0 ON T.\"PRICES_ID\"=T0.\"_id\"");
            builder.append(' ');
            selectDeep = builder.toString();
        }
        return selectDeep;
    }
    
    protected TauronG11Bill loadCurrentDeep(Cursor cursor, boolean lock) {
        TauronG11Bill entity = loadCurrent(cursor, 0, lock);
        int offset = getAllColumns().length;

        TauronPrices tauronPrices = loadCurrentOther(daoSession.getTauronPricesDao(), cursor, offset);
        entity.setTauronPrices(tauronPrices);

        return entity;    
    }

    public TauronG11Bill loadDeep(Long key) {
        assertSinglePk();
        if (key == null) {
            return null;
        }

        StringBuilder builder = new StringBuilder(getSelectDeep());
        builder.append("WHERE ");
        SqlUtils.appendColumnsEqValue(builder, "T", getPkColumns());
        String sql = builder.toString();
        
        String[] keyArray = new String[] { key.toString() };
        Cursor cursor = db.rawQuery(sql, keyArray);
        
        try {
            boolean available = cursor.moveToFirst();
            if (!available) {
                return null;
            } else if (!cursor.isLast()) {
                throw new IllegalStateException("Expected unique result, but count was " + cursor.getCount());
            }
            return loadCurrentDeep(cursor, true);
        } finally {
            cursor.close();
        }
    }
    
    /** Reads all available rows from the given cursor and returns a list of new ImageTO objects. */
    public List<TauronG11Bill> loadAllDeepFromCursor(Cursor cursor) {
        int count = cursor.getCount();
        List<TauronG11Bill> list = new ArrayList<TauronG11Bill>(count);
        
        if (cursor.moveToFirst()) {
            if (identityScope != null) {
                identityScope.lock();
                identityScope.reserveRoom(count);
            }
            try {
                do {
                    list.add(loadCurrentDeep(cursor, false));
                } while (cursor.moveToNext());
            } finally {
                if (identityScope != null) {
                    identityScope.unlock();
                }
            }
        }
        return list;
    }
    
    protected List<TauronG11Bill> loadDeepAllAndCloseCursor(Cursor cursor) {
        try {
            return loadAllDeepFromCursor(cursor);
        } finally {
            cursor.close();
        }
    }
    

    /** A raw-style query where you can pass any WHERE clause and arguments. */
    public List<TauronG11Bill> queryDeep(String where, String... selectionArg) {
        Cursor cursor = db.rawQuery(getSelectDeep() + where, selectionArg);
        return loadDeepAllAndCloseCursor(cursor);
    }
 
} @SuppressWarnings("ALL")
public class TauronG12BillDao extends AbstractDao<TauronG12Bill, Long> {

    public static final String TABLENAME = "TAURON_G12_BILL";

    /**
     * Properties of entity TauronG12Bill.<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 ReadingDayFrom = new Property(1, Integer.class, "readingDayFrom", false, "READING_DAY_FROM");
        public final static Property ReadingDayTo = new Property(2, Integer.class, "readingDayTo", false, "READING_DAY_TO");
        public final static Property ReadingNightFrom = new Property(3, Integer.class, "readingNightFrom", false, "READING_NIGHT_FROM");
        public final static Property ReadingNightTo = new Property(4, Integer.class, "readingNightTo", false, "READING_NIGHT_TO");
        public final static Property DateFrom = new Property(5, java.util.Date.class, "dateFrom", false, "DATE_FROM");
        public final static Property DateTo = new Property(6, java.util.Date.class, "dateTo", false, "DATE_TO");
        public final static Property AmountToPay = new Property(7, Double.class, "amountToPay", false, "AMOUNT_TO_PAY");
        public final static Property PricesId = new Property(8, Long.class, "pricesId", false, "PRICES_ID");
    }

    private DaoSession daoSession;


    public TauronG12BillDao(DaoConfig config) {
        super(config);
    }
    
    public TauronG12BillDao(DaoConfig config, DaoSession daoSession) {
        super(config, daoSession);
        this.daoSession = 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 + "\"TAURON_G12_BILL\" (" + //
                "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id
                "\"READING_DAY_FROM\" INTEGER," + // 1: readingDayFrom
                "\"READING_DAY_TO\" INTEGER," + // 2: readingDayTo
                "\"READING_NIGHT_FROM\" INTEGER," + // 3: readingNightFrom
                "\"READING_NIGHT_TO\" INTEGER," + // 4: readingNightTo
                "\"DATE_FROM\" INTEGER," + // 5: dateFrom
                "\"DATE_TO\" INTEGER," + // 6: dateTo
                "\"AMOUNT_TO_PAY\" REAL," + // 7: amountToPay
                "\"PRICES_ID\" INTEGER);"); // 8: pricesId
    }

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

    @Override
    protected final void bindValues(DatabaseStatement stmt, TauronG12Bill entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
 
        Integer readingDayFrom = entity.getReadingDayFrom();
        if (readingDayFrom != null) {
            stmt.bindLong(2, readingDayFrom);
        }
 
        Integer readingDayTo = entity.getReadingDayTo();
        if (readingDayTo != null) {
            stmt.bindLong(3, readingDayTo);
        }
 
        Integer readingNightFrom = entity.getReadingNightFrom();
        if (readingNightFrom != null) {
            stmt.bindLong(4, readingNightFrom);
        }
 
        Integer readingNightTo = entity.getReadingNightTo();
        if (readingNightTo != null) {
            stmt.bindLong(5, readingNightTo);
        }
 
        java.util.Date dateFrom = entity.getDateFrom();
        if (dateFrom != null) {
            stmt.bindLong(6, dateFrom.getTime());
        }
 
        java.util.Date dateTo = entity.getDateTo();
        if (dateTo != null) {
            stmt.bindLong(7, dateTo.getTime());
        }
 
        Double amountToPay = entity.getAmountToPay();
        if (amountToPay != null) {
            stmt.bindDouble(8, amountToPay);
        }
 
        Long pricesId = entity.getPricesId();
        if (pricesId != null) {
            stmt.bindLong(9, pricesId);
        }
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, TauronG12Bill entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
 
        Integer readingDayFrom = entity.getReadingDayFrom();
        if (readingDayFrom != null) {
            stmt.bindLong(2, readingDayFrom);
        }
 
        Integer readingDayTo = entity.getReadingDayTo();
        if (readingDayTo != null) {
            stmt.bindLong(3, readingDayTo);
        }
 
        Integer readingNightFrom = entity.getReadingNightFrom();
        if (readingNightFrom != null) {
            stmt.bindLong(4, readingNightFrom);
        }
 
        Integer readingNightTo = entity.getReadingNightTo();
        if (readingNightTo != null) {
            stmt.bindLong(5, readingNightTo);
        }
 
        java.util.Date dateFrom = entity.getDateFrom();
        if (dateFrom != null) {
            stmt.bindLong(6, dateFrom.getTime());
        }
 
        java.util.Date dateTo = entity.getDateTo();
        if (dateTo != null) {
            stmt.bindLong(7, dateTo.getTime());
        }
 
        Double amountToPay = entity.getAmountToPay();
        if (amountToPay != null) {
            stmt.bindDouble(8, amountToPay);
        }
 
        Long pricesId = entity.getPricesId();
        if (pricesId != null) {
            stmt.bindLong(9, pricesId);
        }
    }

    @Override
    protected final void attachEntity(TauronG12Bill entity) {
        super.attachEntity(entity);
        entity.__setDaoSession(daoSession);
    }

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

    @Override
    public TauronG12Bill readEntity(Cursor cursor, int offset) {
        TauronG12Bill entity = new TauronG12Bill( //
            cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id
            cursor.isNull(offset + 1) ? null : cursor.getInt(offset + 1), // readingDayFrom
            cursor.isNull(offset + 2) ? null : cursor.getInt(offset + 2), // readingDayTo
            cursor.isNull(offset + 3) ? null : cursor.getInt(offset + 3), // readingNightFrom
            cursor.isNull(offset + 4) ? null : cursor.getInt(offset + 4), // readingNightTo
            cursor.isNull(offset + 5) ? null : new java.util.Date(cursor.getLong(offset + 5)), // dateFrom
            cursor.isNull(offset + 6) ? null : new java.util.Date(cursor.getLong(offset + 6)), // dateTo
            cursor.isNull(offset + 7) ? null : cursor.getDouble(offset + 7), // amountToPay
            cursor.isNull(offset + 8) ? null : cursor.getLong(offset + 8) // pricesId
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, TauronG12Bill entity, int offset) {
        entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
        entity.setReadingDayFrom(cursor.isNull(offset + 1) ? null : cursor.getInt(offset + 1));
        entity.setReadingDayTo(cursor.isNull(offset + 2) ? null : cursor.getInt(offset + 2));
        entity.setReadingNightFrom(cursor.isNull(offset + 3) ? null : cursor.getInt(offset + 3));
        entity.setReadingNightTo(cursor.isNull(offset + 4) ? null : cursor.getInt(offset + 4));
        entity.setDateFrom(cursor.isNull(offset + 5) ? null : new java.util.Date(cursor.getLong(offset + 5)));
        entity.setDateTo(cursor.isNull(offset + 6) ? null : new java.util.Date(cursor.getLong(offset + 6)));
        entity.setAmountToPay(cursor.isNull(offset + 7) ? null : cursor.getDouble(offset + 7));
        entity.setPricesId(cursor.isNull(offset + 8) ? null : cursor.getLong(offset + 8));
     }
    
    @Override
    protected final Long updateKeyAfterInsert(TauronG12Bill entity, long rowId) {
        entity.setId(rowId);
        return rowId;
    }
    
    @Override
    public Long getKey(TauronG12Bill entity) {
        if(entity != null) {
            return entity.getId();
        } else {
            return null;
        }
    }

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

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

    protected String getSelectDeep() {
        if (selectDeep == null) {
            StringBuilder builder = new StringBuilder("SELECT ");
            SqlUtils.appendColumns(builder, "T", getAllColumns());
            builder.append(',');
            SqlUtils.appendColumns(builder, "T0", daoSession.getTauronPricesDao().getAllColumns());
            builder.append(" FROM TAURON_G12_BILL T");
            builder.append(" LEFT JOIN TAURON_PRICES T0 ON T.\"PRICES_ID\"=T0.\"_id\"");
            builder.append(' ');
            selectDeep = builder.toString();
        }
        return selectDeep;
    }
    
    protected TauronG12Bill loadCurrentDeep(Cursor cursor, boolean lock) {
        TauronG12Bill entity = loadCurrent(cursor, 0, lock);
        int offset = getAllColumns().length;

        TauronPrices tauronPrices = loadCurrentOther(daoSession.getTauronPricesDao(), cursor, offset);
        entity.setTauronPrices(tauronPrices);

        return entity;    
    }

    public TauronG12Bill loadDeep(Long key) {
        assertSinglePk();
        if (key == null) {
            return null;
        }

        StringBuilder builder = new StringBuilder(getSelectDeep());
        builder.append("WHERE ");
        SqlUtils.appendColumnsEqValue(builder, "T", getPkColumns());
        String sql = builder.toString();
        
        String[] keyArray = new String[] { key.toString() };
        Cursor cursor = db.rawQuery(sql, keyArray);
        
        try {
            boolean available = cursor.moveToFirst();
            if (!available) {
                return null;
            } else if (!cursor.isLast()) {
                throw new IllegalStateException("Expected unique result, but count was " + cursor.getCount());
            }
            return loadCurrentDeep(cursor, true);
        } finally {
            cursor.close();
        }
    }
    
    /** Reads all available rows from the given cursor and returns a list of new ImageTO objects. */
    public List<TauronG12Bill> loadAllDeepFromCursor(Cursor cursor) {
        int count = cursor.getCount();
        List<TauronG12Bill> list = new ArrayList<TauronG12Bill>(count);
        
        if (cursor.moveToFirst()) {
            if (identityScope != null) {
                identityScope.lock();
                identityScope.reserveRoom(count);
            }
            try {
                do {
                    list.add(loadCurrentDeep(cursor, false));
                } while (cursor.moveToNext());
            } finally {
                if (identityScope != null) {
                    identityScope.unlock();
                }
            }
        }
        return list;
    }
    
    protected List<TauronG12Bill> loadDeepAllAndCloseCursor(Cursor cursor) {
        try {
            return loadAllDeepFromCursor(cursor);
        } finally {
            cursor.close();
        }
    }
    

    /** A raw-style query where you can pass any WHERE clause and arguments. */
    public List<TauronG12Bill> queryDeep(String where, String... selectionArg) {
        Cursor cursor = db.rawQuery(getSelectDeep() + where, selectionArg);
        return loadDeepAllAndCloseCursor(cursor);
    }
 
} public enum BillType {

    PGE_G11,
    PGE_G12,
    PGNIG,
    TAURON_G11,
    TAURON_G12;

    public AbstractDao<? extends Bill, Long> getDao() {
        assertNotNull(Database.getSession());
        switch (this) {
            case PGE_G11:
                return Database.getSession().getPgeG11BillDao();
            case PGE_G12:
                return Database.getSession().getPgeG12BillDao();
            case PGNIG:
                return Database.getSession().getPgnigBillDao();
            case TAURON_G11:
                return Database.getSession().getTauronG11BillDao();
            case TAURON_G12:
                return Database.getSession().getTauronG12BillDao();
        }
        throw new RuntimeException("Type " + this + " not handled.");
    }

    public AbstractDao<? extends Prices, Long> getPricesDao() {
        assertNotNull(Database.getSession());
        switch (this) {
            case PGE_G11:
            case PGE_G12:
                return Database.getSession().getPgePricesDao();
            case PGNIG:
                return Database.getSession().getPgnigPricesDao();
            case TAURON_G11:
            case TAURON_G12:
                return Database.getSession().getTauronPricesDao();
        }
        throw new RuntimeException("Type " + this + " not handled.");
    }

    public static BillType valueOf(Bill bill) {
        if (bill instanceof PgeG11Bill) return BillType.PGE_G11;
        else if (bill instanceof PgeG12Bill) return BillType.PGE_G12;
        else if (bill instanceof PgnigBill) return BillType.PGNIG;
        else if (bill instanceof TauronG11Bill) return BillType.TAURON_G11;
        else if (bill instanceof TauronG12Bill) return BillType.TAURON_G12;
        else throw new RuntimeException("Bill type " +  bill + " is not handled");
    }

    private void assertNotNull(final DaoSession session) {
        if (session == null)
            throw new DbNotInitializedYetException();
    }
} public static SqlTriggerBuilder createTrigger(final String triggerName) {
    final StringBuilder sql = new StringBuilder("CREATE TRIGGER " + triggerName);
    return new SqlTriggerBuilder(sql);
} public static SqlTriggerBuilder deleteFrom(final String tablename) {
    final StringBuilder sql = new StringBuilder("DELETE FROM " + tablename);
    return new SqlTriggerBuilder(sql);
} public static String getNew(final Property col) {
    return "new." + col.columnName;
} public static String getOld(final Property col) {
    return "old." + col.columnName;
} public static SqlTriggerBuilder insertInto(final String tablename) {
    final StringBuilder sql = new StringBuilder("INSERT INTO " + tablename);
    return new SqlTriggerBuilder(sql);
}
import android.database.sqlite.SQLiteDatabase;
import org.greenrobot.greendao.database.Database;
import pl.srw.billcalculator.db.dao.HistoryDao;
import pl.srw.billcalculator.db.dao.PgeG11BillDao;
import pl.srw.billcalculator.db.dao.PgeG12BillDao;
import pl.srw.billcalculator.db.dao.PgnigBillDao;
import pl.srw.billcalculator.db.dao.TauronG11BillDao;
import pl.srw.billcalculator.db.dao.TauronG12BillDao;
import pl.srw.billcalculator.persistence.type.BillType;
import static pl.srw.billcalculator.persistence.SqlTriggerBuilder.createTrigger;
import static pl.srw.billcalculator.persistence.SqlTriggerBuilder.deleteFrom;
import static pl.srw.billcalculator.persistence.SqlTriggerBuilder.getNew;
import static pl.srw.billcalculator.persistence.SqlTriggerBuilder.getOld;
import static pl.srw.billcalculator.persistence.SqlTriggerBuilder.insertInto;
package pl.srw.billcalculator.persistence;





public final class Triggers {

    private static final String DELETE = "DELETE";
    private static final String INSERT = "INSERT";

    private static final String[] BILL_INSERT_TRIGGERS = {
            insertHistoryTrigger("bill_pgeG11_insert_trigger", PgeG11BillDao.TABLENAME, BillType.PGE_G11.toString()),
            insertHistoryTrigger("bill_pgeG12_insert_trigger", PgeG12BillDao.TABLENAME, BillType.PGE_G12.toString()),
            insertHistoryTrigger("bill_pgnig_insert_trigger", PgnigBillDao.TABLENAME, BillType.PGNIG.toString()),
            insertHistoryTrigger("bill_tauronG11_insert_trigger", TauronG11BillDao.TABLENAME, BillType.TAURON_G11.toString()),