org.apache.ibatis.plugin.Interceptor Java Examples

The following examples show how to use org.apache.ibatis.plugin.Interceptor. 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: FramedbConfig.java    From erp-framework with MIT License 6 votes vote down vote up
@Bean(name = "framedbSqlSessionFactory")
public SqlSessionFactory testSqlSessionFactory(@Qualifier("framedbDataSource") DataSource dataSource) throws Exception {
    SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
    bean.setPlugins(new Interceptor[]{ sqlInterceptor});

    bean.setDataSource(dataSource);

    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();

    Resource[] res = resolver.getResources("classpath:mapper/**");
    for (int i =0;i< res.length;i++) {
        if(res[i].getFilename().indexOf("xml")==-1){
            res[i] = null;
        }
    }
    bean.setMapperLocations(res);

    return bean.getObject();
}
 
Example #2
Source File: Cluster1DruidDataSourceConfig.java    From SpringBoot-Study with Apache License 2.0 6 votes vote down vote up
/**
 * SqlSessionFactory配置
 *
 * @return
 * @throws Exception
 */
@Bean(name = "cluster1SqlSessionFactory")
public SqlSessionFactory cluster1SqlSessionFactory(
        @Qualifier("cluster1DataSource") DataSource dataSource
) throws Exception {
    SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
    sqlSessionFactoryBean.setDataSource(dataSource);

    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    //配置mapper文件位置
    sqlSessionFactoryBean.setMapperLocations(resolver.getResources(cluster1MapperLocations));

    //配置分页插件
    PageHelper pageHelper = new PageHelper();
    Properties properties = new Properties();
    properties.setProperty("reasonable", "true");
    properties.setProperty("supportMethodsArguments", "true");
    properties.setProperty("returnPageInfo", "check");
    properties.setProperty("params", "count=countSql");
    pageHelper.setProperties(properties);

    //设置插件
    sqlSessionFactoryBean.setPlugins(new Interceptor[]{pageHelper});
    return sqlSessionFactoryBean.getObject();
}
 
Example #3
Source File: AbstractDataBaseBean.java    From spring-boot-starter-dao with Apache License 2.0 6 votes vote down vote up
protected final AbstractBeanDefinition createSqlSessionFactoryBean(String dataSourceName, String mapperPackage,
		String typeAliasesPackage, Dialect dialect, Configuration configuration) {
	configuration.setDatabaseId(dataSourceName);
	BeanDefinitionBuilder bdb = BeanDefinitionBuilder.rootBeanDefinition(SqlSessionFactoryBean.class);
	bdb.addPropertyValue("configuration", configuration);
	bdb.addPropertyValue("failFast", true);
	bdb.addPropertyValue("typeAliases", this.saenTypeAliases(typeAliasesPackage));
	bdb.addPropertyReference("dataSource", dataSourceName);
	bdb.addPropertyValue("plugins", new Interceptor[] { new CustomPageInterceptor(dialect) });
	if (!StringUtils.isEmpty(mapperPackage)) {
		try {
			mapperPackage = new StandardEnvironment().resolveRequiredPlaceholders(mapperPackage);
			String mapperPackages = ClassUtils.convertClassNameToResourcePath(mapperPackage);
			String mapperPackagePath = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX + mapperPackages + "/*.xml";
			Resource[] resources = new PathMatchingResourcePatternResolver().getResources(mapperPackagePath);
			bdb.addPropertyValue("mapperLocations", resources);
		} catch (Exception e) {
			log.error("初始化失败", e);
			throw new RuntimeException( String.format("SqlSessionFactory 初始化失败  mapperPackage=%s", mapperPackage + ""));
		}
	}
	return bdb.getBeanDefinition();
}
 
