Package co.nubetech.crux.dao

Source Code of co.nubetech.crux.dao.DashboardDAO

package co.nubetech.crux.dao;

import java.util.List;

import org.hibernate.JDBCException;
import org.hibernate.Session;
import org.hibernate.Transaction;

import co.nubetech.crux.model.Dashboard;
import co.nubetech.crux.util.CruxException;

import com.googlecode.s2hibernate.struts2.plugin.annotations.SessionTarget;
import com.googlecode.s2hibernate.struts2.plugin.annotations.TransactionTarget;

public class DashboardDAO {

  @SessionTarget
  public Session session;
  @TransactionTarget
  public Transaction transaction;
 
  public Dashboard findById(Long id) {
    Dashboard dashboard = (Dashboard) session.get(
        Dashboard.class, id);
    return dashboard;
  }
 
  public long save(Dashboard dashboard) throws CruxException {
    try {
      transaction.begin();
      session.saveOrUpdate(dashboard);
      transaction.commit();
    } catch (JDBCException e) {
      transaction.rollback();
      throw new CruxException(e.getSQLException().getMessage(), e);
    }
    return dashboard.getId();
  }
 
  public List<Dashboard> findAll() {
    List<Dashboard> result = session.createQuery("from Dashboard")
        .list();
    return result;
  }
}
TOP

Related Classes of co.nubetech.crux.dao.DashboardDAO

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.