package com.cc.infosur.greendao;

import java.util.List;
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 NODE.
 */
public class Node {

    private Long id;
    private Double latitude;
    private Double longitude;
    private Long linkForward;
    private Integer positionForward;
    private Long linkBackward;
    private Integer positionBackward;
    private Double distance;
    private Long previousId;

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

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

    private Link previous;
    private Long previous__resolvedKey;

    private List<Link> outs;

    public Node() {
    }

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

    public Node(Long id, Double latitude, Double longitude, Long linkForward, Integer positionForward, Long linkBackward, Integer positionBackward, Double distance, Long previousId) {
        this.id = id;
        this.latitude = latitude;
        this.longitude = longitude;
        this.linkForward = linkForward;
        this.positionForward = positionForward;
        this.linkBackward = linkBackward;
        this.positionBackward = positionBackward;
        this.distance = distance;
        this.previousId = previousId;
    }

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

    public Long getId() {
        return id;
    }

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

    public Double getLatitude() {
        return latitude;
    }

    public void setLatitude(Double latitude) {
        this.latitude = latitude;
    }

    public Double getLongitude() {
        return longitude;
    }

    public void setLongitude(Double longitude) {
        this.longitude = longitude;
    }

    public Long getLinkForward() {
        return linkForward;
    }

    public void setLinkForward(Long linkForward) {
        this.linkForward = linkForward;
    }

    public Integer getPositionForward() {
        return positionForward;
    }

    public void setPositionForward(Integer positionForward) {
        this.positionForward = positionForward;
    }

    public Long getLinkBackward() {
        return linkBackward;
    }

    public void setLinkBackward(Long linkBackward) {
        this.linkBackward = linkBackward;
    }

    public Integer getPositionBackward() {
        return positionBackward;
    }

    public void setPositionBackward(Integer positionBackward) {
        this.positionBackward = positionBackward;
    }

    public Double getDistance() {
        return distance;
    }

    public void setDistance(Double distance) {
        this.distance = distance;
    }

    public Long getPreviousId() {
        return previousId;
    }

    public void setPreviousId(Long previousId) {
        this.previousId = previousId;
    }

    /** To-one relationship, resolved on first access. */
    public Link getPrevious() {
        Long __key = this.previousId;
        if (previous__resolvedKey == null || !previous__resolvedKey.equals(__key)) {
            if (daoSession == null) {
                throw new DaoException("Entity is detached from DAO context");
            }
            LinkDao targetDao = daoSession.getLinkDao();
            Link previousNew = targetDao.load(__key);
            synchronized (this) {
                previous = previousNew;
            	previous__resolvedKey = __key;
            }
        }
        return previous;
    }

    public void setPrevious(Link previous) {
        synchronized (this) {
            this.previous = previous;
            previousId = previous == null ? null : previous.getId();
            previous__resolvedKey = previousId;
        }
    }

    /** To-many relationship, resolved on first access (and after reset). Changes to to-many relations are not persisted, make changes to the target entity. */
    public List<Link> getOuts() {
        if (outs == null) {
            if (daoSession == null) {
                throw new DaoException("Entity is detached from DAO context");
            }
            LinkDao targetDao = daoSession.getLinkDao();
            List<Link> outsNew = targetDao._queryNode_Outs(id);
            synchronized (this) {
                if(outs == null) {
                    outs = outsNew;
                }
            }
        }
        return outs;
    }

    /** Resets a to-many relationship, making the next get call to query for a fresh result. */
    public synchronized void resetOuts() {
        outs = null;
    }

    /** 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);
    }

}
