From d09b59f3bd98bb103c8355f0d3066fad866bdd1f Mon Sep 17 00:00:00 2001 From: qi Date: Sun, 18 Aug 2019 00:46:24 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- panda-all/panda-all.iml | 7 ++++ panda-all/pom.xml | 2 +- panda-aop/panda-aop.iml | 7 ++++ panda-aop/pom.xml | 2 +- panda-beans/panda-beans.iml | 7 ++++ panda-beans/pom.xml | 2 +- .../java/org/panda/beans/util/BeanUtil.java | 3 -- panda-code/panda-code.iml | 7 ++++ panda-code/pom.xml | 2 +- panda-jdbc/panda-jdbc.iml | 7 ++++ panda-jdbc/pom.xml | 2 +- .../org/panda/jdbc/sql/AbstractDbBuiler.java | 13 ++++---- .../java/org/panda/jdbc/sql/SqlConstant.java | 32 +++++++++++++++++++ .../jdbc/sql/factory/DbBuilerFactory.java | 14 ++++++++ .../factory/impl/DefaultDbBuilerFactory.java | 30 +++++++++++++++++ panda-web/panda-web.iml | 7 ++++ panda-web/pom.xml | 2 +- pom.xml | 2 +- 18 files changed, 132 insertions(+), 16 deletions(-) create mode 100644 panda-jdbc/src/main/java/org/panda/jdbc/sql/SqlConstant.java create mode 100644 panda-jdbc/src/main/java/org/panda/jdbc/sql/factory/DbBuilerFactory.java create mode 100644 panda-jdbc/src/main/java/org/panda/jdbc/sql/factory/impl/DefaultDbBuilerFactory.java diff --git a/panda-all/panda-all.iml b/panda-all/panda-all.iml index 606c170..949f92a 100644 --- a/panda-all/panda-all.iml +++ b/panda-all/panda-all.iml @@ -7,10 +7,17 @@ + + + + + + + diff --git a/panda-all/pom.xml b/panda-all/pom.xml index e292d90..2a61728 100644 --- a/panda-all/pom.xml +++ b/panda-all/pom.xml @@ -5,7 +5,7 @@ panda org.panda - 2.0 + 2.0.0 jar 4.0.0 diff --git a/panda-aop/panda-aop.iml b/panda-aop/panda-aop.iml index 73638cc..ade316a 100644 --- a/panda-aop/panda-aop.iml +++ b/panda-aop/panda-aop.iml @@ -7,10 +7,17 @@ + + + + + + + diff --git a/panda-aop/pom.xml b/panda-aop/pom.xml index 580a091..351e156 100644 --- a/panda-aop/pom.xml +++ b/panda-aop/pom.xml @@ -5,7 +5,7 @@ panda org.panda - 2.0 + 2.0.0 ${project.version} 4.0.0 diff --git a/panda-beans/panda-beans.iml b/panda-beans/panda-beans.iml index cbe3627..0c9c4a2 100644 --- a/panda-beans/panda-beans.iml +++ b/panda-beans/panda-beans.iml @@ -7,10 +7,17 @@ + + + + + + + diff --git a/panda-beans/pom.xml b/panda-beans/pom.xml index bf536d8..4f1c838 100644 --- a/panda-beans/pom.xml +++ b/panda-beans/pom.xml @@ -5,7 +5,7 @@ panda org.panda - 2.0 + 2.0.0 4.0.0 diff --git a/panda-beans/src/main/java/org/panda/beans/util/BeanUtil.java b/panda-beans/src/main/java/org/panda/beans/util/BeanUtil.java index cefd4dd..b657f2b 100644 --- a/panda-beans/src/main/java/org/panda/beans/util/BeanUtil.java +++ b/panda-beans/src/main/java/org/panda/beans/util/BeanUtil.java @@ -1,7 +1,6 @@ package org.panda.beans.util; -import com.sun.tools.javac.util.Assert; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -218,7 +217,6 @@ public class BeanUtil { */ public static T instantiateClass(Class clazz){ T t = null; - Assert.checkNonNull(clazz); try { t = clazz.newInstance(); } catch (InstantiationException e) { @@ -239,7 +237,6 @@ public class BeanUtil { */ public static T instantiateClass(Class clazz,Object... params){ T t = null; - Assert.checkNonNull(clazz); Class[] classes = new Class[params.length]; for (int i=0;i + + + + + + + diff --git a/panda-code/pom.xml b/panda-code/pom.xml index 5d2901f..ca00ac0 100644 --- a/panda-code/pom.xml +++ b/panda-code/pom.xml @@ -5,7 +5,7 @@ panda org.panda - 2.0 + 2.0.0 4.0.0 panda-code diff --git a/panda-jdbc/panda-jdbc.iml b/panda-jdbc/panda-jdbc.iml index 49f74a8..839e2b5 100644 --- a/panda-jdbc/panda-jdbc.iml +++ b/panda-jdbc/panda-jdbc.iml @@ -6,10 +6,17 @@ + + + + + + + diff --git a/panda-jdbc/pom.xml b/panda-jdbc/pom.xml index e1bdf85..8ffbf23 100644 --- a/panda-jdbc/pom.xml +++ b/panda-jdbc/pom.xml @@ -5,7 +5,7 @@ panda org.panda - 2.0 + 2.0.0 4.0.0 diff --git a/panda-jdbc/src/main/java/org/panda/jdbc/sql/AbstractDbBuiler.java b/panda-jdbc/src/main/java/org/panda/jdbc/sql/AbstractDbBuiler.java index 308f510..44c1a40 100644 --- a/panda-jdbc/src/main/java/org/panda/jdbc/sql/AbstractDbBuiler.java +++ b/panda-jdbc/src/main/java/org/panda/jdbc/sql/AbstractDbBuiler.java @@ -89,14 +89,15 @@ public abstract class AbstractDbBuiler { * @return */ public String countSql(String sql){ - StringBuffer sb=new StringBuffer("select count(*) from ( "); - sql=sql.toLowerCase(); - if (sql.lastIndexOf("order")>sql.lastIndexOf(")")){ - sb.append(sql.substring(sql.indexOf("from")+4,sql.lastIndexOf("order"))); + StringBuffer sb=new StringBuffer("SELECT COUNT(*) FROM "); + //SQL 转成大写适 + String upperCaseSql = sql.toUpperCase(); + //统计SQL排除排序SQL代码 + if (sql.lastIndexOf(SqlConstant.ORDER_SQL)>sql.lastIndexOf(")")){ + sb.append(sql.substring(upperCaseSql.indexOf(SqlConstant.FROM_SQL)+SqlConstant.FROM_SQL.length(),upperCaseSql.lastIndexOf(SqlConstant.ORDER_SQL))); }else{ - sb.append(sql.substring(sql.indexOf("from")+4)); + sb.append(sql.substring(upperCaseSql.indexOf(SqlConstant.FROM_SQL)+SqlConstant.FROM_SQL.length())); } - sb.append(")"); return sb.toString(); } diff --git a/panda-jdbc/src/main/java/org/panda/jdbc/sql/SqlConstant.java b/panda-jdbc/src/main/java/org/panda/jdbc/sql/SqlConstant.java new file mode 100644 index 0000000..40eeb53 --- /dev/null +++ b/panda-jdbc/src/main/java/org/panda/jdbc/sql/SqlConstant.java @@ -0,0 +1,32 @@ +package org.panda.jdbc.sql; + +/** + * @Author: qi + * @Description: + * @Date: Create in 6:28 AM 2019/5/6 + */ +public class SqlConstant { + + /** + * SQL 切割符 + */ + public static final String SQL_SYMBOL = "_"; + /** + * 数据库类型常量:mysql + */ + public static final String DB_TYPE_MYSQL = "mysql"; + /** + * 数据库类型常量:oracle + */ + public static final String DB_TYPE_ORACLE = "oracle"; + + /** + * 常用SQL 关键字:FROM + */ + public static final String FROM_SQL = "FROM "; + /** + * 常用SQL 关键字:order + */ + public static final String ORDER_SQL="ORDER"; + +} diff --git a/panda-jdbc/src/main/java/org/panda/jdbc/sql/factory/DbBuilerFactory.java b/panda-jdbc/src/main/java/org/panda/jdbc/sql/factory/DbBuilerFactory.java new file mode 100644 index 0000000..9bdbafa --- /dev/null +++ b/panda-jdbc/src/main/java/org/panda/jdbc/sql/factory/DbBuilerFactory.java @@ -0,0 +1,14 @@ +package org.panda.jdbc.sql.factory; + + +import org.panda.jdbc.sql.AbstractDbBuiler; + +/** + * Sql 构造器工厂 + * 作用:解耦使用者与具体实现类关系 + * @author qi + */ +public interface DbBuilerFactory { + + AbstractDbBuiler getSqlBuilder(String dbType); +} diff --git a/panda-jdbc/src/main/java/org/panda/jdbc/sql/factory/impl/DefaultDbBuilerFactory.java b/panda-jdbc/src/main/java/org/panda/jdbc/sql/factory/impl/DefaultDbBuilerFactory.java new file mode 100644 index 0000000..219d3bb --- /dev/null +++ b/panda-jdbc/src/main/java/org/panda/jdbc/sql/factory/impl/DefaultDbBuilerFactory.java @@ -0,0 +1,30 @@ +package org.panda.jdbc.sql.factory.impl; + + +import org.panda.jdbc.sql.AbstractDbBuiler; +import org.panda.jdbc.sql.MysqlBuilder; +import org.panda.jdbc.sql.OracleBuiler; +import org.panda.jdbc.sql.SqlConstant; +import org.panda.jdbc.sql.factory.DbBuilerFactory; + +/** + * @author qi + * dbBuilfer 生产工厂模式默认实现 + */ +public class DefaultDbBuilerFactory implements DbBuilerFactory { + + @Override + public AbstractDbBuiler getSqlBuilder(String dbType) { + AbstractDbBuiler abstractDbBuiler = null; + switch (dbType){ + case SqlConstant + .DB_TYPE_MYSQL: + abstractDbBuiler = new MysqlBuilder(); + break; + case SqlConstant.DB_TYPE_ORACLE: + abstractDbBuiler = new OracleBuiler(); + break; + } + return abstractDbBuiler; + } +} diff --git a/panda-web/panda-web.iml b/panda-web/panda-web.iml index ac27d97..518aeb9 100644 --- a/panda-web/panda-web.iml +++ b/panda-web/panda-web.iml @@ -6,10 +6,17 @@ + + + + + + + diff --git a/panda-web/pom.xml b/panda-web/pom.xml index 179371d..6a5beb9 100644 --- a/panda-web/pom.xml +++ b/panda-web/pom.xml @@ -5,7 +5,7 @@ panda org.panda - 2.0 + 2.0.0 4.0.0 diff --git a/pom.xml b/pom.xml index 9fed5fb..290fcc6 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ org.panda panda pom - 1.0-SNAPSHOT + 2.0.0 panda-code panda-jdbc