package com.cc.infosur.greendao;

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 LINK.
 */
public class Link {

    private Long id;
    private Double length;
    private Double speed;
    private long nodeFromId;
    private long nodeToId;

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

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

    private Node nodeFrom;
    private Long nodeFrom__resolvedKey;

    private Node nodeTo;
    private Long nodeTo__resolvedKey;


    public Link() {
    }

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

    public Link(Long id, Double length, Double speed, long nodeFromId, long nodeToId) {
        this.id = id;
        this.length = length;
        this.speed = speed;
        this.nodeFromId = nodeFromId;
        this.nodeToId = nodeToId;
    }

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

    public Long getId() {
        return id;
    }

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

    public Double getLength() {
        return length;
    }

    public void setLength(Double length) {
        this.length = length;
    }

    public Double getSpeed() {
        return speed;
    }

    public void setSpeed(Double speed) {
        this.speed = speed;
    }

    public long getNodeFromId() {
        return nodeFromId;
    }

    public void setNodeFromId(long nodeFromId) {
        this.nodeFromId = nodeFromId;
    }

    public long getNodeToId() {
        return nodeToId;
    }

    public void setNodeToId(long nodeToId) {
        this.nodeToId = nodeToId;
    }

    /** To-one relationship, resolved on first access. */
    public Node getNodeFrom() {
        long __key = this.nodeFromId;
        if (nodeFrom__resolvedKey == null || !nodeFrom__resolvedKey.equals(__key)) {
            if (daoSession == null) {
                throw new DaoException("Entity is detached from DAO context");
            }
            NodeDao targetDao = daoSession.getNodeDao();
            Node nodeFromNew = targetDao.load(__key);
            synchronized (this) {
                nodeFrom = nodeFromNew;
            	nodeFrom__resolvedKey = __key;
            }
        }
        return nodeFrom;
    }

    public void setNodeFrom(Node nodeFrom) {
        if (nodeFrom == null) {
            throw new DaoException("To-one property 'nodeFromId' has not-null constraint; cannot set to-one to null");
        }
        synchronized (this) {
            this.nodeFrom = nodeFrom;
            nodeFromId = nodeFrom.getId();
            nodeFrom__resolvedKey = nodeFromId;
        }
    }

    /** To-one relationship, resolved on first access. */
    public Node getNodeTo() {
        long __key = this.nodeToId;
        if (nodeTo__resolvedKey == null || !nodeTo__resolvedKey.equals(__key)) {
            if (daoSession == null) {
                throw new DaoException("Entity is detached from DAO context");
            }
            NodeDao targetDao = daoSession.getNodeDao();
            Node nodeToNew = targetDao.load(__key);
            synchronized (this) {
                nodeTo = nodeToNew;
            	nodeTo__resolvedKey = __key;
            }
        }
        return nodeTo;
    }

    public void setNodeTo(Node nodeTo) {
        if (nodeTo == null) {
            throw new DaoException("To-one property 'nodeToId' has not-null constraint; cannot set to-one to null");
        }
        synchronized (this) {
            this.nodeTo = nodeTo;
            nodeToId = nodeTo.getId();
            nodeTo__resolvedKey = nodeToId;
        }
    }

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

}
