Interface Database

    • Method Detail

      • getType

        Database.Type getType()
        Returns the database type this Database represents.
        Returns:
        the database type
      • getHost

        String getHost()
        Returns the name of the host this database is running on.
        Returns:
        the database host name
      • getPort

        Integer getPort()
        Returns the port number this database is running on.
        Returns:
        the database port number
      • getSid

        String getSid()
        Returns the database service id or database name.
        Returns:
        the database service id
      • isEmbedded

        boolean isEmbedded()
        Returns true if this database is an embedded one
        Returns:
        true if this database is an embedded one
      • setUrlAppend

        void setUrlAppend​(String urlAppend)
        Sets the string to append to the connection URL.
        Parameters:
        urlAppend - a string to append to the connection URL
      • getUrlAppend

        String getUrlAppend()
        Returns the string to append to the connection URL.
        Returns:
        the string to append to the connection URL
      • getAutoIncrementQuery

        String getAutoIncrementQuery​(String idSource)
        Returns a query string for retrieving the last automatically generated id from the given id source
        Parameters:
        idSource - the source for the id, for example a sequence name or in the case of Derby, the name of the table auto generating the value
        Returns:
        a query string for retrieving the last auto-increment value from idSource
        Throws:
        NullPointerException - in case idSource is required and is null
      • getSequenceQuery

        String getSequenceQuery​(String sequenceName)
        Returns a query string for selecting the next value from the given sequence.
        Parameters:
        sequenceName - the name of the sequence
        Returns:
        a query for selecting the next value from the given sequence
        Throws:
        UnsupportedOperationException - in case the underlying database does not support sequences
        NullPointerException - in case sequenceName is null
      • getURL

        String getURL​(Properties connectionProperties)
        Returns the database url for this database, based on system properties
        Parameters:
        connectionProperties - the connection properties, used primarily to provide embedded databases with user info for authentication purposes
        Returns:
        the database url for this database, based on system properties
      • getAuthenticationInfo

        String getAuthenticationInfo​(Properties connectionProperties)
        In the case of embedded databases the user login info can be appended to the connection url, this method should return that string in case the dbms requires it and connectionProperties contains the username and password info, otherwise it should be safe to return null. This method is usually used in getURL() and onDisconnect().
        Parameters:
        connectionProperties - the connection properties
        Returns:
        an authentication string to append to the connection url, for example user=scott;password=tiger, null if none is required
      • shutdownEmbedded

        void shutdownEmbedded​(Properties connectionProperties)
        This should shutdown the database in case it is an embedded one and if that is applicable, such as for Derby.
        Parameters:
        connectionProperties - the connection properties
      • supportsSelectForUpdate

        boolean supportsSelectForUpdate()
        Returns true if this database supports the 'select for update' syntax
        Returns:
        true if this database supports the 'select for update' syntax
      • supportsNowait

        boolean supportsNowait()
        Returns true if this database supports the select for update NOWAIT option
        Returns:
        true if NOWAIT is supported for select for update
      • getCheckConnectionQuery

        String getCheckConnectionQuery()
        Returns a query to use when checking if the connection is valid, this is used in cases where the dbms does not support the isValid() call. Returning null is safe if isValid() is supported.
        Returns:
        a check connection query
        See Also:
        supportsIsValid()
      • getErrorMessage

        String getErrorMessage​(SQLException exception)
        Returns a user friendly error message for the given exception, otherwise simply return the message from exception
        Parameters:
        exception - the underlying SQLException
        Returns:
        the message assigned to the given exception
      • isAuthenticationException

        boolean isAuthenticationException​(SQLException exception)
        Returns true if this exception represents a login credentials failure
        Parameters:
        exception - the exception
        Returns:
        true if this exception represents a login credentials failure
      • isReferentialIntegrityException

        boolean isReferentialIntegrityException​(SQLException exception)
        Returns true if this exception is a referential integrity exception
        Parameters:
        exception - the exception
        Returns:
        true if this exception is a referential integrity exception
      • isUniqueConstraintException

        boolean isUniqueConstraintException​(SQLException exception)
        Returns true if this exception is a unique key exception
        Parameters:
        exception - the exception
        Returns:
        true if this exception is a unique key exception
      • addConnectionProperties

        Properties addConnectionProperties​(Properties properties)
        Adds any dbms specific connection properties to the given properties map, called each time a connection is created
        Parameters:
        properties - the properties map to add to
        Returns:
        the properties map
      • getDriverClassName

        String getDriverClassName()
        Returns the name of the driver class
        Returns:
        the name of the driver class
      • getDatabaseType

        static Database.Type getDatabaseType()
        Returns:
        the database type string as specified by the DATABASE_TYPE system property
        See Also:
        DATABASE_TYPE