diff --git a/panda-jdbc/src/main/java/org/panda/jdbc/sql/builder/AbstractDbBuiler.java b/panda-jdbc/src/main/java/org/panda/jdbc/sql/builder/AbstractDbBuiler.java new file mode 100644 index 0000000..e64dd52 --- /dev/null +++ b/panda-jdbc/src/main/java/org/panda/jdbc/sql/builder/AbstractDbBuiler.java @@ -0,0 +1,115 @@ +package org.panda.jdbc.sql.builder; + +import org.panda.jdbc.mode.Table; +import org.panda.jdbc.sql.PageInterface; +import org.panda.jdbc.sql.SqlConstant; + +import java.util.List; +import java.util.Map; +import java.util.Set; + +/** + * @author qi + * 抽象类-sql构造器 + * 实现的子类有: MysqlBuilder ,OragleBuilder (为应对不同数据库特点,有部分方法抽象,由子类实现) + * Created by qi_liang on 2018/6/2. + */ +public abstract class AbstractDbBuiler { + + /** + * 构建更新表结构sql + * @param classSet 实体类集合 + * @param tableList 数据库已存在表集合 + * @return + */ + abstract public String automaticUpdateDb(Set classSet, List tableList); + + /** + *  构建分页sql语句 + * @param sql + * @param pageInterface + * @return + */ + abstract public String concatPageSql(String sql, PageInterface pageInterface); + + + /** + * 构建创建表的sql语句 + * @param clazz 对象的class + * @return 构建好的创建表的sql(类型:String) + */ + abstract public String createTableStr(Class clazz); + + /** + * 构建新增sql语句 + * @param obj + * @return + */ + abstract public String insertSql(Object obj); + + /** + * 构建新增sql语句 + * @param obj + * @param fieldMap + * @return + */ + abstract public String insertSql(Object obj, Map fieldMap); + + /** + * 构建更新sql语句 + * @param obj + * @return + */ + abstract public String updateSql(Object obj); + + /** + * 构建更新sql语句 + * @param obj + * @param fieldMap + * @return + */ + abstract public String updateSql(Object obj, Map fieldMap); + + /** + * 构建删除sql + * @param obj + * @return + */ + abstract public String deleteSql(Object obj); + + /** + * 构建删除sql + * @param obj + * @param fieldMap + * @return + */ + abstract public String deleteSql(Object obj,Map fieldMap); + + /** + * 构建统计sql语句 + * @param sql + * @return + */ + public String countSql(String sql){ + 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(upperCaseSql.indexOf(SqlConstant.FROM_SQL)+SqlConstant.FROM_SQL.length())); + } + return sb.toString(); + } + + + + + + + + + + +} diff --git a/panda-jdbc/src/main/java/org/panda/jdbc/sql/MysqlBuilder.java b/panda-jdbc/src/main/java/org/panda/jdbc/sql/builder/MysqlBuilder.java similarity index 98% rename from panda-jdbc/src/main/java/org/panda/jdbc/sql/MysqlBuilder.java rename to panda-jdbc/src/main/java/org/panda/jdbc/sql/builder/MysqlBuilder.java index 97fe5e7..3b5a391 100644 --- a/panda-jdbc/src/main/java/org/panda/jdbc/sql/MysqlBuilder.java +++ b/panda-jdbc/src/main/java/org/panda/jdbc/sql/builder/MysqlBuilder.java @@ -1,9 +1,11 @@ -package org.panda.jdbc.sql; +package org.panda.jdbc.sql.builder; import org.panda.beans.util.BeanUtil; import org.panda.code.uitl.CollectionUtil; import org.panda.jdbc.mode.Column; import org.panda.jdbc.mode.Table; +import org.panda.jdbc.sql.BeanSqlUtil; +import org.panda.jdbc.sql.PageInterface; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/panda-jdbc/src/main/java/org/panda/jdbc/sql/OracleBuiler.java b/panda-jdbc/src/main/java/org/panda/jdbc/sql/builder/OracleBuiler.java similarity index 91% rename from panda-jdbc/src/main/java/org/panda/jdbc/sql/OracleBuiler.java rename to panda-jdbc/src/main/java/org/panda/jdbc/sql/builder/OracleBuiler.java index 877ca6a..2b7f9f5 100644 --- a/panda-jdbc/src/main/java/org/panda/jdbc/sql/OracleBuiler.java +++ b/panda-jdbc/src/main/java/org/panda/jdbc/sql/builder/OracleBuiler.java @@ -1,7 +1,9 @@ -package org.panda.jdbc.sql; +package org.panda.jdbc.sql.builder; import org.panda.jdbc.mode.Table; +import org.panda.jdbc.sql.PageInterface; +import org.panda.jdbc.sql.builder.AbstractDbBuiler; import java.util.List; import java.util.Map;