Example usage for org.hibernate Session clear

List of usage examples for org.hibernate Session clear

Introduction

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

Prototype

void clear();

Source Link

Document

Completely clear the session.

Usage

From source file:com.quix.aia.cn.imo.utilities.ImoUtilityData.java

License:Open Source License

public void getHolidayCache() {

    log.log(Level.INFO, "ImoUtilityDate -->  getHolidayCache");

    Session session = null;
    Transaction tx;/*from   w ww. j a v a2  s.  c om*/
    List<Holiday> listHoliday = null;
    List<Bu> listbu = null;
    List<District> listdist = null;
    List<City> listcity = null;
    List<Ssc> listSsc = null;
    ArrayList al = new ArrayList();

    try {
        Query query = null;
        session = HibernateFactory.openSession();

        Date sdate = new Date();
        log.log(Level.INFO, "Start Time " + sdate.getTime());

        listbu = session.createQuery("FROM Bu where status = 1").setCacheable(true).list();
        listdist = session.createQuery("FROM District where status = 1").setCacheable(true).list();
        listcity = session.createQuery("FROM City where status = 1").setCacheable(true).list();
        listSsc = session.createQuery("FROM Ssc where status = 1").setCacheable(true).list();

        listbu = session.createQuery("FROM Bu where status = 1 order by buName").setCacheable(true).list();
        listdist = session.createQuery("FROM District where status = 1 order by districtName")
                .setCacheable(true).list();

        listcity = session.createQuery("FROM City where status = 1 order by cityName").setCacheable(true)
                .list();
        listSsc = session.createQuery("FROM Ssc where status = 1 order by sscName").setCacheable(true).list();

        for (int i = 0; i < listbu.size(); i++) {

            Bu bu = listbu.get(i);

            query = session.createQuery("FROM Holiday where status = 1  and buCode=:bucode and district=0 ");
            query.setParameter("bucode", bu.getBuCode());
            listHoliday = query.setCacheable(true).list();

            //            listHoliday =  session.createQuery("FROM Holiday where status = 1  and buCode="+ bu.getBuCode()+" and district=0 ").setFirstResult(0).setCacheable(true).list();
            //            al.add(listHoliday);

            query = session.createQuery("FROM Bu where status = 1 and buCode=:bucode ");
            query.setParameter("bucode", bu.getBuCode());
            ArrayList<Bu> bulist = (ArrayList<Bu>) query.setCacheable(true).list();

            for (int j = 0; j < listdist.size(); j++) {

                District dist = listdist.get(j);
                query = session
                        .createQuery("FROM Holiday where status = 1  and district=:distcode and cityCode=0 ");
                query.setParameter("distcode", dist.getDistrictCode());
                listHoliday = query.setCacheable(true).list();

                query = session.createQuery("FROM District where status = 1 and districtCode=:distcode ");
                query.setParameter("distcode", dist.getDistrictCode());
                ArrayList<District> distlist = (ArrayList<District>) query.setCacheable(true).list();

                for (int k = 0; k < listcity.size(); k++) {

                    City city = listcity.get(k);

                    query = session.createQuery(
                            "FROM Holiday where status = 1  and cityCode=:citycode and sscCode=0 ");
                    query.setParameter("citycode", city.getCityCode());
                    listHoliday = query.setCacheable(true).list();

                    query = session.createQuery("FROM City where status = 1 and  cityCode=:citycode ");
                    query.setParameter("citycode", city.getCityCode());
                    ArrayList<City> citylist = (ArrayList<City>) query.setCacheable(true).list();

                    for (int l = 0; l < listSsc.size(); l++) {

                        Ssc ssc = listSsc.get(l);
                        query = session.createQuery("FROM Holiday where status = 1   and  sscCode=:ssccode ");
                        query.setParameter("ssccode", ssc.getSscCode());
                        listHoliday = query.setCacheable(true).list();

                        query = session.createQuery("FROM Ssc where status = 1 and sscCode=:ssccode");
                        query.setParameter("ssccode", ssc.getSscCode());
                        ArrayList<Ssc> ssclist = (ArrayList<Ssc>) query.setCacheable(true).list();

                    } // close ssc for loop

                } //close city for loop

            } //close district for loop

        } //close bu for loop

        //listEGreeting = session.createQuery("FROM E_Greeting where status = 1").setCacheable(true).list();
        Date edate = new Date();
        log.log(Level.INFO, "Total Time " + (edate.getTime() - sdate.getTime()));

        session.flush();
        session.clear();
        session.close();

    } catch (Exception e) {

        log.log(Level.INFO, "ImoUtilityDate -->  getHolidayCache --> Exception " + e);
        e.printStackTrace();
        LogsMaintenance logsMain = new LogsMaintenance();
        StringWriter errors = new StringWriter();
        e.printStackTrace(new PrintWriter(errors));
        logsMain.insertLogs("IMOUtilityData", Level.SEVERE + "", errors.toString());

    } finally {
        try {
            HibernateFactory.close(session);
        } catch (Exception e) {

            e.printStackTrace();
        }

    }

}

