List of usage examples for org.hibernate ScrollableResults get
Object get(int i);
From source file:org.dcm4chee.archive.query.dao.InstanceQuery.java
License:LGPL
@Override protected Attributes toAttributes(ScrollableResults results) { Long seriesPk = results.getLong(0); String retrieveAETs = results.getString(1); String externalRetrieveAET = results.getString(2); Availability availability = (Availability) results.get(3); byte[] instAttributes = results.getBinary(4); if (!seriesPk.equals(this.seriesPk)) { this.seriesAttrs = queryService.seriesService().getAttributes(seriesPk, queryParam); this.seriesPk = seriesPk; }//from ww w .j a v a2 s . co m Attributes attrs = new Attributes(seriesAttrs); Utils.decodeAttributes(attrs, instAttributes); Utils.setRetrieveAET(attrs, retrieveAETs, externalRetrieveAET); Utils.setAvailability(attrs, availability); return attrs; }
From source file:org.dcm4chee.archive.query.dao.SeriesQuery.java
License:LGPL
@Override protected Attributes toAttributes(ScrollableResults results) { Long studyPk = results.getLong(0); Long seriesPk = results.getLong(1); int[] a = { results.getInteger(6), // series.numberOfInstances results.getInteger(7) }; // series.numberOfInstancesA String retrieveAETs = results.getString(10); String externalRetrieveAET = results.getString(11); Availability availability = (Availability) results.get(12); byte[] seriesAttributes = results.getBinary(13); if (!studyPk.equals(this.studyPk)) { this.studyAttrs = toStudyAttributes(studyPk, results); this.studyPk = studyPk; }// w w w . j a v a 2 s . co m Attributes attrs = new Attributes(studyAttrs); Utils.decodeAttributes(attrs, seriesAttributes); if (a[0] == -1) a = queryService.seriesService().calculateNumberOfSeriesRelatedInstances(seriesPk); int numberOfSeriesRelatedInstances = queryParam.isShowRejectedInstances() ? a[1] : a[0]; // skip match for empty Series if (numberOfSeriesRelatedInstances == 0) return null; Utils.setSeriesQueryAttributes(attrs, numberOfSeriesRelatedInstances); Utils.setRetrieveAET(attrs, retrieveAETs, externalRetrieveAET); Utils.setAvailability(attrs, availability); return attrs; }
From source file:org.dcm4chee.archive.query.dao.StudyQuery.java
License:LGPL
@Override protected Attributes toAttributes(ScrollableResults results) { Long studyPk = results.getLong(0); int[] a = { results.getInteger(1), // study.numberOfSeries results.getInteger(2), // study.numberOfSeriesA results.getInteger(3), // study.numberOfInstances results.getInteger(4) }; // study.numberOfInstancesA String modalitiesInStudy = results.getString(5); String sopClassesInStudy = results.getString(6); String retrieveAETs = results.getString(7); String externalRetrieveAET = results.getString(8); Availability availability = (Availability) results.get(9); byte[] studyAttributes = results.getBinary(10); byte[] patientAttributes = results.getBinary(11); Attributes attrs = new Attributes(); Utils.decodeAttributes(attrs, patientAttributes); Utils.decodeAttributes(attrs, studyAttributes); if (a[2] == -1) a = queryService.seriesService().calculateNumberOfStudyRelatedInstances(studyPk); boolean showRejectedInstances = queryParam.isShowRejectedInstances(); int numberOfStudyRelatedInstances = showRejectedInstances ? a[3] : a[2]; // skip match for empty Study if (numberOfStudyRelatedInstances == 0) return null; Utils.setStudyQueryAttributes(attrs, showRejectedInstances ? a[1] : a[0], numberOfStudyRelatedInstances, modalitiesInStudy, sopClassesInStudy); Utils.setRetrieveAET(attrs, retrieveAETs, externalRetrieveAET); Utils.setAvailability(attrs, availability); return attrs; }
From source file:org.dcm4chee.archive.query.impl.InstanceQuery.java
License:LGPL
@Override public Attributes toAttributes(ScrollableResults results, QueryContext context) { Long seriesPk = results.getLong(0); String retrieveAETs = results.getString(1); Availability availability = (Availability) results.get(2); byte[] instByteAttributes = results.getBinary(3); if (!seriesPk.equals(this.seriesPk)) { this.seriesAttrs = context.getQueryService().getSeriesAttributes(seriesPk, context); this.seriesPk = seriesPk; }//from w w w .ja v a 2 s . c o m Attributes instanceAttrs = new Attributes(); Utils.decodeAttributes(instanceAttrs, instByteAttributes); Attributes attrs = Utils.mergeAndNormalize(seriesAttrs, instanceAttrs); Utils.setRetrieveAET(attrs, retrieveAETs); Utils.setAvailability(attrs, availability); return attrs; }
From source file:org.dcm4chee.archive.query.impl.SeriesQuery.java
License:LGPL
@Override public Attributes toAttributes(ScrollableResults results, QueryContext context) { Long studyPk = results.getLong(0); Long seriesPk = results.getLong(1); Integer numberOfInstancesI = results.getInteger(2); int numberOfSeriesRelatedInstances; String retrieveAETs;//from w w w. ja v a 2 s . c o m Availability availability; int numberOfSeriesVisibleInstances; Date seriesLastUpdateTime; if (numberOfInstancesI != null) { numberOfSeriesRelatedInstances = numberOfInstancesI; if (numberOfSeriesRelatedInstances == 0) return null; retrieveAETs = results.getString(9); availability = (Availability) results.get(10); numberOfSeriesVisibleInstances = results.getInteger(11); seriesLastUpdateTime = results.getDate(12); } else { SeriesQueryAttributes seriesView = context.getQueryService().createSeriesView(seriesPk, context.getQueryParam()); numberOfSeriesRelatedInstances = seriesView.getNumberOfInstances(); if (numberOfSeriesRelatedInstances == 0) return null; retrieveAETs = seriesView.getRawRetrieveAETs(); availability = seriesView.getAvailability(); numberOfSeriesVisibleInstances = seriesView.getNumberOfVisibleInstances(); seriesLastUpdateTime = seriesView.getLastUpdateTime(); } byte[] seriesAttributes = results.getBinary(13); if (!studyPk.equals(this.studyPk)) { this.studyAttrs = toStudyAttributes(studyPk, results, context); this.studyPk = studyPk; } Attributes seriesAttrs = new Attributes(); Utils.decodeAttributes(seriesAttrs, seriesAttributes); Attributes attrs = Utils.mergeAndNormalize(studyAttrs, seriesAttrs); ArchiveDeviceExtension ade = context.getArchiveAEExtension().getApplicationEntity().getDevice() .getDeviceExtension(ArchiveDeviceExtension.class); Utils.setSeriesQueryAttributes(attrs, numberOfSeriesRelatedInstances, numberOfSeriesVisibleInstances, ade.getPrivateDerivedFields().findSeriesNumberOfVisibleInstancesTag(), seriesLastUpdateTime, ade.getPrivateDerivedFields().findSeriesUpdateTimeTag()); Utils.setRetrieveAET(attrs, retrieveAETs); Utils.setAvailability(attrs, availability); return attrs; }
From source file:org.dcm4chee.archive.query.impl.StudyQuery.java
License:LGPL
@Override public Attributes toAttributes(ScrollableResults results, QueryContext context) { Long studyPk = results.getLong(0); Integer numberOfInstancesI = results.getInteger(1); int numberOfStudyRelatedInstances; int numberOfStudyRelatedSeries; String modalitiesInStudy;//w w w.j a va 2 s . co m String sopClassesInStudy; String retrieveAETs; Availability availability; int numberOfStudyVisibleInstances; Date studyLastUpdateTime; if (numberOfInstancesI != null) { numberOfStudyRelatedInstances = numberOfInstancesI; if (numberOfStudyRelatedInstances == 0) return null; numberOfStudyRelatedSeries = results.getInteger(2); modalitiesInStudy = results.getString(3); sopClassesInStudy = results.getString(4); retrieveAETs = results.getString(5); availability = (Availability) results.get(6); numberOfStudyVisibleInstances = results.getInteger(7); studyLastUpdateTime = results.getDate(8); } else { StudyQueryAttributes studyView = context.getQueryService().createStudyView(studyPk, context.getQueryParam()); numberOfStudyRelatedInstances = studyView.getNumberOfInstances(); if (numberOfStudyRelatedInstances == 0) return null; numberOfStudyRelatedSeries = studyView.getNumberOfSeries(); modalitiesInStudy = studyView.getRawModalitiesInStudy(); sopClassesInStudy = studyView.getRawSOPClassesInStudy(); retrieveAETs = studyView.getRawRetrieveAETs(); availability = studyView.getAvailability(); numberOfStudyVisibleInstances = studyView.getNumberOfVisibleInstances(); studyLastUpdateTime = studyView.getLastUpdateTime(); } byte[] studyByteAttributes = results.getBinary(9); byte[] patientByteAttributes = results.getBinary(10); Attributes patientAttrs = new Attributes(); Attributes studyAttrs = new Attributes(); Utils.decodeAttributes(patientAttrs, patientByteAttributes); Utils.decodeAttributes(studyAttrs, studyByteAttributes); Attributes attrs = Utils.mergeAndNormalize(patientAttrs, studyAttrs); ArchiveDeviceExtension ade = context.getArchiveAEExtension().getApplicationEntity().getDevice() .getDeviceExtension(ArchiveDeviceExtension.class); Utils.setStudyQueryAttributes(attrs, numberOfStudyRelatedSeries, numberOfStudyRelatedInstances, modalitiesInStudy, sopClassesInStudy, numberOfStudyVisibleInstances, ade.getPrivateDerivedFields().findStudyNumberOfVisibleInstancesTag(), studyLastUpdateTime, ade.getPrivateDerivedFields().findStudyUpdateTimeTag()); Utils.setRetrieveAET(attrs, retrieveAETs); Utils.setAvailability(attrs, availability); return attrs; }
From source file:org.encuestame.core.cron.IndexRebuilder.java
License:Apache License
/** * Reindex domain object./*from ww w. j a v a 2 s . c o m*/ * @param fullTextSession {@link FullTextSession}. * @param clazz domain class. */ public static void reindex(final FullTextSession fullTextSession, final Class<?> clazz) { log.debug(clazz.getName() + " purge index ..."); //purge all index content. fullTextSession.purgeAll(clazz); fullTextSession.flushToIndexes(); fullTextSession.getSearchFactory().optimize(clazz); log.debug(clazz.getName() + " starting index ..."); final long startTime = System.currentTimeMillis(); fullTextSession.setFlushMode(FlushMode.MANUAL); fullTextSession.setCacheMode(CacheMode.IGNORE); final Transaction transaction = fullTextSession.beginTransaction(); //Scrollable results will avoid loading too many objects in memory final ScrollableResults results = fullTextSession.createCriteria(clazz).setFetchSize(100) .setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY).scroll(ScrollMode.FORWARD_ONLY); int index = 0; while (results.next()) { index++; fullTextSession.index(results.get(0)); if (index % 100 == 0) { fullTextSession.flushToIndexes(); fullTextSession.flush(); fullTextSession.clear(); } } fullTextSession.flushToIndexes(); fullTextSession.getSearchFactory().optimize(clazz); transaction.commit(); log.debug(clazz.getName() + " Reindex end in " + ((System.currentTimeMillis() - startTime) / 1000.0) + " seconds."); }
From source file:org.eurekastreams.commons.search.bootstrap.SearchIndexManager.java
License:Apache License
/** * Purge & index all entities with the input class and name. * * @param entityClass// w w w. j a v a 2 s . c om * the type of entities to reindex into search index. * * @param entityName * the name of the entity to reindex * * @param search * the FullTextSession to use */ @SuppressWarnings("unchecked") public void reindexEntities(final Class entityClass, final String entityName, final FullTextSession search) { log.info("reindexEntities(" + entityClass.toString() + ", " + entityName + ")"); // purge first purgeSearchIndex(entityClass, search); log.info("Creating query to find batches of " + entityName); Query q = search.createQuery("FROM " + entityName) // set the result transformer // .setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY) <TODO COMMENTED OUT> // minimize cache .setCacheMode(CacheMode.IGNORE) // limit fetch size .setFetchSize(fetchBatchSize); log.info("setting scroll mode to FORWARD_ONLY for " + entityName); ScrollableResults scroll = q.scroll(ScrollMode.FORWARD_ONLY); int batch = 0; while (scroll.next()) { batch++; search.index(scroll.get(0)); if (batch % flushBatchSize == 0) { if (log.isInfoEnabled()) { log.info("Flushing " + entityName + " - " + batch); } // no need to call s.flush() // we don't change anything search.flushToIndexes(); search.clear(); } } log.info("Flushing " + entityName + " - " + batch + " (final)"); search.flushToIndexes(); search.clear(); log.info("Optimizing index for " + entityName); search.getSearchFactory().optimize(entityClass); }
From source file:org.eurekastreams.server.persistence.mappers.cache.DomainGroupCacheLoader.java
License:Apache License
/** * Query all domain groups, loading them in the cache. *//*from w w w .j av a 2 s . co m*/ private void queryAllDomainGroups() { long start = System.currentTimeMillis(); log.info("Loading up all domain groups with a single query"); Criteria criteria = domainGroupQueryStrategy.getCriteria(getHibernateSession()); // page the data criteria.setFetchSize(FETCH_SIZE); criteria.setCacheMode(CacheMode.IGNORE); ScrollableResults scroll = criteria.scroll(ScrollMode.FORWARD_ONLY); // loop through the results and store in cache long recordCounter = 0; while (scroll.next()) { if (++recordCounter % FETCH_SIZE == 0) { log.info("Loading " + recordCounter + "th domainGroup record, clearing session."); getHibernateSession().clear(); } DomainGroupModelView result = (DomainGroupModelView) scroll.get(0); getCache().set(CacheKeys.GROUP_BY_ID + result.getEntityId(), result); getCache().set(CacheKeys.GROUP_BY_SHORT_NAME + result.getShortName(), result.getEntityId()); } log.info("Completed loading all domain groups in " + (System.currentTimeMillis() - start) + " milliseconds."); }
From source file:org.eurekastreams.server.persistence.mappers.cache.PersonCacheLoader.java
License:Apache License
/** * Query the database for all people, only requesting the fields that we're caching, paging for effeciency. */// w w w .ja v a 2 s . c o m private void queryAllPeople() { Criteria criteria = personQueryStrategy.getCriteria(getHibernateSession()); // page the data criteria.setFetchSize(FETCH_SIZE); criteria.setCacheMode(CacheMode.IGNORE); ScrollableResults scroll = criteria.scroll(ScrollMode.FORWARD_ONLY); // loop through the results and store in cache long recordCounter = 0; while (scroll.next()) { if (++recordCounter % FETCH_SIZE == 0) { log.info("Loading " + recordCounter + "th person record, clearing session."); getHibernateSession().clear(); } PersonModelView result = (PersonModelView) scroll.get(0); getCache().set(CacheKeys.PERSON_BY_ID + result.getEntityId(), result); getCache().set(CacheKeys.PERSON_BY_ACCOUNT_ID + result.getAccountId(), result.getEntityId()); getCache().set(CacheKeys.PERSON_BY_OPEN_SOCIAL_ID + result.getOpenSocialId(), result.getEntityId()); } }