entities.Vote.java Source code

Java tutorial

Introduction

Here is the source code for entities.Vote.java

Source

/**
 * "Visual Paradigm: DO NOT MODIFY THIS FILE!"
 * 
 * This is an automatic generated file. It will be regenerated every time 
 * you generate persistence class.
 * 
 * Modifying its content may cause the program not work, or your work may lost.
 */

/**
 * Licensee: btwesigye
 * License Type: Purchased
 */
package entities;

import org.orm.*;
import org.hibernate.Query;
import org.hibernate.LockMode;
import java.util.List;

import java.io.Serializable;
import javax.persistence.*;

@Entity
@org.hibernate.annotations.Proxy(lazy = false)
@Table(name = "vote")
public class Vote implements Serializable {
    public Vote() {
    }

    public static Vote loadVoteByORMID(int vote_id) throws PersistentException {
        try {
            PersistentSession session = entities.EVotingPersistentManager.instance().getSession();
            return loadVoteByORMID(session, vote_id);
        } catch (Exception e) {
            e.printStackTrace();
            throw new PersistentException(e);
        }
    }

    public static Vote getVoteByORMID(int vote_id) throws PersistentException {
        try {
            PersistentSession session = entities.EVotingPersistentManager.instance().getSession();
            return getVoteByORMID(session, vote_id);
        } catch (Exception e) {
            e.printStackTrace();
            throw new PersistentException(e);
        }
    }

    public static Vote loadVoteByORMID(int vote_id, org.hibernate.LockMode lockMode) throws PersistentException {
        try {
            PersistentSession session = entities.EVotingPersistentManager.instance().getSession();
            return loadVoteByORMID(session, vote_id, lockMode);
        } catch (Exception e) {
            e.printStackTrace();
            throw new PersistentException(e);
        }
    }

    public static Vote getVoteByORMID(int vote_id, org.hibernate.LockMode lockMode) throws PersistentException {
        try {
            PersistentSession session = entities.EVotingPersistentManager.instance().getSession();
            return getVoteByORMID(session, vote_id, lockMode);
        } catch (Exception e) {
            e.printStackTrace();
            throw new PersistentException(e);
        }
    }

    public static Vote loadVoteByORMID(PersistentSession session, int vote_id) throws PersistentException {
        try {
            return (Vote) session.load(entities.Vote.class, new Integer(vote_id));
        } catch (Exception e) {
            e.printStackTrace();
            throw new PersistentException(e);
        }
    }

    public static Vote getVoteByORMID(PersistentSession session, int vote_id) throws PersistentException {
        try {
            return (Vote) session.get(entities.Vote.class, new Integer(vote_id));
        } catch (Exception e) {
            e.printStackTrace();
            throw new PersistentException(e);
        }
    }

    public static Vote loadVoteByORMID(PersistentSession session, int vote_id, org.hibernate.LockMode lockMode)
            throws PersistentException {
        try {
            return (Vote) session.load(entities.Vote.class, new Integer(vote_id), lockMode);
        } catch (Exception e) {
            e.printStackTrace();
            throw new PersistentException(e);
        }
    }

    public static Vote getVoteByORMID(PersistentSession session, int vote_id, org.hibernate.LockMode lockMode)
            throws PersistentException {
        try {
            return (Vote) session.get(entities.Vote.class, new Integer(vote_id), lockMode);
        } catch (Exception e) {
            e.printStackTrace();
            throw new PersistentException(e);
        }
    }

    public static List queryVote(String condition, String orderBy) throws PersistentException {
        try {
            PersistentSession session = entities.EVotingPersistentManager.instance().getSession();
            return queryVote(session, condition, orderBy);
        } catch (Exception e) {
            e.printStackTrace();
            throw new PersistentException(e);
        }
    }

    public static List queryVote(String condition, String orderBy, org.hibernate.LockMode lockMode)
            throws PersistentException {
        try {
            PersistentSession session = entities.EVotingPersistentManager.instance().getSession();
            return queryVote(session, condition, orderBy, lockMode);
        } catch (Exception e) {
            e.printStackTrace();
            throw new PersistentException(e);
        }
    }

