فهرست منبع

fixed osgit IDTZH

= 8 سال پیش
والد
کامیت
71f798c67c

+ 12 - 0
src/main/java/com/baomidou/mybatisplus/generator/config/DataSourceConfig.java

@@ -40,6 +40,10 @@ public class DataSourceConfig {
      * 数据库类型
      * 数据库类型
      */
      */
     private DbType dbType;
     private DbType dbType;
+    /**
+     * PostgreSQL schemaname
+     */
+    private String schemaname = "public";
     /**
     /**
      * 类型转换
      * 类型转换
      */
      */
@@ -86,6 +90,14 @@ public class DataSourceConfig {
         return this;
         return this;
     }
     }
 
 
+    public String getSchemaname() {
+        return schemaname;
+    }
+
+    public void setSchemaname(String schemaname) {
+        this.schemaname = schemaname;
+    }
+
     public ITypeConvert getTypeConvert() {
     public ITypeConvert getTypeConvert() {
         if (null == typeConvert) {
         if (null == typeConvert) {
             switch (getDbType()) {
             switch (getDbType()) {

+ 5 - 1
src/main/java/com/baomidou/mybatisplus/generator/config/builder/ConfigBuilder.java

@@ -372,7 +372,11 @@ public class ConfigBuilder {
         NamingStrategy strategy = config.getNaming();
         NamingStrategy strategy = config.getNaming();
         PreparedStatement preparedStatement = null;
         PreparedStatement preparedStatement = null;
         try {
         try {
-            preparedStatement = connection.prepareStatement(querySQL.getTableCommentsSql());
+            String tableCommentsSql = querySQL.getTableCommentsSql();
+            if (QuerySQL.POSTGRE_SQL == querySQL) {
+                tableCommentsSql = String.format(tableCommentsSql, dataSourceConfig.getSchemaname());
+            }
+            preparedStatement = connection.prepareStatement(tableCommentsSql);
             ResultSet results = preparedStatement.executeQuery();
             ResultSet results = preparedStatement.executeQuery();
             TableInfo tableInfo;
             TableInfo tableInfo;
             while (results.next()) {
             while (results.next()) {

+ 3 - 3
src/main/java/com/baomidou/mybatisplus/generator/config/rules/QuerySQL.java

@@ -59,11 +59,11 @@ public enum QuerySQL {
                     + " WHERE a.NAME = '%s' and sys.types.NAME !='sysname' ",
                     + " WHERE a.NAME = '%s' and sys.types.NAME !='sysname' ",
             "TABLE_NAME", "COMMENTS", "COLUMN_NAME", "DATA_TYPE", "COMMENTS", "KEY"),
             "TABLE_NAME", "COMMENTS", "COLUMN_NAME", "DATA_TYPE", "COMMENTS", "KEY"),
 
 
-    POSTGRE_SQL("postgre_sql", "select tablename from pg_tables where schemaname='public' ORDER BY tablename",
-            "SELECT A.tablename, obj_description(relfilenode, 'pg_class') AS comments FROM pg_tables A, pg_class B WHERE A.schemaname='public' AND A.tablename = B.relname",
+    POSTGRE_SQL("postgre_sql", "select tablename from pg_tables where schemaname='%s' ORDER BY tablename",
+            "SELECT A.tablename, obj_description(relfilenode, 'pg_class') AS comments FROM pg_tables A, pg_class B WHERE A.schemaname='%s' AND A.tablename = B.relname",
             "SELECT DISTINCT A.attname AS name,format_type(A.atttypid,A.atttypmod) AS type,col_description(A.attrelid,A.attnum) AS comment,(CASE C.contype WHEN 'p' THEN 'PRI' ELSE '' END) AS key"
             "SELECT DISTINCT A.attname AS name,format_type(A.atttypid,A.atttypmod) AS type,col_description(A.attrelid,A.attnum) AS comment,(CASE C.contype WHEN 'p' THEN 'PRI' ELSE '' END) AS key"
                     + " FROM pg_attribute A INNER JOIN pg_class B ON A.attrelid = B.oid"
                     + " FROM pg_attribute A INNER JOIN pg_class B ON A.attrelid = B.oid"
-                    + " LEFT JOIN pg_constraint C ON A.attnum = C.conkey[1] AND A.attrelid = C.conrelid WHERE B.relname = '%s' AND A.attnum>0",
+                    + " LEFT JOIN pg_constraint C ON A.attnum = C.conkey[1] AND A.attrelid = C.conrelid WHERE B.relname = '%s' AND A.attnum>0 AND position('...' in A.attname) < 1",
             "tablename", "comments", "name", "type", "comment", "key");
             "tablename", "comments", "name", "type", "comment", "key");
 
 
     private final String dbType;
     private final String dbType;

+ 0 - 7
src/main/java/com/baomidou/mybatisplus/mapper/Condition.java

@@ -33,13 +33,6 @@ public class Condition extends Wrapper {
      */
      */
     public static final Condition EMPTY = Condition.create();
     public static final Condition EMPTY = Condition.create();
 
 
-    /**
-     * 获取实例
-     */
-    @Deprecated
-    public static Condition instance() {
-        return Condition.create();
-    }
 
 
     /**
     /**
      * 获取实例
      * 获取实例

+ 24 - 1
src/test/java/com/baomidou/mybatisplus/test/EntityWrapperTest.java

@@ -24,6 +24,7 @@ import java.util.TreeMap;
 import java.util.TreeSet;
 import java.util.TreeSet;
 
 
 import com.baomidou.mybatisplus.entity.Columns;
 import com.baomidou.mybatisplus.entity.Columns;
+
 import org.junit.Assert;
 import org.junit.Assert;
 import org.junit.Test;
 import org.junit.Test;
 
 
@@ -31,6 +32,7 @@ import com.baomidou.mybatisplus.entity.Column;
 import com.baomidou.mybatisplus.enums.SqlLike;
 import com.baomidou.mybatisplus.enums.SqlLike;
 import com.baomidou.mybatisplus.mapper.Condition;
 import com.baomidou.mybatisplus.mapper.Condition;
 import com.baomidou.mybatisplus.mapper.EntityWrapper;
 import com.baomidou.mybatisplus.mapper.EntityWrapper;
+import com.baomidou.mybatisplus.mapper.Wrapper;
 import com.baomidou.mybatisplus.test.mysql.entity.User;
 import com.baomidou.mybatisplus.test.mysql.entity.User;
 
 
 /**
 /**
@@ -115,7 +117,7 @@ public class EntityWrapperTest {
     @Test
     @Test
     public void test23() {
     public void test23() {
         /*
         /*
-		 * 无实体查询,只排序
+         * 无实体查询,只排序
 		 */
 		 */
         ew.orderBy("id", false);
         ew.orderBy("id", false);
         String sqlSegment = ew.originalSql();
         String sqlSegment = ew.originalSql();
@@ -386,4 +388,25 @@ public class EntityWrapperTest {
         Assert.assertEquals("name AS name1,age,sex AS sex1", entityWrapper.getSqlSelect());
         Assert.assertEquals("name AS name1,age,sex AS sex1", entityWrapper.getSqlSelect());
     }
     }
 
 
+    /**
+     * 测试 EntityWrapper orderBy
+     */
+    @Test
+    public void testEntityWrapperOrderBy() {
+        EntityWrapper entityWrapper = new EntityWrapper();
+        entityWrapper.orderBy("id desc");
+        System.out.println(entityWrapper.getSqlSegment());
+        Assert.assertEquals("ORDER BY id desc", entityWrapper.getSqlSegment());
+    }
+
+    /**
+     * 测试 Condition orderBy
+     */
+    @Test
+    public void testConditionOrderBy() {
+        Wrapper wrapper = Condition.create().orderBy("id desc");
+        System.out.println(wrapper.getSqlSegment());
+        Assert.assertEquals("ORDER BY id desc", wrapper.getSqlSegment());
+    }
+
 }
 }