当前位置: 首页>>代码示例>>Java>>正文


Java Proxy类代码示例

本文整理汇总了Java中javassist.util.proxy.Proxy的典型用法代码示例。如果您正苦于以下问题:Java Proxy类的具体用法?Java Proxy怎么用?Java Proxy使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Proxy类属于javassist.util.proxy包,在下文中一共展示了Proxy类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: shouldGetBlogsWithAuthorsAndPosts

import javassist.util.proxy.Proxy; //导入依赖的package包/类
@Test
public void shouldGetBlogsWithAuthorsAndPosts() {
  SqlSession session = sqlSessionFactory.openSession();
  try {
    BoundBlogMapper mapper = session.getMapper(BoundBlogMapper.class);
    List<Blog> blogs = mapper.selectBlogsWithAutorAndPosts();
    assertEquals(2, blogs.size());
    assertTrue(blogs.get(0) instanceof Proxy);
    assertEquals(101, blogs.get(0).getAuthor().getId());
    assertEquals(1, blogs.get(0).getPosts().size());
    assertEquals(1, blogs.get(0).getPosts().get(0).getId());
    assertTrue(blogs.get(1) instanceof Proxy);      
    assertEquals(102, blogs.get(1).getAuthor().getId());
    assertEquals(1, blogs.get(1).getPosts().size());
    assertEquals(2, blogs.get(1).getPosts().get(0).getId());
  } finally {
    session.close();
  }
}
 
开发者ID:yuexiahandao,项目名称:MybatisCode,代码行数:20,代码来源:BindingTest.java

示例2: shouldFetchPostsForBlog

import javassist.util.proxy.Proxy; //导入依赖的package包/类
@Test
public void shouldFetchPostsForBlog() throws Exception {
  
  Executor executor = createExecutor(new JdbcTransaction(ds, null, false));
  try {
    MappedStatement selectBlog = ExecutorTestHelper.prepareComplexSelectBlogMappedStatement(config);
    MappedStatement selectPosts = ExecutorTestHelper.prepareSelectPostsForBlogMappedStatement(config);
    config.addMappedStatement(selectBlog);
    config.addMappedStatement(selectPosts);
    List<Post> posts = executor.query(selectPosts, 1, RowBounds.DEFAULT, Executor.NO_RESULT_HANDLER);
    executor.flushStatements();
    assertEquals(2, posts.size());
    assertTrue(posts.get(1) instanceof Proxy);
    assertNotNull(posts.get(1).getBlog());
    assertEquals(1, posts.get(1).getBlog().getId());
    executor.rollback(true);
  } finally {
    executor.rollback(true);
    executor.close(false);
  }
}
 
开发者ID:yuexiahandao,项目名称:MybatisCode,代码行数:22,代码来源:BaseExecutorTest.java

示例3: asyncHandler

import javassist.util.proxy.Proxy; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private MethodHandler asyncHandler(final Class clazz) {
    return (o, method, method1, args) -> {
        Pair<ThriftServerInfo, AbstractTrpcClient> borrowClient = ClientCluster.getBlockClient(clientArgs);
        Object client = borrowClient.getValue().getClient(clazz);
        try {
            if (args.length > 0 && args[args.length - 1] instanceof AsyncMethodCallback) {
                //代理AsyncMethodCallback
                args[args.length - 1] = java.lang.reflect.Proxy.newProxyInstance(AsyncMethodCallback.class.getClassLoader(),
                        new Class[]{AsyncMethodCallback.class},
                        new AsyncMethodCallbackProxy(args[args.length - 1], clientArgs, borrowClient));
            }
            return method.invoke(client, args);
        } catch (Exception e) {
            log.error("call rpc error", e);
            throw e;
        }
    };
}
 
开发者ID:sofn,项目名称:trpc,代码行数:20,代码来源:TrpcClientProxy.java

示例4: shouldInitializeProfiledClassesWithProxy

