Commit 35e63c66 authored by yanzg's avatar yanzg

修改实例化关系

parent 0e4dcd82
...@@ -11,11 +11,8 @@ import com.yanzuoguang.util.helper.ArrayHelper; ...@@ -11,11 +11,8 @@ import com.yanzuoguang.util.helper.ArrayHelper;
import com.yanzuoguang.util.helper.StringFormatHandle; import com.yanzuoguang.util.helper.StringFormatHandle;
import com.yanzuoguang.util.helper.StringHelper; import com.yanzuoguang.util.helper.StringHelper;
import com.yanzuoguang.util.vo.*; import com.yanzuoguang.util.vo.*;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanInitializationException;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.*;
import javax.annotation.Resource;
import java.util.*; import java.util.*;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
...@@ -25,17 +22,16 @@ import java.util.regex.Pattern; ...@@ -25,17 +22,16 @@ import java.util.regex.Pattern;
* *
* @author 颜佐光 * @author 颜佐光
*/ */
public abstract class BaseDaoSql implements ApplicationContextAware { public abstract class BaseDaoSql {
/** /**
* SQL语句支持的最大长度 * SQL语句支持的最大长度
*/ */
public static int MAX_LEVEL = 10; public static int MAX_LEVEL = 10;
/** /**
* 数据库执行类 * 缓存的表结构和SQL语句
*/ */
private DbExecute db; protected final static MemoryCache<TableSqlCache> cache = new MemoryCache<>();
/** /**
* 定义列表记录缓存对象 * 定义列表记录缓存对象
...@@ -48,9 +44,9 @@ public abstract class BaseDaoSql implements ApplicationContextAware { ...@@ -48,9 +44,9 @@ public abstract class BaseDaoSql implements ApplicationContextAware {
protected TableSqlCache table = null; protected TableSqlCache table = null;
/** /**
* 缓存的表结构和SQL语句 * 数据库执行类
*/ */
protected final static MemoryCache<TableSqlCache> cache = new MemoryCache<>(); private DbExecute db;
/** /**
* 构造函数 * 构造函数
...@@ -72,29 +68,11 @@ public abstract class BaseDaoSql implements ApplicationContextAware { ...@@ -72,29 +68,11 @@ public abstract class BaseDaoSql implements ApplicationContextAware {
this.init(); this.init();
} }
/** @Resource
* Set the ApplicationContext that this object runs in.
* Normally this call will be used to initialize the object.
* <p>Invoked after population of normal bean properties but before an init callback such
* as {@link InitializingBean#afterPropertiesSet()}
* or a custom init-method. Invoked after {@link ResourceLoaderAware#setResourceLoader},
* {@link ApplicationEventPublisherAware#setApplicationEventPublisher} and
* {@link MessageSourceAware}, if applicable.
*
* @param applicationContext the ApplicationContext object to be used by this object
* @throws ApplicationContextException in case of context initialization errors
* @throws BeansException if thrown by application context methods
* @see BeanInitializationException
*/
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
this.db = applicationContext.getBean(DbExecute.class);
}
public void setDb(DbExecute db) { public void setDb(DbExecute db) {
this.db = db; this.db = db;
} }
/** /**
* 获取数据库执行类 * 获取数据库执行类
* *
......
...@@ -4,10 +4,8 @@ import com.yanzuoguang.db.ConfigDb; ...@@ -4,10 +4,8 @@ import com.yanzuoguang.db.ConfigDb;
import com.yanzuoguang.db.DbExecute; import com.yanzuoguang.db.DbExecute;
import com.yanzuoguang.util.vo.MapRow; import com.yanzuoguang.util.vo.MapRow;
import com.yanzuoguang.util.vo.Ref; import com.yanzuoguang.util.vo.Ref;
import org.springframework.beans.BeansException; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.BeanInitializationException; import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.*;
import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowCallbackHandler; import org.springframework.jdbc.core.RowCallbackHandler;
import org.springframework.jdbc.support.rowset.SqlRowSet; import org.springframework.jdbc.support.rowset.SqlRowSet;
...@@ -25,34 +23,17 @@ import java.util.List; ...@@ -25,34 +23,17 @@ import java.util.List;
* @author 颜佐光 * @author 颜佐光
*/ */
@Component @Component
public class DbExecuteImpl implements DbExecute, ApplicationContextAware { public class DbExecuteImpl implements DbExecute {
private DbPrintSql printSql;
private ConfigDb configDb;
@Resource @Resource
@Qualifier("jdbcTemplate")
private JdbcTemplate jdbc; private JdbcTemplate jdbc;
/** @Autowired
* Set the ApplicationContext that this object runs in. private DbPrintSql printSql;
* Normally this call will be used to initialize the object.
* <p>Invoked after population of normal bean properties but before an init callback such @Autowired
* as {@link InitializingBean#afterPropertiesSet()} private ConfigDb configDb;
* or a custom init-method. Invoked after {@link ResourceLoaderAware#setResourceLoader},
* {@link ApplicationEventPublisherAware#setApplicationEventPublisher} and
* {@link MessageSourceAware}, if applicable.
*
* @param applicationContext the ApplicationContext object to be used by this object
* @throws ApplicationContextException in case of context initialization errors
* @throws BeansException if thrown by application context methods
* @see BeanInitializationException
*/
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
this.printSql = applicationContext.getBean(DbPrintSql.class);
this.configDb = applicationContext.getBean(ConfigDb.class);
}
public JdbcTemplate getJdbc() { public JdbcTemplate getJdbc() {
return jdbc; return jdbc;
......
...@@ -3,10 +3,7 @@ package com.yanzuoguang.db.impl; ...@@ -3,10 +3,7 @@ package com.yanzuoguang.db.impl;
import com.yanzuoguang.db.ConfigDb; import com.yanzuoguang.db.ConfigDb;
import com.yanzuoguang.util.helper.StringHelper; import com.yanzuoguang.util.helper.StringHelper;
import com.yanzuoguang.util.log.Log; import com.yanzuoguang.util.log.Log;
import org.springframework.beans.BeansException; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.BeanInitializationException;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.*;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
/** /**
...@@ -15,29 +12,11 @@ import org.springframework.stereotype.Component; ...@@ -15,29 +12,11 @@ import org.springframework.stereotype.Component;
* @author 颜佐光 * @author 颜佐光
*/ */
@Component @Component
public class DbPrintSql implements ApplicationContextAware { public class DbPrintSql {
@Autowired
private ConfigDb configDb; private ConfigDb configDb;
/**
* Set the ApplicationContext that this object runs in.
* Normally this call will be used to initialize the object.
* <p>Invoked after population of normal bean properties but before an init callback such
* as {@link InitializingBean#afterPropertiesSet()}
* or a custom init-method. Invoked after {@link ResourceLoaderAware#setResourceLoader},
* {@link ApplicationEventPublisherAware#setApplicationEventPublisher} and
* {@link MessageSourceAware}, if applicable.
*
* @param applicationContext the ApplicationContext object to be used by this object
* @throws ApplicationContextException in case of context initialization errors
* @throws BeansException if thrown by application context methods
* @see BeanInitializationException
*/
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
this.configDb = applicationContext.getBean(ConfigDb.class);
}
/** /**
* 获取参数处理之后的SQL语句 * 获取参数处理之后的SQL语句
* *
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment