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

License:Open Source License

public OrganizationOutcomeGroup getOrganizationOutcomeGroupById(int id) {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();/*ww w  .jav a  2s.  c  o  m*/
    OrganizationOutcomeGroup o = null;
    try {
        o = (OrganizationOutcomeGroup) session.get(OrganizationOutcomeGroup.class, id);
        session.getTransaction().commit();
    } catch (Exception e) {
        HibernateUtil.logException(logger, e);
    }
    return o;
}

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

License:Open Source License

public boolean addCharacteristicToOrganization(int charId, int deptId) {
    boolean createSuccessful = false;
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();/*  w ww.j a v  a 2s .com*/
    try {
        Organization o = (Organization) session.get(Organization.class, deptId);
        CharacteristicType cType = (CharacteristicType) session.get(CharacteristicType.class, charId);
        LinkOrganizationCharacteristicType link = new LinkOrganizationCharacteristicType();
        int max = 0;
        try {
            max = (Integer) session.createQuery(
                    "select max(displayIndex) from LinkOrganizationCharacteristicType l where l.organization.id = :orgId")
                    .setParameter("orgId", o.getId()).uniqueResult();
        } catch (Exception e) {
            logger.error("unable to determine max!", e);
        }

        link.setDisplayIndex(max + 1);
        link.setCharacteristicType(cType);
        link.setOrganization(o);
        //p.getLinkProgramCharacteristicTypes().add(link);
        session.persist(link);
        session.getTransaction().commit();
    } catch (Exception e) {
        HibernateUtil.logException(logger, e);
    }
    createSuccessful = true;
    return createSuccessful;
}

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

License:Open Source License

