Example usage for org.apache.ibatis.session SqlSessionFactory getConfiguration

List of usage examples for org.apache.ibatis.session SqlSessionFactory getConfiguration

Introduction

In this page you can find the example usage for org.apache.ibatis.session SqlSessionFactory getConfiguration.

Prototype

Configuration getConfiguration();

Source Link

Usage

From source file:com.baomidou.mybatisplus.entity.GlobalConfiguration.java

License:Apache License

/**
 * <p>//from w w w. j av  a  2  s .  c  o  m
 *  (?)
 * </p>
 *
 * @param sqlSessionFactory
 * @return
 */
public SqlSessionFactory signGlobalConfig(SqlSessionFactory sqlSessionFactory) {
    if (null != sqlSessionFactory) {
        setGlobalConfig(sqlSessionFactory.getConfiguration(), this);
    }
    return sqlSessionFactory;
}

From source file:com.baomidou.mybatisplus.mapper.SqlHelper.java

License:Apache License

/**
 * ?sqlSession//from w  w w  . j  av a  2 s. c  om
 *
 * @param clazz
 * @return
 */
private static SqlSession getSqlSession(Class<?> clazz) {
    SqlSession session = null;
    try {
        SqlSessionFactory sqlSessionFactory = GlobalConfiguration.currentSessionFactory(clazz);
        Configuration configuration = sqlSessionFactory.getConfiguration();
        session = GlobalConfiguration.getGlobalConfig(configuration).getSqlSession();
    } catch (Exception e) {
        // ignored
    }
    return session;
}

From source file:com.baomidou.mybatisplus.MybatisSqlSessionTemplate.java

License:Apache License

/**
 * Constructs a Spring managed SqlSession with the {@code SqlSessionFactory}
 * provided as an argument.//from   w w w .  j  av a  2 s .  co  m
 *
 * @param sqlSessionFactory
 */
public MybatisSqlSessionTemplate(SqlSessionFactory sqlSessionFactory) {
    this(sqlSessionFactory, sqlSessionFactory.getConfiguration().getDefaultExecutorType());
}

From source file:com.baomidou.mybatisplus.MybatisSqlSessionTemplate.java

License:Apache License

/**
 * Constructs a Spring managed SqlSession with the {@code SqlSessionFactory}
 * provided as an argument and the given {@code ExecutorType}
 * {@code ExecutorType} cannot be changed once the
 * {@code SqlSessionTemplate} is constructed.
 *
 * @param sqlSessionFactory/*from  www  .  jav  a  2  s  . co m*/
 * @param executorType
 */
public MybatisSqlSessionTemplate(SqlSessionFactory sqlSessionFactory, ExecutorType executorType) {
    this(sqlSessionFactory, executorType, new MyBatisExceptionTranslator(
            sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), true));
}

From source file:com.baomidou.mybatisplus.spring.MybatisMapperRefresh.java

License:Apache License

public MybatisMapperRefresh(Resource[] mapperLocations, SqlSessionFactory sqlSessionFactory, int delaySeconds,
        int sleepSeconds, boolean enabled) {
    this.mapperLocations = mapperLocations.clone();
    this.sqlSessionFactory = sqlSessionFactory;
    this.delaySeconds = delaySeconds;
    this.enabled = enabled;
    this.sleepSeconds = sleepSeconds;
    this.configuration = sqlSessionFactory.getConfiguration();
    this.run();//from ww  w.  j  ava 2 s.  com
}

From source file:com.baomidou.mybatisplus.spring.MybatisMapperRefresh.java

License:Apache License

public MybatisMapperRefresh(Resource[] mapperLocations, SqlSessionFactory sqlSessionFactory, boolean enabled) {
    this.mapperLocations = mapperLocations.clone();
    this.sqlSessionFactory = sqlSessionFactory;
    this.enabled = enabled;
    this.configuration = sqlSessionFactory.getConfiguration();
    this.run();/*from   w w w .  j a va 2s  . c om*/
}

From source file:com.baomidou.mybatisplus.toolkit.TableInfoHelper.java

License:Apache License

/**
 * ?SqlSessionFactory (Mybatis)/*  w  w w.j  a  v a 2  s  .c om*/
 *
 * @param sqlSessionFactory
 * @return
 */
public static void initSqlSessionFactory(SqlSessionFactory sqlSessionFactory) {
    Configuration configuration = sqlSessionFactory.getConfiguration();
    GlobalConfiguration globalConfig = GlobalConfiguration.getGlobalConfig(configuration);
    // SqlRunner
    SqlRunner.FACTORY = sqlSessionFactory;
    if (globalConfig == null) {
        GlobalConfiguration defaultCache = GlobalConfiguration.defaults();
        defaultCache.setSqlSessionFactory(sqlSessionFactory);
        GlobalConfiguration.setGlobalConfig(configuration, defaultCache);
    } else {
        globalConfig.setSqlSessionFactory(sqlSessionFactory);
    }
}

From source file:com.bibisco.dao.SqlSessionFactoryManager.java

