Class DataQuerySpecifications
Specification factories for DataEntity queries.
All match* methods are pure predicate factories: they never touch an EntityManager and are
freely composable via Specification.and(Specification) /
Specification.allOf(Specification...). Executing them — ordering, limiting, fetch modes — is the
caller's job; see AbstractValueAssembler for the Spring Data path and AbstractDao for the
legacy session path.
They are generic in the entity type so that a caller working with a concrete subtype (say
ProfileDataEntity) gets a Specification for that subtype without casting; the predicates
themselves only ever touch properties declared on DataEntity.
The only exceptions are min(DatasetEntity, EntityManager),
max(DatasetEntity, EntityManager) and average(DatasetEntity, EntityManager): those
project an aggregate rather than restrict a result set, so they cannot be expressed as a
Specification and have to build (and run) a criteria query of their own.
A method that has nothing to restrict returns Specification.unrestricted() rather than
null, so composing it into a chain is always safe.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final org.springframework.data.domain.SortEarliest sampling time start first, newest result time breaking ties.static final org.springframework.data.domain.SortLatest sampling time start first, newest result time breaking ties.static final org.springframework.data.domain.SortNewest result time first.Fields inherited from class org.n52.sensorweb.server.db.query.QuerySpecifications
dbQuery, entityManager -
Method Summary
Modifier and TypeMethodDescriptionaverage(org.n52.series.db.beans.DatasetEntity dataset, jakarta.persistence.EntityManager entityManager) Averages the values of a dataset.<E extends org.n52.series.db.beans.DataEntity<?>>
org.springframework.data.jpa.domain.Specification<E>matchClosestAfter(org.n52.series.db.beans.DatasetEntity dataset, Date after) Matches all observations of a dataset after the given bound.<E extends org.n52.series.db.beans.DataEntity<?>>
org.springframework.data.jpa.domain.Specification<E>matchClosestAfterEnd(org.n52.series.db.beans.DatasetEntity dataset) Matches all observations of a dataset after the requested timespan.<E extends org.n52.series.db.beans.DataEntity<?>>
org.springframework.data.jpa.domain.Specification<E>matchClosestBefore(org.n52.series.db.beans.DatasetEntity dataset, Date before) Matches all observations of a dataset before the given bound.<E extends org.n52.series.db.beans.DataEntity<?>>
org.springframework.data.jpa.domain.Specification<E>matchClosestBeforeStart(org.n52.series.db.beans.DatasetEntity dataset) Matches all observations of a dataset before the requested timespan.<E extends org.n52.series.db.beans.DataEntity<?>>
org.springframework.data.jpa.domain.Specification<E>matchDataset(Long id) Matches data of the dataset with the given database id.<E extends org.n52.series.db.beans.DataEntity<?>>
org.springframework.data.jpa.domain.Specification<E>Matches data of datasets with given ids.<E extends org.n52.series.db.beans.DataEntity<?>>
org.springframework.data.jpa.domain.Specification<E>matchDatasets(String... ids) Matches data of datasets with given ids.<E extends org.n52.series.db.beans.DataEntity<?>>
org.springframework.data.jpa.domain.Specification<E>matchDatasets(Collection<String> ids) Matches data of datasets with given ids.<E extends org.n52.series.db.beans.DataEntity<?>>
org.springframework.data.jpa.domain.Specification<E>The filters the legacyDataDao#getDefaultCriteria(DbQuery, Order)applied to every single-value lookup: not deleted, no child observations, plus the request's spatial and result time filters.<E extends org.n52.series.db.beans.DataEntity<?>>
org.springframework.data.jpa.domain.Specification<E>Matches datasets which have a feature laying within the given bbox using an intersects query.<E extends org.n52.series.db.beans.DataEntity<?>>
org.springframework.data.jpa.domain.Specification<E>Aggregates following filters in an AND expression:matchDatasets()matchTimespan()matchIsNotDeleted()matchesSpatially()<E extends org.n52.series.db.beans.DataEntity<?>>
org.springframework.data.jpa.domain.Specification<E>Aggregates following filters in an AND expression:matchDatasets()matchTimespan()matchIsNotDeleted()matchParentsIsNull()matchesSpatially()<E extends org.n52.series.db.beans.DataEntity<?>>
org.springframework.data.jpa.domain.Specification<E>Aggregates following filters in an AND expression:matchDatasets()matchTimespan()matchIsNotDeleted()matchParentsIsNotNull()matchesSpatially()<E extends org.n52.series.db.beans.DataEntity<?>>
org.springframework.data.jpa.domain.Specification<E>matchFirstValue(org.n52.series.db.beans.DatasetEntity dataset) Matches the observation a dataset'sAbstractDatasetEntity.getFirstValueAt()points at.<E extends org.n52.series.db.beans.DataEntity<?>>
org.springframework.data.jpa.domain.Specification<E>Matches entities which are not flagged as deleted.<E extends org.n52.series.db.beans.DataEntity<?>>
org.springframework.data.jpa.domain.Specification<E>matchLastValue(org.n52.series.db.beans.DatasetEntity dataset) Matches the observation a dataset'sAbstractDatasetEntity.getLastValueAt()points at.<E extends org.n52.series.db.beans.DataEntity<?>>
org.springframework.data.jpa.domain.Specification<E>Matches entities so that parent is not null.<E extends org.n52.series.db.beans.DataEntity<?>>
org.springframework.data.jpa.domain.Specification<E>Matches entities so that parent is null.<E extends org.n52.series.db.beans.DataEntity<?>>
org.springframework.data.jpa.domain.Specification<E>Matches the result times requested viaIoParameters.getResultTimes(), if any.<E extends org.n52.series.db.beans.DataEntity<?>>
org.springframework.data.jpa.domain.Specification<E>Matches the timespan.org.n52.series.db.beans.DataEntity<?>max(org.n52.series.db.beans.DatasetEntity dataset, jakarta.persistence.EntityManager entityManager) Selects the observation carrying the largest value of a dataset, latest sampling time end breaking ties.org.n52.series.db.beans.DataEntity<?>min(org.n52.series.db.beans.DatasetEntity dataset, jakarta.persistence.EntityManager entityManager) Selects the observation carrying the smallest value of a dataset, latest sampling time end breaking ties.static DataQuerySpecificationsMethods inherited from class org.n52.sensorweb.server.db.query.QuerySpecifications
getIdPredicate, getTimespanEnd, getTimespanStart
-
Field Details
-
NEWEST_RESULT_TIME_FIRST
public static final org.springframework.data.domain.Sort NEWEST_RESULT_TIME_FIRSTNewest result time first. Used to pick a single observation when a dataset holds several result times for the same sampling time. Replaces the legacyProjections.max(resultTime)group-by subquery: once dataset and sampling time are pinned down, "the row with the highest result time" and "order by result time descending, take one" select the same row. -
CLOSEST_BEFORE_FIRST
public static final org.springframework.data.domain.Sort CLOSEST_BEFORE_FIRSTLatest sampling time start first, newest result time breaking ties. Use together withmatchClosestBefore(DatasetEntity, Date). -
CLOSEST_AFTER_FIRST
public static final org.springframework.data.domain.Sort CLOSEST_AFTER_FIRSTEarliest sampling time start first, newest result time breaking ties. Use together withmatchClosestAfter(DatasetEntity, Date).
-
-
Method Details
-
of
-
matchFilters
public <E extends org.n52.series.db.beans.DataEntity<?>> org.springframework.data.jpa.domain.Specification<E> matchFilters()Aggregates following filters in an AND expression:- Type Parameters:
E- the data entity type to build the specification for- Returns:
- a boolean expression matching all filter criteria
-
matchFiltersParentsIsNull
public <E extends org.n52.series.db.beans.DataEntity<?>> org.springframework.data.jpa.domain.Specification<E> matchFiltersParentsIsNull()Aggregates following filters in an AND expression:- Type Parameters:
E- the data entity type to build the specification for- Returns:
- a boolean expression matching all filter criteria
-
matchFiltersParentsNotNull
public <E extends org.n52.series.db.beans.DataEntity<?>> org.springframework.data.jpa.domain.Specification<E> matchFiltersParentsNotNull()Aggregates following filters in an AND expression:- Type Parameters:
E- the data entity type to build the specification for- Returns:
- a boolean expression matching all filter criteria
-
matchDefaultFilters
public <E extends org.n52.series.db.beans.DataEntity<?>> org.springframework.data.jpa.domain.Specification<E> matchDefaultFilters()The filters the legacyDataDao#getDefaultCriteria(DbQuery, Order)applied to every single-value lookup: not deleted, no child observations, plus the request's spatial and result time filters.- Type Parameters:
E- the data entity type to build the specification for- Returns:
- a boolean expression
-
matchTimespan
public <E extends org.n52.series.db.beans.DataEntity<?>> org.springframework.data.jpa.domain.Specification<E> matchTimespan()Matches the timespan.- Type Parameters:
E- the data entity type to build the specification for- Returns:
- a boolean expression
-
matchIsNotDeleted
public <E extends org.n52.series.db.beans.DataEntity<?>> org.springframework.data.jpa.domain.Specification<E> matchIsNotDeleted()Matches entities which are not flagged as deleted.- Type Parameters:
E- the data entity type to build the specification for- Returns:
- a boolean expression
-
matchParentsIsNull
public <E extends org.n52.series.db.beans.DataEntity<?>> org.springframework.data.jpa.domain.Specification<E> matchParentsIsNull()Matches entities so that parent is null.- Type Parameters:
E- the data entity type to build the specification for- Returns:
- a boolean expression
-
matchParentsIsNotNull
public <E extends org.n52.series.db.beans.DataEntity<?>> org.springframework.data.jpa.domain.Specification<E> matchParentsIsNotNull()Matches entities so that parent is not null.- Type Parameters:
E- the data entity type to build the specification for- Returns:
- a boolean expression
-
matchResultTimes
public <E extends org.n52.series.db.beans.DataEntity<?>> org.springframework.data.jpa.domain.Specification<E> matchResultTimes()Matches the result times requested viaIoParameters.getResultTimes(), if any.- Type Parameters:
E- the data entity type to build the specification for- Returns:
- a boolean expression
-
matchDatasets
public <E extends org.n52.series.db.beans.DataEntity<?>> org.springframework.data.jpa.domain.Specification<E> matchDatasets()Matches data of datasets with given ids.- Type Parameters:
E- the data entity type to build the specification for- Returns:
- a boolean expression
- See Also:
-
matchDatasets
public <E extends org.n52.series.db.beans.DataEntity<?>> org.springframework.data.jpa.domain.Specification<E> matchDatasets(String... ids) Matches data of datasets with given ids.- Type Parameters:
E- the data entity type to build the specification for- Parameters:
ids- the ids to match- Returns:
- a boolean expression
- See Also:
-
matchDataset
public <E extends org.n52.series.db.beans.DataEntity<?>> org.springframework.data.jpa.domain.Specification<E> matchDataset(Long id) Matches data of the dataset with the given database id. For example:where data.datasetId = <id>
UnlikematchDatasets(Collection)this never joinsdataset: the foreign key onDataEntitycarries the id already.DbQuery.isMatchDomainIds()is irrelevant here because a database id is passed in, not a domain id.- Type Parameters:
E- the data entity type to build the specification for- Parameters:
id- the database id to match- Returns:
- a boolean expression, or
Specification.unrestricted()when the id is null
-
matchDatasets
public <E extends org.n52.series.db.beans.DataEntity<?>> org.springframework.data.jpa.domain.Specification<E> matchDatasets(Collection<String> ids) Matches data of datasets with given ids. For example:where data.datasetId in (<ids>)
In case ofDbQuery.isMatchDomainIds()returns true the following query path will be used:where dataset.identifier in (<ids>)
- Type Parameters:
E- the data entity type to build the specification for- Parameters:
ids- the ids to match- Returns:
- a boolean expression, or
Specification.unrestricted()when given ids are null or empty
-
matchFirstValue
public <E extends org.n52.series.db.beans.DataEntity<?>> org.springframework.data.jpa.domain.Specification<E> matchFirstValue(org.n52.series.db.beans.DatasetEntity dataset) Matches the observation a dataset'sAbstractDatasetEntity.getFirstValueAt()points at.Order by
NEWEST_RESULT_TIME_FIRSTand take the first result.- Type Parameters:
E- the data entity type to build the specification for- Parameters:
dataset- the dataset whose first value is looked up- Returns:
- a boolean expression, matching nothing when the dataset has no first value
-
matchLastValue
public <E extends org.n52.series.db.beans.DataEntity<?>> org.springframework.data.jpa.domain.Specification<E> matchLastValue(org.n52.series.db.beans.DatasetEntity dataset) Matches the observation a dataset'sAbstractDatasetEntity.getLastValueAt()points at.Order by
NEWEST_RESULT_TIME_FIRSTand take the first result.- Type Parameters:
E- the data entity type to build the specification for- Parameters:
dataset- the dataset whose last value is looked up- Returns:
- a boolean expression, matching nothing when the dataset has no last value
-
matchClosestBefore
public <E extends org.n52.series.db.beans.DataEntity<?>> org.springframework.data.jpa.domain.Specification<E> matchClosestBefore(org.n52.series.db.beans.DatasetEntity dataset, Date before) Matches all observations of a dataset before the given bound.Order by
CLOSEST_BEFORE_FIRSTand take the first result to get the closest one. A single ordered query replaces the legacy pair of correlatedmax(samplingTimeStart)subqueries.- Type Parameters:
E- the data entity type to build the specification for- Parameters:
dataset- the dataset to matchbefore- the exclusive upper bound onDataEntity.PROPERTY_SAMPLING_TIME_START- Returns:
- a boolean expression
-
matchClosestAfter
public <E extends org.n52.series.db.beans.DataEntity<?>> org.springframework.data.jpa.domain.Specification<E> matchClosestAfter(org.n52.series.db.beans.DatasetEntity dataset, Date after) Matches all observations of a dataset after the given bound.Order by
CLOSEST_AFTER_FIRSTand take the first result to get the closest one. A single ordered query replaces the legacy pair of correlatedmin(samplingTimeStart)subqueries.- Type Parameters:
E- the data entity type to build the specification for- Parameters:
dataset- the dataset to matchafter- the exclusive lower bound onDataEntity.PROPERTY_SAMPLING_TIME_START- Returns:
- a boolean expression
-
matchClosestBeforeStart
public <E extends org.n52.series.db.beans.DataEntity<?>> org.springframework.data.jpa.domain.Specification<E> matchClosestBeforeStart(org.n52.series.db.beans.DatasetEntity dataset) Matches all observations of a dataset before the requested timespan.- Type Parameters:
E- the data entity type to build the specification for- Parameters:
dataset- the dataset to match- Returns:
- a boolean expression
- See Also:
-
matchClosestAfterEnd
public <E extends org.n52.series.db.beans.DataEntity<?>> org.springframework.data.jpa.domain.Specification<E> matchClosestAfterEnd(org.n52.series.db.beans.DatasetEntity dataset) Matches all observations of a dataset after the requested timespan.- Type Parameters:
E- the data entity type to build the specification for- Parameters:
dataset- the dataset to match- Returns:
- a boolean expression
- See Also:
-
matchesSpatially
public <E extends org.n52.series.db.beans.DataEntity<?>> org.springframework.data.jpa.domain.Specification<E> matchesSpatially()Matches datasets which have a feature laying within the given bbox using an intersects query. For example:where ST_INTERSECTS(feature.geom, <filter_geometry>)
- Type Parameters:
E- the data entity type to build the specification for- Returns:
- a boolean expression, or
Specification.unrestricted()when the given spatial filter is null or empty
-
min
public org.n52.series.db.beans.DataEntity<?> min(org.n52.series.db.beans.DatasetEntity dataset, jakarta.persistence.EntityManager entityManager) Selects the observation carrying the smallest value of a dataset, latest sampling time end breaking ties.- Parameters:
dataset- the dataset to aggregate overentityManager- the entity manager to run the query with- Returns:
- the observation, or null when the value type does not support aggregation or the dataset holds no data
-
max
public org.n52.series.db.beans.DataEntity<?> max(org.n52.series.db.beans.DatasetEntity dataset, jakarta.persistence.EntityManager entityManager) Selects the observation carrying the largest value of a dataset, latest sampling time end breaking ties.- Parameters:
dataset- the dataset to aggregate overentityManager- the entity manager to run the query with- Returns:
- the observation, or null when the value type does not support aggregation or the dataset holds no data
-
average
public BigDecimal average(org.n52.series.db.beans.DatasetEntity dataset, jakarta.persistence.EntityManager entityManager) Averages the values of a dataset.- Parameters:
dataset- the dataset to aggregate overentityManager- the entity manager to run the query with- Returns:
- the average, or null when the value type does not support aggregation or the dataset holds no data
-