Java Code Examples for org.apache.ibatis.plugin.Interceptor#setProperties()

The following examples show how to use org.apache.ibatis.plugin.Interceptor#setProperties() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ApiBootMybatisPageableAutoConfiguration.java    From beihu-boot with Apache License 2.0 6 votes vote down vote up
/**
 * init interceptors
 */
@PostConstruct
void addInterceptors() {
    Interceptor interceptor = new MyBatisExecutePageableInterceptor();
    // set properties to interceptor
    interceptor.setProperties(myBatisPageableProperties.getProperties());

    for (SqlSessionFactory sqlSessionFactory : sqlSessionFactoryList) {
        // pre
        addPreInterceptors(sqlSessionFactory);
        // mybatis pageable interceptor
        sqlSessionFactory.getConfiguration().addInterceptor(interceptor);
        // post
        addPostInterceptors(sqlSessionFactory);
    }
}
 
Example 2
Source File: ApiBootMybatisPageableAutoConfiguration.java    From api-boot with Apache License 2.0 6 votes vote down vote up
/**
 * init interceptors
 */
@PostConstruct
void addInterceptors() {
    Interceptor interceptor = new MyBatisExecutePageableInterceptor();
    // set properties to interceptor
    interceptor.setProperties(myBatisPageableProperties.getProperties());

    for (SqlSessionFactory sqlSessionFactory : sqlSessionFactoryList) {
        // pre
        addPreInterceptors(sqlSessionFactory);
        // mybatis pageable interceptor
        sqlSessionFactory.getConfiguration().addInterceptor(interceptor);
        // post
        addPostInterceptors(sqlSessionFactory);
    }
}
 
Example 3
Source File: ClusterDataSourceConfig.java    From springBoot-study with Apache License 2.0 6 votes vote down vote up
@Bean(name = "clusterSqlSessionFactory")
public SqlSessionFactory clusterSqlSessionFactory(@Qualifier("clusterDataSource") DataSource clusterDataSource)
        throws Exception {
    final SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
    sessionFactory.setDataSource(clusterDataSource);
    //分页插件
    Interceptor interceptor = new PageInterceptor();
    Properties properties = new Properties();
    //数据库
    properties.setProperty("helperDialect", "mysql");
    //是否将参数offset作为PageNum使用
    properties.setProperty("offsetAsPageNum", "true");
    //是否进行count查询
    properties.setProperty("rowBoundsWithCount", "true");
    //是否分页合理化
    properties.setProperty("reasonable", "false");
    interceptor.setProperties(properties);
    sessionFactory.setPlugins(new Interceptor[] {interceptor});
    
    
    sessionFactory.setMapperLocations(new PathMatchingResourcePatternResolver().getResources(ClusterDataSourceConfig.MAPPER_LOCATION));
    return sessionFactory.getObject();
}
 
Example 4
Source File: MasterDataSourceConfig.java    From springBoot-study with Apache License 2.0 5 votes vote down vote up
@Bean(name = "masterSqlSessionFactory")
@Primary
public SqlSessionFactory masterSqlSessionFactory(@Qualifier("masterDataSource") DataSource masterDataSource)
        throws Exception {
    final SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
    sessionFactory.setDataSource(masterDataSource);
    sessionFactory.setMapperLocations(new PathMatchingResourcePatternResolver()
            .getResources(MasterDataSourceConfig.MAPPER_LOCATION));
    //分页插件
    Interceptor interceptor = new PageInterceptor();
    Properties properties = new Properties();
    //数据库
    properties.setProperty("helperDialect", "mysql");
    //是否将参数offset作为PageNum使用
    properties.setProperty("offsetAsPageNum", "true");
    //是否进行count查询
    properties.setProperty("rowBoundsWithCount", "true");
    //是否分页合理化
    properties.setProperty("reasonable", "false");
    interceptor.setProperties(properties);
    sessionFactory.setPlugins(new Interceptor[] {interceptor});
    
    return sessionFactory.getObject();
}
 
Example 5
Source File: HierarchicalXMLConfigBuilder.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void pluginElement(XNode parent) throws Exception {
    if (parent != null) {
        for (XNode child : parent.getChildren()) {
            String interceptor = child.getStringAttribute("interceptor");
            Properties properties = child.getChildrenAsProperties();
            Interceptor interceptorInstance = (Interceptor) resolveClass(interceptor).newInstance();
            interceptorInstance.setProperties(properties);
            configuration.addInterceptor(interceptorInstance);
        }
    }
}
 
Example 6
Source File: XMLConfigBuilder.java    From mybaties with Apache License 2.0 5 votes vote down vote up
private void pluginElement(XNode parent) throws Exception {
  if (parent != null) {
    for (XNode child : parent.getChildren()) {
      String interceptor = child.getStringAttribute("interceptor");
      Properties properties = child.getChildrenAsProperties();
      Interceptor interceptorInstance = (Interceptor) resolveClass(interceptor).newInstance();
      interceptorInstance.setProperties(properties);
      //调用InterceptorChain.addInterceptor
      configuration.addInterceptor(interceptorInstance);
    }
  }
}
 
Example 7
Source File: XMLConfigBuilder.java    From mybatis with Apache License 2.0 5 votes vote down vote up
private void pluginElement(XNode parent) throws Exception {
  if (parent != null) {
    for (XNode child : parent.getChildren()) {
      String interceptor = child.getStringAttribute("interceptor");
      Properties properties = child.getChildrenAsProperties();
      Interceptor interceptorInstance = (Interceptor) resolveClass(interceptor).newInstance();
      interceptorInstance.setProperties(properties);
      //调用InterceptorChain.addInterceptor
      configuration.addInterceptor(interceptorInstance);
    }
  }
}
 
Example 8
Source File: XMLConfigBuilder.java    From QuickProject with Apache License 2.0 5 votes vote down vote up
private void pluginElement(XNode parent) throws Exception {
  if (parent != null) {
    for (XNode child : parent.getChildren()) {
      String interceptor = child.getStringAttribute("interceptor");
      Properties properties = child.getChildrenAsProperties();
      Interceptor interceptorInstance = (Interceptor) resolveClass(interceptor).newInstance();
      interceptorInstance.setProperties(properties);
      configuration.addInterceptor(interceptorInstance);
    }
  }
}