mirror of
https://gitee.com/huoyo/ko-time.git
synced 2025-12-06 16:58:26 +08:00
optimize the DataBase
This commit is contained in:
parent
f28032a829
commit
e6677b3b57
@ -79,13 +79,13 @@ public class LoadConfig {
|
|||||||
Context.setDataSource(dataSource);
|
Context.setDataSource(dataSource);
|
||||||
}catch (NoUniqueBeanDefinitionException e){
|
}catch (NoUniqueBeanDefinitionException e){
|
||||||
if (StringUtils.isEmpty(config.getDataSource())) {
|
if (StringUtils.isEmpty(config.getDataSource())) {
|
||||||
log.warning("kotime=>No unique bean of type 'javax.sql.DataSource' available,you can define it by `ko-time.data-source=xxx`");
|
log.warning("kotime=>No unique bean of type 'DataSource' available,you can define it by `ko-time.data-source=xxx`");
|
||||||
}else {
|
}else {
|
||||||
DataSource dataSource = applicationContext.getBean(config.getDataSource(),DataSource.class);
|
DataSource dataSource = applicationContext.getBean(config.getDataSource(),DataSource.class);
|
||||||
Context.setDataSource(dataSource);
|
Context.setDataSource(dataSource);
|
||||||
}
|
}
|
||||||
}catch (NoSuchBeanDefinitionException e){
|
}catch (NoSuchBeanDefinitionException e){
|
||||||
log.warning("kotime=>No qualifying bean of type 'javax.sql.DataSource' available,you can ignore it if your KoTime saver is `ko-time.saver=memory`");
|
log.warning("kotime=>No qualifying bean of type 'DataSource' available,you can ignore it if your KoTime saver is `ko-time.saver=memory`");
|
||||||
}
|
}
|
||||||
|
|
||||||
Context.setConfig(config);
|
Context.setConfig(config);
|
||||||
|
|||||||
@ -3,14 +3,12 @@ package cn.langpy.kotime.data;
|
|||||||
import cn.langpy.kotime.constant.KoSqlConstant;
|
import cn.langpy.kotime.constant.KoSqlConstant;
|
||||||
import cn.langpy.kotime.model.*;
|
import cn.langpy.kotime.model.*;
|
||||||
import cn.langpy.kotime.service.GraphService;
|
import cn.langpy.kotime.service.GraphService;
|
||||||
import cn.langpy.kotime.util.Common;
|
import cn.langpy.kotime.util.*;
|
||||||
import cn.langpy.kotime.util.Context;
|
|
||||||
import cn.langpy.kotime.util.DataBaseUtil;
|
|
||||||
import cn.langpy.kotime.util.MethodType;
|
|
||||||
import org.springframework.context.annotation.Lazy;
|
import org.springframework.context.annotation.Lazy;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
|
import javax.sql.DataSource;
|
||||||
import java.lang.reflect.Parameter;
|
import java.lang.reflect.Parameter;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
@ -54,7 +52,12 @@ public class DataBase implements GraphService {
|
|||||||
public Connection getReadConnection() {
|
public Connection getReadConnection() {
|
||||||
try {
|
try {
|
||||||
if (null == readConnection || readConnection.isClosed()) {
|
if (null == readConnection || readConnection.isClosed()) {
|
||||||
readConnection = Context.getDataSource().getConnection();
|
DataSource dataSource = Context.getDataSource();
|
||||||
|
if (null==dataSource) {
|
||||||
|
throw new DataBaseException("`ko-time.saver=database` needs a DataSource for MySQl or Oracle");
|
||||||
|
}else {
|
||||||
|
readConnection = dataSource.getConnection();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (SQLException throwables) {
|
} catch (SQLException throwables) {
|
||||||
throwables.printStackTrace();
|
throwables.printStackTrace();
|
||||||
@ -66,7 +69,12 @@ public class DataBase implements GraphService {
|
|||||||
public Connection getWriteConnection() {
|
public Connection getWriteConnection() {
|
||||||
try {
|
try {
|
||||||
if (null == writeConnection || writeConnection.isClosed()) {
|
if (null == writeConnection || writeConnection.isClosed()) {
|
||||||
writeConnection = Context.getDataSource().getConnection();
|
DataSource dataSource = Context.getDataSource();
|
||||||
|
if (null==dataSource) {
|
||||||
|
throw new DataBaseException("`ko-time.saver=database` needs a DataSource for MySQl or Oracle");
|
||||||
|
}else {
|
||||||
|
writeConnection = dataSource.getConnection();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (SQLException throwables) {
|
} catch (SQLException throwables) {
|
||||||
throwables.printStackTrace();
|
throwables.printStackTrace();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user