Class AbstractDao<T>

java.lang.Object
org.n52.series.db.old.dao.AbstractDao<T>
All Implemented Interfaces:
GenericDao<T,Long>
Direct Known Subclasses:
DataDao, DatasetDao, MeasuringProgramDao, ParameterDao, RelatedFeatureDao, SamplingDao

public abstract class AbstractDao<T> extends Object implements GenericDao<T,Long>
  • Field Details

    • TRANSLATIONS_ALIAS

      protected static final String TRANSLATIONS_ALIAS
      See Also:
    • session

      protected final org.hibernate.Session session
  • Constructor Details

    • AbstractDao

      public AbstractDao(org.hibernate.Session session)
  • Method Details

    • getEntityClass

      protected abstract Class<T> getEntityClass()
    • getDatasetProperty

      protected abstract String getDatasetProperty()
    • getDefaultAlias

      protected String getDefaultAlias()
    • findAll

      protected List<T> findAll(org.springframework.data.jpa.domain.Specification<T> spec, DbQuery query, boolean instance)
    • findFirst

      protected T findFirst(org.springframework.data.jpa.domain.Specification<T> spec, org.springframework.data.domain.Sort sort, DbQuery query, boolean instance)
      Returns the first entity matching spec in the given order, or null. Ordering plus setMaxResults(1) is what lets callers express "the closest/newest match" with a plain Specification, instead of the correlated max/min subqueries the legacy Criteria API needed.
      Parameters:
      spec - the restriction to apply, may be null
      sort - the order deciding which match wins
      query - the query to apply fetch modes for
      instance - whether fetch modes apply to a single instance
      Returns:
      the first match or null
    • findUnique

      protected T findUnique(org.springframework.data.jpa.domain.Specification<T> spec, DbQuery query, boolean instance)
    • count

      protected long count(org.springframework.data.jpa.domain.Specification<T> spec)
    • exists

      protected boolean exists(org.springframework.data.jpa.domain.Specification<T> spec)
    • applyLimitOffset

      protected void applyLimitOffset(jakarta.persistence.TypedQuery<?> typedQuery, DbQuery query)
    • hasInstance

      public boolean hasInstance(String id, DbQuery query)
    • hasInstance

      public boolean hasInstance(Long id, DbQuery query)
      Specified by:
      hasInstance in interface GenericDao<T,Long>
    • hasInstance

      public boolean hasInstance(Long id, DbQuery query, Class<?> clazz)
    • getInstance

      public T getInstance(String key, DbQuery query)
    • getInstance

      public T getInstance(Long key, DbQuery query)
      Specified by:
      getInstance in interface GenericDao<T,Long>
    • getInstance

      protected T getInstance(String key, DbQuery query, Class<T> clazz)
    • matchIdOrDomainId

      protected org.springframework.data.jpa.domain.Specification<T> matchIdOrDomainId(String key, DbQuery query)
    • matchId

      protected org.springframework.data.jpa.domain.Specification<T> matchId(Long key)
    • getCount

      public Long getCount(DbQuery query)
      Specified by:
      getCount in interface GenericDao<T,Long>
    • i18nSpec

      protected <I extends org.n52.series.db.beans.i18n.I18nEntity<?>> org.springframework.data.jpa.domain.Specification<T> i18nSpec(Class<I> clazz, DbQuery query)
    • i18nSpec

      protected <I extends org.n52.series.db.beans.i18n.I18nEntity<?>> org.springframework.data.jpa.domain.Specification<T> i18nSpec(Class<I> clazz, DbQuery query, String path)
    • getDefaultSpecification

      public org.springframework.data.jpa.domain.Specification<T> getDefaultSpecification(DbQuery query)
    • getDefaultSpecification

      public org.springframework.data.jpa.domain.Specification<T> getDefaultSpecification(DbQuery query, boolean withRequestFilters)
      Parameters:
      query - the query parameters
      withRequestFilters - true to also apply the datasets= and samplings= request filters (DbQuery.datasetAndSamplingRestrictions(jakarta.persistence.criteria.From<org.n52.series.db.beans.DatasetEntity, ?>, jakarta.persistence.criteria.CriteriaBuilder, jakarta.persistence.EntityManager)) inside the dataset subquery, as the legacy query.addFilters(...) did
      Returns:
      the default specification
    • datasetFilter

      protected org.springframework.data.jpa.domain.Specification<T> datasetFilter(DbQuery query)
    • datasetFilter

      protected org.springframework.data.jpa.domain.Specification<T> datasetFilter(DbQuery query, boolean withRequestFilters)
    • addDefaultOrder

      protected void addDefaultOrder(jakarta.persistence.criteria.CriteriaQuery<?> cq, jakarta.persistence.criteria.CriteriaBuilder cb, jakarta.persistence.criteria.Root<?> root, Class<?> clazz)
    • hasMatchingDataset

      public org.springframework.data.jpa.domain.Specification<T> hasMatchingDataset(DbQuery dbQuery)
      Builds a correlated EXISTS subquery over DatasetEntity that applies the full set of dataset filters and correlates the matching datasets back to the current root via getDatasetProperty().
      Parameters:
      dbQuery - the query parameters
      Returns:
      a specification restricting the root to entities referenced by a matching dataset
    • hasMatchingDataset

      public org.springframework.data.jpa.domain.Specification<T> hasMatchingDataset(DbQuery dbQuery, boolean withRequestFilters)
      As hasMatchingDataset(DbQuery), optionally also restricting the subquery's datasets with the datasets= and samplings= request filters (DbQuery.datasetAndSamplingRestrictions(jakarta.persistence.criteria.From<org.n52.series.db.beans.DatasetEntity, ?>, jakarta.persistence.criteria.CriteriaBuilder, jakarta.persistence.EntityManager)). The other dataset filters are already covered by matchFilters().
      Parameters:
      dbQuery - the query parameters
      withRequestFilters - true to apply the request's dataset filters inside the subquery
      Returns:
      a specification restricting the root to entities referenced by a matching dataset
    • createLastValuesFilter

      public org.springframework.data.jpa.domain.Specification<org.n52.series.db.beans.DatasetEntity> createLastValuesFilter(DbQuery query)
    • checkLevelParameterForHierarchyQuery

      protected DbQuery checkLevelParameterForHierarchyQuery(DbQuery query)
    • toStringList

      protected List<String> toStringList(Collection<Long> set)
    • applyFetchModes

      protected jakarta.persistence.criteria.Root<T> applyFetchModes(jakarta.persistence.criteria.Root<T> root, DbQuery query, boolean instance)
      Hook for subclasses to eagerly fetch associations via JPA fetch joins. The base implementation is a no-op.
      Parameters:
      root - the query root
      query - the query parameters
      instance - true when fetching a single instance (expanded view)
      Returns:
      the (possibly fetch-augmented) root
    • getFetchPath

      protected String getFetchPath(String... values)
    • get

      public Collection<T> get(DbQuery query)
      Parameters:
      query - Query parameters
      Returns:
      the result