-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
applied Dan Jasek's patch for AR-297
- Loading branch information
1 parent
fbe2f25
commit e5aca61
Showing
16 changed files
with
239 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
Castle.ActiveRecord.Tests/Model/ObjectWithLazyAssociation.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright 2004-2010 Castle Project - http://www.castleproject.org/ | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
namespace Castle.ActiveRecord.Tests.Model { | ||
[ActiveRecord] | ||
public class ObjectWithLazyAssociation { | ||
private int id; | ||
private VeryLazyObject lazyObj; | ||
|
||
[PrimaryKey] | ||
public int Id { | ||
get { return id; } | ||
set { id = value; } | ||
} | ||
|
||
[BelongsTo(Lazy = FetchWhen.OnInvoke)] | ||
public VeryLazyObject LazyObj { | ||
get { return lazyObj; } | ||
set { lazyObj = value; } | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright 2004-2010 Castle Project - http://www.castleproject.org/ | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
using System; | ||
using System.Reflection; | ||
using NHibernate; | ||
using NHibernate.Engine; | ||
using NHibernate.Type; | ||
|
||
namespace Castle.ActiveRecord.ByteCode | ||
{ | ||
class LazyInitializer : NHibernate.ByteCode.Castle.LazyInitializer | ||
{ | ||
public LazyInitializer(string entityName, Type persistentClass, object id, | ||
MethodInfo getIdentifierMethod, MethodInfo setIdentifierMethod, | ||
IAbstractComponentType componentIdType, ISessionImplementor session) : | ||
base(entityName, persistentClass, id, getIdentifierMethod, setIdentifierMethod, componentIdType, session) { } | ||
|
||
/// <summary> | ||
/// Perform an ImmediateLoad of the actual object for the Proxy. | ||
/// </summary> | ||
public override void Initialize() { | ||
ISession newSession = null; | ||
try | ||
{ | ||
//If the session has been disconnected, reconnect before continuing with the initialization. | ||
if (Session == null || !Session.IsOpen || !Session.IsConnected) { | ||
newSession = ActiveRecordMediator.GetSessionFactoryHolder().CreateSession(PersistentClass); | ||
Session = newSession.GetSessionImplementation(); | ||
} | ||
base.Initialize(); | ||
} | ||
finally | ||
{ | ||
if (newSession != null) ActiveRecordMediator.GetSessionFactoryHolder().ReleaseSession(newSession); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// Copyright 2004-2010 Castle Project - http://www.castleproject.org/ | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
using System; | ||
using Castle.DynamicProxy; | ||
using NHibernate; | ||
using NHibernate.ByteCode.Castle; | ||
using NHibernate.Engine; | ||
using NHibernate.Proxy; | ||
|
||
namespace Castle.ActiveRecord.ByteCode | ||
{ | ||
class ProxyFactory : AbstractProxyFactory | ||
{ | ||
|
||
protected static readonly IInternalLogger log = LoggerProvider.LoggerFor(typeof(ProxyFactory)); | ||
private static readonly ProxyGenerator ProxyGenerator = new ProxyGenerator(); | ||
|
||
protected static ProxyGenerator DefaultProxyGenerator | ||
{ | ||
get { return ProxyGenerator; } | ||
} | ||
|
||
/// <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 override 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); | ||
} | ||
} | ||
|
||
public override object GetFieldInterceptionProxy() | ||
{ | ||
var proxyGenerationOptions = new ProxyGenerationOptions(); | ||
var interceptor = new LazyFieldInterceptor(); | ||
proxyGenerationOptions.AddMixinInstance(interceptor); | ||
return ProxyGenerator.CreateClassProxy(PersistentClass, proxyGenerationOptions, interceptor); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright 2004-2010 Castle Project - http://www.castleproject.org/ | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
using NHibernate.Bytecode; | ||
using NHibernate.Proxy; | ||
|
||
namespace Castle.ActiveRecord.ByteCode | ||
{ | ||
/// <summary> | ||
/// The factory infrastructure used to build AR proxy objects. | ||
/// Use this one if you want automatic session management durring proxy hydration. | ||
/// </summary> | ||
public class ProxyFactoryFactory : IProxyFactoryFactory | ||
{ | ||
|
||
public IProxyFactory BuildProxyFactory() | ||
{ | ||
return new ProxyFactory(); | ||
} | ||
|
||
public IProxyValidator ProxyValidator | ||
{ | ||
get { return new DynProxyTypeValidator(); } | ||
} | ||
|
||
public bool IsInstrumented(System.Type entityClass) | ||
{ | ||
return true; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.