Example usage for org.apache.ibatis.session Configuration addMapper

List of usage examples for org.apache.ibatis.session Configuration addMapper

Introduction

In this page you can find the example usage for org.apache.ibatis.session Configuration addMapper.

Prototype

public <T> void addMapper(Class<T> type) 

Source Link

Usage

From source file:com.github.mybatis.spring.MapperFactoryBean.java

License:Apache License

/**
 * {@inheritDoc}/*from w w w .j  a v a 2  s  .c  om*/
 */
@Override
protected void checkDaoConfig() {
    super.checkDaoConfig();
    notNull(this.mapperInterface, "Property 'mapperInterface' is required");

    Configuration configuration = getSqlSession().getConfiguration();
    if (this.addToConfig && !configuration.hasMapper(this.mapperInterface)) {
        try {
            configuration.addMapper(this.mapperInterface);
        } catch (Throwable t) {
            logger.error("Error while adding the mapper '" + this.mapperInterface + "' to configuration.", t);
            throw new IllegalArgumentException(t);
        } finally {
            ErrorContext.instance().reset();
        }
    }
}

From source file:com.raise.orgs.impl.cfg.ProcessEngineConfigurationImpl.java

License:Apache License

protected void initSqlSessionFactory() {
    if (sqlSessionFactory == null) {
        InputStream inputStream = null;
        try {//from  w ww.jav  a 2  s  . co m
            inputStream = getMyBatisXmlConfigurationSteam();

            // update the jdbc parameters to the configured ones...
            Environment environment = new Environment("default", transactionFactory, dataSource);
            Reader reader = new InputStreamReader(inputStream);
            Properties properties = new Properties();
            properties.put("prefix", databaseTablePrefix);
            if (databaseType != null) {
                properties.put("limitBefore",
                        DbSqlSessionFactory.databaseSpecificLimitBeforeStatements.get(databaseType));
                properties.put("limitAfter",
                        DbSqlSessionFactory.databaseSpecificLimitAfterStatements.get(databaseType));
                properties.put("limitBetween",
                        DbSqlSessionFactory.databaseSpecificLimitBetweenStatements.get(databaseType));
                properties.put("limitOuterJoinBetween",
                        DbSqlSessionFactory.databaseOuterJoinLimitBetweenStatements.get(databaseType));
                properties.put("orderBy",
                        DbSqlSessionFactory.databaseSpecificOrderByStatements.get(databaseType));
                properties.put("limitBeforeNativeQuery",
                        ObjectUtils
                                .toString(DbSqlSessionFactory.databaseSpecificLimitBeforeNativeQueryStatements
                                        .get(databaseType)));
            }
            XMLConfigBuilder parser = new XMLConfigBuilder(reader, "", properties);
            Configuration configuration = parser.getConfiguration();
            configuration.setEnvironment(environment);
            configuration.getTypeHandlerRegistry().register(VariableType.class, JdbcType.VARCHAR,
                    new IbatisVariableTypeHandler());

            if (getCustomMybatisMappers() != null) {
                for (Class<?> clazz : getCustomMybatisMappers()) {
                    configuration.addMapper(clazz);
                }
            }

            configuration = parser.parse();

            sqlSessionFactory = new DefaultSqlSessionFactory(configuration);

        } catch (Exception e) {
            throw new ActivitiException("Error while building ibatis SqlSessionFactory: " + e.getMessage(), e);
        } finally {
            IoUtil.closeSilently(inputStream);
        }
    }
}

From source file:com.taobao.tdhs.jdbc.test.mybatis.TestBase.java

License:Open Source License

private SqlSession createSession(DataSource dataSource) {
    TransactionFactory transactionFactory = new JdbcTransactionFactory();
    Environment environment = new Environment("development", transactionFactory, dataSource);
    Configuration configuration = new Configuration(environment);
    configuration.addMapper(PersonMapper.class);
    configuration.addMapper(TestMapper.class);
    configuration.addMapper(OrderMapper.class);
    SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(configuration);
    return sqlSessionFactory.openSession();
}

From source file:com.tianjunwei.dynamic.SimpleTableAnnotatedMapperTest.java

License:Apache License

@BeforeEach
public void setup() throws Exception {
    Class.forName(JDBC_DRIVER);/*from w w w . ja  v  a2  s . com*/
    InputStream is = getClass().getResourceAsStream("/examples/simple/CreateSimpleDB.sql");
    try (Connection connection = DriverManager.getConnection(JDBC_URL, "sa", "")) {
        ScriptRunner sr = new ScriptRunner(connection);
        sr.setLogWriter(null);
        sr.runScript(new InputStreamReader(is));
    }

    UnpooledDataSource ds = new UnpooledDataSource(JDBC_DRIVER, JDBC_URL, "sa", "");
    Environment environment = new Environment("test", new JdbcTransactionFactory(), ds);
    Configuration config = new Configuration(environment);
    config.addMapper(SimpleTableAnnotatedMapper.class);
    sqlSessionFactory = new SqlSessionFactoryBuilder().build(config);
}

From source file:examples.animal.data.AnimalDataTest.java

License:Apache License

