Class DataModelUtil

java.lang.Object
org.n52.sensorweb.server.db.old.DataModelUtil

public final class DataModelUtil extends Object
Model-introspection helpers used to keep the DAO layer tolerant of the "simple" and "full" variants of the database model, where some entities and associations are not mapped at all.

This class is the Hibernate 6 replacement for the pre-4.0.8 version, which reached into CriteriaImpl, CriteriaQueryTranslator, CriteriaJoinWalker and NamedQueryDefinition. None of those types exist any more, and the legacy Criteria API they served has been replaced by JPA Criteria / Spring Data Specifications. Everything here is now expressed against the JPA Metamodel.

The isNamedQuerySupported and getSqlString(Criteria) helpers were dropped: the project no longer defines any named query, and Hibernate 6 has no Criteria to stringify (enable the org.hibernate.SQL logger instead).

  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    hasAttribute(jakarta.persistence.metamodel.ManagedType<?> type, String attribute)
    Checks whether a managed type maps an attribute of the given name.
    static boolean
    isEntitySupported(Class<?> clazz, jakarta.persistence.EntityManager entityManager)
    Checks whether the given entity type is mapped in the active persistence unit.
    static boolean
    isPropertyNameSupported(String property, Class<?> clazz, jakarta.persistence.EntityManager entityManager)
    Checks whether the given entity maps an attribute of the given name.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • isEntitySupported

      public static boolean isEntitySupported(Class<?> clazz, jakarta.persistence.EntityManager entityManager)
      Checks whether the given entity type is mapped in the active persistence unit.
      Parameters:
      clazz - the entity type to look for
      entityManager - the entity manager whose metamodel is introspected, may be null
      Returns:
      true if the type is a mapped entity
    • isPropertyNameSupported

      public static boolean isPropertyNameSupported(String property, Class<?> clazz, jakarta.persistence.EntityManager entityManager)
      Checks whether the given entity maps an attribute of the given name.

      Used to decide whether hierarchical filtering (parents / children) is available, which depends on the database-model variant in use.

      Parameters:
      property - the attribute name to look for
      clazz - the entity type owning the attribute
      entityManager - the entity manager whose metamodel is introspected, may be null
      Returns:
      true if the attribute is mapped on that entity
    • hasAttribute

      public static boolean hasAttribute(jakarta.persistence.metamodel.ManagedType<?> type, String attribute)
      Checks whether a managed type maps an attribute of the given name.

      This overload takes the metamodel type directly so it can be used from inside a Specification, where only the query Root is available and there is no handle on the EntityManager: root.getModel() yields the ManagedType to pass here.

      Parameters:
      type - the managed type to introspect, may be null
      attribute - the attribute name to look for
      Returns:
      true if the attribute is mapped on that type