public boolean addCourseToOrganization(String subject, String courseNumber, int organizationId) {

    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();/*from  w  ww  .  j a va 2 s  . c om*/
    try {
        Organization o = (Organization) session.get(Organization.class, organizationId);
        Course course = CourseManager.instance().getCourseBySubjectAndNumber(subject, courseNumber, session);
        LinkCourseOrganization newLink = new LinkCourseOrganization();
        newLink.setCourse(course);
        newLink.setOrganization(o);
        session.save(newLink);
        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 CourseOutcome getCourseOutcomeById(int id) {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();//from w ww  .  ja v  a 2s  . com
    CourseOutcome c = null;
    try {
        c = (CourseOutcome) session.get(CourseOutcome.class, id);
        session.getTransaction().commit();
    } catch (Exception e) {
        HibernateUtil.logException(logger, e);
    }
    return c;
}

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

License:Open Source License

public boolean saveCharacteristic(int id, int outcomeId, String characteristicValue, String characteristicType,
        String creatorUserid, boolean isProgram) {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();/*w ww . j av a2 s.c om*/
    try {
        LinkCourseOfferingOutcome lco = null;
        LinkProgramProgramOutcome lpo = null;
        if (isProgram) {
            ProgramOutcome outcome = (ProgramOutcome) session.get(ProgramOutcome.class, outcomeId);
            Program program = (Program) session.get(Program.class, id);
            lpo = getLinkProgramProgramOutcome(program, outcome, session);

        } else {
            CourseOutcome outcome = (CourseOutcome) session.get(CourseOutcome.class, outcomeId);
            CourseOffering courseOffering = (CourseOffering) session.get(CourseOffering.class, id);
            lco = getLinkCourseOfferingOutcome(courseOffering, outcome, session);
        }
        CharacteristicType cType = getCharacteristicTypeById(Integer.parseInt(characteristicType), session);
        Characteristic characteristic = null;

        if (cType.getValueType().equals("String")) {
            characteristic = this.getCharacteristicById(Integer.parseInt(characteristicValue), session);
        } else if (cType.getValueType().equals("Boolean")) {
            characteristic = this.getCharacteristicByNameAndTypeId(characteristicValue,
                    Integer.parseInt(characteristicType), session);
        }
        if (isProgram) {
            LinkProgramProgramOutcomeCharacteristic characteristicLink = new LinkProgramProgramOutcomeCharacteristic();
            characteristicLink.setCharacteristic(characteristic);
            characteristicLink.setCreatedByUserid(creatorUserid);
            characteristicLink.setCreatedOn(new Date(System.currentTimeMillis()));
            characteristicLink.setLinkProgramProgramOutcome(lpo);
            session.save(characteristicLink);
        } else {
            LinkCourseOfferingOutcomeCharacteristic characteristicLink = new LinkCourseOfferingOutcomeCharacteristic();
            characteristicLink.setCharacteristic(characteristic);
            characteristicLink.setCreatedByUserid(creatorUserid);
            characteristicLink.setCreatedOn(new Date(System.currentTimeMillis()));
            characteristicLink.setLinkCourseOfferingOutcome(lco);
            session.save(characteristicLink);
        }
        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.OutcomeManager.java

License:Open Source License

public boolean updateCharacteristic(int courseOfferingId, int outcomeId, String characteristicValue,
        String characteristicType) {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();//  w w  w  .j a  va  2 s  . com
    try {
        CourseOutcome outcome = (CourseOutcome) session.get(CourseOutcome.class, outcomeId);
        CourseOffering courseOffering = (CourseOffering) session.get(CourseOffering.class, courseOfferingId);
        LinkCourseOfferingOutcome lco = getLinkCourseOfferingOutcome(courseOffering, outcome, session);
        CharacteristicType cType = getCharacteristicTypeById(Integer.parseInt(characteristicType), session);
        Characteristic characteristic = null;
        if (cType.getValueType().equals("String")) {
            characteristic = this.getCharacteristicById(Integer.parseInt(characteristicValue), session);
        } else if (cType.getValueType().equals("Boolean")) {
            characteristic = this.getCharacteristicByNameAndTypeId(characteristicValue,
                    Integer.parseInt(characteristicType), session);
        }

        LinkCourseOfferingOutcomeCharacteristic characteristicLink = this.getCharacteristicLinkWithType(cType,
                lco, session);
        boolean createNew = false;
        if (characteristicLink == null) {
            characteristicLink = new LinkCourseOfferingOutcomeCharacteristic();
            characteristicLink.setLinkCourseOfferingOutcome(lco);
            createNew = true;
        }
        characteristicLink.setCharacteristic(characteristic);
        characteristicLink.setCreatedByUserid("website");
        characteristicLink.setCreatedOn(new Date(System.currentTimeMillis()));
        if (createNew)
            session.save(characteristicLink);
        else
            session.merge(characteristicLink);
        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.OutcomeManager.java

License:Open Source License

public boolean updateProgramOutcomeCharacteristic(int linkId, String characteristicValue,
        String characteristicType, String creatorUserid) {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();//from  w  ww.  ja va2  s  .co  m
    try {
        LinkProgramProgramOutcome lpo = (LinkProgramProgramOutcome) session.get(LinkProgramProgramOutcome.class,
                linkId);
        CharacteristicType cType = getCharacteristicTypeById(Integer.parseInt(characteristicType), session);
        Characteristic characteristic = null;

        if (cType.getValueType().equals("String")) {
            characteristic = this.getCharacteristicById(Integer.parseInt(characteristicValue), session);
        } else if (cType.getValueType().equals("Boolean")) {
            characteristic = this.getCharacteristicByNameAndTypeId(characteristicValue,
                    Integer.parseInt(characteristicType), session);
        }
        LinkProgramProgramOutcomeCharacteristic characteristicLink = this.getCharacteristicLinkWithType(cType,
                lpo, session);
        if (characteristicLink == null) {
            characteristicLink = new LinkProgramProgramOutcomeCharacteristic();
            characteristicLink.setLinkProgramProgramOutcome(lpo);
            characteristicLink.setCharacteristic(characteristic);
            characteristicLink.setCreatedByUserid(creatorUserid);
            characteristicLink.setCreatedOn(new Date(System.currentTimeMillis()));
            session.save(characteristicLink);
        } else {
            characteristicLink.setCharacteristic(characteristic);
            characteristicLink.setCreatedByUserid(creatorUserid);
            characteristicLink.setCreatedOn(new Date(System.currentTimeMillis()));
            session.merge(characteristicLink);
        }
        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.OutcomeManager.java

License:Open Source License

public boolean saveNewProgramOutcome(String name, String programId, String description,
        String programSpecific) {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();//  ww  w  . jav a 2  s  .  c om
    try {
        ProgramOutcome outcome = new ProgramOutcome();
        outcome.setDescription(description);
        outcome.setName(name);
        ProgramOutcomeGroup group = null;
        if (programSpecific.equals("true")) {
            group = (ProgramOutcomeGroup) session.createQuery(
                    "from ProgramOutcomeGroup og WHERE og.programId = :programId AND og.name like '%Custom'")
                    .setParameter("programId", Integer.parseInt(programId)).uniqueResult();
            if (group == null) {
                Program p = (Program) session.get(Program.class, Integer.parseInt(programId));
                group = new ProgramOutcomeGroup();
                group.setName(p.getName() + " Custom");
                group.setProgramId(p.getId());
                group.setProgramSpecific("Y");
                session.save(group);
            }

        } else {
            group = (ProgramOutcomeGroup) session
                    .createQuery("from ProgramOutcomeGroup og WHERE og.programId = -1 AND og.name = 'Custom'")
                    .uniqueResult();
            if (group == null) {
                group = new ProgramOutcomeGroup();
                group.setName("Custom");
                group.setProgramId(-1);
                group.setProgramSpecific("N");
                session.save(group);
            }
        }
        outcome.setGroup(group);
        session.save(outcome);
        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.OutcomeManager.java

License:Open Source License

public boolean deleteOutcomeObject(String object, int id) {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();/* w  w  w . j a v  a2 s.c o  m*/
    try {
        if (object.equals("ProgramOutcome")) {
            ProgramOutcome o = (ProgramOutcome) session.get(ProgramOutcome.class, id);
            session.delete(o);
        } else if (object.equals("ProgramOutcomeGroup")) {
            ProgramOutcomeGroup o = (ProgramOutcomeGroup) session.get(ProgramOutcomeGroup.class, id);
            session.delete(o);
        } else if (object.equals("OrganizationOutcome")) {
            OrganizationOutcome o = (OrganizationOutcome) session.get(OrganizationOutcome.class, id);
            session.delete(o);
        } else if (object.equals("OrganizationOutcomeGroup")) {
            OrganizationOutcomeGroup o = (OrganizationOutcomeGroup) session.get(OrganizationOutcomeGroup.class,
                    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.OutcomeManager.java

License:Open Source License

public boolean saveOrganizationOutcomeLink(int organizationId, int outcomeId) {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();//from ww  w .j a  v a2  s.c  om
    try {
        OrganizationOutcome outcome = (OrganizationOutcome) session.get(OrganizationOutcome.class, outcomeId);
        Organization organization = (Organization) session.get(Organization.class, organizationId);
        LinkOrganizationOrganizationOutcome loo = this.getLinkOrganizationOrganizationOutcome(organization,
                outcome, session);
        if (loo == null) {
            loo = new LinkOrganizationOrganizationOutcome();
            loo.setOrganization(organization);
            loo.setOrganizationOutcome(outcome);
            session.save(loo);
        }
        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;
    }
}