Skip to content

Commit

Permalink
Merge pull request iBase4J#23 from iBase4J/develop
Browse files Browse the repository at this point in the history
缓存优化:Service使用redisson管理数据缓存;Web使用Spring-data-redis管理会话缓存
  • Loading branch information
iBase4J authored Aug 19, 2017
2 parents 0dd575c + c1b8c88 commit 9f16c0a
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 80 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.ibase4j.core.Constants;
import org.ibase4j.core.support.dbcp.ChooseDataSource;
import org.ibase4j.core.support.dbcp.HandleDataSource;
import org.ibase4j.core.util.ExceptionUtil;
import org.ibase4j.core.util.InstanceUtil;
import org.springframework.beans.BeansException;
Expand Down Expand Up @@ -33,6 +35,20 @@ public Parameter execute(Parameter parameter) {
Map<?, ?> map = parameter.getMap();
String method = parameter.getMethod();
Object[] param = parameter.getParam();
try {
L: for (String key : ChooseDataSource.METHODTYPE.keySet()) {
for (String type : ChooseDataSource.METHODTYPE.get(key)) {
if (method.startsWith(type)) {
logger.info(key);
HandleDataSource.putDataSource(key);
break L;
}
}
}
} catch (Exception e) {
logger.error(e);
HandleDataSource.putDataSource("write");
}
Object result = null;
if (param != null) {
result = InstanceUtil.invokeMethod(service, method, param);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.ibase4j.core.aspect;
package org.ibase4j.core.support.dbcp;

import java.util.ArrayList;
import java.util.HashMap;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.ibase4j.core.aspect;
package org.ibase4j.core.support.dbcp;

/**
* @author ShenHuaJie
Expand Down
4 changes: 1 addition & 3 deletions iBase4J-Common/src/main/resources/spring/dataSource.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
<property name="minEvictableIdleTimeMillis" value="${db.minEvictableIdleTimeMillis}" />
<property name="timeBetweenEvictionRunsMillis" value="${db.timeBetweenEvictionRunsMillis}" />
</bean>
<bean id="dataSource" class="org.ibase4j.core.aspect.ChooseDataSource" lazy-init="true">
<bean id="dataSource" class="org.ibase4j.core.support.dbcp.ChooseDataSource" lazy-init="true">
<description>数据源</description>
<property name="targetDataSources">
<map key-type="java.lang.String" value-type="javax.sql.DataSource">
Expand All @@ -90,8 +90,6 @@
</map>
</property>
</bean>
<!-- 切面 -->
<bean class="org.ibase4j.core.aspect.DataSourceAspect" />
<!-- -->
<bean class="org.springframework.jdbc.core.JdbcTemplate">
<constructor-arg ref="dataSource" />
Expand Down
10 changes: 3 additions & 7 deletions iBase4J-Common/src/main/resources/spring/session.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@
<!--是否在从池中取出连接前进行检验,如果检验失败,则从池中去除连接并尝试取出另一个-->
<property name="testOnBorrow" value="${redis.testOnBorrow}" />
</bean >
<bean id="jedisShardInfo" class="org.ibase4j.core.support.cache.jedis.JedisShardInfo">
<constructor-arg index="0" value="${redis.host}" />
<constructor-arg index="1" value="${redis.port}" type="int" />
<property name="password" value="${redis.password}" />
</bean>
<!-- redisCluster配置 -->
<!-- <bean id="redisClusterConfiguration" class="org.springframework.data.redis.connection.RedisClusterConfiguration">
<constructor-arg name="propertySource">
Expand All @@ -33,9 +28,10 @@
</bean>
</constructor-arg>
</bean> -->
<!-- redis服务器中心 -->
<!-- redis服务器中心 -->
<bean id="jedisConnectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"
p:pool-config-ref="jedisPoolConfig" p:shard-info-ref="jedisShardInfo" p:timeout="${redis.timeout}" />
p:host-name="${redis.host}" p:port="${redis.port}" p:password="${redis.password}"
p:pool-config-ref="jedisPoolConfig" p:timeout="${redis.timeout}" />
<!-- SPRING-SESSION -->
<bean class="org.springframework.session.data.redis.config.annotation.web.http.RedisHttpSessionConfiguration">
<property name="maxInactiveIntervalInSeconds" value="${session.maxInactiveInterval}" />
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
<!-- 编码 -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<!-- spring版本号 -->
<spring.version>5.0.0.M5</spring.version>
<spring.version>5.0.0.RC3</spring.version>
<spring-session.version>2.0.0.M2</spring-session.version>
<spring-data-redis.version>2.0.0.M4</spring-data-redis.version>
<spring-data-redis.version>2.0.0.RC2</spring-data-redis.version>
<!-- 数据库 -->
<mysql.version>5.1.39</mysql.version>
<sharding-jdbc.version>1.4.1</sharding-jdbc.version>
Expand Down

0 comments on commit 9f16c0a

Please sign in to comment.