Example usage for org.hibernate Session get

List of usage examples for org.hibernate Session get

Introduction

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

Prototype

Object get(String entityName, Serializable id);

Source Link

Document

Return the persistent instance of the given named entity with the given identifier, or null if there is no such persistent instance.

Usage

From source file:ca.usask.gmcte.currimap.action.ProgramManager.java

License:Open Source License

public boolean update(String id, String name, String description) {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();/*w w  w.  j  a  v a 2s  .c o m*/
    try {

        Program o = (Program) session.get(Program.class, Integer.parseInt(id));
        o.setName(name);
        o.setDescription(description);
        session.merge(o);
        session.getTransaction().commit();
        return true;
    } catch (Exception e) {
        HibernateUtil.logException(logger, e);
        try {
            session.getTransaction().rollback();
        } catch (Exception e2) {
            logger.error("Unable to roll back!", e2);
        }
        return false;
    }
}

From source file:ca.usask.gmcte.currimap.action.ProgramManager.java

License:Open Source License

public boolean saveLinkCourseProgram(int courseId, int programId, int classification, int time) {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();//from   w w  w . j a v a2 s .  c o m
    try {
        /** Creating Pojo */
        CourseClassification cl = (CourseClassification) session.get(CourseClassification.class,
                classification);
        Program p = (Program) session.get(Program.class, programId);
        Course c = (Course) session.get(Course.class, courseId);
        Time min = (Time) session.get(Time.class, time);
        LinkCourseProgram l = new LinkCourseProgram();
        l.setCourse(c);
        l.setCourseClassification(cl);
        l.setTime(min);
        l.setProgram(p);
        session.save(l);
        session.getTransaction().commit();
        return true;
    } catch (Exception e) {
        HibernateUtil.logException(logger, e);
        try {
            session.getTransaction().rollback();
        } catch (Exception e2) {
            logger.error("Unable to roll back!", e2);
        }
        return false;
    }
}

From source file:ca.usask.gmcte.currimap.action.ProgramManager.java

License:Open Source License

public boolean updateLinkCourseProgram(int id, int classification, int time) {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();//from   w  ww  . j a  va 2s  . com
    try {
        LinkCourseProgram l = (LinkCourseProgram) session.get(LinkCourseProgram.class, id);
        CourseClassification cl = (CourseClassification) session.get(CourseClassification.class,
                classification);
        Time min = (Time) session.get(Time.class, time);
        l.setCourseClassification(cl);
        l.setTime(min);
        session.merge(l);
        session.getTransaction().commit();
        return true;
    } catch (Exception e) {
        HibernateUtil.logException(logger, e);
        try {
            session.getTransaction().rollback();
        } catch (Exception e2) {
            logger.error("Unable to roll back!", e2);
        }
        return false;
    }
}

From source file:ca.usask.gmcte.currimap.action.ProgramManager.java

License:Open Source License

public boolean removeProgramCourse(int courseLinkId) {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();/* w  w  w  . j a v a2 s  . c  om*/
    try {
        LinkCourseProgram l = (LinkCourseProgram) session.get(LinkCourseProgram.class, courseLinkId);
        Program p = l.getProgram();
        Course c = l.getCourse();

        //any program contributions in the system linked to the course offering and program outcomes need to be deleted as well.
        @SuppressWarnings("unchecked")
        List<LinkCourseOfferingContributionProgramOutcome> offeringContributions = (List<LinkCourseOfferingContributionProgramOutcome>) session
                .createQuery("FROM LinkCourseOfferingContributionProgramOutcome lcoc "
                        + "WHERE linkProgramOutcome IN (SELECT l FROM LinkProgramProgramOutcome l WHERE l.program.id=:programId) "
                        + "  AND lcoc.courseOffering.course.id = :courseId")
                .setParameter("programId", p.getId()).setParameter("courseId", c.getId()).list();
        for (LinkCourseOfferingContributionProgramOutcome contr : offeringContributions) {
            session.delete(contr);
        }

        //any program contributions in the system linked to the course and program outcomes need to be deleted as well.
        @SuppressWarnings("unchecked")
        List<LinkCourseContributionProgramOutcome> courseContributions = (List<LinkCourseContributionProgramOutcome>) session
                .createQuery("FROM LinkCourseContributionProgramOutcome lcoc "
                        + "WHERE linkProgramOutcome IN (SELECT l FROM LinkProgramProgramOutcome l WHERE l.program.id=:programId) "
                        + "  AND lcoc.course.id = :courseId")
                .setParameter("programId", p.getId()).setParameter("courseId", c.getId()).list();
        for (LinkCourseContributionProgramOutcome contr : courseContributions) {
            session.delete(contr);
        }

        @SuppressWarnings("unchecked")
        List<LinkCourseOutcomeProgramOutcome> courseOutcomeLinks = (List<LinkCourseOutcomeProgramOutcome>) session
                .createQuery("FROM LinkCourseOutcomeProgramOutcome "
                        + " WHERE courseOffering.course.id=:courseId "
                        + "   AND programOutcome IN (SELECT l.programOutcome FROM LinkProgramProgramOutcome l WHERE l.program.id=:programId)")
                .setParameter("courseId", c.getId()).setParameter("programId", p.getId()).list();
        for (LinkCourseOutcomeProgramOutcome link : courseOutcomeLinks) {
            session.delete(link);
        }

        session.delete(l);
        session.getTransaction().commit();
        return true;
    } catch (Exception e) {
        HibernateUtil.logException(logger, e);
        try {
            session.getTransaction().rollback();
        } catch (Exception e2) {
            logger.error("Unable to roll back!", e2);
        }
        return false;
    }
}

