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 saveAssessmentDescriptionById(int id, String newValue) {

    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();/*  ww w .ja va 2s.  c om*/
    try {
        Assessment o = (Assessment) session.get(Assessment.class, id);
        o.setDescription(newValue);
        session.merge(o);
        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 boolean saveAssessmentGroupName(int id, String newName) {

    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();/*w w w.j  a v  a2 s  .  co m*/
    try {
        AssessmentGroup o = (AssessmentGroup) session.get(AssessmentGroup.class, id);
        o.setName(newName);
        session.merge(o);
        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 boolean saveAssessmentGroupShortName(int id, String newName) {

    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();/*w w  w. jav  a  2 s .c o  m*/
    try {
        AssessmentGroup o = (AssessmentGroup) session.get(AssessmentGroup.class, id);
        o.setShortName(newName);
        session.merge(o);
        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 boolean moveAssessmentMethod(int id, int groupId, String direction) {
    //when moving up, find the one to be moved (while keeping track of the previous one) and swap display_index values
    //when moving down, find the one to be moved, swap displayIndex values of it and the next one
    //when deleting, reduce all links following one to be deleted by 1
    boolean done = false;
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();//from   w w  w.  j  a  va2 s .  co m
    try {
        AssessmentGroup group = (AssessmentGroup) session.get(AssessmentGroup.class, groupId);
        List<Assessment> existing = this.getAssessmentsForGroup(group, session);
        if (direction.equals("up")) {
            Assessment prev = null;
            for (Assessment a : existing) {
                if (a.getId() == id && prev != null) {
                    int swap = prev.getDisplayIndex();
                    prev.setDisplayIndex(a.getDisplayIndex());
                    a.setDisplayIndex(swap);
                    session.merge(prev);
                    session.merge(a);
                    done = true;
                    break;
                }
                prev = a;
            }
        } else if (direction.equals("down")) {
            Assessment prev = null;
            for (Assessment a : existing) {
                if (prev != null) {
                    int swap = prev.getDisplayIndex();
                    prev.setDisplayIndex(a.getDisplayIndex());
                    a.setDisplayIndex(swap);
                    session.merge(prev);
                    session.merge(a);
                    done = true;
                    break;
                }
                if (a.getId() == id) {
                    prev = a;
                }

            }
        } else if (direction.equals("delete")) {
            Assessment toDelete = null;
            for (Assessment a : existing) {
                if (toDelete != null) {
                    a.setDisplayIndex(a.getDisplayIndex() - 1);
                    session.merge(a);
                }
                if (a.getId() == id) {
                    toDelete = a;
                }

            }
            if (toDelete != null) {
                session.delete(toDelete);
                done = true;
            }
        }
        session.getTransaction().commit();
        return done;
    } 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 LinkCourseProgram getLinkCourseProgramById(int id) {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();/*w  w w .  j a v a 2 s .c  om*/
    LinkCourseProgram c = null;
    try {
        c = (LinkCourseProgram) session.get(LinkCourseProgram.class, id);
        session.getTransaction().commit();
    } catch (Exception e) {
        HibernateUtil.logException(logger, e);
    }
    return c;
}

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

License:Open Source License

public boolean editInstructorAttributeValue(int id, String value) {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();//from w ww . jav  a 2 s  .  c o m
    try {
        InstructorAttributeValue o = (InstructorAttributeValue) session.get(InstructorAttributeValue.class, id);
        o.setValue(value);
        session.merge(o);
        session.getTransaction().commit();
        return true;
    } catch (Exception e) {
        HibernateUtil.logException(logger, e);
        return false;
    }
}

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

License:Open Source License

public boolean saveInstructorAttributeValue(int attributeTypeId, String value, String userid) {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();/*from   w w w. j a  v a2s . c o  m*/
    try {
        Instructor instructor = this.getInstructorByUserid(userid, session);
        InstructorAttribute attribute = (InstructorAttribute) session.get(InstructorAttribute.class,
                attributeTypeId);
        InstructorAttributeValue o = new InstructorAttributeValue();
        o.setValue(value);
        o.setAttribute(attribute);
        o.setInstructor(instructor);
        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 InstructorAttributeValue getInstructorAttributeValueById(int id) {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();//from  w  w  w. j a  v a  2  s  .  c  om
    InstructorAttributeValue o = null;
    try {
        o = (InstructorAttributeValue) session.get(InstructorAttributeValue.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 InstructorAttribute getInstructorAttributeById(int id, Session session) {
    return (InstructorAttribute) session.get(InstructorAttribute.class, id);
}

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

License:Open Source License

public boolean editCourseAttributeValue(int id, String value) {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();//from  w w w .  j ava 2 s .c  o  m
    try {
        CourseAttributeValue o = (CourseAttributeValue) session.get(CourseAttributeValue.class, id);
        o.setValue(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;
    }
}