Example usage for org.hibernate Session delete

List of usage examples for org.hibernate Session delete

Introduction

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

Prototype

void delete(Object object);

Source Link

Document

Remove a persistent instance from the datastore.

Usage

From source file:ca.qc.cegepoutaouais.tge.pige.server.ManagementServiceImpl.java

License:Open Source License

@Override
public void deleteMaintenance(List<Integer> ids) throws PigeException {

    PermissionHelper.checkInventoryManagementPermission(getThreadLocalRequest());

    logger.debug("Suppression des maintenances [ids = " + ids.toString() + "] ...");

    Session session = null;
    Transaction tx = null;/*  w ww.  ja va2 s. c  om*/

    try {
        session = PigeHibernateUtil.openSession();
        tx = session.beginTransaction();

        for (Integer id : ids) {
            Maintenance maintenance = (Maintenance) session.load(Maintenance.class, id);
            session.delete(maintenance);
        }

        tx.commit();
        logger.debug("Suppression russie!");
    } catch (Exception hex) {
        logger.error(hex);
        if (tx != null) {
            tx.rollback();
        }
    } finally {
        if (session != null) {
            session.close();
        }
    }
}

From source file:ca.qc.cegepoutaouais.tge.pige.server.ManagementServiceImpl.java

License:Open Source License

@Override
public void deleteCategory(List<Category> categories) throws PigeException {

    logger.debug("Suppression d'une ou des catgorie(s)...");

    Transaction tx = null;/*from  w  ww .  jav a2 s  .  c o  m*/
    Session session = null;

    try {
        session = PigeHibernateUtil.openSession();
        tx = session.beginTransaction();

        for (Category c : categories) {
            // Les id ngatifs sont rservs  des catgories spciales telles
            // que la catgorie "Non-class" et ne peuvent donc pas tre
            // supprimes.
            if (c.getId() >= 0) {
                if (c.getParent() != null) {
                    Integer id = c.getParent().getId();
                    Category parent = (Category) session.createCriteria(Category.class)
                            .add(Restrictions.eq(Category.ID_REF, id)).uniqueResult();
                    parent.removeChild(c);
                    session.update(parent);
                } else {
                    session.delete(c);
                }

                logger.debug("Catgorie '" + c.getPath() + "' supprime.");
            } else {
                logger.warn("La catgorie suivante ne peut pas tre " + "supprime: " + c.toString());
            }
        }
        tx.commit();
        logger.debug("Suppression russie!");
    } catch (Exception hex) {
        logger.error(hex);
        if (tx != null) {
            tx.rollback();
        }
    } finally {
        if (session != null) {
            session.close();
        }
    }
}

From source file:ca.qc.cegepoutaouais.tge.pige.server.UserServiceImpl.java

License:Open Source License

@Override
public void deleteSavedLoans(List<Loan> savedLoans) {

    logger.info("Suppression d'emprunts sauvegards...");

    if (savedLoans == null || savedLoans.size() <= 0) {
        return;//from ww  w. ja va 2 s .c o  m
    }

    Session session = null;
    Transaction tx = null;

    try {

        session = PigeHibernateUtil.openSession();
        tx = session.beginTransaction();

        for (Loan l : savedLoans) {
            session.delete(l);
        }

        tx.commit();
        logger.info("Suppression russie!");
    } catch (HibernateException hex) {
        logger.error(hex);
        if (tx != null) {
            tx.rollback();
        }
    } finally {
        if (session != null) {
            session.close();
        }
    }
}

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

License:Open Source License