From source file:ca.usask.gmcte.currimap.action.ProgramManager.java

License:Open Source License

public boolean removeLinkCourseOutcomeProgramOutcome(int id) {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();/*from  w w  w.ja va  2s.com*/
    try {
        LinkCourseOutcomeProgramOutcome l = (LinkCourseOutcomeProgramOutcome) session
                .get(LinkCourseOutcomeProgramOutcome.class, id);
        session.delete(l);
        session.getTransaction().commit();
        return true;
    } catch (Exception e) {
        HibernateUtil.logException(logger, e);
        try {
            session.getTransaction().rollback();
        } catch (Exception e2) {
            logger.error("Unable to roll back!", e2);
        }
        return false;
    }
}

From source file:ca.usask.gmcte.currimap.action.ProgramManager.java

License:Open Source License

public boolean removeProgram(int programId) {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();/*from ww  w .j a v a  2 s.  c o  m*/
    try {
        Program p = (Program) session.get(Program.class, programId);
        List<LinkProgramProgramOutcome> outcomeLinks = p.getLinkProgramOutcomes();
        for (LinkProgramProgramOutcome link : outcomeLinks) {
            session.delete(link);
        }

        List<QuestionResponse> questionResponses = QuestionManager.instance()
                .getAllQuestionResponsesForProgram(p, session);
        for (QuestionResponse link : questionResponses) {
            session.delete(link);
        }

        List<LinkProgramQuestion> programQuestions = p.getLinkProgramQuestions();
        for (LinkProgramQuestion link : programQuestions) {

            session.delete(link);
        }
        List<LinkCourseProgram> courseLinks = p.getLinkCoursePrograms();
        for (LinkCourseProgram link : courseLinks) {
            session.delete(link);
        }

        @SuppressWarnings("unchecked")
        List<ProgramAdmin> adminLinks = session.createQuery("FROM ProgramAdmin WHERE program.id = :programId")
                .setParameter("programId", p.getId()).list();
        for (ProgramAdmin link : adminLinks) {
            session.delete(link);
        }
        session.delete(p);
        session.getTransaction().commit();
        return true;
    } catch (Exception e) {
        HibernateUtil.logException(logger, e);
        try {
            session.getTransaction().rollback();
        } catch (Exception e2) {
            logger.error("Unable to roll back!", e2);
        }
        return false;
    }
}

From source file:ca.usask.gmcte.currimap.action.ProgramManager.java

License:Open Source License

@SuppressWarnings("unchecked")
public boolean removeProgramOutcome(int outcomeLinkId) {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();//from   w  w  w . j a v a 2 s  .  c o m
    try {
        LinkProgramProgramOutcome l = (LinkProgramProgramOutcome) session.get(LinkProgramProgramOutcome.class,
                outcomeLinkId);

        //delete associated characteristics
        List<LinkProgramProgramOutcomeCharacteristic> chars = session.createQuery(
                "FROM LinkProgramProgramOutcomeCharacteristic WHERE linkProgramProgramOutcome.id=:linkId")
                .setParameter("linkId", outcomeLinkId).list();
        for (LinkProgramProgramOutcomeCharacteristic linkedChar : chars) {
            session.delete(linkedChar);
        }
        List<LinkCourseOfferingContributionProgramOutcome> offeringLinks = (List<LinkCourseOfferingContributionProgramOutcome>) session
                .createQuery(
                        "FROM LinkCourseOfferingContributionProgramOutcome l where l.linkProgramOutcome.id=:linkId")
                .setParameter("linkId", outcomeLinkId).list();
        if (offeringLinks != null) {
            for (LinkCourseOfferingContributionProgramOutcome li : offeringLinks) {

                session.delete(li);
            }
        }
        session.delete(l);
        session.getTransaction().commit();
        return true;
    } catch (Exception e) {
        HibernateUtil.logException(logger, e);
        try {
            session.getTransaction().rollback();
        } catch (Exception e2) {
            logger.error("Unable to roll back!", e2);
        }
        return false;
    }
}

From source file:ca.usask.gmcte.currimap.action.ProgramManager.java

License:Open Source License

public Program getProgramById(int id) {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();//from   w  ww  . j ava2s .  co m
    Program o = null;
    try {
        o = (Program) session.get(Program.class, id);
        session.getTransaction().commit();
    } catch (Exception e) {
        HibernateUtil.logException(logger, e);
    }
    return o;
}

From source file:ca.usask.gmcte.currimap.action.ProgramManager.java

License:Open Source License

public ProgramOutcome getProgramOutcomeById(int id) {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();/*from   w  ww . j av a  2 s. co  m*/
    ProgramOutcome o = null;
    try {
        o = (ProgramOutcome) session.get(ProgramOutcome.class, id);
        session.getTransaction().commit();
    } catch (Exception e) {
        HibernateUtil.logException(logger, e);
    }
    return o;
}

From source file:ca.usask.gmcte.currimap.action.ProgramManager.java

License:Open Source License

public ProgramOutcomeGroup getProgramOutcomeGroupById(int id) {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();//from w w w .  jav a2s.c  om
    ProgramOutcomeGroup o = null;
    try {
        o = (ProgramOutcomeGroup) session.get(ProgramOutcomeGroup.class, id);
        session.getTransaction().commit();
    } catch (Exception e) {
        HibernateUtil.logException(logger, e);
    }
    return o;
}