psdi.configure

Class CommonShell

  • java.lang.Object
    • psdi.configure.CommonShell
  • All Implemented Interfaces:
    UpgConstants
    Direct Known Subclasses:
    ConfigDB, DropBackup, EncryptProperties, Maxinst, RestoreFromBackup, TextSearchScript, Unlcvt, Validate, ValidateDBForMAS


    public abstract class CommonShell
    extends java.lang.Object
    implements UpgConstants
    CommonShell is the superclass for most of the configuration utility programs. It provides standard methods for running from the commandline and running from within MXServer, and also handles the common runtime parameters.

    Generally speaking, the instance should provide the following methods:

    1. To support invokation from the commandline, the instance should provide main.
    2. If additional runtime parameters are to be supported, the instance should override setupInstance (for standalone invokation), setupNested (for invokation from another configuration utility), and/or endSetupInstance.
    3. The method process must be overridden to provide the core functionality.
    4. If additional end-run processing is required, endProcessInstance should be overridden.

    To invoke from within MXServer, the calling routine must do the following:

    1. Instanciate with the constructor that accepts the MXServer parameter.
    2. Call setup, passing the appropriate parameters.
    3. Call process.
    4. Call endProcess.

    To invoke from another configuration utility class, the calling routine must do the following:

    1. Instanciate with whatever constructor is appropriate.
    2. Call setupNested, passing the appropriate parameters.
    3. Call process.
    4. Call endProcess.

    The commandline parameters for CommonShell are as follows:

    Parameter IDParameter ValueDescription
    -aDatabase aliasThis is optional. If not specified, uses mxe.db.url from properties file. The value is used in setupFromPropfile when connecting to the database. If this class is invoked from within MXServer, this parameter is not used.
    -dDirectory for output fileThis is optional. If not specified, uses the MXServer "log" directory. This value is used in endSetup. If you do not want to specify -d and do not want the "log" directory, then override createOutfile.
    -e(none)This is optional. Indicates to execute all Sql statements. If this is not specified, only the necessary Select stements will be executed. Either -l, -e, or both must be specified. This value is stored in the execute variable and is used in doSql.
    -fFilename for properties fileThis is optional. If not specified, the default is maximo.properties. The value is used in setupFromPropfile. If this class is invoked from within MXServer, this parameter is not used. Also see -k parameter to specify properties directory.
    -h(none)Show help. If specified, a list of the possible standard commandline parameters will be printed to the screen, and the program will not run after that.
    -help(none)Same as -h.
    -kDirectory for properties fileThis is optional. If this class is invoked from within MXServer, this parameter is not used. Also see -f parameter to specify properties filename.
    -l(none)This is optional. Indicates to write all Sql statements the the logfile (except selects). Either -l, -e, or both must be specified. This value is stored in the log variable and is used in doSql.
    -oFilename for output logThis is optional. If not specified, uses classname + YYYY + MM (month) + DD + HH24 + MM (minutes) + SS.log. For example: ConfigDB20021209100930.log.
    -pPassword for database connectionThis is optional. If not specified, uses mxe.db.password from properties file, or "maximo". The value is handled in setupFromPropfile when connecting to the database. If this class is invoked from within MXServer, this parameter is not used (the class calls getSystemUserInfo).
    -uUsername for database connectionThis is optional. If not specified, uses mxe.db.user from properties file, or "maximo". The value is handled in setupFromPropfile when connecting to the database. If this class is invoked from within MXServer, this parameter is not used (the class calls getSystemUserInfo).
    • Field Detail

      • classShortName

        protected java.lang.String classShortName
        Used in CommonShell for reporting in messages, etc.
      • propFileNameDefault

        protected java.lang.String propFileNameDefault
        The Properties filename can be passed in via an argument. The default value, stored here, is "maximo.properties".
      • driver

        protected java.sql.Driver driver
        Database driver, initialized by setup, cleared in endProcess.
      • schemaOwner

        protected java.lang.String schemaOwner
        Schema owner global variable.
      • userName

        protected java.lang.String userName
        User name for connecting to database.
      • url

        protected java.lang.String url
        URL for connecting to database.
      • log

        protected boolean log
        True if logging (-l parameter), False if not logging.
      • execute

        protected boolean execute
        True if executing (-e parameter), False if not executing.
      • outFileNameDefault

        protected java.lang.String outFileNameDefault
        The output filename can be passed in via an argument. The default value, stored here, is the classShortName + ".log".
      • outputFile

        protected java.io.File outputFile
        The output file.
      • dbIn

        protected int dbIn
        The database platform we are connected to. Valid values are specified in UpgConstants.
      • sYes

        protected java.lang.String sYes
        The value indicating Yes for YORN attributes.
      • sNo

        protected java.lang.String sNo
        The value indicating No for YORN attributes.
      • con

        protected java.sql.Connection con
        The database connection.
      • externalConnection

        protected boolean externalConnection
        True if this connection was set via setConnection. Normally this will be False.
      • out

        protected java.io.PrintStream out
        The print stream for the log.
      • util

        protected Util util
        Reference to the Util class.
      • servername

        protected java.lang.String servername
        The name of MXServer.
      • hostname

        protected java.lang.String hostname
        The name of the host.
      • port

        protected java.lang.String port
        The rmi registry port
      • mxs

        protected MXServer mxs
        MXServer, passed via the constructor or otherwise established if MXServer is running.
      • thisIsNested

        protected boolean thisIsNested
        Identifies whether this class is owned by another; set to true in setupNested.
      • session

        protected MXSession session
        Session, if MXServer is running.
      • conKey

        protected ConnectionKey conKey
        Database connection key, if established via MXServer.
      • conService

        protected AppServiceRemote conService
        Service for the connection key, if established via MXServer.
      • myLogger

        protected MXLogger myLogger
        Logger to use when running from MXServer ("maximo.service.CONFIGURE").
      • forceCreateOutfile

        protected boolean forceCreateOutfile
        This will force calling createOutfile even when myLogger is not null. (Usually you will use the logger when called from MXServer, and the outfile when called from DOS.)
      • lastSqlIssued

        protected java.lang.String lastSqlIssued
        The last command issued through doSql.
      • listStream

        public java.io.PrintStream listStream
        The print stream for the lis output.
      • userLangCode

        protected java.lang.String userLangCode
    • Constructor Detail

      • CommonShell

        public CommonShell()
        This constructor does nothing. Used when running from the DOS prompt.
      • CommonShell

        public CommonShell(MXServer server)
        This constructor accepts parameter for MXServer and sets value for mxs. Used when invoked from the Config application.
    • Method Detail

      • process

        public abstract void process()
                              throws java.lang.Exception
        Main processing routine for this class. In CommonShell, this does nothing. It must be overridden by the instance.

        Either setup or setupNested must be called prior to process.

        Throws:
        java.lang.Exception
      • doSql

        public void doSql(java.util.List list)
                   throws java.lang.Exception
        Loops through an array and calls doSql for each element.
        Parameters:
        list - Any instance or extension of AbstractList, including ArrayList, etc.
        Throws:
        java.lang.Exception
        See Also:
        CommonShell.doSql(String)
      • doSql

        public void doSql(java.util.List list,
                          Util util)
                   throws java.lang.Exception
        Loops through an array and calls doSql for each element.
        Parameters:
        list - Any instance or extension of AbstractList, including ArrayList, etc.
        Throws:
        java.lang.Exception
        See Also:
        CommonShell.doSql(String)
      • doSql

        public void doSql(java.lang.String sql)
                   throws java.lang.Exception
        Looks at params to determine whether the execute only, log only, or both execute and log.
        Parameters:
        sql - The Sql statement
        Throws:
        java.lang.Exception
      • doSql

        public void doSql(java.lang.String sql,
                          Util util)
                   throws java.lang.Exception
        Looks at params to determine whether the execute only, log only, or both execute and log.
        Parameters:
        sql - The Sql statement
        Throws:
        java.lang.Exception
      • doCall

        public void doCall(java.lang.String sql)
                    throws java.lang.Exception
        Execute a callable statement.
        Parameters:
        sql - The statement, such as "{call maximo_ts_job_call}".
        Throws:
        java.lang.Exception
      • doDB2TextSearchCall

        public void doDB2TextSearchCall(java.lang.String sql)
                                 throws java.lang.Exception
        For DB2 text search procedures (SYSPROC.SYSTS...).
        Parameters:
        sql -
        Throws:
        java.lang.Exception
      • doWait

        public void doWait(int milli)
                    throws java.lang.Exception
        Wait the specified number of milliseconds.
        Parameters:
        milli -
        Throws:
        java.lang.Exception
      • getProperty

        public java.lang.String getProperty(java.lang.String propName)
        Get the property value from cache. If the property is not defined, this will return null. If the property is defined but has no value, this will return the empty string.

        This will not work for Maxinst, since properties will not yet exist on database.

        Parameters:
        propName - Property name
        Returns:
        Property value
      • reformatForSqlsvr

        public static java.lang.String reformatForSqlsvr(java.sql.Connection sqlCon,
                                                         java.lang.String sqlIn)
                                                  throws java.lang.Exception
        Throws:
        java.lang.Exception
      • reformatForSqlsvrMaxSequence

        public static java.lang.String reformatForSqlsvrMaxSequence(java.sql.Connection sqlCon,
                                                                    java.lang.String sql)
                                                             throws java.lang.Exception
        This method is used for reformatting the sql statement for Sql Server script. Specifically, any statement that uses the oracle sequence (namely, ***Seq.nextVal), should be replaced by the next sequence number obtained from the MaxSequence table. It also updates the MaxSequence table with the new number.

        This method is provided in CommonShell so that those processes that need it can reformat the Sql statement input to doSql before executing. It does not automatically reformat anything via the superclass.

        Parameters:
        sqlCon - Connection
        sql - The original sql statement.
        Returns:
        The reformated sql statement.
        Throws:
        java.lang.Exception
      • auditProcess

        public void auditProcess(java.lang.String process,
                                 java.lang.String message)
                          throws java.lang.Exception
        Throws:
        java.lang.Exception
      • reformatForDB2

        public static java.lang.String reformatForDB2(java.sql.Connection sqlCon,
                                                      java.lang.String sqlIn)
                                               throws java.lang.Exception
        Reformat the nextval for DB2
        Parameters:
        sqlCon -
        sqlIn -
        Returns:
        relaced sql string
        Throws:
        java.lang.Exception
      • execRuntime

        public void execRuntime(java.lang.String arg)
                         throws java.lang.Exception
        Execute a runtime command on the O/S.
        Parameters:
        arg -
        Throws:
        java.lang.Exception
      • showMXException

        public void showMXException(MXApplicationException e,
                                    boolean infoOnly,
                                    boolean hideErrorKey)
        Display a message to the console and to the logfile, including errorGroup and errorKey.
        Parameters:
        e - The MXApplicationException; must have error group "configdb".
        infoOnly - True if this is an Info message, False is this is an Error (or Warning) message.
        hideErrorKey - True to hide the errorGroup and errorKey. This would be True for messages such as the header of the Unlcvt output.
        See Also:
        CommonShell.getDisplayMessage(java.lang.String, java.lang.Object[])
      • getDisplayMessage

        public java.lang.String getDisplayMessage(java.lang.String errorkey,
                                                  java.lang.Object[] params)
        Error group is assumed to be "configdb".
        Parameters:
        errorkey -
        params -
        Returns:
        String of message with param substitutions (if any).
      • getDisplayMessage

        public java.lang.String getDisplayMessage(java.lang.String errorkey)
        Call getDisplayMessage with null second param. Error group is assumed to be "configdb".
        Parameters:
        errorkey -
        Returns:
        String of message.
      • showMXException

        public void showMXException(MXApplicationException e)
        Display a message to the console and to the logfile, including errorGroup and errorKey. Call {#link #showMXException(MXApplicationException, boolean) showMXException} with second parameter False.
        Parameters:
        e - The MXApplicationException; must have error group "configdb".
      • showMsg

        public void showMsg(java.lang.String str)
        Display a one-line "info" message to the console (or Logger) and to the logfile. Also to the list file, if available.
        Parameters:
        str - The one-line message to be displayed.
      • logSql

        public final void logSql(java.lang.String sql)
        Records a sql statement to the log, and only the log. A SQL terminator (; or go) will be placed after the sql statement.
        Parameters:
        sql - The Sql to record
      • getRootDirName

        public java.lang.String getRootDirName()
                                        throws java.lang.Exception
        Get the name of the MXServer root directory. This is used for finding the "log" subdirectory.
        Returns:
        The name of the MXServer root directory.
        Throws:
        java.lang.Exception
      • setupInstance

        public void setupInstance(java.util.HashMap params)
                           throws java.lang.Exception
        In CommonShell, this does nothing. In an extension, it can handle parameters in addition to those in CommonShell. It is called from setup after the standard parameters have been loaded into cache.

        If the output file name should be anything other than classname + ".log", the default value outFileNameDefault should be set here.

        Parameters:
        params - HashMap of input parameters, where key = the parameter identifier (for example, -u) and value = the value of the parameter (for example, SMITH). If there is no value, it should equal the empty string "". See javadocs for the list of parameters for this class.
        Throws:
        java.lang.Exception
      • setupFromPropfile

        public java.lang.String setupFromPropfile(java.lang.String propfile,
                                                  java.lang.String user,
                                                  java.lang.String password,
                                                  java.lang.String tempUrl,
                                                  java.lang.String rootDirName,
                                                  java.lang.String propdir)
                                           throws java.lang.Exception
        Setup when not invoked directly from MXServer. Uses the properties file and the commandline parameters to connect to database, etc.
        Parameters:
        propfile - Name of properties file
        user - Username when not connecting via MXServer (optional). Must be a superuser. Defaults to mxe.db.user.
        password - Password when not connecting via MXServer (optional). Must be a superuser. Defaults to mxe.db.password.
        tempUrl - Database url (alias) (optional). Defaults to mxe.db.url.
        rootDirName - The name of the MXServer root directory.
        propdir - The name of the directory containing the properties file.
        Returns:
        Database url
        Throws:
        java.lang.Exception
      • getMessage

        protected java.lang.String getMessage(java.lang.String eg,
                                              java.lang.String ek,
                                              java.lang.String defaultMsg,
                                              java.lang.Object[] param)
      • setupNested

        public void setupNested(java.sql.Connection con,
                                Util util,
                                java.lang.String schemaOwner,
                                java.sql.Driver driver,
                                java.lang.String outdir,
                                boolean logparam,
                                boolean execparam,
                                java.util.HashMap params,
                                java.lang.String nestedUrl)
                         throws java.lang.Exception
        This version of setup is used when this class is invoked from another configuration utility (for example, when ConfigDB is instanciated from Upgrade). Either setup or setupNested must be called prior to process.

        If an extension of CommonShell has more than the standard parameters, the method setupNestedInstance or endSetupInstance should be extended.

        Parameters:
        con - Database connection
        util - Util class
        schemaOwner - The schema owner
        driver - Database driver
        outdir - Output directory
        logparam - True for verbose logging, False to log only messages.
        execparam - True to execute Sql, else False.
        params - HashMap for any additional parameters required for the instance. If no additional parameters are needed, this may be null or empty.
        nestedUrl - Database url.
        Throws:
        java.lang.Exception
        See Also:
        CommonShell.setupNestedInstance(java.util.HashMap), CommonShell.endSetup(java.lang.String, java.lang.String, java.util.HashMap), CommonShell.thisIsNested
      • setupNestedInstance

        public void setupNestedInstance(java.util.HashMap params)
                                 throws java.lang.Exception
        In CommonShell, this does nothing. In an extension, it can handle parameters in addition to those in CommonShell. It is called from setupNested after the standard parameters have been loaded into cache.
        Parameters:
        params - HashMap of any additional runtime parameters beyond those explicitly provided via setupNested, where key = the parameter identifier (for example, -u) and value = the value of the parameter (for example, SMITH). If there is no value, it should equal the empty string "". See javadocs for the list of parameters for this class.
        Throws:
        java.lang.Exception
      • createOutfile

        public void createOutfile(java.lang.String outdir,
                                  java.lang.String outfile)
                           throws java.lang.Exception
        Create the output file (outputFile and out). If no -d parameter was specified, this defaults to the mxserver "log" directory, unless this method is overridden in the instance.
        Parameters:
        outdir - The output directory.
        outfile - The output filename.
        Throws:
        java.lang.Exception
      • logMessage

        public void logMessage(java.lang.String message)
        Logs a message onto printstream
        Parameters:
        message -
        Throws:
        java.lang.Exception
      • getOutfile

        public java.io.File getOutfile()
        Return the output file.
        Returns:
        #outputFile
      • getOutstream

        public java.io.PrintStream getOutstream()
        Return logfile.
        Returns:
        PrintStream for logfile.
        See Also:
        CommonShell.out
      • endSetupInstance

        public void endSetupInstance(java.lang.String outdir,
                                     java.lang.String outfile,
                                     java.util.HashMap params)
                              throws java.lang.Exception
        In CommonShell, this does nothing. In an extension, it can handle parameters in addition to those in CommonShell. It is called from endSetup after the standard parameters have been loaded into cache.
        Parameters:
        params - HashMap of any additional runtime parameters, where key = the parameter identifier (for example, -u) and value = the value of the parameter (for example, SMITH). If there is no value, it should equal the empty string "". See javadocs for the list of parameters for this class.
        Throws:
        java.lang.Exception
      • endProcess

        public void endProcess(boolean errors)
                        throws java.lang.Exception
        Close the connection, deregister the driver.
        Parameters:
        errors - True if ended with errors
        Throws:
        java.lang.Exception
        See Also:
        CommonShell.endProcessInstance()
      • endProcessInstance

        public void endProcessInstance()
                                throws java.lang.Exception
        Called from endProcess for any additional end-process functionality. Does nothing in CommonShell.
        Throws:
        java.lang.Exception
      • loadMessageCache

        protected void loadMessageCache()
                                 throws java.lang.Exception
        Call {#loadMessageCacheSub loadMessageCacheSub} with messages from database using msggroup "configdb".
        Throws:
        java.lang.Exception
        See Also:
        CommonShell.loadMessageCacheSub(java.lang.String)
      • loadMessageCacheSub

        protected void loadMessageCacheSub(java.lang.String msggroup)
                                    throws java.lang.Exception
        Load {#messageCache messageCache} with messages from database using msggroup provided in the parameter.
        Parameters:
        msggroup - The value to use for maxmessages.msggroup when reading from this table.
        Throws:
        java.lang.Exception
      • isXmlOut

        protected boolean isXmlOut()
        Returns:
        Returns the xmlOut.
      • setXmlOut

        protected void setXmlOut(boolean xmlOut)
        Parameters:
        xmlOut - The xmlOut to set.
      • setDB2TextOutput

        public void setDB2TextOutput(java.io.PrintStream out1,
                                     java.io.PrintStream out2)
      • setUserLangCode

        public void setUserLangCode(java.lang.String value)
                             throws java.lang.Exception
        Parameters:
        value - The user's language code -- used only for running within an app in MXServer.
        Throws:
        java.lang.Exception
      • setConnection

        public void setConnection(java.sql.Connection inCon)
                           throws java.lang.Exception
        Parameters:
        inCon - The connection for use in special situations.
        Throws:
        java.lang.Exception