Example usage for org.hibernate FlushMode MANUAL

List of usage examples for org.hibernate FlushMode MANUAL

Introduction

In this page you can find the example usage for org.hibernate FlushMode MANUAL.

Prototype

FlushMode MANUAL

To view the source code for org.hibernate FlushMode MANUAL.

Click Source Link

Document

The Session is only ever flushed when Session#flush is explicitly called by the application.

Usage

From source file:org.unitime.banner.model.BannerSection.java

License:Apache License

private void initClassesIfNecessary(Session hibSession, Class_ clazz) {
    if (classes == null) {
        classes = new HashSet<Class_>();
        if (getBannerSectionToClasses() != null && !getBannerSectionToClasses().isEmpty()) {
            Session querySession;/*from   www.  j a  v  a  2  s .c o  m*/
            if (hibSession == null) {
                querySession = Class_DAO.getInstance().getSession();
            } else {
                querySession = hibSession;
            }
            for (Iterator it = getBannerSectionToClasses().iterator(); it.hasNext();) {
                BannerSectionToClass bsc = (BannerSectionToClass) it.next();
                if (clazz != null && bsc.getClassId().equals(clazz.getUniqueId())) {
                    classes.add(clazz);
                } else {
                    Class_ c = (Class_) querySession.createQuery("from Class_ c where c.uniqueId = :classId")
                            .setLong("classId", bsc.getClassId().longValue()).setFlushMode(FlushMode.MANUAL)
                            .uniqueResult();
                    if (c != null) {
                        classes.add(c);
                    }
                }
            }
        }
    }
}

From source file:org.unitime.banner.model.BannerSection.java

License:Apache License

public static BannerSection findBannerSectionForClassAndCourseExternalId(Class_ clazz, String courseExternalId,
        Session hibSession, org.unitime.timetable.model.Session acadSession) {
    return ((BannerSection) hibSession.createQuery(
            "select bs from BannerSection bs inner join bs.bannerSectionToClasses as bsc where bs.bannerConfig.bannerCourse.courseOfferingId = "
                    + " (select co.uniqueId from CourseOffering co where co.externalUniqueId = :courseExternalId and co.instructionalOffering.session.uniqueId = :sessionId)"
                    + " and bsc.classId = :classId")
            .setLong("classId", clazz.getUniqueId().longValue())
            .setLong("sessionId", acadSession.getUniqueId().longValue())
            .setString("courseExternalId", courseExternalId).setFlushMode(FlushMode.MANUAL).setCacheable(false)
            .uniqueResult());/* w  w  w .  j  a v a2  s.c o  m*/
}

From source file:org.unitime.banner.model.BannerSection.java

License:Apache License

@SuppressWarnings("unchecked")
public static List<BannerSection> findBannerSectionsForInstructionalOffering(
        InstructionalOffering instructionalOffering, Session hibSession) {
    return ((List<BannerSection>) hibSession.createQuery(
            "select bs from BannerSection bs, CourseOffering co where co.instructionalOffering = :instrOfferId and bs.bannerConfig.bannerCourse.courseOfferingId = co.uniqueId")
            .setLong("instrOfferId", instructionalOffering.getUniqueId().longValue())
            .setFlushMode(FlushMode.MANUAL).list());
}

From source file:org.unitime.banner.model.BannerSection.java

License:Apache License

private int countBannerSectionsFor(Long classId, Session hibSession) {
    if (classId == null) {
        return (0);
    }//w  w  w. j  a va  2  s . co m
    Session querySession = hibSession;
    if (querySession == null) {
        querySession = Class_DAO.getInstance().getSession();
    }
    return ((Long) querySession
            .createQuery("select count(bsc) from BannerSectionToClass bsc where bsc.classId = :classId")
            .setLong("classId", classId.longValue()).setFlushMode(FlushMode.MANUAL).uniqueResult()).intValue();

}

From source file:org.unitime.banner.model.BannerSection.java

License:Apache License

@SuppressWarnings("unchecked")
public static List<BannerSection> findBannerSectionsForClass(Class_ clazz, Session hibSession) {
    return ((List<BannerSection>) hibSession.createQuery(
            "select distinct bsc.bannerSection from BannerSectionToClass as bsc where bsc.classId = :classId")
            .setLong("classId", clazz.getUniqueId().longValue()).setFlushMode(FlushMode.MANUAL).list());
}

From source file:org.unitime.banner.model.BannerSection.java

License:Apache License

@SuppressWarnings("unchecked")
public static List<BannerSection> findBannerSectionsForInstrOfferingConfig(
        InstrOfferingConfig instrOfferingConfig, Session hibSession) {
    return ((List<BannerSection>) hibSession.createQuery(
            "select distinct bsc.bannerSection from BannerSectionToClass as bsc, Class_ c where c.schedulingSubpart.instrOfferingConfig.uniqueId = :configId and bsc.classId = c.uniqueId")
            .setLong("configId", instrOfferingConfig.getUniqueId().longValue()).setFlushMode(FlushMode.MANUAL)
            .list());/*from  ww  w  .j a  v a 2s  .  c o  m*/
}

