Search in sources :

Example 1 with CglibProxyFactory

use of org.apache.ibatis.executor.loader.cglib.CglibProxyFactory in project mybatis-3 by mybatis.

the class LazyPropertiesTest method shouldInvokingSetterNotTriggerLazyLoading_Cglib.

@Test
public void shouldInvokingSetterNotTriggerLazyLoading_Cglib() {
    Configuration config = sqlSessionFactory.getConfiguration();
    config.setProxyFactory(new CglibProxyFactory());
    config.setAggressiveLazyLoading(false);
    SqlSession sqlSession = sqlSessionFactory.openSession();
    try {
        Mapper mapper = sqlSession.getMapper(Mapper.class);
        User user = mapper.getUser(1);
        user.setLazy1(new User());
        assertNotNull(user.getLazy1().getId());
    } finally {
        sqlSession.close();
    }
}
Also used : CglibProxyFactory(org.apache.ibatis.executor.loader.cglib.CglibProxyFactory) Configuration(org.apache.ibatis.session.Configuration) SqlSession(org.apache.ibatis.session.SqlSession) Test(org.junit.Test)

Example 2 with CglibProxyFactory

use of org.apache.ibatis.executor.loader.cglib.CglibProxyFactory in project mybatis-3 by mybatis.

the class CglibProxyTest method shouldSerizalizeADeserlizaliedProxy.

@Test
void shouldSerizalizeADeserlizaliedProxy() throws Exception {
    Object proxy = ((CglibProxyFactory) proxyFactory).createDeserializationProxy(author, new HashMap<>(), new DefaultObjectFactory(), new ArrayList<>(), new ArrayList<>());
    Author author2 = (Author) deserialize(serialize((Serializable) proxy));
    assertEquals(author, author2);
    assertNotEquals(author.getClass(), author2.getClass());
}
Also used : CglibProxyFactory(org.apache.ibatis.executor.loader.cglib.CglibProxyFactory) DefaultObjectFactory(org.apache.ibatis.reflection.factory.DefaultObjectFactory) Author(org.apache.ibatis.domain.blog.Author) Test(org.junit.jupiter.api.Test)

Example 3 with CglibProxyFactory

use of org.apache.ibatis.executor.loader.cglib.CglibProxyFactory in project mybatis-3 by mybatis.

the class XmlConfigBuilderTest method shouldSuccessfullyLoadXMLConfigFile.

