Class HibernateUtil

    • Constructor Detail

      • HibernateUtil

        public HibernateUtil()
    • Method Detail

      • setHibernateMediaLibrary

        public void setHibernateMediaLibrary​(HibernateMediaLibrary<?> hibernateMediaLibrary)
      • isRunning

        public boolean isRunning()
      • setDatabaseBaseFilename

        public void setDatabaseBaseFilename​(File databaseBaseFilename)
        Sets the database base file name. I.e. this file will not be the file the database it stored in.
        Parameters:
        databaseBaseFilename - base file name
        See Also:
        getDatabaseBaseFilename(), doesDatabaseExist(java.io.File)
      • getDatabaseBaseDirectory

        public File getDatabaseBaseDirectory()
        Returns the database directory name.
        Returns:
        directory name
      • doesDatabaseExist

        public static boolean doesDatabaseExist​(File databaseBaseFilename)
        Indicates whether a database actually exists. The test is file-based.
        Parameters:
        databaseBaseFilename - database base filename
        Returns:
        true, if the file exists
      • removeDatabaseLock

        public void removeDatabaseLock()
      • executeTransaction

        public <R> R executeTransaction​(Function<org.hibernate.Session,​R> work)
        Execute some database work inside a transaction. The transaction is automatically rolled back, should an exception be thrown by the given work.
        Type Parameters:
        R - result type
        Parameters:
        work - stuff to do inside the transaction.
        Returns:
        result
        See Also:
        executeTransaction(Consumer)
      • executeTransaction

        public void executeTransaction​(Consumer<org.hibernate.Session> work)
        Execute some database work inside a transaction. The transaction is automatically rolled back, should an exception be thrown by the given work.
        Parameters:
        work - stuff to do inside the transaction.
        See Also:
        executeTransaction(Function)
      • execute

        public <R> R execute​(Function<org.hibernate.Session,​R> work,
                             boolean failSilently)
        Execute some database work with a given session. The session is thread-local and will be closed after the work is done, unless a transaction is already TransactionStatus.ACTIVE before the work is started.
        Type Parameters:
        R - result type
        Parameters:
        work - stuff to do with the session
        failSilently - do not report failure, simply return null
        Returns:
        result
        See Also:
        executeTransaction(Function)
      • execute

        public <R> R execute​(Function<org.hibernate.Session,​R> work)
        Execute some database work with a given session. The session is thread-local and will be closed after the work is done, unless a transaction is already TransactionStatus.ACTIVE before the work is started.
        Type Parameters:
        R - result type
        Parameters:
        work - stuff to do with the session
        Returns:
        result
        See Also:
        executeTransaction(Function)
      • enableFastImportSettings

        public void enableFastImportSettings​(boolean enable)
        Sets special database settings for the very first import, i.e. when the database is empty. See H2 docs for details.
        Parameters:
        enable - true or false
      • init

        public void init()
      • handleException

        public void handleException​(org.hibernate.JDBCException e)
      • handleException

        public void handleException​(SQLException sqlException)
      • dumpLocks

        public static void dumpLocks​(Connection connection)
      • shutdown

        public void shutdown()
      • shutdown

        public void shutdown​(boolean compact)
      • logStatistics

        public void logStatistics()
        Log Hibernate statistics, if enabled.
      • getBestIndex

        public static String getBestIndex​(Class<?> entity,
                                          String... orderedColumns)
        Extracts the best index for the given entity class for the given columns from JPA class annotations. The returned index may be used in SQL USE INDEX hints.
        Parameters:
        entity - entity
        orderedColumns - ordered columns
        Returns:
        an index or null, if we cannot find a suitable index