Example #4
Source File: DataSource1Config.java    From Resource with GNU General Public License v3.0 6 votes vote down vote up
@Bean(name = "db1SqlSessionFactory")
public SqlSessionFactory setSqlSessionFactory(@Qualifier("db1DataSource") DataSource dataSource,
                                              @Qualifier("db1Configuration") org.apache.ibatis.session.Configuration configuration)
    throws Exception
{
    String url = "classpath:com/zsm/mapper/db1/*.xml";
    SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
    bean.setDataSource(dataSource);
    bean.setConfiguration(configuration);
    bean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources(url));
    org.apache.ibatis.session.Configuration config = new org.apache.ibatis.session.Configuration();
    config.setMapUnderscoreToCamelCase(true); // 开启驼峰命名支持
    bean.setConfiguration(config);
    //格式化sql语句打印
    PerformanceInterceptor performanceInterceptor = new PerformanceInterceptor();
    Properties properties = new Properties();
    properties.setProperty("format", "true");
    performanceInterceptor.setProperties(properties);
    bean.setPlugins(new Interceptor[] {performanceInterceptor});
    return bean.getObject();
}
 
Example #5
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 #6
Source File: MasterDataSourceConfig.java    From springBoot-study with Apache License 2.0 6 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);
    //分页插件
    PageHelper pageHelper = new PageHelper();  
    Properties properties = new Properties();
    //数据库
    properties.setProperty("helperDialect", "mysql");
    //是否将参数offset作为PageNum使用
    properties.setProperty("offsetAsPageNum", "true");
    //是否进行count查询
    properties.setProperty("rowBoundsWithCount", "true");
    //是否分页合理化
    properties.setProperty("reasonable", "false");
    pageHelper.setProperties(properties);
    sessionFactory.setPlugins(new Interceptor[] {pageHelper});
    
    return sessionFactory.getObject();
}
 
Example #7
Source File: DataSource2Config.java    From Resource with GNU General Public License v3.0 6 votes vote down vote up
@Bean(name = "db2SqlSessionFactory")
public SqlSessionFactory setSqlSessionFactory(@Qualifier("db2DataSource") DataSource dataSource,
                                              @Qualifier("db2Configuration") org.apache.ibatis.session.Configuration configuration)
    throws Exception
{
    String url = "classpath:com/zsm/mapper/db2/*.xml";
    SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
    bean.setDataSource(dataSource);
    bean.setConfiguration(configuration);
    bean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources(url));
    org.apache.ibatis.session.Configuration config = new org.apache.ibatis.session.Configuration();
    config.setMapUnderscoreToCamelCase(true); // 开启驼峰命名支持
    bean.setConfiguration(config);
    //格式化sql语句打印
    PerformanceInterceptor performanceInterceptor = new PerformanceInterceptor();
    Properties properties = new Properties();
    properties.setProperty("format", "true");
    performanceInterceptor.setProperties(properties);
    bean.setPlugins(new Interceptor[] {performanceInterceptor});
    return bean.getObject();
}
 
Example #8
Source File: DruidDataSourceConfig.java    From xxpay-master with MIT License 6 votes vote down vote up
@Bean
public SqlSessionFactory sqlSessionFactory() throws Exception {
    SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
    sqlSessionFactoryBean.setDataSource(dataSource());
    //mybatis分页
    PageHelper pageHelper = new PageHelper();
    Properties props = new Properties();
    props.setProperty("dialect", "mysql");
    props.setProperty("reasonable", "true");
    props.setProperty("supportMethodsArguments", "true");
    props.setProperty("returnPageInfo", "check");
    props.setProperty("params", "count=countSql");
    pageHelper.setProperties(props); //添加插件
    sqlSessionFactoryBean.setPlugins(new Interceptor[]{pageHelper});
    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    sqlSessionFactoryBean.setMapperLocations(resolver.getResources("classpath:org/xxpay/dal/dao/mapper/*.xml"));
    return sqlSessionFactoryBean.getObject();
}
 
