Class AbstractSqlQuery

    • Field Detail

      • logSql

        private static final org.slf4j.Logger logSql
        Log all SQL statements.
      • debugSqlEnabled

        private static final boolean debugSqlEnabled
        So we don't always have to call logSql.debug()
      • logParam

        private static final org.slf4j.Logger logParam
        Log all parameter bindings to prepared statement.
      • debugParamEnabled

        private static final boolean debugParamEnabled
        So we don't always have to call logParam.debug()
      • namedParameter

        private static final Pattern namedParameter
        Pattern that finds a named parameter in an SQL string. A named parameter is a colon (:) followed by one or more alphanumeric characters.
    • Constructor Detail

      • AbstractSqlQuery

        AbstractSqlQuery​(String rootEntity)
    • Method Detail

      • getDefaultSelects

        abstract Select[] getDefaultSelects()
      • getJepFunctions

        public abstract JepFunction[] getJepFunctions​(DbControl dc,
                                                      boolean restrictions)
        Create custom JEP function that can be used with the current query. The actual function need to implement either JepExpressionFunction or JepRestrictionFunction.
        Parameters:
        restrictions - If FALSE the metod should only return functions that can be used as Expression:s, otherwise it should return both expression and restriction functions
        Since:
        2.15 and 3.12
      • parseParameters

        String parseParameters​(String sql,
                               List<String> parameterOrder)
        Parse the given SQL and find named parameters. A named parameter is a colon (:) followed by one or more alphanumeric characters. Replaces the named parameters with a JDBC parameter placeholder, ie. a question mark. The name of the parameters are put in the specified list in the order they appear in the SQL string.
        Parameters:
        sql - The original SQL string, which may contain named parameters
        parameterOrder - A list that should store the name of the parameters in the correct order
        Returns:
        The new SQL statement with JDBC question marks instead of named parameters
      • getLimitHandler

        org.hibernate.dialect.pagination.LimitHandler getLimitHandler()
        Get a handler for adding LIMIT and OFFSET parameters to an SQL statement.
        Since:
        3.8
      • getRowSelectionForLimitHandler

        org.hibernate.engine.spi.RowSelection getRowSelectionForLimitHandler()
        Get a RowSelection object to be used with a LimitHandler so that it can modify and add parameters to the SQL.
        Returns:
        A RowSelection object if limit/offset should be applied, null otherwise
        Since:
        3.8
      • setParameters

        int setParameters​(PreparedStatement ps,
                          List<String> parameterOrder,
                          int parameterIndex)
                   throws SQLException
        Set parameter values on a prepared statement.
        Parameters:
        ps - The prepared statement
        parameterOrder - The names of the parameters in the order they appear in the prepared statement
        parameterIndex - The index of the first parameter to bind
        Returns:
        The number of parameters bound
        Throws:
        SQLException
      • setParameterValue

        private void setParameterValue​(PreparedStatement ps,
                                       int index,
                                       Object parameterValue,
                                       Type valueType)
                                throws SQLException
        Set a parameter value on a prepared statement. If the object is a BasicItem the id of the object is used a value.
        Parameters:
        ps - The prepared statement
        index - The index of the parameter, starting at 1
        parameterValue - The value of the parameter
        Throws:
        SQLException
      • closeResultSet

        protected void closeResultSet​(ResultSet result,
                                      String msg)
        Close the result set without throwing an exception. If the ResultSet.close() method throws an exception it is logged together with the message.
        Parameters:
        msg - A message to write to the log if the close fails
        result - The result set to close
        Since:
        3.1
      • closeStatement

        protected void closeStatement​(Statement stmt,
                                      String msg)
        Close the statement without throwing an exception. If the Statement.close() method throws an exception it is logged together with the message.
        Parameters:
        msg - A message to write to the log if the close fails
        stmt - The statement to close
        Since:
        3.1
      • rollbackToSavepoint

        protected void rollbackToSavepoint​(Connection conn,
                                           Savepoint savepoint,
                                           String msg)
        Rollback the current transaction to the given savepoint.
        Parameters:
        conn - The connection to rollback
        savepoint - The savepoint to rollback to
        msg - A message to write to the log if the rollback fails
        Since:
        3.1
      • releaseSavepoint

        protected void releaseSavepoint​(Connection conn,
                                        Savepoint savepoint,
                                        String msg)
        Release the given savepoint.
        Parameters:
        conn - The connection that holds the savepoint
        savepoint - The savepoint to release
        msg - A message to write to the log if the release fails
        Since:
        3.1