package com.jingpu.android.apersistance.greendao.model;

import com.jingpu.android.apersistance.greendao.model.DaoSession;
import de.greenrobot.dao.DaoException;

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. Enable "keep" sections if you want to edit. 
/**
 * Entity mapped to table "CITEM".
 */
public class CItem {

    private Long cId;
    private Long id;
    private int iImId;
    /** Not-null value. */
    private String iName;
    private float iPrice;
    /** Not-null value. */
    private String iData;

    /** Used to resolve relations */
    private transient DaoSession daoSession;

    /** Used for active entity operations. */
    private transient CItemDao myDao;

    private Category category;
    private Long category__resolvedKey;


    public CItem() {
    }

    public CItem(Long id) {
        this.id = id;
    }

    public CItem(Long cId, Long id, int iImId, String iName, float iPrice, String iData) {
        this.cId = cId;
        this.id = id;
        this.iImId = iImId;
        this.iName = iName;
        this.iPrice = iPrice;
        this.iData = iData;
    }

    /** called by internal mechanisms, do not call yourself. */
    public void __setDaoSession(DaoSession daoSession) {
        this.daoSession = daoSession;
        myDao = daoSession != null ? daoSession.getCItemDao() : null;
    }

    public Long getCId() {
        return cId;
    }

    public void setCId(Long cId) {
        this.cId = cId;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public int getIImId() {
        return iImId;
    }

    public void setIImId(int iImId) {
        this.iImId = iImId;
    }

    /** Not-null value. */
    public String getIName() {
        return iName;
    }

    /** Not-null value; ensure this value is available before it is saved to the database. */
    public void setIName(String iName) {
        this.iName = iName;
    }

    public float getIPrice() {
        return iPrice;
    }

    public void setIPrice(float iPrice) {
        this.iPrice = iPrice;
    }

    /** Not-null value. */
    public String getIData() {
        return iData;
    }

    /** Not-null value; ensure this value is available before it is saved to the database. */
    public void setIData(String iData) {
        this.iData = iData;
    }

    /** To-one relationship, resolved on first access. */
    public Category getCategory() {
        Long __key = this.cId;
        if (category__resolvedKey == null || !category__resolvedKey.equals(__key)) {
            if (daoSession == null) {
                throw new DaoException("Entity is detached from DAO context");
            }
            CategoryDao targetDao = daoSession.getCategoryDao();
            Category categoryNew = targetDao.load(__key);
            synchronized (this) {
                category = categoryNew;
            	category__resolvedKey = __key;
            }
        }
        return category;
    }

    public void setCategory(Category category) {
        synchronized (this) {
            this.category = category;
            cId = category == null ? null : category.getId();
            category__resolvedKey = cId;
        }
    }

    /** Convenient call for {@link AbstractDao#delete(Object)}. Entity must attached to an entity context. */
    public void delete() {
        if (myDao == null) {
            throw new DaoException("Entity is detached from DAO context");
        }    
        myDao.delete(this);
    }

    /** Convenient call for {@link AbstractDao#update(Object)}. Entity must attached to an entity context. */
    public void update() {
        if (myDao == null) {
            throw new DaoException("Entity is detached from DAO context");
        }    
        myDao.update(this);
    }

    /** Convenient call for {@link AbstractDao#refresh(Object)}. Entity must attached to an entity context. */
    public void refresh() {
        if (myDao == null) {
            throw new DaoException("Entity is detached from DAO context");
        }    
        myDao.refresh(this);
    }

}
