-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- NHibernate helper git-svn-id: https://nhcontrib.svn.sourceforge.net/svnroot/nhcontrib/trunk@1662 d7b3437e-3345-0410-94a8-cbd290e69f67
- Loading branch information
darioquintana
committed
Mar 11, 2011
1 parent
894ce58
commit 194fb85
Showing
12 changed files
with
1,077 additions
and
494 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file modified
BIN
+0 Bytes
(100%)
src/NHibernate.Validator/lib/NHibernate.ByteCode.Castle.dll
Binary file not shown.
Binary file not shown.
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
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
82 changes: 82 additions & 0 deletions
82
src/NHibernate.Validator/src/NHibernate.Validator/Util/NHibernateHelper.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,82 @@ | ||
using NHibernate.Bytecode; | ||
using NHibernate.Collection; | ||
using NHibernate.Intercept; | ||
using NHibernate.Proxy; | ||
|
||
namespace NHibernate.Validator.Util | ||
{ | ||
/// <summary> | ||
/// Ported from NHibernate with changes | ||
/// </summary> | ||
public class NHibernateHelper | ||
{ | ||
public static bool IsPropertyInitialized(object proxy, string propertyName) | ||
{ | ||
object entity; | ||
|
||
if (!IsProxyFactoryConfigurated()) | ||
{ | ||
//if the proxy provider it's not configurated, can't be a proxy neither an instrumented field. | ||
return true; | ||
} | ||
|
||
if (proxy.IsProxy()) | ||
{ | ||
ILazyInitializer li = ((INHibernateProxy)proxy).HibernateLazyInitializer; | ||
if (li.IsUninitialized) | ||
{ | ||
return false; | ||
} | ||
else | ||
{ | ||
entity = li.GetImplementation(); | ||
} | ||
} | ||
else | ||
{ | ||
entity = proxy; | ||
} | ||
|
||
if (FieldInterceptionHelper.IsInstrumented(entity)) | ||
{ | ||
IFieldInterceptor interceptor = FieldInterceptionHelper.ExtractFieldInterceptor(entity); | ||
return interceptor == null || interceptor.IsInitializedField(propertyName); | ||
} | ||
else | ||
{ | ||
return true; | ||
} | ||
} | ||
|
||
public static bool IsInitialized(object proxy) | ||
{ | ||
var noProxyFactory = IsProxyFactoryConfigurated(); | ||
|
||
if (noProxyFactory && proxy.IsProxy()) | ||
{ | ||
return !((INHibernateProxy)proxy).HibernateLazyInitializer.IsUninitialized; | ||
} | ||
else if (proxy is IPersistentCollection) | ||
{ | ||
return ((IPersistentCollection)proxy).WasInitialized; | ||
} | ||
else | ||
{ | ||
return true; | ||
} | ||
} | ||
|
||
public static bool IsProxyFactoryConfigurated() | ||
{ | ||
try | ||
{ | ||
var f = NHibernate.Cfg.Environment.BytecodeProvider.ProxyFactoryFactory; | ||
return true; | ||
} | ||
catch (ProxyFactoryFactoryNotConfiguredException) | ||
{ | ||
return false; | ||
} | ||
} | ||
} | ||
} |