You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ibatis.apache.org by gb...@apache.org on 2006/10/03 19:00:02 UTC
svn commit: r452570 - in /ibatis/trunk/cs/mapper:
IBatisNet.Common/Utilities/ IBatisNet.DataMapper.Test/NUnit/SqlMapTests/
IBatisNet.DataMapper.Test/bin/Debug/ IBatisNet.DataMapper/Configuration/
Author: gbayon
Date: Tue Oct 3 10:00:01 2006
New Revision: 452570
URL: http://svn.apache.org/viewvc?view=rev&rev=452570
Log:
Fixed IBATISNET-178
Modified:
ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/ConfigWatcherHandler.cs
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/ConfigureTest.cs
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/bin/Debug/IBatisNet.DataMapper.Test.dll.config
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/DomSqlMapBuilder.cs
Modified: ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/ConfigWatcherHandler.cs
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/ConfigWatcherHandler.cs?view=diff&rev=452570&r1=452569&r2=452570
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/ConfigWatcherHandler.cs (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/ConfigWatcherHandler.cs Tue Oct 3 10:00:01 2006
@@ -25,6 +25,7 @@
#endregion
using System.Collections;
+using System.Collections.Specialized;
using System.IO;
using System.Threading;
using IBatisNet.Common.Logging;
@@ -111,33 +112,43 @@
{
FileInfo configFile = (FileInfo)_filesToWatch[index];
- // Create a new FileSystemWatcher and set its properties.
- FileSystemWatcher watcher = new FileSystemWatcher();
-
- watcher.Path = configFile.DirectoryName;
- watcher.Filter = configFile.Name;
-
- // Set the notification filters
- watcher.NotifyFilter = NotifyFilters.CreationTime | NotifyFilters.LastWrite | NotifyFilters.FileName;
-
- // Add event handlers. OnChanged will do for all event handlers that fire a FileSystemEventArgs
- watcher.Changed += new FileSystemEventHandler(ConfigWatcherHandler_OnChanged);
- watcher.Created += new FileSystemEventHandler(ConfigWatcherHandler_OnChanged);
- watcher.Deleted += new FileSystemEventHandler(ConfigWatcherHandler_OnChanged);
- watcher.Renamed += new RenamedEventHandler(ConfigWatcherHandler_OnRenamed);
-
- // Begin watching.
- watcher.EnableRaisingEvents = true;
-
- _filesWatcher.Add( watcher );
-
+ AttachWatcher(configFile);
+
// Create the timer that will be used to deliver events. Set as disabled
- _timer = new Timer(onWhatchedFileChange, state, Timeout.Infinite, Timeout.Infinite);
+ // callback : A TimerCallback delegate representing a method to be executed.
+ // state : An object containing information to be used by the callback method, or a null reference
+ // dueTime : The amount of time to delay before callback is invoked, in milliseconds. Specify Timeout.Infinite to prevent the timer from starting. Specify zero (0) to start the timer immediately
+ // period : The time interval between invocations of callback, in milliseconds. Specify Timeout.Infinite to disable periodic signaling
+ _timer = new Timer(onWhatchedFileChange, state, Timeout.Infinite, Timeout.Infinite);
}
}
#endregion
#region Methods
+
+ private void AttachWatcher(FileInfo configFile)
+ {
+ // Create a new FileSystemWatcher and set its properties.
+ FileSystemWatcher watcher = new FileSystemWatcher();
+
+ watcher.Path = configFile.DirectoryName;
+ watcher.Filter = configFile.Name;
+
+ // Set the notification filters
+ watcher.NotifyFilter = NotifyFilters.CreationTime | NotifyFilters.LastWrite | NotifyFilters.FileName;
+
+ // Add event handlers. OnChanged will do for all event handlers that fire a FileSystemEventArgs
+ watcher.Changed += new FileSystemEventHandler(ConfigWatcherHandler_OnChanged);
+ watcher.Created += new FileSystemEventHandler(ConfigWatcherHandler_OnChanged);
+ watcher.Deleted += new FileSystemEventHandler(ConfigWatcherHandler_OnChanged);
+ watcher.Renamed += new RenamedEventHandler(ConfigWatcherHandler_OnRenamed);
+
+ // Begin watching.
+ watcher.EnableRaisingEvents = true;
+
+ _filesWatcher.Add(watcher);
+ }
+
/// <summary>
/// Add a file to be monitored.
/// </summary>
Modified: ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/ConfigureTest.cs
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/ConfigureTest.cs?view=diff&rev=452570&r1=452569&r2=452570
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/ConfigureTest.cs (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/ConfigureTest.cs Tue Oct 3 10:00:01 2006
@@ -2,6 +2,7 @@
using System.Configuration;
using System.IO;
using System.Reflection;
+using System.Threading;
using IBatisNet.Common.Utilities;
using IBatisNet.DataMapper; // SqlMap API
using IBatisNet.DataMapper.Configuration;
@@ -391,6 +392,93 @@
}
#endregion
+
+ private bool _hasChanged = false;
+
+ /// <summary>
+ /// ConfigurationWatcher Test
+ /// </summary>
+ [Test]
+ public void ConfigurationWatcherTestOnSqlMapConfig()
+ {
+ string fileName = @"..\..\Maps\MSSQL\SqlClient\Account.xml";
+
+ ConfigureHandler handler = new ConfigureHandler(MyHandler);
+
+ DomSqlMapBuilder builder = new DomSqlMapBuilder();
+
+ NameValueCollection properties = new NameValueCollection();
+ properties.Add("collection2Namespace", "IBatisNet.DataMapper.Test.Domain.LineItemCollection, IBatisNet.DataMapper.Test");
+ properties.Add("nullableInt", "int");
+
+ builder.Properties = properties;
+
+ ISqlMapper mapper = builder.ConfigureAndWatch(_fileName, handler);
+
+ // test that the mapper was correct build
+ Assert.IsNotNull(mapper);
+
+ FileInfo fi = Resources.GetFileInfo(_fileName);
+ fi.LastWriteTime = DateTime.Now;
+
+ fi.Refresh();
+
+ // Let's give a small bit of time for the change to propagate.
+ // The ConfigWatcherHandler class has a timer which
+ // waits for 500 Millis before delivering
+ // the event notification.
+ System.Threading.Thread.Sleep(600);
+
+ Assert.IsTrue(_hasChanged);
+
+ _hasChanged = false;
+
+ }
+
+ /// <summary>
+ /// ConfigurationWatcher Test
+ /// </summary>
+ [Test]
+ public void ConfigurationWatcherTestOnMappingFile()
+ {
+ string fileName = @"..\..\Maps\MSSQL\SqlClient\Account.xml";
+
+ ConfigureHandler handler = new ConfigureHandler(MyHandler);
+
+ DomSqlMapBuilder builder = new DomSqlMapBuilder();
+
+ NameValueCollection properties = new NameValueCollection();
+ properties.Add("collection2Namespace", "IBatisNet.DataMapper.Test.Domain.LineItemCollection, IBatisNet.DataMapper.Test");
+ properties.Add("nullableInt", "int");
+
+ builder.Properties = properties;
+
+ ISqlMapper mapper = builder.ConfigureAndWatch(_fileName, handler);
+
+ // test that the mapper was correct build
+ Assert.IsNotNull(mapper);
+
+ FileInfo fi = Resources.GetFileInfo(fileName);
+ fi.LastWriteTime = DateTime.Now;
+
+ fi.Refresh();
+
+ // Let's give a small bit of time for the change to propagate.
+ // The ConfigWatcherHandler class has a timer which
+ // waits for 500 Millis before delivering
+ // the event notification.
+ System.Threading.Thread.Sleep(600);
+
+ Assert.IsTrue(_hasChanged);
+
+ _hasChanged = false;
+
+ }
+
+ protected void MyHandler(object obj)
+ {
+ _hasChanged = true;
+ }
}
}
Modified: ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/bin/Debug/IBatisNet.DataMapper.Test.dll.config
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/bin/Debug/IBatisNet.DataMapper.Test.dll.config?view=diff&rev=452570&r1=452569&r2=452570
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/bin/Debug/IBatisNet.DataMapper.Test.dll.config (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/bin/Debug/IBatisNet.DataMapper.Test.dll.config Tue Oct 3 10:00:01 2006
@@ -30,20 +30,21 @@
<iBATIS>
<logging>
-<!--
- <logFactoryAdapter type="IBatisNet.Common.Logging.Impl.ConsoleOutLoggerFA, IBatisNet.Common">
+<!--
+ <logFactoryAdapter type="IBatisNet.Common.Logging.Impl.ConsoleOutLoggerFA, IBatisNet.Common">
<arg key="showLogName" value="true" />
<arg key="showDataTime" value="true" />
<arg key="level" value="ALL" />
<arg key="dateTimeFormat" value="yyyy/MM/dd HH:mm:ss:SSS" />
</logFactoryAdapter>
- <logFactoryAdapter type="IBatisNet.Common.Logging.Impl.Log4NetLoggerFA, IBatisNet.Common.Logging.Log4Net">
+ <logFactoryAdapter type="IBatisNet.Common.Logging.Impl.Log4NetLoggerFA, IBatisNet.Common.Logging.Log4Net">
<arg key="configType" value="inline" />
- </logFactoryAdapter>
- -->
+ </logFactoryAdapter>
+-->
+<!--
<logFactoryAdapter type="IBatisNet.Common.Logging.Impl.NoOpLoggerFA, IBatisNet.Common" />
-
+ -->
</logging>
</iBATIS>
@@ -110,6 +111,9 @@
<logger name="IBatisNet.DataMapper.Commands.DefaultPreparedCommand">
<level value="DEBUG" />
</logger>
+ <logger name="IBatisNet.Common.Utilities.ConfigWatcherHandler">
+ <level value="DEBUG" />
+ </logger>
</log4net>
</configuration>
Modified: ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/DomSqlMapBuilder.cs
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/DomSqlMapBuilder.cs?view=diff&rev=452570&r1=452569&r2=452570
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/DomSqlMapBuilder.cs (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/DomSqlMapBuilder.cs Tue Oct 3 10:00:01 2006
@@ -504,10 +504,12 @@
StateConfig state = new StateConfig();
state.FileName = resource;
state.ConfigureHandler = configureDelegate;
-
+
+ ISqlMapper sqlMapper = Build( document, true );
+
new ConfigWatcherHandler( callBakDelegate, state );
- return Build( document, true );
+ return sqlMapper;
}
/// <summary>
@@ -534,9 +536,11 @@
state.FileName = resource.FullName;
state.ConfigureHandler = configureDelegate;
- new ConfigWatcherHandler( callBakDelegate, state );
+ ISqlMapper sqlMapper = Build( document, true );
+
+ new ConfigWatcherHandler(callBakDelegate, state);
- return Build( document, true );
+ return sqlMapper;
}
/// <summary>