From e8aa0312bdfb87253972356ddf33082257321276 Mon Sep 17 00:00:00 2001 From: qi Date: Fri, 16 Aug 2019 23:03:44 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../InstantiationTracingBeanPostProcessor.java | 13 ++++++------- .../com/lq/code/interceptor/PageInteceptor.java | 13 +++++-------- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/lq/code/executor/processor/InstantiationTracingBeanPostProcessor.java b/src/main/java/com/lq/code/executor/processor/InstantiationTracingBeanPostProcessor.java index aacec4f..7babbe0 100755 --- a/src/main/java/com/lq/code/executor/processor/InstantiationTracingBeanPostProcessor.java +++ b/src/main/java/com/lq/code/executor/processor/InstantiationTracingBeanPostProcessor.java @@ -4,14 +4,16 @@ import com.lq.code.dto.QueueDto; import com.lq.code.util.BeanUtil; import com.lq.code.util.jdbc.JdbcUtils; import com.lq.code.util.sql.AbstractDbBuiler; -import com.lq.code.util.sql.MysqlBuilder; +import com.lq.code.util.sql.SqlConstant; +import com.lq.code.util.sql.factory.DbBuilerFactory; +import com.lq.code.util.sql.factory.impl.DefaultDbBuilerFactory; import org.springframework.context.ApplicationListener; import org.springframework.context.event.ContextRefreshedEvent; import java.util.Set; /** - * Created by qi_liang on 2018/6/1. + * @author qi */ public class InstantiationTracingBeanPostProcessor implements ApplicationListener { @@ -42,15 +44,12 @@ public class InstantiationTracingBeanPostProcessor implements ApplicationListene //需要执行的逻辑代码,当spring容器初始化完成后就会执行该方法。 //扫描实体类 if (isUpdateDB) { - long startTime = System.currentTimeMillis(); Set set = BeanUtil.getClassSet(packagePath); QueueDto queueDto = BeanUtil.getQueueDto(packagePath); - AbstractDbBuiler dbBuiler = new MysqlBuilder(); -// String sql = dbBuiler.automaticUpdateDbNew(queueDto); + DbBuilerFactory dbBuilerFactory = new DefaultDbBuilerFactory(); + AbstractDbBuiler dbBuiler = dbBuilerFactory.getSqlBuilder(SqlConstant.DB_TYPE_MYSQL); String sql = dbBuiler.automaticUpdateDb(set); JdbcUtils.createTable(sql); - System.out.println("=========实体同步数据结构==========="); - System.out.println(System.currentTimeMillis()-startTime+"毫秒"); } } } diff --git a/src/main/java/com/lq/code/interceptor/PageInteceptor.java b/src/main/java/com/lq/code/interceptor/PageInteceptor.java index 4c53e02..4660bdb 100755 --- a/src/main/java/com/lq/code/interceptor/PageInteceptor.java +++ b/src/main/java/com/lq/code/interceptor/PageInteceptor.java @@ -2,6 +2,8 @@ package com.lq.code.interceptor; import com.lq.code.util.StringUtil; import com.lq.code.util.sql.*; +import com.lq.code.util.sql.factory.DbBuilerFactory; +import com.lq.code.util.sql.factory.impl.DefaultDbBuilerFactory; import org.apache.ibatis.executor.Executor; import org.apache.ibatis.executor.statement.StatementHandler; import org.apache.ibatis.mapping.BoundSql; @@ -17,7 +19,7 @@ import java.sql.Connection; import java.util.Properties; /** - * Created by qi_liang on 2018/2/16. + * @author qi */ //注解拦截器并签名 //@Signature 拦截的类签名 type 拦截的类 method 类里面的方法 args方法里面的参数 @@ -48,13 +50,8 @@ public class PageInteceptor implements Interceptor { BoundSql boundSql=(BoundSql)metaStatementHandler.getValue("delegate.boundSql"); String sql=boundSql.getSql(); PageInterface pageInterface=(PageInterface)boundSql.getParameterObject(); - AbstractDbBuiler db = null; - if (SqlConstant.DB_TYPE_MYSQL.equals(dialect)){ - db = new MysqlBuilder(); - } - if (SqlConstant.DB_TYPE_ORACLE.equals(dialect)){ - db = new OracleBuiler(); - } + DbBuilerFactory dbBuilerFactory = new DefaultDbBuilerFactory(); + AbstractDbBuiler db = dbBuilerFactory.getSqlBuilder(dialect); String pageSql=db.concatPageSql(sql,pageInterface); metaStatementHandler.setValue("delegate.boundSql.sql",pageSql);