Skip to content

Commit

Permalink
Renamed ICommitSetting to IListenerSettings
Browse files Browse the repository at this point in the history
Implemented AddParameter parameter in CfgHelper.Configure
  • Loading branch information
richtea committed Jan 5, 2011
1 parent e6f6d31 commit f443bcd
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 118 deletions.
17 changes: 17 additions & 0 deletions NHibernate.SolrNet.Tests/CfgHelperTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,23 @@ public void Configure_from_serviceprovider() {
Assert.IsInstanceOfType<SolrNetListener<Entity>>(listener);
}

[Test]
public void Configure_with_addparameters() {
var nhConfig = ConfigurationExtensions.GetNhConfig();
var provider = MockRepository.GenerateMock<IServiceProvider>();
var mapper = MockRepository.GenerateMock<IReadOnlyMappingManager>();
mapper.Expect(x => x.GetRegisteredTypes()).Return(new[] {typeof (Entity)});
var solr = MockRepository.GenerateMock<ISolrOperations<Entity>>();
provider.Expect(x => x.GetService(typeof (IReadOnlyMappingManager))).Return(mapper);
provider.Expect(x => x.GetService(typeof (ISolrOperations<Entity>))).Return(solr);
var addParameters = new AddParameters {CommitWithin = 4343};
var helper = new CfgHelper(provider);
helper.Configure(nhConfig, true, addParameters);
var listener = nhConfig.EventListeners.PostInsertEventListeners[0];
Assert.IsInstanceOfType<SolrNetListener<Entity>>(listener);
Assert.AreEqual(addParameters, ((IListenerSettings)listener).AddParameters);
}

