Example usage for org.hibernate Session load

List of usage examples for org.hibernate Session load

Introduction

In this page you can find the example usage for org.hibernate Session load.

Prototype

void load(Object object, Serializable id);

Source Link

Document

Read the persistent state associated with the given identifier into the given transient instance.

Usage

From source file:com.appeligo.search.actions.home.FavoriteAction.java

License:Apache License

public String up() {
    user = getUser();/* w w w  .j  av a 2s .c om*/
    if (user == null) {
        return super.execute();
    } else {
        Session session = HibernateUtil.currentSession();
        Favorite fav = (Favorite) session.load(Favorite.class, f);
        if (fav == null || !fav.getUser().equals(user)) {
            return super.execute();
        }
        //Is it a show or a episode
        List<Favorite> favorites = null;
        if (fav.getProgramId().startsWith("EP")) {
            favorites = Favorite.getFavoriteEpisodes(user);
        } else {
            favorites = Favorite.getFavoriteShows(user);
        }
        int index = favorites.indexOf(fav);
        if (index > 0) {
            double startValue = 0.0;

            if (index > 1) {
                startValue = favorites.get(index - 2).getRank();
            }
            double endValue = favorites.get(index - 1).getRank();
            fav.setRank(((startValue + endValue) / 2.0));
        }
        return super.execute();
    }
}

From source file:com.appeligo.search.actions.home.FavoriteAction.java

License:Apache License

public String down() {
    user = getUser();//from   ww  w .  j  a va2s .com
    if (user == null) {
        return super.execute();
    } else {
        Session session = HibernateUtil.currentSession();
        Favorite fav = (Favorite) session.load(Favorite.class, f);
        if (fav == null || !fav.getUser().equals(user)) {
            return super.execute();
        }
        //Is it a show or a episode
        List<Favorite> favorites = null;
        if (fav.getProgramId().startsWith("EP")) {
            favorites = Favorite.getFavoriteEpisodes(user);
        } else {
            favorites = Favorite.getFavoriteShows(user);
        }
        int index = favorites.indexOf(fav);
        int size = favorites.size();
        if (index >= 0 && index + 1 < size) {
            double startValue = favorites.get(index + 1).getRank();
            double endValue = 100.0;
            if (index + 2 >= size) {
                double diff = startValue - fav.getRank();
                endValue = startValue + diff;
            } else {
                endValue = favorites.get(index + 2).getRank();
            }
            fav.setRank(((startValue + endValue) / 2.0));
        }
        return super.execute();
    }
}

From source file:com.appeligo.search.actions.home.FavoriteAction.java

License:Apache License

public String delete() {
    user = getUser();/* w  w  w.j  a va  2  s  .  com*/
    if (user == null) {
        return super.execute();
    } else {
        Session session = HibernateUtil.currentSession();
        Favorite fav = (Favorite) session.load(Favorite.class, f);
        if (fav == null || !fav.getUser().equals(user)) {
            return super.execute();
        }
        fav.setDeleted(true);
        deletedFavorite = fav;
        return super.execute();
    }
}

From source file:com.appeligo.search.actions.home.FavoriteAction.java

License:Apache License

public String undoDelete() {
    user = getUser();/*  w w w.  j a v a2 s . co m*/
    if (user == null) {
        return super.execute();
    } else {
        Session session = HibernateUtil.currentSession();
        Favorite fav = (Favorite) session.load(Favorite.class, f);
        if (fav == null || !fav.getUser().equals(user)) {
            return super.execute();
        }
        fav.setDeleted(false);
        return super.execute();
    }
}

From source file:com.artech.prototype2.saver.dao.AbstractDao.java

public Type getById(AbstractSUBD db, ID id) {
    Session session = null;
    Type entity = null;/*  ww  w  .j av a 2 s. c  o  m*/
    try {
        session = HibernateUtil.getSessionFactory(db).openSession();
        entity = (Type) session.load(Entity.class, id);
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (session != null && session.isOpen()) {
            session.close();
        }
    }
    return entity;
}

From source file:com.assignment.elance.modelManager.FilesManager.java

public void insert(String file_name, String file_temp, int job_id, boolean sent_dir) {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();//  w  w  w.  ja  va2s. c o  m

    Files file = new Files();
    file.setFile_name(file_name);
    file.setJob((Job) session.load(Job.class, new Integer(job_id)));
    file.setSent_dir(sent_dir);
    file.setFile(file_temp);

    session.save(file);
    session.getTransaction().commit();
}

From source file:com.assignment.elance.modelManager.JobManager.java

public void addBidder(int bidderId, int jobId) {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();//from   w  ww . jav a2s.  com

    Job job = (Job) session.load(Job.class, new Integer(jobId));

    Bidder bidder = (Bidder) session.load(Bidder.class, bidderId);
    job.setBidder(bidder);

    session.save(job);
    session.getTransaction().commit();
}

From source file:com.assignment.elance.modelManager.JobManager.java

public void changeStatus(int jobId, String status) {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();/*from   w w w  .  j a  va  2  s . c  om*/

    Job job = (Job) session.load(Job.class, new Integer(jobId));
    job.setJob_status(status);

    session.update(job);
    session.getTransaction().commit();

}

From source file:com.assignment.elance.modelManager.JobManager.java

public void setStartAndEndDate(int jobId, long hrs, float price) {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();//from w w w. j  ava  2s. c  o m

    Job job = (Job) session.load(Job.class, new Integer(jobId));
    Date currentDate = new Date();
    job.setStart_date(currentDate);
    long tempDate = currentDate.getTime() + hrs * 60 * 60 * 1000;
    job.setEnd_date(new Date(tempDate));
    job.setBidded_price(price);
    session.update(job);
    session.getTransaction().commit();
}

From source file:com.assignment.elance.modelManager.MessageManager.java

public void insert(int job_id, String msg, boolean sent_dir) {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();//from  ww w .ja  va  2s. c o  m

    Message message = new Message();
    message.setJob((Job) session.load(Job.class, new Integer(job_id)));
    message.setMessage(msg);
    message.setSend_dir(sent_dir);

    session.save(message);
    session.getTransaction().commit();
}