psdi.iface.util

Class SQLConverterUtil

  • All Implemented Interfaces:
    UpgConstants


    public class SQLConverterUtil
    extends Util
    Utility methods for programs in the psdi.configure package. These methods output various kinds of Sql statements, values, etc. but generally do not actually perform any database updates.

    Click here for an overview of the most commonly-used data structures.

    • Constructor Detail

      • SQLConverterUtil

        public SQLConverterUtil(java.sql.Connection conparam,
                                java.io.PrintStream outparam,
                                java.lang.String schemaOwnerparam)
                         throws java.lang.Exception
        Constructor. This is the normal way to instanciate this class.
        Throws:
        java.lang.Exception
    • Method Detail

      • cacheSequences

        public java.util.HashMap cacheSequences(java.lang.String tableName)
                                         throws java.lang.Exception
        Cache the sequences for later use in createSequences.
        Throws:
        java.lang.Exception
      • buildSelectStatement

        public java.lang.String buildSelectStatement(java.lang.String tbname,
                                                     java.util.TreeMap tableCols,
                                                     boolean includeDroppedCols,
                                                     boolean addRowstamp,
                                                     boolean addtenantID,
                                                     java.lang.String colNameList)
        Builds a select statement in the format "select col1, col2, col3, ... from tbname".

        If you need a "where" clause, you can append it separately.

        Besides being used for Select statements, this can be used with buildInsertStatementPrefix to create an Insert statement.

        Overrides:
        buildSelectStatement in class Util
        Parameters:
        tbname - Table name (must be persistent).
        tableCols - Column info, see getAttributeMeta.
        includeDroppedCols - True to include columns whose "changed" attribute equals "R", else False to exclude them.
        addRowstamp - True if the rowstamp column should be included in the statement, else False.
        colNameList - Can be null. If this parameter is not null, it should be a comma-delimited list of column names, and a column name will be included in the output string only if it exists in both the tableCols TreeMap and in the colNameList. If this parameter is null then this comparison is not performed. For building this list, see getColumnNames and getColumnNamesNative.
        Returns:
        Sql statement for select
      • buildInsertValuesStatement

        public java.util.TreeMap buildInsertValuesStatement(java.lang.String prefix,
                                                            java.sql.ResultSet rs,
                                                            java.util.TreeMap tableCols,
                                                            boolean includeDroppedCols,
                                                            java.lang.String rowstampValue,
                                                            boolean psFormat,
                                                            boolean defaultDate,
                                                            java.util.HashMap allSeq,
                                                            java.lang.String whereClause,
                                                            boolean dbc,
                                                            boolean addTenantID)
                                                     throws java.sql.SQLException,
                                                            java.io.UnsupportedEncodingException
        Build one complete insert statement in the format "insert into tbname (col1, col2, col3, ...) values (val1, val2, val3,...)". Uses the current row from the result set. To dump the entire table, you need to code a loop through the result set, calling this method for each row.

        For an example of how this can be used, see writeDumpTable.

        Any encrypted datatypes (such as password) will be set to a foobar value, as encrypted data cannot be output to a print file.

        Parameters:
        prefix - "insert into" part of the statement, see buildInsertStatementPrefix.
        rs - ResultSet, where you have already called "next" to get a row. It is presumed that the Select statement specified the column names in the same sequence as tableCols. See buildSelectStatement.
        tableCols - Column info, see getAttributeMeta. These must be in the same sequence as the columns listed in the prefix, presumed to be in sequence by attributeno.
        includeDroppedCols - True to include columns whose "changed" attribute equals "R", else False to exclude them.
        rowstampValue - String to specify in the statement for rowstamp value (for example, maxseq.nextval or '12345'). If no rowstamp should be included, this should be null.
        psFormat - If true, output will support use of PreparedStatement in Maxinst. If false, output will be normal string format for use in a Sql statement.
        Returns:
        Sql insert statement(s). Normally, the TreeMap will contain only one statement. However, if the data contained a Clob or string datatype longer than 2000 and this is Oracle or DB2, there will be one insert statement followed by one or more update statements until the entire Clob has been filled.
        Throws:
        java.io.UnsupportedEncodingException
        java.sql.SQLException
        See Also:
        Util.useQuotes(java.lang.String), Util.singleToDoubleQuotes(java.lang.String), SQLConverterUtil.getChunkUpdates(java.lang.String, int, java.lang.String, java.lang.String, java.sql.ResultSet, java.lang.Object, java.lang.String)
      • buildInsertElementDBC

        public org.jdom2.Element buildInsertElementDBC(java.lang.String tbname,
                                                       java.sql.ResultSet rs,
                                                       java.util.TreeMap tableCols,
                                                       java.util.List allData,
                                                       org.jdom2.Element header,
                                                       boolean defaultDate,
                                                       java.util.HashMap allSeq,
                                                       boolean allowReplace)
                                                throws java.sql.SQLException,
                                                       java.io.UnsupportedEncodingException
        Throws:
        java.sql.SQLException
        java.io.UnsupportedEncodingException
      • buildCSVfile

        public java.util.List buildCSVfile(java.lang.String tbname,
                                           java.sql.ResultSet rs,
                                           java.util.TreeMap tableCols,
                                           boolean addColumns)
                                    throws java.sql.SQLException,
                                           java.io.UnsupportedEncodingException
        Throws:
        java.sql.SQLException
        java.io.UnsupportedEncodingException
      • buildDBCFile

        public byte[] buildDBCFile(java.lang.String fileName,
                                   java.lang.String dir,
                                   java.util.List allData,
                                   java.lang.String scriptType,
                                   boolean demoOnly)
                            throws java.lang.Exception
        Get parent tables name
        Throws:
        MXException - Maximo Exception
        java.rmi.RemoteException - Remote Exception
        java.lang.Exception
      • buildFreeForm

        public java.util.List buildFreeForm(java.util.List allData,
                                            java.lang.String data,
                                            java.lang.String name)
                                     throws java.lang.Exception
        Get parent tables name
        Returns:
        name of the parent table
        Throws:
        MXException - Maximo Exception
        java.rmi.RemoteException - Remote Exception
        java.lang.Exception
      • getFileName

        public java.lang.String getFileName(java.lang.String dirName,
                                            java.lang.String name,
                                            java.lang.String ext)
                                     throws java.lang.Exception
        Get the full path and file name based on given message data.
        Parameters:
        dirName - directory name
        name - Service Name
        ext - extension
        Returns:
        Full path and file name of message file.
        Throws:
        MXException
        java.rmi.RemoteException
        java.lang.Exception
      • buildDefaineTableDBC

        public void buildDefaineTableDBC(java.lang.String tbname,
                                         boolean mainObject,
                                         java.util.List allData,
                                         boolean addDelete)
                                  throws java.lang.Exception
        Throws:
        java.lang.Exception
      • buildCreateRelationshipDBC

        public void buildCreateRelationshipDBC(java.lang.String parent,
                                               java.lang.String child,
                                               java.lang.String name,
                                               java.lang.String whereClause,
                                               java.lang.String remarks,
                                               java.util.List allData)
                                        throws java.lang.Exception
        Throws:
        java.lang.Exception
      • buildCreateSigOptionDBC

        public void buildCreateSigOptionDBC(java.lang.String app,
                                            java.lang.String optionName,
                                            int esigenabled,
                                            int visible,
                                            java.lang.String description,
                                            java.lang.String alsoGrants,
                                            java.lang.String alsoRevokes,
                                            java.lang.String prereq,
                                            java.lang.String langCode,
                                            java.lang.String grantApp,
                                            boolean addDelete,
                                            java.util.List allData)
                                     throws java.lang.Exception
        Throws:
        java.lang.Exception
      • handleSpecialChars

        protected static java.lang.String handleSpecialChars(java.lang.String str)
        Calls replaceSpecialCharsForXML for &, <, > and " in str.
        Parameters:
        str -
        Returns:
      • getMaxRowstamp

        public java.lang.Object getMaxRowstamp(java.lang.String tableName)
                                        throws java.lang.Exception
        Cache the sequences for later use in createSequences.
        Throws:
        java.lang.Exception
      • buildRecordList

        public java.lang.String buildRecordList(java.lang.String tableName,
                                                long maxRowStamp)
                                         throws java.lang.Exception
        Cache the sequences for later use in createSequences.
        Throws:
        java.lang.Exception
      • buildRecordWhere

        public java.lang.String buildRecordWhere(java.lang.String tableName,
                                                 long maxRowStamp)
                                          throws java.lang.Exception
        Cache the sequences for later use in createSequences.
        Throws:
        java.lang.Exception