/// <summary> /// Run the provided query against the source database to get the data to be moved. /// </summary> /// <param name="server">ip or name of the source database</param> /// <param name="keyspace">name of the keyspace to use for the source query</param> /// <param name="query">query to get source data</param> /// <param name="gotSourceData">Data retrieved</param> /// <param name="sourceData">indicator of if an error was thrown</param> private static void GetSourceData(string server, string keyspace, string query, TransferResultsInfo info, out bool gotSourceData, out List<dynamic> sourceData) { sourceData = new List<dynamic>(); gotSourceData = true; try { CqlConnection srcConn = new CqlConnection("Contact Points=" + server, server); CqlCommand srcCmd = new CqlCommand(); srcConn.Open(); srcConn.ChangeDatabase(keyspace); srcCmd.Connection = srcConn; srcCmd.CommandType = CommandType.Text; srcCmd.CommandText = query; sourceData = srcCmd.ExecuteDynamics(); info.SourceCount = sourceData.Count; //cleanup srcCmd.Connection.Close(); srcCmd.Connection.Dispose(); srcCmd.Dispose(); } catch (Exception ex) { info.Message = "Error getting source data: \r\n" + ex.Message; gotSourceData = false; } }
private void StartBtn_Click(object sender, EventArgs e) { StartBtn.Enabled = false; if (!String.IsNullOrWhiteSpace(SourceSvr.Text) && !String.IsNullOrWhiteSpace(SourceKeySp.Text) && !String.IsNullOrWhiteSpace(SourceQry.Text) && !String.IsNullOrWhiteSpace(DestSvr.Text) && !String.IsNullOrWhiteSpace(DestClmFam.Text) && !String.IsNullOrWhiteSpace(DestKeySp.Text)) { ProgressBar.Visible = true; TransferResultsInfo res = Program.TransferData(SourceSvr.Text, SourceKeySp.Text, SourceQry.Text, DestSvr.Text, DestKeySp.Text, DestClmFam.Text); ProgressBar.Visible = false; MessageBox.Show(res.Message); } else { MessageBox.Show("All fields are required."); } StartBtn.Enabled = true; }
/// <summary> /// Move the data specified from the source query to the destination column family /// </summary> /// <param name="sourceSvr">ip or the host name of the source database</param> /// <param name="sourceKeySp">name of the keyspace to use for the source query</param> /// <param name="sourceQry">query to get source data</param> /// <param name="destSvr">ip or the host name of the destination database</param> /// <param name="destKeySp">name of the keyspace to use for the destination insert</param> /// <param name="destClmFam">name of the column family to insert the source data into</param> public static TransferResultsInfo TransferData(string sourceSvr, string sourceKeySp, string sourceQry, string destSvr, string destKeySp, string destClmFam) { TransferResultsInfo info = new TransferResultsInfo(); List<dynamic> sourceData; bool gotSourceData; GetSourceData(sourceSvr, sourceKeySp, sourceQry, info, out gotSourceData, out sourceData); if (gotSourceData) { InsertIntoDest(destSvr, destKeySp, destClmFam, sourceData, info); info.Message = string.Format("Sucess!\r\n\r\nSource Count: {0}\r\nOrigional Destination Count: {1}\r\nAfter Destination Count: {2}", info.SourceCount, info.OriginalDestCount, info.AfterDestCount); } return info; }
/// <summary> /// Move the data specified from the source query to the destination column family /// </summary> /// <param name="sourceSvr">ip or the host name of the source database</param> /// <param name="sourceKeySp">name of the keyspace to use for the source query</param> /// <param name="sourceQry">query to get source data</param> /// <param name="destSvr">ip or the host name of the destination database</param> /// <param name="destKeySp">name of the keyspace to use for the destination insert</param> /// <param name="destClmFam">name of the column family to insert the source data into</param> public static TransferResultsInfo TransferData(string sourceSvr, string sourceKeySp, string sourceQry, string destSvr, string destKeySp, string destClmFam) { TransferResultsInfo info = new TransferResultsInfo(); List <dynamic> sourceData; bool gotSourceData; GetSourceData(sourceSvr, sourceKeySp, sourceQry, info, out gotSourceData, out sourceData); if (gotSourceData) { InsertIntoDest(destSvr, destKeySp, destClmFam, sourceData, info); info.Message = string.Format("Sucess!\r\n\r\nSource Count: {0}\r\nOrigional Destination Count: {1}\r\nAfter Destination Count: {2}", info.SourceCount, info.OriginalDestCount, info.AfterDestCount); } return(info); }
/// <summary> /// Run the provided query against the source database to get the data to be moved. /// </summary> /// <param name="server">ip or name of the source database</param> /// <param name="keyspace">name of the keyspace to use for the source query</param> /// <param name="query">query to get source data</param> /// <param name="gotSourceData">Data retrieved</param> /// <param name="sourceData">indicator of if an error was thrown</param> private static void GetSourceData(string server, string keyspace, string query, TransferResultsInfo info, out bool gotSourceData, out List <dynamic> sourceData) { sourceData = new List <dynamic>(); gotSourceData = true; try { CqlConnection srcConn = new CqlConnection("Contact Points=" + server, server); CqlCommand srcCmd = new CqlCommand(); srcConn.Open(); srcConn.ChangeDatabase(keyspace); srcCmd.Connection = srcConn; srcCmd.CommandType = CommandType.Text; srcCmd.CommandText = query; sourceData = srcCmd.ExecuteDynamics(); info.SourceCount = sourceData.Count; //cleanup srcCmd.Connection.Close(); srcCmd.Connection.Dispose(); srcCmd.Dispose(); } catch (Exception ex) { info.Message = "Error getting source data: \r\n" + ex.Message; gotSourceData = false; } }
/// <summary> /// Insert retrived data into destination table /// </summary> /// <param name="server">ip or name of the destination database</param> /// <param name="keyspace">name of the keyspace to use for the insert</param> /// <param name="columnFamily">name of the column family for the insert</param> /// <param name="sourceData">data retrieved from the source</param> private static void InsertIntoDest(string server, string keyspace, string columnFamily, List <dynamic> sourceData, TransferResultsInfo info) { try { CqlConnection destConn = new CqlConnection("Contact Points=" + server, server); CqlCommand destCmd = new CqlCommand(); destConn.Open(); destConn.ChangeDatabase(keyspace); destCmd.Connection = destConn; destCmd.CommandText = "SELECT COUNT(*) FROM " + columnFamily; info.OriginalDestCount = Convert.ToInt32(destCmd.ExecuteScalar()); destCmd.InsertDynamicList(sourceData, columnFamily); destCmd.CommandText = "SELECT COUNT(*) FROM " + columnFamily; info.AfterDestCount = Convert.ToInt32(destCmd.ExecuteScalar()); //cleanup destCmd.Connection.Close(); destCmd.Connection.Dispose(); destCmd.Dispose(); } catch (Exception ex) { info.Message = "Error writting to destination: \r\n" + ex.Message; } }
/// <summary> /// Insert retrived data into destination table /// </summary> /// <param name="server">ip or name of the destination database</param> /// <param name="keyspace">name of the keyspace to use for the insert</param> /// <param name="columnFamily">name of the column family for the insert</param> /// <param name="sourceData">data retrieved from the source</param> private static void InsertIntoDest(string server, string keyspace, string columnFamily, List<dynamic> sourceData, TransferResultsInfo info) { try { CqlConnection destConn = new CqlConnection("Contact Points=" + server, server); CqlCommand destCmd = new CqlCommand(); destConn.Open(); destConn.ChangeDatabase(keyspace); destCmd.Connection = destConn; destCmd.CommandText = "SELECT COUNT(*) FROM " + columnFamily; info.OriginalDestCount = Convert.ToInt32(destCmd.ExecuteScalar()); destCmd.InsertDynamicList(sourceData, columnFamily); destCmd.CommandText = "SELECT COUNT(*) FROM " + columnFamily; info.AfterDestCount = Convert.ToInt32(destCmd.ExecuteScalar()); //cleanup destCmd.Connection.Close(); destCmd.Connection.Dispose(); destCmd.Dispose(); } catch (Exception ex) { info.Message = "Error writting to destination: \r\n" + ex.Message; } }