Example #9
Source File: DruidDataSourceConfig.java    From xxpay-master with MIT License 6 votes vote down vote up
@Bean
public SqlSessionFactory sqlSessionFactory() throws Exception {
    SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
    sqlSessionFactoryBean.setDataSource(dataSource());
    //mybatis分页
    PageHelper pageHelper = new PageHelper();
    Properties props = new Properties();
    props.setProperty("dialect", "mysql");
    props.setProperty("reasonable", "true");
    props.setProperty("supportMethodsArguments", "true");
    props.setProperty("returnPageInfo", "check");
    props.setProperty("params", "count=countSql");
    pageHelper.setProperties(props); //添加插件
    sqlSessionFactoryBean.setPlugins(new Interceptor[]{pageHelper});
    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    sqlSessionFactoryBean.setMapperLocations(resolver.getResources("classpath:org/xxpay/shop/dao/mapper/*.xml"));
    return sqlSessionFactoryBean.getObject();
}
 
Example #10
Source File: ClusterDruidDataSourceConfig.java    From SpringBoot-Study with Apache License 2.0 6 votes vote down vote up
/**
 * SqlSessionFactory配置
 *
 * @return
 * @throws Exception
 */
@Bean(name = "clusterSqlSessionFactory")
public SqlSessionFactory clusterSqlSessionFactory(
        @Qualifier("clusterDataSource") DataSource dataSource
) throws Exception {
    SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
    sqlSessionFactoryBean.setDataSource(dataSource);

    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    //配置mapper文件位置
    sqlSessionFactoryBean.setMapperLocations(resolver.getResources(clusterMapperLocations));

    //配置分页插件
    PageHelper pageHelper = new PageHelper();
    Properties properties = new Properties();
    properties.setProperty("reasonable", "true");
    properties.setProperty("supportMethodsArguments", "true");
    properties.setProperty("returnPageInfo", "check");
    properties.setProperty("params", "count=countSql");
    pageHelper.setProperties(properties);

    //设置插件
    sqlSessionFactoryBean.setPlugins(new Interceptor[]{pageHelper});
    return sqlSessionFactoryBean.getObject();
}
 
Example #11
Source File: MybatisConfigurer.java    From spring-boot-api-project-seed with Apache License 2.0 6 votes vote down vote up
@Bean
public SqlSessionFactory sqlSessionFactoryBean(DataSource dataSource) throws Exception {
    PackagesSqlSessionFactoryBean sqlSessionFactory = new PackagesSqlSessionFactoryBean();
    sqlSessionFactory.setDataSource(dataSource);
    sqlSessionFactory.setTypeAliasesPackage(TYPE_ALIASES_PACKAGE);

    //配置分页插件,详情请查阅官方文档
    PageInterceptor interceptor = new PageInterceptor();
    Properties properties = new Properties();
    //分页尺寸为0时查询所有纪录不再执行分页
    properties.setProperty("pageSizeZero", "true");
    //页码<=0 查询第一页,页码>=总页数查询最后一页
    properties.setProperty("reasonable", "true");
    //支持通过 Mapper 接口参数来传递分页参数
    properties.setProperty("supportMethodsArguments", "true");
    interceptor.setProperties(properties);

    //添加插件
    //为了防止插件被重复注册,可以在启动类中使用"@SpringBootApplication(exclude = PageHelperAutoConfiguration.class)"排除默认的配置
    sqlSessionFactory.setPlugins(new Interceptor[]{interceptor});

    //添加XML目录
    ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    sqlSessionFactory.setMapperLocations(resolver.getResources("classpath:mapper/*.xml"));
    return sqlSessionFactory.getObject();
}
 
