Class DatabaseUtils

java.lang.Object
com.priint.pubserver.connector.jpa.api.DatabaseUtils

public class DatabaseUtils extends Object
Database utilities for working with JPA.

Methods to support special queries that are vendor dependent.

Database types are "mysql", "oracle", "sqlserver", and "unknown".

  • Field Details

  • Method Details

    • getLikeStr

      public static String getLikeStr(String searchStr, String databaseDriverName)
      Returns a JPQL LIKE expression value from an input string.
      E.g. for Oracle this will escape the string and then prepend and append "%".

      No input (null) will return a "match all" expression.

      Empty string will return an exact search for an empty string.
      Note: This is currently not supported in the ison UI.

      You cannot specify a search for a database NULL value.

      Parameters:
      searchStr - the search str
      databaseDriverName - the database driver name
      Returns:
      the like str
    • getStartWithStr

      public static String getStartWithStr(String searchStr, String databaseDriverName)
      Returns a JPQL LIKE expression value from an input string. E.g. for Oracle this will escape the string and then append "%".

      No input (null) will return a "match all" expression.

      Empty string will return an exact search for an empty string.
      Note: This is currently not supported in the ison UI.

      You cannot specify a search for a database NULL value.

      Parameters:
      searchStr - the search str
      databaseDriverName - the database driver name
      Returns:
      the start with str
    • getForLikeStr

      public static String getForLikeStr(String searchStr, String databaseDriverName)
      Escapes a JPQL LIKE expression value.

      E.g. for Oracle this will escape the characters "_" and "%" by prepending them with "?".

      No input (null) will return a "match all" expression.

      Empty string will return an exact search for an empty string.
      Note: This is currently not supported in the ison UI.

      You cannot specify a search for a database NULL value.

      Parameters:
      searchStr - the search str
      databaseDriverName - the database driver name
      Returns:
      the for like str
    • getDatabaseType

      public static String getDatabaseType(jakarta.persistence.EntityManager em)
      Get the database type backing an JPA entity manager.

      Type is extracted from the JDBC URL as lowercase string. E.g. "sqlserver" from jdbc:sqlserver://127.0.0.1:1433;databaseName=priint_PublishingHubDB

      Supported types are "mysql", "sqlserver", "oracle", and "unknown"

      Parameters:
      em - the em
      Returns:
      the database type
    • getMetaData

      public static DatabaseMetaData getMetaData(jakarta.persistence.EntityManager em)
      Get the metadata of the database backing an JPA entity manager.

      Example usages of this method for an MSSQL

      • getMetaData(em).getDatabaseProductName() => Microsoft SQL Server
      • getMetaData(em).getDatabaseProductVersion() => 12.00.2269
      • getMetaData(em).getDriverName() => Microsoft JDBC Driver 4.0 for SQL Server
      • getMetaData(em).getDriverVersion() => 4.0.2206.100
      • getMetaData(em).getURL() => jdbc:sqlserver://127.0.0.1:1433;databaseName=priint_PublishingHubDB;sendStringParametersAsUnicode=true;...
      Parameters:
      em - the em
      Returns:
      the meta data
    • getDatabaseDriverName

      @Deprecated public static String getDatabaseDriverName(jakarta.persistence.EntityManager em)
      Gets the database driver name.
      Parameters:
      em - the em
      Returns:
      the database driver name