License:GNU General Public License

public void cleanSqlSessionFactoryProject() {

    mLog.debug("Start cleanSqlSessionFactoryProject()");

    Validate.notEmpty(ContextManager.getInstance().getIdProject(), "There is no project in context");

    String lStrProjectId = ContextManager.getInstance().getIdProject();
    SqlSessionFactory lSqlSessionFactoryProject = mMapSqlSessionFactoryProjects.get(lStrProjectId);
    PooledDataSource lPooledDataSource = (PooledDataSource) lSqlSessionFactoryProject.getConfiguration()
            .getEnvironment().getDataSource();
    lPooledDataSource.forceCloseAll();/*from  w ww . j  av  a  2s .  c  o m*/
    mMapSqlSessionFactoryProjects.remove(lStrProjectId);

    mLog.debug("End cleanSqlSessionFactoryProject()");
}

From source file:com.bibisco.manager.ProjectManager.java

License:GNU General Public License

public static void closeConnection() {

    mLog.debug("Start closeConnection()");

    SqlSessionFactory lSqlSessionFactory = SqlSessionFactoryManager.getInstance().getSqlSessionFactoryProject();
    Configuration lConfiguration = lSqlSessionFactory.getConfiguration();
    Environment lEnvironment = lConfiguration.getEnvironment();
    DataSource lDataSource = lEnvironment.getDataSource();

    //production/*from   w  w w . java2 s. c  om*/
    if (lDataSource instanceof PooledDataSource) {
        ((PooledDataSource) lDataSource).forceCloseAll();
    }
    //test
    else if (lDataSource instanceof JdbcDataSource) {
        try {
            lDataSource.getConnection().close();
        } catch (Throwable t) {
            mLog.error(t);
            throw new BibiscoException(t, BibiscoException.SQL_EXCEPTION);
        }
    }

    mLog.debug("End closeConnection()");
}

From source file:com.funtl.framework.smoke.core.commons.supcan.SupcanController.java

License:Apache License

/**
 * ?????XML/*from  w  ww . j a  v a 2 s . c  o m*/
 *
 * @return
 */
@RequestMapping(value = "treeList/{typeAlias}.xml")
@ResponseBody
public TreeList treeList(@PathVariable("typeAlias") String typeAlias) {

    // CacheCache
    boolean useCache = Global.getConfig("supcan.useCache") == "true";
    if (useCache) {
        Object object = CacheUtils.get(SUPCAN_CACHE, typeAlias);
        if (object != null) {
            return (TreeList) object;
        }
    }

    // 
    Class<?> clazz;

    try {
        // ????MyBaits
        SqlSessionFactory sqlSessionFactory = SpringContextHolder.getBean(SqlSessionFactory.class);
        clazz = sqlSessionFactory.getConfiguration().getTypeAliasRegistry().resolveAlias(typeAlias);
    } catch (Exception e) {
        // ??
        return null;
    }

    // ??
    SupTreeList supTreeList = clazz.getAnnotation(SupTreeList.class);

    // ?
    if (supTreeList == null) {
        return null;
    }

    // 
    TreeList treeList = new TreeList(supTreeList);

    // ?
    Map<String, Group> groupMap = Maps.newHashMap();
    if (supTreeList != null && supTreeList.groups() != null) {
        for (SupGroup supGroup : supTreeList.groups()) {
            groupMap.put(supGroup.id(), new Group(supGroup));
        }
    }

    // ?
    List<Object> cols = treeList.getCols();
    for (Method m : clazz.getMethods()) {
        SupCol supCol = m.getAnnotation(SupCol.class);
        if (supCol != null) {

            // Col
            Col col = new Col(supCol);
            if (StringUtils.isBlank(col.getName())) {
                col.setName(StringUtils.uncapitalize(StringUtils.substring(m.getName(), 3)));
            }

            // 
            if (StringUtils.isBlank(supCol.groupId())) {
                cols.add(col);
            }
            // 
            else {
                Group group = groupMap.get(supCol.groupId());
                if (group != null) {
                    group.getCols().add(col);
                }
            }
        }
    }

    // ?
    Comparator<Object> comparator = new Comparator<Object>() {
        @Override
        public int compare(Object o1, Object o2) {
            int sort1 = 0, sort2 = 0;
            if (o1 instanceof Group) {
                sort1 = ((Group) o1).getSort();
            } else if (o1 instanceof Col) {
                sort1 = ((Col) o1).getSort();
            }
            if (o2 instanceof Group) {
                sort2 = ((Group) o2).getSort();
            } else if (o2 instanceof Col) {
                sort2 = ((Col) o2).getSort();
            }
            return new Integer(sort1).compareTo(new Integer(sort2));
        }
    };

    // ??
    listToTree(cols, groupMap, null, comparator);

    // ?
    Collections.sort(cols, comparator);

    // Cache?Cache
    if (useCache) {
        CacheUtils.put(SUPCAN_CACHE, typeAlias, treeList);
    }

    return treeList;
}