Example #12
Source File: DataSourceAutoConfiguration.java    From super-cloudops with Apache License 2.0 6 votes vote down vote up
@Bean
public SqlSessionFactoryBean SqlSessionFactoryBean(DataSource dataSource) throws Exception {
	// Define path matcher resolver.
	PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();

	// SqlSessionFactory
	SqlSessionFactoryBean factory = new MultipleSqlSessionFactoryBean();
	factory.setDataSource(dataSource);
	factory.setTypeAliases(getTypeAliases(resolver));
	factory.setConfigLocation(new ClassPathResource(configLocation));

	// Page.
	PageHelper pageHelper = new PageHelper();
	Properties props = new Properties();
	props.setProperty("dialect", "mysql");
	props.setProperty("reasonable", "true");
	props.setProperty("supportMethodsArguments", "true");
	props.setProperty("returnPageInfo", "check");
	props.setProperty("params", "count=countSql");
	pageHelper.setProperties(props); // 添加插件
	factory.setPlugins(new Interceptor[] { pageHelper });

	factory.setMapperLocations(resolver.getResources(mapperLocations));
	return factory;
}
 
Example #13
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 #14
Source File: MasterDruidDataSourceConfig.java    From SpringBoot-Study with Apache License 2.0 6 votes vote down vote up
/**
 * SqlSessionFactory配置
 *
 * @return
 * @throws Exception
 */
@Bean(name = "masterSqlSessionFactory")
@Primary
public SqlSessionFactory masterSqlSessionFactory(
        @Qualifier("masterDataSource") DataSource dataSource
) throws Exception {
    SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
    sqlSessionFactoryBean.setDataSource(dataSource);

    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    // 配置mapper文件位置
    sqlSessionFactoryBean.setMapperLocations(resolver.getResources(masterMapperLocations));

    //配置分页插件
    PageHelper pageHelper = new PageHelper();
    Properties properties = new Properties();
    properties.setProperty("reasonable", "true");
    properties.setProperty("supportMethodsArguments", "true");
    properties.setProperty("returnPageInfo", "check");
    properties.setProperty("params", "count=countSql");
    pageHelper.setProperties(properties);

    //设置插件
    sqlSessionFactoryBean.setPlugins(new Interceptor[]{pageHelper});
    return sqlSessionFactoryBean.getObject();
}
 
Example #15
Source File: Read1DruidDataSourceConfig.java    From SpringBoot-Study with Apache License 2.0 6 votes vote down vote up
/**
 * SqlSessionFactory配置
 *
 * @return
 * @throws Exception
 */
@Bean(name = "read1SqlSessionFactory")
public SqlSessionFactory read1SqlSessionFactory(
        @Qualifier("read1DataSource") DataSource dataSource
) throws Exception {
    SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
    sqlSessionFactoryBean.setDataSource(dataSource);

    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    // 配置mapper文件位置
    sqlSessionFactoryBean.setMapperLocations(resolver.getResources(read1MapperLocations));

    //配置分页插件
    PageHelper pageHelper = new PageHelper();
    Properties properties = new Properties();
    properties.setProperty("reasonable", "true");
    properties.setProperty("supportMethodsArguments", "true");
    properties.setProperty("returnPageInfo", "check");
    properties.setProperty("params", "count=countSql");
    pageHelper.setProperties(properties);

    //设置插件
    sqlSessionFactoryBean.setPlugins(new Interceptor[]{pageHelper});
    return sqlSessionFactoryBean.getObject();
}
 
Example #16
Source File: Read2DruidDataSourceConfig.java    From SpringBoot-Study with Apache License 2.0 6 votes vote down vote up
/**
 * SqlSessionFactory配置
 *
 * @return
 * @throws Exception
 */
@Bean(name = "read2SqlSessionFactory")
public SqlSessionFactory read2SqlSessionFactory(
        @Qualifier("read2DataSource") DataSource dataSource
) throws Exception {
    SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
    sqlSessionFactoryBean.setDataSource(dataSource);

    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    // 配置mapper文件位置
    sqlSessionFactoryBean.setMapperLocations(resolver.getResources(read2MapperLocations));

    //配置分页插件
    PageHelper pageHelper = new PageHelper();
    Properties properties = new Properties();
    properties.setProperty("reasonable", "true");
    properties.setProperty("supportMethodsArguments", "true");
    properties.setProperty("returnPageInfo", "check");
    properties.setProperty("params", "count=countSql");
    pageHelper.setProperties(properties);

    //设置插件
    sqlSessionFactoryBean.setPlugins(new Interceptor[]{pageHelper});
    return sqlSessionFactoryBean.getObject();
}
 