public boolean deleteCharacteristicsType(String toDelete) {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();/* ww w . j a  v  a2  s .c o  m*/
    try {
        CharacteristicType ct = (CharacteristicType) session.get(CharacteristicType.class,
                Integer.parseInt(toDelete));
        List<Characteristic> existing = this.getCharacteristicsForType(ct, session);
        for (Characteristic ch : existing) {
            deleteCharacteristic(ch, session);
        }

        @SuppressWarnings("unchecked")
        List<LinkOrganizationCharacteristicType> programLinks = session
                .createQuery(
                        "FROM LinkOrganizationCharacteristicType WHERE characteristicType.id = :charTypeId")
                .setParameter("charTypeId", ct.getId()).list();
        for (LinkOrganizationCharacteristicType pLink : programLinks) {
            session.delete(pLink);
        }

        session.delete(ct);

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

License:Open Source License

private void deleteCharacteristic(Characteristic c, Session session) {
    @SuppressWarnings("unchecked")
    List<LinkCourseOfferingOutcomeCharacteristic> linkedOutcomes = session
            .createQuery("FROM LinkCourseOfferingOutcomeCharacteristic WHERE characteristic.id=:charId")
            .setParameter("charId", c.getId()).list();
    for (LinkCourseOfferingOutcomeCharacteristic link : linkedOutcomes) {
        session.delete(link);
    }//from w  ww.  j  a  va 2  s  . c  om
    session.delete(c);
}

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

License:Open Source License

public boolean moveCharacteristic(int id, int charTypeId, 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  v a 2 s .  c o  m
    try {
        CharacteristicType ct = (CharacteristicType) session.get(CharacteristicType.class, charTypeId);
        List<Characteristic> existing = this.getCharacteristicsForType(ct, session);
        if (direction.equals("up")) {
            Characteristic prev = null;
            for (Characteristic ch : existing) {
                if (ch.getId() == id && prev != null) {
                    int swap = prev.getDisplayIndex();
                    prev.setDisplayIndex(ch.getDisplayIndex());
                    ch.setDisplayIndex(swap);
                    session.merge(prev);
                    session.merge(ch);
                    done = true;
                    break;
                }
                prev = ch;
            }
        } else if (direction.equals("down")) {
            Characteristic prev = null;
            for (Characteristic ch : existing) {
                if (prev != null) {
                    int swap = prev.getDisplayIndex();
                    prev.setDisplayIndex(ch.getDisplayIndex());
                    ch.setDisplayIndex(swap);
                    session.merge(prev);
                    session.merge(ch);
                    done = true;
                    break;
                }
                if (ch.getId() == id) {
                    prev = ch;
                }

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

            }
            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

private void deleteExistingAdditionalAssessmentOptions(LinkCourseOfferingAssessment link, Session session) {
    @SuppressWarnings("unchecked")
    List<LinkCourseAssessmentFeedbackOption> existing = (List<LinkCourseAssessmentFeedbackOption>) session
            .createQuery(/*from   ww  w  .  jav a  2 s .  c  o  m*/
                    "FROM LinkCourseAssessmentFeedbackOption WHERE linkCourseOfferingAssessment.id=:linkId")
            .setParameter("linkId", link.getId()).list();
    for (LinkCourseAssessmentFeedbackOption o : existing) {
        session.delete(o);
    }

}

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

License:Open Source License

public boolean removeOrganizationFromCourse(int linkId) {

    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();/*from  w  w  w .j  a v  a2  s .  c om*/
    try {
        LinkCourseOrganization link = (LinkCourseOrganization) session.get(LinkCourseOrganization.class,
                linkId);

        session.delete(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.CourseManager.java

License:Open Source License

public boolean removeInstructorFromCourseOffering(int linkId) {

    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();/* ww  w  .  ja va  2 s  .c  o  m*/
    try {
        LinkCourseOfferingInstructor link = (LinkCourseOfferingInstructor) session
                .get(LinkCourseOfferingInstructor.class, linkId);

        session.delete(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.CourseManager.java

License:Open Source License

public boolean deleteTeachingMethod(int courseOfferingId, int teachingMethodId) {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();/* w ww  .j  av  a 2s.co m*/
    try {
        CourseOffering c = (CourseOffering) session.get(CourseOffering.class, courseOfferingId);
        TeachingMethod tm = (TeachingMethod) session.get(TeachingMethod.class, teachingMethodId);
        LinkCourseOfferingTeachingMethod link = this.getLinkTeachingMethodByData(c, tm, session);
        session.delete(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;
    }
}