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();
}
}
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);
}
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;
}
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;
}
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;
}
Aggregations