Example #17
Source File: GjpaymentDatabaseConfig.java    From maintain with MIT License 6 votes vote down vote up
@Bean(name = "gjpaymentSqlSessionFactory")
public SqlSessionFactory gjpaymentSqlSessionFactory() throws Exception {
	SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
	logger.info("gjpayment sqlsession--" + this.gjpaymentDataSource().hashCode());
	sqlSessionFactoryBean.setDataSource(this.gjpaymentDataSource());
	PageHelper pageHelper = new PageHelper();
	Properties properties = new Properties();
	properties.setProperty("dialect", "oracle");
	properties.setProperty("pageSizeZero", "true");
	properties.setProperty("reasonable", "false");
	properties.setProperty("params", "pageNum=pageHelperStart;pageSize=pageHelperRows;");
	properties.setProperty("supportMethodsArguments", "true");
	properties.setProperty("returnPageInfo", "none");
	pageHelper.setProperties(properties);
	Interceptor[] interceptors = new Interceptor[] { pageHelper };
	sqlSessionFactoryBean.setPlugins(interceptors);
	return sqlSessionFactoryBean.getObject();
}
 
Example #18
Source File: GjentDatabaseConfig.java    From maintain with MIT License 6 votes vote down vote up
@Bean(name = "gjentSqlSessionFactory")
public SqlSessionFactory gjentSqlSessionFactory() throws Exception {
	SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
	logger.info("gjent sqlsession--" + this.gjentDataSource().hashCode());
	sqlSessionFactoryBean.setDataSource(this.gjentDataSource());
	PageHelper pageHelper = new PageHelper();
	Properties properties = new Properties();
	properties.setProperty("dialect", "oracle");
	properties.setProperty("pageSizeZero", "true");
	properties.setProperty("reasonable", "false");
	properties.setProperty("params", "pageNum=pageHelperStart;pageSize=pageHelperRows;");
	properties.setProperty("supportMethodsArguments", "true");
	properties.setProperty("returnPageInfo", "none");
	pageHelper.setProperties(properties);
	Interceptor[] interceptors = new Interceptor[] { pageHelper };
	sqlSessionFactoryBean.setPlugins(interceptors);
	return sqlSessionFactoryBean.getObject();
}
 
Example #19
Source File: ParaDatabaseConfig.java    From maintain with MIT License 6 votes vote down vote up
@Bean(name = "paraSqlSessionFactory")
public SqlSessionFactory paraSqlSessionFactory() throws Exception {
	SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
	logger.info("para sqlsession--" + this.paraDataSource().hashCode());
	sqlSessionFactoryBean.setDataSource(this.paraDataSource());
	PageHelper pageHelper = new PageHelper();
	Properties properties = new Properties();
	properties.setProperty("dialect", "oracle");
	properties.setProperty("pageSizeZero", "true");
	properties.setProperty("reasonable", "false");
	properties.setProperty("params", "pageNum=pageHelperStart;pageSize=pageHelperRows;");
	properties.setProperty("supportMethodsArguments", "true");
	properties.setProperty("returnPageInfo", "none");
	pageHelper.setProperties(properties);
	Interceptor[] interceptors = new Interceptor[] { pageHelper };
	sqlSessionFactoryBean.setPlugins(interceptors);
	return sqlSessionFactoryBean.getObject();
}
 
