Commit 35e63c66 authored by yanzg's avatar yanzg

修改实例化关系

parent 0e4dcd82
......@@ -11,11 +11,8 @@ import com.yanzuoguang.util.helper.ArrayHelper;
import com.yanzuoguang.util.helper.StringFormatHandle;
import com.yanzuoguang.util.helper.StringHelper;
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.regex.Matcher;
import java.util.regex.Pattern;
......@@ -25,17 +22,16 @@ import java.util.regex.Pattern;
*
* @author 颜佐光
*/
public abstract class BaseDaoSql implements ApplicationContextAware {
public abstract class BaseDaoSql {
/**
* SQL语句支持的最大长度
*/
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 {
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 {
this.init();
}
/**
* 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);
}
@Resource
public void setDb(DbExecute db) {
this.db = db;
}
/**
* 获取数据库执行类
*
......
......@@ -4,10 +4,8 @@ import com.yanzuoguang.db.ConfigDb;
import com.yanzuoguang.db.DbExecute;
import com.yanzuoguang.util.vo.MapRow;
import com.yanzuoguang.util.vo.Ref;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanInitializationException;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowCallbackHandler;
import org.springframework.jdbc.support.rowset.SqlRowSet;
......@@ -25,34 +23,17 @@ import java.util.List;
* @author 颜佐光
*/
@Component
public class DbExecuteImpl implements DbExecute, ApplicationContextAware {
private DbPrintSql printSql;
private ConfigDb configDb;
public class DbExecuteImpl implements DbExecute {
@Resource
@Qualifier("jdbcTemplate")
private JdbcTemplate jdbc;
/**
* 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.printSql = applicationContext.getBean(DbPrintSql.class);
this.configDb = applicationContext.getBean(ConfigDb.class);
}
@Autowired
private DbPrintSql printSql;
@Autowired
private ConfigDb configDb;
public JdbcTemplate getJdbc() {
return jdbc;
......
......@@ -3,10 +3,7 @@ package com.yanzuoguang.db.impl;
import com.yanzuoguang.db.ConfigDb;
import com.yanzuoguang.util.helper.StringHelper;
import com.yanzuoguang.util.log.Log;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanInitializationException;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
......@@ -15,29 +12,11 @@ import org.springframework.stereotype.Component;
* @author 颜佐光
*/
@Component
public class DbPrintSql implements ApplicationContextAware {
public class DbPrintSql {
@Autowired
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语句
*
......
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