From source file:com.redhat.rhn.taskomatic.task.test.KickstartCleanupTest.java

License:Open Source License

public void testHungKickstart() throws Exception {

    Session session = HibernateFactory.getSession();
    KickstartSessionState failedState = lookupByLabel("failed");
    KickstartSessionState inProgressState = lookupByLabel("in_progress");
    KickstartSession ksession = createSession();
    ksession.setState(inProgressState);/*from w ww . j a va  2s .  c  om*/
    TestUtils.saveAndFlush(ksession);
    backdateKickstartSession(session, ksession, 2);
    session.clear();
    ksession = (KickstartSession) session.load(KickstartSession.class, ksession.getId());
    KickstartCleanup j = new KickstartCleanup();
    j.execute(null);
    session.clear();
    ksession = (KickstartSession) session.load(KickstartSession.class, ksession.getId());
    assertTrue(ksession.getState().getId().equals(failedState.getId()));
}

From source file:com.redhat.rhn.taskomatic.task.test.KickstartCleanupTest.java

License:Open Source License

public void testAbandonedKickstart() throws Exception {
    Session session = HibernateFactory.getSession();
    KickstartSessionState failedState = lookupByLabel("failed");
    KickstartSessionState createdState = lookupByLabel("created");
    KickstartSession ksession = createSession();
    ksession.setState(createdState);//ww  w.  j a  v a  2s.  c om
    TestUtils.saveAndFlush(ksession);
    backdateKickstartSession(session, ksession, 7);
    session.clear();
    ksession = (KickstartSession) session.load(KickstartSession.class, ksession.getId());
    KickstartCleanup j = new KickstartCleanup();
    j.execute(null);
    session.clear();
    ksession = (KickstartSession) session.load(KickstartSession.class, ksession.getId());
    assertTrue(ksession.getState().getId().equals(failedState.getId()));
}

From source file:com.romeikat.datamessie.core.base.util.hibernate.HibernateSessionProvider.java

License:Open Source License

private void closeSession(final Session session) {
    try {/*from   w  ww  .  j  av  a  2 s .co  m*/
        session.flush();
        session.clear();
        session.close();
    } catch (final Exception e) {
        LOG.warn("Could not close session", e);
    }
}

From source file:com.rui.common_delete.XbrlMappingProc.java

License:Open Source License

/**
 * write everything back to DB//from w ww.ja va2  s. c  om
 * @return 
 */
public boolean writeAllToDB() {
    if (xbrlNameMapping.size() == 0)
        return true;
    try {
        Session session = sf.openSession();
        Transaction tx = session.beginTransaction();
        int count = 0;
        for (Map.Entry<String, String> pair : xbrlNameMapping.entrySet()) {
            Xbrlmapping xm = new Xbrlmapping();
            xm.setXname(pair.getKey());
            xm.setDescription(pair.getValue());
            session.save(xm);
            if (++count % 20 == 0) {
                session.flush();
                session.clear();
            }
        }
        tx.commit();
        session.close();
        return true;
    } catch (HibernateException e) {
        // e.printStackTrace();
        return false;
    }
}

