Class Convert

  • Direct Known Subclasses:
    Convert_Oracle, Convert_SQL92

    public abstract class Convert
    extends Object
    Convert SQL to Target DB
    Version:
    $Id: Convert.java,v 1.3 2006/07/30 00:55:04 jjanke Exp $
    Author:
    Jorg Janke, Victor Perez, Teo Sarca, www.arhipac.ro
  • BF [ 2782095 ] Do not log *Access records https://sourceforge.net/p/adempiere/bugs/1867/
  • TODO: BF [ 2782611 ] Migration scripts are not UTF8 https://sourceforge.net/p/adempiere/bugs/1869/, Teo Sarca
  • BF [ 3137355 ] PG query not valid when contains quotes and backslashes https://sourceforge.net/p/adempiere/bugs/2560/
    • Field Detail

      • REGEX_FLAGS

        public static final int REGEX_FLAGS
        RegEx: insensitive and dot to include line end characters
        See Also:
        Constant Field Values
      • m_stmt

        protected Statement m_stmt
        Statement used
      • m_conversionError

        protected String m_conversionError
        Last Conversion Error
      • m_exception

        protected Exception m_exception
        Last Execution Error
      • m_verbose

        protected boolean m_verbose
        Verbose Messages
    • Constructor Detail

      • Convert

        public Convert()
    • Method Detail

      • setVerbose

        public void setVerbose​(boolean verbose)
        Set Verbose
        Parameters:
        verbose -
      • execute

        public boolean execute​(String sqlStatements,
                               Connection conn)
        Execute SQL Statement (stops at first error). If an error occured hadError() returns true. You can get details via getConversionError() or getException()
        Parameters:
        sqlStatements -
        conn - connection
        Returns:
        true if success
        Throws:
        IllegalStateException - if no connection
      • getException

        public Exception getException()
        Return last execution exception
        Returns:
        execution exception
      • hasError

        public boolean hasError()
        Returns true if a conversion or execution error had occured. Get more details via getConversionError() or getException()
        Returns:
        true if error had occured
      • convertAll

        public String convertAll​(String sqlStatements)
        Convert SQL Statement (stops at first error). Statements are delimited by / If an error occured hadError() returns true. You can get details via getConversionError()
        Parameters:
        sqlStatements -
        Returns:
        converted statement as a string
      • convert

        public String[] convert​(String sqlStatements)
        Convert SQL Statement (stops at first error). If an error occured hadError() returns true. You can get details via getConversionError()
        Parameters:
        sqlStatements -
        Returns:
        Array of converted Statements
      • getConversionError

        public String getConversionError()
        Return last conversion error or null.
        Returns:
        lst conversion error
      • convertIt

        protected String[] convertIt​(String sqlStatements)
        Conversion routine (stops at first error).
          - convertStatement
              - convertWithConvertMap
              - convertComplexStatement
              - decode, sequence, exception
          
        Parameters:
        sqlStatements -
        Returns:
        array of converted statements
      • cleanUpStatement

        protected String cleanUpStatement​(String statement)
        Clean up Statement. Remove trailing spaces, carrige return and tab
        Parameters:
        statement -
        Returns:
        sql statement
      • replaceQuotedStrings

        protected String replaceQuotedStrings​(String inputValue,
                                              Vector<String> retVars,
                                              String nonce)
        Utility method to replace quoted string with a predefined marker
        Parameters:
        inputValue -
        retVars -
        nonce -
        Returns:
        string
      • recoverQuotedStrings

        protected String recoverQuotedStrings​(String retValue,
                                              Vector<String> retVars,
                                              String nonce)
        Utility method to recover quoted string store in retVars
        Parameters:
        retValue -
        retVars -
        Returns:
        string
      • escapeQuotedString

        protected String escapeQuotedString​(String in)
        hook for database specific escape of quoted string ( if needed )
        Parameters:
        in -
        Returns:
        string
      • convertWithConvertMap

        protected String convertWithConvertMap​(String sqlStatement)
        do convert map base conversion
        Parameters:
        sqlStatement -
        Returns:
        string
      • getConvertMap

        protected Map<String,​String> getConvertMap()
        Get convert map for use in sql convertion
        Returns:
        map
      • convertStatement

        protected abstract ArrayList<String> convertStatement​(String sqlStatement)
        Convert single Statements. - remove comments - process FUNCTION/TRIGGER/PROCEDURE - process Statement
        Parameters:
        sqlStatement -
        Returns:
        converted statement
      • isOracle

        public abstract boolean isOracle()
        True if the database support native oracle dialect, false otherwise.
        Returns:
        boolean
      • logMigrationScript

        public static void logMigrationScript​(String oraStatement,
                                              String pgStatement)
      • isLogMigrationScript

        public static boolean isLogMigrationScript()
        Returns:
        true if it is in log migration script mode