import javassist.util.proxy.Proxy; //导入依赖的package包/类
@Test
public void shouldInitializeProfiledClassesWithProxy() {
    // given
    InjectorImpl injector = (InjectorImpl) new InjectorBuilder()
        .addDefaultHandlers(PACKAGE)
        .create();
    ProfilePostConstructHandler profileHandler = new ProfilePostConstructHandler(injector);
    injector.getConfig().addHandlers(singletonList(profileHandler));
    injector.register(ProvidedClass.class, new ProvidedClass(""));
    injector.registerProvider(SailService.class, SailServiceProvider.class);

    // when (trigger initialization + invoke some methods)
    VehiclesJourneyService journeyService = injector.getSingleton(VehiclesJourneyService.class);
    journeyService.startJourney();
    SteerServiceManager steerManager = injector.getSingleton(SteerServiceManager.class);
    steerManager.brakeAll();
    injector.getSingleton(Plane.class).identify();

    // then
    assertThat(profileHandler.getInvocations(), contains("Car#startJourney", "DriveService#brake",
        "SteerServiceManager#brakeAll", "DriveService#brake", "Plane#identify"));
    assertThat(injector.getIfAvailable(Plane.class), instanceOf(Proxy.class));
    assertThat(injector.getIfAvailable(Bicycle.class), not(instanceOf(Proxy.class)));
    assertThat(injector.getIfAvailable(DriveService.class), instanceOf(Proxy.class));
}
 
开发者ID:ljacqu,项目名称:DependencyInjector,代码行数:26,代码来源:PostConstructRemappingTest.java

示例5: testInterceptInheritedMethod

import javassist.util.proxy.Proxy; //导入依赖的package包/类
/**
 * Tests {@link JavaAssistInterceptor#createInterceptedClass(Class)} with a class whose abstract super class declares a {@link Cached} method.<br>
 * Verifies that the method under test returns a proxy class.
 * 
 * @throws Exception
 */
@Test
public void testInterceptInheritedMethod() throws Exception
{
	final JavaAssistInterceptor javaAssistInterceptor = new JavaAssistInterceptor();
	final CacheInterceptorDummy interceptordummy = new CacheInterceptorDummy();

	javaAssistInterceptor.registerInterceptor(Cached.class, interceptordummy);
	final Class<TestService> interceptedClass = javaAssistInterceptor.createInterceptedClass(TestService.class);

	assertThat(interceptedClass, notNullValue());
	assertThat(interceptedClass, typeCompatibleWith(TestService.class));
	assertThat(interceptedClass, not(sameInstance(TestService.class))); // we expect a proxy class, not TestService.class itself

	final TestService interceptedInstance = interceptedClass.newInstance();
	assertThat(interceptedInstance, instanceOf(Proxy.class));

	interceptedInstance.testMethod1();
	interceptedInstance.testMethod2();
	assertThat(interceptordummy.interceptedInvocations.contains("testMethod1"), is(true));
	assertThat(interceptordummy.interceptedInvocations.contains("testMethod2"), is(false));
}
 
开发者ID:metasfresh,项目名称:metasfresh,代码行数:28,代码来源:JavaAssistInterceptorTests.java

示例6: logClassLoaders

import javassist.util.proxy.Proxy; //导入依赖的package包/类
private static void logClassLoaders(Class clazz) {
	logClassLoader("[proxies loaded in this one]", clazz.getClassLoader());
	
	Class[] interfaces = clazz.getInterfaces();
	for(Class inter : interfaces) {
		if (log.isInfoEnabled())
			log.info("loggin interface="+inter);
		logClassLoader("[INTERFACE="+inter+"]", inter.getClassLoader());
	}
	
	ClassLoader cl = Thread.currentThread().getContextClassLoader();
	logClassLoader("[context classloader]", cl);
	
	ClassLoader sysCl = ClassLoader.getSystemClassLoader();
	logClassLoader("[system classloader]", sysCl);
	
	ClassLoader playCl = DboTableMeta.class.getClassLoader();
	logClassLoader("[play jar in this classloader]", playCl);
	
	ClassLoader assistCl = Proxy.class.getClassLoader();
	logClassLoader("[javassist jar in this classloader]", assistCl);
}
 
开发者ID:guci314,项目名称:playorm,代码行数:23,代码来源:DboTableMeta.java

示例7: getRid