Example #20
Source File: MhinDatabaseConfig.java    From maintain with MIT License 6 votes vote down vote up
@Bean(name = "mhinSqlSessionFactory")
public SqlSessionFactory mhinSqlSessionFactory() throws Exception {
	SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
	logger.info("mhin sqlsession--" + this.mhinDataSource().hashCode());
	sqlSessionFactoryBean.setDataSource(this.mhinDataSource());
	PageHelper pageHelper = new PageHelper();
	Properties properties = new Properties();
	properties.setProperty("dialect", "oracle");
	properties.setProperty("pageSizeZero", "true");
	properties.setProperty("reasonable", "false");
	properties.setProperty("params", "pageNum=pageHelperStart;pageSize=pageHelperRows;");
	properties.setProperty("supportMethodsArguments", "true");
	properties.setProperty("returnPageInfo", "none");
	pageHelper.setProperties(properties);
	Interceptor[] interceptors = new Interceptor[] { pageHelper };
	sqlSessionFactoryBean.setPlugins(interceptors);
	return sqlSessionFactoryBean.getObject();
}
 
Example #21
Source File: EcssentDatabaseConfig.java    From maintain with MIT License 6 votes vote down vote up
@Primary
@Bean(name = "ecssentSqlSessionFactory")
public SqlSessionFactory ecssentSqlSessionFactory() throws Exception {
	SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
	logger.info("ecssent sqlsession--" + this.ecssentDataSource().hashCode());
	sqlSessionFactoryBean.setDataSource(this.ecssentDataSource());
	PageHelper pageHelper = new PageHelper();
	Properties properties = new Properties();
	properties.setProperty("dialect", "oracle");
	properties.setProperty("pageSizeZero", "true");
	properties.setProperty("reasonable", "false");
	properties.setProperty("params", "pageNum=pageHelperStart;pageSize=pageHelperRows;");
	properties.setProperty("supportMethodsArguments", "true");
	properties.setProperty("returnPageInfo", "none");
	pageHelper.setProperties(properties);
	Interceptor[] interceptors = new Interceptor[] { pageHelper };
	sqlSessionFactoryBean.setPlugins(interceptors);
	return sqlSessionFactoryBean.getObject();
}
 
Example #22
Source File: MhoutDatabaseConfig.java    From maintain with MIT License 6 votes vote down vote up
@Bean(name = "mhoutSqlSessionFactory")
public SqlSessionFactory mhoutSqlSessionFactory() throws Exception {
	SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
	logger.info("mhout sqlsession--" + this.mhoutDataSource().hashCode());
	sqlSessionFactoryBean.setDataSource(this.mhoutDataSource());
	PageHelper pageHelper = new PageHelper();
	Properties properties = new Properties();
	properties.setProperty("dialect", "oracle");
	properties.setProperty("pageSizeZero", "true");
	properties.setProperty("reasonable", "false");
	properties.setProperty("params", "pageNum=pageHelperStart;pageSize=pageHelperRows;");
	properties.setProperty("supportMethodsArguments", "true");
	properties.setProperty("returnPageInfo", "none");
	pageHelper.setProperties(properties);
	Interceptor[] interceptors = new Interceptor[] { pageHelper };
	sqlSessionFactoryBean.setPlugins(interceptors);
	return sqlSessionFactoryBean.getObject();
}
 
Example #23
Source File: MyBatisConfig.java    From cc-s with MIT License 6 votes vote down vote up
@Bean
public SqlSessionFactoryBean createSqlSessionFactoryBean() throws IOException {
    SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
    sqlSessionFactoryBean.setConfigLocation(new ClassPathResource(env.getProperty("mybatis.config-location")));
    PathMatchingResourcePatternResolver pathMatchingResourcePatternResolver = new PathMatchingResourcePatternResolver();
    String packageSearchPath = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX + env.getProperty("mybatis.mapper-locations");
    sqlSessionFactoryBean.setMapperLocations(pathMatchingResourcePatternResolver.getResources(packageSearchPath));
    sqlSessionFactoryBean.setDataSource(dataSource());

    PageHelper pageHelper = new PageHelper();
    Properties properties = new Properties();
    properties.setProperty("reasonable", env.getProperty("pageHelper.reasonable"));
    properties.setProperty("supportMethodsArguments", env.getProperty("pageHelper.supportMethodsArguments"));
    properties.setProperty("returnPageInfo", env.getProperty("pageHelper.returnPageInfo"));
    properties.setProperty("params", env.getProperty("pageHelper.params"));
    pageHelper.setProperties(properties);
    sqlSessionFactoryBean.setPlugins(new Interceptor[]{pageHelper});

    return sqlSessionFactoryBean;
}
 
