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 5fcb6a92..2f390165 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 @@ -152,7 +152,7 @@ public abstract class AbstractDevotedDBMetaResolver implements DevotedDBMetaReso column.setTypeName(resultSetMetaData.getColumnTypeName(i)); column.setSize(resultSetMetaData.getPrecision(i)); column.setDecimalDigits(resultSetMetaData.getScale(i)); - column.setNullable(DatabaseMetaData.columnNoNulls == resultSetMetaData.isNullable(i)); + column.setNullable(DatabaseMetaData.columnNoNulls != resultSetMetaData.isNullable(i)); column.setAutoincrement(resultSetMetaData.isAutoIncrement(i)); columnInfos[i - 1] = column; @@ -264,7 +264,7 @@ public abstract class AbstractDevotedDBMetaResolver implements DevotedDBMetaReso if (simpleTable != null) { - postProcessSimpleTable(cn, metaData, schema, simpleTable); + simpleTable = postProcessSimpleTable(cn, metaData, schema, simpleTable); simpleTables.add(simpleTable); } } @@ -318,9 +318,10 @@ public abstract class AbstractDevotedDBMetaResolver implements DevotedDBMetaReso return null; } - protected void postProcessSimpleTable(Connection cn, DatabaseMetaData metaData, String schema, + protected SimpleTable postProcessSimpleTable(Connection cn, DatabaseMetaData metaData, String schema, SimpleTable simpleTable) throws SQLException { + return simpleTable; } protected List getDataTypes(Connection cn, DatabaseMetaData metaData) throws DBMetaResolverException @@ -372,6 +373,13 @@ public abstract class AbstractDevotedDBMetaResolver implements DevotedDBMetaReso table.setUniqueKeys(getUniqueKeys(cn, metaData, schema, tableName)); table.setImportKeys(getImportKeys(cn, metaData, schema, tableName)); + table = postProcessTable(cn, metaData, schema, table); + + return table; + } + + protected Table postProcessTable(Connection cn, DatabaseMetaData metaData, String schema, Table table) + { return table; } @@ -409,8 +417,8 @@ public abstract class AbstractDevotedDBMetaResolver implements DevotedDBMetaReso while (rs.next()) { Column column = readColumn(cn, metaData, schema, tableName, rs); - if (addColumn(columns, column)) - postProcessColumn(cn, metaData, schema, tableName, column); + column = postProcessColumn(cn, metaData, schema, tableName, column); + addColumn(columns, column); if (count != null && columns.size() == count) break; @@ -450,13 +458,15 @@ public abstract class AbstractDevotedDBMetaResolver implements DevotedDBMetaReso column.setTypeName(rs.getString("TYPE_NAME")); column.setSize(rs.getInt("COLUMN_SIZE")); column.setDecimalDigits(rs.getInt("DECIMAL_DIGITS")); - column.setNullable(DatabaseMetaData.columnNoNulls == rs.getInt("NULLABLE")); + column.setNullable(DatabaseMetaData.columnNoNulls != rs.getInt("NULLABLE")); column.setComment(rs.getString("REMARKS")); column.setDefaultValue(rs.getString("COLUMN_DEF")); column.setAutoincrement("yes".equalsIgnoreCase(rs.getString("IS_AUTOINCREMENT"))); resolveSortable(cn, metaData, schema, tableName, column); resolveSearchableType(cn, metaData, schema, tableName, column); + resolveDefaultValue(column); + return column; } catch (SQLException e) @@ -465,6 +475,27 @@ public abstract class AbstractDevotedDBMetaResolver implements DevotedDBMetaReso } } + protected void resolveDefaultValue(Column column) + { + if (!column.hasDefaultValue()) + return; + + String value = column.getDefaultValue(); + int len = value.length(); + + // 移除开头和结尾的引号 + if (len >= 2 && ((value.charAt(0) == '\'' && value.charAt(len - 1) == '\'') + || (value.charAt(0) == '"' && value.charAt(len - 1) == '"'))) + { + value = (len == 2 ? "" : value.substring(1, value.length() - 1)); + column.setDefaultValue(value); + } + + if (StringUtil.isEmpty(value)) + return; + + } + @JDBCCompatiblity("很多驱动程序的值为SearchableType.ALL但实际并不支持LIKE语法(比如:PostgreSQL JDBC 42.2.5)," + "这里为了兼容,不采用数据库级的SearchableType逻辑") protected void resolveSearchableType(Connection cn, DatabaseMetaData metaData, String schema, String tableName, @@ -496,9 +527,10 @@ public abstract class AbstractDevotedDBMetaResolver implements DevotedDBMetaReso column.setSortable(sortable); } - protected void postProcessColumn(Connection cn, DatabaseMetaData metaData, String schema, String tableName, + protected Column postProcessColumn(Connection cn, DatabaseMetaData metaData, String schema, String tableName, Column column) throws SQLException { + return column; } protected ResultSet getColumnResulSet(Connection cn, DatabaseMetaData databaseMetaData, String schema, diff --git a/datagear-meta/src/main/java/org/datagear/meta/resolver/support/MySqlDevotedDBMetaResolver.java b/datagear-meta/src/main/java/org/datagear/meta/resolver/support/MySqlDevotedDBMetaResolver.java index 6851e147..fd5e43a8 100644 --- a/datagear-meta/src/main/java/org/datagear/meta/resolver/support/MySqlDevotedDBMetaResolver.java +++ b/datagear-meta/src/main/java/org/datagear/meta/resolver/support/MySqlDevotedDBMetaResolver.java @@ -36,10 +36,11 @@ public class MySqlDevotedDBMetaResolver extends AbstractConnectionDevotedDBMetaR } @Override - protected void postProcessSimpleTable(Connection cn, DatabaseMetaData metaData, String schema, + protected SimpleTable postProcessSimpleTable(Connection cn, DatabaseMetaData metaData, String schema, SimpleTable simpleTable) throws SQLException { resolveTableComment(simpleTable); + return simpleTable; } protected void resolveTableComment(SimpleTable st) diff --git a/datagear-persistence/src/main/java/org/datagear/persistence/support/ConversionSqlParamValueMapper.java b/datagear-persistence/src/main/java/org/datagear/persistence/support/ConversionSqlParamValueMapper.java index 870c9564..08100773 100644 --- a/datagear-persistence/src/main/java/org/datagear/persistence/support/ConversionSqlParamValueMapper.java +++ b/datagear-persistence/src/main/java/org/datagear/persistence/support/ConversionSqlParamValueMapper.java @@ -329,13 +329,19 @@ public class ConversionSqlParamValueMapper extends AbstractSqlParamValueMapper else if (value instanceof String) { String v = (String) value; - paramValue = getInputStreamIfFilePath(table, column, v); - if (paramValue == null) - paramValue = getIfBytesValue(table, column, v); + if (StringUtil.isEmpty(v)) + paramValue = null; + else + { + paramValue = getInputStreamIfFilePath(table, column, v); - if (paramValue == null) - sqlParamValue = mapToSqlParamValueExt(cn, table, column, value, InputStream.class); + if (paramValue == null) + paramValue = getIfBytesValue(table, column, v); + + if (paramValue == null) + sqlParamValue = mapToSqlParamValueExt(cn, table, column, value, InputStream.class); + } } else sqlParamValue = mapToSqlParamValueExt(cn, table, column, value, InputStream.class); @@ -410,13 +416,19 @@ public class ConversionSqlParamValueMapper extends AbstractSqlParamValueMapper else if (value instanceof String) { String v = (String) value; - paramValue = getInputStreamIfFilePath(table, column, v); - if (paramValue == null) - paramValue = getIfBytesValue(table, column, v); + if (StringUtil.isEmpty(v)) + paramValue = null; + else + { + paramValue = getInputStreamIfFilePath(table, column, v); - if (paramValue == null) - sqlParamValue = mapToSqlParamValueExt(cn, table, column, value, Blob.class); + if (paramValue == null) + paramValue = getIfBytesValue(table, column, v); + + if (paramValue == null) + sqlParamValue = mapToSqlParamValueExt(cn, table, column, value, Blob.class); + } } else sqlParamValue = mapToSqlParamValueExt(cn, table, column, value, Blob.class); 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 62c14ec4..ec0363be 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 @@ -81,7 +81,7 @@ public class DataController extends AbstractSchemaConnTableController public static final String KEY_TITLE_DISPLAY_DESC = "titleDisplayDesc"; - public static final String KEY_CONDITION_SOURCE = "conditionSource"; + public static final String KEY_SQL_IDENTIFIER_QUOTE = "sqlIdentifierQuote"; @Autowired private PersistenceManager persistenceManager; @@ -181,8 +181,11 @@ public class DataController extends AbstractSchemaConnTableController { checkReadTableDataPermission(schema, user); + Dialect dialect = persistenceManager.getDialectSource().getDialect(getConnection()); + springModel.addAttribute(KEY_TITLE_DISPLAY_NAME, table.getName()); springModel.addAttribute(KEY_TITLE_DISPLAY_DESC, table.getComment()); + springModel.addAttribute(KEY_SQL_IDENTIFIER_QUOTE, dialect.getIdentifierQuote()); setGridPageAttributes(request, response, springModel, schema, table); } }.execute(); @@ -357,8 +360,7 @@ public class DataController extends AbstractSchemaConnTableController org.springframework.ui.Model springModel, @PathVariable("schemaId") String schemaId, @PathVariable("tableName") String tableName, @RequestParam(value = PARAM_IGNORE_DUPLICATION, required = false) final Boolean ignoreDuplication, - @RequestBody Map paramData) - throws Throwable + @RequestBody Map paramData) throws Throwable { final User user = WebUtils.getUser(request, response); final Row originalRow = convertToRow((Map) paramData.get("originalData")); @@ -397,8 +399,7 @@ public class DataController extends AbstractSchemaConnTableController org.springframework.ui.Model springModel, @PathVariable("schemaId") String schemaId, @PathVariable("tableName") String tableName, @RequestParam(value = PARAM_IGNORE_DUPLICATION, required = false) final Boolean ignoreDuplication, - @RequestBody List> paramData) - throws Throwable + @RequestBody List> paramData) throws Throwable { final User user = WebUtils.getUser(request, response); final Row[] rows = convertToRows(paramData); @@ -578,7 +579,10 @@ public class DataController extends AbstractSchemaConnTableController { checkReadTableDataPermission(schema, user); + Dialect dialect = persistenceManager.getDialectSource().getDialect(getConnection()); + springModel.addAttribute(KEY_TITLE_DISPLAY_NAME, table.getName()); + springModel.addAttribute(KEY_SQL_IDENTIFIER_QUOTE, dialect.getIdentifierQuote()); springModel.addAttribute(KEY_SELECTONLY, true); setGridPageAttributes(request, response, springModel, schema, table); } diff --git a/datagear-web/src/main/java/org/datagear/web/controller/SqlpadController.java b/datagear-web/src/main/java/org/datagear/web/controller/SqlpadController.java index 4217f11a..ef191910 100644 --- a/datagear-web/src/main/java/org/datagear/web/controller/SqlpadController.java +++ b/datagear-web/src/main/java/org/datagear/web/controller/SqlpadController.java @@ -37,13 +37,13 @@ import org.datagear.web.sqlpad.SqlpadExecutionService; import org.datagear.web.sqlpad.SqlpadExecutionService.CommitMode; import org.datagear.web.sqlpad.SqlpadExecutionService.ExceptionHandleMode; import org.datagear.web.sqlpad.SqlpadExecutionService.SqlCommand; +import org.datagear.web.sqlpad.SqlpadExecutionSubmit; import org.datagear.web.util.WebUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; @@ -155,7 +155,7 @@ public class SqlpadController extends AbstractSchemaConnController springModel.addAttribute("sqlpadId", sqlpadId); springModel.addAttribute("sqlpadChannelId", sqlpadChannelId); - springModel.addAttribute("sqlResultReadActualLobRows", this.sqlResultReadActualLobRows); + springModel.addAttribute("sqlResultRowMapper", buildDefaultLOBRowMapper()); springModel.addAttribute("initSql", initSql); return "/sqlpad/sqlpad"; @@ -206,9 +206,12 @@ public class SqlpadController extends AbstractSchemaConnController List sqlStatements = sqlScriptParser.parseAll(); - this.sqlpadExecutionService.submit(user, schema, sqlpadId, + SqlpadExecutionSubmit submit = new SqlpadExecutionSubmit(user, schema, sqlpadId, FileUtil.getDirectory(getSqlpadTmpDirectory(), sqlpadId), sqlStatements, commitMode, - exceptionHandleMode, overTimeThreashold, resultsetFetchSize, WebUtils.getLocale(request)); + exceptionHandleMode, overTimeThreashold, resultsetFetchSize, buildDefaultLOBRowMapper(), + WebUtils.getLocale(request)); + + this.sqlpadExecutionService.submit(submit); return buildOperationMessageSuccessEmptyResponseEntity(); } @@ -311,7 +314,7 @@ public class SqlpadController extends AbstractSchemaConnController @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 User user = WebUtils.getUser(request, response); final PagingQuery pagingQuery = inflatePagingQuery(request, pagingQueryParam); diff --git a/datagear-web/src/main/java/org/datagear/web/sqlpad/SqlpadExecutionService.java b/datagear-web/src/main/java/org/datagear/web/sqlpad/SqlpadExecutionService.java index ad6b8c53..a1c53285 100644 --- a/datagear-web/src/main/java/org/datagear/web/sqlpad/SqlpadExecutionService.java +++ b/datagear-web/src/main/java/org/datagear/web/sqlpad/SqlpadExecutionService.java @@ -4,7 +4,6 @@ package org.datagear.web.sqlpad; -import java.io.File; import java.io.Serializable; import java.sql.Connection; import java.sql.ResultSet; @@ -22,10 +21,8 @@ import org.cometd.bayeux.server.ServerChannel; import org.datagear.connection.ConnectionSource; import org.datagear.connection.ConnectionSourceException; import org.datagear.management.domain.Schema; -import org.datagear.management.domain.User; import org.datagear.management.service.SqlHistoryService; import org.datagear.management.util.SchemaConnectionSupport; -import org.datagear.persistence.RowMapper; import org.datagear.persistence.support.PersistenceSupport; import org.datagear.persistence.support.SqlSelectManager; import org.datagear.persistence.support.SqlSelectResult; @@ -53,8 +50,6 @@ public class SqlpadExecutionService extends PersistenceSupport private SqlSelectManager sqlSelectManager; - private RowMapper sqlSelectResultRowMapper = null; - private SqlPermissionChecker sqlPermissionChecker = new SqlPermissionChecker(); private SchemaConnectionSupport schemaConnectionSupport = new SchemaConnectionSupport(); @@ -130,16 +125,6 @@ public class SqlpadExecutionService extends PersistenceSupport this.sqlSelectManager = sqlSelectManager; } - public RowMapper getSqlSelectResultRowMapper() - { - return sqlSelectResultRowMapper; - } - - public void setSqlSelectResultRowMapper(RowMapper sqlSelectResultRowMapper) - { - this.sqlSelectResultRowMapper = sqlSelectResultRowMapper; - } - public SqlPermissionChecker getSqlPermissionChecker() { return sqlPermissionChecker; @@ -163,29 +148,18 @@ public class SqlpadExecutionService extends PersistenceSupport /** * 提交SQL执行。 * - * @param user - * @param schema - * @param sqlpadId - * @param sqlpadFileDirectory - * @param sqlStatements - * @param commitMode - * @param exceptionHandleMode - * @param overTimeThreashold - * @param resultsetFetchSize - * @param locale + * @param submit * @return */ - public boolean submit(User user, Schema schema, String sqlpadId, File sqlpadFileDirectory, - List sqlStatements, CommitMode commitMode, ExceptionHandleMode exceptionHandleMode, - int overTimeThreashold, int resultsetFetchSize, Locale locale) + public boolean submit(SqlpadExecutionSubmit submit) { - String sqlpadChannelId = getSqlpadChannelId(sqlpadId); + String sqlpadChannelId = getSqlpadChannelId(submit.getSqlpadId()); - SqlpadExecutionRunnable sqlpadExecutionRunnable = new SqlpadExecutionRunnable(user, schema, sqlpadId, - sqlpadFileDirectory, sqlpadChannelId, sqlpadCometdService, sqlStatements, commitMode, - exceptionHandleMode, overTimeThreashold, resultsetFetchSize, locale); + SqlpadExecutionRunnable sqlpadExecutionRunnable = new SqlpadExecutionRunnable(submit, sqlpadChannelId, + sqlpadCometdService); - SqlpadExecutionRunnable old = this._sqlpadExecutionRunnableMap.putIfAbsent(sqlpadId, sqlpadExecutionRunnable); + SqlpadExecutionRunnable old = this._sqlpadExecutionRunnableMap.putIfAbsent(submit.getSqlpadId(), + sqlpadExecutionRunnable); if (old != null) return false; @@ -276,34 +250,12 @@ public class SqlpadExecutionService extends PersistenceSupport * @author datagear@163.com * */ - protected class SqlpadExecutionRunnable implements Runnable + protected class SqlpadExecutionRunnable extends SqlpadExecutionSubmit implements Runnable { - private User user; - - private Schema schema; - - private String sqlpadId; - - private File sqlpadFileDirectory; - private String sqlpadChannelId; private SqlpadCometdService sqlpadCometdService; - private List sqlStatements; - - private CommitMode commitMode; - - private ExceptionHandleMode exceptionHandleMode; - - /** 超时分钟数 */ - private int overTimeThreashold; - - /** 结果集页大小 */ - private int resultsetFetchSize; - - private Locale locale; - /** 发送给此Runnable的SQL命令 */ private volatile SqlCommand sqlCommand; @@ -314,64 +266,12 @@ public class SqlpadExecutionService extends PersistenceSupport super(); } - public SqlpadExecutionRunnable(User user, Schema schema, String sqlpadId, File sqlpadFileDirectory, - String sqlpadChannelId, SqlpadCometdService sqlpadCometdService, List sqlStatements, - CommitMode commitMode, ExceptionHandleMode exceptionHandleMode, int overTimeThreashold, - int resultsetFetchSize, Locale locale) + public SqlpadExecutionRunnable(SqlpadExecutionSubmit submit, String sqlpadChannelId, + SqlpadCometdService sqlpadCometdService) { - super(); - this.user = user; - this.schema = schema; - this.sqlpadId = sqlpadId; - this.sqlpadFileDirectory = sqlpadFileDirectory; + super(submit); this.sqlpadChannelId = sqlpadChannelId; this.sqlpadCometdService = sqlpadCometdService; - this.sqlStatements = sqlStatements; - this.commitMode = commitMode; - this.exceptionHandleMode = exceptionHandleMode; - this.overTimeThreashold = overTimeThreashold; - this.resultsetFetchSize = resultsetFetchSize; - this.locale = locale; - } - - public User getUser() - { - return user; - } - - public void setUser(User user) - { - this.user = user; - } - - public Schema getSchema() - { - return schema; - } - - public void setSchema(Schema schema) - { - this.schema = schema; - } - - public String getSqlpadId() - { - return sqlpadId; - } - - public void setSqlpadId(String sqlpadId) - { - this.sqlpadId = sqlpadId; - } - - public File getSqlpadFileDirectory() - { - return sqlpadFileDirectory; - } - - public void setSqlpadFileDirectory(File sqlpadFileDirectory) - { - this.sqlpadFileDirectory = sqlpadFileDirectory; } public String getSqlpadChannelId() @@ -394,66 +294,6 @@ public class SqlpadExecutionService extends PersistenceSupport this.sqlpadCometdService = sqlpadCometdService; } - public List getSqlStatements() - { - return sqlStatements; - } - - public void setSqlStatements(List sqlStatements) - { - this.sqlStatements = sqlStatements; - } - - public CommitMode getCommitMode() - { - return commitMode; - } - - public void setCommitMode(CommitMode commitMode) - { - this.commitMode = commitMode; - } - - public ExceptionHandleMode getExceptionHandleMode() - { - return exceptionHandleMode; - } - - public void setExceptionHandleMode(ExceptionHandleMode exceptionHandleMode) - { - this.exceptionHandleMode = exceptionHandleMode; - } - - public int getOverTimeThreashold() - { - return overTimeThreashold; - } - - public void setOverTimeThreashold(int overTimeThreashold) - { - this.overTimeThreashold = overTimeThreashold; - } - - public int getResultsetFetchSize() - { - return resultsetFetchSize; - } - - public void setResultsetFetchSize(int resultsetFetchSize) - { - this.resultsetFetchSize = resultsetFetchSize; - } - - public Locale getLocale() - { - return locale; - } - - public void setLocale(Locale locale) - { - this.locale = locale; - } - public SqlCommand getSqlCommand() { return sqlCommand; @@ -481,11 +321,11 @@ public class SqlpadExecutionService extends PersistenceSupport Connection cn = null; Statement st = null; - this.sqlpadCometdService.sendStartMessage(this._sqlpadServerChannel, this.sqlStatements.size()); + this.sqlpadCometdService.sendStartMessage(this._sqlpadServerChannel, getSqlStatements().size()); try { - cn = getSchemaConnection(this.schema); + cn = getSchemaConnection(getSchema()); JdbcUtil.setAutoCommitIfSupports(cn, false); JdbcUtil.setReadonlyIfSupports(cn, false); st = createStatement(cn); @@ -493,19 +333,19 @@ public class SqlpadExecutionService extends PersistenceSupport catch (Throwable t) { this.sqlpadCometdService.sendExceptionMessage(_sqlpadServerChannel, t, - getMessage(this.locale, "sqlpad.executionConnectionException"), false); + getMessage(getLocale(), "sqlpad.executionConnectionException"), false); this.sqlpadCometdService.sendFinishMessage(this._sqlpadServerChannel); - _sqlpadExecutionRunnableMap.remove(this.sqlpadId); + _sqlpadExecutionRunnableMap.remove(getSqlpadId()); return; } long startTime = System.currentTimeMillis(); - int totalCount = this.sqlStatements.size(); + int totalCount = getSqlStatements().size(); SQLExecutionStat sqlExecutionStat = new SQLExecutionStat(totalCount); - SqlpadFileDirectory sqlpadFileDirectory = SqlpadFileDirectory.valueOf(this.sqlpadFileDirectory); + SqlpadFileDirectory sqlpadFileDirectory = SqlpadFileDirectory.valueOf(getSqlpadFileDirectory()); List sqlHistories = new ArrayList<>(); @@ -516,12 +356,13 @@ public class SqlpadExecutionService extends PersistenceSupport if (handleSqlCommandInExecution(cn, true, sqlExecutionStat)) break; - SqlStatement sqlStatement = sqlStatements.get(i); + SqlStatement sqlStatement = getSqlStatements().get(i); - if (!SqlpadExecutionService.this.sqlPermissionChecker.hasPermission(user, schema, sqlStatement)) + if (!SqlpadExecutionService.this.sqlPermissionChecker.hasPermission(getUser(), getSchema(), + sqlStatement)) { this.sqlpadCometdService.sendSqlExceptionMessage(_sqlpadServerChannel, sqlStatement, i, - getMessage(this.locale, "sqlpad.executionSQLPermissionDenied")); + getMessage(getLocale(), "sqlpad.executionSQLPermissionDenied")); sqlExecutionStat.increaseExceptionCount(); } @@ -539,9 +380,9 @@ public class SqlpadExecutionService extends PersistenceSupport sqlExecutionStat.increaseExceptionCount(); this.sqlpadCometdService.sendSqlExceptionMessage(_sqlpadServerChannel, sqlStatement, i, e, - getMessage(this.locale, "sqlpad.executionSQLException", e.getMessage())); + getMessage(getLocale(), "sqlpad.executionSQLException", e.getMessage())); - if (ExceptionHandleMode.IGNORE.equals(this.exceptionHandleMode)) + if (ExceptionHandleMode.IGNORE.equals(getExceptionHandleMode())) ; else { @@ -555,10 +396,10 @@ public class SqlpadExecutionService extends PersistenceSupport ; else { - if (CommitMode.AUTO.equals(this.commitMode)) + if (CommitMode.AUTO.equals(getCommitMode())) { if (sqlExecutionStat.getExceptionCount() > 0 - && ExceptionHandleMode.ROLLBACK.equals(this.exceptionHandleMode)) + && ExceptionHandleMode.ROLLBACK.equals(getExceptionHandleMode())) this.sqlCommand = SqlCommand.ROLLBACK; else this.sqlCommand = SqlCommand.COMMIT; @@ -570,7 +411,7 @@ public class SqlpadExecutionService extends PersistenceSupport catch (Throwable t) { this.sqlpadCometdService.sendExceptionMessage(_sqlpadServerChannel, t, - getMessage(this.locale, "sqlpad.executionErrorOccure"), true); + getMessage(getLocale(), "sqlpad.executionErrorOccure"), true); } finally { @@ -581,11 +422,11 @@ public class SqlpadExecutionService extends PersistenceSupport this.sqlpadCometdService.sendFinishMessage(this._sqlpadServerChannel, sqlExecutionStat); - _sqlpadExecutionRunnableMap.remove(this.sqlpadId); + _sqlpadExecutionRunnableMap.remove(getSqlpadId()); } if (!sqlHistories.isEmpty()) - SqlpadExecutionService.this.sqlHistoryService.addForRemain(this.schema.getId(), this.user.getId(), + SqlpadExecutionService.this.sqlHistoryService.addForRemain(getSchema().getId(), getUser().getId(), sqlHistories); } @@ -611,19 +452,19 @@ public class SqlpadExecutionService extends PersistenceSupport hasPaused = true; if (sendMessageIfPause) - sendSqlCommandMessage(this.sqlCommand, this.overTimeThreashold); + sendSqlCommandMessage(this.sqlCommand, getOverTimeThreashold()); long waitStartTime = System.currentTimeMillis(); while (SqlCommand.PAUSE.equals(this.sqlCommand) - && (System.currentTimeMillis() - waitStartTime) <= this.overTimeThreashold * 60 * 1000) + && (System.currentTimeMillis() - waitStartTime) <= getOverTimeThreashold() * 60 * 1000) sleepForSqlCommand(); // 暂停超时 if (SqlCommand.PAUSE.equals(this.sqlCommand)) { this.sqlpadCometdService.sendTextMessage(this._sqlpadServerChannel, - getMessage(this.locale, "sqlpad.pauseOverTime")); + getMessage(getLocale(), "sqlpad.pauseOverTime")); this.sqlCommand = SqlCommand.RESUME; } @@ -690,12 +531,12 @@ public class SqlpadExecutionService extends PersistenceSupport long waitStartTime = System.currentTimeMillis(); while (!SqlCommand.COMMIT.equals(this.sqlCommand) && !SqlCommand.ROLLBACK.equals(this.sqlCommand) - && (System.currentTimeMillis() - waitStartTime) <= this.overTimeThreashold * 60 * 1000) + && (System.currentTimeMillis() - waitStartTime) <= getOverTimeThreashold() * 60 * 1000) { if (!sendWatingMessage) { this.sqlpadCometdService.sendTextMessage(this._sqlpadServerChannel, - getMessage(this.locale, "sqlpad.waitingForCommitOrRollback", this.overTimeThreashold), + getMessage(getLocale(), "sqlpad.waitingForCommitOrRollback", getOverTimeThreashold()), "message-content-highlight", sqlExecutionStat); sendWatingMessage = true; @@ -708,7 +549,7 @@ public class SqlpadExecutionService extends PersistenceSupport if (!SqlCommand.COMMIT.equals(this.sqlCommand) && !SqlCommand.ROLLBACK.equals(this.sqlCommand)) { this.sqlpadCometdService.sendTextMessage(this._sqlpadServerChannel, - getMessage(this.locale, "sqlpad.waitOverTime")); + getMessage(getLocale(), "sqlpad.waitOverTime")); this.sqlCommand = (sqlExecutionStat.getExceptionCount() > 0 ? SqlCommand.ROLLBACK : SqlCommand.COMMIT); } @@ -760,7 +601,7 @@ public class SqlpadExecutionService extends PersistenceSupport ResultSet rs = st.getResultSet(); SqlSelectResult sqlSelectResult = SqlpadExecutionService.this.sqlSelectManager.select(cn, sql, rs, 1, - this.resultsetFetchSize, SqlpadExecutionService.this.sqlSelectResultRowMapper); + getResultsetFetchSize(), getResultsetRowMapper()); this.sqlpadCometdService.sendSqlSuccessMessage(this._sqlpadServerChannel, sqlStatement, sqlStatementIndex, sqlSelectResult); @@ -795,7 +636,7 @@ public class SqlpadExecutionService extends PersistenceSupport String messageKey = "sqlpad.SqlCommand." + sqlCommand.toString() + ".ok"; this.sqlpadCometdService.sendSqlCommandMessage(this._sqlpadServerChannel, sqlCommand, - getMessage(this.locale, messageKey, messageArgs)); + getMessage(getLocale(), messageKey, messageArgs)); } /** @@ -811,7 +652,7 @@ public class SqlpadExecutionService extends PersistenceSupport // 而这里调用的结果集都是从第一行开始,不会用到ResultSet.TYPE_SCROLL_*特性, // 因而采用ResultSet.TYPE_FORWARD_ONLY,避免遇到上述情况而抛出异常 Statement st = createUpdateStatement(cn); - JdbcUtil.setFetchSizeIfSupports(st, resultsetFetchSize); + JdbcUtil.setFetchSizeIfSupports(st, getResultsetFetchSize()); return st; } diff --git a/datagear-web/src/main/java/org/datagear/web/sqlpad/SqlpadExecutionSubmit.java b/datagear-web/src/main/java/org/datagear/web/sqlpad/SqlpadExecutionSubmit.java new file mode 100644 index 00000000..91c48df3 --- /dev/null +++ b/datagear-web/src/main/java/org/datagear/web/sqlpad/SqlpadExecutionSubmit.java @@ -0,0 +1,189 @@ +/* + * Copyright (c) 2018 datagear.tech. All Rights Reserved. + */ + +/** + * + */ +package org.datagear.web.sqlpad; + +import java.io.File; +import java.util.List; +import java.util.Locale; + +import org.datagear.management.domain.Schema; +import org.datagear.management.domain.User; +import org.datagear.persistence.RowMapper; +import org.datagear.util.SqlScriptParser.SqlStatement; +import org.datagear.web.sqlpad.SqlpadExecutionService.CommitMode; +import org.datagear.web.sqlpad.SqlpadExecutionService.ExceptionHandleMode; + +/** + * SQL工作台执行提交。 + * + * @author datagear@163.com + * + */ +public class SqlpadExecutionSubmit +{ + private User user; + + private Schema schema; + + private String sqlpadId; + + private File sqlpadFileDirectory; + + private List sqlStatements; + + private CommitMode commitMode; + + private ExceptionHandleMode exceptionHandleMode; + + private int overTimeThreashold; + + private int resultsetFetchSize; + + private RowMapper resultsetRowMapper; + + private Locale locale; + + public SqlpadExecutionSubmit() + { + } + + public SqlpadExecutionSubmit(SqlpadExecutionSubmit from) + { + this(from.user, from.schema, from.sqlpadId, from.sqlpadFileDirectory, from.sqlStatements, from.commitMode, + from.exceptionHandleMode, from.overTimeThreashold, from.resultsetFetchSize, from.resultsetRowMapper, + from.locale); + } + + public SqlpadExecutionSubmit(User user, Schema schema, String sqlpadId, File sqlpadFileDirectory, + List sqlStatements, CommitMode commitMode, ExceptionHandleMode exceptionHandleMode, + int overTimeThreashold, int resultsetFetchSize, RowMapper resultsetRowMapper, Locale locale) + { + super(); + this.user = user; + this.schema = schema; + this.sqlpadId = sqlpadId; + this.sqlpadFileDirectory = sqlpadFileDirectory; + this.sqlStatements = sqlStatements; + this.commitMode = commitMode; + this.exceptionHandleMode = exceptionHandleMode; + this.overTimeThreashold = overTimeThreashold; + this.resultsetFetchSize = resultsetFetchSize; + this.resultsetRowMapper = resultsetRowMapper; + this.locale = locale; + } + + public User getUser() + { + return user; + } + + public void setUser(User user) + { + this.user = user; + } + + public Schema getSchema() + { + return schema; + } + + public void setSchema(Schema schema) + { + this.schema = schema; + } + + public String getSqlpadId() + { + return sqlpadId; + } + + public void setSqlpadId(String sqlpadId) + { + this.sqlpadId = sqlpadId; + } + + public File getSqlpadFileDirectory() + { + return sqlpadFileDirectory; + } + + public void setSqlpadFileDirectory(File sqlpadFileDirectory) + { + this.sqlpadFileDirectory = sqlpadFileDirectory; + } + + public List getSqlStatements() + { + return sqlStatements; + } + + public void setSqlStatements(List sqlStatements) + { + this.sqlStatements = sqlStatements; + } + + public CommitMode getCommitMode() + { + return commitMode; + } + + public void setCommitMode(CommitMode commitMode) + { + this.commitMode = commitMode; + } + + public ExceptionHandleMode getExceptionHandleMode() + { + return exceptionHandleMode; + } + + public void setExceptionHandleMode(ExceptionHandleMode exceptionHandleMode) + { + this.exceptionHandleMode = exceptionHandleMode; + } + + public int getOverTimeThreashold() + { + return overTimeThreashold; + } + + public void setOverTimeThreashold(int overTimeThreashold) + { + this.overTimeThreashold = overTimeThreashold; + } + + public int getResultsetFetchSize() + { + return resultsetFetchSize; + } + + public void setResultsetFetchSize(int resultsetFetchSize) + { + this.resultsetFetchSize = resultsetFetchSize; + } + + public RowMapper getResultsetRowMapper() + { + return resultsetRowMapper; + } + + public void setResultsetRowMapper(RowMapper resultsetRowMapper) + { + this.resultsetRowMapper = resultsetRowMapper; + } + + public Locale getLocale() + { + return locale; + } + + public void setLocale(Locale locale) + { + this.locale = locale; + } +} diff --git a/datagear-web/src/main/resources/org/datagear/web/webapp/static/script/datagear-util.js b/datagear-web/src/main/resources/org/datagear/web/webapp/static/script/datagear-util.js index 88065685..f2655a29 100644 --- a/datagear-web/src/main/resources/org/datagear/web/webapp/static/script/datagear-util.js +++ b/datagear-web/src/main/resources/org/datagear/web/webapp/static/script/datagear-util.js @@ -1432,21 +1432,15 @@ /** * 构建查询条件Autocomplete组件的“source”选项值。 - * - * @param propertyPathDisplayNames */ - buildSearchConditionAutocompleteSource : function(propertyPathDisplayNames) + buildSearchConditionAutocompleteSource : function(table, sqlIdentifierQuote) { var source = []; - if(!propertyPathDisplayNames) - return source; - - for(var i=0; i").attr("name", "dataSetPropertyTypes").val(dsp.type).appendTo($dspWrapper); } - po.sqlPreviewOptions.startRow = modelSqlResult.startRow; - po.sqlPreviewOptions.nextStartRow = modelSqlResult.nextStartRow; - po.sqlPreviewOptions.fetchSize = modelSqlResult.fetchSize; + po.sqlPreviewOptions.startRow = sqlResult.startRow; + po.sqlPreviewOptions.nextStartRow = sqlResult.nextStartRow; + po.sqlPreviewOptions.fetchSize = sqlResult.fetchSize; if(initDataTable) { - var model = modelSqlResult.model; - var columns = $.buildDataTablesColumns(model); + var columns = $.buildDataTablesColumns(sqlResult.table); var newColumns = [ { @@ -266,7 +265,7 @@ readonly 是否只读操作,允许为null var settings = { "columns" : newColumns, - "data" : (modelSqlResult.datas ? modelSqlResult.datas : []), + "data" : (sqlResult.rows ? sqlResult.rows : []), "scrollX": true, "scrollY" : po.calSqlResultTableHeight(), "autoWidth": true, @@ -287,10 +286,10 @@ readonly 是否只读操作,允许为null else { var dataTable = table.DataTable(); - $.addDataTableData(dataTable, modelSqlResult.datas, modelSqlResult.startRow-1); + $.addDataTableData(dataTable, sqlResult.rows, sqlResult.startRow-1); } - if(modelSqlResult.datas.length < modelSqlResult.fetchSize) + if(sqlResult.rows.length < sqlResult.fetchSize) { po.sqlPreviewOptions.noMoreData = true; po.element(".no-more-data-flag").show(); diff --git a/datagear-web/src/main/resources/org/datagear/web/webapp/view/freemarker/data/data_grid.ftl b/datagear-web/src/main/resources/org/datagear/web/webapp/view/freemarker/data/data_grid.ftl index 3879e1b4..668e97e3 100644 --- a/datagear-web/src/main/resources/org/datagear/web/webapp/view/freemarker/data/data_grid.ftl +++ b/datagear-web/src/main/resources/org/datagear/web/webapp/view/freemarker/data/data_grid.ftl @@ -5,13 +5,15 @@ Schema schema 数据库,不允许为null Table table 模型,不允许为null String titleDisplayName 页面展示名称,默认为"" String titleDisplayDesc 页面展示描述,默认为"" -selectonly 是否选择操作,允许为null +boolean selectonly 是否选择操作,允许为null +boolean isMultipleSelect 是否多选,默认为false boolean readonly 是否只读操作,默认为false List PropertyPathDisplayName conditionSource 可用的查询条件列表,不允许为null --> <#assign titleDisplayName=(titleDisplayName!'')> <#assign titleDisplayDesc=(titleDisplayDesc!'')> <#assign selectonly=(selectonly!false)> +<#assign isMultipleSelect=(isMultipleSelect!false)> <#assign readonly=(readonly!false)> <#if selectonly> <#assign readonly=true> @@ -89,7 +91,8 @@ List PropertyPathDisplayName conditionSource 可用的查询条件列表,不 - - diff --git a/datagear-web/src/main/resources/org/datagear/web/webapp/view/freemarker/data/include/data_page_obj_form.ftl b/datagear-web/src/main/resources/org/datagear/web/webapp/view/freemarker/data/include/data_page_obj_form.ftl index 966b4c26..7c4bc2d1 100644 --- a/datagear-web/src/main/resources/org/datagear/web/webapp/view/freemarker/data/include/data_page_obj_form.ftl +++ b/datagear-web/src/main/resources/org/datagear/web/webapp/view/freemarker/data/include/data_page_obj_form.ftl @@ -49,6 +49,7 @@ po.isClientPageData = undefined; { submit : function(data) { + alert("TODO"); } } }; diff --git a/datagear-web/src/main/resources/org/datagear/web/webapp/view/freemarker/sqlpad/sqlpad.ftl b/datagear-web/src/main/resources/org/datagear/web/webapp/view/freemarker/sqlpad/sqlpad.ftl index 1450ba95..04a40826 100644 --- a/datagear-web/src/main/resources/org/datagear/web/webapp/view/freemarker/sqlpad/sqlpad.ftl +++ b/datagear-web/src/main/resources/org/datagear/web/webapp/view/freemarker/sqlpad/sqlpad.ftl @@ -181,7 +181,8 @@ Schema schema 数据库,不允许为null po.schemaId = "${schema.id}"; po.sqlpadId = "${sqlpadId}"; po.sqlpadChannelId = "${sqlpadChannelId}"; - po.sqlResultReadActualLobRows = parseInt("${sqlResultReadActualLobRows}"); + po.sqlResultReadActualBlobRows = parseInt("${sqlResultRowMapper.readActualBlobRows}"); + po.sqlResultBlobPlaceholder = "${sqlResultRowMapper.blobPlaceholder?js_string}"; po.resultMessageElement = po.element("#${pageId}-resultMessage"); po.sqlResultTabs = po.element("#${pageId}-sqlResultTabs"); @@ -391,7 +392,7 @@ Schema schema 数据库,不允许为null if(!tabId) tabId = po.genSqlResultTabId(); - po.renderSqlResultTab(tabId, msgData.sqlStatement.sql, msgData.modelSqlResult, (po.executingSqlCount == 1)); + po.renderSqlResultTab(tabId, msgData.sqlStatement.sql, msgData.sqlSelectResult, (po.executingSqlCount == 1)); $("") .html("<@spring.message code='sqlpad.viewResult' />") @@ -591,7 +592,7 @@ Schema schema 数据库,不允许为null return tabId + "-form"; }; - po.renderSqlResultTab = function(tabId, sql, modelSqlResult, active) + po.renderSqlResultTab = function(tabId, sql, sqlSelectResult, active) { var tabsNav = po.getTabsNav(po.sqlResultTabs); var tab = po.getTabsTabByTabId(po.sqlResultTabs, tabsNav, tabId); @@ -638,7 +639,7 @@ Schema schema 数据库,不允许为null } var table = $("
").attr("id", po.getSqlResultTabPanelTableId(tabId)).appendTo(tabPanel); - po.initSqlResultDataTable(tabId, table, sql, modelSqlResult); + po.initSqlResultDataTable(tabId, table, sql, sqlSelectResult); $("
") .attr("title", "<@spring.message code='sqlpad.noMoreData' />").appendTo(tabPanel); @@ -652,10 +653,10 @@ Schema schema 数据库,不允许为null $("").val(po.sqlpadId).appendTo(form); $("