import javassist.util.proxy.Proxy; //导入依赖的package包/类
/**
 * Resolve rid from almost all possible objects.
 * Even if simple string provided, value will be checked for correctness.
 * <p>
 * Note: not saved object proxy, document or vertex will contain fake id and will be accepted
 * (but query result against such id will be empty).
 *
 * @param value value may be a mapped object (proxy or raw), document, vertex, ORID or simple string
 * @return correct rid string
 * @throws ru.vyarus.guice.persist.orient.db.PersistException if rid couldn't be resolved
 * @throws NullPointerException                               if value is null
 */
public static String getRid(final Object value) {
    Preconditions.checkNotNull(value, "Not null value required");
    final String res;
    if (value instanceof ORID) {
        res = value.toString();
    } else if (value instanceof OIdentifiable) {
        // ODocument, Vertex support
        res = ((OIdentifiable) value).getIdentity().toString();
    } else if (value instanceof String) {
        res = checkRid(value);
    } else if (value instanceof Proxy) {
        // object proxy
        res = OObjectEntitySerializer.getRid((Proxy) value).toString();
    } else {
        // raw (non proxy) object
        res = resolveIdFromObject(value);
    }
    return res;
}
 
开发者ID:xvik,项目名称:guice-persist-orient,代码行数:32,代码来源:RidUtils.java

示例8: newJavassistProxy

import javassist.util.proxy.Proxy; //导入依赖的package包/类
static NonTrivialBean newJavassistProxy() 
        throws InstantiationException, IllegalAccessException {
  ProxyFactory f = new ProxyFactory();
  f.setSuperclass(NonTrivialBean.class);
  Class<?> c = f.createClass();
  MethodHandler mi = new MethodHandler() {
    // delegate to source methods
    public Object invoke(Object self, Method m, Method proceed, 
        Object[] args) throws Throwable {
      return proceed.invoke(self, args);
    }
  };
  NonTrivialBean b = (NonTrivialBean) c.newInstance();
  ((Proxy) b).setHandler(mi);
  return b;
}
 
开发者ID:Salauyou,项目名称:Java-Utils,代码行数:17,代码来源:TestBeanHelper.java

示例9: getProxy

