static void Main(string[] args)
        {
            try
            {

                String xml_results = "<Results><Row><billtocode>3DAKE</billtocode><billtodesc>l@K(&gt;ur(ZCxbt</billtodesc><billtoeffdt>2009-10-18 00:00:00</billtoeffdt><billtoexpdt>2011-07-04 00:00:00</billtoexpdt></Row><Row><billtocode>3DAKE</billtocode><billtodesc>l@K(&gt;ur(ZCxbt</billtodesc><billtoeffdt>2009-10-18 00:00:00</billtoeffdt><billtoexpdt>2011-07-04 00:00:00</billtoexpdt></Row></Results>";
                System.Xml.XmlDocument doc = new XmlDocument();
                doc.LoadXml(xml_results);
                XmlNode root = doc.FirstChild;
                if (root.HasChildNodes)
                {
                    // These are row nodes
                    //for (int i = 0; i < root.ChildNodes.Count; i++)
                    //{
                    //    Debug.WriteLine(root.ChildNodes[i].Name);
                    //    for (int ii = 0; ii < root.ChildNodes[i].ChildNodes.Count; ii++)
                    //    {
                    //        Debug.WriteLine(root.ChildNodes[i].ChildNodes[ii].Name);
                    //    }
                    //}

                    foreach (XmlNode row_node in root.ChildNodes)
                    {
                        Debug.WriteLine(row_node.Name);
                        foreach (XmlNode field_node in row_node.ChildNodes)
                        {
                            Debug.WriteLine(field_node.Name + " = " + field_node.InnerText);
                        }

                    }

                }

                String local_path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);

                var bridgeSetup = new BridgeSetup();
                bridgeSetup.AddAllJarsClassPath(".");
                bridgeSetup.AddAllJarsClassPath(local_path);
                Bridge.CreateJVM(bridgeSetup);
                Bridge.RegisterAssembly(typeof(MojoHiveDriver).Assembly);

                String drivername = "org.apache.hive.jdbc.HiveDriver";
                String url = "jdbc:hive2://54.218.97.70:21050/;auth=noSasl";
                String username = "";
                String password = "";
                String queuename = "";

                IMojoHiveDriver driver = new MojoHiveDriver();

                int result = driver.TestConnection(drivername, url, queuename, username, password);

                Console.WriteLine("Connection successful.");

                String sql = "SELECT * FROM billtocodes WHERE billtocode LIKE '3D%'";

                String xml = driver.QueryResultSetAsXML(drivername, url, queuename, username, password, sql);

                Console.WriteLine("Results\r\n" + xml);

            }
            catch (System.Exception ex)
            {
                Console.WriteLine("***Error in Main(): " + ex.Message);
            }
        }
        private IEnumerable <QvxDataRow> GetBillToCodes()
        {
            String tableName   = "BillToCodes";
            String xml_results = "";

            try
            {
                //QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Notice, "GetBillToCodes()");
                _logger.LogMsg(log4net.Core.Level.Info, "Enter callback function GetBillToCodes()");

                // DEBUGGING: try to connect to named pipe from here.
                //Program.RunNamedPipeHandler(Program._parentWindowHandle, Program._commandQueue, _logger);


                //QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Notice, String.Format("GetEvents(log: {0}, tableName: {1})", log, tableName));

                // TO DO: put this back in?
                //VerifyCredentials();

                // TO DO: put in basic validation of query ?
                //if (!EventLog.Exists(log))
                //{
                //    throw new QvxPleaseSendReplyException(QvxResult.QVX_TABLE_NOT_FOUND,
                //        String.Format("There is no EventLog with name: {0}", tableName));
                //}

                // Run the query, get a dataset in XML ?

                // Get the path to the executing program so we can add it to the Java CLASSPATH.
                String local_path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
                _logger.LogMsg(log4net.Core.Level.Info, "Working folder: " + local_path);


                //QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Notice, "Opening DotNet-Java bridge.");
                _logger.LogMsg(log4net.Core.Level.Info, "Opening DotNet-Java bridge.");

                var bridgeSetup = new BridgeSetup();
                bridgeSetup.AddAllJarsClassPath(".");
                bridgeSetup.AddAllJarsClassPath(local_path);

                Bridge.CreateJVM(bridgeSetup);
                Bridge.RegisterAssembly(typeof(MojoHiveDriver).Assembly);

                String drivername = "org.apache.hive.jdbc.HiveDriver";
                String url        = "jdbc:hive2://54.218.97.70:21050/;auth=noSasl";
                String username   = "";
                String password   = "";
                String queuename  = "";

                // *** Create the Java proxy class
                //QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Notice, "Creating MojoHiveDriver proxy.");
                _logger.LogMsg(log4net.Core.Level.Info, "Creating MojoHiveDriver proxy.");
                IMojoHiveDriver driver = new MojoHiveDriver();

                // *** Test Cloudera connection
                //QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Notice, String.Format("Testing connection: driver={0} | url={1} | queuename={2} | username={3} | password={4}.", drivername, url, queuename, username, password));
                _logger.LogMsg(log4net.Core.Level.Info, String.Format("Testing connection: driver={0} | url={1} | queuename={2} | username={3} | password={4}.", drivername, url, queuename, username, password));
                int result = driver.TestConnection(drivername, url, queuename, username, password);
                if (result == 0)
                {
                    //QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Notice, "Connection successful.");
                    _logger.LogMsg(log4net.Core.Level.Info, "Connection successful.");
                }
                else
                {
                    //QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Notice, "Connection failed: " + driver.GetLastExceptionMessage());
                    _logger.LogMsg(log4net.Core.Level.Info, "Connection failed: " + driver.GetLastExceptionMessage());
                }

                // *** Run an actual query
                //TO DO: get this from QlikView ? Must use named pipes?
                //String sql = "SELECT * FROM billtocodes WHERE billtocode='3DAKE'";
                //String sql = "SELECT * FROM billtocodes WHERE billtocode LIKE '4P%'";
                String sql = "SELECT * FROM billtocodes WHERE billtoeffdt > '2008-02-01 00:00:00' AND billtoeffdt < '2008-02-28 00:00:00'";

                _logger.LogMsg(log4net.Core.Level.Info, "Running query: " + sql);
                xml_results = driver.QueryResultSetAsXML(drivername, url, queuename, username, password, sql);
                //_logger.LogMsg(log4net.Core.Level.Info, "XML results:\r\n" + xml_results);
            }
            catch (System.Exception ex)
            {
                _logger.LogMsg(log4net.Core.Level.Error, "Fatal exception: " + ex.Message);
            }

            _logger.LogMsg(log4net.Core.Level.Info, "Loading XML into parser." + xml_results);
            System.Xml.XmlDocument doc = new XmlDocument();
            doc.LoadXml(xml_results);
            XmlNode root = doc.FirstChild;

            if (root.HasChildNodes)
            {
                _logger.LogMsg(log4net.Core.Level.Info, String.Format("Query returned {0} rows.", root.ChildNodes.Count.ToString()));

                _logger.LogMsg(log4net.Core.Level.Info, "Moving data from XML to QlikView objects." + xml_results);
                foreach (XmlNode row_node in root.ChildNodes)
                {
                    //Debug.WriteLine(row_node.Name);
                    yield return(MakeEntry(row_node, FindTable(tableName, MTables)));

                    //foreach (XmlNode field_node in row_node.ChildNodes)
                    //{
                    //    Debug.WriteLine(field_node.Name + " = " + field_node.InnerText);
                    //}
                }
            }
            else
            {
                _logger.LogMsg(log4net.Core.Level.Warn, "No rows returned!" + xml_results);
            }
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            try
            {
                String xml_results         = "<Results><Row><billtocode>3DAKE</billtocode><billtodesc>l@K(&gt;ur(ZCxbt</billtodesc><billtoeffdt>2009-10-18 00:00:00</billtoeffdt><billtoexpdt>2011-07-04 00:00:00</billtoexpdt></Row><Row><billtocode>3DAKE</billtocode><billtodesc>l@K(&gt;ur(ZCxbt</billtodesc><billtoeffdt>2009-10-18 00:00:00</billtoeffdt><billtoexpdt>2011-07-04 00:00:00</billtoexpdt></Row></Results>";
                System.Xml.XmlDocument doc = new XmlDocument();
                doc.LoadXml(xml_results);
                XmlNode root = doc.FirstChild;
                if (root.HasChildNodes)
                {
                    // These are row nodes
                    //for (int i = 0; i < root.ChildNodes.Count; i++)
                    //{
                    //    Debug.WriteLine(root.ChildNodes[i].Name);
                    //    for (int ii = 0; ii < root.ChildNodes[i].ChildNodes.Count; ii++)
                    //    {
                    //        Debug.WriteLine(root.ChildNodes[i].ChildNodes[ii].Name);
                    //    }
                    //}

                    foreach (XmlNode row_node in root.ChildNodes)
                    {
                        Debug.WriteLine(row_node.Name);
                        foreach (XmlNode field_node in row_node.ChildNodes)
                        {
                            Debug.WriteLine(field_node.Name + " = " + field_node.InnerText);
                        }
                    }
                }



                String local_path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);


                var bridgeSetup = new BridgeSetup();
                bridgeSetup.AddAllJarsClassPath(".");
                bridgeSetup.AddAllJarsClassPath(local_path);
                Bridge.CreateJVM(bridgeSetup);
                Bridge.RegisterAssembly(typeof(MojoHiveDriver).Assembly);



                String drivername = "org.apache.hive.jdbc.HiveDriver";
                String url        = "jdbc:hive2://54.218.97.70:21050/;auth=noSasl";
                String username   = "";
                String password   = "";
                String queuename  = "";

                IMojoHiveDriver driver = new MojoHiveDriver();

                int result = driver.TestConnection(drivername, url, queuename, username, password);

                Console.WriteLine("Connection successful.");

                String sql = "SELECT * FROM billtocodes WHERE billtocode LIKE '3D%'";

                String xml = driver.QueryResultSetAsXML(drivername, url, queuename, username, password, sql);

                Console.WriteLine("Results\r\n" + xml);
            }
            catch (System.Exception ex)
            {
                Console.WriteLine("***Error in Main(): " + ex.Message);
            }
        }
        private IEnumerable<QvxDataRow> GetBillToCodes()
        {
            String tableName = "BillToCodes";
            String xml_results = "";

            try
            {

                //QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Notice, "GetBillToCodes()");
                _logger.LogMsg(log4net.Core.Level.Info, "Enter callback function GetBillToCodes()");

                // DEBUGGING: try to connect to named pipe from here.
                //Program.RunNamedPipeHandler(Program._parentWindowHandle, Program._commandQueue, _logger);

                //QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Notice, String.Format("GetEvents(log: {0}, tableName: {1})", log, tableName));

                // TO DO: put this back in?
                //VerifyCredentials();

                // TO DO: put in basic validation of query ?
                //if (!EventLog.Exists(log))
                //{
                //    throw new QvxPleaseSendReplyException(QvxResult.QVX_TABLE_NOT_FOUND,
                //        String.Format("There is no EventLog with name: {0}", tableName));
                //}

                // Run the query, get a dataset in XML ?

                // Get the path to the executing program so we can add it to the Java CLASSPATH.
                String local_path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location );
                _logger.LogMsg(log4net.Core.Level.Info, "Working folder: " + local_path);

                //QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Notice, "Opening DotNet-Java bridge.");
                _logger.LogMsg(log4net.Core.Level.Info, "Opening DotNet-Java bridge.");

                var bridgeSetup = new BridgeSetup();
                bridgeSetup.AddAllJarsClassPath(".");
                bridgeSetup.AddAllJarsClassPath(local_path);

                Bridge.CreateJVM(bridgeSetup);
                Bridge.RegisterAssembly(typeof(MojoHiveDriver).Assembly);

                String drivername = "org.apache.hive.jdbc.HiveDriver";
                String url = "jdbc:hive2://54.218.97.70:21050/;auth=noSasl";
                String username = "";
                String password = "";
                String queuename = "";

                // *** Create the Java proxy class
                //QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Notice, "Creating MojoHiveDriver proxy.");
                _logger.LogMsg(log4net.Core.Level.Info, "Creating MojoHiveDriver proxy.");
                IMojoHiveDriver driver = new MojoHiveDriver();

                // *** Test Cloudera connection
                //QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Notice, String.Format("Testing connection: driver={0} | url={1} | queuename={2} | username={3} | password={4}.", drivername, url, queuename, username, password));
                _logger.LogMsg(log4net.Core.Level.Info, String.Format("Testing connection: driver={0} | url={1} | queuename={2} | username={3} | password={4}.", drivername, url, queuename, username, password));
                int result = driver.TestConnection(drivername, url, queuename, username, password);
                if (result == 0)
                {
                    //QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Notice, "Connection successful.");
                    _logger.LogMsg(log4net.Core.Level.Info, "Connection successful.");
                }
                else
                {
                    //QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Notice, "Connection failed: " + driver.GetLastExceptionMessage());
                    _logger.LogMsg(log4net.Core.Level.Info, "Connection failed: " + driver.GetLastExceptionMessage());
                }

                // *** Run an actual query
                //TO DO: get this from QlikView ? Must use named pipes?
                //String sql = "SELECT * FROM billtocodes WHERE billtocode='3DAKE'";
                //String sql = "SELECT * FROM billtocodes WHERE billtocode LIKE '4P%'";
                String sql = "SELECT * FROM billtocodes WHERE billtoeffdt > '2008-02-01 00:00:00' AND billtoeffdt < '2008-02-28 00:00:00'";

                _logger.LogMsg(log4net.Core.Level.Info, "Running query: " + sql);
                xml_results = driver.QueryResultSetAsXML(drivername, url, queuename, username, password, sql);
                //_logger.LogMsg(log4net.Core.Level.Info, "XML results:\r\n" + xml_results);

            }
            catch (System.Exception ex)
            {
                _logger.LogMsg(log4net.Core.Level.Error, "Fatal exception: " + ex.Message);
            }

            _logger.LogMsg(log4net.Core.Level.Info, "Loading XML into parser." + xml_results);
            System.Xml.XmlDocument doc = new XmlDocument();
            doc.LoadXml(xml_results);
            XmlNode root = doc.FirstChild;
            if (root.HasChildNodes)
            {
                _logger.LogMsg(log4net.Core.Level.Info, String.Format("Query returned {0} rows.", root.ChildNodes.Count.ToString()));

                _logger.LogMsg(log4net.Core.Level.Info, "Moving data from XML to QlikView objects." + xml_results);
                foreach (XmlNode row_node in root.ChildNodes)
                {
                    //Debug.WriteLine(row_node.Name);
                    yield return MakeEntry(row_node, FindTable(tableName, MTables));

                    //foreach (XmlNode field_node in row_node.ChildNodes)
                    //{
                    //    Debug.WriteLine(field_node.Name + " = " + field_node.InnerText);
                    //}

                }
            }
            else
            {
                _logger.LogMsg(log4net.Core.Level.Warn, "No rows returned!" + xml_results);
            }
        }