diff --git a/datagear-meta/src/main/java/org/datagear/meta/Table.java b/datagear-meta/src/main/java/org/datagear/meta/Table.java index 7a8a56d1..cd7bfae8 100644 --- a/datagear-meta/src/main/java/org/datagear/meta/Table.java +++ b/datagear-meta/src/main/java/org/datagear/meta/Table.java @@ -28,6 +28,9 @@ public class Table extends AbstractTable /** 导入外键 */ private ImportKey[] importKeys; + /** 表是否只读 */ + private boolean readonly = false; + public Table() { super(); @@ -94,6 +97,16 @@ public class Table extends AbstractTable this.importKeys = importKeys; } + public boolean isReadonly() + { + return readonly; + } + + public void setReadonly(boolean readonly) + { + this.readonly = readonly; + } + /** * 获取指定名称的{@linkplain Column}。 * diff --git a/datagear-meta/src/main/java/org/datagear/meta/resolver/AbstractDevotedDBMetaResolver.java b/datagear-meta/src/main/java/org/datagear/meta/resolver/AbstractDevotedDBMetaResolver.java index 2f390165..aa3daf7a 100644 --- a/datagear-meta/src/main/java/org/datagear/meta/resolver/AbstractDevotedDBMetaResolver.java +++ b/datagear-meta/src/main/java/org/datagear/meta/resolver/AbstractDevotedDBMetaResolver.java @@ -104,6 +104,12 @@ public abstract class AbstractDevotedDBMetaResolver implements DevotedDBMetaReso @Override public Table getTable(Connection cn, String tableName) throws DBMetaResolverException { + @JDBCCompatiblity("如果cn为readonly,某些驱动程序的DatabaseMetaData.isReadOnly()也将为true(比如:Postgresql JDBC 42.2.5)," + + "这会导致解析Table.readonly不正确,因此这里设为false,以保证解析正确") + boolean readonly = JdbcUtil.isReadonlyIfSupports(cn, true); + if (readonly) + JdbcUtil.setReadonlyIfSupports(cn, false); + DatabaseMetaData metaData = getDatabaseMetaData(cn); String schema = getSchema(cn, metaData); @@ -357,6 +363,8 @@ public abstract class AbstractDevotedDBMetaResolver implements DevotedDBMetaReso protected Table getTable(Connection cn, DatabaseMetaData metaData, String schema, String tableName) throws DBMetaResolverException { + boolean readonly = resolveTableReadonly(cn); + List simpleTables = getSimpleTables(cn, metaData, schema, tableName); if (simpleTables == null || simpleTables.isEmpty()) @@ -372,12 +380,33 @@ public abstract class AbstractDevotedDBMetaResolver implements DevotedDBMetaReso table.setPrimaryKey(getPrimaryKey(cn, metaData, schema, tableName)); table.setUniqueKeys(getUniqueKeys(cn, metaData, schema, tableName)); table.setImportKeys(getImportKeys(cn, metaData, schema, tableName)); + table.setReadonly(readonly); table = postProcessTable(cn, metaData, schema, table); return table; } + protected boolean resolveTableReadonly(Connection cn) + { + @JDBCCompatiblity("如果cn为readonly,某些驱动程序的DatabaseMetaData.isReadOnly()也将为true(比如:Postgresql JDBC 42.2.5)," + + "这会导致解析Table.readonly不正确,因此这里尝试设为false,来测试数据库是否为只读") + boolean cnReadonly = JdbcUtil.isReadonlyIfSupports(cn, true); + if (cnReadonly) + JdbcUtil.setReadonlyIfSupports(cn, false); + + try + { + // 数据库是否只读 + boolean dbReadonly = cn.getMetaData().isReadOnly(); + return dbReadonly; + } + catch(SQLException e) + { + return false; + } + } + protected Table postProcessTable(Connection cn, DatabaseMetaData metaData, String schema, Table table) { return table; diff --git a/datagear-web/src/main/java/org/datagear/web/controller/DataController.java b/datagear-web/src/main/java/org/datagear/web/controller/DataController.java index ec0363be..f0d356f6 100644 --- a/datagear-web/src/main/java/org/datagear/web/controller/DataController.java +++ b/datagear-web/src/main/java/org/datagear/web/controller/DataController.java @@ -186,6 +186,7 @@ public class DataController extends AbstractSchemaConnTableController springModel.addAttribute(KEY_TITLE_DISPLAY_NAME, table.getName()); springModel.addAttribute(KEY_TITLE_DISPLAY_DESC, table.getComment()); springModel.addAttribute(KEY_SQL_IDENTIFIER_QUOTE, dialect.getIdentifierQuote()); + springModel.addAttribute("readonly", table.isReadonly()); setGridPageAttributes(request, response, springModel, schema, table); } }.execute(); diff --git a/datagear-web/src/main/java/org/datagear/web/controller/SchemaController.java b/datagear-web/src/main/java/org/datagear/web/controller/SchemaController.java index d1740a4a..f49f55c1 100644 --- a/datagear-web/src/main/java/org/datagear/web/controller/SchemaController.java +++ b/datagear-web/src/main/java/org/datagear/web/controller/SchemaController.java @@ -251,7 +251,7 @@ public class SchemaController extends AbstractSchemaConnTableController @ResponseBody public PagingData pagingQueryTable(HttpServletRequest request, HttpServletResponse response, org.springframework.ui.Model springModel, @PathVariable("schemaId") String schemaId, - @RequestBody(required = false) PagingQuery pagingQueryParam) throws Throwable + PagingQuery pagingQueryParam) throws Throwable { final PagingQuery pagingQuery = inflatePagingQuery(request, pagingQueryParam, COOKIE_PAGINATION_SIZE); diff --git a/datagear-web/src/main/resources/org/datagear/web/webapp/view/freemarker/main.ftl b/datagear-web/src/main/resources/org/datagear/web/webapp/view/freemarker/main.ftl index beeef941..318bc4db 100644 --- a/datagear-web/src/main/resources/org/datagear/web/webapp/view/freemarker/main.ftl +++ b/datagear-web/src/main/resources/org/datagear/web/webapp/view/freemarker/main.ftl @@ -374,8 +374,6 @@ ${detectNewVersionScript} { "data" : { - contentType: $.CONTENT_TYPE_JSON, - "type" : "POST", "url" : function(node) { //根节点 @@ -449,7 +447,6 @@ ${detectNewVersionScript} $.ajax($.toPath(false, contextPath, "schema", schemaId, "pagingQueryTable"), { - contentType: $.CONTENT_TYPE_JSON, data : param, success : function(pagingData) {