Example #24
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 #25
Source File: MyBatisConfig.java    From jim-framework with Apache License 2.0 5 votes vote down vote up
@Bean(name = "sqlSessionFactory")
public SqlSessionFactory sqlSessionFactoryBean() {
    SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
    bean.setDataSource(dataSource);
    bean.setTypeAliasesPackage("com.jim.dao.generated.entity");

    //分页插件
    PageHelper pageHelper = new PageHelper();
    Properties properties = new Properties();
    properties.setProperty("dialect", "postgresql");
    properties.setProperty("reasonable", "true");
    properties.setProperty("supportMethodsArguments", "true");
    properties.setProperty("returnPageInfo", "check");
    properties.setProperty("params", "count=countSql");
    pageHelper.setProperties(properties);

    //添加插件
    bean.setPlugins(new Interceptor[]{pageHelper});

    //添加XML目录
    ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    try {
        bean.setMapperLocations(resolver.getResources("classpath:mapper/*.xml"));
        return bean.getObject();
    } catch (Exception e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    }
}
 
Example #26
Source File: ApiBootMyBatisEnhanceAutoConfiguration.java    From beihu-boot with Apache License 2.0 5 votes vote down vote up
public ApiBootMyBatisEnhanceAutoConfiguration(ApiBootMyBatisEnhanceProperties properties,
                                              ObjectProvider<Interceptor[]> interceptorsProvider,
                                              ResourceLoader resourceLoader,
                                              ObjectProvider<DatabaseIdProvider> databaseIdProvider,
                                              ObjectProvider<List<ConfigurationCustomizer>> configurationCustomizersProvider) {
    this.properties = properties;
    this.interceptors = interceptorsProvider.getIfAvailable();
    this.resourceLoader = resourceLoader;
    this.databaseIdProvider = databaseIdProvider.getIfAvailable();
    this.configurationCustomizers = configurationCustomizersProvider.getIfAvailable();
}
 
Example #27
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 #28
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 #29
Source File: MybatisConfig.java    From genericdao with Artistic License 2.0 5 votes vote down vote up
/**
 * 初始化分页插件
 * @param interceptorList
 * @param environment
    */
protected void initPagePlugin(List<Interceptor> interceptorList , Environment environment){
	//初始化mybatis的分页插件
	PageInterceptor pageHelper = new PageInterceptor() ;
	Properties properties = new Properties() ;
	properties.put("dialect", environment.getProperty(PROPERTY_MYBATIS_DIALECT , "mysql")) ;
	//不进行合理化查询优化
	properties.put("reasonable", "false") ;
	pageHelper.setProperties(properties);
	//添加分页插件
	interceptorList.add(pageHelper) ;
}
 
Example #30
Source File: MysqlConfig.java    From jee-universal-bms with Apache License 2.0 5 votes vote down vote up
@Bean
  public SqlSessionFactoryBean sqlSessionFactory() throws Exception {
  	SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
  	sessionFactory.setDataSource(dataSource());

      //String[] paths = {"classpath*:com/yuzhi/bms/dao/**/*.class"};
      //String aliasesPackage = PathUtil.getMultiResources(paths);
      //sessionFactory.setTypeAliasesPackage(aliasesPackage);

Interceptor[] plugins = new Interceptor[] {pageHelper()};
sessionFactory.setPlugins(plugins);

  	return sessionFactory;
  }