Class ClassImportIntegrator

  • All Implemented Interfaces:
    org.hibernate.integrator.spi.Integrator

    public class ClassImportIntegrator
    extends java.lang.Object
    implements org.hibernate.integrator.spi.Integrator
    The ClassImportIntegrator implements the Hibernate Integrator contract and allows you to provide a List of classes to be imported using their simple name. For instance, you could use a DTO simple class name, instead of the fully-qualified name when building a constructor expression in a JPQL query. For more details about how to use it, check out this article on vladmihalcea.com.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.List<? extends java.lang.Class> classImportList  
      private static java.lang.String DOT  
      private java.lang.String excludedPath  
    • Constructor Summary

      Constructors 
      Constructor Description
      ClassImportIntegrator​(java.util.List<? extends java.lang.Class> classImportList)
      Builds a new integrator that can register the provided classes.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void disintegrate​(org.hibernate.engine.spi.SessionFactoryImplementor sessionFactory, org.hibernate.service.spi.SessionFactoryServiceRegistry serviceRegistry)
      ClassImportIntegrator excludePath​(java.lang.String path)
      Exclude the provided parent path and register the remaining relative path.
      void integrate​(org.hibernate.boot.Metadata metadata, org.hibernate.engine.spi.SessionFactoryImplementor sessionFactory, org.hibernate.service.spi.SessionFactoryServiceRegistry serviceRegistry)
      Register the provided classes by their simple name or relative package and class name.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • classImportList

        private final java.util.List<? extends java.lang.Class> classImportList
      • excludedPath

        private java.lang.String excludedPath
    • Constructor Detail

      • ClassImportIntegrator

        public ClassImportIntegrator​(java.util.List<? extends java.lang.Class> classImportList)
        Builds a new integrator that can register the provided classes.
        Parameters:
        classImportList - list of classes to be imported
    • Method Detail

      • excludePath

        public ClassImportIntegrator excludePath​(java.lang.String path)
        Exclude the provided parent path and register the remaining relative path. If the excludedPath is not set, then the package is excluded and only the simple class name is registered. For instance, if you provide the com.vladmihalcea.hibernate.type path, and register a class whose fully-qualified name is com.vladmihalcea.hibernate.type.json.PostDTO, then the class is going to be registered under the json.PostDTO alias.
        Parameters:
        path - path to be excluded.
        Returns:
        the ClassImportIntegrator object reference
      • integrate

        public void integrate​(org.hibernate.boot.Metadata metadata,
                              org.hibernate.engine.spi.SessionFactoryImplementor sessionFactory,
                              org.hibernate.service.spi.SessionFactoryServiceRegistry serviceRegistry)
        Register the provided classes by their simple name or relative package and class name.
        Specified by:
        integrate in interface org.hibernate.integrator.spi.Integrator
        Parameters:
        metadata - metadata
        sessionFactory - Hibernate session factory
        serviceRegistry - Hibernate service registry
      • disintegrate

        public void disintegrate​(org.hibernate.engine.spi.SessionFactoryImplementor sessionFactory,
                                 org.hibernate.service.spi.SessionFactoryServiceRegistry serviceRegistry)
        Specified by:
        disintegrate in interface org.hibernate.integrator.spi.Integrator