Esempio n. 1
0
    public INHibernateProxy GetProxy(object id, ISessionImplementor session)
    {
        INHibernateProxy proxy;
        try
        {
            object generatedProxy;
            LazyInitializer initializer = new LazyInitializer(_entityName, _persistentClass, id, _getIdentifierMethod, _setIdentifierMethod, _componentIdType, session);
            IInterceptor[] interceptors = new IInterceptor[] { initializer };

            object[] args;
            if (_isClassProxy)
            {
                args = new object[] { interceptors };
            }
            else
            {
                args = new object[] { interceptors, new object() };
            }
            generatedProxy = Activator.CreateInstance(_proxyType, args);

            initializer._constructed = true;
            proxy = (INHibernateProxy)generatedProxy;
        }
        catch (Exception e)
        {
            string message = "Creating a proxy instance failed";
            _log.Error(message, e);
            throw new HibernateException(message, e);
        }

        return proxy;
    }
Esempio n. 2
0
    public INHibernateProxy GetProxy(object id, ISessionImplementor session)
    {
        INHibernateProxy proxy;

        try
        {
            object          generatedProxy;
            LazyInitializer initializer  = new LazyInitializer(_entityName, _persistentClass, id, _getIdentifierMethod, _setIdentifierMethod, _componentIdType, session);
            IInterceptor[]  interceptors = new IInterceptor[] { initializer };

            object[] args;
            if (_isClassProxy)
            {
                args = new object[] { interceptors };
            }
            else
            {
                args = new object[] { interceptors, new object() };
            }
            generatedProxy = Activator.CreateInstance(_proxyType, args);

            initializer._constructed = true;
            proxy = (INHibernateProxy)generatedProxy;
        }
        catch (Exception e)
        {
            string message = "Creating a proxy instance failed";
            _log.Error(message, e);
            throw new HibernateException(message, e);
        }

        return(proxy);
    }
Esempio n. 3
0
		/// <summary>
		/// Generates a class which extends the baseClass, overriding all 
		/// the virtual methods and implementing all the mixin interfaces.
		/// </summary>
		/// <param name="baseClass">Super class</param>
		/// <param name="mixins">Array of mixins to be implemented by the proxy</param>
		/// <param name="interceptor">Instance of <see cref="IInterceptor"/></param>
		/// <param name="constructorArgs"></param>
		/// <returns>Proxy instance</returns>
		public object CreateClassProxy(Type baseClass, object[] mixins, IInterceptor interceptor,
			params object[] constructorArgs)
		{
			ProxyGenerationOptions options = CreateProxyGenerationOptions(mixins);
			return CreateClassProxy(baseClass, null, options, constructorArgs, interceptor);
		}
Esempio n. 4
0
		/// <summary>
		/// Generates a proxy implementing the specified interface and the mixins
		/// redirecting method invocations to the specifed interceptor.
		/// </summary>
		/// <param name="inter">Interface to be implemented.</param>
		/// <param name="target"></param>
		/// <param name="mixins">Array of instances (mixins) to be introducted.</param>
		/// <param name="interceptor">Instance of <see cref="IInterceptor"/>.</param>
		/// <returns>Proxy Instance.</returns>
		public object CreateProxy(Type inter, object target, object[] mixins, IInterceptor interceptor)
		{
			ProxyGenerationOptions options = CreateProxyGenerationOptions(mixins);
			return CreateInterfaceProxyWithTarget(inter, target, options, interceptor);
		}