public static Boolean TestConnection(String driver, String connectionString, String username, String password, out String errormessage) { Boolean success = false; errormessage = null; try { IMojoHiveDriver hivedriver = CreateCustomDriver(driver); String queue = ""; // The queue is actually part of the connection string (url) so we pass a blank. int result = hivedriver.TestConnection(driver, connectionString, queue, username, password); if (result == 0) { success = true; } else { errormessage = hivedriver.GetLastExceptionMessage(); } } catch (System.Exception ex) { Debug.WriteLine("Error in TestConnection(): " + ex.Message); //throw ex; } return(success); }
public static int RunBigDataQueryJava(String dataPipePath, String connectionString, String sql) { int result = 0; _logger.LogMsg(Level.Debug, "Enter function RunBigDataQueryJava()."); try { // The queue name is not necessary as a separate parameter. it is part of the URL. // TO DO: change Java interface so we don't need to pass this parameter at all. String unused_queue_name = ""; // Create Java proxy IMojoHiveDriver driver = CreateCustomDriver(_driverName); if (!Properties.Settings.Default.SimulateQuery) { // Run the real query via Java / JDBC. _logger.LogMsg(Level.Debug, "Calling Java method QueryResultSetToPipe()."); result = driver.QueryResultSetToPipe(_driverName, _connectionString, unused_queue_name, _userName, _password, _sql, _dataPipePath); _logger.LogMsg(Level.Debug, "Return from Java method QueryResultSetToPipe(). Result = " + result.ToString()); // DEBUGGING: just write a fixed data file to the pipe instead of running an actual JDBC query. } else { // Load the data from a local data file instead. String data_file = ""; if (File.Exists(Properties.Settings.Default.TestDataFilename)) { data_file = Properties.Settings.Default.TestDataFilename; } else { String local_path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); data_file = Path.Combine(local_path, Properties.Settings.Default.TestDataFilename); } if (File.Exists(data_file)) { _logger.LogMsg(Level.Debug, String.Format("Calling Java method TestNamedPipeWrite() with input data file {0}.", data_file)); result = driver.TestNamedPipeWrite(dataPipePath, data_file); _logger.LogMsg(Level.Debug, "Return from Java method TestNamedPipeWrite(). Result = " + result.ToString()); } else { _logger.LogMsg(Level.Error, String.Format("Test data file not found: {0}", Properties.Settings.Default.TestDataFilename)); } // TO DO: If we can't run the test, do we still have to close the data pipe? } if (driver.GetLastErrorCode() != 0) { _logger.LogMsg(Level.Error, String.Format("Exception from MojoHiveDriver: {0}.", driver.GetLastExceptionMessage())); } } catch (Exception ex) { _logger.LogMsg(Level.Fatal, "Unexpected error in RunBigDataQueryJava(): " + ex.Message); } return(result); }
public static IMojoHiveDriver CreateCustomDriver(String drivername) { IMojoHiveDriver driver = null; try { String local_path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); _logger.LogMsg(log4net.Core.Level.Debug, "Connector program folder: " + local_path); _logger.LogMsg(log4net.Core.Level.Debug, "Creating .NET-Java bridge."); var bridgeSetup = new BridgeSetup(); // The local_path is the folder where the connector EXE itself is located. bridgeSetup.AddAllJarsClassPath(local_path); // Check to see if a specific folder has been configured as the location for the current driver. // If so, load all JARs in that folder. String driver_folder = ""; Boolean found_the_folder = false; try { if (Properties.Settings.Default.Drivers.Contains(drivername)) { int driver_index = Properties.Settings.Default.Drivers.IndexOf(drivername); if (Properties.Settings.Default.DriverLocations.Count > driver_index) { driver_folder = Properties.Settings.Default.DriverLocations[driver_index]; // First assume the folder is a full path, check if it exists. if (Directory.Exists(driver_folder)) { found_the_folder = true; } else { // Try to append to the driver folder to the current local EXE path as a sub-folder. driver_folder = Path.Combine(local_path, driver_folder); if (Directory.Exists(driver_folder)) { found_the_folder = true; } } // Always try to add the folder if it exists. if (found_the_folder) { bridgeSetup.AddAllJarsClassPath(driver_folder); } } } } catch (Exception ex) { _logger.LogMsg(Level.Warn, String.Format("Error adding custom driver folder [{0}] to Java CLASSPATH: {1}.", driver_folder, ex.Message)); } _logger.LogMsg(log4net.Core.Level.Debug, "Creating Java virtual machine (JVM)."); Bridge.CreateJVM(bridgeSetup); _logger.LogMsg(log4net.Core.Level.Debug, "Registering custom driver assembly with .NET-Java bridge."); Bridge.RegisterAssembly(typeof(MojoHiveDriver).Assembly); _logger.LogMsg(log4net.Core.Level.Debug, "Creating custom driver proxy for .NET."); driver = new MojoHiveDriver(); } catch (System.Exception ex) { _logger.LogMsg(log4net.Core.Level.Error, "Error creating MojoHiveDriver proxy: " + ex.Message); } return(driver); }