@BeforeEach
public void setup() throws Exception {
    Class.forName(JDBC_DRIVER);// w ww. j av a 2s  . c  o  m
    InputStream is = getClass().getResourceAsStream("/examples/animal/data/CreateAnimalData.sql");
    try (Connection connection = DriverManager.getConnection(JDBC_URL, "sa", "")) {
        ScriptRunner sr = new ScriptRunner(connection);
        sr.setLogWriter(null);
        sr.runScript(new InputStreamReader(is));
    }

    UnpooledDataSource ds = new UnpooledDataSource(JDBC_DRIVER, JDBC_URL, "sa", "");
    Environment environment = new Environment("test", new JdbcTransactionFactory(), ds);
    Configuration config = new Configuration(environment);
    config.addMapper(AnimalDataMapper.class);
    sqlSessionFactory = new SqlSessionFactoryBuilder().build(config);
}

From source file:examples.column.comparison.ColumnComparisonTest.java

License:Apache License

@BeforeEach
public void setup() throws Exception {
    Class.forName(JDBC_DRIVER);//from   w w w .  ja  v  a 2s .c  om
    InputStream is = getClass().getResourceAsStream("/examples/column/comparison/CreateDB.sql");
    try (Connection connection = DriverManager.getConnection(JDBC_URL, "sa", "")) {
        ScriptRunner sr = new ScriptRunner(connection);
        sr.setLogWriter(null);
        sr.runScript(new InputStreamReader(is));
    }

    UnpooledDataSource ds = new UnpooledDataSource(JDBC_DRIVER, JDBC_URL, "sa", "");
    Environment environment = new Environment("test", new JdbcTransactionFactory(), ds);
    Configuration config = new Configuration(environment);
    config.addMapper(ColumnComparisonMapper.class);
    sqlSessionFactory = new SqlSessionFactoryBuilder().build(config);
}

From source file:examples.generated.always.mybatis.GeneratedAlwaysAnnotatedMapperTest.java

License:Apache License

@BeforeEach
public void setup() throws Exception {
    Class.forName(JDBC_DRIVER);/*  w w  w  . jav a  2s .co  m*/
    InputStream is = getClass().getResourceAsStream("/examples/generated/always/CreateGeneratedAlwaysDB.sql");
    try (Connection connection = DriverManager.getConnection(JDBC_URL, "sa", "")) {
        ScriptRunner sr = new ScriptRunner(connection);
        sr.setLogWriter(null);
        sr.runScript(new InputStreamReader(is));
    }

    UnpooledDataSource ds = new UnpooledDataSource(JDBC_DRIVER, JDBC_URL, "sa", "");
    Environment environment = new Environment("test", new JdbcTransactionFactory(), ds);
    Configuration config = new Configuration(environment);
    config.addMapper(GeneratedAlwaysAnnotatedMapper.class);
    sqlSessionFactory = new SqlSessionFactoryBuilder().build(config);
}

From source file:examples.groupby.GroupByTest.java

License:Apache License

@BeforeEach
public void setup() throws Exception {
    Class.forName(JDBC_DRIVER);//from   ww  w  .  j av a  2 s. com
    InputStream is = getClass().getResourceAsStream("/examples/groupby/CreateGroupByDB.sql");
    try (Connection connection = DriverManager.getConnection(JDBC_URL, "sa", "")) {
        ScriptRunner sr = new ScriptRunner(connection);
        sr.setLogWriter(null);
        sr.runScript(new InputStreamReader(is));
    }

    UnpooledDataSource ds = new UnpooledDataSource(JDBC_DRIVER, JDBC_URL, "sa", "");
    Environment environment = new Environment("test", new JdbcTransactionFactory(), ds);
    Configuration config = new Configuration(environment);
    config.addMapper(GroupByMapper.class);
    sqlSessionFactory = new SqlSessionFactoryBuilder().build(config);
}

From source file:examples.joins.JoinMapperTest.java

License:Apache License

@BeforeEach
public void setup() throws Exception {
    Class.forName(JDBC_DRIVER);/*w  ww  .  j  av  a 2 s . c  o  m*/
    InputStream is = getClass().getResourceAsStream("/examples/joins/CreateJoinDB.sql");
    try (Connection connection = DriverManager.getConnection(JDBC_URL, "sa", "")) {
        ScriptRunner sr = new ScriptRunner(connection);
        sr.setLogWriter(null);
        sr.runScript(new InputStreamReader(is));
    }

    UnpooledDataSource ds = new UnpooledDataSource(JDBC_DRIVER, JDBC_URL, "sa", "");
    Environment environment = new Environment("test", new JdbcTransactionFactory(), ds);
    Configuration config = new Configuration(environment);
    config.addMapper(JoinMapper.class);
    sqlSessionFactory = new SqlSessionFactoryBuilder().build(config);
}

From source file:examples.paging.LimitAndOffsetTest.java

License:Apache License

@BeforeEach
public void setup() throws Exception {
    Class.forName(JDBC_DRIVER);//from   w ww.ja v a 2  s  .co  m
    InputStream is = getClass().getResourceAsStream("/examples/animal/data/CreateAnimalData.sql");
    try (Connection connection = DriverManager.getConnection(JDBC_URL, "sa", "")) {
        ScriptRunner sr = new ScriptRunner(connection);
        sr.setLogWriter(null);
        sr.runScript(new InputStreamReader(is));
    }

    UnpooledDataSource ds = new UnpooledDataSource(JDBC_DRIVER, JDBC_URL, "sa", "");
    Environment environment = new Environment("test", new JdbcTransactionFactory(), ds);
    Configuration config = new Configuration(environment);
    config.addMapper(LimitAndOffsetMapper.class);
    sqlSessionFactory = new SqlSessionFactoryBuilder().build(config);
}