Search in sources :

Example 1 with Factory

use of net.sf.cglib.proxy.Factory in project mybatis-3 by mybatis.

the class BindingTest method shouldGetBlogsWithAuthorsAndPostsEagerly.

@Test
public void shouldGetBlogsWithAuthorsAndPostsEagerly() {
    SqlSession session = sqlSessionFactory.openSession();
    try {
        BoundBlogMapper mapper = session.getMapper(BoundBlogMapper.class);
        List<Blog> blogs = mapper.selectBlogsWithAutorAndPostsEagerly();
        assertEquals(2, blogs.size());
        assertFalse(blogs.get(0) instanceof Factory);
        assertEquals(101, blogs.get(0).getAuthor().getId());
        assertEquals(1, blogs.get(0).getPosts().size());
        assertEquals(1, blogs.get(0).getPosts().get(0).getId());
        assertFalse(blogs.get(1) instanceof Factory);
        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();
    }
}
Also used : SqlSession(org.apache.ibatis.session.SqlSession) JdbcTransactionFactory(org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory) SqlSessionFactory(org.apache.ibatis.session.SqlSessionFactory) TransactionFactory(org.apache.ibatis.transaction.TransactionFactory) Factory(net.sf.cglib.proxy.Factory) Blog(org.apache.ibatis.domain.blog.Blog) BaseDataTest(org.apache.ibatis.BaseDataTest) Test(org.junit.Test)

Example 2 with Factory

use of net.sf.cglib.proxy.Factory in project powermock by powermock.

the class ProxyFrameworksTest method should_return_interface_as_original_type_if_only_one_non_mocking_interface.

@Test
public void should_return_interface_as_original_type_if_only_one_non_mocking_interface() {
    Factory someClass = (Factory) createCglibProxy(Factory.class, SomeInterface.class);
    UnproxiedType unproxiedType = proxyFrameworks.getUnproxiedType(someClass);
    assertThatOriginalTypeInstanceOf(unproxiedType, SomeInterface.class);
}
Also used : Factory(net.sf.cglib.proxy.Factory) Test(org.junit.Test)

Example 3 with Factory

use of net.sf.cglib.proxy.Factory in project CloudStack-archive by CloudStack-extras.

the class GenericDaoBase method createSearchCriteria2.

@Override
@DB(txn = false)
public SearchCriteria2 createSearchCriteria2() {
    final T entity = (T) _searchEnhancer.create();
    final Factory factory = (Factory) entity;
    SearchCriteria2 sc = new SearchCriteria2(entity, entity.getClass(), _allAttributes, this);
    factory.setCallback(0, sc);
    return sc;
}
Also used : Factory(net.sf.cglib.proxy.Factory) AttributeOverride(javax.persistence.AttributeOverride)

Example 4 with Factory

use of net.sf.cglib.proxy.Factory in project CloudStack-archive by CloudStack-extras.

the class GenericDaoBase method createSearchBuilder.

@SuppressWarnings("unchecked")
@Override
@DB(txn = false)
public SearchBuilder<T> createSearchBuilder() {
    final T entity = (T) _searchEnhancer.create();
    final Factory factory = (Factory) entity;
    SearchBuilder<T> builder = new SearchBuilder<T>(entity, _allAttributes);
    factory.setCallback(0, builder);
    return builder;
}
Also used : Factory(net.sf.cglib.proxy.Factory) AttributeOverride(javax.persistence.AttributeOverride)

Example 5 with Factory

use of net.sf.cglib.proxy.Factory in project CloudStack-archive by CloudStack-extras.

the class ComponentLocator method createInstance.

private static Object createInstance(Class<?> clazz, boolean inject, boolean singleton, Object... args) {
    Factory factory = null;
    Singleton entity = null;
    synchronized (s_factories) {
        if (singleton) {
            entity = s_singletons.get(clazz);
            if (entity != null) {
                s_logger.debug("Found singleton instantiation for " + clazz.toString());
                return entity.singleton;
            }
        }
        InjectInfo info = s_factories.get(clazz);
        if (info == null) {
            Enhancer enhancer = new Enhancer();
            enhancer.setSuperclass(clazz);
            enhancer.setCallbackFilter(s_callbackFilter);
            enhancer.setCallbacks(s_callbacks);
            factory = (Factory) enhancer.create();
            info = new InjectInfo(enhancer, factory);
            s_factories.put(clazz, info);
        } else {
            factory = info.factory;
        }
    }
    Class<?>[] argTypes = null;
    if (args != null && args.length > 0) {
        Constructor<?>[] constructors = clazz.getConstructors();
        for (Constructor<?> constructor : constructors) {
            Class<?>[] paramTypes = constructor.getParameterTypes();
            if (paramTypes.length == args.length) {
                boolean found = true;
                for (int i = 0; i < paramTypes.length; i++) {
                    if (!paramTypes[i].isAssignableFrom(args[i].getClass()) && !paramTypes[i].isPrimitive()) {
                        found = false;
                        break;
                    }
                }
                if (found) {
                    argTypes = paramTypes;
                    break;
                }
            }
        }
        if (argTypes == null) {
            throw new CloudRuntimeException("Unable to find constructor to match parameters given: " + clazz.getName());
        }
        entity = new Singleton(factory.newInstance(argTypes, args, s_callbacks));
    } else {
        entity = new Singleton(factory.newInstance(s_callbacks));
    }
    if (inject) {
        inject(clazz, entity.singleton);
        entity.state = Singleton.State.Injected;
    }
    if (singleton) {
        synchronized (s_factories) {
            s_singletons.put(clazz, entity);
        }
    }
    return entity.singleton;
}
Also used : Enhancer(net.sf.cglib.proxy.Enhancer) Constructor(java.lang.reflect.Constructor) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Factory(net.sf.cglib.proxy.Factory) SAXParserFactory(javax.xml.parsers.SAXParserFactory)

Aggregations

Factory (net.sf.cglib.proxy.Factory)17 Test (org.junit.Test)5 AttributeOverride (javax.persistence.AttributeOverride)4 Method (java.lang.reflect.Method)2 Enhancer (net.sf.cglib.proxy.Enhancer)2 AmazonS3 (com.amazonaws.services.s3.AmazonS3)1 Attribute (com.amazonaws.services.simpledb.model.Attribute)1 DeleteAttributesRequest (com.amazonaws.services.simpledb.model.DeleteAttributesRequest)1 PutAttributesRequest (com.amazonaws.services.simpledb.model.PutAttributesRequest)1 ReplaceableAttribute (com.amazonaws.services.simpledb.model.ReplaceableAttribute)1 UpdateCondition (com.amazonaws.services.simpledb.model.UpdateCondition)1 Select (com.cloud.utils.db.GenericSearchBuilder.Select)1 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1 AnnotationInfo (com.spaceprogram.simplejpa.AnnotationInfo)1 LazyInterceptor (com.spaceprogram.simplejpa.LazyInterceptor)1 PersistentProperty (com.spaceprogram.simplejpa.PersistentProperty)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InputStream (java.io.InputStream)1 ObjectOutputStream (java.io.ObjectOutputStream)1