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

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

Introduction

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

Prototype

public boolean hasMapper(Class<?> type) 

Source Link

Usage

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

License:Apache License

/**
 * {@inheritDoc}/*w  w  w .  j av 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:fxapp01.orm.ORMBackendConnector.java

License:Apache License

private void checkORMapperClass(Class mapperClass, Object dao) {
    //?,   ? mapperClass  dao.
    //? ,  ? . ? , ??
    log.trace(">>> checkMapperClass");
    Configuration conf = getConfiguration();
    //conf.getMapperRegistry().getMappers();
    if (conf != null) {
        if (mapperClass == null) {
            if (dao != null) {
                // ??  ?.    - ? ?  ? MyBatis
                Class<?>[] itf = dao.getClass().getInterfaces();
                log.debug("Interfaces.length=" + itf.length);
                for (int i = 0; i < itf.length; i++) {
                    log.debug("Interfaces[" + i + "]=" + itf[i].getName());
                    if (conf.hasMapper(itf[i])) {
                        mapperClass = itf[i];
                        log.debug("mapperClass=" + mapperClass.getName());
                        break;
                    }/*from  w  w w  . j  a v a  2 s. c  om*/
                }
            } else {
                throw new IllegalArgumentException("Wrong parameter dao = NULL");
            }
        } else {
            if (!conf.hasMapper(mapperClass)) {
                throw new IllegalArgumentException("Wrong mapperClass=" + mapperClass.getName());
            } else {
                log.debug("mapperClass=" + mapperClass.getName());
            }
        }
    } else {
        log.debug("getConfiguration == null. checkMapperClass failed.");
    }
}

From source file:org.jessma.dao.mybatis.MyBatisSessionMgr.java

License:Apache License

/**  {@link SqlSessionFactory} */
private void buildSessionFactory() {
    synchronized (this) {
        if (sessionFactory == null) {
            try {
                Reader reader = Resources.getResourceAsReader(configFile);
                sessionFactory = new SqlSessionFactoryBuilder().build(reader, environment);

                if (GeneralHelper.isStrNotEmpty(pattern)) {
                    Set<String> packages = PackageHelper.getPackages(pattern);

                    for (String pkg : packages) {
                        Set<Class<?>> entities = PackageHelper.getClasses(pkg, false, new ClassFilter() {
                            @Override
                            public boolean accept(Class<?> clazz) {
                                if (!BeanHelper.isPublicInterface(clazz))
                                    return false;

                                return true;
                            }/*w  w  w  .jav  a  2  s.  c om*/
                        });

                        Configuration cfg = sessionFactory.getConfiguration();

                        for (Class<?> clazz : entities) {
                            if (!cfg.hasMapper(clazz))
                                cfg.addMapper(clazz);
                        }
                    }
                }
            } catch (IOException e) {
                throw new SqlSessionException(e);
            }
        }
    }
}

From source file:org.mybatis.guice.configuration.settings.MapperConfigurationSetting.java

License:Apache License

public void applyConfigurationSetting(Configuration configuration) {
    if (!configuration.hasMapper(mapperClass)) {
        configuration.addMapper(mapperClass);
    }/*from w  ww  . j  av  a2  s  .com*/
}

From source file:org.mybatis.spring.mapper.MapperFactoryBean.java

License:Apache License

/**
 * {@inheritDoc}//from  ww  w  .  j  av  a 2s .  c  o  m
 */
@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 (Exception e) {
            logger.error("Error while adding the mapper '" + this.mapperInterface + "' to configuration.", e);
            throw new IllegalArgumentException(e);
        } finally {
            ErrorContext.instance().reset();
        }
    }
}

From source file:org.sonar.core.persistence.MyBatisTest.java

License:Open Source License

@Test
public void shouldConfigureMyBatis() {
    MyBatis myBatis = new MyBatis(database, logback, queue);
    myBatis.start();//from w  w w.  j  ava  2 s .  com

    Configuration conf = myBatis.getSessionFactory().getConfiguration();
    assertThat(conf.isUseGeneratedKeys(), Is.is(true));
    assertThat(conf.hasMapper(RuleMapper.class), Is.is(true));
    assertThat(conf.isLazyLoadingEnabled(), Is.is(false));
}

From source file:org.sonar.db.MyBatisTest.java

License:Open Source License

@Test
public void shouldConfigureMyBatis() {
    MyBatis myBatis = new MyBatis(database);
    myBatis.start();//  ww  w . j  av a2  s.c om

    Configuration conf = myBatis.getSessionFactory().getConfiguration();
    assertThat(conf.isUseGeneratedKeys(), Is.is(true));
    assertThat(conf.hasMapper(RuleMapper.class), Is.is(true));
    assertThat(conf.isLazyLoadingEnabled(), Is.is(false));
}