|
From: <fab...@us...> - 2009-03-03 19:55:10
|
Revision: 4106
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4106&view=rev
Author: fabiomaulo
Date: 2009-03-03 19:55:08 +0000 (Tue, 03 Mar 2009)
Log Message:
-----------
ByteCode provider of Spring.NET
Modified Paths:
--------------
trunk/nhibernate/default.build
trunk/nhibernate/src/NHibernate.Everything.sln
Added Paths:
-----------
trunk/nhibernate/src/NHibernate.ByteCode.Spring/
trunk/nhibernate/src/NHibernate.ByteCode.Spring/AbstractProxyFactory.cs
trunk/nhibernate/src/NHibernate.ByteCode.Spring/ByteCode.build
trunk/nhibernate/src/NHibernate.ByteCode.Spring/LazyInitializer.cs
trunk/nhibernate/src/NHibernate.ByteCode.Spring/NHibernate.ByteCode.Spring.csproj
trunk/nhibernate/src/NHibernate.ByteCode.Spring/Properties/
trunk/nhibernate/src/NHibernate.ByteCode.Spring/ProxyFactory.cs
trunk/nhibernate/src/NHibernate.ByteCode.Spring/ProxyFactoryFactory.cs
trunk/nhibernate/src/NHibernate.ByteCode.Spring.Tests/
trunk/nhibernate/src/NHibernate.ByteCode.Spring.Tests/App.config
trunk/nhibernate/src/NHibernate.ByteCode.Spring.Tests/ByteCode.Test.build
trunk/nhibernate/src/NHibernate.ByteCode.Spring.Tests/DebugConnectionProvider.cs
trunk/nhibernate/src/NHibernate.ByteCode.Spring.Tests/NHibernate.ByteCode.Spring.Tests.csproj
trunk/nhibernate/src/NHibernate.ByteCode.Spring.Tests/Properties/
trunk/nhibernate/src/NHibernate.ByteCode.Spring.Tests/ProxyInterface/
trunk/nhibernate/src/NHibernate.ByteCode.Spring.Tests/ProxyInterface/IMyProxy.cs
trunk/nhibernate/src/NHibernate.ByteCode.Spring.Tests/ProxyInterface/MyProxyImpl.cs
trunk/nhibernate/src/NHibernate.ByteCode.Spring.Tests/ProxyInterface/ProxyFixture.cs
trunk/nhibernate/src/NHibernate.ByteCode.Spring.Tests/ProxyInterface/ProxyImpl.hbm.xml
trunk/nhibernate/src/NHibernate.ByteCode.Spring.Tests/TestCase.cs
trunk/nhibernate/src/NHibernate.ByteCode.Spring.Tests/TestConfigurationHelper.cs
Modified: trunk/nhibernate/default.build
===================================================================
--- trunk/nhibernate/default.build 2009-03-03 07:06:19 UTC (rev 4105)
+++ trunk/nhibernate/default.build 2009-03-03 19:55:08 UTC (rev 4106)
@@ -30,6 +30,8 @@
<include name="NHibernate.ByteCode.LinFu.Tests/ByteCode.Test.build" />
<include name="NHibernate.ByteCode.Castle/ByteCode.build" />
<include name="NHibernate.ByteCode.Castle.Tests/ByteCode.Test.build" />
+ <include name="NHibernate.ByteCode.Spring/ByteCode.build" />
+ <include name="NHibernate.ByteCode.Spring.Tests/ByteCode.Test.build" />
<include name="NHibernate.DomainModel/NHibernate.DomainModel.build" />
<include name="NHibernate.Test/NHibernate.Test.build" />
<include name="NHibernate.Test.Performance/NHibernate.Test.Performance.build" />
@@ -41,6 +43,7 @@
<include name="Iesi.Collections.Test/Iesi.Collections.Test.build" />
<include name="NHibernate.ByteCode.LinFu.Tests/ByteCode.Test.build" />
<include name="NHibernate.ByteCode.Castle.Tests/ByteCode.Test.build" />
+ <include name="NHibernate.ByteCode.Spring.Tests/ByteCode.Test.build" />
<include name="NHibernate.Test/NHibernate.Test.build" />
<include name="NHibernate.Test.Performance/NHibernate.Test.Performance.build"
if="${run.performance.tests}" />
@@ -89,10 +92,12 @@
-->
<exclude name="Iesi.Collections.dll" />
<exclude name="Iesi.Collections.xml" />
- <exclude name="NHibernate.ByteCode.LinFuDynamicProxy.dll" />
- <exclude name="NHibernate.ByteCode.LinFuDynamicProxy.xml" />
- <exclude name="NHibernate.ByteCode.CastleDynamicProxy.dll" />
- <exclude name="NHibernate.ByteCode.CastleDynamicProxy.xml" />
+ <exclude name="NHibernate.ByteCode.LinFu.dll" />
+ <exclude name="NHibernate.ByteCode.LinFu.xml" />
+ <exclude name="NHibernate.ByteCode.Castle.dll" />
+ <exclude name="NHibernate.ByteCode.Castle.xml" />
+ <exclude name="NHibernate.ByteCode.Spring.dll" />
+ <exclude name="NHibernate.ByteCode.Spring.xml" />
<include name="*.dll" />
<include name="*.xml" />
<include name="*.license.txt" />
Property changes on: trunk/nhibernate/src/NHibernate.ByteCode.Spring
___________________________________________________________________
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.Spring/AbstractProxyFactory.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.ByteCode.Spring/AbstractProxyFactory.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.ByteCode.Spring/AbstractProxyFactory.cs 2009-03-03 19:55:08 UTC (rev 4106)
@@ -0,0 +1,51 @@
+using System.Reflection;
+using Common.Logging;
+using Iesi.Collections.Generic;
+using NHibernate.Engine;
+using NHibernate.Proxy;
+using NHibernate.Type;
+
+namespace NHibernate.ByteCode.Spring
+{
+ /// <summary>
+ /// Convenience base class for <see cref="IProxyFactory"/> implementations,
+ /// providing common functionality.
+ /// </summary>
+ /// <author>Erich Eichinger (Spring.NET Team)</author>
+ public abstract class AbstractProxyFactory : IProxyFactory
+ {
+ protected readonly ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
+
+ protected string EntityName { get; private set; }
+ protected System.Type PersistentClass { get; private set; }
+ protected System.Type[] Interfaces { get; private set; }
+ protected MethodInfo GetIdentifierMethod { get; private set; }
+ protected MethodInfo SetIdentifierMethod { get; private set; }
+ protected IAbstractComponentType ComponentIdType { get; private set; }
+
+ protected bool IsClassProxy
+ {
+ get { return Interfaces.Length == 1; }
+ }
+
+ 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];
+
+ if (interfaces.Count > 0)
+ {
+ interfaces.CopyTo(Interfaces, 0);
+ }
+
+ GetIdentifierMethod = getIdentifierMethod;
+ SetIdentifierMethod = setIdentifierMethod;
+ ComponentIdType = componentIdType;
+ }
+
+ public abstract INHibernateProxy GetProxy(object id, ISessionImplementor session);
+ }
+}
\ No newline at end of file
Added: trunk/nhibernate/src/NHibernate.ByteCode.Spring/ByteCode.build
===================================================================
(Binary files differ)
Property changes on: trunk/nhibernate/src/NHibernate.ByteCode.Spring/ByteCode.build
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: trunk/nhibernate/src/NHibernate.ByteCode.Spring/LazyInitializer.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.ByteCode.Spring/LazyInitializer.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.ByteCode.Spring/LazyInitializer.cs 2009-03-03 19:55:08 UTC (rev 4106)
@@ -0,0 +1,105 @@
+using System;
+using System.Reflection;
+using AopAlliance.Intercept;
+using NHibernate.Engine;
+using NHibernate.Proxy.Poco;
+using NHibernate.Type;
+using Spring.Aop;
+using Spring.Reflection.Dynamic;
+
+namespace NHibernate.ByteCode.Spring
+{
+ [Serializable]
+ public class LazyInitializer : BasicLazyInitializer, IMethodInterceptor, ITargetSource
+ {
+ private static readonly object NULL = new object();
+
+ private static readonly MethodInfo exceptionInternalPreserveStackTrace =
+ typeof (Exception).GetMethod("InternalPreserveStackTrace", BindingFlags.Instance | BindingFlags.NonPublic);
+
+ private static MethodInfo MapInterfaceMethodToImplementationIfNecessary(MethodInfo methodInfo,
+ System.Type implementingType)
+ {
+ MethodInfo concreteMethodInfo = methodInfo;
+
+ if (methodInfo!= null && methodInfo.DeclaringType.IsInterface)
+ {
+ InterfaceMapping interfaceMapping = implementingType.GetInterfaceMap(methodInfo.DeclaringType);
+ int methodIndex = Array.IndexOf(interfaceMapping.InterfaceMethods, methodInfo);
+ concreteMethodInfo = interfaceMapping.TargetMethods[methodIndex];
+ }
+
+ return concreteMethodInfo;
+ }
+
+ public LazyInitializer(string entityName, System.Type persistentClass, object id, MethodInfo getIdentifierMethod,
+ MethodInfo setIdentifierMethod, IAbstractComponentType componentIdType,
+ ISessionImplementor session)
+ : base(
+ entityName, persistentClass, id, MapInterfaceMethodToImplementationIfNecessary(getIdentifierMethod, persistentClass),
+ MapInterfaceMethodToImplementationIfNecessary(setIdentifierMethod, persistentClass), componentIdType, session)
+ {
+ InterceptCalls = true;
+ }
+
+ public bool InterceptCalls { get; set; }
+
+ #region Implementation of IInterceptor
+
+ public object Invoke(IMethodInvocation info)
+ {
+ object returnValue;
+ try
+ {
+ returnValue = base.Invoke(info.Method, info.Arguments, info.Target);
+
+ if (returnValue != InvokeImplementation)
+ {
+ return returnValue;
+ }
+ if (InterceptCalls)
+ {
+ var method = new SafeMethod(info.Method);
+ return method.Invoke(GetImplementation(), info.Arguments);
+ }
+ }
+ catch (TargetInvocationException ex)
+ {
+ exceptionInternalPreserveStackTrace.Invoke(ex.InnerException, new Object[] { });
+ throw ex.InnerException;
+ }
+
+ return returnValue;
+ }
+
+ #endregion
+
+ #region Implementation of ITargetSource
+
+ object ITargetSource.GetTarget()
+ {
+ if (!IsUninitialized)
+ {
+ return Target;
+ }
+ return NULL;
+ }
+
+ void ITargetSource.ReleaseTarget(object target)
+ {
+ //throw new System.NotImplementedException();
+ }
+
+ System.Type ITargetSource.TargetType
+ {
+ get { return base.PersistentClass; }
+ }
+
+ bool ITargetSource.IsStatic
+ {
+ get { return false; }
+ }
+
+ #endregion
+ }
+}
\ No newline at end of file
Added: trunk/nhibernate/src/NHibernate.ByteCode.Spring/NHibernate.ByteCode.Spring.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate.ByteCode.Spring/NHibernate.ByteCode.Spring.csproj (rev 0)
+++ trunk/nhibernate/src/NHibernate.ByteCode.Spring/NHibernate.ByteCode.Spring.csproj 2009-03-03 19:55:08 UTC (rev 4106)
@@ -0,0 +1,92 @@
+<?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>{946BCA10-109A-4472-8521-76616174AD4D}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>NHibernate.ByteCode.Spring</RootNamespace>
+ <AssemblyName>NHibernate.ByteCode.Spring</AssemblyName>
+ <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
+ <FileAlignment>512</FileAlignment>
+ <TargetFrameworkSubset>
+ </TargetFrameworkSubset>
+ </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="antlr.runtime, Version=2.7.6.2, Culture=neutral, PublicKeyToken=65e474d141e25e07, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\..\lib\net\3.5\antlr.runtime.dll</HintPath>
+ </Reference>
+ <Reference Include="Common.Logging, Version=1.2.0.0, Culture=neutral, PublicKeyToken=af08829b84f0328e">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\..\lib\net\3.5\Common.Logging.dll</HintPath>
+ </Reference>
+ <Reference Include="Iesi.Collections, Version=1.0.1.0, Culture=neutral, PublicKeyToken=aa95f207798dfdb4, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\..\lib\net\3.5\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\3.5\log4net.dll</HintPath>
+ </Reference>
+ <Reference Include="Spring.Aop, Version=1.2.0.20001, Culture=neutral, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\..\lib\net\3.5\Spring.Aop.dll</HintPath>
+ </Reference>
+ <Reference Include="Spring.Core, Version=1.2.0.20001, Culture=neutral, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\..\lib\net\3.5\Spring.Core.dll</HintPath>
+ </Reference>
+ <Reference Include="System" />
+ <Reference Include="System.Core">
+ <RequiredTargetFramework>3.5</RequiredTargetFramework>
+ </Reference>
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="AbstractProxyFactory.cs" />
+ <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.Spring/Properties
___________________________________________________________________
Added: bugtraq:url
+ http://jira.nhibernate.org/browse/%BUGID%
Added: bugtraq:logregex
+ NH-\d+
Added: trunk/nhibernate/src/NHibernate.ByteCode.Spring/ProxyFactory.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.ByteCode.Spring/ProxyFactory.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.ByteCode.Spring/ProxyFactory.cs 2009-03-03 19:55:08 UTC (rev 4106)
@@ -0,0 +1,55 @@
+using System;
+using NHibernate.Engine;
+using NHibernate.Proxy;
+
+namespace NHibernate.ByteCode.Spring
+{
+ /// <summary>
+ /// A Spring for .NET backed <see cref="IProxyFactory"/> implementation for creating
+ /// NHibernate proxies.
+ /// </summary>
+ /// <seealso cref="ProxyFactoryFactory"/>
+ /// <author>Erich Eichinger (Spring.NET Team)</author>
+ public class ProxyFactory : AbstractProxyFactory
+ {
+ [Serializable]
+ private class SerializableProxyFactory : global::Spring.Aop.Framework.ProxyFactory
+ {
+ // ensure proxy types are generated as Serializable
+ public override bool IsSerializable
+ {
+ get { return true; }
+ }
+ }
+
+ #region IProxyFactory Members
+
+ public override INHibernateProxy GetProxy(object id, ISessionImplementor session)
+ {
+ try
+ {
+ var initializer = new LazyInitializer(EntityName, PersistentClass, id, GetIdentifierMethod, SetIdentifierMethod,
+ ComponentIdType, session);
+
+ var proxyFactory = new SerializableProxyFactory();
+ proxyFactory.Interfaces = Interfaces;
+ proxyFactory.TargetSource = initializer;
+ proxyFactory.ProxyTargetType = IsClassProxy;
+ proxyFactory.AddAdvice(initializer);
+
+ object proxyInstance = proxyFactory.GetProxy();
+
+ initializer.InterceptCalls = true;
+
+ return (INHibernateProxy) proxyInstance;
+ }
+ catch (Exception ex)
+ {
+ log.Error("Creating a proxy instance failed", ex);
+ throw new HibernateException("Creating a proxy instance failed", ex);
+ }
+ }
+
+ #endregion
+ }
+}
\ No newline at end of file
Added: trunk/nhibernate/src/NHibernate.ByteCode.Spring/ProxyFactoryFactory.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.ByteCode.Spring/ProxyFactoryFactory.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.ByteCode.Spring/ProxyFactoryFactory.cs 2009-03-03 19:55:08 UTC (rev 4106)
@@ -0,0 +1,30 @@
+using NHibernate.Bytecode;
+using NHibernate.Proxy;
+
+namespace NHibernate.ByteCode.Spring
+{
+ /// <summary>
+ /// Creates a Spring for .NET backed <see cref="IProxyFactory"/> instance.
+ /// </summary>
+ /// <remarks>
+ /// TODO: mention how to configure
+ /// </remarks>
+ /// <author>Erich Eichinger</author>
+ public class ProxyFactoryFactory : IProxyFactoryFactory
+ {
+ #region IProxyFactoryFactory Members
+
+ public IProxyFactory BuildProxyFactory()
+ {
+ return new ProxyFactory();
+ }
+
+ public IProxyValidator ProxyValidator
+ {
+ // TODO : check what this validator does?
+ get { return new DynProxyTypeValidator(); }
+ }
+
+ #endregion
+ }
+}
\ No newline at end of file
Property changes on: trunk/nhibernate/src/NHibernate.ByteCode.Spring.Tests
___________________________________________________________________
Added: bugtraq:url
+ http://jira.nhibernate.org/browse/%BUGID%
Added: svn:ignore
+ obj
.#*
*.user
*.xsx
*.aps
*.eto
[Bb]in
[Dd]ebug
[Rr]elease
*resharper*
AssemblyInfo.cs
hibernate.cfg.xml
Added: bugtraq:logregex
+ NH-\d+
Added: trunk/nhibernate/src/NHibernate.ByteCode.Spring.Tests/App.config
===================================================================
--- trunk/nhibernate/src/NHibernate.ByteCode.Spring.Tests/App.config (rev 0)
+++ trunk/nhibernate/src/NHibernate.ByteCode.Spring.Tests/App.config 2009-03-03 19:55:08 UTC (rev 4106)
@@ -0,0 +1,84 @@
+<?xml version="1.0"?>
+<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.Spring.Tests.DebugConnectionProvider, NHibernate.ByteCode.Spring.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>
+
+ <property name="proxyfactory.factory_class">NHibernate.ByteCode.Spring.ProxyFactoryFactory, NHibernate.ByteCode.Spring</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.Proxy.Poco">
+ <priority value="DEBUG"/>
+ </logger>
+
+ <logger name="NHibernate.ByteCode.Spring">
+ <priority value="DEBUG"/>
+ </logger>
+ </log4net>
+
+
+<startup><supportedRuntime version="v2.0.50727"/></startup></configuration>
Added: trunk/nhibernate/src/NHibernate.ByteCode.Spring.Tests/ByteCode.Test.build
===================================================================
--- trunk/nhibernate/src/NHibernate.ByteCode.Spring.Tests/ByteCode.Test.build (rev 0)
+++ trunk/nhibernate/src/NHibernate.ByteCode.Spring.Tests/ByteCode.Test.build 2009-03-03 19:55:08 UTC (rev 4106)
@@ -0,0 +1,47 @@
+<?xml version="1.0" ?>
+
+<project
+ name="NHibernate.ByteCode.Spring.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 Spring ByteCode." />
+ <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="System.Core.dll" />
+ <include name="Common.Logging.dll" />
+ <include name="Iesi.Collections.dll" />
+ <include name="log4net.dll" />
+ <include name="antlr.runtime.dll" />
+ <include name="Spring.Aop.dll" />
+ <include name="Spring.Core.dll" />
+ <include name="NHibernate.dll" />
+ <include name="NHibernate.ByteCode.Spring.dll" />
+ <include name="nunit.framework.dll"/>
+ </assemblyfileset>
+
+ <resourcefileset id="project.resources" prefix="NHibernate.ByteCode.Spring.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.Spring.Tests/DebugConnectionProvider.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.ByteCode.Spring.Tests/DebugConnectionProvider.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.ByteCode.Spring.Tests/DebugConnectionProvider.cs 2009-03-03 19:55:08 UTC (rev 4106)
@@ -0,0 +1,68 @@
+using System.Collections;
+using System.Data;
+using Iesi.Collections;
+using NHibernate.Connection;
+
+namespace NHibernate.ByteCode.Spring.Tests
+{
+ 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.Spring.Tests/NHibernate.ByteCode.Spring.Tests.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate.ByteCode.Spring.Tests/NHibernate.ByteCode.Spring.Tests.csproj (rev 0)
+++ trunk/nhibernate/src/NHibernate.ByteCode.Spring.Tests/NHibernate.ByteCode.Spring.Tests.csproj 2009-03-03 19:55:08 UTC (rev 4106)
@@ -0,0 +1,112 @@
+<?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>{7EFC4549-3761-4B68-B81F-12AA51D78E92}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>NHibernate.ByteCode.Spring.Tests</RootNamespace>
+ <AssemblyName>NHibernate.ByteCode.Spring.Tests</AssemblyName>
+ <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
+ <FileAlignment>512</FileAlignment>
+ <TargetFrameworkSubset>
+ </TargetFrameworkSubset>
+ </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="antlr.runtime, Version=2.7.6.2, Culture=neutral, PublicKeyToken=65e474d141e25e07, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\..\lib\net\3.5\antlr.runtime.dll</HintPath>
+ </Reference>
+ <Reference Include="Common.Logging, Version=1.2.0.0, Culture=neutral, PublicKeyToken=af08829b84f0328e">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\..\lib\net\3.5\Common.Logging.dll</HintPath>
+ </Reference>
+ <Reference Include="Iesi.Collections, Version=1.0.1.0, Culture=neutral, PublicKeyToken=aa95f207798dfdb4, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\..\lib\net\3.5\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\3.5\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\3.5\nunit.framework.dll</HintPath>
+ </Reference>
+ <Reference Include="Spring.Aop, Version=1.2.0.20001, Culture=neutral, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\..\lib\net\3.5\Spring.Aop.dll</HintPath>
+ </Reference>
+ <Reference Include="Spring.Core, Version=1.2.0.20001, Culture=neutral, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\..\lib\net\3.5\Spring.Core.dll</HintPath>
+ </Reference>
+ <Reference Include="System" />
+ <Reference Include="System.Core">
+ <RequiredTargetFramework>3.5</RequiredTargetFramework>
+ </Reference>
+ <Reference Include="System.Data" />
+ <Reference Include="System.XML" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="AssemblyInfo.cs" />
+ <Compile Include="DebugConnectionProvider.cs" />
+ <Compile Include="ProxyInterface\IMyProxy.cs" />
+ <Compile Include="ProxyInterface\MyProxyImpl.cs" />
+ <Compile Include="ProxyInterface\ProxyFixture.cs" />
+ <Compile Include="TestCase.cs" />
+ <Compile Include="TestConfigurationHelper.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <EmbeddedResource Include="ProxyInterface\ProxyImpl.hbm.xml" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="App.config" />
+ <None Include="ByteCode.Test.build" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\NHibernate.ByteCode.Spring\NHibernate.ByteCode.Spring.csproj">
+ <Project>{946BCA10-109A-4472-8521-76616174AD4D}</Project>
+ <Name>NHibernate.ByteCode.Spring</Name>
+ </ProjectReference>
+ <ProjectReference Include="..\NHibernate\NHibernate.csproj">
+ <Project>{5909BFE7-93CF-4E5F-BE22-6293368AF01D}</Project>
+ <Name>NHibernate</Name>
+ </ProjectReference>
+ </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.Spring.Tests/Properties
___________________________________________________________________
Added: bugtraq:url
+ http://jira.nhibernate.org/browse/%BUGID%
Added: bugtraq:logregex
+ NH-\d+
Property changes on: trunk/nhibernate/src/NHibernate.ByteCode.Spring.Tests/ProxyInterface
___________________________________________________________________
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.Spring.Tests/ProxyInterface/IMyProxy.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.ByteCode.Spring.Tests/ProxyInterface/IMyProxy.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.ByteCode.Spring.Tests/ProxyInterface/IMyProxy.cs 2009-03-03 19:55:08 UTC (rev 4106)
@@ -0,0 +1,11 @@
+namespace NHibernate.ByteCode.Spring.Tests.ProxyInterface
+{
+ public interface IMyProxy
+ {
+ int Id { get; set; }
+
+ string Name { get; set; }
+
+ void ThrowDeepException();
+ }
+}
\ No newline at end of file
Added: trunk/nhibernate/src/NHibernate.ByteCode.Spring.Tests/ProxyInterface/MyProxyImpl.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.ByteCode.Spring.Tests/ProxyInterface/MyProxyImpl.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.ByteCode.Spring.Tests/ProxyInterface/MyProxyImpl.cs 2009-03-03 19:55:08 UTC (rev 4106)
@@ -0,0 +1,30 @@
+using System;
+
+namespace NHibernate.ByteCode.Spring.Tests.ProxyInterface
+{
+ public class MyProxyImpl: IMyProxy
+ {
+ private static void Level1()
+ {
+ Level2();
+ }
+
+ private static void Level2()
+ {
+ throw new ArgumentException("thrown from Level2");
+ }
+
+ #region IMyProxy 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.Spring.Tests/ProxyInterface/ProxyFixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.ByteCode.Spring.Tests/ProxyInterface/ProxyFixture.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.ByteCode.Spring.Tests/ProxyInterface/ProxyFixture.cs 2009-03-03 19:55:08 UTC (rev 4106)
@@ -0,0 +1,137 @@
+using System;
+using System.Collections;
+using System.IO;
+using System.Runtime.Serialization;
+using System.Runtime.Serialization.Formatters.Binary;
+using NUnit.Framework;
+
+namespace NHibernate.ByteCode.Spring.Tests.ProxyInterface
+{
+ [TestFixture]
+ public class ProxyFixture : TestCase
+ {
+ protected override IList Mappings
+ {
+ get { return new[] {"ProxyInterface.ProxyImpl.hbm.xml"}; }
+ }
+
+ 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 Proxy()
+ {
+ ISession s = OpenSession();
+ IMyProxy ap = new MyProxyImpl {Id = 1, Name = "first proxy"};
+ s.Save(ap);
+ s.Flush();
+ s.Close();
+
+ s = OpenSession();
+ ap = (IMyProxy) s.Load(typeof (MyProxyImpl), 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();
+ }
+
+ [Test]
+ public void ExceptionStackTrace()
+ {
+ ISession s = OpenSession();
+ IMyProxy ap = new MyProxyImpl {Id = 1, Name = "first proxy"};
+ s.Save(ap);
+ s.Flush();
+ s.Close();
+
+ s = OpenSession();
+ ap = (IMyProxy) s.Load(typeof (MyProxyImpl), 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();
+ }
+ }
+
+ [Test]
+ public void ProxySerialize()
+ {
+ ISession s = OpenSession();
+ IMyProxy ap = new MyProxyImpl {Id = 1, Name = "first proxy"};
+ s.Save(ap);
+ s.Flush();
+ s.Close();
+
+ s = OpenSession();
+ ap = (IMyProxy) s.Load(typeof (MyProxyImpl), 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 = (IMyProxy) s.Load(typeof (MyProxyImpl), 5);
+ Assert.AreEqual(5, notThere.Id);
+ s.Disconnect();
+
+ // serialize and then deserialize the session.
+ SerializeAndDeserialize(ref s);
+
+ Assert.IsNotNull(s.Load(typeof (MyProxyImpl), 5), "should be proxy - even though it doesn't exists in db");
+ s.Close();
+ }
+ }
+}
\ No newline at end of file
Added: trunk/nhibernate/src/NHibernate.ByteCode.Spring.Tests/ProxyInterface/ProxyImpl.hbm.xml
===================================================================
--- trunk/nhibernate/src/NHibernate.ByteCode.Spring.Tests/ProxyInterface/ProxyImpl.hbm.xml (rev 0)
+++ trunk/nhibernate/src/NHibernate.ByteCode.Spring.Tests/ProxyInterface/ProxyImpl.hbm.xml 2009-03-03 19:55:08 UTC (rev 4106)
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
+ assembly="NHibernate.ByteCode.Spring.Tests"
+ namespace="NHibernate.ByteCode.Spring.Tests.ProxyInterface">
+ <class name="MyProxyImpl" proxy="IMyProxy">
+ <id name="Id">
+ <generator class="assigned" />
+ </id>
+
+ <property name="Name" />
+ </class>
+</hibernate-mapping>
\ No newline at end of file
Added: trunk/nhibernate/src/NHibernate.ByteCode.Spring.Tests/TestCase.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.ByteCode.Spring.Tests/TestCase.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.ByteCode.Spring.Tests/TestCase.cs 2009-03-03 19:55:08 UTC (rev 4106)
@@ -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.Spring.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.Spring.Tests/TestConfigurationHelper.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.ByteCode.Spring.Tests/TestConfigurationHelper.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.ByteCode.Spring.Tests/TestConfigurationHelper.cs 2009-03-03 19:55:08 UTC (rev 4106)
@@ -0,0 +1,40 @@
+using System;
+using System.IO;
+using NHibernate.Cfg;
+
+namespace NHibernate.ByteCode.Spring.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 = AppDomain.CurrentDomain.RelativeSearchPath;
+ string binPath = relativeSearchPath == null ? baseDir : Path.Combine(baseDir, relativeSearchPath);
+ string fullPath = Path.Combine(binPath, Configuration.DefaultHibernateCfgFileName);
+ return File.Exists(fullPath) ? fullPath : null;
+ }
+
+ /// <summary>
+ /// Standard Configuration for tests.
+ /// </summary>
+ /// <returns>The configuration using merge between App.Config and hibernate.cfg.xml if present.</returns>
+ public static Configuration GetDefaultConfiguration()
+ {
+ var result = new Configuration();
+ if (hibernateConfigFile != null)
+ {
+ result.Configure(hibernateConfigFile);
+ }
+ return result;
+ }
+ }
+}
\ No newline at end of file
Modified: trunk/nhibernate/src/NHibernate.Everything.sln
===================================================================
--- trunk/nhibernate/src/NHibernate.Everything.sln 2009-03-03 07:06:19 UTC (rev 4105)
+++ trunk/nhibernate/src/NHibernate.Everything.sln 2009-03-03 19:55:08 UTC (rev 4106)
@@ -109,6 +109,10 @@
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NHibernate.ByteCode.LinFu.Tests", "NHibernate.ByteCode.LinFu.Tests\NHibernate.ByteCode.LinFu.Tests.csproj", "{94FDD99B-8275-4E51-8F43-958B2C632120}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NHibernate.ByteCode.Spring", "NHibernate.ByteCode.Spring\NHibernate.ByteCode.Spring.csproj", "{946BCA10-109A-4472-8521-76616174AD4D}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NHibernate.ByteCode.Spring.Tests", "NHibernate.ByteCode.Spring.Tests\NHibernate.ByteCode.Spring.Tests.csproj", "{7EFC4549-3761-4B68-B81F-12AA51D78E92}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|.NET = Debug|.NET
@@ -250,6 +254,26 @@
{94FDD99B-8275-4E51-8F43-958B2C632120}.Release|Any CPU.Build.0 = Release|Any CPU
{94FDD99B-8275-4E51-8F43-958B2C632120}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{94FDD99B-8275-4E51-8F43-958B2C632120}.Release|Mixed Platforms.Build.0 = Release|Any CPU
+ {946BCA10-109A-4472-8521-76616174AD4D}.Debug|.NET.ActiveCfg = Debug|Any CPU
+ {946BCA10-109A-4472-8521-76616174AD4D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {946BCA10-109A-4472-8521-76616174AD4D}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {946BCA10-109A-4472-8521-76616174AD4D}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
+ {946BCA10-109A-4472-8521-76616174AD4D}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
+ {946BCA10-109A-4472-8521-76616174AD4D}.Release|.NET.ActiveCfg = Release|Any CPU
+ {946BCA10-109A-4472-8521-76616174AD4D}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {946BCA10-109A-4472-8521-76616174AD4D}.Release|Any CPU.Build.0 = Release|Any CPU
+ {946BCA10-109A-4472-8521-76616174AD4D}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
+ {946BCA10-109A-4472-8521-76616174AD4D}.Release|Mixed Platforms.Build.0 = Release|Any CPU
+ {7EFC4549-3761-4B68-B81F-12AA51D78E92}.Debug|.NET.ActiveCfg = Debug|Any CPU
+ {7EFC4549-3761-4B68-B81F-12AA51D78E92}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {7EFC4549-3761-4B68-B81F-12AA51D78E92}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {7EFC4549-3761-4B68-B81F-12AA51D78E92}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
+ {7EFC4549-3761-4B68-B81F-12AA51D78E92}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
+ {7EFC4549-3761-4B68-B81F-12AA51D78E92}.Release|.NET.ActiveCfg = Release|Any CPU
+ {7EFC4549-3761-4B68-B81F-12AA51D78E92}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {7EFC4549-3761-4B68-B81F-12AA51D78E92}.Release|Any CPU.Build.0 = Release|Any CPU
+ {7EFC4549-3761-4B68-B81F-12AA51D78E92}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
+ {7EFC4549-3761-4B68-B81F-12AA51D78E92}.Release|Mixed Platforms.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -270,10 +294,12 @@
{446E148D-A9D5-4D7D-A706-BEDD45B2BC7D} = {92509065-DAEA-4457-8300-C7B64CD0E9F4}
{4C251E3E-6EA1-4A51-BBCB-F9C42AE55344} = {C91E7018-3C67-4830-963A-C388C75E1BD5}
{58CE4584-31B9-4E74-A7FB-5D40BFAD0876} = {C91E7018-3C67-4830-963A-C388C75E1BD5}
+ {31C3F0EA-0FED-4A2F-B68D-96CE29844487} = {D2E4E87F-2531-4C7A-BBE9-FE8BFEDECECE}
{4972EE96-2417-4D47-9FF1-3B1D6B1D3191} = {D2E4E87F-2531-4C7A-BBE9-FE8BFEDECECE}
{8289D6AD-9714-42D3-A94D-D4D9814D1281} = {D2E4E87F-2531-4C7A-BBE9-FE8BFEDECECE}
{94FDD99B-8275-4E51-8F43-958B2C632120} = {D2E4E87F-2531-4C7A-BBE9-FE8BFEDECECE}
- {31C3F0EA-0FED-4A2F-B68D-96CE29844487} = {D2E4E87F-2531-4C7A-BBE9-FE8BFEDECECE}
+ {946BCA10-109A-4472-8521-76616174AD4D} = {D2E4E87F-2531-4C7A-BBE9-FE8BFEDECECE}
+ {7EFC4549-3761-4B68-B81F-12AA51D78E92} = {D2E4E87F-2531-4C7A-BBE9-FE8BFEDECECE}
EndGlobalSection
GlobalSection(TextTemplating) = postSolution
TextTemplating = 1
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|