Package mondrian.tui

Class CmdRunner


  • public class CmdRunner
    extends java.lang.Object
    Command line utility which reads and executes MDX commands.

    TODO: describe how to use this class.

    Author:
    Richard Emberson
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      protected static class  CmdRunner.Options  
    • Field Summary

      Fields 
      Modifier and Type Field Description
      (package private) static java.text.NumberFormat nf  
    • Constructor Summary

      Constructors 
      Constructor Description
      CmdRunner​(CmdRunner.Options options, java.io.PrintWriter out)
      Creates a CmdRunner.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected static void appendCube​(java.lang.StringBuilder buf)  
      protected static void appendEcho​(java.lang.StringBuilder buf)  
      protected static void appendError​(java.lang.StringBuilder buf)  
      protected static void appendExit​(java.lang.StringBuilder buf)  
      protected static void appendExpr​(java.lang.StringBuilder buf)  
      protected static void appendFile​(java.lang.StringBuilder buf)  
      protected static void appendFunc​(java.lang.StringBuilder buf)  
      protected static void appendIndent​(java.lang.StringBuilder buf, int i)  
      protected static void appendList​(java.lang.StringBuilder buf)  
      protected static void appendLog​(java.lang.StringBuilder buf)  
      protected static void appendParam​(java.lang.StringBuilder buf)  
      protected static void appendSet​(java.lang.StringBuilder buf)  
      (package private) void clearError()  
      protected void commandLoop​(boolean interactive)  
      protected void commandLoop​(java.io.File file)  
      protected void commandLoop​(java.io.Reader in, boolean interactive)
      The Command Loop where lines are read from the InputStream and interpreted.
      protected void commandLoop​(java.lang.String mdxCmd, boolean interactive)  
      protected void debug​(java.lang.String msg)  
      java.lang.String execute​(java.lang.String queryString)
      Executes a query and returns the result as a string.
      protected java.lang.String executeCube​(java.lang.String mdxCmd)  
      void executeCubeCommand​(java.lang.String cubename, java.lang.String command, java.lang.StringBuilder buf)  
      protected java.lang.String executeEcho​(java.lang.String mdxCmd)  
      protected java.lang.String executeError​(java.lang.String mdxCmd)  
      protected java.lang.String executeExpr​(java.lang.String mdxCmd)  
      protected java.lang.String executeFile​(java.lang.String mdxCmd)  
      protected java.lang.String executeFunc​(java.lang.String mdxCmd)  
      protected static java.lang.String executeHelp​(java.lang.String mdxCmd)  
      protected java.lang.String executeList​(java.lang.String mdxCmd)  
      protected java.lang.String executeLog​(java.lang.String mdxCmd)  
      protected java.lang.String executeMdxCmd​(java.lang.String mdxCmd)  
      protected java.lang.String executeParam​(java.lang.String mdxCmd)  
      protected java.lang.String executeSet​(java.lang.String mdxCmd)  
      protected static java.lang.String getCatalogURLProperty()  
      Connection getConnection()
      Gets a connection to Mondrian.
      Connection getConnection​(boolean fresh)
      Gets a Mondrian connection, creating a new one if fresh is true.
      java.lang.String getConnectString()  
      java.lang.String getConnectString​(boolean fresh)  
      protected static java.lang.String getConnectStringProperty()  
      Cube getCube​(java.lang.String name)  
      Cube[] getCubes()  
      protected static java.lang.String getJdbcDriversProperty()  
      protected static java.lang.String getJdbcPasswordProperty()  
      protected static java.lang.String getJdbcURLProperty()  
      protected static java.lang.String getJdbcUserProperty()  
      protected static int getLine​(java.io.Reader reader, java.lang.StringBuilder line)
      Read the next line of input.
      OlapConnection getOlapConnection()
      Gets an olap4j connection, creating a new one if fresh is true.
      long getQueryTime()  
      boolean getTimeQueries()  
      long getTotalQueryTime()  
      java.lang.String highCardToString​(Result result)
      Converts a Result object to a string printing to standard output directly, without buffering.
      static boolean isParam​(java.lang.String name)  
      static boolean isProperty​(java.lang.String propertyName)  
      void listCubeAttribues​(java.lang.String name, java.lang.StringBuilder buf)  
      void listCubeName​(java.lang.StringBuilder buf)  
      static void listParam​(java.lang.String name, java.lang.StringBuilder buf)  
      static void listParameterNameValues​(java.lang.StringBuilder buf)  
      static void listPropertiesAll​(java.lang.StringBuilder buf)  
      static void listProperty​(java.lang.String propertyName, java.lang.StringBuilder buf)  
      static void listPropertyNames​(java.lang.StringBuilder buf)  
      void loadParameter​(Query query, Parameter param)  
      void loadParameters​(Query query)  
      protected static void loadPropertiesFromFile​(java.lang.String propFile)  
      static void main​(java.lang.String[] args)  
      void makeConnectString()  
      void noCubeCaching()  
      mondrian.tui.CmdRunner.Expr parseParameter​(java.lang.String value)  
      protected void printQueryTime()  
      protected void printResults​(java.lang.String resultString)  
      protected void processSoapXmla​(java.io.File file, int validateXmlaResponse)
      This is called to process a file containing XMLA as the contents of SOAP xml.
      protected void processXmla​(java.io.File file, int validateXmlaResponce)
      This is called to process a file containing XMLA xml.
      protected static int readBlock​(java.io.Reader reader, java.lang.StringBuilder line, int offset, java.lang.String startDelim, java.lang.String endDelim, boolean allowEscape, boolean addToBuf, java.lang.StringBuilder buf, int i)
      Start of a delimted block, read all of it even if it spans more than one line adding each line's to the buffer.
      protected static java.lang.String readLine​(java.io.Reader reader, boolean inMdxCmd)
      Gather up a line ending in '\n' or EOF.
      protected static int readString​(java.io.Reader reader, java.lang.StringBuilder line, int offset, java.lang.StringBuilder buf, int i)
      Start of a string, read all of it even if it spans more than one line adding each line's to the buffer.
      protected java.lang.String reExecuteMdxCmd()  
      Result runQuery​(java.lang.String queryString, boolean loadParams)
      Executes a query and returns the result.
      <T> T runQuery​(java.lang.String queryString, Util.Functor1<T,​CellSet> f)
      Executes a query and processes the result using a callback.
      void setCubeAttribute​(java.lang.String cubename, java.lang.String name, java.lang.String value, java.lang.StringBuilder buf)  
      (package private) void setError​(java.lang.String s)  
      (package private) void setError​(java.lang.Throwable t)  
      static void setParameter​(java.lang.String name, java.lang.String value)  
      static boolean setProperty​(java.lang.String name, java.lang.String value)  
      void setTimeQueries​(boolean timeQueries)  
      java.lang.String toString​(Result result)
      Converts a Result object to a string
      protected static void usage​(java.lang.String msg, java.io.PrintStream out)
      Prints a usage message.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • nf

        static java.text.NumberFormat nf
    • Constructor Detail

      • CmdRunner

        public CmdRunner​(CmdRunner.Options options,
                         java.io.PrintWriter out)
        Creates a CmdRunner.
        Parameters:
        options - Option set, or null to use default options
        out - Output writer, or null to use System.out.
    • Method Detail

      • setTimeQueries

        public void setTimeQueries​(boolean timeQueries)
      • getTimeQueries

        public boolean getTimeQueries()
      • getQueryTime

        public long getQueryTime()
      • getTotalQueryTime

        public long getTotalQueryTime()
      • noCubeCaching

        public void noCubeCaching()
      • setError

        void setError​(java.lang.String s)
      • setError

        void setError​(java.lang.Throwable t)
      • clearError

        void clearError()
      • listPropertyNames

        public static void listPropertyNames​(java.lang.StringBuilder buf)
      • listPropertiesAll

        public static void listPropertiesAll​(java.lang.StringBuilder buf)
      • listProperty

        public static void listProperty​(java.lang.String propertyName,
                                        java.lang.StringBuilder buf)
      • isProperty

        public static boolean isProperty​(java.lang.String propertyName)
      • setProperty

        public static boolean setProperty​(java.lang.String name,
                                          java.lang.String value)
      • loadParameters

        public void loadParameters​(Query query)
      • loadParameter

        public void loadParameter​(Query query,
                                  Parameter param)
      • parseParameter

        public mondrian.tui.CmdRunner.Expr parseParameter​(java.lang.String value)
      • listParameterNameValues

        public static void listParameterNameValues​(java.lang.StringBuilder buf)
      • listParam

        public static void listParam​(java.lang.String name,
                                     java.lang.StringBuilder buf)
      • isParam

        public static boolean isParam​(java.lang.String name)
      • setParameter

        public static void setParameter​(java.lang.String name,
                                        java.lang.String value)
      • getCubes

        public Cube[] getCubes()
      • getCube

        public Cube getCube​(java.lang.String name)
      • listCubeName

        public void listCubeName​(java.lang.StringBuilder buf)
      • listCubeAttribues

        public void listCubeAttribues​(java.lang.String name,
                                      java.lang.StringBuilder buf)
      • executeCubeCommand

        public void executeCubeCommand​(java.lang.String cubename,
                                       java.lang.String command,
                                       java.lang.StringBuilder buf)
      • setCubeAttribute

        public void setCubeAttribute​(java.lang.String cubename,
                                     java.lang.String name,
                                     java.lang.String value,
                                     java.lang.StringBuilder buf)
      • execute

        public java.lang.String execute​(java.lang.String queryString)
        Executes a query and returns the result as a string.
        Parameters:
        queryString - MDX query text
        Returns:
        result String
      • runQuery

        public Result runQuery​(java.lang.String queryString,
                               boolean loadParams)
        Executes a query and returns the result.
        Parameters:
        queryString - MDX query text
        Returns:
        a Result object
      • runQuery

        public <T> T runQuery​(java.lang.String queryString,
                              Util.Functor1<T,​CellSet> f)
        Executes a query and processes the result using a callback.
        Parameters:
        queryString - MDX query text
      • toString

        public java.lang.String toString​(Result result)
        Converts a Result object to a string
        Returns:
        String version of mondrian Result object.
      • highCardToString

        public java.lang.String highCardToString​(Result result)
        Converts a Result object to a string printing to standard output directly, without buffering.
        Returns:
        null String since output is dump directly to stdout.
      • makeConnectString

        public void makeConnectString()
      • getConnection

        public Connection getConnection()
        Gets a connection to Mondrian.
        Returns:
        Mondrian Connection
      • getConnection

        public Connection getConnection​(boolean fresh)
        Gets a Mondrian connection, creating a new one if fresh is true.
        Returns:
        mondrian Connection.
      • getOlapConnection

        public OlapConnection getOlapConnection()
                                         throws java.sql.SQLException
        Gets an olap4j connection, creating a new one if fresh is true.
        Returns:
        mondrian Connection.
        Throws:
        java.sql.SQLException
      • getConnectString

        public java.lang.String getConnectString()
      • getConnectString

        public java.lang.String getConnectString​(boolean fresh)
      • debug

        protected void debug​(java.lang.String msg)
      • getConnectStringProperty

        protected static java.lang.String getConnectStringProperty()
      • getJdbcURLProperty

        protected static java.lang.String getJdbcURLProperty()
      • getJdbcUserProperty

        protected static java.lang.String getJdbcUserProperty()
      • getJdbcPasswordProperty

        protected static java.lang.String getJdbcPasswordProperty()
      • getCatalogURLProperty

        protected static java.lang.String getCatalogURLProperty()
      • getJdbcDriversProperty

        protected static java.lang.String getJdbcDriversProperty()
      • commandLoop

        protected void commandLoop​(boolean interactive)
                            throws java.io.IOException
        Throws:
        java.io.IOException
      • commandLoop

        protected void commandLoop​(java.io.File file)
                            throws java.io.IOException
        Throws:
        java.io.IOException
      • commandLoop

        protected void commandLoop​(java.lang.String mdxCmd,
                                   boolean interactive)
                            throws java.io.IOException
        Throws:
        java.io.IOException
      • commandLoop

        protected void commandLoop​(java.io.Reader in,
                                   boolean interactive)
        The Command Loop where lines are read from the InputStream and interpreted. If interactive then prompts are printed.
        Parameters:
        in - Input reader (preferably buffered)
        interactive - Whether the session is interactive
      • printResults

        protected void printResults​(java.lang.String resultString)
      • printQueryTime

        protected void printQueryTime()
      • readLine

        protected static java.lang.String readLine​(java.io.Reader reader,
                                                   boolean inMdxCmd)
                                            throws java.io.IOException
        Gather up a line ending in '\n' or EOF. Returns null if at EOF. Strip out comments. If a comment character appears within a string then its not a comment. Strings are defined with "\"" or "'" characters. Also, a string can span more than one line (a nice little complication). So, if we read a string, then we consume the whole string as part of the "line" returned, including EOL characters. If an escape character is seen '\\', then it and the next character is added to the line regardless of what the next character is.
        Throws:
        java.io.IOException
      • getLine

        protected static int getLine​(java.io.Reader reader,
                                     java.lang.StringBuilder line)
                              throws java.io.IOException
        Read the next line of input. Return the terminating character, -1 for end of file, or \n or \r. Add \n and \r to the end of the buffer to be included in strings and comment blocks.
        Throws:
        java.io.IOException
      • readString

        protected static int readString​(java.io.Reader reader,
                                        java.lang.StringBuilder line,
                                        int offset,
                                        java.lang.StringBuilder buf,
                                        int i)
                                 throws java.io.IOException
        Start of a string, read all of it even if it spans more than one line adding each line's to the buffer.
        Throws:
        java.io.IOException
      • readBlock

        protected static int readBlock​(java.io.Reader reader,
                                       java.lang.StringBuilder line,
                                       int offset,
                                       java.lang.String startDelim,
                                       java.lang.String endDelim,
                                       boolean allowEscape,
                                       boolean addToBuf,
                                       java.lang.StringBuilder buf,
                                       int i)
                                throws java.io.IOException
        Start of a delimted block, read all of it even if it spans more than one line adding each line's to the buffer. A delimited block is a delimited comment (/\* ... *\/), or a string.
        Throws:
        java.io.IOException
      • processSoapXmla

        protected void processSoapXmla​(java.io.File file,
                                       int validateXmlaResponse)
                                throws java.lang.Exception
        This is called to process a file containing XMLA as the contents of SOAP xml.
        Throws:
        java.lang.Exception
      • processXmla

        protected void processXmla​(java.io.File file,
                                   int validateXmlaResponce)
                            throws java.lang.Exception
        This is called to process a file containing XMLA xml.
        Throws:
        java.lang.Exception
      • executeHelp

        protected static java.lang.String executeHelp​(java.lang.String mdxCmd)
      • appendIndent

        protected static void appendIndent​(java.lang.StringBuilder buf,
                                           int i)
      • appendSet

        protected static void appendSet​(java.lang.StringBuilder buf)
      • executeSet

        protected java.lang.String executeSet​(java.lang.String mdxCmd)
      • appendLog

        protected static void appendLog​(java.lang.StringBuilder buf)
      • executeLog

        protected java.lang.String executeLog​(java.lang.String mdxCmd)
      • appendFile

        protected static void appendFile​(java.lang.StringBuilder buf)
      • executeFile

        protected java.lang.String executeFile​(java.lang.String mdxCmd)
      • appendList

        protected static void appendList​(java.lang.StringBuilder buf)
      • executeList

        protected java.lang.String executeList​(java.lang.String mdxCmd)
      • appendFunc

        protected static void appendFunc​(java.lang.StringBuilder buf)
      • executeFunc

        protected java.lang.String executeFunc​(java.lang.String mdxCmd)
      • appendParam

        protected static void appendParam​(java.lang.StringBuilder buf)
      • executeParam

        protected java.lang.String executeParam​(java.lang.String mdxCmd)
      • appendCube

        protected static void appendCube​(java.lang.StringBuilder buf)
      • executeCube

        protected java.lang.String executeCube​(java.lang.String mdxCmd)
      • appendError

        protected static void appendError​(java.lang.StringBuilder buf)
      • executeError

        protected java.lang.String executeError​(java.lang.String mdxCmd)
      • appendEcho

        protected static void appendEcho​(java.lang.StringBuilder buf)
      • executeEcho

        protected java.lang.String executeEcho​(java.lang.String mdxCmd)
      • appendExpr

        protected static void appendExpr​(java.lang.StringBuilder buf)
      • executeExpr

        protected java.lang.String executeExpr​(java.lang.String mdxCmd)
      • appendExit

        protected static void appendExit​(java.lang.StringBuilder buf)
      • reExecuteMdxCmd

        protected java.lang.String reExecuteMdxCmd()
      • executeMdxCmd

        protected java.lang.String executeMdxCmd​(java.lang.String mdxCmd)
      • loadPropertiesFromFile

        protected static void loadPropertiesFromFile​(java.lang.String propFile)
                                              throws java.io.IOException
        Throws:
        java.io.IOException
      • usage

        protected static void usage​(java.lang.String msg,
                                    java.io.PrintStream out)
        Prints a usage message.
        Parameters:
        msg - Prefix to the message
        out - Output stream
      • main

        public static void main​(java.lang.String[] args)
                         throws java.lang.Exception
        Throws:
        java.lang.Exception