@Test
void shouldSuccessfullyLoadXMLConfigFile() throws Exception {
    // System.setProperty(XPathParser.KEY_USE_XSD, "true");
    String resource = "org/apache/ibatis/builder/xsd/CustomizedSettingsMapperConfig.xml";
    try (InputStream inputStream = Resources.getResourceAsStream(resource)) {
        XMLConfigBuilder builder = new XMLConfigBuilder(inputStream);
        Configuration config = builder.parse();
        assertEquals(AutoMappingBehavior.NONE, config.getAutoMappingBehavior());
        assertEquals(AutoMappingUnknownColumnBehavior.WARNING, config.getAutoMappingUnknownColumnBehavior());
        assertFalse(config.isCacheEnabled());
        assertTrue(config.getProxyFactory() instanceof CglibProxyFactory);
        assertTrue(config.isLazyLoadingEnabled());
        assertTrue(config.isAggressiveLazyLoading());
        assertFalse(config.isMultipleResultSetsEnabled());
        assertFalse(config.isUseColumnLabel());
        assertTrue(config.isUseGeneratedKeys());
        assertEquals(ExecutorType.BATCH, config.getDefaultExecutorType());
        assertEquals(Integer.valueOf(10), config.getDefaultStatementTimeout());
        assertEquals(Integer.valueOf(100), config.getDefaultFetchSize());
        assertTrue(config.isMapUnderscoreToCamelCase());
        assertTrue(config.isSafeRowBoundsEnabled());
        assertEquals(LocalCacheScope.STATEMENT, config.getLocalCacheScope());
        assertEquals(JdbcType.NULL, config.getJdbcTypeForNull());
        assertEquals(new HashSet<>(Arrays.asList("equals", "clone", "hashCode", "toString", "xxx")), config.getLazyLoadTriggerMethods());
        assertFalse(config.isSafeResultHandlerEnabled());
        assertTrue(config.getDefaultScriptingLanguageInstance() instanceof RawLanguageDriver);
        assertTrue(config.isCallSettersOnNulls());
        assertEquals("mybatis_", config.getLogPrefix());
        assertEquals(Slf4jImpl.class.getName(), config.getLogImpl().getName());
        assertEquals(JBoss6VFS.class.getName(), config.getVfsImpl().getName());
        assertEquals(String.class.getName(), config.getConfigurationFactory().getName());
        assertTrue(config.isShrinkWhitespacesInSql());
        assertEquals(Author.class, config.getTypeAliasRegistry().getTypeAliases().get("blogauthor"));
        assertEquals(Blog.class, config.getTypeAliasRegistry().getTypeAliases().get("blog"));
        assertEquals(Cart.class, config.getTypeAliasRegistry().getTypeAliases().get("cart"));
        assertTrue(config.getTypeHandlerRegistry().getTypeHandler(Integer.class) instanceof CustomIntegerTypeHandler);
        assertTrue(config.getTypeHandlerRegistry().getTypeHandler(Long.class) instanceof CustomLongTypeHandler);
        assertTrue(config.getTypeHandlerRegistry().getTypeHandler(String.class) instanceof CustomStringTypeHandler);
        assertTrue(config.getTypeHandlerRegistry().getTypeHandler(String.class, JdbcType.VARCHAR) instanceof CustomStringTypeHandler);
        ExampleObjectFactory objectFactory = (ExampleObjectFactory) config.getObjectFactory();
        assertEquals(1, objectFactory.getProperties().size());
        assertEquals("100", objectFactory.getProperties().getProperty("objectFactoryProperty"));
        assertTrue(config.getObjectWrapperFactory() instanceof CustomObjectWrapperFactory);
        assertTrue(config.getReflectorFactory() instanceof CustomReflectorFactory);
        ExamplePlugin plugin = (ExamplePlugin) config.getInterceptors().get(0);
        assertEquals(1, plugin.getProperties().size());
        assertEquals("100", plugin.getProperties().getProperty("pluginProperty"));
        Environment environment = config.getEnvironment();
        assertEquals("development", environment.getId());
        assertTrue(environment.getDataSource() instanceof UnpooledDataSource);
        assertTrue(environment.getTransactionFactory() instanceof JdbcTransactionFactory);
        assertEquals("derby", config.getDatabaseId());
        assertEquals(4, config.getMapperRegistry().getMappers().size());
        assertTrue(config.getMapperRegistry().hasMapper(CachedAuthorMapper.class));
        assertTrue(config.getMapperRegistry().hasMapper(CustomMapper.class));
        assertTrue(config.getMapperRegistry().hasMapper(BlogMapper.class));
        assertTrue(config.getMapperRegistry().hasMapper(NestedBlogMapper.class));
    } finally {
    // System.clearProperty(XPathParser.KEY_USE_XSD);
    }
}
Also used : CustomIntegerTypeHandler(org.apache.ibatis.builder.typehandler.CustomIntegerTypeHandler) NestedBlogMapper(org.apache.ibatis.domain.blog.mappers.NestedBlogMapper) BlogMapper(org.apache.ibatis.domain.blog.mappers.BlogMapper) CustomStringTypeHandler(org.apache.ibatis.builder.CustomStringTypeHandler) CustomLongTypeHandler(org.apache.ibatis.builder.CustomLongTypeHandler) InputStream(java.io.InputStream) NestedBlogMapper(org.apache.ibatis.domain.blog.mappers.NestedBlogMapper) ExamplePlugin(org.apache.ibatis.builder.ExamplePlugin) CustomReflectorFactory(org.apache.ibatis.builder.CustomReflectorFactory) CustomMapper(org.apache.ibatis.builder.mapper.CustomMapper) CustomObjectWrapperFactory(org.apache.ibatis.builder.CustomObjectWrapperFactory) UnpooledDataSource(org.apache.ibatis.datasource.unpooled.UnpooledDataSource) JBoss6VFS(org.apache.ibatis.io.JBoss6VFS) CglibProxyFactory(org.apache.ibatis.executor.loader.cglib.CglibProxyFactory) XMLConfigBuilder(org.apache.ibatis.builder.xml.XMLConfigBuilder) RawLanguageDriver(org.apache.ibatis.scripting.defaults.RawLanguageDriver) ExampleObjectFactory(org.apache.ibatis.builder.ExampleObjectFactory) Environment(org.apache.ibatis.mapping.Environment) Slf4jImpl(org.apache.ibatis.logging.slf4j.Slf4jImpl) JdbcTransactionFactory(org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory) Test(org.junit.jupiter.api.Test)

Aggregations

CglibProxyFactory (org.apache.ibatis.executor.loader.cglib.CglibProxyFactory)3 Test (org.junit.jupiter.api.Test)2 InputStream (java.io.InputStream)1 CustomLongTypeHandler (org.apache.ibatis.builder.CustomLongTypeHandler)1 CustomObjectWrapperFactory (org.apache.ibatis.builder.CustomObjectWrapperFactory)1 CustomReflectorFactory (org.apache.ibatis.builder.CustomReflectorFactory)1 CustomStringTypeHandler (org.apache.ibatis.builder.CustomStringTypeHandler)1 ExampleObjectFactory (org.apache.ibatis.builder.ExampleObjectFactory)1 ExamplePlugin (org.apache.ibatis.builder.ExamplePlugin)1 CustomMapper (org.apache.ibatis.builder.mapper.CustomMapper)1 CustomIntegerTypeHandler (org.apache.ibatis.builder.typehandler.CustomIntegerTypeHandler)1 XMLConfigBuilder (org.apache.ibatis.builder.xml.XMLConfigBuilder)1 UnpooledDataSource (org.apache.ibatis.datasource.unpooled.UnpooledDataSource)1 Author (org.apache.ibatis.domain.blog.Author)1 BlogMapper (org.apache.ibatis.domain.blog.mappers.BlogMapper)1 NestedBlogMapper (org.apache.ibatis.domain.blog.mappers.NestedBlogMapper)1 JBoss6VFS (org.apache.ibatis.io.JBoss6VFS)1 Slf4jImpl (org.apache.ibatis.logging.slf4j.Slf4jImpl)1 Environment (org.apache.ibatis.mapping.Environment)1 DefaultObjectFactory (org.apache.ibatis.reflection.factory.DefaultObjectFactory)1