Search in sources :

Example 46 with Configuration

use of org.apache.ibatis.session.Configuration in project mybatis-3 by mybatis.

the class ClobReaderTypeHandlerTest method setupSqlSessionFactory.

@BeforeClass
public static void setupSqlSessionFactory() throws Exception {
    DataSource dataSource = BaseDataTest.createUnpooledDataSource("org/apache/ibatis/type/jdbc.properties");
    BaseDataTest.runScript(dataSource, "org/apache/ibatis/type/ClobReaderTypeHandlerTest.sql");
    TransactionFactory transactionFactory = new JdbcTransactionFactory();
    Environment environment = new Environment("Production", transactionFactory, dataSource);
    Configuration configuration = new Configuration(environment);
    configuration.addMapper(Mapper.class);
    sqlSessionFactory = new SqlSessionFactoryBuilder().build(configuration);
}
Also used : Configuration(org.apache.ibatis.session.Configuration) TransactionFactory(org.apache.ibatis.transaction.TransactionFactory) JdbcTransactionFactory(org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory) Environment(org.apache.ibatis.mapping.Environment) SqlSessionFactoryBuilder(org.apache.ibatis.session.SqlSessionFactoryBuilder) JdbcTransactionFactory(org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory) DataSource(javax.sql.DataSource) BeforeClass(org.junit.BeforeClass)

Example 47 with Configuration

use of org.apache.ibatis.session.Configuration in project mybatis-3 by mybatis.

the class SerializableProxyTest method shouldNotGenerateWriteReplaceItThereIsAlreadyOne.

@Test
public void shouldNotGenerateWriteReplaceItThereIsAlreadyOne() throws Exception {
    AuthorWithWriteReplaceMethod beanWithWriteReplace = new AuthorWithWriteReplaceMethod(999, "someone", "!@#@!#!@#", "someone@somewhere.com", "blah", Section.NEWS);
    try {
        beanWithWriteReplace.getClass().getDeclaredMethod("writeReplace");
    } catch (NoSuchMethodException e) {
        fail("Bean should declare a writeReplace method");
    }
    Object proxy = proxyFactory.createProxy(beanWithWriteReplace, new ResultLoaderMap(), new Configuration(), new DefaultObjectFactory(), new ArrayList<Class<?>>(), new ArrayList<Object>());
    Class<?>[] interfaces = proxy.getClass().getInterfaces();
    boolean ownInterfaceFound = false;
    for (Class<?> i : interfaces) {
        if (i.equals(WriteReplaceInterface.class)) {
            ownInterfaceFound = true;
            break;
        }
    }
    assertFalse(ownInterfaceFound);
}
Also used : Configuration(org.apache.ibatis.session.Configuration) DefaultObjectFactory(org.apache.ibatis.reflection.factory.DefaultObjectFactory) Test(org.junit.Test)

Example 48 with Configuration

use of org.apache.ibatis.session.Configuration in project mybatis-3 by mybatis.

the class SerializableProxyTest method shouldSerializeAProxyForABeanWithDefaultConstructor.

@Test
public void shouldSerializeAProxyForABeanWithDefaultConstructor() throws Exception {
    Object proxy = proxyFactory.createProxy(author, new ResultLoaderMap(), new Configuration(), new DefaultObjectFactory(), new ArrayList<Class<?>>(), new ArrayList<Object>());
    Object proxy2 = deserialize(serialize((Serializable) proxy));
    assertEquals(author, proxy2);
}
Also used : Serializable(java.io.Serializable) Configuration(org.apache.ibatis.session.Configuration) DefaultObjectFactory(org.apache.ibatis.reflection.factory.DefaultObjectFactory) Test(org.junit.Test)

Example 49 with Configuration

use of org.apache.ibatis.session.Configuration in project mybatis-3 by mybatis.

the class SerializableProxyTest method shouldNotLetReadUnloadedPropertyAfterTwoSerializations.

@Test(expected = ExecutorException.class)
public void shouldNotLetReadUnloadedPropertyAfterTwoSerializations() 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(deserialize(serialize((Serializable) proxy))));
    author2.getId();
}
Also used : Configuration(org.apache.ibatis.session.Configuration) DefaultObjectFactory(org.apache.ibatis.reflection.factory.DefaultObjectFactory) Author(org.apache.ibatis.domain.blog.Author) Test(org.junit.Test)

Example 50 with Configuration

use of org.apache.ibatis.session.Configuration in project mybatis-3 by mybatis.

the class SerializableProxyTest method shouldKeepGenericTypes.

@Test
public void shouldKeepGenericTypes() throws Exception {
    for (int i = 0; i < 10000; i++) {
        Author pc = new Author();
        Author proxy = (Author) proxyFactory.createProxy(pc, new ResultLoaderMap(), new Configuration(), new DefaultObjectFactory(), new ArrayList<Class<?>>(), new ArrayList<Object>());
        proxy.getBio();
    }
}
Also used : Configuration(org.apache.ibatis.session.Configuration) DefaultObjectFactory(org.apache.ibatis.reflection.factory.DefaultObjectFactory) ArrayList(java.util.ArrayList) Author(org.apache.ibatis.domain.blog.Author) Test(org.junit.Test)

Aggregations

Configuration (org.apache.ibatis.session.Configuration)121 Test (org.junit.Test)85 SqlSessionFactoryBuilder (org.apache.ibatis.session.SqlSessionFactoryBuilder)30 Environment (org.apache.ibatis.mapping.Environment)19 Reader (java.io.Reader)18 BoundSql (org.apache.ibatis.mapping.BoundSql)18 BaseDataTest (org.apache.ibatis.BaseDataTest)17 MappedStatement (org.apache.ibatis.mapping.MappedStatement)17 DynamicSqlSource (org.apache.ibatis.scripting.xmltags.DynamicSqlSource)17 Connection (java.sql.Connection)16 TextSqlNode (org.apache.ibatis.scripting.xmltags.TextSqlNode)16 JdbcTransactionFactory (org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory)16 DefaultObjectFactory (org.apache.ibatis.reflection.factory.DefaultObjectFactory)13 SqlSession (org.apache.ibatis.session.SqlSession)13 SqlSessionFactory (org.apache.ibatis.session.SqlSessionFactory)13 Properties (java.util.Properties)12 IfSqlNode (org.apache.ibatis.scripting.xmltags.IfSqlNode)12 UnpooledDataSource (org.apache.ibatis.datasource.unpooled.UnpooledDataSource)10 StatementHandler (org.apache.ibatis.executor.statement.StatementHandler)10 WhereSqlNode (org.apache.ibatis.scripting.xmltags.WhereSqlNode)10