From source file:com.sap.data.db.dao.BapiDD03LDao.java

public void save(BapiDD03LPojo pojo) throws NotFoundException {
    Session session = null;
    try {//from w  w  w  .j  a v a  2s . c  o  m
        session = HibernateUtil.getSession();
        session.beginTransaction();
        session.saveOrUpdate("BapiDD03LPojo", pojo);
        session.flush();
        session.clear();
        session.getTransaction().commit();
    } catch (HibernateException ex) {
        session.getTransaction().rollback();
        Logger.getLogger(BapiDD03LDao.class.getName()).log(Level.SEVERE, null, ex);
        throw new NotFoundException(ex.getMessage());
    } finally {
        HibernateUtil.close(session);
    }
}

From source file:com.sap.data.db.dao.BapiDD03LDao.java

public void save(List<BapiDD03LPojo> list) throws NotFoundException {
    Session session = null;
    try {// w ww .  j  a v a2  s.co m
        session = HibernateUtil.getSession();
        session.beginTransaction();
        for (BapiDD03LPojo pojo : list) {
            session.saveOrUpdate("BapiDD03LPojo", pojo);
            session.flush();
            session.clear();
        }
        session.getTransaction().commit();
    } catch (HibernateException ex) {
        session.getTransaction().rollback();
        Logger.getLogger(BapiDD03LDao.class.getName()).log(Level.SEVERE, null, ex);
        throw new NotFoundException(ex.getMessage());
    } finally {
        HibernateUtil.close(session);
    }
}

From source file:com.sap.data.db.dao.BapiDD04TDao.java

public void save(List<BapiDD04TPojo> list) throws NotFoundException {
    Session session = null;
    try {/*w  w w . jav  a2  s.  com*/
        session = HibernateUtil.getSession();
        session.beginTransaction();
        for (BapiDD04TPojo pojo : list) {
            session.saveOrUpdate("BapiDD04TPojo", pojo);
            session.flush();
            session.clear();
        }
        session.getTransaction().commit();
    } catch (HibernateException ex) {
        session.getTransaction().rollback();
        Logger.getLogger(BapiDD03LDao.class.getName()).log(Level.SEVERE, null, ex);
        throw new NotFoundException(ex.getMessage());
    } finally {
        HibernateUtil.close(session);
    }
}

From source file:com.sap.data.db.dao.BapiFUPARAREFDao.java

public void save(BapiFUPARAREFPojo pojo) throws NotFoundException {
    Session session = null;
    try {//from   w  w w  . j a v  a2s . c  o m
        session = HibernateUtil.getSession();
        session.beginTransaction();
        session.saveOrUpdate("BapiFUPARAREFPojo", pojo);
        session.flush();
        session.clear();
        session.getTransaction().commit();
    } catch (HibernateException ex) {
        session.getTransaction().rollback();
        Logger.getLogger(BapiFUPARAREFDao.class.getName()).log(Level.SEVERE, null, ex);
        throw new NotFoundException(ex.getMessage());
    } finally {
        HibernateUtil.close(session);
    }
}

From source file:com.sap.data.db.dao.BapiFUPARAREFDao.java

public void save(List<BapiFUPARAREFPojo> list) throws NotFoundException {
    Session session = null;
    try {//from   www.ja  v  a2s  . c o  m
        session = HibernateUtil.getSession();
        session.beginTransaction();
        for (BapiFUPARAREFPojo pojo : list) {
            session.saveOrUpdate("BapiFUPARAREFPojo", pojo);
            session.flush();
            session.clear();
        }
        session.getTransaction().commit();
    } catch (HibernateException ex) {
        ex.printStackTrace();
        session.getTransaction().rollback();
        Logger.getLogger(BapiFUPARAREFDao.class.getName()).log(Level.SEVERE, null, ex);
        throw new NotFoundException(ex.getMessage());
    } finally {
        HibernateUtil.close(session);
    }
}