Package mondrian.tui

Class CmdRunner


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

    TODO: describe how to use this class.

    Author:
    Richard Emberson
    • Constructor Detail

      • CmdRunner

        public CmdRunner​(CmdRunner.Options options,
                         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()
      • listPropertyNames

        public static void listPropertyNames​(StringBuilder buf)
      • listPropertiesAll

        public static void listPropertiesAll​(StringBuilder buf)
      • isProperty

        public static boolean isProperty​(String propertyName)
      • setProperty

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

        public void loadParameters​(Query query)
      • loadParameter

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

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

        public static void listParameterNameValues​(StringBuilder buf)
      • isParam

        public static boolean isParam​(String name)
      • setParameter

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

        public Cube[] getCubes()
      • execute

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

        public Result runQuery​(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​(String queryString,
                              Util.Functor1<T,​org.olap4j.CellSet> f)
        Executes a query and processes the result using a callback.
        Parameters:
        queryString - MDX query text
      • toString

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

        public 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 org.olap4j.OlapConnection getOlapConnection()
                                                    throws SQLException
        Gets an olap4j connection, creating a new one if fresh is true.
        Returns:
        mondrian Connection.
        Throws:
        SQLException
      • getConnectString

        public String getConnectString()
      • getConnectString

        public String getConnectString​(boolean fresh)
      • debug

        protected void debug​(String msg)
      • getConnectStringProperty

        protected static String getConnectStringProperty()
      • getJdbcURLProperty

        protected static String getJdbcURLProperty()
      • getJdbcUserProperty

        protected static String getJdbcUserProperty()
      • getJdbcPasswordProperty

        protected static String getJdbcPasswordProperty()
      • getCatalogURLProperty

        protected static String getCatalogURLProperty()
      • getJdbcDriversProperty

        protected static String getJdbcDriversProperty()
      • commandLoop

        protected void commandLoop​(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​(String resultString)
      • printQueryTime

        protected void printQueryTime()
      • readLine

        protected static String readLine​(Reader reader,
                                         boolean inMdxCmd)
                                  throws 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:
        IOException
      • getLine

        protected static int getLine​(Reader reader,
                                     StringBuilder line)
                              throws 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:
        IOException
      • readString

        protected static int readString​(Reader reader,
                                        StringBuilder line,
                                        int offset,
                                        StringBuilder buf,
                                        int i)
                                 throws 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:
        IOException
      • readBlock

        protected static int readBlock​(Reader reader,
                                       StringBuilder line,
                                       int offset,
                                       String startDelim,
                                       String endDelim,
                                       boolean allowEscape,
                                       boolean addToBuf,
                                       StringBuilder buf,
                                       int i)
                                throws 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:
        IOException
      • processSoapXmla

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

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

        protected static String executeHelp​(String mdxCmd)
      • appendIndent

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

        protected static void appendSet​(StringBuilder buf)
      • executeSet

        protected String executeSet​(String mdxCmd)
      • appendLog

        protected static void appendLog​(StringBuilder buf)
      • executeLog

        protected String executeLog​(String mdxCmd)
      • appendFile

        protected static void appendFile​(StringBuilder buf)
      • executeFile

        protected String executeFile​(String mdxCmd)
      • appendList

        protected static void appendList​(StringBuilder buf)
      • executeList

        protected String executeList​(String mdxCmd)
      • appendFunc

        protected static void appendFunc​(StringBuilder buf)
      • executeFunc

        protected String executeFunc​(String mdxCmd)
      • appendParam

        protected static void appendParam​(StringBuilder buf)
      • executeParam

        protected String executeParam​(String mdxCmd)
      • appendCube

        protected static void appendCube​(StringBuilder buf)
      • executeCube

        protected String executeCube​(String mdxCmd)
      • appendError

        protected static void appendError​(StringBuilder buf)
      • executeError

        protected String executeError​(String mdxCmd)
      • appendEcho

        protected static void appendEcho​(StringBuilder buf)
      • executeEcho

        protected String executeEcho​(String mdxCmd)
      • appendExpr

        protected static void appendExpr​(StringBuilder buf)
      • executeExpr

        protected String executeExpr​(String mdxCmd)
      • appendExit

        protected static void appendExit​(StringBuilder buf)
      • reExecuteMdxCmd

        protected String reExecuteMdxCmd()
      • executeMdxCmd

        protected String executeMdxCmd​(String mdxCmd)
      • usage

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