entities.Candidate.java Source code

Java tutorial

Introduction

Here is the source code for entities.Candidate.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 = "candidate")
public class Candidate implements Serializable {
    public Candidate() {
    }

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

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

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

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

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

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

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

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

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

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

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

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

    public static List queryCandidate(PersistentSession session, String condition, String orderBy)
            throws PersistentException {
        StringBuffer sb = new StringBuffer("From entities.Candidate as Candidate");
        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 queryCandidate(PersistentSession session, String condition, String orderBy,
            org.hibernate.LockMode lockMode) throws PersistentException {
        StringBuffer sb = new StringBuffer("From entities.Candidate as Candidate");
        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("Candidate", lockMode);
            return query.list();
        } catch (Exception e) {
            e.printStackTrace();
            throw new PersistentException(e);
        }
    }

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

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

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

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

    public static Candidate loadCandidateByQuery(PersistentSession session, String condition, String orderBy)
            throws PersistentException {
        Candidate[] candidates = listCandidateByQuery(session, condition, orderBy);
        if (candidates != null && candidates.length > 0)
            return candidates[0];
        else
            return null;
    }

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

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

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

    public static java.util.Iterator iterateCandidateByQuery(PersistentSession session, String condition,
            String orderBy) throws PersistentException {
        StringBuffer sb = new StringBuffer("From entities.Candidate as Candidate");
        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 iterateCandidateByQuery(PersistentSession session, String condition,
            String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
        StringBuffer sb = new StringBuffer("From entities.Candidate as Candidate");
        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("Candidate", lockMode);
            return query.iterate();
        } catch (Exception e) {
            e.printStackTrace();
            throw new PersistentException(e);
        }
    }

    public static Candidate loadCandidateByCriteria(CandidateCriteria candidateCriteria) {
        Candidate[] candidates = listCandidateByCriteria(candidateCriteria);
        if (candidates == null || candidates.length == 0) {
            return null;
        }
        return candidates[0];
    }

    public static Candidate[] listCandidateByCriteria(CandidateCriteria candidateCriteria) {
        return candidateCriteria.listCandidate();
    }

    public static Candidate createCandidate() {
        return new entities.Candidate();
    }

    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 (getVoter() != null) {
                getVoter().getCandidate().remove(this);
            }

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

            entities.Vote[] lVotes = (entities.Vote[]) getVote().toArray(new entities.Vote[getVote().size()]);
            for (int i = 0; i < lVotes.length; i++) {
                lVotes[i].setCandidate(null);
            }
            return delete();
        } catch (Exception e) {
            e.printStackTrace();
            throw new PersistentException(e);
        }
    }

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

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

            entities.Vote[] lVotes = (entities.Vote[]) getVote().toArray(new entities.Vote[getVote().size()]);
            for (int i = 0; i < lVotes.length; i++) {
                lVotes[i].setCandidate(null);
            }
            try {
                session.delete(this);
                return true;
            } catch (Exception e) {
                return false;
            }
        } catch (Exception e) {
            e.printStackTrace();
            throw new PersistentException(e);
        }
    }

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

    @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;

    @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;

    @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;

    @OneToMany(mappedBy = "candidate", targetEntity = entities.Vote.class)
    @org.hibernate.annotations.Cascade({ org.hibernate.annotations.CascadeType.SAVE_UPDATE,
            org.hibernate.annotations.CascadeType.LOCK })
    @org.hibernate.annotations.LazyCollection(org.hibernate.annotations.LazyCollectionOption.EXTRA)
    private java.util.Set vote = new java.util.HashSet();

    private void setCandidate_id(int value) {
        this.candidate_id = value;
    }

    public int getCandidate_id() {
        return candidate_id;
    }

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

    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 setVoter(entities.Voter value) {
        this.voter = value;
    }

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

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

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

    public void setVote(java.util.Set value) {
        this.vote = value;
    }

    public java.util.Set getVote() {
        return vote;
    }

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

}