From source file:org.unitime.banner.model.BannerSection.java

License:Apache License

@SuppressWarnings("unchecked")
public static List<BannerSection> findBannerSectionsForSchedulingSubpart(SchedulingSubpart schedulingSubpart,
        Session hibSession) {/* www  . j  av  a  2 s  .co  m*/
    return ((List<BannerSection>) hibSession.createQuery(
            "select distinct bsc.bannerSection from BannerSectionToClass as bsc, Class_ c where c.schedulingSubpart.uniqueId = :subpartId and bsc.classId = c.uniqueId")
            .setLong("subpartId", schedulingSubpart.getUniqueId().longValue()).setFlushMode(FlushMode.MANUAL)
            .list());
}

From source file:org.unitime.banner.model.BannerSection.java

License:Apache License

@SuppressWarnings("unchecked")
public static List<BannerSection> findBannerSectionsForSolution(Solution solution, Session hibSession) {
    Vector<BannerSection> hs = new Vector<BannerSection>();
    List sections = hibSession.createQuery(
            "select distinct bsc.bannerSection from BannerSectionToClass as bsc, Assignment a where a.solution.uniqueId = :solutionId and bsc.classId = a.clazz.uniqueId")
            .setLong("solutionId", solution.getUniqueId().longValue()).setFlushMode(FlushMode.MANUAL)
            .setCacheable(false).list();
    BannerSection bs = null;/*from   w ww  .  j ava 2  s.  co  m*/
    Iterator it = sections.iterator();
    while (it.hasNext()) {
        bs = (BannerSection) it.next();
        hs.add(bs);
    }
    return (hs);
}

From source file:org.unitime.banner.model.BannerSection.java

License:Apache License

@SuppressWarnings("unchecked")
public static void removeOrphanedBannerSections(Session hibSession) {
    String orphanedBannerCoursesQuery = "select distinct bs from BannerSection bs where bs.bannerConfig.bannerCourse.courseOfferingId not in ( select co.uniqueId from CourseOffering co )";
    HashSet<BannerConfig> parentList = new HashSet<BannerConfig>();
    String orphanedBannerSectionsQuery = "select distinct bsc.bannerSection from BannerSectionToClass bsc where bsc.classId not in ( select c.uniqueId from Class_ c )";
    HashSet<BannerCourse> orphanedCourses = new HashSet<BannerCourse>();

    Transaction trans = hibSession.beginTransaction();
    List<BannerSection> orphanedBannerCourses = (List<BannerSection>) hibSession
            .createQuery(orphanedBannerCoursesQuery).setFlushMode(FlushMode.MANUAL).list();
    for (BannerSection bs : orphanedBannerCourses) {
        SendBannerMessage.sendBannerMessage(bs, BannerMessageAction.DELETE, hibSession);
        orphanedCourses.add(bs.getBannerConfig().getBannerCourse());
    }/*from   ww w  .  ja v a2  s.c o m*/
    for (BannerCourse bc : orphanedCourses) {
        hibSession.delete(bc);
        hibSession.flush();
    }
    List<BannerSection> orphanedBannerSections = (List<BannerSection>) hibSession
            .createQuery(orphanedBannerSectionsQuery).setFlushMode(FlushMode.MANUAL).list();
    for (BannerSection bs : orphanedBannerSections) {
        Debug.info("removing orphaned banner section");
        SendBannerMessage.sendBannerMessage(bs, BannerMessageAction.DELETE, hibSession);
        parentList.add(bs.getBannerConfig());
        if (bs.getParentBannerSection() != null) {
            bs.getParentBannerSection().getBannerSectionToChildSections().remove(bs);
        }
        if (bs.getBannerSectionToChildSections() != null && !bs.getBannerSectionToChildSections().isEmpty()) {
            for (BannerSection cBs : (Set<BannerSection>) bs.getBannerSectionToChildSections()) {
                cBs.setParentBannerSection(null);
            }
        }
        bs.getBannerConfig().getBannerSections().remove(bs);
    }
    for (BannerConfig bc : parentList) {
        hibSession.update(bc);
    }

    trans.commit();
}

From source file:org.unitime.banner.model.BannerSection.java

License:Apache License

public static BannerSection findBannerSectionForClassAndCourseOffering(Class_ clazz,
        CourseOffering courseOffering, Session hibSession) {
    if (clazz == null || courseOffering == null) {
        return (null);
    }/*from  w  w w  .  j av a2 s. co  m*/
    return ((BannerSection) hibSession.createQuery(
            "select distinct bsc.bannerSection from BannerSectionToClass as bsc where bsc.bannerSection.bannerConfig.bannerCourse.courseOfferingId = :courseOfferingId "
                    + " and bsc.classId = :classId")
            .setLong("classId", clazz.getUniqueId().longValue())
            .setLong("courseOfferingId", courseOffering.getUniqueId().longValue())
            .setFlushMode(FlushMode.MANUAL).setCacheable(false).uniqueResult());

}