List of usage examples for org.hibernate.internal.util.collections CollectionHelper isEmpty
public static boolean isEmpty(Object[] objects)
From source file:org.n52.sos.ds.hibernate.cache.base.FeatureOfInterestCacheUpdate.java
License:Open Source License
@Override public void execute() { LOGGER.debug("Executing FeatureOfInterestCacheUpdate"); startStopwatch();/*from ww w.j av a 2 s .c om*/ // FIXME shouldn't the identifiers be translated using // CacheHelper.addPrefixAndGetFeatureIdentifier()? try { FeatureOfInterestDAO featureOfInterestDAO = new FeatureOfInterestDAO(); Map<String, Collection<String>> foisWithParents = new FeatureOfInterestDAO() .getFeatureOfInterestIdentifiersWithParents(getSession()); List<FeatureOfInterest> featureOfInterestObjects = featureOfInterestDAO .getFeatureOfInterestObjects(getSession()); Map<String, Collection<String>> procsForAllFois = new ProcedureDAO() .getProceduresForAllFeaturesOfInterest(getSession()); for (final FeatureOfInterest featureOfInterest : featureOfInterestObjects) { String featureOfInterestIdentifier = featureOfInterest.getIdentifier(); getCache().addFeatureOfInterest(featureOfInterestIdentifier); if (featureOfInterest.isSetName()) { getCache().addFeatureOfInterestIdentifierHumanReadableName(featureOfInterestIdentifier, featureOfInterest.getName()); } getCache().setProceduresForFeatureOfInterest(featureOfInterestIdentifier, procsForAllFois.get(featureOfInterestIdentifier)); Collection<String> parentFois = foisWithParents.get(featureOfInterestIdentifier); if (!CollectionHelper.isEmpty(parentFois)) { getCache().addParentFeatures(featureOfInterestIdentifier, parentFois); } } FeatureQueryHandlerQueryObject queryHandler = new FeatureQueryHandlerQueryObject() .setFeatureIdentifiers(getCache().getFeaturesOfInterest()).setConnection(getSession()); getCache().setGlobalEnvelope(getFeatureQueryHandler().getEnvelopeForFeatureIDs(queryHandler)); } catch (final OwsExceptionReport ex) { getErrors().add(ex); } LOGGER.debug("Finished executing FeatureOfInterestCacheUpdate ({})", getStopwatchResult()); }
From source file:org.n52.sos.ds.hibernate.cache.base.OfferingCacheUpdate.java
License:Open Source License
@Override public void execute() { LOGGER.debug("Executing OfferingCacheUpdate (Single Threaded Tasks)"); startStopwatch();/*from w w w . j a v a 2s. c om*/ //perform single threaded updates here WritableContentCache cache = getCache(); for (Offering offering : getOfferingsToUpdate()) { // try { String offeringId = offering.getIdentifier(); if (shouldOfferingBeProcessed(offeringId)) { String prefixedOfferingId = CacheHelper.addPrefixOrGetOfferingIdentifier(offeringId); cache.addOffering(prefixedOfferingId); if (offering instanceof TOffering) { TOffering tOffering = (TOffering) offering; // Related features cache.setRelatedFeaturesForOffering(prefixedOfferingId, getRelatedFeatureIdentifiersFrom(tOffering)); cache.setAllowedObservationTypeForOffering(prefixedOfferingId, getObservationTypesFromObservationType(tOffering.getObservationTypes())); // featureOfInterestTypes cache.setAllowedFeatureOfInterestTypeForOffering(prefixedOfferingId, getFeatureOfInterestTypesFromFeatureOfInterestType( tOffering.getFeatureOfInterestTypes())); } } // } catch (OwsExceptionReport ex) { // getErrors().add(ex); // } } //time ranges //TODO querying offering time extrema in a single query is definitely faster for a properly // indexed Postgres db, but may not be true for all platforms. move back to multithreaded execution // in OfferingCacheUpdateTask if needed Map<String, OfferingTimeExtrema> offeringTimeExtrema = null; try { offeringTimeExtrema = offeringDAO.getOfferingTimeExtrema(offeringsIdToUpdate, getSession()); } catch (OwsExceptionReport ce) { LOGGER.error("Error while querying offering time ranges!", ce); getErrors().add(ce); } if (!CollectionHelper.isEmpty(offeringTimeExtrema)) { for (Entry<String, OfferingTimeExtrema> entry : offeringTimeExtrema.entrySet()) { String offeringId = entry.getKey(); OfferingTimeExtrema ote = entry.getValue(); cache.setMinPhenomenonTimeForOffering(offeringId, ote.getMinPhenomenonTime()); cache.setMaxPhenomenonTimeForOffering(offeringId, ote.getMaxPhenomenonTime()); cache.setMinResultTimeForOffering(offeringId, ote.getMinResultTime()); cache.setMaxResultTimeForOffering(offeringId, ote.getMaxResultTime()); } } LOGGER.debug("Finished executing OfferingCacheUpdate (Single Threaded Tasks) ({})", getStopwatchResult()); //execute multi-threaded updates LOGGER.debug("Executing OfferingCacheUpdate (Multi-Threaded Tasks)"); startStopwatch(); super.execute(); LOGGER.debug("Finished executing OfferingCacheUpdate (Multi-Threaded Tasks) ({})", getStopwatchResult()); }
From source file:org.n52.sos.ds.hibernate.cache.base.ProcedureCacheUpdate.java
License:Open Source License
@Override public void execute() { //single threaded updates LOGGER.debug("Executing ProcedureCacheUpdate (Single Threaded Tasks)"); startStopwatch();/*ww w . j a v a2 s .c o m*/ getProcedureDescriptionFormat(); boolean obsConstSupported = HibernateHelper.isEntitySupported(ObservationConstellation.class); Map<String, Collection<String>> procedureMap = procedureDAO.getProcedureIdentifiers(getSession()); List<Procedure> procedures = procedureDAO.getProcedureObjects(getSession()); for (Procedure procedure : procedures) { String procedureIdentifier = procedure.getIdentifier(); Collection<String> parentProcedures = procedureMap.get(procedureIdentifier); // } // for (Entry<String, Collection<String>> entry : procedureMap.entrySet()) { // String procedureIdentifier = entry.getKey(); // Collection<String> parentProcedures = entry.getValue(); getCache().addProcedure(procedureIdentifier); if (procedure.isSetName()) { getCache().addProcedureIdentifierHumanReadableName(procedureIdentifier, procedure.getName()); } if (obsConstSupported) { Collection<ObservationConstellationInfo> ocis = getProcedureObservationConstellationInfo() .get(procedureIdentifier); if (CollectionHelper.isNotEmpty(ocis)) { getCache().setOfferingsForProcedure(procedureIdentifier, DatasourceCacheUpdateHelper .getAllOfferingIdentifiersFromObservationConstellationInfos(ocis)); getCache().setObservablePropertiesForProcedure(procedureIdentifier, DatasourceCacheUpdateHelper .getAllObservablePropertyIdentifiersFromObservationConstellationInfos(ocis)); } } else { try { getCache().setOfferingsForProcedure(procedureIdentifier, Sets.newHashSet( offeringDAO.getOfferingIdentifiersForProcedure(procedureIdentifier, getSession()))); } catch (OwsExceptionReport ce) { LOGGER.error("Error while querying offering identifiers for procedure!", ce); getErrors().add(ce); } getCache().setObservablePropertiesForProcedure(procedureIdentifier, Sets.newHashSet(observablePropertyDAO .getObservablePropertyIdentifiersForProcedure(procedureIdentifier, getSession()))); } if (!CollectionHelper.isEmpty(parentProcedures)) { getCache().addParentProcedures(procedureIdentifier, parentProcedures); } } LOGGER.debug("Finished executing ProcedureCacheUpdate (Single Threaded Tasks) ({})", getStopwatchResult()); //multi-threaded execution LOGGER.debug("Executing ProcedureCacheUpdate (Multi-Threaded Tasks)"); startStopwatch(); super.execute(); LOGGER.debug("Finished executing ProcedureCacheUpdate (Multi-Threaded Tasks) ({})", getStopwatchResult()); }