Package org.hibernate.repackage.cglib.proxy

Examples of org.hibernate.repackage.cglib.proxy.Enhancer


    public BasicProxyFactoryImpl(Class superClass, Class[] interfaces) {
      if ( superClass == null && ( interfaces == null || interfaces.length < 1 ) ) {
        throw new AssertionFailure( "attempting to build proxy without any superclass or interfaces" );
      }

      Enhancer en = new Enhancer();
      en.setUseCache( false );
      en.setInterceptDuringConstruction( false );
      en.setUseFactory( true );
      en.setCallbackTypes( CALLBACK_TYPES );
      en.setCallbackFilter( FINALIZE_FILTER );
      if ( superClass != null ) {
        en.setSuperclass( superClass );
      }
      if ( interfaces != null && interfaces.length > 0 ) {
        en.setInterfaces( interfaces );
      }
      proxyClass = en.createClass();
      try {
        factory = ( Factory ) proxyClass.newInstance();
      }
      catch ( Throwable t ) {
        throw new HibernateException( "Unable to build CGLIB Factory instance" );
View Full Code Here


    return proxy;
  }

  public static Class getProxyFactory(Class persistentClass, Class[] interfaces)
      throws HibernateException {
    Enhancer e = new Enhancer();
    e.setSuperclass( interfaces.length == 1 ? persistentClass : null );
    e.setInterfaces(interfaces);
    e.setCallbackTypes(new Class[]{
      InvocationHandler.class,
      NoOp.class,
        });
      e.setCallbackFilter(FINALIZE_FILTER);
      e.setUseFactory(false);
    e.setInterceptDuringConstruction( false );
    return e.createClass();
  }
View Full Code Here

         */
        if (!runsFromAnt()) {
            return;
        }

        Enhancer enh = new Enhancer();
        enh.setInterfaces(new Class[] { BeanInterfaceHib.class });
        enh.setCallback(new MethodInterceptor() {
            @Override
            public Object intercept(Object obj, Method method,
                    Object[] args, MethodProxy proxy)
                            throws Throwable
            {
                if ("getX".equals(method.getName ())) {
                    return Integer.valueOf(13);
                }
                return proxy.invokeSuper(obj, args);
            }
        });
        BeanInterfaceHib bean = (BeanInterfaceHib) enh.create();
        ObjectMapper mapper = new ObjectMapper();
        Map<String,Object> result = writeAndMap(mapper, bean);
        assertEquals(1, result.size());
        assertEquals(Integer.valueOf(13), result.get("x"));
    }
View Full Code Here

         */
        if (!runsFromAnt()) {
            return;
        }

        Enhancer enh = new Enhancer();
        enh.setInterfaces(new Class[] { BeanInterfaceHib.class });
        enh.setCallback(new MethodInterceptor() {
            @Override
            public Object intercept(Object obj, Method method,
                    Object[] args, MethodProxy proxy)
                            throws Throwable
            {
                if ("getX".equals(method.getName ())) {
                    return Integer.valueOf(13);
                }
                return proxy.invokeSuper(obj, args);
            }
        });
        BeanInterfaceHib bean = (BeanInterfaceHib) enh.create();
        ObjectMapper mapper = new ObjectMapper();
        Map<String,Object> result = writeAndMap(mapper, bean);
        assertEquals(1, result.size());
        assertEquals(Integer.valueOf(13), result.get("x"));
    }
View Full Code Here

TOP

Related Classes of org.hibernate.repackage.cglib.proxy.Enhancer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.