[Test]
public void Does_not_override_existing_listeners() {
var nhConfig = ConfigurationExtensions.GetNhConfig();
Expand Down
13 changes: 3 additions & 10 deletions NHibernate.SolrNet/CfgHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,7 @@ public CfgHelper() {
/// <param name="autoCommit"></param>
/// <returns></returns>
public Configuration Configure(Configuration config, bool autoCommit) {
foreach (var t in mapper.GetRegisteredTypes()) {
var listenerType = typeof (SolrNetListener<>).MakeGenericType(t);
var solrType = typeof (ISolrOperations<>).MakeGenericType(t);
var solr = provider.GetService(solrType);
var listener = (ICommitSetting) Activator.CreateInstance(listenerType, solr);
listener.Commit = autoCommit;
NHHelper.SetListener(config, listener);
}
return config;
return Configure(config, autoCommit, null);
}

/// <summary>
Expand All @@ -85,8 +77,9 @@ public Configuration Configure(Configuration config, bool autoCommit, AddParamet
var listenerType = typeof (SolrNetListener<>).MakeGenericType(t);
var solrType = typeof (ISolrOperations<>).MakeGenericType(t);
var solr = provider.GetService(solrType);
var listener = (ICommitSetting) Activator.CreateInstance(listenerType, solr);
var listener = (IListenerSettings) Activator.CreateInstance(listenerType, solr);
listener.Commit = autoCommit;
listener.AddParameters = parameters;
NHHelper.SetListener(config, listener);
}
return config;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,19 @@
// limitations under the License.
#endregion

using SolrNet;

namespace NHibernate.SolrNet.Impl {
public interface ICommitSetting {
public interface IListenerSettings {
/// <summary>
/// Automatically commit Solr after each update
/// </summary>
bool Commit { get; set; }

/// <summary>
/// Gets or sets the parameters to use when adding a document to the index.
/// </summary>
/// <value>The parameters to use when adding a document to the index.</value>
AddParameters AddParameters { get; set; }
}
}
2 changes: 1 addition & 1 deletion NHibernate.SolrNet/Impl/SolrNetListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace NHibernate.SolrNet.Impl {
/// NHibernate event listener for updating Solr index
/// </summary>
/// <typeparam name="T"></typeparam>
public class SolrNetListener<T> : ICommitSetting, IAutoFlushEventListener, IFlushEventListener, IPostInsertEventListener, IPostDeleteEventListener, IPostUpdateEventListener where T : class {
public class SolrNetListener<T> : IListenerSettings, IAutoFlushEventListener, IFlushEventListener, IPostInsertEventListener, IPostDeleteEventListener, IPostUpdateEventListener where T : class {
private readonly ISolrOperations<T> solr;
private readonly WeakHashtable entitiesToAdd = new WeakHashtable();
private readonly WeakHashtable entitiesToDelete = new WeakHashtable();
Expand Down
212 changes: 106 additions & 106 deletions NHibernate.SolrNet/NHibernate.SolrNet.csproj
Original file line number Diff line number Diff line change
@@ -1,113 +1,113 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{D3312CD6-C4E8-4903-9B9D-95175B85EEE8}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>NHibernate.SolrNet</RootNamespace>
<AssemblyName>NHibernate.SolrNet</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<FileUpgradeFlags>
</FileUpgradeFlags>
<OldToolsVersion>3.5</OldToolsVersion>
<UpgradeBackupLocation />
<TargetFrameworkProfile />
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
<DocumentationFile>bin\Debug\NHibernate.SolrNet.XML</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
<DocumentationFile>bin\Release\NHibernate.SolrNet.XML</DocumentationFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.Practices.ServiceLocation, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\lib\Microsoft.Practices.ServiceLocation.dll</HintPath>
</Reference>
<Reference Include="NHibernate, Version=2.1.2.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\lib\NHibernate.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="CfgHelper.cs" />
<Compile Include="Impl\DelegatingSession.cs" />
<Compile Include="Impl\ICommitSetting.cs" />
<Compile Include="Impl\NHHelper.cs" />
<Compile Include="INHSolrQuery.cs" />
<Compile Include="ISolrSession.cs" />
<Compile Include="Impl\NHSolrQueryImpl.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Impl\SolrNetListener.cs" />
<Compile Include="SolrSession.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SolrNet\SolrNet.csproj">
<Project>{CEEB8690-3E08-4440-B647-787A58E71CFA}</Project>
<Name>SolrNet</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
<Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Windows.Installer.3.1">
<Visible>False</Visible>
<ProductName>Windows Installer 3.1</ProductName>
<Install>true</Install>
</BootstrapperPackage>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{D3312CD6-C4E8-4903-9B9D-95175B85EEE8}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>NHibernate.SolrNet</RootNamespace>
<AssemblyName>NHibernate.SolrNet</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<FileUpgradeFlags>
</FileUpgradeFlags>
<OldToolsVersion>3.5</OldToolsVersion>
<UpgradeBackupLocation />
<TargetFrameworkProfile />
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
<DocumentationFile>bin\Debug\NHibernate.SolrNet.XML</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
<DocumentationFile>bin\Release\NHibernate.SolrNet.XML</DocumentationFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.Practices.ServiceLocation, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\lib\Microsoft.Practices.ServiceLocation.dll</HintPath>
</Reference>
<Reference Include="NHibernate, Version=2.1.2.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\lib\NHibernate.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="CfgHelper.cs" />
<Compile Include="Impl\DelegatingSession.cs" />
<Compile Include="Impl\IListenerSettings.cs" />
<Compile Include="Impl\NHHelper.cs" />
<Compile Include="INHSolrQuery.cs" />
<Compile Include="ISolrSession.cs" />
<Compile Include="Impl\NHSolrQueryImpl.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Impl\SolrNetListener.cs" />
<Compile Include="SolrSession.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SolrNet\SolrNet.csproj">
<Project>{CEEB8690-3E08-4440-B647-787A58E71CFA}</Project>
<Name>SolrNet</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
<Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Windows.Installer.3.1">
<Visible>False</Visible>
<ProductName>Windows Installer 3.1</ProductName>
<Install>true</Install>
</BootstrapperPackage>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
-->
</Project>

0 comments on commit f443bcd

Please sign in to comment.