Class Convert

java.lang.Object
org.compiere.dbPort.Convert
Direct Known Subclasses:
Convert_Oracle, Convert_SQL92

public abstract class Convert extends Object
Convert SQL from Oracle syntax to Target DB syntax
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 Details

      • REGEX_FLAGS

        public static final int REGEX_FLAGS
        RegEx: insensitive and dot to include line end characters
        See Also:
      • 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 Details

      • Convert

        public Convert()
    • Method Details

      • setVerbose

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

        public boolean execute(String sqlStatements, Connection conn)
        Execute SQL Statements (stops at first error).
        If an error occur, hadError() returns true.
        You can get error 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 occurred. Get more details via getConversionError() or getException().
        Returns:
        true if error had occurred
      • convertAll

        public String convertAll(String sqlStatements)
        Convert SQL Statements (stops at first error).
        Statements are delimited by /.
        If an error occurred, 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 Statements (stops at first error).
        If an error occurred, 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:
        last 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, carriage 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 -
        nonce -
        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:
        converted sql statement
      • 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)
        Log oraStatement and pgStatement to SQL migration script file.
        Parameters:
        oraStatement -
        pgStatement -
      • getMigrationScriptFileName

        public static String getMigrationScriptFileName(String ticketComment)
        Parameters:
        ticketComment -
        Returns:
        migration script file name
      • getMigrationScriptFolder

        public static String getMigrationScriptFolder(String dbtype)
        Parameters:
        dbtype - oracle or postgresql
        Returns:
        absolute migration script folder path for dbtype
      • isLogMigrationScript

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

        public static boolean isDontLogTable(String tableName)
        Parameters:
        tableName -
        Returns:
        true if log migration script should ignore tableName
      • closeLogMigrationScript

        public static void closeLogMigrationScript()
        Close the files for migration scripts, used just on Tests
      • getGeneratedMigrationScriptFileName

        public static String getGeneratedMigrationScriptFileName()
        Get the name of the migration script file
        Returns: