|
From: Jason J. <jrj...@us...> - 2010-03-02 21:50:17
|
Update of /cvsroot/autopatch/autopatch/migrate/dotnet/AutopatchNet/src/com/tacitknowledge/util/migration/ado/loader In directory sfp-cvsdas-1.v30.ch3.sourceforge.com:/tmp/cvs-serv7743/migrate/dotnet/AutopatchNet/src/com/tacitknowledge/util/migration/ado/loader Modified Files: DelimitedFileLoader.cs FileLoadingUtility.cs Log Message: Implemented delimited file loading Index: DelimitedFileLoader.cs =================================================================== RCS file: /cvsroot/autopatch/autopatch/migrate/dotnet/AutopatchNet/src/com/tacitknowledge/util/migration/ado/loader/DelimitedFileLoader.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** DelimitedFileLoader.cs 20 Mar 2007 19:38:28 -0000 1.1 --- DelimitedFileLoader.cs 2 Mar 2010 21:49:37 -0000 1.2 *************** *** 24,28 **** /// <summary> Loads files assumed to be in a delimited format and representing a /// table in the database. The file name should begin with the prefix: ! /// "<tablename>_tb". The file's first row should represent the name of /// each column in the table that the underlying data elements (rows 2 /// through n) will be mapped to. --- 24,28 ---- /// <summary> Loads files assumed to be in a delimited format and representing a /// table in the database. The file name should begin with the prefix: ! /// "<tablename>_db". The file's first row should represent the name of /// each column in the table that the underlying data elements (rows 2 /// through n) will be mapped to. *************** *** 35,45 **** public abstract class DelimitedFileLoader:SqlLoadMigrationTask { #region Member Variable /// <summary> The path separator</summary> - //UPGRADE_NOTE: Final was removed from the declaration of 'PATH_SEPARATOR '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'" public static readonly System.String PATH_SEPARATOR = System.IO.Path.DirectorySeparatorChar.ToString(); /// <summary> Class logger</summary> - //UPGRADE_NOTE: The initialization of 'log' was moved to static method 'com.tacitknowledge.util.migration.ado.loader.DelimitedFileLoader'. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1005'" private static ILog log; --- 35,44 ---- public abstract class DelimitedFileLoader:SqlLoadMigrationTask { + private const string PARAMETER_NAME_PREFIX = "@P"; #region Member Variable /// <summary> The path separator</summary> public static readonly System.String PATH_SEPARATOR = System.IO.Path.DirectorySeparatorChar.ToString(); /// <summary> Class logger</summary> private static ILog log; *************** *** 55,59 **** /// <returns> the delimiter string used to separate columns /// </returns> ! public abstract System.String Delimiter{get;} /// <summary> Returns the table name from the full path name /// by parsing it out of a file in the format --- 54,59 ---- /// <returns> the delimiter string used to separate columns /// </returns> ! public abstract System.Char Delimiter{get;} ! /// <summary> Returns the table name from the full path name /// by parsing it out of a file in the format *************** *** 69,73 **** System.String name = Name; int startTable = name.LastIndexOf(PATH_SEPARATOR); - //UPGRADE_WARNING: Method 'java.lang.String.indexOf' was converted to 'System.String.IndexOf' which may throw an exception. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1101'" int endTable = name.IndexOf("_db", startTable); return name.Substring((startTable + 1), (endTable) - ((startTable + 1))); --- 69,72 ---- *************** *** 89,105 **** { System.String columnHeader = getHeader(ResourceAsStream); ! System.String delimiter = Delimiter; ! //SupportClass.Tokenizer st = new SupportClass.Tokenizer(columnHeader, delimiter); ! System.Collections.ArrayList columnNames = new System.Collections.ArrayList(); ! //while (st.HasMoreTokens()) ! //{ ! // columnNames.Add((st.NextToken().Trim())); ! //} ! System.Text.StringBuilder query = new System.Text.StringBuilder("INSERT INTO "); ! query.Append(TableFromName); query.Append(" ("); System.Collections.IEnumerator it = columnNames.GetEnumerator(); bool firstTime = true; - //UPGRADE_TODO: Method 'java.util.Iterator.hasNext' was converted to 'System.Collections.IEnumerator.MoveNext' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilIteratorhasNext'" while (it.MoveNext()) { --- 88,99 ---- { System.String columnHeader = getHeader(ResourceAsStream); ! System.Char delimiter = Delimiter; ! string[] columnNames = columnHeader.Split(delimiter); ! ! System.Text.StringBuilder query = new System.Text.StringBuilder("INSERT INTO "); ! query.Append(TableFromName); query.Append(" ("); System.Collections.IEnumerator it = columnNames.GetEnumerator(); bool firstTime = true; while (it.MoveNext()) { *************** *** 112,131 **** firstTime = false; } ! //UPGRADE_TODO: Method 'java.util.Iterator.next' was converted to 'System.Collections.IEnumerator.Current' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilIteratornext'" ! query.Append((System.String) it.Current); } query.Append(") VALUES ("); ! for (int i = 0; i < columnNames.Count; i++) { ! if (i > 0) ! { ! query.Append(", "); ! } ! query.Append("?"); ! } ! query.Append(")"); return query.ToString(); } ! catch (System.IO.IOException e) { log.Error("No header was found for file: " + Name, e); --- 106,124 ---- firstTime = false; } ! query.Append((string) it.Current); } query.Append(") VALUES ("); ! for (int i = 1; i <= columnNames.Length; i++) { ! if (i > 1) ! { ! query.Append(", "); ! } ! query.Append(PARAMETER_NAME_PREFIX + i.ToString()); ! } ! query.Append(")"); return query.ToString(); } ! catch (System.ArgumentException e) { log.Error("No header was found for file: " + Name, e); *************** *** 133,139 **** return null; } ! ! } ! /// <summary> Gets an input stream by first checking the current classloader, /// then trying to use the system classloader, and finally, trying /// to access the file on the file system. If the file is not found, --- 126,132 ---- return null; } ! } ! ! /// <summary> Gets an input stream by first checking the current classloader, /// then trying to use the system classloader, and finally, trying /// to access the file on the file system. If the file is not found, *************** *** 178,182 **** /// </returns> /// <throws> SQLException if an error occurs while inserting data into the database </throws> ! protected internal bool insert(System.String data, System.Data.OleDb.OleDbCommand stmt) { if (!parsedHeader) --- 171,175 ---- /// </returns> /// <throws> SQLException if an error occurs while inserting data into the database </throws> ! override protected internal bool insert(System.String data, System.Data.Common.DbCommand stmt) { if (!parsedHeader) *************** *** 186,206 **** return false; } ! //SupportClass.Tokenizer st = new SupportClass.Tokenizer(data, Delimiter); ! //int counter = 1; log.Info("Row being parsed: " + data); ! //while (st.HasMoreTokens()) ! //{ ! // System.String colVal = st.NextToken(); ! // if (colVal.ToUpper().Equals("<null>".ToUpper())) ! // { ! // SupportClass.TransactionManager.manager.SetValue(stmt, counter, null); ! // } ! // else ! // { ! // SupportClass.TransactionManager.manager.SetValue(stmt, counter, colVal); ! // } ! // counter++; ! //} ! return true; } --- 179,204 ---- return false; } ! ! int counter = 1; log.Info("Row being parsed: " + data); ! stmt.Parameters.Clear(); ! foreach (string colVal in data.Split(Delimiter)) ! { ! System.Data.Common.DbParameter parameter = stmt.CreateParameter(); ! parameter.ParameterName = PARAMETER_NAME_PREFIX + counter.ToString(); ! ! if (colVal.ToLower().Equals("<null>")) ! { ! parameter.Value = DBNull.Value; ! } ! else ! { ! parameter.Value = colVal; ! } ! ! stmt.Parameters.Add(parameter); ! counter++; ! } ! return true; } *************** *** 208,221 **** /// /// </summary> ! /// <param name="is">the input stream containing the data to load /// </param> /// <returns> the first row /// </returns> /// <throws> IOException if the input stream could not be read </throws> ! protected internal virtual System.String getHeader(System.IO.Stream is_Renamed) { ! //UPGRADE_TODO: The differences in the expected value of parameters for constructor 'java.io.BufferedReader.BufferedReader' may cause compilation errors. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1092'" ! //UPGRADE_WARNING: At least one expression was used more than once in the target code. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1181'" ! System.IO.StreamReader reader = new System.IO.StreamReader(new System.IO.StreamReader(is_Renamed, System.Text.Encoding.Default).BaseStream, new System.IO.StreamReader(is_Renamed, System.Text.Encoding.Default).CurrentEncoding); return reader.ReadLine(); } --- 206,217 ---- /// /// </summary> ! /// <param name="inputStream">the input stream containing the data to load /// </param> /// <returns> the first row /// </returns> /// <throws> IOException if the input stream could not be read </throws> ! protected internal virtual System.String getHeader(System.IO.Stream inputStream) { ! System.IO.StreamReader reader = new System.IO.StreamReader(inputStream); return reader.ReadLine(); } Index: FileLoadingUtility.cs =================================================================== RCS file: /cvsroot/autopatch/autopatch/migrate/dotnet/AutopatchNet/src/com/tacitknowledge/util/migration/ado/loader/FileLoadingUtility.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** FileLoadingUtility.cs 20 Mar 2007 19:38:28 -0000 1.1 --- FileLoadingUtility.cs 2 Mar 2010 21:49:58 -0000 1.2 *************** *** 52,77 **** get { ! //UPGRADE_ISSUE: Method 'java.lang.Class.getResourceAsStream' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javalangClassgetResourceAsStream_javalangString'" ! System.IO.Stream stream = null;// GetType().getResourceAsStream(fileName); ! if (stream == null) ! { ! //UPGRADE_ISSUE: Method 'java.lang.ClassLoader.getSystemResourceAsStream' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javalangClassLoader'" ! stream = null;// ClassLoader.getSystemResourceAsStream(fileName); ! } ! if (stream == null) ! { ! System.IO.FileInfo f = new System.IO.FileInfo(fileName); ! try ! { ! //UPGRADE_TODO: Constructor 'java.io.FileInputStream.FileInputStream' was converted to 'System.IO.FileStream.FileStream' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaioFileInputStreamFileInputStream_javaioFile'" ! stream = new System.IO.FileStream(f.FullName, System.IO.FileMode.Open, System.IO.FileAccess.Read); ! } ! catch (System.IO.FileNotFoundException e) ! { ! log.Error("The file: " + fileName + " was not found.", e); ! throw new System.ArgumentException("Must have a valid file name."); ! } ! } ! return stream; } --- 52,68 ---- get { ! System.IO.Stream stream = null; ! ! System.IO.FileInfo f = new System.IO.FileInfo(fileName); ! try ! { ! stream = new System.IO.FileStream(f.FullName, System.IO.FileMode.Open, System.IO.FileAccess.Read); ! } ! catch (System.IO.FileNotFoundException e) ! { ! log.Error("The file: " + fileName + " was not found.", e); ! throw new System.ArgumentException("Must have a valid file name.", e); ! } ! return stream; } |