List of usage examples for org.hibernate FetchMode EAGER
FetchMode EAGER
To view the source code for org.hibernate FetchMode EAGER.
Click Source Link
From source file:gov.nih.nci.caintegrator.studyQueryService.germline.SubjectSearchHandler.java
License:BSD License
private void sendFindingsWithAnnotationCriteria(Collection<Long> specimenIDs, Session session, List toBePopulated) {/* w ww .java 2s . c om*/ List<StudyParticipant> subjects = new ArrayList<StudyParticipant>(); HashSet<StudyParticipant> subjectsSet = new HashSet<StudyParticipant>(); ArrayList<Long> arrayIDs = new ArrayList<Long>(specimenIDs); for (int i = 0; i < arrayIDs.size();) { List<Long> values = new ArrayList<Long>(); int begIndex = i; i += BatchFindingsHandler.IN_PARAMETERS; int lastIndex = (i < arrayIDs.size()) ? i : (arrayIDs.size()); values.addAll(arrayIDs.subList(begIndex, lastIndex)); Criteria crit = session.createCriteria(StudyParticipant.class) .createAlias("specimenCollection", "specimens") .setFetchMode("populationCollection", FetchMode.EAGER) .add(Restrictions.in("specimens.id", values)); Collection<StudyParticipant> currentFindings = executeBatchSearch(crit, -1, -1); /* convert these currentFindings in to a List for convenience */ for (Iterator<StudyParticipant> iterator = currentFindings.iterator(); iterator.hasNext();) { StudyParticipant studyParticipant = iterator.next(); if (!subjectsSet.contains(studyParticipant)) { subjectsSet.add(studyParticipant); subjects.add(studyParticipant); } } while (subjects.size() >= BatchFindingsHandler.BATCH_OBJECT_INCREMENT) populateCurrentResultSet(subjects, toBePopulated, session); } /* Now write remaining findings i.e. less than 500 in one call */ if (subjects != null) populateCurrentResultSet(subjects, toBePopulated, session); /* Finally after all the results were written, write an empty Object (HashSet of size=0 to indicate the caller that all results were written */ populateCurrentResultSet(getConcreteTypedFindingList(), toBePopulated, session); return; }
From source file:gov.nih.nci.caintegrator.studyQueryService.germline.SubjectSearchHandler.java
License:BSD License
private void sendFindingsWithoutAnnotationCriteria(Session session, List toBePopulated) { Criteria crit = session.createCriteria(StudyParticipant.class).setFetchMode("populationCollection", FetchMode.EAGER); Collection findings = null;/*from w w w .j av a2 s . com*/ int start = 0; int end = BatchFindingsHandler.BATCH_OBJECT_INCREMENT; do { findings = executeBatchSearch(crit, start, end); Set toBeSent = new HashSet<StudyParticipant>(); toBeSent.addAll(findings); process(toBePopulated, toBeSent, session); start += BatchFindingsHandler.BATCH_OBJECT_INCREMENT; end += BatchFindingsHandler.BATCH_OBJECT_INCREMENT; } while (findings.size() >= BatchFindingsHandler.BATCH_OBJECT_INCREMENT); /* send empty data object to let the client know that no more results are present */ process(toBePopulated, new HashSet<StudyParticipant>(), session); }
From source file:net.longfalcon.newsj.persistence.hibernate.BinaryDAOImpl.java
License:Open Source License
@Override @Transactional(readOnly = true, propagation = Propagation.SUPPORTS) public List<Binary> searchByNameAndExcludedCats(String[] searchTokens, int limit, Collection<Integer> excludedCategoryIds) { Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Binary.class); if (searchTokens != null && searchTokens.length > 0) { Conjunction searchTokensOr = Restrictions.conjunction(); for (String searchToken : searchTokens) { searchTokensOr.add(Restrictions.ilike("name", searchToken.trim(), MatchMode.ANYWHERE)); }//from w w w . ja v a 2 s.c o m criteria.add(searchTokensOr); } if (excludedCategoryIds != null && !excludedCategoryIds.isEmpty()) { criteria.add(Restrictions.not(Restrictions.in("categoryId", excludedCategoryIds))); } criteria.setMaxResults(limit); criteria.setFetchMode("releaseGuid", FetchMode.EAGER); criteria.setFetchMode("numberParts", FetchMode.EAGER); criteria.setFetchMode("groupName", FetchMode.EAGER); return criteria.list(); }
From source file:org.apache.ode.daohib.bpel.BpelDAOConnectionImpl.java
License:Apache License
@SuppressWarnings({ "unchecked", "deprecation" }) public List<Date> bpelEventTimelineQuery(InstanceFilter ifilter, BpelEventFilter efilter) { CriteriaBuilder cb = new CriteriaBuilder(); Criteria crit = getSession().createCriteria(HBpelEvent.class); if (ifilter != null) cb.buildCriteria(crit, efilter); if (ifilter != null) cb.buildCriteria(crit.createCriteria("instance"), ifilter); crit.setFetchMode("tstamp", FetchMode.EAGER); crit.setProjection(Projections.property("tstamp")); return crit.list(); }
From source file:org.ednovo.gooru.infrastructure.persistence.hibernate.content.ContentRepositoryHibernate.java
License:Open Source License
@SuppressWarnings({ "unchecked", "deprecation" }) @Override/*from w w w . jav a 2 s . c o m*/ public Content findContentByGooruId(String gooruContentId, boolean fetchUser) { if (!fetchUser) { List<Content> cc = getSession().createQuery( "SELECT c FROM Content c WHERE c.gooruOid = ? AND " + generateAuthQueryWithDataNew("c.")) .setString(0, gooruContentId).list(); return cc.size() == 0 ? null : cc.get(0); } else { Criteria crit = getSession().createCriteria(Content.class); crit.setFetchMode("user", FetchMode.EAGER).setFetchMode("userPermSet", FetchMode.JOIN) .add(Restrictions.eq("gooruOid", gooruContentId)); Content content = (Content) crit.uniqueResult(); return content; } }
From source file:org.grails.orm.hibernate.cfg.AbstractGrailsDomainBinder.java
License:Apache License
/** * @param property/*from w w w .j a v a2s . c o m*/ * @param manyToOne */ protected void bindUnidirectionalOneToManyInverseValues(ToMany property, ManyToOne manyToOne) { PropertyConfig config = getPropertyConfig(property); if (config == null) { manyToOne.setLazy(true); } else { manyToOne.setIgnoreNotFound(config.getIgnoreNotFound()); final FetchMode fetch = config.getFetchMode(); if (!fetch.equals(FetchMode.JOIN) && !fetch.equals(FetchMode.EAGER)) { manyToOne.setLazy(true); } final Boolean lazy = config.getLazy(); if (lazy != null) { manyToOne.setLazy(lazy); } } // set referenced entity manyToOne.setReferencedEntityName(property.getAssociatedEntity().getName()); }
From source file:org.grails.orm.hibernate.cfg.AbstractGrailsDomainBinder.java
License:Apache License
protected void bindCollectionForPropertyConfig(Collection collection, PropertyConfig config) { if (config == null) { collection.setLazy(true);/*ww w.j a v a2s.co m*/ collection.setExtraLazy(false); } else { final FetchMode fetch = config.getFetchMode(); if (!fetch.equals(FetchMode.JOIN) && !fetch.equals(FetchMode.EAGER)) { collection.setLazy(true); } final Boolean lazy = config.getLazy(); if (lazy != null) { collection.setExtraLazy(lazy); } } }
From source file:org.sakaiproject.component.app.postem.GradebookManagerImpl.java
License:Educational Community License
public Gradebook getGradebookByTitleAndContext(final String title, final String context) { if (title == null || context == null) { throw new IllegalArgumentException("Null Argument"); } else {// w ww.j a va2 s . co m HibernateCallback hcb = new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException, SQLException { Criteria crit = session.createCriteria(GradebookImpl.class).add(Expression.eq(TITLE, title)) .add(Expression.eq(CONTEXT, context)).setFetchMode(STUDENTS, FetchMode.EAGER); Gradebook gradebook = (Gradebook) crit.uniqueResult(); return gradebook; } }; return (Gradebook) getHibernateTemplate().execute(hcb); } }
From source file:org.sakaiproject.component.app.postem.GradebookManagerImpl.java
License:Educational Community License
public SortedSet getStudentGradesForGradebook(final Gradebook gradebook) throws IllegalArgumentException { if (gradebook == null) { throw new IllegalArgumentException("Null Argument"); } else {/*from w w w . j a v a 2s . c o m*/ HibernateCallback hcb = new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException, SQLException { // get syllabi in an eager fetch mode Criteria crit = session.createCriteria(Gradebook.class) .add(Expression.eq(ID, gradebook.getId())).setFetchMode(STUDENTS, FetchMode.EAGER); Gradebook grades = (Gradebook) crit.uniqueResult(); if (grades != null) { return grades.getStudents(); } return new TreeSet(); } }; return (SortedSet) getHibernateTemplate().execute(hcb); } }
From source file:org.sakaiproject.component.app.syllabus.SyllabusManagerImpl.java
License:Educational Community License
/** * getSyllabiForSyllabusItem returns the collection of syllabi * @param syllabusItem//from ww w. ja v a 2 s . co m */ public Set getSyllabiForSyllabusItem(final SyllabusItem syllabusItem) { if (syllabusItem == null) { throw new IllegalArgumentException("Null Argument"); } else { HibernateCallback hcb = new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException, SQLException { // get syllabi in an eager fetch mode Criteria crit = session.createCriteria(SyllabusItemImpl.class) .add(Expression.eq(SURROGATE_KEY, syllabusItem.getSurrogateKey())) .setFetchMode(SYLLABI, FetchMode.EAGER); SyllabusItem syllabusItem = (SyllabusItem) crit.uniqueResult(); if (syllabusItem != null) { return syllabusItem.getSyllabi(); } return new TreeSet(); } }; return (Set) getHibernateTemplate().execute(hcb); } }