From: <fab...@us...> - 2008-11-07 22:33:00
|
Revision: 3894 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=3894&view=rev Author: fabiomaulo Date: 2008-11-07 22:32:55 +0000 (Fri, 07 Nov 2008) Log Message: ----------- - Fix some SVN problems of previous commit - Changed names of ProxyGenerators to ByteCode - Using LinFu for NH-Tests Added Paths: ----------- trunk/nhibernate/src/NHibernate.ByteCode.Castle/ trunk/nhibernate/src/NHibernate.ByteCode.Castle/ByteCode.build trunk/nhibernate/src/NHibernate.ByteCode.Castle/LazyInitializer.cs trunk/nhibernate/src/NHibernate.ByteCode.Castle/NHibernate.ByteCode.Castle.csproj trunk/nhibernate/src/NHibernate.ByteCode.Castle/Properties/ trunk/nhibernate/src/NHibernate.ByteCode.Castle/ProxyFactory.cs trunk/nhibernate/src/NHibernate.ByteCode.Castle/ProxyFactoryFactory.cs trunk/nhibernate/src/NHibernate.ByteCode.Castle.Tests/ trunk/nhibernate/src/NHibernate.ByteCode.Castle.Tests/App.config trunk/nhibernate/src/NHibernate.ByteCode.Castle.Tests/ByteCode.Test.build trunk/nhibernate/src/NHibernate.ByteCode.Castle.Tests/DebugConnectionProvider.cs trunk/nhibernate/src/NHibernate.ByteCode.Castle.Tests/NHibernate.ByteCode.Castle.Tests.csproj trunk/nhibernate/src/NHibernate.ByteCode.Castle.Tests/Properties/ trunk/nhibernate/src/NHibernate.ByteCode.Castle.Tests/ProxyInterface/ trunk/nhibernate/src/NHibernate.ByteCode.Castle.Tests/ProxyInterface/CastleProxy.cs trunk/nhibernate/src/NHibernate.ByteCode.Castle.Tests/ProxyInterface/CastleProxyFixture.cs trunk/nhibernate/src/NHibernate.ByteCode.Castle.Tests/ProxyInterface/CastleProxyImpl.cs trunk/nhibernate/src/NHibernate.ByteCode.Castle.Tests/ProxyInterface/CastleProxyImpl.hbm.xml trunk/nhibernate/src/NHibernate.ByteCode.Castle.Tests/ProxyInterface/Classes.cs trunk/nhibernate/src/NHibernate.ByteCode.Castle.Tests/ProxyInterface/CustomProxyFixture.cs trunk/nhibernate/src/NHibernate.ByteCode.Castle.Tests/ProxyInterface/Mappings.hbm.xml trunk/nhibernate/src/NHibernate.ByteCode.Castle.Tests/TestCase.cs trunk/nhibernate/src/NHibernate.ByteCode.Castle.Tests/TestConfigurationHelper.cs trunk/nhibernate/src/NHibernate.ByteCode.LinFu/ trunk/nhibernate/src/NHibernate.ByteCode.LinFu/ByteCode.build trunk/nhibernate/src/NHibernate.ByteCode.LinFu/LazyInitializer.cs trunk/nhibernate/src/NHibernate.ByteCode.LinFu/NHibernate.ByteCode.LinFu.csproj trunk/nhibernate/src/NHibernate.ByteCode.LinFu/Properties/ trunk/nhibernate/src/NHibernate.ByteCode.LinFu/ProxyFactory.cs trunk/nhibernate/src/NHibernate.ByteCode.LinFu/ProxyFactoryFactory.cs trunk/nhibernate/src/NHibernate.ByteCode.LinFu.Tests/ trunk/nhibernate/src/NHibernate.ByteCode.LinFu.Tests/App.config trunk/nhibernate/src/NHibernate.ByteCode.LinFu.Tests/ByteCode.Test.build trunk/nhibernate/src/NHibernate.ByteCode.LinFu.Tests/DebugConnectionProvider.cs trunk/nhibernate/src/NHibernate.ByteCode.LinFu.Tests/NHibernate.ByteCode.LinFu.Tests.csproj trunk/nhibernate/src/NHibernate.ByteCode.LinFu.Tests/Properties/ trunk/nhibernate/src/NHibernate.ByteCode.LinFu.Tests/ProxyInterface/ trunk/nhibernate/src/NHibernate.ByteCode.LinFu.Tests/ProxyInterface/IMyProxy.cs trunk/nhibernate/src/NHibernate.ByteCode.LinFu.Tests/ProxyInterface/MyProxyImpl.cs trunk/nhibernate/src/NHibernate.ByteCode.LinFu.Tests/ProxyInterface/ProxyFixture.cs trunk/nhibernate/src/NHibernate.ByteCode.LinFu.Tests/ProxyInterface/ProxyImpl.hbm.xml trunk/nhibernate/src/NHibernate.ByteCode.LinFu.Tests/TestCase.cs trunk/nhibernate/src/NHibernate.ByteCode.LinFu.Tests/TestConfigurationHelper.cs Property changes on: trunk/nhibernate/src/NHibernate.ByteCode.Castle ___________________________________________________________________ Added: bugtraq:url + http://jira.nhibernate.org/browse/%BUGID% Added: svn:ignore + obj .#* *.user *.xsx AssemblyInfo.cs *.aps *.eto [Bb]in [Dd]ebug [Rr]elease *resharper* Added: bugtraq:logregex + NH-\d+ Added: trunk/nhibernate/src/NHibernate.ByteCode.Castle/ByteCode.build =================================================================== --- trunk/nhibernate/src/NHibernate.ByteCode.Castle/ByteCode.build (rev 0) +++ trunk/nhibernate/src/NHibernate.ByteCode.Castle/ByteCode.build 2008-11-07 22:32:55 UTC (rev 3894) @@ -0,0 +1,37 @@ +<?xml version="1.0" ?> + +<project + name="NHibernate.ProxyGenerators.CastleDynamicProxy" + default="build" + xmlns="http://nant.sf.net/release/0.85-rc3/nant.xsd" +> + + <property name="root.dir" value="../.." /> + <include buildfile="${root.dir}/build-common/common-project.xml" /> + + <target name="init" depends="common.init"> + + <property name="assembly.is-cls-compliant" value="true" /> + <property name="assembly.description" + value="Castle Dynamic proxy generator adapters for NHibernate." /> + <property name="assembly.copyright" + value="Licensed under LGPL." /> + <property name="assembly.allow-partially-trusted-callers" value="true" /> + + <property name="clover.instrument" value="true" /> + + <assemblyfileset basedir="${bin.dir}" id="project.references"> + <include name="System.dll" /> + <include name="Iesi.Collections.dll" /> + <include name="log4net.dll" /> + <include name="Castle.Core.dll" /> + <include name="Castle.DynamicProxy2.dll" /> + <include name="NHibernate.dll" /> + </assemblyfileset> + + </target> + + <target name="generate-assemblyinfo" depends="init common.generate-assemblyinfo" /> + <target name="build" depends="init generate-assemblyinfo common.compile-dll" description="Build Castle ProxyGenerators" /> + +</project> Added: trunk/nhibernate/src/NHibernate.ByteCode.Castle/LazyInitializer.cs =================================================================== --- trunk/nhibernate/src/NHibernate.ByteCode.Castle/LazyInitializer.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.ByteCode.Castle/LazyInitializer.cs 2008-11-07 22:32:55 UTC (rev 3894) @@ -0,0 +1,86 @@ +using System; +using System.Reflection; +using Castle.Core.Interceptor; +using NHibernate.Proxy; +using NHibernate.Proxy.Poco; +using NHibernate.Type; +using NHibernate.Engine; + +namespace NHibernate.ByteCode.Castle +{ + /// <summary> + /// A <see cref="ILazyInitializer"/> for use with the Castle Dynamic Class Generator. + /// </summary> + [Serializable] + [CLSCompliant(false)] + public class LazyInitializer : BasicLazyInitializer, global::Castle.Core.Interceptor.IInterceptor + { + private static readonly MethodInfo Exception_InternalPreserveStackTrace = + typeof(Exception).GetMethod("InternalPreserveStackTrace", BindingFlags.Instance | BindingFlags.NonPublic); + + #region Instance + + public bool _constructed; + + /// <summary> + /// Initializes a new <see cref="LazyInitializer"/> object. + /// </summary> + /// <param name="entityName"></param> + /// <param name="persistentClass">The Class to Proxy.</param> + /// <param name="id">The Id of the Object we are Proxying.</param> + /// <param name="getIdentifierMethod"></param> + /// <param name="setIdentifierMethod"></param> + /// <param name="componentIdType"></param> + /// <param name="session">The ISession this Proxy is in.</param> + public LazyInitializer(string entityName, System.Type persistentClass, object id, + MethodInfo getIdentifierMethod, MethodInfo setIdentifierMethod, + IAbstractComponentType componentIdType, ISessionImplementor session) + :base(entityName, persistentClass, id, getIdentifierMethod, setIdentifierMethod, componentIdType, session) + { + } + + /// <summary> + /// Invoke the actual Property/Method using the Proxy or instantiate the actual + /// object and use it when the Proxy can't handle the method. + /// </summary> + /// <param name="invocation">The <see cref="IInvocation"/> from the generated Castle.DynamicProxy.</param> + public virtual void Intercept(IInvocation invocation) + { + try + { + if (_constructed) + { + // let the generic LazyInitializer figure out if this can be handled + // with the proxy or if the real class needs to be initialized + invocation.ReturnValue = base.Invoke(invocation.Method, invocation.Arguments, invocation.Proxy); + + // the base LazyInitializer could not handle it so we need to Invoke + // the method/property against the real class + if (invocation.ReturnValue == InvokeImplementation) + { + invocation.ReturnValue = invocation.Method.Invoke(GetImplementation(), invocation.Arguments); + return; + } + else + { + return; + } + } + else + { + // TODO: Find out equivalent to CGLIB's 'method.invokeSuper'. + return; + } + } + catch (TargetInvocationException tie) + { + // Propagate the inner exception so that the proxy throws the same exception as + // the real object would + Exception_InternalPreserveStackTrace.Invoke(tie.InnerException, new Object[] { }); + throw tie.InnerException; + } + } + + #endregion + } +} \ No newline at end of file Added: trunk/nhibernate/src/NHibernate.ByteCode.Castle/NHibernate.ByteCode.Castle.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.ByteCode.Castle/NHibernate.ByteCode.Castle.csproj (rev 0) +++ trunk/nhibernate/src/NHibernate.ByteCode.Castle/NHibernate.ByteCode.Castle.csproj 2008-11-07 22:32:55 UTC (rev 3894) @@ -0,0 +1,78 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project ToolsVersion="3.5" 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>{31C3F0EA-0FED-4A2F-B68D-96CE29844487}</ProjectGuid> + <OutputType>Library</OutputType> + <AppDesignerFolder>Properties</AppDesignerFolder> + <RootNamespace>NHibernate.ByteCode.Castle</RootNamespace> + <AssemblyName>NHibernate.ByteCode.Castle</AssemblyName> + <TargetFrameworkVersion>v2.0</TargetFrameworkVersion> + <FileAlignment>512</FileAlignment> + </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> + </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> + </PropertyGroup> + <ItemGroup> + <Reference Include="Castle.Core, Version=1.0.3.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL"> + <SpecificVersion>False</SpecificVersion> + <HintPath>..\..\lib\net\2.0\Castle.Core.dll</HintPath> + </Reference> + <Reference Include="Castle.DynamicProxy2, Version=2.0.3.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL"> + <SpecificVersion>False</SpecificVersion> + <HintPath>..\..\lib\net\2.0\Castle.DynamicProxy2.dll</HintPath> + </Reference> + <Reference Include="Iesi.Collections, Version=1.0.0.3, Culture=neutral, PublicKeyToken=aa95f207798dfdb4, processorArchitecture=MSIL"> + <SpecificVersion>False</SpecificVersion> + <HintPath>..\..\lib\net\2.0\Iesi.Collections.dll</HintPath> + </Reference> + <Reference Include="log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=1b44e1d426115821, processorArchitecture=MSIL"> + <SpecificVersion>False</SpecificVersion> + <HintPath>..\..\lib\net\2.0\log4net.dll</HintPath> + </Reference> + <Reference Include="System" /> + </ItemGroup> + <ItemGroup> + <Compile Include="AssemblyInfo.cs" /> + <Compile Include="LazyInitializer.cs" /> + <Compile Include="ProxyFactory.cs" /> + <Compile Include="ProxyFactoryFactory.cs" /> + </ItemGroup> + <ItemGroup> + <ProjectReference Include="..\NHibernate\NHibernate.csproj"> + <Project>{5909BFE7-93CF-4E5F-BE22-6293368AF01D}</Project> + <Name>NHibernate</Name> + </ProjectReference> + </ItemGroup> + <ItemGroup> + <None Include="ByteCode.build" /> + </ItemGroup> + <ItemGroup> + <Folder Include="Properties\" /> + </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> \ No newline at end of file Property changes on: trunk/nhibernate/src/NHibernate.ByteCode.Castle/Properties ___________________________________________________________________ Added: bugtraq:url + http://jira.nhibernate.org/browse/%BUGID% Added: bugtraq:logregex + NH-\d+ Added: trunk/nhibernate/src/NHibernate.ByteCode.Castle/ProxyFactory.cs =================================================================== --- trunk/nhibernate/src/NHibernate.ByteCode.Castle/ProxyFactory.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.ByteCode.Castle/ProxyFactory.cs 2008-11-07 22:32:55 UTC (rev 3894) @@ -0,0 +1,105 @@ +using System; +using System.Reflection; +using Castle.DynamicProxy; +using Iesi.Collections.Generic; +using log4net; +using NHibernate.Engine; +using NHibernate.Proxy; +using NHibernate.Type; + +namespace NHibernate.ByteCode.Castle +{ + public class ProxyFactory : IProxyFactory + { + protected static readonly ILog log = LogManager.GetLogger(typeof (ProxyFactory)); + private static readonly ProxyGenerator _proxyGenerator = new ProxyGenerator(); + + private System.Type _persistentClass; + private System.Type[] _interfaces; + private MethodInfo _getIdentifierMethod; + private MethodInfo _setIdentifierMethod; + private string _entityName; + private IAbstractComponentType _componentIdType; + + public virtual void PostInstantiate(string entityName, System.Type persistentClass, ISet<System.Type> interfaces, + MethodInfo getIdentifierMethod, MethodInfo setIdentifierMethod, + IAbstractComponentType componentIdType) + { + _entityName = entityName; + _persistentClass = persistentClass; + _interfaces = new System.Type[interfaces.Count]; + interfaces.CopyTo(_interfaces, 0); + _getIdentifierMethod = getIdentifierMethod; + _setIdentifierMethod = setIdentifierMethod; + _componentIdType = componentIdType; + } + + protected static ProxyGenerator DefaultProxyGenerator + { + get { return _proxyGenerator; } + } + + protected System.Type PersistentClass + { + get { return _persistentClass; } + } + + protected System.Type[] Interfaces + { + get { return _interfaces; } + } + + protected MethodInfo GetIdentifierMethod + { + get { return _getIdentifierMethod; } + } + + protected MethodInfo SetIdentifierMethod + { + get { return _setIdentifierMethod; } + } + + protected bool IsClassProxy + { + get { return _interfaces.Length == 1; } + } + + public string EntityName + { + get { return _entityName; } + } + + public IAbstractComponentType ComponentIdType + { + get { return _componentIdType; } + } + + /// <summary> + /// Build a proxy using the Castle.DynamicProxy library. + /// </summary> + /// <param name="id">The value for the Id.</param> + /// <param name="session">The Session the proxy is in.</param> + /// <returns>A fully built <c>INHibernateProxy</c>.</returns> + public virtual INHibernateProxy GetProxy(object id, ISessionImplementor session) + { + try + { + var initializer = new LazyInitializer(EntityName, _persistentClass, id, _getIdentifierMethod, + _setIdentifierMethod, ComponentIdType, session); + + object generatedProxy = IsClassProxy + ? _proxyGenerator.CreateClassProxy(_persistentClass, _interfaces, initializer) + : _proxyGenerator.CreateInterfaceProxyWithoutTarget(_interfaces[0], _interfaces, + initializer); + + initializer._constructed = true; + return (INHibernateProxy) generatedProxy; + } + catch (Exception e) + { + log.Error("Creating a proxy instance failed", e); + throw new HibernateException("Creating a proxy instance failed", e); + } + } + } +} \ No newline at end of file Added: trunk/nhibernate/src/NHibernate.ByteCode.Castle/ProxyFactoryFactory.cs =================================================================== --- trunk/nhibernate/src/NHibernate.ByteCode.Castle/ProxyFactoryFactory.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.ByteCode.Castle/ProxyFactoryFactory.cs 2008-11-07 22:32:55 UTC (rev 3894) @@ -0,0 +1,22 @@ +using NHibernate.Bytecode; +using NHibernate.Proxy; + +namespace NHibernate.ByteCode.Castle +{ + public class ProxyFactoryFactory : IProxyFactoryFactory + { + #region IProxyFactoryFactory Members + + public IProxyFactory BuildProxyFactory() + { + return new ProxyFactory(); + } + + public IProxyValidator ProxyValidator + { + get { return new DynProxyTypeValidator(); } + } + + #endregion + } +} \ No newline at end of file Property changes on: trunk/nhibernate/src/NHibernate.ByteCode.Castle.Tests ___________________________________________________________________ Added: bugtraq:url + http://jira.nhibernate.org/browse/%BUGID% Added: svn:ignore + obj .#* *.user *.xsx AssemblyInfo.cs hibernate.cfg.xml *.aps *.eto [Bb]in [Dd]ebug [Rr]elease *resharper* Added: bugtraq:logregex + NH-\d+ Added: trunk/nhibernate/src/NHibernate.ByteCode.Castle.Tests/App.config =================================================================== --- trunk/nhibernate/src/NHibernate.ByteCode.Castle.Tests/App.config (rev 0) +++ trunk/nhibernate/src/NHibernate.ByteCode.Castle.Tests/App.config 2008-11-07 22:32:55 UTC (rev 3894) @@ -0,0 +1,102 @@ +<?xml version="1.0" encoding="utf-8" ?> +<configuration> + <configSections> + <section name="hibernate-configuration" + type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate" /> + <section name="log4net" + type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" /> + </configSections> + + <!-- + hibernate-configuration section + + You don't need to change this section for your own use. + You can write your own hibernate.cfg.xml to override all session-factory configuration. + Templates are available in NHibernate.Config.Templates folder. + --> + <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2"> + <bytecode-provider type="lcg"/> + <reflection-optimizer use="true"/> + <session-factory name="NHibernate.Test"> + <property name="connection.provider">NHibernate.ByteCode.Castle.Tests.DebugConnectionProvider, NHibernate.ByteCode.Castle.Tests</property> + <property name="cache.provider_class">NHibernate.Cache.HashtableCacheProvider, NHibernate</property> + <property name="cache.use_query_cache">true</property> + <property name="prepare_sql">false</property> + <property name="query.startup_check">false</property> + <property name="connection.isolation">ReadCommitted</property> + <property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property> + <property name="connection.connection_string"> + Server=(local);initial catalog=nhibernate;Integrated Security=SSPI + </property> + <property name="show_sql">false</property> + <property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property> + <property name="use_outer_join">true</property> + <property name="command_timeout">10</property> + <property name="query.substitutions">true 1, false 0, yes 'Y', no 'N'</property> + <property name="adonet.wrap_result_sets">false</property> + + <!-- This property is the default value in NH Core --> + <property name="proxyfactory.factory_class">NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property> + + </session-factory> + </hibernate-configuration> + + <!-- This section contains the log4net configuration settings --> + <log4net debug="false"> + + <!-- Define some output appenders --> + <appender name="trace" + type="log4net.Appender.TraceAppender, log4net"> + <layout type="log4net.Layout.PatternLayout,log4net"> + <param name="ConversionPattern" + value="%d{ABSOLUTE} %-5p %c{1}:%L - %m%n" /> + </layout> + </appender> + + <appender name="console" + type="log4net.Appender.ConsoleAppender, log4net"> + <layout type="log4net.Layout.PatternLayout,log4net"> + <param name="ConversionPattern" + value="%d{ABSOLUTE} %-5p %c{1}:%L - %m%n" /> + </layout> + </appender> + + <appender name="rollingFile" + type="log4net.Appender.RollingFileAppender,log4net" > + + <param name="File" + value="log.txt" /> + <param name="AppendToFile" + value="false" /> + <param name="RollingStyle" + value="Date" /> + <param name="DatePattern" + value="yyyy.MM.dd" /> + <param name="StaticLogFileName" + value="true" /> + + <layout type="log4net.Layout.PatternLayout,log4net"> + <param name="ConversionPattern" + value="%d [%t] %-5p %c - %m%n" /> + </layout> + </appender> + + <root> + <priority value="WARN" /> + <appender-ref ref="console" /> + </root> + + <logger name="NHibernate"> + <priority value="ERROR" /> + </logger> + + <logger name="NHibernate.Tool.hbm2ddl.SchemaExport"> + <level value="ERROR" /> + </logger> + </log4net> + + +</configuration> + + + Added: trunk/nhibernate/src/NHibernate.ByteCode.Castle.Tests/ByteCode.Test.build =================================================================== --- trunk/nhibernate/src/NHibernate.ByteCode.Castle.Tests/ByteCode.Test.build (rev 0) +++ trunk/nhibernate/src/NHibernate.ByteCode.Castle.Tests/ByteCode.Test.build 2008-11-07 22:32:55 UTC (rev 3894) @@ -0,0 +1,45 @@ +<?xml version="1.0" ?> + +<project + name="NHibernate.ProxyGenerators.CastleDynamicProxy.Tests" + default="build" + xmlns="http://nant.sf.net/release/0.85-rc3/nant.xsd" +> + + <property name="root.dir" value="../.." /> + + <include buildfile="${root.dir}/build-common/common-project.xml" /> + + <target name="init" depends="common.init"> + + <property name="assembly.is-cls-compliant" value="false" /> + <property name="assembly.description" value="The Unit Tests for Castle ProxyGenerators." /> + <property name="assembly.version" value="1.0.0.1" /> + <property name="assembly.version.informational" value="1.0" /> + + <property name="clover.instrument" value="false" /> + + <assemblyfileset id="project.references" basedir="${bin.dir}"> + <include name="System.dll" /> + <include name="System.XML.dll" /> + <include name="System.Data.dll" /> + <include name="Iesi.Collections.dll" /> + <include name="log4net.dll" /> + <include name="Castle.Core.dll" /> + <include name="Castle.DynamicProxy2.dll" /> + <include name="NHibernate.dll" /> + <include name="NHibernate.ByteCode.Castle.dll" /> + <include name="nunit.framework.dll"/> + </assemblyfileset> + + <resourcefileset id="project.resources" prefix="NHibernate.ByteCode.Castle.Tests" dynamicprefix="true"> + <include name="**/*.xml" /> + <exclude name="bin/**/*.xml" /> + </resourcefileset> + </target> + + <target name="generate-assemblyinfo" depends="init common.generate-assemblyinfo" /> + <target name="build" depends="init generate-assemblyinfo common.compile-tests" /> + <target name="test" depends="init build common.run-tests" /> + +</project> Added: trunk/nhibernate/src/NHibernate.ByteCode.Castle.Tests/DebugConnectionProvider.cs =================================================================== --- trunk/nhibernate/src/NHibernate.ByteCode.Castle.Tests/DebugConnectionProvider.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.ByteCode.Castle.Tests/DebugConnectionProvider.cs 2008-11-07 22:32:55 UTC (rev 3894) @@ -0,0 +1,72 @@ +using System.Collections; +using System.Data; +using Iesi.Collections; +using NHibernate.Connection; + +namespace NHibernate.ByteCode.Castle.Tests +{ + /// <summary> + /// This connection provider keeps a list of all open connections, + /// it is used when testing to check that tests clean up after themselves. + /// </summary> + public class DebugConnectionProvider : DriverConnectionProvider + { + private readonly ISet connections = new ListSet(); + + public override IDbConnection GetConnection() + { + IDbConnection connection = base.GetConnection(); + connections.Add(connection); + return connection; + } + + public override void CloseConnection(IDbConnection conn) + { + base.CloseConnection(conn); + connections.Remove(conn); + } + + public bool HasOpenConnections + { + get + { + // check to see if all connections that were at one point opened + // have been closed through the CloseConnection + // method + if (connections.IsEmpty) + { + // there are no connections, either none were opened or + // all of the closings went through CloseConnection. + return false; + } + else + { + // Disposing of an ISession does not call CloseConnection (should it???) + // so a Diposed of ISession will leave an IDbConnection in the list but + // the IDbConnection will be closed (atleast with MsSql it works this way). + foreach (IDbConnection conn in connections) + { + if (conn.State != ConnectionState.Closed) + { + return true; + } + } + + // all of the connections have been Disposed and were closed that way + // or they were Closed through the CloseConnection method. + return false; + } + } + } + + public void CloseAllConnections() + { + while (!connections.IsEmpty) + { + IEnumerator en = connections.GetEnumerator(); + en.MoveNext(); + CloseConnection(en.Current as IDbConnection); + } + } + } +} \ No newline at end of file Added: trunk/nhibernate/src/NHibernate.ByteCode.Castle.Tests/NHibernate.ByteCode.Castle.Tests.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.ByteCode.Castle.Tests/NHibernate.ByteCode.Castle.Tests.csproj (rev 0) +++ trunk/nhibernate/src/NHibernate.ByteCode.Castle.Tests/NHibernate.ByteCode.Castle.Tests.csproj 2008-11-07 22:32:55 UTC (rev 3894) @@ -0,0 +1,104 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project ToolsVersion="3.5" 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>{4972EE96-2417-4D47-9FF1-3B1D6B1D3191}</ProjectGuid> + <OutputType>Library</OutputType> + <AppDesignerFolder>Properties</AppDesignerFolder> + <RootNamespace>NHibernate.ByteCode.Castle.Tests</RootNamespace> + <AssemblyName>NHibernate.ByteCode.Castle.Tests</AssemblyName> + <TargetFrameworkVersion>v2.0</TargetFrameworkVersion> + <FileAlignment>512</FileAlignment> + </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> + </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> + </PropertyGroup> + <ItemGroup> + <Reference Include="Castle.Core, Version=1.0.3.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL"> + <SpecificVersion>False</SpecificVersion> + <HintPath>..\..\lib\net\2.0\Castle.Core.dll</HintPath> + </Reference> + <Reference Include="Castle.DynamicProxy2, Version=2.0.3.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL"> + <SpecificVersion>False</SpecificVersion> + <HintPath>..\..\lib\net\2.0\Castle.DynamicProxy2.dll</HintPath> + </Reference> + <Reference Include="Iesi.Collections, Version=1.0.0.3, Culture=neutral, PublicKeyToken=aa95f207798dfdb4, processorArchitecture=MSIL"> + <SpecificVersion>False</SpecificVersion> + <HintPath>..\..\lib\net\2.0\Iesi.Collections.dll</HintPath> + </Reference> + <Reference Include="log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=1b44e1d426115821, processorArchitecture=MSIL"> + <SpecificVersion>False</SpecificVersion> + <HintPath>..\..\lib\net\2.0\log4net.dll</HintPath> + </Reference> + <Reference Include="nunit.framework, Version=2.4.8.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL"> + <SpecificVersion>False</SpecificVersion> + <HintPath>..\..\lib\net\2.0\nunit.framework.dll</HintPath> + </Reference> + <Reference Include="System" /> + <Reference Include="System.Data" /> + <Reference Include="System.Xml" /> + </ItemGroup> + <ItemGroup> + <Compile Include="DebugConnectionProvider.cs" /> + <Compile Include="AssemblyInfo.cs" /> + <Compile Include="ProxyInterface\CastleProxy.cs" /> + <Compile Include="ProxyInterface\CastleProxyFixture.cs" /> + <Compile Include="ProxyInterface\CastleProxyImpl.cs" /> + <Compile Include="ProxyInterface\Classes.cs" /> + <Compile Include="ProxyInterface\CustomProxyFixture.cs" /> + <Compile Include="TestCase.cs" /> + <Compile Include="TestConfigurationHelper.cs" /> + </ItemGroup> + <ItemGroup> + <ProjectReference Include="..\NHibernate.ByteCode.Castle\NHibernate.ByteCode.Castle.csproj"> + <Project>{31C3F0EA-0FED-4A2F-B68D-96CE29844487}</Project> + <Name>NHibernate.ByteCode.Castle</Name> + </ProjectReference> + <ProjectReference Include="..\NHibernate\NHibernate.csproj"> + <Project>{5909BFE7-93CF-4E5F-BE22-6293368AF01D}</Project> + <Name>NHibernate</Name> + </ProjectReference> + </ItemGroup> + <ItemGroup> + <EmbeddedResource Include="ProxyInterface\CastleProxyImpl.hbm.xml" /> + </ItemGroup> + <ItemGroup> + <EmbeddedResource Include="ProxyInterface\Mappings.hbm.xml" /> + </ItemGroup> + <ItemGroup> + <None Include="App.config" /> + <None Include="ByteCode.Test.build" /> + </ItemGroup> + <ItemGroup> + <Folder Include="Properties\" /> + </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> + --> + <PropertyGroup> + <PostBuildEvent>if exist hibernate.cfg.xml (del hibernate.cfg.xml) +if exist "$(ProjectDir)hibernate.cfg.xml" (copy "$(ProjectDir)hibernate.cfg.xml" "hibernate.cfg.xml")</PostBuildEvent> + </PropertyGroup> +</Project> \ No newline at end of file Property changes on: trunk/nhibernate/src/NHibernate.ByteCode.Castle.Tests/Properties ___________________________________________________________________ Added: bugtraq:url + http://jira.nhibernate.org/browse/%BUGID% Added: bugtraq:logregex + NH-\d+ Property changes on: trunk/nhibernate/src/NHibernate.ByteCode.Castle.Tests/ProxyInterface ___________________________________________________________________ Added: bugtraq:url + http://jira.nhibernate.org/browse/%BUGID% Added: bugtraq:logregex + NH-\d+ Added: trunk/nhibernate/src/NHibernate.ByteCode.Castle.Tests/ProxyInterface/CastleProxy.cs =================================================================== --- trunk/nhibernate/src/NHibernate.ByteCode.Castle.Tests/ProxyInterface/CastleProxy.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.ByteCode.Castle.Tests/ProxyInterface/CastleProxy.cs 2008-11-07 22:32:55 UTC (rev 3894) @@ -0,0 +1,14 @@ +namespace NHibernate.ByteCode.Castle.Tests.ProxyInterface +{ + /// <summary> + /// Summary description for CastleProxy. + /// </summary> + public interface CastleProxy + { + int Id { get; set; } + + string Name { get; set; } + + void ThrowDeepException(); + } +} \ No newline at end of file Added: trunk/nhibernate/src/NHibernate.ByteCode.Castle.Tests/ProxyInterface/CastleProxyFixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.ByteCode.Castle.Tests/ProxyInterface/CastleProxyFixture.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.ByteCode.Castle.Tests/ProxyInterface/CastleProxyFixture.cs 2008-11-07 22:32:55 UTC (rev 3894) @@ -0,0 +1,144 @@ +using System; +using System.Collections; +using System.IO; +using System.Runtime.Serialization; +using System.Runtime.Serialization.Formatters.Binary; +using NUnit.Framework; + +namespace NHibernate.ByteCode.Castle.Tests.ProxyInterface +{ + /// <summary> + /// Summary description for CastleProxyFixture. + /// </summary> + [TestFixture] + public class CastleProxyFixture : TestCase + { + protected override IList Mappings + { + get { return new[] {"ProxyInterface.CastleProxyImpl.hbm.xml"}; } + } + + [Test] + public void Proxy() + { + ISession s = OpenSession(); + CastleProxy ap = new CastleProxyImpl {Id = 1, Name = "first proxy"}; + s.Save(ap); + s.Flush(); + s.Close(); + + s = OpenSession(); + ap = (CastleProxy) s.Load(typeof (CastleProxyImpl), ap.Id); + Assert.IsFalse(NHibernateUtil.IsInitialized(ap)); + int id = ap.Id; + Assert.IsFalse(NHibernateUtil.IsInitialized(ap), "get id should not have initialized it."); + string name = ap.Name; + Assert.IsTrue(NHibernateUtil.IsInitialized(ap), "get name should have initialized it."); + s.Delete(ap); + s.Flush(); + s.Close(); + } + + private void SerializeAndDeserialize(ref ISession s) + { + // Serialize the session + using (Stream stream = new MemoryStream()) + { + IFormatter formatter = new BinaryFormatter(); + formatter.Serialize(stream, s); + + // Close the original session + s.Close(); + + // Deserialize the session + stream.Position = 0; + s = (ISession) formatter.Deserialize(stream); + } + } + + [Test] + public void ProxySerialize() + { + ISession s = OpenSession(); + CastleProxy ap = new CastleProxyImpl(); + ap.Id = 1; + ap.Name = "first proxy"; + s.Save(ap); + s.Flush(); + s.Close(); + + s = OpenSession(); + ap = (CastleProxy) s.Load(typeof (CastleProxyImpl), ap.Id); + Assert.AreEqual(1, ap.Id); + s.Disconnect(); + + SerializeAndDeserialize(ref s); + + s.Reconnect(); + s.Disconnect(); + + // serialize and then deserialize the session again - make sure Castle.DynamicProxy + // has no problem with serializing two times - earlier versions of it did. + SerializeAndDeserialize(ref s); + + s.Close(); + + s = OpenSession(); + s.Delete(ap); + s.Flush(); + s.Close(); + } + + [Test] + public void SerializeNotFoundProxy() + { + ISession s = OpenSession(); + // this does not actually exists in db + var notThere = (CastleProxy) s.Load(typeof (CastleProxyImpl), 5); + Assert.AreEqual(5, notThere.Id); + s.Disconnect(); + + // serialize and then deserialize the session. + SerializeAndDeserialize(ref s); + + Assert.IsNotNull(s.Load(typeof (CastleProxyImpl), 5), "should be proxy - even though it doesn't exists in db"); + s.Close(); + } + + [Test] + public void ExceptionStackTrace() + { + ISession s = OpenSession(); + CastleProxy ap = new CastleProxyImpl(); + ap.Id = 1; + ap.Name = "first proxy"; + s.Save(ap); + s.Flush(); + s.Close(); + + s = OpenSession(); + ap = (CastleProxy) s.Load(typeof (CastleProxyImpl), ap.Id); + Assert.IsFalse(NHibernateUtil.IsInitialized(ap), "check we have a proxy"); + + try + { + ap.ThrowDeepException(); + Assert.Fail("Exception not thrown"); + } + catch (ArgumentException ae) + { + Assert.AreEqual("thrown from Level2", ae.Message); + + string[] stackTraceLines = ae.StackTrace.Split('\n'); + Assert.IsTrue(stackTraceLines[0].Contains("Level2"), "top of exception stack is Level2()"); + Assert.IsTrue(stackTraceLines[1].Contains("Level1"), "next on exception stack is Level1()"); + } + finally + { + s.Delete(ap); + s.Flush(); + s.Close(); + } + } + } +} \ No newline at end of file Added: trunk/nhibernate/src/NHibernate.ByteCode.Castle.Tests/ProxyInterface/CastleProxyImpl.cs =================================================================== --- trunk/nhibernate/src/NHibernate.ByteCode.Castle.Tests/ProxyInterface/CastleProxyImpl.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.ByteCode.Castle.Tests/ProxyInterface/CastleProxyImpl.cs 2008-11-07 22:32:55 UTC (rev 3894) @@ -0,0 +1,35 @@ +using System; +using NHibernate.ByteCode.Castle.Tests.ProxyInterface; + +namespace NHibernate.ByteCode.Castle.Tests.ProxyInterface +{ + /// <summary> + /// Summary description for CastleProxyImpl. + /// </summary> + [Serializable] + public class CastleProxyImpl : CastleProxy + { + private static void Level1() + { + Level2(); + } + + private static void Level2() + { + throw new ArgumentException("thrown from Level2"); + } + + #region CastleProxy Members + + public int Id { get; set; } + + public string Name { get; set; } + + public void ThrowDeepException() + { + Level1(); + } + + #endregion + } +} \ No newline at end of file Added: trunk/nhibernate/src/NHibernate.ByteCode.Castle.Tests/ProxyInterface/CastleProxyImpl.hbm.xml =================================================================== --- trunk/nhibernate/src/NHibernate.ByteCode.Castle.Tests/ProxyInterface/CastleProxyImpl.hbm.xml (rev 0) +++ trunk/nhibernate/src/NHibernate.ByteCode.Castle.Tests/ProxyInterface/CastleProxyImpl.hbm.xml 2008-11-07 22:32:55 UTC (rev 3894) @@ -0,0 +1,12 @@ +<?xml version="1.0" encoding="utf-8" ?> +<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" + assembly="NHibernate.ByteCode.Castle.Tests" + namespace="NHibernate.ByteCode.Castle.Tests.ProxyInterface"> + <class name="CastleProxyImpl" proxy="CastleProxy" table="avalon_p"> + <id name="Id"> + <generator class="assigned" /> + </id> + + <property name="Name" /> + </class> +</hibernate-mapping> Added: trunk/nhibernate/src/NHibernate.ByteCode.Castle.Tests/ProxyInterface/Classes.cs =================================================================== --- trunk/nhibernate/src/NHibernate.ByteCode.Castle.Tests/ProxyInterface/Classes.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.ByteCode.Castle.Tests/ProxyInterface/Classes.cs 2008-11-07 22:32:55 UTC (rev 3894) @@ -0,0 +1,212 @@ +using System.Collections; +using Iesi.Collections; + +namespace NHibernate.ByteCode.Castle.Tests.ProxyInterface +{ + public class Blog + { + private ISet _posts; + private ISet _users; + + private int blog_id; + + public virtual int BlogID + { + get { return blog_id; } + set { blog_id = value; } + } + + private string blog_name; + + public virtual string BlogName + { + get { return blog_name; } + set { blog_name = value; } + } + + public virtual ISet Posts + { + get { return _posts; } + set { _posts = value; } + } + + public virtual ISet Users + { + get { return _users; } + set { _users = value; } + } + + public Blog() + { + _posts = new HashedSet(); + _users = new HashedSet(); + } + + public Blog(string name) : this() + { + blog_name = name; + } + } + + public class Comment + { + private Comment() {} + + public Comment(string text) : this() + { + _text = text; + } + + private int _id; + private int _indexInPost; + private string _text; + private Post _post; + private User commenter; + + public User Commenter + { + get { return commenter; } + set { commenter = value; } + } + + public virtual int IndexInPost + { + get { return _indexInPost; } + set { _indexInPost = value; } + } + + public virtual Post Post + { + get { return _post; } + set { _post = value; } + } + + public virtual int CommentId + { + get { return _id; } + set { _id = value; } + } + + public virtual string Text + { + get { return _text; } + set { _text = value; } + } + } + + public class Post + { + private int post_id; + private Blog _blog; + private string post_title; + private IList _comments; + private ISet categories = new HashedSet(); + + public ISet Categories + { + get { return categories; } + set { categories = value; } + } + + public virtual IList Comments + { + get { return _comments; } + set { _comments = value; } + } + + public virtual int PostId + { + get { return post_id; } + set { post_id = value; } + } + + public virtual string PostTitle + { + get { return post_title; } + set { post_title = value; } + } + + public virtual Blog Blog + { + get { return _blog; } + set { _blog = value; } + } + + public Post() + { + _comments = new ArrayList(); + } + + public Post(string title) : this() + { + post_title = title; + } + } + + public class User + { + private string _userName; + private int _userId; + private ISet _blogs; + + public virtual ISet Blogs + { + get { return _blogs; } + set { _blogs = value; } + } + + public virtual int UserId + { + get { return _userId; } + set { _userId = value; } + } + + public virtual string UserName + { + get { return _userName; } + set { _userName = value; } + } + + public User() + { + _blogs = new HashedSet(); + } + + public User(string name) : this() + { + _userName = name; + } + } + + public class Category + { + private int category_id; + private string name; + private ISet posts = new HashedSet(); + + public Category() {} + + public Category(string name) + { + this.name = name; + } + + public int CategoryId + { + get { return category_id; } + set { category_id = value; } + } + + public string Name + { + get { return name; } + set { name = value; } + } + + public ISet Posts + { + get { return posts; } + set { posts = value; } + } + } +} \ No newline at end of file Added: trunk/nhibernate/src/NHibernate.ByteCode.Castle.Tests/ProxyInterface/CustomProxyFixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.ByteCode.Castle.Tests/ProxyInterface/CustomProxyFixture.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.ByteCode.Castle.Tests/ProxyInterface/CustomProxyFixture.cs 2008-11-07 22:32:55 UTC (rev 3894) @@ -0,0 +1,151 @@ +using System; +using System.Collections; +using System.ComponentModel; +using System.Reflection; +using Castle.Core.Interceptor; +using Castle.DynamicProxy; +using NHibernate.Bytecode; +using NHibernate.Cfg; +using NHibernate.Engine; +using NHibernate.Proxy; +using NHibernate.Type; +using NUnit.Framework; +using Environment=NHibernate.Cfg.Environment; + +namespace NHibernate.ByteCode.Castle.Tests.ProxyInterface +{ + [TestFixture] + public class CustomProxyFixture : TestCase + { + protected override IList Mappings + { + get { return new[] { "ProxyInterface.Mappings.hbm.xml" }; } + } + + protected override void Configure(Configuration configuration) + { + configuration.Properties[Environment.ProxyFactoryFactoryClass] = + typeof (CustomProxyFactoryFactory).AssemblyQualifiedName; + } + + [Test] + public void CanImplementNotifyPropertyChanged() + { + using (ISession s = OpenSession()) + { + s.Save(new Blog("blah")); + s.Flush(); + } + + using (ISession s = OpenSession()) + { + var blog = (Blog) s.Load(typeof (Blog), 1); + var propertyChanged = (INotifyPropertyChanged) blog; + string propChanged = null; + propertyChanged.PropertyChanged += + delegate(object sender, PropertyChangedEventArgs e) { propChanged = e.PropertyName; }; + + blog.BlogName = "foo"; + Assert.AreEqual("BlogName", propChanged); + } + + using (ISession s = OpenSession()) + { + s.Delete("from Blog"); + s.Flush(); + } + } + } + + public class CustomProxyFactoryFactory : IProxyFactoryFactory + { + #region IProxyFactoryFactory Members + + public IProxyFactory BuildProxyFactory() + { + return new DataBindingProxyFactory(); + } + + public IProxyValidator ProxyValidator + { + get { return new DynProxyTypeValidator(); } + } + + #endregion + } + + public class DataBindingProxyFactory : ProxyFactory + { + public override INHibernateProxy GetProxy(object id, ISessionImplementor session) + { + try + { + LazyInitializer initializer = new DataBindingInterceptor(EntityName, PersistentClass, id, GetIdentifierMethod, + SetIdentifierMethod, ComponentIdType, session); + + object generatedProxy; + + var list = new ArrayList(Interfaces); + list.Add(typeof (INotifyPropertyChanged)); + var interfaces = (System.Type[]) list.ToArray(typeof (System.Type)); + if (IsClassProxy) + { + generatedProxy = DefaultProxyGenerator.CreateClassProxy(PersistentClass, interfaces, ProxyGenerationOptions.Default, + initializer); + } + else + { + generatedProxy = DefaultProxyGenerator.CreateInterfaceProxyWithoutTarget(interfaces[0], interfaces, initializer); + } + + initializer._constructed = true; + return (INHibernateProxy) generatedProxy; + } + catch (Exception e) + { + log.Error("Creating a proxy instance failed", e); + throw new HibernateException("Creating a proxy instance failed", e); + } + } + } + + public class DataBindingInterceptor : LazyInitializer + { + private PropertyChangedEventHandler subscribers = delegate { }; + + public DataBindingInterceptor(string entityName, System.Type persistentClass, object id, + MethodInfo getIdentifierMethod, MethodInfo setIdentifierMethod, + IAbstractComponentType componentIdType, ISessionImplementor session) + : base(entityName, persistentClass, id, getIdentifierMethod, setIdentifierMethod, componentIdType, session) {} + + //public DataBindingInterceptor(System.Type persistentClass, object id, MethodInfo getIdentifierMethod, MethodInfo setIdentifierMethod, ISessionImplementor session) + // : base(persistentClass, id, getIdentifierMethod, setIdentifierMethod, session) + //{ + //} + + public override void Intercept(IInvocation invocation) + { + object result; + if (invocation.Method.DeclaringType == typeof (INotifyPropertyChanged)) + { + var propertyChangedEventHandler = (PropertyChangedEventHandler) invocation.GetArgumentValue(0); + if (invocation.Method.Name.StartsWith("add_")) + { + subscribers += propertyChangedEventHandler; + } + else + { + subscribers -= propertyChangedEventHandler; + } + return; + } + base.Intercept(invocation); + result = invocation.ReturnValue; + if (invocation.Method.Name.StartsWith("set_")) + { + subscribers(this, new PropertyChangedEventArgs(invocation.Method.Name.Substring(4))); + } + invocation.ReturnValue = result; + } + } +} \ No newline at end of file Added: trunk/nhibernate/src/NHibernate.ByteCode.Castle.Tests/ProxyInterface/Mappings.hbm.xml =================================================================== --- trunk/nhibernate/src/NHibernate.ByteCode.Castle.Tests/ProxyInterface/Mappings.hbm.xml (rev 0) +++ trunk/nhibernate/src/NHibernate.ByteCode.Castle.Tests/ProxyInterface/Mappings.hbm.xml 2008-11-07 22:32:55 UTC (rev 3894) @@ -0,0 +1,156 @@ +<?xml version='1.0' encoding='utf-8'?> +<hibernate-mapping + xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' + xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns='urn:nhibernate-mapping-2.2' + assembly="NHibernate.ByteCode.Castle.Tests" + namespace="NHibernate.ByteCode.Castle.Tests.ProxyInterface" + default-lazy='false'> + + <class + name='Blog' + lazy='true' + table='Blogs'> + <id + name='BlogID' + column='blog_id' + unsaved-value='0'> + <generator + class='native' /> + </id> + <property + name='BlogName' + column='blog_name' /> + <set + name='Posts' + lazy='true' + cascade='all-delete-orphan' + inverse='true'> + <key + column='post_blogid' /> + <one-to-many + class='Post' /> + + </set> + <set + name='Users' + + table='UsersBlogs' + lazy='true' + cascade='save-update' + inverse='true'> + <key + column='blog_id' /> + <many-to-many + class='User' + column='user_id' /> + </set> + </class> + <class + name='User' + lazy='true' + table='`Users`'> + <id + name='UserId' + column='user_id'> + <generator + class='native' /> + </id> + <property + name='UserName' + type='string' + column='user_name' /> + <set + name='Blogs' + + table='UsersBlogs' + lazy='true' + cascade='save-update'> + <key + column='user_id' /> + + <many-to-many + class='Blog' + column='blog_id' /> + </set> + </class> + <class + name='Post' + table='Posts'> + <id + name='PostId' + column='post_id' + unsaved-value='0'> + <generator + class='native' /> + </id> + <many-to-one + name='Blog' + + class='Blog' + column='post_blogid' /> + <bag + name='Comments' + + table='Comments' + lazy='true' + cascade='all-delete-orphan' + inverse='true'> + + <key + column='comment_postid' /> + <one-to-many + class='Comment' /> + </bag> + <set name='Categories' + table='PostsCategories'> + <key column='post_id'/> + <many-to-many class='Category' + column='category_id'/> + </set> + </class> + <class name='Category' + table='Categories'> + <id + name='CategoryId' + column='category_id' + unsaved-value='0'> + <generator + class='native' /> + </id> + <property name='Name'/> + <set name='Posts' inverse='true' + table='PostsCategories'> + <key column='category_id'/> + <many-to-many class='Post' + column='post_id'/> + </set> + </class> + <class + name='Comment' + table='Comments'> + <id + name='CommentId' + column='comment_id' + unsaved-value='0'> + <generator + class='native' /> + </id> + <property + name='Text' + type='string' + column='comment_text' /> + + <property + name='IndexInPost' + column='comment_post_index' /> + <many-to-one + name='Post' + + class='Post' + column='comment_postid' /> + <many-to-one + name='Commenter' + class='User' + column='user_id' /> + </class> +</hibernate-mapping> \ No newline at end of file Added: trunk/nhibernate/src/NHibernate.ByteCode.Castle.Tests/TestCase.cs =================================================================== --- trunk/nhibernate/src/NHibernate.ByteCode.Castle.Tests/TestCase.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.ByteCode.Castle.Tests/TestCase.cs 2008-11-07 22:32:55 UTC (rev 3894) @@ -0,0 +1,323 @@ +using System; +using System.Collections; +using System.Data; +using System.Reflection; +using log4net; +using log4net.Config; +using NHibernate.Cfg; +using NHibernate.Connection; +using NHibernate.Engine; +using NHibernate.Mapping; +using NHibernate.Tool.hbm2ddl; +using NHibernate.Type; +using NUnit.Framework; + +namespace NHibernate.ByteCode.Castle.Tests +{ + public abstract class TestCase + { + private const bool OutputDdl = false; + protected Configuration cfg; + protected ISessionFactoryImplementor sessions; + + private static readonly ILog log = LogManager.GetLogger(typeof(TestCase)); + + protected Dialect.Dialect Dialect + { + get { return NHibernate.Dialect.Dialect.GetDialect(cfg.Properties); } + } + + protected ISession lastOpenedSession; + private DebugConnectionProvider connectionProvider; + + /// <summary> + /// Mapping files used in the TestCase + /// </summary> + protected abstract IList Mappings { get; } + + /// <summary> + /// Assembly to load mapping files from (default is NHibernate.DomainModel). + /// </summary> + protected virtual string MappingsAssembly + { + get { return typeof(TestCase).Namespace; } + } + + static TestCase() + { + // Configure log4net here since configuration through an attribute doesn't always work. + XmlConfigurator.Configure(); + } + + /// <summary> + /// Creates the tables used in this TestCase + /// </summary> + [TestFixtureSetUp] + public void TestFixtureSetUp() + { + try + { + Configure(); + if (!AppliesTo(Dialect)) + { + Assert.Ignore(GetType() + " does not apply to " + Dialect); + } + + CreateSchema(); + BuildSessionFactory(); + } + catch (Exception e) + { + log.Error("Error while setting up the test fixture", e); + throw; + } + } + + /// <summary> + /// Removes the tables used in this TestCase. + /// </summary> + /// <remarks> + /// If the tables are not cleaned up sometimes SchemaExport runs into + /// Sql errors because it can't drop tables because of the FKs. This + /// will occur if the TestCase does not have the same hbm.xml files + /// included as a previous one. + /// </remarks> + [TestFixtureTearDown] + public void TestFixtureTearDown() + { + DropSchema(); + Cleanup(); + } + + protected virtual void OnSetUp() + { + } + + /// <summary> + /// Set up the test. This method is not overridable, but it calls + /// <see cref="OnSetUp" /> which is. + /// </summary> + [SetUp] + public void SetUp() + { + OnSetUp(); + } + + protected virtual void OnTearDown() + { + } + + /// <summary> + /// Checks that the test case cleans up after itself. This method + /// is not overridable, but it calls <see cref="OnTearDown" /> which is. + /// </summary> + [TearDown] + public void TearDown() + { + OnTearDown(); + + bool wasClosed = CheckSessionWasClosed(); + bool wasCleaned = CheckDatabaseWasCleaned(); + bool wereConnectionsClosed = CheckConnectionsWereClosed(); + bool fail = !wasClosed || !wasCleaned || !wereConnectionsClosed; + + if (fail) + { + Assert.Fail("Test didn't clean up after itself"); + } + } + + private bool CheckSessionWasClosed() + { + if (lastOpenedSession != null && lastOpenedSession.IsOpen) + { + log.Error("Test case didn't close a session, closing"); + lastOpenedSession.Close(); + return false; + } + + return true; + } + + private bool CheckDatabaseWasCleaned() + { + if (sessions.GetAllClassMetadata().Count == 0) + { + // Return early in the case of no mappings, also avoiding + // a warning when executing the HQL below. + return true; + } + + bool empty; + using (ISession s = sessions.OpenSession()) + { + IList objects = s.CreateQuery("from System.Object o").List(); + empty = objects.Count == 0; + } + + if (!empty) + { + log.Error("Test case didn't clean up the database after itself, re-creating the schema"); + DropSchema(); + CreateSchema(); + } + + return empty; + } + + private bool CheckConnectionsWereClosed() + { + if (connectionProvider == null || !connectionProvider.HasOpenConnections) + { + return true; + } + + log.Error("Test case didn't close all open connections, closing"); + connectionProvider.CloseAllConnections(); + return false; + } + + private void Configure() + { + cfg = new Configuration(); + if (TestConfigurationHelper.hibernateConfigFile != null) + cfg.Configure(TestConfigurationHelper.hibernateConfigFile); + + Assembly assembly = Assembly.Load(MappingsAssembly); + + foreach (string file in Mappings) + { + cfg.AddResource(MappingsAssembly + "." + file, assembly); + } + + Configure(cfg); + + ApplyCacheSettings(cfg); + } + + private void CreateSchema() + { + new SchemaExport(cfg).Create(OutputDdl, true); + } + + private void DropSchema() + { + new SchemaExport(cfg).Drop(OutputDdl, true); + } + + protected virtual void BuildSessionFactory() + { + sessions = (ISessionFactoryImplementor)cfg.BuildSessionFactory(); + connectionProvider = sessions.ConnectionProvider as DebugConnectionProvider; + } + + private void Cleanup() + { + sessions.Close(); + sessions = null; + connectionProvider = null; + lastOpenedSession = null; + cfg = null; + } + + public int ExecuteStatement(string sql) + { + if (cfg == null) + { + cfg = new Configuration(); + } + + using (IConnectionProvider prov = ConnectionProviderFactory.NewConnectionProvider(cfg.Properties)) + { + IDbConnection conn = prov.GetConnection(); + + try + { + using (IDbTransaction tran = conn.BeginTransaction()) + using (IDbCommand comm = conn.CreateCommand()) + { + comm.CommandText = sql; + comm.Transaction = tran; + comm.CommandType = CommandType.Text; + int result = comm.ExecuteNonQuery(); + tran.Commit(); + return result; + } + } + finally + { + prov.CloseConnection(conn); + } + } + } + + protected ISessionFactoryImplementor Sfi + { + get { return sessions; } + } + + protected virtual ISession OpenSession() + { + lastOpenedSession = sessions.OpenSession(); + return lastOpenedSession; + } + + protected virtual ISession OpenSession(IInterceptor sessionLocalInterceptor) + { + lastOpenedSession = sessions.OpenSession(sessionLocalInterceptor); + return lastOpenedSession; + } + + protected void ApplyCacheSettings(Configuration configuration) + { + if (CacheConcurrencyStrategy == null) + { + return; + } + + foreach (PersistentClass clazz in configuration.ClassMappings) + { + bool hasLob = false; + foreach (Property prop in clazz.PropertyClosureIterator) + { + if (prop.Value.IsSimpleValue) + { + IType type = ((SimpleValue)prop.Value).Type; + if (type == NHibernateUtil.BinaryBlob) + { + hasLob = true; + } + } + } + if (!hasLob && !clazz.IsInherited) + { + configuration.SetCacheConcurrencyStrategy(clazz.EntityName, CacheConcurrencyStrategy); + } + } + + foreach (Mapping.Collection coll in configuration.CollectionMappings) + { + configuration.SetCollectionCacheConcurrencyStrategy(coll.Role, CacheConcurrencyStrategy); + } + } + + #region Properties overridable by subclasses + + protected virtual bool AppliesTo(Dialect.Dialect dialect) + { + return true; + } + + protected virtual void Configure(Configuration configuration) + { + } + + protected virtual string CacheConcurrencyStrategy + { + get { return "nonstrict-read-write"; } + //get { return null; } + } + + #endregion + } +} \ No newline at end of file Added: trunk/nhibernate/src/NHibernate.ByteCode.Castle.Tests/TestConfigurationHelper.cs =================================================================== --- trunk/nhibernate/src/NHibernate.ByteCode.Castle.Tests/TestConfigurationHelper.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.ByteCode.Castle.Tests/TestConfigurationHelper.cs 2008-11-07 22:32:55 UTC (rev 3894) @@ -0,0 +1,40 @@ +using System; +using System.IO; +using NHibernate.Cfg; + +namespace NHibernate.ByteCode.Castle.Tests +{ + public static class TestConfigurationHelper + { + public static readonly string hibernateConfigFile; + + static TestConfigurationHelper() + { + // Verify if hibernate.cfg.xml exists + hibernateConfigFile = GetDefaultConfigurationFilePath(); + } + + public static string GetDefaultConfigurationFilePath() + { + string baseDir = AppDomain.CurrentDomain.BaseDirectory; + string relativeSearchPath = AppDo... [truncated message content] |