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.CourseManager.java

License:Open Source License

public boolean saveCourseAttributeValue(int attributeTypeId, String value, int courseId) {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();//from w w  w  .  jav  a  2 s.  c  o  m
    try {
        Course course = (Course) session.get(Course.class, courseId);
        CourseAttribute attribute = (CourseAttribute) session.get(CourseAttribute.class, attributeTypeId);
        CourseAttributeValue o = new CourseAttributeValue();
        o.setValue(value);
        o.setAttribute(attribute);
        o.setCourse(course);
        session.save(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.CourseManager.java

License:Open Source License

public CourseAttributeValue getCourseAttributeValueById(int id) {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();//from ww  w .  j  a v  a 2 s. com
    CourseAttributeValue o = null;
    try {
        o = (CourseAttributeValue) session.get(CourseAttributeValue.class, id);
        session.getTransaction().commit();
    } catch (Exception e) {
        HibernateUtil.logException(logger, e);
    }
    return o;
}

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

License:Open Source License

private CourseAttribute getCourseAttributeById(int id, Session session) {
    return (CourseAttribute) session.get(CourseAttribute.class, id);
}

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

License:Open Source License

@SuppressWarnings("unchecked")
public boolean removeCourseOfferingFromCourse(int offeringId) {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();//from  ww  w.j a v a 2 s . c  o m
    try {
        CourseOffering offering = (CourseOffering) session.get(CourseOffering.class, offeringId);

        List<LinkCourseOfferingOutcome> linkOutcomes = (List<LinkCourseOfferingOutcome>) session
                .createQuery("FROM LinkCourseOfferingOutcome WHERE courseOffering.id=:offeringId")
                .setParameter("offeringId", offeringId).list();
        for (LinkCourseOfferingOutcome link : linkOutcomes) {
            List<LinkCourseOfferingOutcomeCharacteristic> chars = (List<LinkCourseOfferingOutcomeCharacteristic>) session
                    .createQuery(
                            "FROM LinkCourseOfferingOutcomeCharacteristic WHERE linkCourseOfferingOutcome.id =:linkId")
                    .setParameter("linkId", link.getId()).list();
            for (LinkCourseOfferingOutcomeCharacteristic c : chars) {
                session.delete(c);
            }
            session.delete(link);
        }
        List<LinkCourseOfferingAssessment> assessments = (List<LinkCourseOfferingAssessment>) session
                .createQuery("FROM LinkCourseOfferingAssessment WHERE courseOffering.id = :offeringId")
                .setParameter("offeringId", offeringId).list();
        for (LinkCourseOfferingAssessment assessment : assessments) {
            List<LinkCourseAssessmentFeedbackOption> exitsingOptions = session.createQuery(
                    "FROM LinkCourseAssessmentFeedbackOption WHERE linkCourseOfferingAssessment.id = :linkId")
                    .setParameter("linkId", assessment.getId()).list();
            for (LinkCourseAssessmentFeedbackOption toDelete : exitsingOptions) {
                session.delete(toDelete);
            }
            session.delete(assessment);
        }
        List<LinkCourseOfferingTeachingMethod> methods = (List<LinkCourseOfferingTeachingMethod>) session
                .createQuery("FROM LinkCourseOfferingTeachingMethod WHERE courseOffering.id = :offeringId")
                .setParameter("offeringId", offeringId).list();
        for (LinkCourseOfferingTeachingMethod method : methods) {
            session.delete(method);
        }
        List<LinkCourseOfferingInstructor> instructors = (List<LinkCourseOfferingInstructor>) session
                .createQuery("FROM LinkCourseOfferingInstructor WHERE courseOffering.id = :offeringId")
                .setParameter("offeringId", offeringId).list();
        for (LinkCourseOfferingInstructor instructor : instructors) {
            session.delete(instructor);
        }
        List<LinkAssessmentCourseOutcome> existingLinks = OutcomeManager.instance()
                .getLinkAssessmentCourseOutcomes(offeringId, session);
        for (LinkAssessmentCourseOutcome outcomeLink : existingLinks) {
            session.delete(outcomeLink);
        }
        List<LinkCourseOfferingContributionProgramOutcome> contributionLinks = ProgramManager.instance()
                .getCourseOfferingContributionLinks(offering, session);
        for (LinkCourseOfferingContributionProgramOutcome link : contributionLinks) {
            session.delete(link);
        }
        List<LinkCourseOutcomeProgramOutcome> links = ProgramManager.instance().getCourseOutcomeLinks(offering,
                session);
        for (LinkCourseOutcomeProgramOutcome link : links) {
            session.delete(link);
        }
        session.refresh(offering);

        session.delete(offering);
        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.OrganizationManager.java

License:Open Source License

public boolean save(String name, int parentId, String systemName) {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();/* www  . ja  v  a  2 s  .c om*/
    try {
        Organization o = new Organization();
        o.setName(name);
        o.setActive("Y");
        o.setSystemName(systemName);
        if (parentId > -1) {
            Organization parent = (Organization) session.get(Organization.class, parentId);
            o.setParentOrganization(parent);
        }
        session.save(o);
        CharacteristicType defaultType = CharacteristicManager.instance().getFirstCharacteristicType(session);
        if (defaultType != null) {
            LinkOrganizationCharacteristicType link = new LinkOrganizationCharacteristicType();
            link.setOrganization(o);
            link.setCharacteristicType(defaultType);
            session.save(link);
        }

        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.OrganizationManager.java

License:Open Source License

public boolean update(String id, String name, String systemName, String active, int parentId, int oldParentId) {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();//from ww w .j a v a 2  s.c  om
    try {

        Organization o = (Organization) session.get(Organization.class, Integer.parseInt(id));
        if (oldParentId != parentId) {
            Organization parent = (Organization) session.get(Organization.class, parentId);
            o.setParentOrganization(parent);
        }
        o.setName(name);
        o.setActive(active);
        o.setSystemName(systemName);
        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.OrganizationManager.java

License:Open Source License

public boolean deleteOrganization(String id) {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();//from  w  w  w. ja  v  a 2 s .  c o  m
    try {

        Organization o = (Organization) session.get(Organization.class, Integer.parseInt(id));
        session.delete(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.OrganizationManager.java

License:Open Source License

public boolean saveOrganizationOutcomeGroupNameById(String value, int organizationOutcomeGroupId) {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();/*  www .  ja  v  a 2s.  c  om*/
    try {
        OrganizationOutcomeGroup o = (OrganizationOutcomeGroup) session.get(OrganizationOutcomeGroup.class,
                organizationOutcomeGroupId);
        o.setName(value);
        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.OrganizationManager.java

License:Open Source License

public boolean saveOrganizationOutcomeNameById(String value, int organizationOutcomeId) {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();// w  w w. j ava  2 s.com
    try {
        OrganizationOutcome o = (OrganizationOutcome) session.get(OrganizationOutcome.class,
                organizationOutcomeId);
        o.setName(value);
        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.OrganizationManager.java

License:Open Source License

public boolean saveNewOrganizationOutcomeNameAndGroup(String value, int organizationOutcomeGroupId) {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();//from w  w w .j a  v a2  s . c o m
    try {
        OrganizationOutcome o = new OrganizationOutcome();
        OrganizationOutcomeGroup group = (OrganizationOutcomeGroup) session.get(OrganizationOutcomeGroup.class,
                organizationOutcomeGroupId);
        o.setGroup(group);
        o.setDescription("");
        o.setName(value);
        session.save(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;
    }
}