diff --git a/code/datastudio/src/org.opengauss.mppdbide.bl/src/org/opengauss/mppdbide/bl/serverdatacache/DebugObjects.java b/code/datastudio/src/org.opengauss.mppdbide.bl/src/org/opengauss/mppdbide/bl/serverdatacache/DebugObjects.java index 0b95a949502842e6126648015673acfadabca64a..b5f38dcd44bec98c7b53aa3f63ee760dfb907f21 100644 --- a/code/datastudio/src/org.opengauss.mppdbide.bl/src/org/opengauss/mppdbide/bl/serverdatacache/DebugObjects.java +++ b/code/datastudio/src/org.opengauss.mppdbide.bl/src/org/opengauss/mppdbide/bl/serverdatacache/DebugObjects.java @@ -27,6 +27,7 @@ import org.opengauss.mppdbide.bl.serverdatacache.DebugObjects.DebugObjectsUtils. import org.opengauss.mppdbide.utils.IMessagesConstants; import org.opengauss.mppdbide.utils.IMessagesConstantsOne; import org.opengauss.mppdbide.utils.MPPDBIDEConstants; +import org.opengauss.mppdbide.utils.VariableRunLine; import org.opengauss.mppdbide.utils.exceptions.DatabaseCriticalException; import org.opengauss.mppdbide.utils.exceptions.DatabaseOperationException; import org.opengauss.mppdbide.utils.exceptions.MPPDBIDEException; @@ -873,8 +874,8 @@ public class DebugObjects extends BatchDropServerObject implements ObjectChange, hasout = createTemplateFromParams(params, parameterObject.getTemplateParams(), template, parameterObject.getOutParams()); - if (MessageConfigLoader.getProperty(IMessagesConstants.COVERAGE_HINT).equalsIgnoreCase(coverageHint)) { - usagehint.append(coverageHint + MPPDBIDEConstants.LINE_SEPARATOR); + if (VariableRunLine.isDebugUsagehint != null) { + usagehint.append(coverageHint + MPPDBIDEConstants.LINE_SEPARATOR); } if (hasout) { usagehint.append(MessageConfigLoader.getProperty(IMessagesConstants.EXEC_DEBUG_DIALOG_OUT_PARA_MSG) diff --git a/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/common/DbeCommonUtils.java b/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/common/DbeCommonUtils.java index 3543434012d35e64092d21decf351e65e3d4ce08..a34a6dafe9c35f99e67008a0a4350180060b6326 100644 --- a/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/common/DbeCommonUtils.java +++ b/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/common/DbeCommonUtils.java @@ -27,6 +27,7 @@ import java.util.stream.Collectors; import org.apache.commons.lang.StringUtils; import org.opengauss.mppdbide.debuger.service.DbeDebugService; +import org.opengauss.mppdbide.debuger.service.SourceCodeService; import org.opengauss.mppdbide.debuger.vo.dbe.InfoCodeVo; import org.opengauss.mppdbide.utils.IMessagesConstants; import org.opengauss.mppdbide.utils.loader.MessageConfigLoader; @@ -53,6 +54,13 @@ public final class DbeCommonUtils { */ public static final String END = "END"; + /** + * CREATE_TABLE + */ + public static final String CREATE_TABLE = "CREATE TABLE"; + + private static final String CREATE_TABLE_NOT = "CREATE TABLE IF NOT EXISTS"; + private DbeCommonUtils() { } @@ -72,7 +80,10 @@ public final class DbeCommonUtils { List canBreaks = infos.stream().filter(item -> item.canbreak).collect(Collectors.toList()); for (int i = 0; i < indexs.size(); i++) { String selectCode = sourceCodes.get(Integer.parseInt(indexs.get(i))); - long count = canBreaks.stream().filter(item -> item.query.equalsIgnoreCase(selectCode)).count(); + long count = canBreaks.stream().filter(item -> { + String str = item.query.replaceAll("$function$", "$$"); + return str.equalsIgnoreCase(selectCode); + }).count(); if (count == 0) { throw new SQLException(MessageConfigLoader.getProperty(IMessagesConstants.NOT_SUPPORT_BREAK)); } @@ -99,6 +110,14 @@ public final class DbeCommonUtils { map.put(END, i); } } + Integer begin = map.get(BEGIN); + Integer end = map.get(END); + if (begin == null) { + map.put(BEGIN, getBeginIndex(sourceCodes, BEGIN)); + } + if (end == null) { + map.put(END, getEndIndex(sourceCodes, END)); + } return map; } @@ -113,6 +132,49 @@ public final class DbeCommonUtils { return firstCode.toUpperCase(Locale.ENGLISH).trim().startsWith(endCode); } + /** + * getBeginIndex + * + * @param codes codes + * @param match match + * @return int int + */ + public static int getBeginIndex(List codes, String match) { + for(int i =0; i codes, String match) { + for(int i =codes.size()-1; i sourceCodes, String match) { + return sourceCodes.stream().filter(item -> checkStrEquals(item ,END)).count(); + } + /** * getCanBreakLinesByInfo * @@ -122,7 +184,7 @@ public final class DbeCommonUtils { * @return List string */ public static List getCanBreakLinesByInfo(IConnection conn, List inputsParams, - List sourceCodes) { + List sourceCodes) { List infos = null; try { infos = DbeDebugService.getInfoCodes(conn, inputsParams); @@ -145,6 +207,9 @@ public final class DbeCommonUtils { List linse = new ArrayList(); for (int i = map.get(BEGIN); i < sourceCodes.size(); i++) { if (i >= map.get(END)) { + if (checkIsEqualLine(sourceCodes, END) == 0) { + linse.add(String.valueOf(i)); + } return linse; } if (i < infos.size() && infos.get(i).canbreak) { @@ -175,4 +240,30 @@ public final class DbeCommonUtils { } return index; } + + /** + * getNeedDropTableName + * + * @param code code + * @return List list + */ + public static List getNeedDropTableName(String code) { + List list = new ArrayList<>(); + String newCode = code.toUpperCase(Locale.ENGLISH).replaceAll(CREATE_TABLE, CREATE_TABLE_NOT); + int index = 0; + String needCode = null; + while(true) { + index = newCode.indexOf(CREATE_TABLE_NOT); + if (index == -1) { + return list; + } + index = index + CREATE_TABLE_NOT.length(); + newCode = newCode.substring(index); + index = newCode.indexOf("("); + if (index != -1) { + needCode = newCode.substring(0, index); + list.add(needCode.trim()); + } + } + } } \ No newline at end of file diff --git a/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/debuger/service/DbeSourceCodeService.java b/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/debuger/service/DbeSourceCodeService.java index 16a430449df1ac77405d415edb14e76f89275c83..a026eb0af85f7a5577201b61f9d7b8750dae86c4 100644 --- a/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/debuger/service/DbeSourceCodeService.java +++ b/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/debuger/service/DbeSourceCodeService.java @@ -16,6 +16,7 @@ package org.opengauss.mppdbide.debuger.service; import java.util.List; +import java.util.Locale; import org.opengauss.mppdbide.common.DbeCommonUtils; import org.opengauss.mppdbide.debuger.exception.DebugPositionNotFoundException; @@ -37,4 +38,56 @@ public class DbeSourceCodeService extends SourceCodeService { List terminalCodes = super.totalCodeDesc.getCodeList(); return DbeCommonUtils.compluteIndex(DbeCommonUtils.infoCodes, terminalCodes); } -} + + /** + * set base code + * + * @param the base code + * @return void + */ + @Override + public void setBaseCode(String code) { + this.baseCodeDesc = new DbeCodeDescription(code); + } + + /** + * set total code + * + * @param the total code + * @return void + */ + @Override + public void setTotalCode(String code) { + this.totalCodeDesc = new DbeCodeDescription(code); + } + + /** + * Title: CodeDescription class + */ + public static class DbeCodeDescription extends CodeDescription{ + /** + * DbeCodeDescription + * + * @param code + */ + public DbeCodeDescription(String code) { + super(code); + } + + /** + * get BeginFromCode + * + * @param lines line + * @return int linse item + */ + @Override + public int getBeginFromCode(List lines) { + for (int i = 0; i < lines.size(); i++) { + if (lines.get(i).toUpperCase(Locale.ENGLISH).trim().startsWith(DbeCommonUtils.BEGIN)) { + return i; + } + } + return DbeCommonUtils.getBeginIndex(lines, DbeCommonUtils.BEGIN); + } + } +} \ No newline at end of file diff --git a/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/debuger/service/DebuggerReportService.java b/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/debuger/service/DebuggerReportService.java index fbf1081acfefc5d4d85174f43cb829a82cd583ce..1d143b64a01cdbd539f3a3399a8b3b8a768b2a30 100644 --- a/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/debuger/service/DebuggerReportService.java +++ b/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/debuger/service/DebuggerReportService.java @@ -20,11 +20,15 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.Arrays; +import java.util.LinkedHashSet; import java.util.List; +import java.util.Locale; +import java.util.Set; import java.util.concurrent.CompletableFuture; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; +import org.apache.commons.lang.StringUtils; import org.opengauss.mppdbide.common.DbeCommonUtils; import org.opengauss.mppdbide.common.IConnection; import org.opengauss.mppdbide.common.IConnectionProvider; @@ -52,11 +56,11 @@ public class DebuggerReportService { * default offset value */ public static final int CODE_BASE_OFFSET = 1; - private static final String CREAT_TABLE = "CREATE TABLE IF NOT EXISTS his_coverage( oid BIGINT,"; + private static final String CREAT_TABLE = "CREATE TABLE IF NOT EXISTS public.his_coverage( oid BIGINT,"; private static final String TABLE_FIELD_ONE = " cid BIGINT, coverageLines VARCHAR, remarkLines VARCHAR, "; private static final String TABLE_FIELD_TWO = "endTime BIGINT, sourceCode VARCHAR, params VARCHAR," + " canBreakLine VARCHAR);"; - private static final String INSERT = "insert into his_coverage VALUES(?,?,?,?,?,?,?,?);"; + private static final String INSERT = "insert into public.his_coverage VALUES(?,?,?,?,?,?,?,?);"; /** * default value @@ -66,11 +70,13 @@ public class DebuggerReportService { private IConnection serverConn; private IConnection clientConn; private IConnection queryConn; + private IConnection dropConn; private FunctionVo functionVo; private TurnOnVo turnOnVo; private DebuggerStartInfoVo startInfo; private CodeDescription baseCodeDesc = null; private CodeDescription totalCodeDesc = null; + private boolean hasExp = false; private DebuggerReportService() { @@ -129,6 +135,7 @@ public class DebuggerReportService { this.serverConn = connectProvider.getValidFreeConnection(); this.clientConn = connectProvider.getValidFreeConnection(); this.queryConn = connectProvider.getValidFreeConnection(); + this.dropConn = connectProvider.getValidFreeConnection(); this.functionVo = functionVo; } catch (SQLException e) { MPPDBIDELoggerUtility.error(e.getMessage()); @@ -185,6 +192,14 @@ public class DebuggerReportService { } catch (SQLException sqlErr) { MPPDBIDELoggerUtility.warn("reportService queryConn close failed, err=" + sqlErr.toString()); } + try { + if (dropConn != null) { + dropConn.close(); + dropConn = null; + } + } catch (SQLException sqlErr) { + MPPDBIDELoggerUtility.warn("reportService dropConn close failed, err=" + sqlErr.toString()); + } } /** @@ -200,7 +215,8 @@ public class DebuggerReportService { /** * make dbedebugger report info */ - public void makeReport() { + public void makeReport(boolean hasExp) { + this.hasExp = hasExp; startInfo = DebuggerStartVariable.getStartInfo(functionVo.oid); if (!startInfo.isMakeReport) { return; @@ -208,6 +224,7 @@ public class DebuggerReportService { List inputsParams = Arrays.asList(functionVo.oid); ResultSet rs = null; try { + dropTable(startInfo.sourceCode); // DBE_DEBUG_OFF DebugOpt opt = DebugConstants.DebugOpt.DBE_DEBUG_OFF; rs = serverConn.getDebugOptPrepareStatement(opt, inputsParams).executeQuery(); @@ -242,6 +259,21 @@ public class DebuggerReportService { } } + private void dropTable(String code) { + if (StringUtils.isBlank(code)) { + return; + } + List tableNames = DbeCommonUtils.getNeedDropTableName(code); + tableNames.forEach(item -> { + String dropSql = String.format(Locale.ENGLISH, "DROP TABLE IF EXISTS %s", item) ; + try { + dropConn.getStatement(dropSql).executeQuery(); + } catch (SQLException e) { + MPPDBIDELoggerUtility.error("dropTable failed: " + e.getMessage()); + } + }); + } + private void doClient() { VariableRunLine.runList.clear(); // attach @@ -254,19 +286,26 @@ public class DebuggerReportService { } catch (SQLException e) { MPPDBIDELoggerUtility.error(e.getMessage()); } - List runLinks = new ArrayList(); + Set runLinks = new LinkedHashSet(); runLinks.add(getCurLine()); // next inputsParams = new ArrayList(); opt = DebugConstants.DebugOpt.DBE_STEP_OVER; Boolean hasNext = true; + Boolean isAdd= true; while (hasNext) { try (ResultSet rs = clientConn.getDebugOptPrepareStatement(opt, inputsParams).executeQuery()) { if (rs.next()) { AttachVo attachVo = ParseVo.parse(rs, AttachVo.class); Integer lineNo = attachVo.lineno; if (lineNo > 1) { - runLinks.add(getCurLine(lineNo)); + if (isAdd && this.hasExp && attachVo.query.toUpperCase(Locale.ENGLISH).contains(DbeCommonUtils.CREATE_TABLE)) { + runLinks.add(getCurLine(lineNo)); + isAdd = false; + } + if (isAdd) { + runLinks.add(getCurLine(lineNo)); + } } } else { hasNext = false; @@ -275,20 +314,24 @@ public class DebuggerReportService { hasNext = false; } } - VariableRunLine.runList.addAll(runLinks); + List toRunLines = DbeCommonUtils.getCanBreakLinesByInfo(queryConn, + Arrays.asList(functionVo.oid), SourceCodeService.CodeDescription.getLines(startInfo.sourceCode)) + .stream().map(item -> String.valueOf(Integer.parseInt(item) + 1)) + .collect(Collectors.toList()); + List runnings = runLinks.stream().filter(item -> toRunLines. + contains(String.valueOf(Integer.valueOf(item) + 1))).sorted().collect(Collectors.toList()); + VariableRunLine.runList.addAll(runnings); DebuggerEndInfoVo endInfo = new DebuggerEndInfoVo(); - String runStr = String.join(",", runLinks); + String runStr = String.join(",", runnings); endInfo.runStr = runStr; endInfo.setInfo(startInfo); List historyList = DebuggerStartVariable.getHistoryList(functionVo.oid); historyList.add(endInfo); DebuggerStartVariable.setHistoryList(functionVo.oid, historyList); - List toRunLines = DbeCommonUtils.getCanBreakLinesByInfo(queryConn, - Arrays.asList(functionVo.oid), SourceCodeService.CodeDescription.getLines(endInfo.sourceCode)) - .stream().map(item -> String.valueOf(Integer.parseInt(item) + 1)) - .collect(Collectors.toList()); endInfo.canBreakLine = String.join(",", toRunLines); - createTbale(endInfo); + if (!this.hasExp) { + createTbale(endInfo); + } } private void createTbale(DebuggerEndInfoVo endInfo) { diff --git a/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/debuger/service/QueryService.java b/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/debuger/service/QueryService.java index 6b07081fcf9b80dd5d7c300e51b5381f551bf6ce..128af2ec675ca559f288767523f731787264cd6f 100644 --- a/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/debuger/service/QueryService.java +++ b/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/debuger/service/QueryService.java @@ -22,6 +22,7 @@ import org.opengauss.mppdbide.debuger.vo.FunctionVo; import org.opengauss.mppdbide.debuger.vo.SourceCodeVo; import org.opengauss.mppdbide.debuger.vo.TotalSourceCodeVo; import org.opengauss.mppdbide.common.IConnection; +import org.opengauss.mppdbide.utils.VariableRunLine; import org.opengauss.mppdbide.utils.logger.MPPDBIDELoggerUtility; import java.sql.PreparedStatement; @@ -50,8 +51,11 @@ public class QueryService implements IService { public FunctionVo queryFunction(String proname) throws SQLException { try (PreparedStatement ps = conn.getStatement(functionDao.getSql(proname))) { try (ResultSet rs = ps.executeQuery()) { - if (rs.next()) { - return functionDao.parse(rs); + while(rs.next()) { + FunctionVo functionVo = functionDao.parse(rs); + if (functionVo.oid == VariableRunLine.currentOid) { + return functionVo; + } } throw new SQLException("proname:" + proname + " not found!"); } diff --git a/code/datastudio/src/org.opengauss.mppdbide.utils/src/messages.properties b/code/datastudio/src/org.opengauss.mppdbide.utils/src/messages.properties index 671ff78b4909aa8455130ef40c606aa484d274b7..34f72c62bac8da8f2e48d0e84d0564e00ceffe9a 100644 --- a/code/datastudio/src/org.opengauss.mppdbide.utils/src/messages.properties +++ b/code/datastudio/src/org.opengauss.mppdbide.utils/src/messages.properties @@ -3205,4 +3205,5 @@ EXPORT_PATH = The report has been downloaded to: {0} COVERAGE_CHECK = This version does not support this function! INPUT_PARAMS = Input Params NOT_SUPPORT_BREAK = There are rows that do not support flags! -VERSION_CHECK_FAIL = Check version failed! \ No newline at end of file +VERSION_CHECK_FAIL = Check version failed! +WRITE_DATA = This operation will save the data to the history table! \ No newline at end of file diff --git a/code/datastudio/src/org.opengauss.mppdbide.utils/src/messages_zh_CN.properties b/code/datastudio/src/org.opengauss.mppdbide.utils/src/messages_zh_CN.properties index 259934b0ae35ba2741cccd912200188e1351b532..f087ce09f2f5371d02f30426ed023ffa6c0c8cbf 100644 --- a/code/datastudio/src/org.opengauss.mppdbide.utils/src/messages_zh_CN.properties +++ b/code/datastudio/src/org.opengauss.mppdbide.utils/src/messages_zh_CN.properties @@ -3194,4 +3194,5 @@ EXP_MARK_ROW = \u6807\u8BB0\u884C EXP_MARK_EXECUTION_LINE = \u6807\u8BB0\u6267\u884C\u884C EXP_MARKER_COVERAGE = \u6807\u8BB0\u8986\u76D6\u7387 EXP_INPUT_PARAMS = \u5165\u53C2 -EXP_UPDATE_TIME = \u7ED3\u675F\u65F6\u95F4 \ No newline at end of file +EXP_UPDATE_TIME = \u7ED3\u675F\u65F6\u95F4 +WRITE_DATA = \u6B64\u64CD\u4F5C\u5C06\u4FDD\u5B58\u6570\u636E\u81F3\u5386\u53F2\u8868! \ No newline at end of file diff --git a/code/datastudio/src/org.opengauss.mppdbide.utils/src/org/opengauss/mppdbide/utils/IMessagesConstantsOne.java b/code/datastudio/src/org.opengauss.mppdbide.utils/src/org/opengauss/mppdbide/utils/IMessagesConstantsOne.java index 35f159f250b46af6526efcba97fe84a92d206f62..8c6baf9e8e39e4d0b92f7c3711172fda2ad8237d 100644 --- a/code/datastudio/src/org.opengauss.mppdbide.utils/src/org/opengauss/mppdbide/utils/IMessagesConstantsOne.java +++ b/code/datastudio/src/org.opengauss.mppdbide.utils/src/org/opengauss/mppdbide/utils/IMessagesConstantsOne.java @@ -1174,4 +1174,9 @@ public interface IMessagesConstantsOne extends IMessagesConstantsTwo { * EXP_UPDATE_TIME */ String EXP_UPDATE_TIME = "EXP_UPDATE_TIME"; + + /** + * EXP_UPDATE_TIME + */ + String WRITE_DATA = "WRITE_DATA"; } \ No newline at end of file diff --git a/code/datastudio/src/org.opengauss.mppdbide.utils/src/org/opengauss/mppdbide/utils/VariableRunLine.java b/code/datastudio/src/org.opengauss.mppdbide.utils/src/org/opengauss/mppdbide/utils/VariableRunLine.java index 477ac6111c8a0a8399e40a56756ba81fc7aa554a..93dc48aba6f06bc630a8b9697d0409942550e616 100644 --- a/code/datastudio/src/org.opengauss.mppdbide.utils/src/org/opengauss/mppdbide/utils/VariableRunLine.java +++ b/code/datastudio/src/org.opengauss.mppdbide.utils/src/org/opengauss/mppdbide/utils/VariableRunLine.java @@ -50,4 +50,14 @@ public class VariableRunLine { * isPldebugger of function */ public static volatile Boolean isPldebugger; + + /** + * id of function + */ + public static volatile long currentOid; + + /** + * isDebugUsagehint of function + */ + public static volatile Boolean isDebugUsagehint; } diff --git a/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/core/sourceeditor/PLSourceEditorCore.java b/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/core/sourceeditor/PLSourceEditorCore.java index d90cb242c4df7176b6267d71ecc1e6955149e362..4c53788fb539d8dd407dd5d720cacc59108b0481 100644 --- a/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/core/sourceeditor/PLSourceEditorCore.java +++ b/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/core/sourceeditor/PLSourceEditorCore.java @@ -2152,7 +2152,10 @@ public final class PLSourceEditorCore extends SelectMenuItem implements IPropert PLSourceEditor pl = UIElement.getInstance().getVisibleSourceViewer(); long oid = pl.getDebugObject().getOid(); DebuggerStartInfoVo vo = DebuggerStartVariable.getStartInfo(oid); - List oldList = Arrays.asList(vo.remarLinesStr.split(",")); + List oldList = new ArrayList(); + if (StringUtils.isNotBlank(vo.remarLinesStr)) { + oldList.addAll(Arrays.asList(vo.remarLinesStr.split(","))); + } List newLine = new ArrayList<>(); oldList.forEach(item -> { if (!StringUtils.isBlank(item) && (Integer.valueOf(item) < start || Integer.valueOf(item) > end)) { diff --git a/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/coverage/CoverageService.java b/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/coverage/CoverageService.java index bdc1a495422e2562f81f071b53efe891fca2dba5..08322d2c7f245bba75011433c608be0c4837940d 100644 --- a/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/coverage/CoverageService.java +++ b/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/coverage/CoverageService.java @@ -20,10 +20,12 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.Comparator; import java.util.List; import java.util.stream.Collectors; +import org.apache.commons.lang3.StringUtils; import org.opengauss.mppdbide.common.IConnection; import org.opengauss.mppdbide.debuger.annotation.ParseVo; import org.opengauss.mppdbide.debuger.service.IService; @@ -77,19 +79,19 @@ public class CoverageService implements IService { * @return the value */ public List getCoverageInfoByOid(long oid) { - String sql = "select * from his_coverage where oid=" + oid + " order by cid desc;"; + String sql = "select * from public.his_coverage where oid=" + oid + " order by cid desc;"; try { List res = this.queryList(sql, CoverageVo.class); res.stream().forEach(cov -> { if (cov.sourceCode != null) { - List toRunLines = Arrays.asList(cov.canBreakLine.split(",")); + List toRunLines = Arrays.asList(cov.canBreakLine.split(",")).stream() + .filter(item -> StringUtils.isNotBlank(item)).collect(Collectors.toList()); cov.totalLineNum = toRunLines.size(); cov.coverageLineNum = cov.getRunList().size(); cov.coverageLinesArr = cov.getRunList(); - cov.totalPercent = Double.parseDouble( - String.format("%.2f", - ((double) cov.coverageLineNum * 100 / (double) cov.totalLineNum))) - + "%"; + Double totPer = Double.parseDouble(String.format("%.2f", + ((double) cov.coverageLineNum * 100 / (double) cov.totalLineNum))); + cov.totalPercent = Double.isNaN(totPer) ? "0%" : totPer + "%"; // if not remark if (cov.remarkLines == null || "".equals(cov.remarkLines)) { cov.remarkLines = toRunLines.stream() @@ -104,11 +106,12 @@ public class CoverageService implements IService { cov.remarkCoverageLinesArr = cov.coverageLinesArr.stream().map(item -> Integer.parseInt(item) + 1 + "") .filter(ite -> cov.remarkLinesArr.contains(ite)).collect(Collectors.toList()); + Collections.sort(cov.remarkCoverageLinesArr, + (o1, o2) -> Integer.valueOf(o1).compareTo(Integer.valueOf(o2))); cov.remarkCoverageLineNum = cov.remarkCoverageLinesArr.size(); - cov.remarkPercent = Double.parseDouble( - String.format("%.2f", - ((double) cov.remarkCoverageLineNum * 100 / (double) cov.remarkLineNum))) - + "%"; + Double remarkPer = Double.parseDouble(String.format("%.2f", + ((double) cov.remarkCoverageLineNum * 100 / (double) cov.remarkLineNum))); + cov.remarkPercent = Double.isNaN(remarkPer) ? "0%" : remarkPer + "%"; } }); return res.stream().sorted(Comparator.comparing(CoverageVo::getEndTime) @@ -125,7 +128,7 @@ public class CoverageService implements IService { * @param cid the cid */ public void delCoverageInfoByOid(long oid, Long cid) { - String sql = "delete from his_coverage where oid=" + oid + " and cid=" + cid + ";"; + String sql = "delete from public.his_coverage where oid=" + oid + " and cid=" + cid + ";"; try { conn.getStatement(sql).executeUpdate(); } catch (SQLException e) { diff --git a/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/handler/ExecuteEditorItem.java b/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/handler/ExecuteEditorItem.java index dc2a0dc053ee1c56b15744aea0c8438eb2f2827e..0348745beab52d9c35da02fa016abce2e9487d43 100644 --- a/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/handler/ExecuteEditorItem.java +++ b/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/handler/ExecuteEditorItem.java @@ -48,6 +48,7 @@ import org.opengauss.mppdbide.presentation.IExecutionContext; import org.opengauss.mppdbide.presentation.IResultDisplayUIManager; import org.opengauss.mppdbide.utils.IMessagesConstants; import org.opengauss.mppdbide.utils.MPPDBIDEConstants; +import org.opengauss.mppdbide.utils.VariableRunLine; import org.opengauss.mppdbide.utils.exceptions.DatabaseCriticalException; import org.opengauss.mppdbide.utils.exceptions.DatabaseOperationException; import org.opengauss.mppdbide.utils.exceptions.MPPDBIDEException; @@ -117,7 +118,9 @@ public class ExecuteEditorItem implements ExecuteWrapper { checkVersion(editor); if (editor.getDebugObject() instanceof DebugObjects) { debugObject = (DebugObjects) editor.getDebugObject(); + VariableRunLine.isDebugUsagehint = null; if (!isPldebugger) { + VariableRunLine.isDebugUsagehint = false; debugObject.setUsagehint(MessageConfigLoader.getProperty(IMessagesConstants.COVERAGE_HINT)); } else { debugObject.setUsagehint(""); diff --git a/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/handler/debug/DebugServiceHelper.java b/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/handler/debug/DebugServiceHelper.java index 57fb85b646e4e6172ce640a30e32cc408815ed53..0ba9c752f7884d128ae0b398c8fedfbf7ddbb147 100644 --- a/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/handler/debug/DebugServiceHelper.java +++ b/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/handler/debug/DebugServiceHelper.java @@ -34,11 +34,13 @@ import org.opengauss.mppdbide.debuger.service.WrappedDebugService; import org.opengauss.mppdbide.debuger.vo.FunctionVo; import org.opengauss.mppdbide.debuger.service.DebuggerReportService; import org.opengauss.mppdbide.debuger.vo.SourceCodeVo; +import org.opengauss.mppdbide.utils.DebuggerStartVariable; import org.opengauss.mppdbide.utils.IMessagesConstants; import org.opengauss.mppdbide.utils.MPPDBIDEConstants; import org.opengauss.mppdbide.utils.VariableRunLine; import org.opengauss.mppdbide.utils.loader.MessageConfigLoader; import org.opengauss.mppdbide.utils.logger.MPPDBIDELoggerUtility; +import org.opengauss.mppdbide.utils.vo.DebuggerStartInfoVo; import org.opengauss.mppdbide.view.core.sourceeditor.BreakpointAnnotation; import org.opengauss.mppdbide.view.coverage.CoverageService; import org.opengauss.mppdbide.view.prefernces.PreferenceWrapper; @@ -91,7 +93,9 @@ public class DebugServiceHelper { checkSupportDebug(); checkDebugVersion(provider); queryService = serviceFactory.getQueryService(); + VariableRunLine.currentOid = debugObject.getOid(); functionVo = queryService.queryFunction(debugObject.getName()); + functionVo.proname = debugObject.getNamespace().getName() + "." + functionVo.proname; debugService = new WrappedDebugService(serviceFactory.getDebugService(functionVo)); debugService.addHandler(new UiEventHandler()); debugService.addHandler(new DebugEventHandler()); @@ -110,6 +114,8 @@ public class DebugServiceHelper { codeService.setTotalCode(debugObject.getSourceCode().getCode()); debuggerReportService.setTotalCode(codeService.getTotalCodeDesc()); this.debugObject = debugObject; + DebuggerStartInfoVo info = DebuggerStartVariable.getStartInfo(debugObject.getOid()); + info.sourceCode = debugObject.getSourceCode().getCode(); } if (debugService != null) { debugService.setRollback(getRollbackPreference()); @@ -265,11 +271,7 @@ public class DebugServiceHelper { conn = provider.getValidFreeConnection(); VariableRunLine.isPldebugger = VersionHelper.getDebuggerVersion(conn).isPldebugger(); } catch (SQLException e) { - MPPDBIDEDialogs.generateOKMessageDialog(MESSAGEDIALOGTYPE.INFORMATION, true, - MessageConfigLoader.getProperty(IMessagesConstants.EXECDIALOG_HINT), - MessageConfigLoader.getProperty(IMessagesConstants.VERSION_CHECK_FAIL)); - MPPDBIDELoggerUtility.error(e.getMessage()); - return; + throw new SQLException(MessageConfigLoader.getProperty(IMessagesConstants.VERSION_CHECK_FAIL)); } finally { if (conn != null) { conn.close(); @@ -307,8 +309,14 @@ public class DebugServiceHelper { } void closeDbConn() { - queryService.closeService(); - debuggerReportService.close(); - debugService.closeService(); + if (queryService != null) { + queryService.closeService(); + } + if (queryService != null) { + debuggerReportService.close(); + } + if (queryService != null) { + debugService.closeService(); + } } } diff --git a/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/handler/debug/StartDebugHandler.java b/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/handler/debug/StartDebugHandler.java index dfbef0da4c88f36c07791e1a88146ff1c8e1909d..a881c509e108059ca70275d374b4528d16763f51 100644 --- a/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/handler/debug/StartDebugHandler.java +++ b/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/handler/debug/StartDebugHandler.java @@ -25,13 +25,17 @@ import org.eclipse.e4.core.di.annotations.CanExecute; import org.eclipse.e4.core.di.annotations.Execute; import org.eclipse.swt.widgets.Display; import org.opengauss.mppdbide.adapter.keywordssyntax.SQLSyntax; +import org.opengauss.mppdbide.bl.serverdatacache.DebugObjects; import org.opengauss.mppdbide.bl.serverdatacache.DefaultParameter; import org.opengauss.mppdbide.bl.serverdatacache.IDebugObject; import org.opengauss.mppdbide.bl.serverdatacache.ObjectParameter; import org.opengauss.mppdbide.bl.serverdatacache.ObjectParameter.PARAMETERTYPE; import org.opengauss.mppdbide.debuger.service.DbeDebugService; +import org.opengauss.mppdbide.debuger.service.QueryService; import org.opengauss.mppdbide.debuger.service.WrappedDebugService; +import org.opengauss.mppdbide.debuger.vo.FunctionVo; import org.opengauss.mppdbide.utils.IMessagesConstants; +import org.opengauss.mppdbide.utils.VariableRunLine; import org.opengauss.mppdbide.utils.exceptions.DatabaseCriticalException; import org.opengauss.mppdbide.utils.exceptions.DatabaseOperationException; import org.opengauss.mppdbide.utils.exceptions.MPPDBIDEException; @@ -91,11 +95,35 @@ public class StartDebugHandler { plSourceEditor.setExecuteInProgress(true); debugUtils.showAllDebugView(true); startInputParamDialog(); - PLSourceEditor pl = UIElement.getInstance().getVisibleSourceViewer(); - List params = Arrays.asList(pl.getDebugObject().getObjectParameters()); - long oid = pl.getDebugObject().getOid(); - List paramNames = params.stream().map(item -> item.getName()).distinct().collect(Collectors.toList()); - DbeDebugService.map.put(oid, paramNames); + dbeStartDebugParam(plSourceEditor); + } + + private void dbeStartDebugParam(PLSourceEditor pl) { + try { + List params = Arrays.asList(pl.getDebugObject().getObjectParameters()); + String functionName = plSourceEditor.getDebugObject().getName(); + QueryService queryService = serviceHelper.getQueryService(); + FunctionVo functionVo = queryService.queryFunction(functionName); + long oid = functionVo.oid; + List paramNames = params.stream().map(item -> item.getName()).distinct().collect(Collectors.toList()); + DbeDebugService.map.put(oid, paramNames); + setUsagehint(plSourceEditor); + } catch (SQLException e) { + MPPDBIDELoggerUtility.info("dbeStartDebugParam get failed: " + e.getMessage()); + } + } + + private void setUsagehint(PLSourceEditor plSourceEditor) { + if (plSourceEditor.getDebugObject() instanceof DebugObjects) { + VariableRunLine.isDebugUsagehint = null; + DebugObjects debugObject = (DebugObjects) plSourceEditor.getDebugObject(); + if (!VariableRunLine.isPldebugger) { + VariableRunLine.isDebugUsagehint = true; + debugObject.setUsagehint(MessageConfigLoader.getProperty(IMessagesConstants.WRITE_DATA)); + } else { + debugObject.setUsagehint(""); + } + } } private void startInputParamDialog() { diff --git a/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/handler/debug/chain/ServerExitChain.java b/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/handler/debug/chain/ServerExitChain.java index dfa647b59e17848bd60fa03cfc92b13f8096c12d..e4b975646959426a36469eb80b53afb4e7ecc961 100644 --- a/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/handler/debug/chain/ServerExitChain.java +++ b/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/handler/debug/chain/ServerExitChain.java @@ -60,9 +60,7 @@ public class ServerExitChain extends IMsgChain { Display.getDefault().asyncExec(new UpdateHighlightLineNumTask()); if (VariableRunLine.isPldebugger != null && !VariableRunLine.isPldebugger) { - if (!event.hasException()) { - reportService.makeReport(); - } + reportService.makeReport(event.hasException()); if (VariableRunLine.isContinue != null && VariableRunLine.isContinue) { Display.getDefault().asyncExec(() -> UpdateDebugPositionTask.continueDebug()); } diff --git a/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/ui/PLSourceEditor.java b/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/ui/PLSourceEditor.java index f948607994538c81f89ed94ac9c119a4d4215821..ca3ad39341aba3794b35744c6d9e7efdfb775e79 100644 --- a/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/ui/PLSourceEditor.java +++ b/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/ui/PLSourceEditor.java @@ -93,7 +93,6 @@ import org.opengauss.mppdbide.presentation.grid.IDSGridDataProvider; import org.opengauss.mppdbide.presentation.resultset.ActionAfterResultFetch; import org.opengauss.mppdbide.presentation.resultsetif.IConsoleResult; import org.opengauss.mppdbide.presentation.resultsetif.IResultConfig; -import org.opengauss.mppdbide.utils.DebuggerStartVariable; import org.opengauss.mppdbide.utils.IMessagesConstants; import org.opengauss.mppdbide.utils.MPPDBIDEConstants; import org.opengauss.mppdbide.utils.MemoryCleaner; @@ -104,7 +103,6 @@ import org.opengauss.mppdbide.utils.loader.MessageConfigLoader; import org.opengauss.mppdbide.utils.logger.ILogger; import org.opengauss.mppdbide.utils.logger.MPPDBIDELoggerUtility; import org.opengauss.mppdbide.utils.messaging.MessageQueue; -import org.opengauss.mppdbide.utils.vo.DebuggerStartInfoVo; import org.opengauss.mppdbide.view.core.ConsoleCoreWindow; import org.opengauss.mppdbide.view.core.ConsoleMessageWindow; import org.opengauss.mppdbide.view.core.sourceeditor.AnnotationHelper.AnnotationType; @@ -687,9 +685,6 @@ public class PLSourceEditor extends AbstractAutoSaveObject sourceEditor.setDocument(new Document(debugObject.getLatestSouceCode().getCode()), 0); debugObject.setCodeReloaded(false); } - String sourceCode = debugObject.getLatestSouceCode().getCode(); - DebuggerStartInfoVo info = DebuggerStartVariable.getStartInfo(debugObject.getOid()); - info.sourceCode = sourceCode; registerModifyListener(); setSourceChangedInEditor(false); setSourceViewerConfiguration(); diff --git a/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/utils/ExportUtil.java b/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/utils/ExportUtil.java index 64625203f596136ec0960d52ecc01671a7540874..334d1eaa6daef340b43fb04afddb4462ef5632b9 100644 --- a/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/utils/ExportUtil.java +++ b/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/utils/ExportUtil.java @@ -129,8 +129,13 @@ public final class ExportUtil { file = new File(path); String workDir = System.getProperty("user.dir"); String fileSepa = System.getProperty("file.separator"); - outpath = String.format(Locale.ENGLISH, "%s%s%s_%s_%s.html", - workDir, fileSepa, oid, sqlName, System.currentTimeMillis()); + String dir = String.format(Locale.ENGLISH, "%s%shis_coverage%s", workDir, fileSepa, fileSepa); + File outFile = new File(dir); + if (!outFile.exists()) { + outFile.mkdir(); + } + outpath = String.format(Locale.ENGLISH, "%s%s_%s_%s.html", dir, oid, sqlName, + System.currentTimeMillis()); parse = Jsoup.parse(file, "gbk"); convertZhCn(parse); } else { diff --git a/code/datastudio/testcode/LLT/org.opengauss.mppdbide.bl.debug.test.fragment/src/org/opengauss/mppdbide/bl/test/debug/DbeDebugerTest.java b/code/datastudio/testcode/LLT/org.opengauss.mppdbide.bl.debug.test.fragment/src/org/opengauss/mppdbide/bl/test/debug/DbeDebugerTest.java index fe8feb5b7f6447125662e10c80b5be36cdd9ff3c..578b92b7d2528a5edaaf8dfc77bd76a24e39e7f1 100644 --- a/code/datastudio/testcode/LLT/org.opengauss.mppdbide.bl.debug.test.fragment/src/org/opengauss/mppdbide/bl/test/debug/DbeDebugerTest.java +++ b/code/datastudio/testcode/LLT/org.opengauss.mppdbide.bl.debug.test.fragment/src/org/opengauss/mppdbide/bl/test/debug/DbeDebugerTest.java @@ -158,7 +158,7 @@ public class DbeDebugerTest extends DebugerJdbcTestCaseBase { total.append(toParam4); CodeDescription totalCode = new CodeDescription(total.toString()); debuggerReportService.setTotalCode(totalCode); - debuggerReportService.makeReport(); + debuggerReportService.makeReport(false); } @Test diff --git a/information/datastudio/Data Studio User Manual.pdf b/information/datastudio/Data Studio User Manual.pdf index dd01dee80271bee1766c4ea094562a1121f4581b..ab2b22bc60bca9cb30f5ee159fba49a887da48b6 100644 Binary files a/information/datastudio/Data Studio User Manual.pdf and b/information/datastudio/Data Studio User Manual.pdf differ diff --git "a/information/datastudio/Data Studio \347\224\250\346\210\267\346\211\213\345\206\214.pdf" "b/information/datastudio/Data Studio \347\224\250\346\210\267\346\211\213\345\206\214.pdf" index ea5abac83a996b8414999f362f5ac932d6bcae5a..b58aa21af40f16a183aac42df17f2ae3c52f5905 100644 Binary files "a/information/datastudio/Data Studio \347\224\250\346\210\267\346\211\213\345\206\214.pdf" and "b/information/datastudio/Data Studio \347\224\250\346\210\267\346\211\213\345\206\214.pdf" differ