import javassist.util.proxy.Proxy; //导入依赖的package包/类
public static HibernateProxy getProxy(
		final String entityName,
		final Class persistentClass,
		final Class[] interfaces,
		final Method getIdentifierMethod,
		final Method setIdentifierMethod,
		CompositeType componentIdType,
		final Serializable id,
		final SessionImplementor session) throws HibernateException {
	// note: interface is assumed to already contain HibernateProxy.class
	try {
		final JavassistLazyInitializer instance = new JavassistLazyInitializer(
				entityName,
				persistentClass,
				interfaces,
				id,
				getIdentifierMethod,
				setIdentifierMethod,
				componentIdType,
				session,
				ReflectHelper.overridesEquals(persistentClass)
		);
		ProxyFactory factory = new ProxyFactory();
		factory.setSuperclass( interfaces.length == 1 ? persistentClass : null );
		factory.setInterfaces( interfaces );
		factory.setFilter( FINALIZE_FILTER );
		Class cl = factory.createClass();
		final HibernateProxy proxy = ( HibernateProxy ) cl.newInstance();
		( ( Proxy ) proxy ).setHandler( instance );
		instance.constructed = true;
		return proxy;
	}
	catch ( Throwable t ) {
		LOG.error(LOG.javassistEnhancementFailed(entityName), t);
		throw new HibernateException(LOG.javassistEnhancementFailed(entityName), t);
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:38,代码来源:JavassistLazyInitializer.java

示例10: getProxy

import javassist.util.proxy.Proxy; //导入依赖的package包/类
public Object getProxy() {
	try {
		final Proxy proxy = (Proxy) proxyClass.newInstance();
		proxy.setHandler( new PassThroughHandler( proxy, proxyClass.getName() ) );
		return proxy;
	}
	catch ( Throwable t ) {
		throw new HibernateException( "Unable to instantiated proxy instance" );
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:11,代码来源:ProxyFactoryFactoryImpl.java

示例11: shouldSelectBlogWithPostsAndAuthorUsingSubSelectsLazily

import javassist.util.proxy.Proxy; //导入依赖的package包/类
@Test
public void shouldSelectBlogWithPostsAndAuthorUsingSubSelectsLazily() throws Exception {
  SqlSession session = sqlMapper.openSession();
  try {
    Blog blog = session.selectOne("org.apache.ibatis.domain.blog.mappers.BlogMapper.selectBlogWithPostsUsingSubSelectLazily", 1);
    Assert.assertTrue(blog instanceof Proxy);
    assertEquals("Jim Business", blog.getTitle());
    assertEquals(2, blog.getPosts().size());
    assertEquals("Corn nuts", blog.getPosts().get(0).getSubject());
    assertEquals(101, blog.getAuthor().getId());
    assertEquals("jim", blog.getAuthor().getUsername());
  } finally {
    session.close();
  }
}
 
开发者ID:yuexiahandao,项目名称:MybatisCode,代码行数:16,代码来源:SqlSessionTest.java

示例12: shouldGetAUserAndGroups

import javassist.util.proxy.Proxy; //导入依赖的package包/类
@Test
public void shouldGetAUserAndGroups() {
  SqlSession sqlSession = sqlSessionFactory.openSession();
  try {
    Mapper mapper = sqlSession.getMapper(Mapper.class);
    User user = mapper.getUser(1);
    Assert.assertEquals("User1", user.getName());
    assertTrue(user instanceof Proxy);
    Assert.assertEquals(1, user.getGroups().size());
  } finally {
    sqlSession.close();
  }
}
 
开发者ID:yuexiahandao,项目名称:MybatisCode,代码行数:14,代码来源:JavassistTest.java

示例13: shouldCreateAProxyForAPartiallyLoadedBean

import javassist.util.proxy.Proxy; //导入依赖的package包/类
@Test
public void shouldCreateAProxyForAPartiallyLoadedBean() throws Exception {
  ResultLoaderMap loader = new ResultLoaderMap();
  loader.addLoader("id", null, null);
  Object proxy = proxyFactory.createProxy(author, loader, new Configuration(), new DefaultObjectFactory(), new ArrayList<Class<?>>(), new ArrayList<Object>());
  Author author2 = (Author) deserialize(serialize((Serializable) proxy));
  assertTrue(author2 instanceof Proxy);
}
 
开发者ID:yuexiahandao,项目名称:MybatisCode,代码行数:9,代码来源:JavassistProxyTest.java

示例14: postProcess

import javassist.util.proxy.Proxy; //导入依赖的package包/类
@Override
public <T> T postProcess(final T object, ResolutionContext context,
                         Resolution<?> resolution) throws ReflectiveOperationException {
    final Class<?> clazz = object.getClass();
    if (!hasProfileMethod(clazz)) {
        return null;
    }

    // The Proxy generated by javassist will have the same constructor args as on the real class
    // We can easily check and satisfy this by getting the instantiation method: if it is constructor injection
    // get the args from it. This approach requires some refactoring to support custom instantiation methods.
    Class<?>[] constructorTypes = getConstructorType(clazz);
    Object[] constructorArgs = resolveConstructorArgs(constructorTypes);

    ProxyFactory pf = new ProxyFactory();
    pf.setSuperclass(clazz);
    Class<?> proxyClass = pf.createClass(METHOD_FILTER);

    T proxy = (T) proxyClass
        .getConstructor(constructorTypes)
        .newInstance(constructorArgs);

    ((Proxy) proxy).setHandler(new MethodHandler() {
        @Override
        public Object invoke(Object self, Method thisMethod, Method proceed, Object[] args)
                             throws ReflectiveOperationException {
            invocations.add(clazz.getSimpleName() + "#" + thisMethod.getName());
            return thisMethod.invoke(object, args);
        }
    });
    return proxy;
}
 
开发者ID:ljacqu,项目名称:DependencyInjector,代码行数:33,代码来源:ProfilePostConstructHandler.java

示例15: getObject

import javassist.util.proxy.Proxy; //导入依赖的package包/类
private Object getObject(Object value)
{
    Object detached;
    if (value instanceof Proxy)
    {
        detached = db.detachAll(value, true);

    } else
    {
        detached = value;
    }
    return detached;
}
 
开发者ID:jesty,项目名称:orientdb-javaee,代码行数:14,代码来源:OrientDBJacksonProvider.java


注:本文中的javassist.util.proxy.Proxy类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。