    public static Vote[] listVoteByQuery(String condition, String orderBy) throws PersistentException {
        try {
            PersistentSession session = entities.EVotingPersistentManager.instance().getSession();
            return listVoteByQuery(session, condition, orderBy);
        } catch (Exception e) {
            e.printStackTrace();
            throw new PersistentException(e);
        }
    }

    public static Vote[] listVoteByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode)
            throws PersistentException {
        try {
            PersistentSession session = entities.EVotingPersistentManager.instance().getSession();
            return listVoteByQuery(session, condition, orderBy, lockMode);
        } catch (Exception e) {
            e.printStackTrace();
            throw new PersistentException(e);
        }
    }

    public static List queryVote(PersistentSession session, String condition, String orderBy)
            throws PersistentException {
        StringBuffer sb = new StringBuffer("From entities.Vote as Vote");
        if (condition != null)
            sb.append(" Where ").append(condition);
        if (orderBy != null)
            sb.append(" Order By ").append(orderBy);
        try {
            Query query = session.createQuery(sb.toString());
            return query.list();
        } catch (Exception e) {
            e.printStackTrace();
            throw new PersistentException(e);
        }
    }

    public static List queryVote(PersistentSession session, String condition, String orderBy,
            org.hibernate.LockMode lockMode) throws PersistentException {
        StringBuffer sb = new StringBuffer("From entities.Vote as Vote");
        if (condition != null)
            sb.append(" Where ").append(condition);
        if (orderBy != null)
            sb.append(" Order By ").append(orderBy);
        try {
            Query query = session.createQuery(sb.toString());
            query.setLockMode("Vote", lockMode);
            return query.list();
        } catch (Exception e) {
            e.printStackTrace();
            throw new PersistentException(e);
        }
    }

    public static Vote[] listVoteByQuery(PersistentSession session, String condition, String orderBy)
            throws PersistentException {
        try {
            List list = queryVote(session, condition, orderBy);
            return (Vote[]) list.toArray(new Vote[list.size()]);
        } catch (Exception e) {
            e.printStackTrace();
            throw new PersistentException(e);
        }
    }

    public static Vote[] listVoteByQuery(PersistentSession session, String condition, String orderBy,
            org.hibernate.LockMode lockMode) throws PersistentException {
        try {
            List list = queryVote(session, condition, orderBy, lockMode);
            return (Vote[]) list.toArray(new Vote[list.size()]);
        } catch (Exception e) {
            e.printStackTrace();
            throw new PersistentException(e);
        }
    }

    public static Vote loadVoteByQuery(String condition, String orderBy) throws PersistentException {
        try {
            PersistentSession session = entities.EVotingPersistentManager.instance().getSession();
            return loadVoteByQuery(session, condition, orderBy);
        } catch (Exception e) {
            e.printStackTrace();
            throw new PersistentException(e);
        }
    }

    public static Vote loadVoteByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode)
            throws PersistentException {
        try {
            PersistentSession session = entities.EVotingPersistentManager.instance().getSession();
            return loadVoteByQuery(session, condition, orderBy, lockMode);
        } catch (Exception e) {
            e.printStackTrace();
            throw new PersistentException(e);
        }
    }

    public static Vote loadVoteByQuery(PersistentSession session, String condition, String orderBy)
            throws PersistentException {
        Vote[] votes = listVoteByQuery(session, condition, orderBy);
        if (votes != null && votes.length > 0)
            return votes[0];
        else
            return null;
    }

    public static Vote loadVoteByQuery(PersistentSession session, String condition, String orderBy,
            org.hibernate.LockMode lockMode) throws PersistentException {
        Vote[] votes = listVoteByQuery(session, condition, orderBy, lockMode);
        if (votes != null && votes.length > 0)
            return votes[0];
        else
            return null;
    }

    public static java.util.Iterator iterateVoteByQuery(String condition, String orderBy)
            throws PersistentException {
        try {
            PersistentSession session = entities.EVotingPersistentManager.instance().getSession();
            return iterateVoteByQuery(session, condition, orderBy);
        } catch (Exception e) {
            e.printStackTrace();
            throw new PersistentException(e);
        }
    }

    public static java.util.Iterator iterateVoteByQuery(String condition, String orderBy,
            org.hibernate.LockMode lockMode) throws PersistentException {
        try {
            PersistentSession session = entities.EVotingPersistentManager.instance().getSession();
            return iterateVoteByQuery(session, condition, orderBy, lockMode);
        } catch (Exception e) {
            e.printStackTrace();
            throw new PersistentException(e);
        }
    }

    public static java.util.Iterator iterateVoteByQuery(PersistentSession session, String condition, String orderBy)
            throws PersistentException {
        StringBuffer sb = new StringBuffer("From entities.Vote as Vote");
        if (condition != null)
            sb.append(" Where ").append(condition);
        if (orderBy != null)
            sb.append(" Order By ").append(orderBy);
        try {
            Query query = session.createQuery(sb.toString());
            return query.iterate();
        } catch (Exception e) {
            e.printStackTrace();
            throw new PersistentException(e);
        }
    }

    public static java.util.Iterator iterateVoteByQuery(PersistentSession session, String condition, String orderBy,
            org.hibernate.LockMode lockMode) throws PersistentException {
        StringBuffer sb = new StringBuffer("From entities.Vote as Vote");
        if (condition != null)
            sb.append(" Where ").append(condition);
        if (orderBy != null)
            sb.append(" Order By ").append(orderBy);
        try {
            Query query = session.createQuery(sb.toString());
            query.setLockMode("Vote", lockMode);
            return query.iterate();
        } catch (Exception e) {
            e.printStackTrace();
            throw new PersistentException(e);
        }
    }

    public static Vote loadVoteByCriteria(VoteCriteria voteCriteria) {
        Vote[] votes = listVoteByCriteria(voteCriteria);
        if (votes == null || votes.length == 0) {
            return null;
        }
        return votes[0];
    }

    public static Vote[] listVoteByCriteria(VoteCriteria voteCriteria) {
        return voteCriteria.listVote();
    }

    public static Vote createVote() {
        return new entities.Vote();
    }

    public boolean save() throws PersistentException {
        try {
            entities.EVotingPersistentManager.instance().saveObject(this);
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            throw new PersistentException(e);
        }
    }

    public boolean delete() throws PersistentException {
        try {
            entities.EVotingPersistentManager.instance().deleteObject(this);
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            throw new PersistentException(e);
        }
    }

    public boolean refresh() throws PersistentException {
        try {
            entities.EVotingPersistentManager.instance().getSession().refresh(this);
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            throw new PersistentException(e);
        }
    }

    public boolean evict() throws PersistentException {
        try {
            entities.EVotingPersistentManager.instance().getSession().evict(this);
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            throw new PersistentException(e);
        }
    }

    public boolean deleteAndDissociate() throws PersistentException {
        try {
            if (getPost() != null) {
                getPost().getVote().remove(this);
            }

            if (getCandidate() != null) {
                getCandidate().getVote().remove(this);
            }

            if (getVoter() != null) {
                getVoter().getVote().remove(this);
            }

            return delete();
        } catch (Exception e) {
            e.printStackTrace();
            throw new PersistentException(e);
        }
    }

    public boolean deleteAndDissociate(org.orm.PersistentSession session) throws PersistentException {
        try {
            if (getPost() != null) {
                getPost().getVote().remove(this);
            }

            if (getCandidate() != null) {
                getCandidate().getVote().remove(this);
            }

            if (getVoter() != null) {
                getVoter().getVote().remove(this);
            }

            try {
                session.delete(this);
                return true;
            } catch (Exception e) {
                return false;
            }
        } catch (Exception e) {
            e.printStackTrace();
            throw new PersistentException(e);
        }
    }

    @Column(name = "vote_id", nullable = false, length = 10)
    @Id
    @GeneratedValue(generator = "ENTITIES_VOTE_VOTE_ID_GENERATOR")
    @org.hibernate.annotations.GenericGenerator(name = "ENTITIES_VOTE_VOTE_ID_GENERATOR", strategy = "native")
    private int vote_id;

    @ManyToOne(targetEntity = entities.Post.class, fetch = FetchType.LAZY)
    @org.hibernate.annotations.Cascade({ org.hibernate.annotations.CascadeType.LOCK })
    @JoinColumns({ @JoinColumn(name = "post_id", referencedColumnName = "post_id", nullable = false) })
    private entities.Post post;

    @ManyToOne(targetEntity = entities.Candidate.class, fetch = FetchType.LAZY)
    @org.hibernate.annotations.Cascade({ org.hibernate.annotations.CascadeType.LOCK })
    @JoinColumns({ @JoinColumn(name = "candidate_id", referencedColumnName = "candidate_id", nullable = false) })
    private entities.Candidate candidate;

    @Column(name = "vote_date_time", nullable = false)
    @Temporal(TemporalType.DATE)
    private java.util.Date vote_date_time;

    @Column(name = "is_deleted", nullable = true, length = 1)
    private Integer is_deleted;

    @Column(name = "is_active", nullable = false, length = 1)
    private int is_active;

    @Column(name = "add_date", nullable = true)
    private java.sql.Timestamp add_date;

    @Column(name = "add_by", nullable = true, length = 11)
    private Integer add_by;

    @Column(name = "last_edit_date", nullable = true)
    private java.sql.Timestamp last_edit_date;

    @Column(name = "last_edit_by", nullable = true, length = 11)
    private Integer last_edit_by;

    @ManyToOne(targetEntity = entities.Voter.class, fetch = FetchType.LAZY)
    @org.hibernate.annotations.Cascade({ org.hibernate.annotations.CascadeType.LOCK })
    @JoinColumns({ @JoinColumn(name = "voter_id", referencedColumnName = "voter_id", nullable = false) })
    private entities.Voter voter;

    private void setVote_id(int value) {
        this.vote_id = value;
    }

    public int getVote_id() {
        return vote_id;
    }

    public int getORMID() {
        return getVote_id();
    }

    public void setVote_date_time(java.util.Date value) {
        this.vote_date_time = value;
    }

    public java.util.Date getVote_date_time() {
        return vote_date_time;
    }

    public void setIs_deleted(int value) {
        setIs_deleted(new Integer(value));
    }

    public void setIs_deleted(Integer value) {
        this.is_deleted = value;
    }

    public Integer getIs_deleted() {
        return is_deleted;
    }

    public void setIs_active(int value) {
        this.is_active = value;
    }

    public int getIs_active() {
        return is_active;
    }

    public void setAdd_date(java.sql.Timestamp value) {
        this.add_date = value;
    }

    public java.sql.Timestamp getAdd_date() {
        return add_date;
    }

    public void setAdd_by(int value) {
        setAdd_by(new Integer(value));
    }

    public void setAdd_by(Integer value) {
        this.add_by = value;
    }

    public Integer getAdd_by() {
        return add_by;
    }

    public void setLast_edit_date(java.sql.Timestamp value) {
        this.last_edit_date = value;
    }

    public java.sql.Timestamp getLast_edit_date() {
        return last_edit_date;
    }

    public void setLast_edit_by(int value) {
        setLast_edit_by(new Integer(value));
    }

    public void setLast_edit_by(Integer value) {
        this.last_edit_by = value;
    }

    public Integer getLast_edit_by() {
        return last_edit_by;
    }

    public void setPost(entities.Post value) {
        this.post = value;
    }

    public entities.Post getPost() {
        return post;
    }

    public void setCandidate(entities.Candidate value) {
        this.candidate = value;
    }

    public entities.Candidate getCandidate() {
        return candidate;
    }

    public void setVoter(entities.Voter value) {
        this.voter = value;
    }

    public entities.Voter getVoter() {
        return voter;
    }

    public String toString() {
        return String.valueOf(getVote_id());
    }

}