[Quantproject-developers] QuantDownloader/Downloader/OpenTickDownloader/DatabaseManagement DataBas
Brought to you by:
glauco_1
|
From: Glauco S. <gla...@us...> - 2009-01-14 23:32:50
|
Update of /cvsroot/quantproject/QuantDownloader/Downloader/OpenTickDownloader/DatabaseManagement In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv2030/Downloader/OpenTickDownloader/DatabaseManagement Modified Files: DataBaseWriter.cs Log Message: Bars with a duplicate key are skipped now Index: DataBaseWriter.cs =================================================================== RCS file: /cvsroot/quantproject/QuantDownloader/Downloader/OpenTickDownloader/DatabaseManagement/DataBaseWriter.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** DataBaseWriter.cs 11 Jan 2009 20:38:14 -0000 1.4 --- DataBaseWriter.cs 14 Jan 2009 23:32:39 -0000 1.5 *************** *** 3,7 **** DataBaseWriter.cs ! Copyright (C) 2008 Glauco Siliprandi --- 3,7 ---- DataBaseWriter.cs ! Copyright (C) 2008 Glauco Siliprandi *************** *** 19,23 **** along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ! */ using System; --- 19,23 ---- along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ! */ using System; *************** *** 82,93 **** } private void writeToDataBaseActually( Bar bar ) { DateTime dateTimeForOpenInESTTime = TimeZoneManager.ConvertToEST( bar.DateTimeForOpenInUTCTime ); ! Bars.AddBar( ! bar.Ticker , bar.Exchange , dateTimeForOpenInESTTime , bar.Interval , ! bar.Open , bar.High , bar.Low , bar.Close , bar.Volume ); } private void riseDatabaseUpdatedEvent( Bar bar ) { --- 82,114 ---- } + #region writeToDataBaseActually + private void throwExceptionIfOtherThanBarAlreadyInTheDatabase( + string ticker , string exchange , DateTime dateTimeForOpenInESTTime , long interval , + Exception exception ) + { + if ( !Bars.ContainsBar( + ticker , exchange , dateTimeForOpenInESTTime , interval ) ) + // exception was not due to a duplicate key + throw exception; + } private void writeToDataBaseActually( Bar bar ) { DateTime dateTimeForOpenInESTTime = TimeZoneManager.ConvertToEST( bar.DateTimeForOpenInUTCTime ); ! try ! { ! Bars.AddBar( ! bar.Ticker , bar.Exchange , dateTimeForOpenInESTTime , bar.Interval , ! bar.Open , bar.High , bar.Low , bar.Close , bar.Volume ); ! } ! catch ( Exception exception ) ! { ! this.throwExceptionIfOtherThanBarAlreadyInTheDatabase( ! bar.Ticker , bar.Exchange , dateTimeForOpenInESTTime , bar.Interval , ! exception ); ! } } + #endregion writeToDataBaseActually + private void riseDatabaseUpdatedEvent( Bar bar ) { *************** *** 114,119 **** this.writeToDataBaseActually(); } ! #endregion writeToDataBaseIfEnoughBars ! private void writeToDataBase() { --- 135,140 ---- this.writeToDataBaseActually(); } ! #endregion writeToDataBaseIfEnoughBars ! private void writeToDataBase() { *************** *** 122,126 **** this.writeToDataBaseIfEnoughBars(); Thread.Sleep( 50 ); ! } } #endregion writeToDataBase --- 143,147 ---- this.writeToDataBaseIfEnoughBars(); Thread.Sleep( 50 ); ! } } #endregion writeToDataBase *************** *** 132,135 **** --- 153,180 ---- this.writeToDataBaseThread.Start(); } + + // uncomment the two following methods to test if writeToDataBaseActually + // properly handles duplicate keys attempt + // public static void TestAddBar() + // { + // DataBaseWriter dataBaseWriter = new DataBaseWriter( + // new BarQueue( 1 ) , 1 ); + // dataBaseWriter.TestAddBarForInstance(); + // } + // public void TestAddBarForInstance() + // { + // Bar bar = new Bar( + // "AAPL" , "Q" , new DateTime( 2009 , 1 , 2 , 15 , 52 , 0 ) , 60 , + // 1 , 4 , 3 , 2 , 10000 ); + // // the following statement should actually add a bar, if no bar with the same + // // key is in the database + // this.writeToDataBaseActually( bar ); + // bar = new Bar( + // "AAPL" , "Q" , new DateTime( 2009 , 1 , 2 , 15 , 52 , 0 ) , 60 , + // 1 , 4 , 3 , 2 , 20000 ); + // // the following statement will not add the bar, because a bar with the + // // same key has just been added above, but NO EXCEPTION will be risen + // this.writeToDataBaseActually( bar ); + // } } } |