Class DatabaseProduct


  • public final class DatabaseProduct
    extends Object
    Represent a Database Product name as returned by DatabaseMetaData.getDatabaseProductName().

    Ideally we shouldn't have to take care of Database specificities since we're using Hibernate to abstract ourselves from Databases. However it happens that Hibernate doesn't support setting Catalogs on some databases and instead we need to use our own tricks to do that and these tricks depend on the database. Hence the need to differentiate them and hence the need for this class.

    Version:
    $Id: 329669043d02a8f5c7d810cc79e8a3e707c7354f $
    • Field Detail

      • ORACLE

        public static final DatabaseProduct ORACLE
        The Product name and the JDBC scheme to recognize an Oracle DB.
      • DERBY

        public static final DatabaseProduct DERBY
        The Product name and the JDBC scheme to recognize a Derby DB.
      • HSQLDB

        public static final DatabaseProduct HSQLDB
        The Product name and the JDBC scheme to recognize a HSQLDB DB.
      • DB2

        public static final DatabaseProduct DB2
        The Product name and the JDBC scheme to recognize a DB2 DB.

        Per DB2 documentation at http://publib.boulder.ibm.com/infocenter/db2luw/v9r5/topic/com.ibm.db2.luw.apdv.java.doc/doc/c0053013.html, the database product name returned by the DatabaseMetaData.getDatabaseProductName() method of DB2 JDBC drivers varies by the OS and environment the product is running on. Hence the DB string here uses only the first 3 unique characters of the database product name. The toProduct(String) method also hence checks for String.startsWith(String) rather than an exact match.

      • MYSQL

        public static final DatabaseProduct MYSQL
        The Product name and the JDBC scheme to recognize a MySQL DB.
      • POSTGRESQL

        public static final DatabaseProduct POSTGRESQL
        The Product name and the JDBC scheme to recognize a PostgreSQL DB.
      • MSSQL

        public static final DatabaseProduct MSSQL
        The Product name and the JDBC scheme to recognize a Microsoft SQL Server DB.
      • H2

        public static final DatabaseProduct H2
        The Product name and the JDBC scheme to recognize a H2 DB.
      • UNKNOWN

        public static final DatabaseProduct UNKNOWN
        Represents an unknown database for which we were not able to find the product name.
    • Method Detail

      • toProduct

        public static DatabaseProduct toProduct​(String productNameOrJDBCScheme)
        Transform a product name represented as a string into a DatabaseProduct object.
        Parameters:
        productNameOrJDBCScheme - the string to parse (can either represent a product name or a URL connection DB scheme
        Returns:
        the DatabaseProduct object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object