diff --git a/code/datastudio/src/copyExternalsToBuild.sh b/code/datastudio/src/copyExternalsToBuild.sh index 9c2d20c883895edcb0e20838729024cbc16d52b1..b23aead61171ef0fa8c72f1584b0fbeea026bd72 100644 --- a/code/datastudio/src/copyExternalsToBuild.sh +++ b/code/datastudio/src/copyExternalsToBuild.sh @@ -49,6 +49,7 @@ cp $SOURCE/3rd_src/target/dependency/guava-30.1.1-jre.jar $DEST/org.opengauss.mp cp $SOURCE/3rd_src/target/dependency/javafx-base-18-ea+2-win.jar $DEST/org.opengauss.mppdbide.view/. cp $SOURCE/3rd_src/target/dependency/javafx-controls-18-ea+2-win.jar $DEST/org.opengauss.mppdbide.view/. cp $SOURCE/3rd_src/target/dependency/javafx-graphics-18-ea+2-win.jar $DEST/org.opengauss.mppdbide.view/. +cp $SOURCE/3rd_src/target/dependency/jsoup-1.14.3.jar $DEST/org.opengauss.mppdbide.view/. cp $SOURCE/platform/Gauss200/gs_jdbc/gsjdbc4.jar $DEST/org.opengauss.dbdriver.jdbc.gauss/. rm -rf $TEST/org.opengauss.mppdbide.adapter.test.fragment/lib 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 b32769dd9fb27ad0b6ad34e2435683253da0e47a..574ddf4d47aaaeb7477a585c0a61ae993f3b3e9c 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 @@ -55,6 +55,7 @@ public class DebugObjects extends BatchDropServerObject implements ObjectChange, private ObjectParameter returnType; private Database db; private String usageHint; + private static String coverageHint; private Namespace namespace; private String lang; @@ -88,6 +89,7 @@ public class DebugObjects extends BatchDropServerObject implements ObjectChange, */ public void setUsagehint(String usagehint) { this.usageHint = usagehint; + this.coverageHint = usagehint; } /** @@ -868,7 +870,10 @@ 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 (hasout) { usagehint.append(MessageConfigLoader.getProperty(IMessagesConstants.EXEC_DEBUG_DIALOG_OUT_PARA_MSG) + MPPDBIDEConstants.LINE_SEPARATOR); diff --git a/code/datastudio/src/org.opengauss.mppdbide.bl/src/org/opengauss/mppdbide/bl/serverdatacache/IDebugObject.java b/code/datastudio/src/org.opengauss.mppdbide.bl/src/org/opengauss/mppdbide/bl/serverdatacache/IDebugObject.java index 3dc740b00f3cd1b31ef4f0acad3c1ec6b184de06..444ff7a6910560a31816741caa150baf7182ffa0 100644 --- a/code/datastudio/src/org.opengauss.mppdbide.bl/src/org/opengauss/mppdbide/bl/serverdatacache/IDebugObject.java +++ b/code/datastudio/src/org.opengauss.mppdbide.bl/src/org/opengauss/mppdbide/bl/serverdatacache/IDebugObject.java @@ -258,6 +258,8 @@ public interface IDebugObject { * @return the template parameters */ ArrayList getTemplateParameters(); + + ObjectParameter[] getObjectParameters(); /** * Clear template parameter values. diff --git a/code/datastudio/src/org.opengauss.mppdbide.debuger/META-INF/MANIFEST.MF b/code/datastudio/src/org.opengauss.mppdbide.debuger/META-INF/MANIFEST.MF index 2a29a9e20ed5a232f17618256d37a9cb0e1212a3..9fb82c430e9edccf9b45cf9e1f52f58bab881a0f 100644 --- a/code/datastudio/src/org.opengauss.mppdbide.debuger/META-INF/MANIFEST.MF +++ b/code/datastudio/src/org.opengauss.mppdbide.debuger/META-INF/MANIFEST.MF @@ -20,7 +20,8 @@ Export-Package: org.opengauss.mppdbide.common, org.opengauss.mppdbide.debuger.service, org.opengauss.mppdbide.debuger.service.chain, org.opengauss.mppdbide.debuger.thread, - org.opengauss.mppdbide.debuger.vo + org.opengauss.mppdbide.debuger.vo, + org.opengauss.mppdbide.debuger.vo.dbe Bundle-ClassPath: . Import-Package: org.postgresql.core, org.postgresql.jdbc, diff --git a/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/common/QueryResVoConvertHelper.java b/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/common/QueryResVoConvertHelper.java new file mode 100644 index 0000000000000000000000000000000000000000..151b07e1c71c1b506fad6152a4ccc4ccf81c245a --- /dev/null +++ b/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/common/QueryResVoConvertHelper.java @@ -0,0 +1,161 @@ +package org.opengauss.mppdbide.common; + +import java.io.File; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; +import java.util.Locale; +import java.util.Properties; + +import org.opengauss.mppdbide.debuger.annotation.ParseVo; +import org.opengauss.mppdbide.debuger.debug.DebugConstants; +import org.opengauss.mppdbide.debuger.vo.BreakPointListVo; +import org.opengauss.mppdbide.debuger.vo.PositionVo; +import org.opengauss.mppdbide.debuger.vo.SourceCodeVo; +import org.opengauss.mppdbide.debuger.vo.StackVo; +import org.opengauss.mppdbide.debuger.vo.VariableVo; +import org.opengauss.mppdbide.debuger.vo.VersionVo; +import org.opengauss.mppdbide.debuger.vo.dbe.BacktraceVo; +import org.opengauss.mppdbide.debuger.vo.dbe.InfoBreakpointsVo; +import org.opengauss.mppdbide.debuger.vo.dbe.InfoCodeVo; +import org.opengauss.mppdbide.debuger.vo.dbe.VariablesVo; + +/** + * Convert openGauss 3.0 vo to openGauss2.0 vo + * + * @author gitam + */ +public class QueryResVoConvertHelper { + + public static T parse(ResultSet rs,Class clazz,IConnection conn) throws SQLException { + VersionVo version=VersionHelper.getDebuggerVersion(conn); + return parse(rs,clazz,version); + } + + public static T parse(ResultSet rs,Class clazz,VersionVo versionVo) throws SQLException { + String className= clazz.getName(); + T obj = null; + //if openGauss2.0 command do not need to convert + boolean needConvert=versionVo.getDebuggerVersion().equalsIgnoreCase(DebugConstants.DBE_DEBUGGER); + if(!needConvert) { + obj= ParseVo.parse(rs, clazz); + }else { + switch(className) { + case "org.opengauss.mppdbide.debuger.vo.SourceCodeVo": + obj= convertToSourceCodeVo(rs); + break; + case "org.opengauss.mppdbide.debuger.vo.TotalSourceCodeVo": + break; + default: + break; + } + } + return obj; + } + + public static List parseList(ResultSet rs,Class clazz,IConnection conn) throws SQLException { + VersionVo version=VersionHelper.getDebuggerVersion(conn); + return parseList(rs,clazz,version); + } + + public static List parseList(ResultSet rs,Class clazz,VersionVo versionVo) throws SQLException { + String className= clazz.getName(); + List list = null; + //if openGauss2.0 command do not need to convert + boolean needConvert=versionVo.getDebuggerVersion().equalsIgnoreCase(DebugConstants.DBE_DEBUGGER); + if(!needConvert) { + list= ParseVo.parseList(rs, clazz); + }else { + switch(className) { + case "org.opengauss.mppdbide.debuger.vo.BreakpointVo": + list= covertToInofBreakpointsVo(rs); + break; + case "org.opengauss.mppdbide.debuger.vo.StackVo": + list= covertToInofBacktraceVo(rs); + break; + case "org.opengauss.mppdbide.debuger.vo.VariableVo": + list = covertToInofVariablesVo(rs); + break; + case "org.opengauss.mppdbide.debuger.vo.BreakPointListVo": + list = covertToInofBreakPointList(rs); + break; + default: + break; + } + } + return list; + } + + public static List covertToInofBreakPointList(ResultSet rs) throws SQLException { + List list = new ArrayList(); + List vos = ParseVo.parseList(rs,BreakPointListVo.class); + vos.forEach(item -> { + BreakPointListVo vo = new BreakPointListVo(); + vo.breakpointno = item.breakpointno; + vo.enable = item.enable; + vo.funcoid = item.funcoid; + vo.lineno = item.lineno; + vo.query = item.query; + list.add((T) vo); + }); + return list; + } + + public static List covertToInofVariablesVo(ResultSet rs) throws SQLException { + List list = new ArrayList(); + VariablesVo item = ParseVo.parse(rs,VariablesVo.class); + VariableVo vo = new VariableVo(); + vo.name = item.getVarname(); + vo.isconst = item.getIsconst(); + vo.value = item.getValue(); + vo.dtype = item.getDtype(); + list.add((T) vo); + return list; + } + + public static List covertToInofBacktraceVo(ResultSet rs) throws SQLException { + List list = new ArrayList(); + List infos = ParseVo.parseList(rs,BacktraceVo.class); + infos.forEach(item -> { + StackVo vo = new StackVo(); + vo.func = item.getFuncoid(); + vo.linenumber = item.getLineno(); + vo.level = 0; + vo.targetname = item.getQuery(); + list.add((T) vo); + }); + return list; + } + + public static List covertToInofBreakpointsVo(ResultSet rs) throws SQLException { + List list = new ArrayList(); + List infos = ParseVo.parseList(rs,InfoBreakpointsVo.class); + infos.forEach(item -> { + PositionVo vo = new PositionVo(); + vo.func = item.getFuncoid(); + vo.linenumber = item.getLineno(); + vo.breakpointno = item.getBreakpointno(); + list.add((T) vo); + }); + return list; + } + + public static T convertToSourceCodeVo(ResultSet rs) throws SQLException { + SourceCodeVo sourceCodeVo = new SourceCodeVo(); + List infoCodeList= ParseVo.parseList(rs,InfoCodeVo.class); + StringBuffer buffer=new StringBuffer(); + infoCodeList.forEach(a->{ + if (a.query.toLowerCase().contains("begin")) { + a.query = a.query.toUpperCase(Locale.ROOT).replaceFirst("BEGIN", System.getProperty("line.separator")+"BEGIN"); + } + if (a.query.toLowerCase().contains("end")) { + a.query = a.query.toUpperCase(Locale.ROOT).replaceFirst("END", System.getProperty("line.separator")+"END"); + } + buffer.append(a.query); + }); + sourceCodeVo.setCodes(infoCodeList); + sourceCodeVo.setSourceCode(buffer.toString()); + return (T) sourceCodeVo; + } +} diff --git a/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/common/VersionHelper.java b/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/common/VersionHelper.java new file mode 100644 index 0000000000000000000000000000000000000000..076ca3f1a648561d735c86023d8a2edcac48e6c0 --- /dev/null +++ b/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/common/VersionHelper.java @@ -0,0 +1,50 @@ +package org.opengauss.mppdbide.common; + +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; + +import org.opengauss.mppdbide.debuger.debug.DebugConstants; +import org.opengauss.mppdbide.debuger.debug.DebugConstants.DebugOpt; +import org.opengauss.mppdbide.debuger.vo.VersionVo; +import org.opengauss.mppdbide.utils.logger.MPPDBIDELoggerUtility; + +public class VersionHelper { + + /** + * get openGauss debugger version + * @return pl_debugger or dbe_debugger + */ + public static VersionVo getDebuggerVersion(IConnection serverConn) throws SQLException { + if (null == serverConn) { + MPPDBIDELoggerUtility.error("serverConn is null!"); + } + String sql= DebugConstants.getDbVersionSql(); + VersionVo versionVo=new VersionVo(); + try (PreparedStatement ps = serverConn.getStatement(sql)) { + try (ResultSet rs = ps.executeQuery()) { + if (rs.next()) { + // (openGauss 2.1.0 build 590b0f8e) openGauss version info + String version= rs.getObject(1).toString(); + MPPDBIDELoggerUtility.debug("openGauss db info version:" + version); + versionVo.version = version; + } + MPPDBIDELoggerUtility.debug("openGauss db info is empty!"); + return versionVo; + } + } + } + + public static DebugOpt getDebugOptByDebuggerVersion(IConnection serverConn,DebugOpt debugOpt) throws SQLException { + if (null == serverConn) { + return debugOpt; + } + VersionVo versionVo=getDebuggerVersion(serverConn); + DebugOpt res=DebugConstants.getDebugOptByDebuggerVersion(debugOpt,versionVo.getDebuggerVersion()); + if (null == res) { + return debugOpt; + } + return res; + } + +} diff --git a/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/debuger/debug/DebugConstants.java b/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/debuger/debug/DebugConstants.java index 8e28d5218d2c168aee52829c67bb63d46389b188..8c26b1628e9991254c6d301d30de96c18dee43c4 100644 --- a/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/debuger/debug/DebugConstants.java +++ b/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/debuger/debug/DebugConstants.java @@ -15,6 +15,8 @@ package org.opengauss.mppdbide.debuger.debug; +import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.Locale; import java.util.stream.Stream; @@ -28,28 +30,87 @@ public class DebugConstants { * default string length */ public static final int DEFAULT_STRING_BUILD_LEN = 128; + public static final String PL_DEBUGGER="pl_debugger"; + public static final String DBE_DEBUGGER="dbe_debugger"; + public static final Integer DBE_DEBUGGER_MIN_VERSION=300; + public static final LinkedHashMap enumMap=getEnumMap(DebugOpt.class); + public static HashMap oidSqlMap = new HashMap<>(); + + /** + * get DebugOpt by different debugger + * @param debugOpt + * @param debuggerVersion + * @return DebugOpt + */ + public static DebugOpt getDebugOptByDebuggerVersion(DebugOpt debugOpt,String debuggerVersion) { + if(PL_DEBUGGER.equalsIgnoreCase(debuggerVersion)) { + return debugOpt; + }else { + String optName=debugOpt.name(); + optName="DBE_"+optName; + return enumMap.get(optName); + } + } + + /** + * get name and all enum map + * @param + * @param enumClass + * @return LinkedHashMap + */ + public static > LinkedHashMap getEnumMap(final Class enumClass) { + final LinkedHashMap map = new LinkedHashMap<>(); + for (final E e : enumClass.getEnumConstants()) { + map.put(e.name(), e); + } + return map; + } /** * Title: the DebugOpt enum use to descript debuger interface */ public static enum DebugOpt { + //pldebugger command DEBUG_ON("pldbg_on", 0), DEBUG_OFF("pldbg_off", 0), - DEBUG_VERSION("pldbg_get_proxy_info", 0), + DEBUG_VERSION("version", 0), GET_SOURCE_CODE("pldbg_get_source", 1), GET_TOTAL_SOURCE_CODE("pg_get_functiondef", 1), START_SESSION("plpgsql_oid_debug", 1), ATTACH_SESSION("pldbg_attach_to_port", 1), STEP_INTO("pldbg_step_into", 1), STEP_OVER("pldbg_step_over", 1), - STEP_OUT("pldbg_step_out", 1), + STEP_OUT("pldbg_step_out", 1),//not support CONTINUE_EXEC("pldbg_continue", 1), ABORT_TARGET("pldbg_abort_target", 1), GET_VARIABLES("pldbg_get_variables", 1), GET_STACKS("pldbg_get_stack", 1), GET_BREAKPOINTS("pldbg_get_breakpoints", 1), DROP_BREAKPOINT("pldbg_drop_breakpoint", 3), - SET_BREAKPOINT("pldbg_set_breakpoint", 3); + SET_BREAKPOINT("pldbg_set_breakpoint", 3), + //dbe_debugger command + DBE_DEBUG_ON("DBE_PLDEBUGGER.turn_on",1), + DBE_DEBUG_OFF("DBE_PLDEBUGGER.turn_off", 1), + DBE_DEBUG_VERSION("version", 0), + DBE_GET_SOURCE_CODE("DBE_PLDEBUGGER.info_code", 1), + DBE_GET_TOTAL_SOURCE_CODE("pg_get_functiondef", 1), + DBE_START_SESSION("DBE_PLDEBUGGER.turn_on", 1), + DBE_ATTACH_SESSION("DBE_PLDEBUGGER.attach", 2), + DBE_STEP_INTO("DBE_PLDEBUGGER.step", 1), + DBE_STEP_OVER("DBE_PLDEBUGGER.next", 0), + DBE_STEP_OUT("pldbg_step_out", 1),//not support + DBE_CONTINUE_EXEC("DBE_PLDEBUGGER.continue", 0), + DBE_ABORT_TARGET("DBE_PLDEBUGGER.abort", 0), + DBE_GET_VARIABLES("DBE_PLDEBUGGER.print_var", 1), + DBE_GET_STACKS("DBE_PLDEBUGGER.backtrace", 0), + DBE_GET_BREAKPOINTS("DBE_PLDEBUGGER.info_breakpoints", 0), + DBE_DROP_BREAKPOINT("DBE_PLDEBUGGER.delete_breakpoint", 1), + DBE_SET_BREAKPOINT("DBE_PLDEBUGGER.add_breakpoint", 2), + DBE_REMARK_INFO_SET("DBE_PLDEBUGGER.remark_info_set",2), + DBE_REMARK_INFO_GET("DBE_PLDEBUGGER.remark_info_get",1), + DBE_COVERAGE_INFO_GET("DBE_PLDEBUGGER.coverage_info_get",1), + DBE_COVERAGE_INFO_DEL("DBE_PLDEBUGGER.coverage_info_del",2) + ; /** * opt of interface @@ -95,4 +156,12 @@ public class DebugConstants { paramReplace ); } + + /** + * get openGauss db version sql + * @return String query sql + */ + public static String getDbVersionSql() { + return "select version()"; + } } diff --git a/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/debuger/service/DebugService.java b/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/debuger/service/DebugService.java index ea5d4e2dbb80fc7af994312a22d1188481887edf..435c6d62b3bced7779b18f25c77ed5d627b3ecee 100644 --- a/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/debuger/service/DebugService.java +++ b/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/debuger/service/DebugService.java @@ -1,4 +1,4 @@ -/* +/* * Copyright (c) 2022 Huawei Technologies Co.,Ltd. * * openGauss is licensed under Mulan PSL v2. @@ -6,7 +6,7 @@ * You may obtain a copy of Mulan PSL v2 at: * * http://license.coscl.org.cn/MulanPSL2 - * + * * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. @@ -27,15 +27,23 @@ import org.opengauss.mppdbide.debuger.debug.DebugState; import org.opengauss.mppdbide.debuger.thread.DebugServerRunable; import org.opengauss.mppdbide.debuger.thread.DebugServerThreadProxy; import org.opengauss.mppdbide.debuger.thread.EventQueueThread; +import org.opengauss.mppdbide.debuger.vo.BreakPointListVo; import org.opengauss.mppdbide.debuger.vo.FunctionVo; import org.opengauss.mppdbide.debuger.vo.PositionVo; import org.opengauss.mppdbide.debuger.vo.SessionVo; import org.opengauss.mppdbide.debuger.vo.StackVo; import org.opengauss.mppdbide.debuger.vo.VariableVo; import org.opengauss.mppdbide.debuger.vo.VersionVo; +import org.opengauss.mppdbide.debuger.vo.dbe.AttachVo; +import org.opengauss.mppdbide.debuger.vo.dbe.TurnOnVo; import org.opengauss.mppdbide.common.IConnection; +import org.opengauss.mppdbide.common.QueryResVoConvertHelper; +import org.opengauss.mppdbide.utils.ConstantRunLine; import org.opengauss.mppdbide.utils.logger.MPPDBIDELoggerUtility; import org.postgresql.core.NoticeListener; +import org.opengauss.mppdbide.common.VersionHelper; +import org.opengauss.mppdbide.utils.vo.DebuggerStartInfoVo; +import org.opengauss.mppdbide.utils.DebuggerStartConstants; import java.lang.Thread.State; import java.sql.PreparedStatement; @@ -45,7 +53,11 @@ import java.sql.SQLWarning; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Map; import java.util.Optional; +import java.util.Timer; +import java.util.TimerTask; +import java.util.concurrent.ConcurrentHashMap; /** * Title: the DebugService class @@ -53,632 +65,812 @@ import java.util.Optional; * you can use by this step: * 1. create and DebugService by new DebugService() * 2. set DebugService.functionVo which come from QueryService.queryFunction - * by functionName + * by functionName * 3. set DebugService.clientConn and DebugService.serverConn, - * this is IConnection instance, your can create ConnectionAdapter objects + * this is IConnection instance, your can create ConnectionAdapter objects * 4. set DebugService.clinetConn and DebugService.serverConn's NoticeListener, - * which is DebugService instance self + * which is DebugService instance self * 5. call DebugService.prepareDebug * 6. call DebugService.startDebug and receive return value for close back server - * thread in end + * thread in end * 7. call DebugService.attachDebug * 8. then you can use stepOver/StepInto/continueExec to control debug process * 9. you can use getVariables and getStacks get variables and stacks info * 10. you can use getBreakPoints/setBreakpoint/dropBreakpoint function to manager - * breakpoints + * breakpoints * 11. when debug over, call DebugService.abortDebug, if forget this operation, - * threadleak will occur + * threadleak will occur * 12. call DebugService.debugOff, if forget this operation, openGauss Database - * will exit!! + * will exit!! * 13. call DebugService.closeConn * sample use you can see DebugTest.java * * @since 3.0.0 */ public class DebugService implements NoticeListener, EventHander, IDebugService { - private static final int DEFAULT_WAIT_LOCK_TIME = 2000; // ms - private IConnection serverConn; - private IConnection clientConn; - private FunctionVo functionVo; - private MsgChainHelper msgChainHelper; - private boolean isRollback = false; - private SessionVo sessionVo = new SessionVo(); - private final Object waitLock = new int[0]; - private DebugState serverState = new DebugState(); - private DebugState clientState = new DebugState(); - private EventQueueThread eventQueueThread = new EventQueueThread(); - private DebugServerThreadProxy serverThreadProxy = new DebugServerThreadProxy(); - - public DebugService() { - eventQueueThread.addHandler(this); - msgChainHelper = new MsgChainHelper(this); - } - - /** - * prepare to debug - * - * @return void - * @throws SQLException the exp - */ - public void prepareDebug() throws SQLException { - List inputsParams = Arrays.asList(functionVo.oid); - serverConn.getDebugOptPrepareStatement( - DebugConstants.DebugOpt.START_SESSION, - inputsParams).execute(); - } - - /** - * start to debug - * - * @param args input args to function - * @return DebugServerThreadProxy debug manager thread - */ - public DebugServerThreadProxy startDebug(List args) { - DebugServerRunable debugServerRunable = new DebugServerRunable( - this, - args, - eventQueueThread); - serverThreadProxy.setDebugServerRunable(debugServerRunable); - serverThreadProxy.start(); - return serverThreadProxy; - } - - /** - * get debug manager thread - * - * @return DebugServerThreadProxy debug manager thread - */ - public DebugServerThreadProxy getServerThreadProxy() { - return serverThreadProxy; - } - - /** - * when server backthread started, this will callback - * - * @param args input args to function - * @return Optional the function result - * @throws SQLException the exp - */ - public Optional serverDebugCallBack(List args) throws SQLException { - try { - serverCallBackBegin(); - String sql = DebugConstants.getSql(functionVo.proname, args.size()); - try (PreparedStatement ps = serverConn.getStatement(sql)) { - for (int i = 1 ; i < args.size() + 1; i ++) { - ps.setObject(i, args.get(i - 1)); - } - try (ResultSet rs = ps.executeQuery()) { - if (rs.next()) { - return Optional.ofNullable(rs.getObject(1)); - } - return Optional.empty(); - } - } - } finally { - serverCallBackEnd(); - } - } - - /** - * client attach debug - * - * @return void - * @throws SQLException the exp - */ - public void attachDebug() throws SQLException { - waitServerStart(); - List inputParams = Arrays.asList(sessionVo.serverPort); - try (PreparedStatement ps = clientConn.getDebugOptPrepareStatement( - DebugConstants.DebugOpt.ATTACH_SESSION, inputParams)) { - try (ResultSet rs = ps.executeQuery()) { - if (rs.next()) { - clientState.attached(); - sessionVo.clientPort = rs.getInt(1); - return; - } - } - } - throw new SQLException("client attach failed, please check"); - } - - private void waitServerStart() throws SQLException { - synchronized (waitLock) { - try { - waitLock.wait(DEFAULT_WAIT_LOCK_TIME); - } catch (InterruptedException intExp) { - MPPDBIDELoggerUtility.debug("wait has error!!!! err=" + intExp.toString()); - Thread.currentThread().interrupt(); - } - } - - if (!serverState.isRunning()) { - throw new SQLException("server not running, please check!"); - } - } - - /** - * server set debug session off - * - * @return void - * @throws SQLException the exp - */ - public void debugOff() throws SQLException { - serverConn.getDebugOptPrepareStatement( - DebugConstants.DebugOpt.DEBUG_OFF, - new ArrayList(1)).execute(); - } - - /** - * client abort debug - * - * @return Optional true if success - * @throws SQLException the exp - */ - public Optional abortDebug() throws SQLException { - if (clientState.isStopped()) { - return Optional.empty(); - } - List inputParams = Arrays.asList(sessionVo.clientPort); - try (PreparedStatement ps = clientConn.getDebugOptPrepareStatement( - DebugConstants.DebugOpt.ABORT_TARGET, inputParams)) { - clientState.stop(); - clientState.stateLocked(); - try (ResultSet rs = ps.executeQuery()) { - Boolean result = false; - if (rs.next()) { - result = rs.getBoolean(1); - } - return Optional.of(result); - } - } - } - - /** - * step over run - * - * @return Optional the breakpoint line position - * @throws SQLException the exp - * @throws DebugExitException the debug exit exp - */ - @Override - public Optional stepOver() throws SQLException, DebugExitException { - return getPositionVo(DebugConstants.DebugOpt.STEP_OVER); - } - - /** - * step into run - * - * @return Optional the breakpoint line position - * @throws SQLException the exp - * @throws DebugExitException the debug exit exp - */ - @Override - public Optional stepInto() throws SQLException, DebugExitException { - return getPositionVo(DebugConstants.DebugOpt.STEP_INTO); - } - - /** - * step out run - * - * @return Optional the breakpoint line position - * @throws SQLException the exp - * @throws DebugExitException the debug exit exp - */ - @Override - public Optional stepOut() throws SQLException, DebugExitException { - return getPositionVo(DebugOpt.STEP_OUT); - } - - /** - * continue exec run - * - * @return Optional the breakpoint line position - * @throws SQLException the exp - * @throws DebugExitException the debug exit exp - */ - @Override - public Optional continueExec() throws SQLException, DebugExitException { - return getPositionVo(DebugConstants.DebugOpt.CONTINUE_EXEC); - } - - /** - * step run common command - * - * @param debugOpt which opteration to exec - * @return Optional the breakpoint line position - * @throws SQLException the exp - * @throws DebugExitException the debug exit exp - */ - @Override - public Optional getPositionVo( - DebugConstants.DebugOpt debugOpt - ) throws SQLException, DebugExitException { - clientState.running(); - if (debugOpt == DebugOpt.STEP_OUT) { - throw new SQLException("not support method!"); - } - List inputParams = Arrays.asList(sessionVo.clientPort); - try (PreparedStatement ps = clientConn.getDebugOptPrepareStatement( - debugOpt, inputParams)) { - try (ResultSet rs = ps.executeQuery()) { - // this order is very important, because when debug opt is return, - // maybe server is already over, so must stop debug! - if (!serverState.isRunning()) { - throw new DebugExitException(); - } - PositionVo positionVo = null; - if (rs.next()) { - positionVo = ParseVo.parse(rs, PositionVo.class); - } - return Optional.ofNullable(positionVo); - } - } - } - - /** - * get cur variables - * - * @return List all variables - * @throws SQLException the exp - */ - @Override - public List getVariables() throws SQLException { - return getListVos(DebugConstants.DebugOpt.GET_VARIABLES, VariableVo.class); - } - - /** - * get cur stacks - * - * @return List all stacks - * @throws SQLException the exp - */ - @Override - public List getStacks() throws SQLException { - return getListVos(DebugConstants.DebugOpt.GET_STACKS, StackVo.class); - } - - /** - * get cur breakpoints - * - * @return List all breakpoints - * @throws SQLException the exp - */ - @Override - public List getBreakPoints() throws SQLException { - return getListVos(DebugConstants.DebugOpt.GET_BREAKPOINTS, PositionVo.class); - } - - private List getListVos(DebugConstants.DebugOpt debugOpt, Class clazz) throws SQLException { - List inputParams = Arrays.asList(sessionVo.clientPort); - try (PreparedStatement ps = clientConn.getDebugOptPrepareStatement( - debugOpt, inputParams)) { - try (ResultSet rs = ps.executeQuery()) { - List results = ParseVo.parseList(rs, clazz); - return results; - } - } - } - - /** - * set breakpoint - * - * @param positionVo which line will set breakpoint - * @return boolean true if success - * @throws SQLException the exp - */ - @Override - public boolean setBreakPoint(PositionVo positionVo) throws SQLException { - return disposeBreakpoint(DebugConstants.DebugOpt.SET_BREAKPOINT, positionVo); - } - - /** - * delete breakpoint - * - * @param positionVo which line will set breakpoint - * @return boolean true if success - * @throws SQLException the exp - */ - @Override - public boolean dropBreakPoint(PositionVo positionVo) throws SQLException { - return disposeBreakpoint(DebugConstants.DebugOpt.DROP_BREAKPOINT, positionVo); - } - - /** - * set/delete breakpoint - * - * @param debugOpt which opteration to exec - * @param positionVo which line will set breakpoint - * @return boolean true if success - * @throws SQLException the exp - */ - public boolean disposeBreakpoint(DebugConstants.DebugOpt debugOpt, - PositionVo positionVo) throws SQLException { - if (positionVo.func == null || positionVo.func.intValue() == 0) { - positionVo.func = functionVo.oid; - } - - List inputParams = Arrays.asList( - sessionVo.clientPort, - positionVo.func, - positionVo.linenumber - ); - try (PreparedStatement ps = clientConn.getDebugOptPrepareStatement( - debugOpt, inputParams)) { - try (ResultSet rs = ps.executeQuery()) { - boolean result = false; - if (rs.next()) { - result = rs.getBoolean(1); - } - return result; - } - } - } - - /** - * set server connection - * - * @param serverConn connection to set of server - * @return void - */ - public void setServerConn(IConnection serverConn) { - this.serverConn = serverConn; - this.serverConn.setNoticeListener(this); - } - - /** - * set client connection - * - * @param clientConn connection - * @return void - */ - public void setClientConn(IConnection clientConn) { - this.clientConn = clientConn; - this.clientConn.setNoticeListener(this); - } - - /** - * close all connection - * - * @return void - */ - @Override - public void closeService() { - eventQueueThread.stopThread(); - try { - if (clientConn != null) { - clientConn.close(); - clientConn = null; - } - } catch (SQLException sqlErr) { - MPPDBIDELoggerUtility.warn("clientConn close failed!err=" + sqlErr.toString()); - } - - try { - if (serverConn != null) { - serverConn.close(); - serverConn = null; - } - } catch (SQLException sqlErr) { - MPPDBIDELoggerUtility.warn("serverConn close failed, err=" + sqlErr.toString()); - } - } - - /** - * dispose sql warning of notice - * - * @param notice the notice - * @return void - */ - @Override - public void noticeReceived(SQLWarning notice) { - if (notice == null || notice.getMessage() == null) { - return; - } - String msgString = notice.getMessage(); - MPPDBIDELoggerUtility.debug("sql message:" + msgString); - msgChainHelper.handleSqlMsg(new Event(EventMessage.ON_SQL_MSG, msgString)); - } - - /** - * handle event - * - * @param event event to handle - * @return void - */ - @Override - public void handleEvent(Event event) { - msgChainHelper.handleEventMsg(event); - } - - /** - * update server port - * - * @param serverPort the port to set - * @return void - */ - public void updateServerPort(int serverPort) { - sessionVo.serverPort = serverPort; - serverState.running(); - synchronized (waitLock) { - waitLock.notifyAll(); - } - } - - /** - * update server state with exception - * - * @return void - */ - public void updateServerWithException() { - serverState.terminaled(); - } - - /** - * update server state with normal exit - * - * @param result the execute result - * @return void - */ - public void updateServerWithResult(Object result) { - serverState.stop(); - serverState.stateLocked(); - sessionVo.result = result; - serverThreadProxy.start(); - } - - @Override - public Optional version() throws SQLException { - try (PreparedStatement ps = serverConn.getDebugOptPrepareStatement( - DebugConstants.DebugOpt.DEBUG_VERSION, new ArrayList<>(1))) { - try (ResultSet rs = ps.executeQuery()) { - if (rs.next()) { - return Optional.ofNullable(ParseVo.parse(rs, VersionVo.class)); - } - return Optional.empty(); - } - } - } - - /** - * begin debug - * - * @param args function input args - * @return void - * @throws SQLException sql exception - */ - @Override - public void begin(List args) throws SQLException { - init(); - prepareDebug(); - startDebug(args); - attachDebug(); - } - - /** - * end debug - * - * @return void - */ - @Override - public void end() { - try { - abortDebug(); - } catch (SQLException e) { - MPPDBIDELoggerUtility.debug("abortDebug with error:" + e.toString()); - } - serverThreadProxy.join(); - try { - debugOff(); - } catch (SQLException e) { - MPPDBIDELoggerUtility.debug("debugOff with error:" + e.toString()); - } - closeService(); - } - - /** - * get normal end result - * - * @return Optional the result - */ - @Override - public Optional getResult() { - if (isNormalEnd()) { - return Optional.ofNullable(sessionVo.result); - } - return Optional.empty(); - } - - /** - * is normal end - * - * @return true if normal end - */ - @Override - public boolean isNormalEnd() { - return serverState.isNormalStopped(); - } - - /** - * is debug server still running - * - * @return true if running - */ - @Override - public boolean isRunning() { - return getServerDebugState().isRunning(); - } - - /** - * set function vo - * - * @param functionVo function vo - * @return void - */ - public void setFunctionVo(FunctionVo functionVo) { - this.functionVo = functionVo; - } - - /** - * get server state - * - * @return DebugState state of server - */ - public DebugState getServerDebugState() { - return serverState; - } - - /** - * get server state - * - * @return DebugState state of client - */ - public DebugState getClientDebugState() { - return clientState; - } - - /** - * add server debug exit listener - * - * @param handler event handler of exit - * @return void - */ - @Override - public void addServerExistListener(EventHander handler) { - eventQueueThread.addHandler(handler); - } - - @Override - public void init() { - if (eventQueueThread.getState() == State.NEW) { - eventQueueThread.start(); - } - } - - @Override - public boolean isRollback() { - return isRollback; - } - - @Override - public void setRollback(boolean isRollback) { - this.isRollback = isRollback; - } - - private void serverCallBackBegin() throws SQLException { - serverExecuteInner("begin;"); - } - - private void serverCallBackEnd() throws SQLException { - if (isRollback()) { - serverExecuteInner("rollback;"); - } else { - serverExecuteInner("commit;"); - } - } - - private void serverExecuteInner(String sql) throws SQLException { - try (PreparedStatement ps = serverConn.getStatement(sql)) { - ps.execute(); - } - } + private static final int DEFAULT_WAIT_LOCK_TIME = 2000; // ms + private IConnection serverConn; + private IConnection clientConn; + private FunctionVo functionVo; + private MsgChainHelper msgChainHelper; + private boolean isRollback = false; + private SessionVo sessionVo = new SessionVo(); + private TurnOnVo turnOnVo=null; + private final Object waitLock = new int[0]; + private DebugState serverState = new DebugState(); + private DebugState clientState = new DebugState(); + private EventQueueThread eventQueueThread = new EventQueueThread(); + private DebugServerThreadProxy serverThreadProxy = new DebugServerThreadProxy(); + public static final Map> map = new ConcurrentHashMap<>(); + public DebuggerReportService reportService = DebuggerReportService.getInstance(); + + public DebugService() { + eventQueueThread.addHandler(this); + msgChainHelper = new MsgChainHelper(this); + } + + /** + * prepare to debug + * + * @return void + * @throws SQLException the exp + */ + public void prepareDebug() throws SQLException { + List inputsParams = Arrays.asList(functionVo.oid); + DebugOpt opt=VersionHelper.getDebugOptByDebuggerVersion(clientConn,DebugConstants.DebugOpt.START_SESSION); + ResultSet rs=serverConn.getDebugOptPrepareStatement(opt,inputsParams).executeQuery(); + if(rs.next()) { + if (!getVersion()) { + turnOnVo=ParseVo.parse(rs, TurnOnVo.class); + SQLWarning sql=new SQLWarning("Pldebugger is started successfully, you are SERVER now."); + noticeReceived(sql); + } + + } + } + + /** + * start to debug + * + * @param args input args to function + * @return DebugServerThreadProxy debug manager thread + */ + public DebugServerThreadProxy startDebug(List args) { + DebugServerRunable debugServerRunable = new DebugServerRunable( + this, + args, + eventQueueThread); + serverThreadProxy.setDebugServerRunable(debugServerRunable); + serverThreadProxy.start(); + return serverThreadProxy; + } + + /** + * get debug manager thread + * + * @return DebugServerThreadProxy debug manager thread + */ + public DebugServerThreadProxy getServerThreadProxy() { + return serverThreadProxy; + } + + /** + * when server backthread started, this will callback + * + * @param args input args to function + * @return Optional the function result + * @throws SQLException the exp + */ + public Optional serverDebugCallBack(List args) throws SQLException { + try { + serverCallBackBegin(); + String sql = DebugConstants.getSql(functionVo.proname, args.size()); + try (PreparedStatement ps = serverConn.getStatement(sql)) { + for (int i = 1 ; i < args.size() + 1; i ++) { + ps.setObject(i, args.get(i - 1)); + } + if (!getVersion()) { + Timer timer = new Timer(); + timer.schedule(new TimerTask() { + public void run() { + SQLWarning sqlWarning=new SQLWarning("YOUR PROXY PORT ID IS:"+turnOnVo.port); + noticeReceived(sqlWarning); + } + }, 2000); + } + + try (ResultSet rs = ps.executeQuery()) { + if (rs.next()) { + return Optional.ofNullable(rs.getObject(1)); + } + return Optional.empty(); + } + } + } finally { + serverCallBackEnd(); + } + } + + /** + * client attach debug + * + * @return void + * @throws SQLException the exp + */ + public void attachDebug() throws SQLException { + if (!getVersion()) { + try { + Thread.sleep(DEFAULT_WAIT_LOCK_TIME); + } catch (InterruptedException e) { + MPPDBIDELoggerUtility.error(e.getMessage()); + } + } + waitServerStart(); + List inputParams = Arrays.asList(sessionVo.serverPort); + DebugOpt opt=VersionHelper.getDebugOptByDebuggerVersion(clientConn,DebugConstants.DebugOpt.ATTACH_SESSION); + + if (!getVersion()) { + inputParams=Arrays.asList(turnOnVo.nodename,sessionVo.serverPort); + } + try (PreparedStatement ps = clientConn.getDebugOptPrepareStatement(opt, inputParams)) { + try (ResultSet rs = ps.executeQuery()) { + if (rs.next()) { + clientState.attached(); + if (getVersion()) { + sessionVo.clientPort = rs.getInt(1); + }else { + AttachVo attachVo=ParseVo.parse(rs, AttachVo.class); + sessionVo.clientPort=attachVo.lineno; + } + + return; + } + }catch(SQLException e) { + MPPDBIDELoggerUtility.error(e.getMessage()); + } + } + throw new SQLException("client attach failed, please check"); + } + + private void waitServerStart() throws SQLException { + synchronized (waitLock) { + try { + waitLock.wait(DEFAULT_WAIT_LOCK_TIME); + } catch (InterruptedException intExp) { + MPPDBIDELoggerUtility.debug("wait has error!!!! err=" + intExp.toString()); + Thread.currentThread().interrupt(); + } + } + + if (!serverState.isRunning()) { + throw new SQLException("server not running, please check!"); + } + } + + /** + * server set debug session off + * + * @return void + * @throws SQLException the exp + */ + public void debugOff() throws SQLException { + List inputParams = new ArrayList(1); + DebugOpt opt=DebugConstants.DebugOpt.DEBUG_OFF; + if (!getVersion()) { + inputParams = Arrays.asList(functionVo.oid); + opt = DebugConstants.DebugOpt.DBE_DEBUG_OFF; + clientConn.getDebugOptPrepareStatement(opt,inputParams).execute(); + } else if (null != serverConn){ + serverConn.getDebugOptPrepareStatement(opt,inputParams).execute(); + } + } + + /** + * client abort debug + * + * @return Optional true if success + * @throws SQLException the exp + */ + public Optional abortDebug() throws SQLException { + if (clientState.isStopped()) { + return Optional.empty(); + } + List inputParams = Arrays.asList(sessionVo.clientPort); + DebugConstants.DebugOpt opt=VersionHelper.getDebugOptByDebuggerVersion(clientConn,DebugConstants.DebugOpt.ABORT_TARGET); + if (!getVersion()) { + inputParams=new ArrayList(); + } + try (PreparedStatement ps = clientConn.getDebugOptPrepareStatement(opt, inputParams)) { + clientState.stop(); + clientState.stateLocked(); + try (ResultSet rs = ps.executeQuery()) { + Boolean result = false; + if (rs.next()) { + result = rs.getBoolean(1); + } + return Optional.of(result); + }catch(SQLException e) { + return Optional.of(true); + } + } + } + + /** + * step over run + * + * @return Optional the breakpoint line position + * @throws SQLException the exp + * @throws DebugExitException the debug exit exp + */ + @Override + public Optional stepOver() throws SQLException, DebugExitException { + return getPositionVo(DebugConstants.DebugOpt.STEP_OVER); + } + + /** + * step into run + * + * @return Optional the breakpoint line position + * @throws SQLException the exp + * @throws DebugExitException the debug exit exp + */ + @Override + public Optional stepInto() throws SQLException, DebugExitException { + return getPositionVo(DebugConstants.DebugOpt.STEP_INTO); + } + + /** + * step out run + * + * @return Optional the breakpoint line position + * @throws SQLException the exp + * @throws DebugExitException the debug exit exp + */ + @Override + public Optional stepOut() throws SQLException, DebugExitException { + return getPositionVo(DebugOpt.STEP_OUT); + } + + /** + * continue exec run + * + * @return Optional the breakpoint line position + * @throws SQLException the exp + * @throws DebugExitException the debug exit exp + */ + @Override + public Optional continueExec() throws SQLException, DebugExitException { + return getPositionVo(DebugConstants.DebugOpt.CONTINUE_EXEC); + } + + /** + * step run common command + * + * @param debugOpt which opteration to exec + * @return Optional the breakpoint line position + * @throws SQLException the exp + * @throws DebugExitException the debug exit exp + */ + @Override + public Optional getPositionVo( + DebugConstants.DebugOpt debugOpt + ) throws SQLException, DebugExitException { + clientState.running(); + if (debugOpt == DebugOpt.STEP_OUT) { + throw new SQLException("not support method!"); + } + List inputParams = Arrays.asList(sessionVo.clientPort); + DebugOpt opt=VersionHelper.getDebugOptByDebuggerVersion(clientConn,debugOpt); + if (!getVersion()) { + inputParams=new ArrayList(); + } + try (PreparedStatement ps = clientConn.getDebugOptPrepareStatement(opt, inputParams)) { + try (ResultSet rs = ps.executeQuery()) { + // this order is very important, because when debug opt is return, + // maybe server is already over, so must stop debug! + if (!serverState.isRunning()) { + throw new DebugExitException(); + } + PositionVo positionVo = null; + if (rs.next()) { + if (getVersion()) { + positionVo = ParseVo.parse(rs, PositionVo.class); + }else { + AttachVo vo = new AttachVo(); + vo = ParseVo.parse(rs, AttachVo.class); + positionVo = new PositionVo(vo.funcoid,vo.lineno,vo.funcname); + } + } + return Optional.ofNullable(positionVo); + }catch(SQLException e) { + return Optional.empty(); + } + } + } + + /** + * get cur variables + * + * @return List all variables + * @throws SQLException the exp + */ + @Override + public List getVariables() throws SQLException { + return getAllVariable(DebugConstants.DebugOpt.GET_VARIABLES, VariableVo.class); + } + + private List getAllVariable(DebugConstants.DebugOpt debugOpt, Class clazz) throws SQLException { + if (!getVersion()) { + List vos = new ArrayList(); + map.get(functionVo.oid).forEach(item -> { + DebugOpt opt; + try { + opt = DebugConstants.DebugOpt.DBE_GET_VARIABLES; + List inputParams = Arrays.asList(item); + try (PreparedStatement ps = clientConn.getDebugOptPrepareStatement(opt, inputParams)) { + try (ResultSet rs = ps.executeQuery()) { + if (rs.next()) { + vos.addAll(QueryResVoConvertHelper.parseList(rs,clazz,clientConn)); + } + }catch(SQLException e) { + MPPDBIDELoggerUtility.error(e.getMessage()); + } + } + } catch (SQLException e) { + MPPDBIDELoggerUtility.error(e.getMessage()); + } + }); + return vos; + } else { + return getListVos(debugOpt, clazz); + } + } + + /** + * get cur stacks + * + * @return List all stacks + * @throws SQLException the exp + */ + @Override + public List getStacks() throws SQLException { + if (getVersion()) { + return getListVos(DebugConstants.DebugOpt.GET_STACKS, StackVo.class); + } else { + return getListVos_v3(DebugConstants.DebugOpt.GET_STACKS, StackVo.class, new ArrayList<>()); + } + } + + /** + * get cur breakpoints + * + * @return List all breakpoints + * @throws SQLException the exp + */ + @Override + public List getBreakPoints() throws SQLException { + if (getVersion()) { + return getListVos(DebugConstants.DebugOpt.GET_BREAKPOINTS, PositionVo.class); + } else { + List list = getListVos_v3(DebugConstants.DebugOpt.DBE_GET_BREAKPOINTS, BreakPointListVo.class, new ArrayList<>()); + List vos = new ArrayList<>(); + list.forEach(item -> { + PositionVo vo = new PositionVo(); + vo.breakpointno = item.breakpointno; + vo.enable = item.enable; + vo.func = item.funcoid; + vo.linenumber = item.lineno; + vo.targetname = item.query; + vos.add(vo); + }); + return vos; + } + } + + private List getListVos_v3(DebugConstants.DebugOpt debugOpt, Class clazz, List inputParams) throws SQLException { + DebugOpt opt=VersionHelper.getDebugOptByDebuggerVersion(clientConn,debugOpt); + try (PreparedStatement ps = clientConn.getDebugOptPrepareStatement(opt, inputParams)) { + try (ResultSet rs = ps.executeQuery()) { + List results = QueryResVoConvertHelper.parseList(rs,clazz,clientConn); + return results; + }catch(SQLException e) { + return new ArrayList(); + } + } + } + + private List getListVos(DebugConstants.DebugOpt debugOpt, Class clazz) throws SQLException { + List inputParams = Arrays.asList(sessionVo.clientPort); + try (PreparedStatement ps = clientConn.getDebugOptPrepareStatement( + debugOpt, inputParams)) { + try (ResultSet rs = ps.executeQuery()) { + List results = ParseVo.parseList(rs, clazz); + return results; + } + } + } + + /** + * set breakpoint + * + * @param positionVo which line will set breakpoint + * @return boolean true if success + * @throws SQLException the exp + */ + @Override + public boolean setBreakPoint(PositionVo positionVo) throws SQLException { + if (getVersion()) { + return disposeBreakpoint(DebugConstants.DebugOpt.SET_BREAKPOINT, positionVo,false); + }else { + return disposeBreakpoint(DebugConstants.DebugOpt.DBE_SET_BREAKPOINT, positionVo,false); + } + } + + /** + * delete breakpoint + * + * @param positionVo which line will set breakpoint + * @return boolean true if success + * @throws SQLException the exp + */ + @Override + public boolean dropBreakPoint(PositionVo positionVo) throws SQLException { + if (getVersion()) { + return disposeBreakpoint(DebugConstants.DebugOpt.DROP_BREAKPOINT, positionVo, true); + }else { + return disposeBreakpoint(DebugConstants.DebugOpt.DBE_DROP_BREAKPOINT, positionVo, true); + } + } + + /** + * set/delete breakpoint + * + * @param debugOpt which opteration to exec + * @param positionVo which line will set breakpoint + * @return boolean true if success + * @throws SQLException the exp + */ + public boolean disposeBreakpoint(DebugConstants.DebugOpt debugOpt,PositionVo positionVo, Boolean isDelete) throws SQLException { + if (positionVo.func == null || positionVo.func.intValue() == 0) { + positionVo.func = functionVo.oid; + } + List inputParams; + if (getVersion()) { + inputParams = Arrays.asList(sessionVo.clientPort,positionVo.func,positionVo.linenumber); + } else { + if (isDelete) { + List res = getBreakPoints(); + Optional vo = res.stream().filter(item -> item.linenumber.equals(positionVo.linenumber)).findFirst(); + inputParams = new ArrayList<>(); + if (vo.isPresent()) { + inputParams = Arrays.asList(vo.get().getBreakpointno()); + } + }else { + inputParams = Arrays.asList(positionVo.func,positionVo.linenumber); + } + } + try (PreparedStatement ps = clientConn.getDebugOptPrepareStatement(debugOpt, inputParams)) { + try (ResultSet rs = ps.executeQuery()) { + boolean result = false; + if (rs.next() && getVersion()) { + result = rs.getBoolean(1); + } + return result; + } + } + } + + /** + * set server connection + * + * @param serverConn connection to set of server + * @return void + */ + public void setServerConn(IConnection serverConn) { + this.serverConn = serverConn; + this.serverConn.setNoticeListener(this); + } + + /** + * set client connection + * + * @param clientConn connection + * @return void + */ + public void setClientConn(IConnection clientConn) { + this.clientConn = clientConn; + this.clientConn.setNoticeListener(this); + } + + /** + * close all connection + * + * @return void + */ + @Override + public void closeService() { + eventQueueThread.stopThread(); + try { + if (clientConn != null) { + clientConn.close(); + clientConn = null; + } + } catch (SQLException sqlErr) { + MPPDBIDELoggerUtility.warn("clientConn close failed!err=" + sqlErr.toString()); + } + + try { + if (serverConn != null) { + serverConn.close(); + serverConn = null; + } + } catch (SQLException sqlErr) { + MPPDBIDELoggerUtility.warn("serverConn close failed, err=" + sqlErr.toString()); + } + if (null != reportService) { + try { + if (null != reportService.serverConn) { + reportService.serverConn.close(); + reportService.serverConn=null; + } + } catch (SQLException sqlErr) { + MPPDBIDELoggerUtility.warn("reportService serverConn close failed, err=" + sqlErr.toString()); + } + try { + if (null != reportService.clientConn) { + reportService.clientConn.close(); + reportService.clientConn=null; + } + } catch (SQLException sqlErr) { + MPPDBIDELoggerUtility.warn("reportService clientConn close failed, err=" + sqlErr.toString()); + } + } + } + + /** + * dispose sql warning of notice + * + * @param notice the notice + * @return void + */ + @Override + public void noticeReceived(SQLWarning notice) { + if (notice == null || notice.getMessage() == null) { + return; + } + String msgString = notice.getMessage(); + MPPDBIDELoggerUtility.debug("sql message:" + msgString); + msgChainHelper.handleSqlMsg(new Event(EventMessage.ON_SQL_MSG, msgString)); + } + + /** + * handle event + * + * @param event event to handle + * @return void + */ + @Override + public void handleEvent(Event event) { + msgChainHelper.handleEventMsg(event); + } + + /** + * update server port + * + * @param serverPort the port to set + * @return void + */ + public void updateServerPort(int serverPort) { + sessionVo.serverPort = serverPort; + serverState.running(); + synchronized (waitLock) { + waitLock.notifyAll(); + } + } + + /** + * update server state with exception + * + * @return void + */ + public void updateServerWithException() { + serverState.terminaled(); + } + + /** + * update server state with normal exit + * + * @param result the execute result + * @return void + */ + public void updateServerWithResult(Object result) { + serverState.stop(); + serverState.stateLocked(); + sessionVo.result = result; + serverThreadProxy.start(); + } + + @Override + public Optional version() throws SQLException { + try (PreparedStatement ps = serverConn.getDebugOptPrepareStatement( + DebugConstants.DebugOpt.DEBUG_VERSION, new ArrayList<>(1))) { + try (ResultSet rs = ps.executeQuery()) { + if (rs.next()) { + return Optional.ofNullable(ParseVo.parse(rs, VersionVo.class)); + } + return Optional.empty(); + } + } + } + + /** + * begin debug + * + * @param args function input args + * @return void + * @throws SQLException sql exception + */ + @Override + public void begin(List args) throws SQLException { + ConstantRunLine.isContinue = null; + ConstantRunLine.isPldebugger = null; + ConstantRunLine.passLine.clear(); + ConstantRunLine.isTerminate = true; + DebuggerStartInfoVo startInfo=DebuggerStartConstants.getStartInfo(functionVo.oid); + startInfo.args=args; + startInfo.oid=functionVo.oid; + startInfo.ifMakeReport=true; + DebuggerStartConstants.setStartInfo(functionVo.oid, startInfo); + getVersion(); + init(); + prepareDebug(); + startDebug(args); + attachDebug(); + } + + public boolean getVersion() { + if (null == ConstantRunLine.isPldebugger) { + try { + ConstantRunLine.isPldebugger = VersionHelper.getDebuggerVersion(clientConn).isPldebugger(); + } catch (SQLException e) { + MPPDBIDELoggerUtility.error(e.getMessage()); + } + } + return ConstantRunLine.isPldebugger; + } + + /** + * end debug + * + * @return void + */ + @Override + public void end() { + try { + abortDebug(); + } catch (SQLException e) { + MPPDBIDELoggerUtility.error("abortDebug with error:" + e.toString()); + } + + serverThreadProxy.join(); + + try { + debugOff(); + Thread.sleep(500); + } catch(InterruptedException e) { + MPPDBIDELoggerUtility.error(e.getMessage()); + } catch (SQLException e) { + MPPDBIDELoggerUtility.debug("debugOff with error:" + e.toString()); + } + closeService(); + } + + /** + * get normal end result + * + * @return Optional the result + */ + @Override + public Optional getResult() { + if (isNormalEnd()) { + return Optional.ofNullable(sessionVo.result); + } + return Optional.empty(); + } + + /** + * is normal end + * + * @return true if normal end + */ + @Override + public boolean isNormalEnd() { + return serverState.isNormalStopped(); + } + + /** + * is debug server still running + * + * @return true if running + */ + @Override + public boolean isRunning() { + return getServerDebugState().isRunning(); + } + + /** + * set function vo + * + * @param functionVo function vo + * @return void + */ + public void setFunctionVo(FunctionVo functionVo) { + this.functionVo = functionVo; + } + + /** + * get server state + * + * @return DebugState state of server + */ + public DebugState getServerDebugState() { + return serverState; + } + + /** + * get server state + * + * @return DebugState state of client + */ + public DebugState getClientDebugState() { + return clientState; + } + + /** + * add server debug exit listener + * + * @param handler event handler of exit + * @return void + */ + @Override + public void addServerExistListener(EventHander handler) { + eventQueueThread.addHandler(handler); + } + + @Override + public void init() { + if (eventQueueThread.getState() == State.NEW) { + eventQueueThread.start(); + } + } + + @Override + public boolean isRollback() { + return isRollback; + } + + @Override + public void setRollback(boolean isRollback) { + this.isRollback = isRollback; + } + + private void serverCallBackBegin() throws SQLException { + serverExecuteInner("begin;"); + } + + private void serverCallBackEnd() throws SQLException { + if (isRollback()) { + serverExecuteInner("rollback;"); + } else { + serverExecuteInner("commit;"); + } + } + + private void serverExecuteInner(String sql) throws SQLException { + if (null != serverConn) { + try (PreparedStatement ps = serverConn.getStatement(sql)) { + ps.execute(); + } + } + } } 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 new file mode 100644 index 0000000000000000000000000000000000000000..79f98d772b8d1447ff5fc8ead725d2a9cc53391e --- /dev/null +++ b/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/debuger/service/DebuggerReportService.java @@ -0,0 +1,246 @@ +package org.opengauss.mppdbide.debuger.service; + +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; + +import org.opengauss.mppdbide.common.IConnection; +import org.opengauss.mppdbide.common.IConnectionProvider; +import org.opengauss.mppdbide.debuger.annotation.ParseVo; +import org.opengauss.mppdbide.debuger.debug.DebugConstants; +import org.opengauss.mppdbide.debuger.debug.DebugConstants.DebugOpt; +import org.opengauss.mppdbide.debuger.exception.DebugPositionNotFoundException; +import org.opengauss.mppdbide.debuger.service.SourceCodeService.CodeDescription; +import org.opengauss.mppdbide.debuger.vo.FunctionVo; +import org.opengauss.mppdbide.debuger.vo.dbe.AttachVo; +import org.opengauss.mppdbide.debuger.vo.dbe.TurnOnVo; +import org.opengauss.mppdbide.utils.ConstantRunLine; +import org.opengauss.mppdbide.utils.DebuggerStartConstants; +import org.opengauss.mppdbide.utils.logger.MPPDBIDELoggerUtility; +import org.opengauss.mppdbide.utils.vo.DebuggerEndInfoVo; +import org.opengauss.mppdbide.utils.vo.DebuggerStartInfoVo; + +/** + * 覆盖率记录生成 + * + * @author gitam + */ +public class DebuggerReportService { + private static DebuggerReportService debuggerReportService = new DebuggerReportService(); + public IConnection serverConn; + public IConnection clientConn; + private FunctionVo functionVo; + private TurnOnVo turnOnVo; + private DebuggerStartInfoVo startInfo; + public static final int CODE_BASE_OFFSET = 1; + + private CodeDescription baseCodeDesc = null; + private CodeDescription totalCodeDesc = null; + + public static DebuggerReportService getInstance() { + return debuggerReportService; + } + + public void setBaseCode(CodeDescription baseCodeDesc) { + this.baseCodeDesc = baseCodeDesc; + } + + public void setTotalCode(CodeDescription totalCodeDesc) { + this.totalCodeDesc = totalCodeDesc; + } + + public DebuggerReportService() { + + } + + private String getCurLine(int breakPointLine) { + try { + return String.valueOf(codeLine2ShowLine(breakPointLine)); + } catch (DebugPositionNotFoundException dbgExp) { + MPPDBIDELoggerUtility.error("receive invalid position:" + dbgExp.toString()); + } + return "-1"; + } + + private String getCurLine() { + try { + return String.valueOf(getBeginDebugCodeLine()); + } catch (DebugPositionNotFoundException debugExp) { + MPPDBIDELoggerUtility.error("receive invalid position:" + debugExp.toString()); + } + return "-1"; + } + + public void setAttr(IConnectionProvider connectProvider, FunctionVo functionVo) { + try { + this.serverConn = connectProvider.getValidFreeConnection(); + this.clientConn = connectProvider.getValidFreeConnection(); + this.functionVo = functionVo; + } catch (SQLException e) { + MPPDBIDELoggerUtility.error(e.getMessage()); + } + } + + /** + * set server connection + * + * @param serverConn connection to set of server + * @return void + */ + public void setServerConn(IConnection serverConn) { + this.serverConn = serverConn; + } + + /** + * set client connection + * + * @param clientConn connection + * @return void + */ + public void setClientConn(IConnection clientConn) { + this.clientConn = clientConn; + } + + /** + * set function vo + * + * @param functionVo function vo + * @return void + */ + public void setFunctionVo(FunctionVo functionVo) { + this.functionVo = functionVo; + } + + /** + * make dbedebugger report info + */ + public void makeReport() { + startInfo = DebuggerStartConstants.getStartInfo(functionVo.oid); + if(!startInfo.ifMakeReport) { + return; + } + List inputsParams = Arrays.asList(functionVo.oid); + ResultSet rs = null; + try { + //DBE_DEBUG_OFF + DebugOpt opt = DebugConstants.DebugOpt.DBE_DEBUG_OFF; + rs = serverConn.getDebugOptPrepareStatement(opt, inputsParams).executeQuery(); + opt = DebugConstants.DebugOpt.DBE_START_SESSION; + rs = serverConn.getDebugOptPrepareStatement(opt, inputsParams).executeQuery(); + if (rs.next()) { + turnOnVo = ParseVo.parse(rs, TurnOnVo.class); + } + + // call proc + List args = startInfo.args; + String sql = DebugConstants.getSql(functionVo.proname, args.size()); + try (PreparedStatement ps = serverConn.getStatement(sql)) { + for (int i = 1; i < args.size() + 1; i++) { + ps.setObject(i, args.get(i - 1)); + } + CompletableFuture.delayedExecutor(100, TimeUnit.MILLISECONDS).execute(() -> { + doClient(); + }); + ps.executeQuery(); + } + } catch (SQLException e) { + MPPDBIDELoggerUtility.error(e.getMessage()); + } finally { + try { + if (null !=rs) { + rs.close(); + } + } catch (SQLException e) { + MPPDBIDELoggerUtility.error(e.getMessage()); + } + } + } + + public void doClient() { + ConstantRunLine.runList.clear(); + List runLinks = new ArrayList(); + List historyList=DebuggerStartConstants.getHistoryList(functionVo.oid); + // attach + List inputsParams = new ArrayList(); + inputsParams.add(turnOnVo.nodename); + inputsParams.add(turnOnVo.port); + DebugOpt opt = DebugConstants.DebugOpt.DBE_ATTACH_SESSION; + try (ResultSet rs= clientConn.getDebugOptPrepareStatement(opt, inputsParams).executeQuery();){ + } catch (SQLException e) { + MPPDBIDELoggerUtility.error(e.getMessage()); + } + runLinks.add(getCurLine()); + //next + inputsParams = new ArrayList(); + opt = DebugConstants.DebugOpt.DBE_STEP_OVER; + Boolean hasNext = 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)); + } + } else { + hasNext = false; + } + } catch (SQLException e) { + hasNext = false; + } + } + ConstantRunLine.runList.addAll(runLinks); + DebuggerEndInfoVo endInfo = new DebuggerEndInfoVo(); + String runStr = runLinks.stream().map(String::valueOf).collect(Collectors.joining(",")); + endInfo.runStr = runStr; + endInfo.setInfo(startInfo); + historyList.add(endInfo); + DebuggerStartConstants.setHistoryList(functionVo.oid, historyList); + String createTableSql="CREATE TABLE IF NOT EXISTS his_coverage( oid BIGINT, cid BIGINT, coverageLines VARCHAR, remarkLines VARCHAR, endTime BIGINT,sourceCode VARCHAR);"; + try { + clientConn.getStatement(createTableSql).execute(); + String insertSql="insert into his_coverage VALUES(?,?,?,?,?,?);"; + PreparedStatement preparedStatement= clientConn.getStatement(insertSql); + preparedStatement.setObject(1, endInfo.oid); + preparedStatement.setObject(2, endInfo.cid); + preparedStatement.setObject(3, endInfo.runStr); + preparedStatement.setObject(4, endInfo.remarLinesStr); + preparedStatement.setObject(5, endInfo.endDateLong); + preparedStatement.setObject(6, endInfo.sourceCode); + preparedStatement.execute(); + } catch (SQLException e) { + MPPDBIDELoggerUtility.error(e.getMessage()); + } + } + + private int getBeginDebugCodeLine() throws DebugPositionNotFoundException { + return getFirstValidDebugPos() + getBeginTotalAndBaseDiff(); + } + + private int getFirstValidDebugPos() throws DebugPositionNotFoundException { + return getBeignOfBaseCode() + CODE_BASE_OFFSET; + } + + private int codeLine2ShowLine(int codeLine) throws DebugPositionNotFoundException { + return codeLine + getBeginTotalAndBaseDiff() - CODE_BASE_OFFSET; + } + + private int getBeginTotalAndBaseDiff() throws DebugPositionNotFoundException { + return getBeignfTotalCode() - getBeignOfBaseCode(); + } + + private int getBeignOfBaseCode() throws DebugPositionNotFoundException { + return this.baseCodeDesc.getBeginPosition(); + } + + private int getBeignfTotalCode() throws DebugPositionNotFoundException { + return this.totalCodeDesc.getBeginPosition(); + } + +} diff --git a/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/debuger/service/IDebugService.java b/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/debuger/service/IDebugService.java index 6ddb1c65120fa61d76d57e4bd75e943476a34c2b..4cb3c42a1aa6cd49595b97e8213dacd9181de792 100644 --- a/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/debuger/service/IDebugService.java +++ b/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/debuger/service/IDebugService.java @@ -194,4 +194,7 @@ public interface IDebugService extends IService { * @return true if running */ boolean isRunning(); + + + } \ No newline at end of file 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 810bbf6cb0ff23720519ec040545df368afa1b63..97dd74984642bdbcecb0d8ff9d8754b8e1382139 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 @@ -15,15 +15,6 @@ package org.opengauss.mppdbide.debuger.service; -import org.opengauss.mppdbide.debuger.dao.FunctionDao; -import org.opengauss.mppdbide.debuger.annotation.ParseVo; -import org.opengauss.mppdbide.debuger.debug.DebugConstants; -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.logger.MPPDBIDELoggerUtility; - import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; @@ -31,6 +22,17 @@ import java.util.Arrays; import java.util.List; import java.util.Optional; +import org.opengauss.mppdbide.common.IConnection; +import org.opengauss.mppdbide.common.QueryResVoConvertHelper; +import org.opengauss.mppdbide.common.VersionHelper; +import org.opengauss.mppdbide.debuger.dao.FunctionDao; +import org.opengauss.mppdbide.debuger.debug.DebugConstants; +import org.opengauss.mppdbide.debuger.debug.DebugConstants.DebugOpt; +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.utils.logger.MPPDBIDELoggerUtility; + /** * Title: the QueryService class * @@ -66,9 +68,10 @@ public class QueryService implements IService { * @throws SQLException sql exp */ public Optional getSourceCode(Long oid) throws SQLException { - return getTempSourceCode(oid, - DebugConstants.DebugOpt.GET_SOURCE_CODE, - SourceCodeVo.class); + DebugOpt opt=VersionHelper.getDebugOptByDebuggerVersion(conn,DebugConstants.DebugOpt.GET_SOURCE_CODE); + Optional sourceCodeVo=getTempSourceCode(oid,opt,SourceCodeVo.class); + String sourceCode= sourceCodeVo.get().getSourceCode(); + return sourceCodeVo; } /** @@ -93,7 +96,7 @@ public class QueryService implements IService { debugOpt, inputParams)) { try (ResultSet rs = ps.executeQuery()) { if (rs.next()) { - return Optional.of(ParseVo.parse(rs, clazz)); + return Optional.of(QueryResVoConvertHelper.parse(rs, clazz,conn)); } return Optional.empty(); } diff --git a/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/debuger/service/ServiceFactory.java b/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/debuger/service/ServiceFactory.java index f6f19ba1d5b6319749e7185251d2b8603a785837..2100564ee22420b78ceb39a28c0adcd727c110cc 100644 --- a/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/debuger/service/ServiceFactory.java +++ b/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/debuger/service/ServiceFactory.java @@ -1,4 +1,4 @@ -/* +/* * Copyright (c) 2022 Huawei Technologies Co.,Ltd. * * openGauss is licensed under Mulan PSL v2. @@ -6,7 +6,7 @@ * You may obtain a copy of Mulan PSL v2 at: * * http://license.coscl.org.cn/MulanPSL2 - * + * * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. @@ -23,7 +23,6 @@ import org.opengauss.mppdbide.common.IConnection; import org.opengauss.mppdbide.common.IConnectionProvider; import org.opengauss.mppdbide.debuger.vo.VersionVo; import org.opengauss.mppdbide.utils.logger.MPPDBIDELoggerUtility; - import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; diff --git a/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/debuger/service/SourceCodeService.java b/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/debuger/service/SourceCodeService.java index 717547e4bf1f928f963032c1c1982c93d4adecc0..cb1183183eaaedd3dd79faae3a99e63f3e7e8014 100644 --- a/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/debuger/service/SourceCodeService.java +++ b/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/debuger/service/SourceCodeService.java @@ -15,12 +15,15 @@ package org.opengauss.mppdbide.debuger.service; -import org.opengauss.mppdbide.debuger.exception.DebugPositionNotFoundException; - +import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Locale; import java.util.stream.Collectors; +import java.util.stream.Stream; + +import org.apache.commons.lang.StringUtils; +import org.opengauss.mppdbide.debuger.exception.DebugPositionNotFoundException; /** * Title: the SourceCodeService class @@ -223,8 +226,70 @@ public class SourceCodeService implements IService { * @return List the list of code */ public static List getLines(String srcCode) { - return Arrays.stream(srcCode.split("[\\n]")).collect(Collectors.toList()); + List s1 = Arrays.stream(srcCode.split("[\r]")).filter(item-> !item.isBlank()).collect(Collectors.toList()); + List s2 = Arrays.stream(srcCode.split("[\\n]")).filter(item-> !item.isBlank()).collect(Collectors.toList()); + List s3 = Arrays.stream(srcCode.split("[\r\\n]")).filter(item-> !item.isBlank()).collect(Collectors.toList()); + return Stream.of(s1,s2,s3).max((v1,v2)-> v1.size() -v2.size()).get().stream().map(item->item.trim()).filter(item-> StringUtils.isNotBlank(item)).collect(Collectors.toList()); + } + + /** + * get code to run lines + * @param srcCode + * @return + */ + public static List getRunLines(String srcCode){ + List totalLines=getLines(srcCode); + Boolean isStart=false; + Boolean isEnd=false; + Boolean isBegin=false; + List runLines=new ArrayList(); + for(String line:totalLines) { + if(!isStart) { + isStart=line.toUpperCase(Locale.ENGLISH).contains("BEGIN"); + } + isEnd=line.toUpperCase(Locale.ENGLISH).contains("END;"); + if(isEnd) { + break; + } + if(isStart) { + isBegin=line.toUpperCase(Locale.ENGLISH).contains("BEGIN"); + if(!isBegin) { + runLines.add(line); + } + } + } + return runLines; + + } + + + public static List getRunLinesNums(String srcCode){ + List totalLines=getLines(srcCode); + Boolean isStart=false; + Boolean isEnd=false; + Boolean isBegin=false; + List runLines=new ArrayList(); + Integer count=0; + for(String line:totalLines) { + count++; + if(!isStart) { + isStart=line.toUpperCase(Locale.ENGLISH).contains("BEGIN"); + } + isEnd=line.toUpperCase(Locale.ENGLISH).contains("END;"); + if(isEnd) { + break; + } + if(isStart) { + isBegin=line.toUpperCase(Locale.ENGLISH).contains("BEGIN"); + if(!isBegin) { + runLines.add(count.toString()); + } + } + } + return runLines; + } + private int getBeginFromCode(List lines) { for (int i = 0; i < lines.size(); i ++) { diff --git a/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/debuger/vo/BreakPointListVo.java b/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/debuger/vo/BreakPointListVo.java new file mode 100644 index 0000000000000000000000000000000000000000..44b66f5482b3b481043dd4875789c5bc0c6aef86 --- /dev/null +++ b/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/debuger/vo/BreakPointListVo.java @@ -0,0 +1,17 @@ +package org.opengauss.mppdbide.debuger.vo; + +import org.opengauss.mppdbide.debuger.annotation.DumpFiled; + +public class BreakPointListVo { + + @DumpFiled + public int breakpointno; + @DumpFiled + public Long funcoid; + @DumpFiled + public int lineno; + @DumpFiled + public String query; + @DumpFiled + public Boolean enable; +} diff --git a/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/debuger/vo/BreakpointList.java b/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/debuger/vo/BreakpointList.java index 294a36e36e938c3eb0b44b8941ff690d7d0d7500..2b09cca24301e16e384ba1933e7d078d1b7b29dd 100644 --- a/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/debuger/vo/BreakpointList.java +++ b/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/debuger/vo/BreakpointList.java @@ -36,6 +36,9 @@ public class BreakpointList { * @return Map the instance of BreakpointList */ public static Map getInstance() { + if(breakpointList==null) { + initialInstance(); + } return breakpointList; } diff --git a/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/debuger/vo/PositionVo.java b/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/debuger/vo/PositionVo.java index 7c2250faa006746c8768537df70fe254243d4a4c..aabe8df6ac0c78f1ee6ede95e529e998b57ed2d5 100644 --- a/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/debuger/vo/PositionVo.java +++ b/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/debuger/vo/PositionVo.java @@ -29,7 +29,10 @@ public class PositionVo { * the format of this vo */ public static final String FORMAT = "%8s %20s"; + + public Boolean enable; + public Integer breakpointno; /** * func of positionvo */ @@ -51,6 +54,10 @@ public class PositionVo { public PositionVo() { this(null, null, null); } + + public Integer getBreakpointno() { + return breakpointno; + } public PositionVo(Long func, Integer linenumber, String targetname) { this.func = func; diff --git a/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/debuger/vo/SourceCodeVo.java b/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/debuger/vo/SourceCodeVo.java index 967e572f621cf92a99d731739bb62fa115c59ced..2d48c503e203a39310a166377975e9753befc7fc 100644 --- a/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/debuger/vo/SourceCodeVo.java +++ b/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/debuger/vo/SourceCodeVo.java @@ -15,7 +15,13 @@ package org.opengauss.mppdbide.debuger.vo; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + import org.opengauss.mppdbide.debuger.annotation.DumpFiled; +import org.opengauss.mppdbide.debuger.vo.dbe.InfoCodeVo; /** * Title: the SourceCodeVo class @@ -28,7 +34,9 @@ public class SourceCodeVo { */ @DumpFiled public String pldbg_get_source; - + + private List codes; + /** * get source code * @@ -37,4 +45,19 @@ public class SourceCodeVo { public String getSourceCode() { return pldbg_get_source; } + + public void setSourceCode(String sourceCode) { + this.pldbg_get_source=sourceCode; + } + + public Map getCodes() { + if (null == codes) { + return Collections.emptyMap(); + } + return codes.stream().collect(Collectors.toMap(InfoCodeVo::getLineno, InfoCodeVo::getQuery)); + } + + public void setCodes(List codes) { + this.codes=codes; + } } diff --git a/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/debuger/vo/VersionVo.java b/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/debuger/vo/VersionVo.java index aebe21855b3ceb9a56e44e5fbd28c5bfe0ed3a52..61e1f1574f027061290bf4994f98a4c1f623f6a9 100644 --- a/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/debuger/vo/VersionVo.java +++ b/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/debuger/vo/VersionVo.java @@ -1,4 +1,4 @@ -/* +/* * Copyright (c) 2022 Huawei Technologies Co.,Ltd. * * openGauss is licensed under Mulan PSL v2. @@ -6,7 +6,7 @@ * You may obtain a copy of Mulan PSL v2 at: * * http://license.coscl.org.cn/MulanPSL2 - * + * * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. @@ -16,6 +16,7 @@ package org.opengauss.mppdbide.debuger.vo; import org.opengauss.mppdbide.debuger.annotation.DumpFiled; +import org.opengauss.mppdbide.debuger.debug.DebugConstants; /** * Title: VersionVo for use @@ -27,23 +28,47 @@ public class VersionVo { * this is version str */ @DumpFiled + public String version; + + public String debuggerVersion; + + /** + * this is version str + */ public String serverversionstr; /** * this is version number */ - @DumpFiled public Integer serverversionnum; /** * this is proxy api version */ - @DumpFiled public Integer proxyapiver; /** * this is server process id */ - @DumpFiled public Long serverprocessid; + + public String getDebuggerVersion() { + String versionStr=this.version; + Integer start = versionStr.indexOf("openGauss")+9; + Integer end = versionStr.indexOf("build"); + versionStr = versionStr.substring(start, end); + versionStr=versionStr.replaceAll("\\.", "").trim(); + Integer ver = Integer.valueOf(versionStr); + if (ver < DebugConstants.DBE_DEBUGGER_MIN_VERSION) { + return DebugConstants.PL_DEBUGGER; + } else { + return DebugConstants.DBE_DEBUGGER; + } + } + + public boolean isPldebugger() { + this.debuggerVersion=getDebuggerVersion(); + return debuggerVersion.equalsIgnoreCase(DebugConstants.PL_DEBUGGER); + + } } diff --git a/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/debuger/vo/dbe/AttachVo.java b/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/debuger/vo/dbe/AttachVo.java new file mode 100644 index 0000000000000000000000000000000000000000..d967763e053de755599e0f552cc09a647895d6e4 --- /dev/null +++ b/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/debuger/vo/dbe/AttachVo.java @@ -0,0 +1,16 @@ +package org.opengauss.mppdbide.debuger.vo.dbe; + +import org.opengauss.mppdbide.debuger.annotation.DumpFiled; + +public class AttachVo { + + @DumpFiled + public long funcoid; + @DumpFiled + public String funcname; + @DumpFiled + public int lineno; + @DumpFiled + public String query; + +} diff --git a/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/debuger/vo/dbe/BacktraceVo.java b/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/debuger/vo/dbe/BacktraceVo.java new file mode 100644 index 0000000000000000000000000000000000000000..812740e2ae9dc518afcef173ccce0fb7e7401ae0 --- /dev/null +++ b/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/debuger/vo/dbe/BacktraceVo.java @@ -0,0 +1,37 @@ +package org.opengauss.mppdbide.debuger.vo.dbe; + +import org.opengauss.mppdbide.debuger.annotation.DumpFiled; + +public class BacktraceVo { + + @DumpFiled + public Integer frameno; + @DumpFiled + public String funcname; + @DumpFiled + public Integer lineno; + @DumpFiled + public String query; + @DumpFiled + public long funcoid; + + public Integer getFrameno() { + return frameno; + } + + public String getFuncname() { + return funcname; + } + + public Integer getLineno() { + return lineno; + } + + public String getQuery() { + return query; + } + + public long getFuncoid() { + return funcoid; + } +} diff --git a/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/debuger/vo/dbe/InfoBreakpointsVo.java b/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/debuger/vo/dbe/InfoBreakpointsVo.java new file mode 100644 index 0000000000000000000000000000000000000000..b10a1abe31d4366b96cc441284db6ac682efda5a --- /dev/null +++ b/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/debuger/vo/dbe/InfoBreakpointsVo.java @@ -0,0 +1,37 @@ +package org.opengauss.mppdbide.debuger.vo.dbe; + +import org.opengauss.mppdbide.debuger.annotation.DumpFiled; + +public class InfoBreakpointsVo { + + @DumpFiled + private Integer breakpointno; + @DumpFiled + private long funcoid; + @DumpFiled + private Integer lineno; + @DumpFiled + private String query; + @DumpFiled + private Boolean enable; + + public Integer getBreakpointno() { + return breakpointno; + } + + public long getFuncoid() { + return funcoid; + } + + public Integer getLineno() { + return lineno; + } + + public String getQuery() { + return query; + } + + public Boolean getEnable() { + return enable; + } +} diff --git a/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/debuger/vo/dbe/InfoCodeVo.java b/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/debuger/vo/dbe/InfoCodeVo.java new file mode 100644 index 0000000000000000000000000000000000000000..228c00682fa9e9abcf88ae0f8086990b9ed2140c --- /dev/null +++ b/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/debuger/vo/dbe/InfoCodeVo.java @@ -0,0 +1,22 @@ +package org.opengauss.mppdbide.debuger.vo.dbe; + +import org.opengauss.mppdbide.debuger.annotation.DumpFiled; + +public class InfoCodeVo { + + @DumpFiled + public int lineno; + @DumpFiled + public String query; + @DumpFiled + public boolean canbreak; + + public Integer getLineno() { + return lineno; + } + + public String getQuery() { + return query; + } + +} diff --git a/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/debuger/vo/dbe/ServerInfoVo.java b/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/debuger/vo/dbe/ServerInfoVo.java new file mode 100644 index 0000000000000000000000000000000000000000..f3ffb9d2df9b23be34861d5d782e35fea52f1f30 --- /dev/null +++ b/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/debuger/vo/dbe/ServerInfoVo.java @@ -0,0 +1,13 @@ +package org.opengauss.mppdbide.debuger.vo.dbe; + +import org.opengauss.mppdbide.debuger.annotation.DumpFiled; + +public class ServerInfoVo { + + @DumpFiled + String nodename; + @DumpFiled + Long port; + @DumpFiled + Long funcoid; +} diff --git a/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/debuger/vo/dbe/TurnOnVo.java b/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/debuger/vo/dbe/TurnOnVo.java new file mode 100644 index 0000000000000000000000000000000000000000..f4f1c7e4d4fc61310d39fe84573cb0c99a840e81 --- /dev/null +++ b/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/debuger/vo/dbe/TurnOnVo.java @@ -0,0 +1,13 @@ +package org.opengauss.mppdbide.debuger.vo.dbe; + +import org.opengauss.mppdbide.debuger.annotation.DumpFiled; + +public class TurnOnVo { + + + @DumpFiled + public String nodename; + @DumpFiled + public int port; + +} diff --git a/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/debuger/vo/dbe/VariablesVo.java b/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/debuger/vo/dbe/VariablesVo.java new file mode 100644 index 0000000000000000000000000000000000000000..5ea25dab08887ff2ad7a8c8b50d6334f6950a7c7 --- /dev/null +++ b/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/debuger/vo/dbe/VariablesVo.java @@ -0,0 +1,113 @@ +package org.opengauss.mppdbide.debuger.vo.dbe; + +import java.util.Map; +import java.util.Map.Entry; + +import org.opengauss.mppdbide.adapter.gauss.Datatype; +import org.opengauss.mppdbide.adapter.gauss.GaussDatatypeUtils; +import org.opengauss.mppdbide.debuger.annotation.DumpFiled; +import org.opengauss.mppdbide.utils.logger.MPPDBIDELoggerUtility; + +public class VariablesVo { + + @DumpFiled + public String varname; + @DumpFiled + public String vartype; + @DumpFiled + public String value; + @DumpFiled + public String package_name; + @DumpFiled + public Boolean isconst; + public Long dtype; + + + public Long getDtype() { + String type = null; + switch (this.vartype) { + case "bpchar": { + type ="char"; + break; + } + case "bool": { + type = "boolean"; + break; + } + case "float": { + type = "binary double"; + break; + } + case "int2": { + type = "smallint"; + break; + } + case "int4": { + type = "integer"; + break; + } + case "int8": { + type = "bigint"; + break; + } + case "float8": { + type = "double precision"; + break; + } + case "float4": { + type = "real"; + break; + } + case "timetz": { + type = "time with time zone"; + break; + } + case "timestamptz": { + type = "timestamp with time zone"; + break; + } + case "time": { + type = "time without time zone"; + break; + } + case "timestamp": { + type = "timestamp without time zone"; + break; + } + default: + break; + } + if (type == null) { + MPPDBIDELoggerUtility.error("not supported type!"); + return 0L; + } + Map map = GaussDatatypeUtils.getDataTypeHashMap(); + for (Entry entry : map.entrySet()) { + if (type.equalsIgnoreCase(entry.getValue().getTypename())) { + this.dtype = Long.valueOf(entry.getKey()); + break; + } + } + return dtype; + } + + public String getVarname() { + return varname; + } + + public String getVartype() { + return vartype; + } + + public String getValue() { + return value; + } + + public String getPackage_name() { + return package_name; + } + + public Boolean getIsconst() { + return isconst; + } +} diff --git a/code/datastudio/src/org.opengauss.mppdbide.utils/META-INF/MANIFEST.MF b/code/datastudio/src/org.opengauss.mppdbide.utils/META-INF/MANIFEST.MF index 34b3e4418c4ee2d14be19364f30e837ec31ad71a..c5b38b942c93cfae1c5e36dc06b6dc7021ab22b6 100644 --- a/code/datastudio/src/org.opengauss.mppdbide.utils/META-INF/MANIFEST.MF +++ b/code/datastudio/src/org.opengauss.mppdbide.utils/META-INF/MANIFEST.MF @@ -24,7 +24,8 @@ Export-Package: ., org.opengauss.mppdbide.utils.messaging, org.opengauss.mppdbide.utils.observer, org.opengauss.mppdbide.utils.security, - org.opengauss.mppdbide.utils.stringparse + org.opengauss.mppdbide.utils.stringparse, + org.opengauss.mppdbide.utils.vo Import-Package: net.sf.jsqlparser.schema Bundle-ClassPath: ., log4j-api-2.17.1.jar, diff --git a/code/datastudio/src/org.opengauss.mppdbide.utils/src/org/opengauss/mppdbide/utils/ConstantRunLine.java b/code/datastudio/src/org.opengauss.mppdbide.utils/src/org/opengauss/mppdbide/utils/ConstantRunLine.java new file mode 100644 index 0000000000000000000000000000000000000000..84a763be6795103ee918012e06ded43eb8ec2a80 --- /dev/null +++ b/code/datastudio/src/org.opengauss.mppdbide.utils/src/org/opengauss/mppdbide/utils/ConstantRunLine.java @@ -0,0 +1,19 @@ +package org.opengauss.mppdbide.utils; + +import java.util.List; +import java.util.Set; +import java.util.concurrent.CopyOnWriteArrayList; +import java.util.concurrent.CopyOnWriteArraySet; + +public class ConstantRunLine { + + public static volatile List runList = new CopyOnWriteArrayList<>(); + + public static volatile Set passLine = new CopyOnWriteArraySet(); + + public static volatile boolean isTerminate = true; + + public static volatile Boolean isContinue; + + public static volatile Boolean isPldebugger; +} diff --git a/code/datastudio/src/org.opengauss.mppdbide.utils/src/org/opengauss/mppdbide/utils/DebuggerStartConstants.java b/code/datastudio/src/org.opengauss.mppdbide.utils/src/org/opengauss/mppdbide/utils/DebuggerStartConstants.java new file mode 100644 index 0000000000000000000000000000000000000000..b464749af6bd7954b1a0ffc789d589ac59af8374 --- /dev/null +++ b/code/datastudio/src/org.opengauss.mppdbide.utils/src/org/opengauss/mppdbide/utils/DebuggerStartConstants.java @@ -0,0 +1,44 @@ +package org.opengauss.mppdbide.utils; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.opengauss.mppdbide.utils.vo.DebuggerEndInfoVo; +import org.opengauss.mppdbide.utils.vo.DebuggerStartInfoVo; + +public class DebuggerStartConstants { + + public static Map beginInfoMap = new HashMap(); + + public static Map> endInfoMap = new HashMap(); + + public static List getHistoryList(Long oid) { + List list = endInfoMap.get(oid); + if (list == null) { + list = new ArrayList(); + setHistoryList(oid, list); + } + return list; + } + + public static void setHistoryList(Long oid, List list) { + endInfoMap.put(oid, list); + } + + + public static DebuggerStartInfoVo getStartInfo(Long oid) { + DebuggerStartInfoVo info = beginInfoMap.get(oid); + if (info == null) { + info = new DebuggerStartInfoVo(); + setStartInfo(oid, info); + } + return info; + } + + public static void setStartInfo(Long oid, DebuggerStartInfoVo info) { + beginInfoMap.put(oid, info); + } + +} diff --git a/code/datastudio/src/org.opengauss.mppdbide.utils/src/org/opengauss/mppdbide/utils/IMessagesConstants.java b/code/datastudio/src/org.opengauss.mppdbide.utils/src/org/opengauss/mppdbide/utils/IMessagesConstants.java index 9ed69f4b5bf900edac773da187d0d58493296cdd..f39b6cc741c48bd4508c678f543dca323705e17e 100644 --- a/code/datastudio/src/org.opengauss.mppdbide.utils/src/org/opengauss/mppdbide/utils/IMessagesConstants.java +++ b/code/datastudio/src/org.opengauss.mppdbide.utils/src/org/opengauss/mppdbide/utils/IMessagesConstants.java @@ -1,4 +1,4 @@ -/* +/* * Copyright (c) 2022 Huawei Technologies Co.,Ltd. * * openGauss is licensed under Mulan PSL v2. @@ -6,7 +6,7 @@ * You may obtain a copy of Mulan PSL v2 at: * * http://license.coscl.org.cn/MulanPSL2 - * + * * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. @@ -1027,7 +1027,7 @@ public interface IMessagesConstants extends IMessagesConstantsOne { String YES_OPTION = "YES_OPTION"; String NO_OPTION = "NO_OPTION"; - + String SECURITY_WARNING_OPTION = "SECURITY_WARNING_OPTION"; String ENABLE_OPTION = "ENABLE_OPTION"; @@ -1948,7 +1948,7 @@ public interface IMessagesConstants extends IMessagesConstantsOne { String CODE_TEMPLATE_PREFPAGE_MESSAGE = "CODE_TEMPLATE_PREFPAGE_MESSAGE"; String CODE_TEMPLATE_PREFPAGE_TITLE = "CODE_TEMPLATE_PREFPAGE_TITLE"; - + String CODE_TEMPLATE_DUPLICATE_MSG = "CODE_TEMPLATE_DUPLICATE_MSG"; String CODE_TEMPLATE_PREFPAGE_EDIT = "CODE_TEMPLATE_PREFPAGE_EDIT"; @@ -2135,6 +2135,7 @@ public interface IMessagesConstants extends IMessagesConstantsOne { String PROPERTIES_COMPLEX_DATATYPE_ERROR_MSG = "PROPERTIES_COMPLEX_DATATYPE_ERROR_MSG"; String PREFERENCE_SHORTCUT_KEY_BINDING_TOGGLE_LINE_COMMENTS = "PREFERENCE_SHORTCUT_KEY_BINDING_TOGGLE_LINE_COMMENTS"; + String REMARK_SHORTCUT_KEY_BINDING_TOGGLE_LINE_COMMENTS="REMARK_SHORTCUT_KEY_BINDING_TOGGLE_LINE_COMMENTS"; String PREFERENCE_SHORTCUT_KEY_BINDING_TOGGLE_BLOCK_COMMENTS = "PREFERENCE_SHORTCUT_KEY_BINDING_TOGGLE_BLOCK_COMMENTS"; @@ -2921,6 +2922,8 @@ public interface IMessagesConstants extends IMessagesConstantsOne { String BREAKPOINT_ANNOTATION_LABEL = "BREAKPOINT_ANNOTATION_LABEL"; String DEBUG_POSITION_LABEL = "DEBUG_POSITION_LABEL"; + String DEBUG_POSITION_LABEL_PASS = "DEBUG_POSITION_LABEL_PASS"; + String DEBUG_POSITION_LABEL_FAIL = "DEBUG_POSITION_LABEL_FAIL"; String DEBUG_TABLE_ORDER = "DEBUG_TABLE_ORDER"; String DEBUG_STACK_INVOKING_LEVEL = "DEBUG_STACK_INVOKING_LEVEL"; @@ -3015,4 +3018,25 @@ public interface IMessagesConstants extends IMessagesConstantsOne { String CREATE_VIEW_UI_VIEW = "CREATE_VIEW_UI_VIEW"; String CREATE_VIEW_UI_MATERVIEW = "CREATE_VIEW_UI_MATERVIEW"; String CREATE_VIEW_UI_NAME_NOT_EMPTY = "CREATE_VIEW_UI_NAME_NOT_EMPTY"; + + String OID="OID"; + String TOTAL_LINE="TOTAL_LINE"; + String TOTAL_RUN_LINE_NUM="TOTAL_RUN_LINE_NUM"; + String TOTAL_Coverage="TOTAL_Coverage"; + String REMARK_LINE="REMARK_LINE"; + String REMARK_RUM_LIME_NUM="REMARK_RUM_LIME_NUM"; + String REMARK_Coverage="REMARK_Coverage"; + String DELETE_Coverage = "DELETE_Coverage"; + String DELETE_Coverage_All="DELETE_Coverage_All"; + String EXPORT_REPORT="EXPORT_REPORT"; + + String COVERAGE_HISTORY_TITLE = "COVERAGE_HISTORY_TITLE"; + String DELETE_COVERAGE_REPORT_TITLE = "DELETE_COVERAGE_REPORT_TITLE"; + String DELETE_SELECTED_COVERAGE_HISTORY_ALERT = "DELETE_SELECTED_COVERAGE_HISTORY_ALERT"; + String DELETE_ALL_COVERAGE_HISTORY_ALERT = "DELETE_ALL_COVERAGE_HISTORY_ALERT"; + String SURE_EXPORT_REPORT = "SURE_EXPORT_REPORT"; + String COVERAGE_REPORT_NOT_EXIST = "COVERAGE_REPORT_NOT_EXIST"; + String COVERAGE_REPORT_TO_SELECT = "COVERAGE_REPORT_TO_SELECT"; + String UPDATE_TIME = "UPDATE_TIME"; + } 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 ff57dd80b67f2b4c5efc463d17f0cec2516ce6fe..3e024733bbb77ccc6b58f0f857dc67daad034077 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 @@ -1099,4 +1099,7 @@ public interface IMessagesConstantsOne extends IMessagesConstantsTwo { String ERROR_WHILE_FETCHING_OWNER_NAME = "ERROR_WHILE_FETCHING_OWNER_NAME"; String ERR_WHILE_FETCHING_SEQ_VALUE = "ERR_WHILE_FETCHING_SEQ_VALUE"; + String COVERAGE_HINT = "COVERAGE_HINT"; + String EXPORT_PATH = "EXPORT_PATH"; + String COVERAGE_CHECK = "COVERAGE_CHECK"; } \ No newline at end of file diff --git a/code/datastudio/src/org.opengauss.mppdbide.utils/src/org/opengauss/mppdbide/utils/vo/DebuggerEndInfoVo.java b/code/datastudio/src/org.opengauss.mppdbide.utils/src/org/opengauss/mppdbide/utils/vo/DebuggerEndInfoVo.java new file mode 100644 index 0000000000000000000000000000000000000000..932f6cbc8105c5ad46dde71dd4575b5cdc429efb --- /dev/null +++ b/code/datastudio/src/org.opengauss.mppdbide.utils/src/org/opengauss/mppdbide/utils/vo/DebuggerEndInfoVo.java @@ -0,0 +1,36 @@ +package org.opengauss.mppdbide.utils.vo; + +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +/** + * 存储过程结束后的执行信息 + * @author gitam + * + */ +public class DebuggerEndInfoVo extends DebuggerStartInfoVo{ + SimpleDateFormat dateFormat = new SimpleDateFormat("ddMMyyyyHHmmssSSS"); + public Long cid=System.currentTimeMillis(); //覆盖率id + public Long endDateLong=System.currentTimeMillis(); //结束时间 + public List runList; //跑到的行 + public String runStr; //跑到行的字符串 + + public List getRunList() { + if (runStr==null || "".equals(runStr)){ + return new ArrayList(); + }else { + remarkList =new ArrayList<>(Arrays.asList(runStr.split(","))); + } + return remarkList; + } + + public void setInfo(DebuggerStartInfoVo info) { + super.oid=info.oid; + super.sourceCode=info.sourceCode; + super.args=info.args; + super.remarLinesStr=info.remarLinesStr; + } + +} diff --git a/code/datastudio/src/org.opengauss.mppdbide.utils/src/org/opengauss/mppdbide/utils/vo/DebuggerStartInfoVo.java b/code/datastudio/src/org.opengauss.mppdbide.utils/src/org/opengauss/mppdbide/utils/vo/DebuggerStartInfoVo.java new file mode 100644 index 0000000000000000000000000000000000000000..36cf885e938cf378a77ea23a69e33f25163ea4c1 --- /dev/null +++ b/code/datastudio/src/org.opengauss.mppdbide.utils/src/org/opengauss/mppdbide/utils/vo/DebuggerStartInfoVo.java @@ -0,0 +1,29 @@ +package org.opengauss.mppdbide.utils.vo; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +/** + * 存储过程启动时候的信息 + * @author gitam + * + */ +public class DebuggerStartInfoVo { + + public Long oid; //存储过程id + public String sourceCode; //源代码 + public List args; //启动参数 + public List remarkList; //标记的行 + public String remarLinesStr; //标记行的字符串 + public boolean ifMakeReport=true; //是否生成报告 + + public List getRemarkList() { + if (remarLinesStr==null || "".equals(remarLinesStr)){ + return new ArrayList(); + }else { + remarkList =new ArrayList<>(Arrays.asList(remarLinesStr.split(","))); + } + return remarkList; + } +} diff --git a/code/datastudio/src/org.opengauss.mppdbide.view/Application.e4xmi b/code/datastudio/src/org.opengauss.mppdbide.view/Application.e4xmi index 26da7d5e56fd0dc252a3103b2a4e804d53ebaa40..0d93b5955efaf5f19d2a29cbecb94e4c6e5e76d3 100644 --- a/code/datastudio/src/org.opengauss.mppdbide.view/Application.e4xmi +++ b/code/datastudio/src/org.opengauss.mppdbide.view/Application.e4xmi @@ -166,6 +166,7 @@ + @@ -314,6 +315,7 @@ + @@ -1020,6 +1022,7 @@ + diff --git a/code/datastudio/src/org.opengauss.mppdbide.view/META-INF/MANIFEST.MF b/code/datastudio/src/org.opengauss.mppdbide.view/META-INF/MANIFEST.MF index b8eb0ac833da42df25c1d6c12399ba8fd40b220e..3770da56c384bf14f64b3d6a532bdb5e73a63af1 100644 --- a/code/datastudio/src/org.opengauss.mppdbide.view/META-INF/MANIFEST.MF +++ b/code/datastudio/src/org.opengauss.mppdbide.view/META-INF/MANIFEST.MF @@ -8,7 +8,9 @@ Bundle-ClassPath: ., guava-30.1.1-jre.jar Bundle-Activator: org.opengauss.mppdbide.view.Activator Bundle-Vendor: Huawei Technologies -Export-Package: org.opengauss.mppdbide.view.utils +Export-Package: org.opengauss.mppdbide.view.handler.debug, + org.opengauss.mppdbide.view.ui, + org.opengauss.mppdbide.view.utils Require-Bundle: org.eclipse.core.runtime;bundle-version="3.15.300", org.eclipse.swt;bundle-version="3.108.0", javax.inject;bundle-version="1.0.0", @@ -71,12 +73,20 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="3.15.300", openjfx.graphics.win32_64;bundle-version="17.0.2", openjfx.swing;bundle-version="17.0.2", openjfx.swt;bundle-version="17.0.2" -Bundle-RequiredExecutionEnvironment: JavaSE-11 +Bundle-RequiredExecutionEnvironment: JavaSE-11, + OSGi/Minimum-1.2 Bundle-ActivationPolicy: lazy Import-Package: com.google.common.collect;version="15.0.0", com.google.inject;version="1.3.0", com.google.inject.binder;version="1.3.0", com.google.inject.util;version="1.3.0", + javax.annotation;version="1.0.0";resolution:=optional, + javax.inject;version="1.0.0", + org.apache.commons.collections4.trie, + org.apache.commons.csv, + org.eclipse.ui.editors.text, + org.jsoup;version="1.14.3", + org.jsoup.nodes;version="1.14.3", org.opengauss.mppdbide.editor.extension.nameparser, org.opengauss.mppdbide.explainplan.ui.model, org.opengauss.mppdbide.parser.alias, @@ -93,9 +103,4 @@ Import-Package: com.google.common.collect;version="15.0.0", org.opengauss.mppdbide.presentation.resultsetif, org.opengauss.mppdbide.presentation.search, org.opengauss.mppdbide.presentation.visualexplainplan, - javax.annotation;version="1.0.0";resolution:=optional, - javax.inject;version="1.0.0", - org.apache.commons.collections4.trie, - org.apache.commons.csv, - org.eclipse.ui.editors.text, org.postgresql diff --git a/code/datastudio/src/org.opengauss.mppdbide.view/icons/debug/breakpoint_indicate.png b/code/datastudio/src/org.opengauss.mppdbide.view/icons/debug/breakpoint_indicate.png index bf1501cf404360d9719e0a90cd2b3dd9c48efe46..e978dff6fdc6ebaf1a0e9670844de7ff5d4a3cee 100644 Binary files a/code/datastudio/src/org.opengauss.mppdbide.view/icons/debug/breakpoint_indicate.png and b/code/datastudio/src/org.opengauss.mppdbide.view/icons/debug/breakpoint_indicate.png differ diff --git a/code/datastudio/src/org.opengauss.mppdbide.view/icons/debug/debug_fail.png b/code/datastudio/src/org.opengauss.mppdbide.view/icons/debug/debug_fail.png new file mode 100644 index 0000000000000000000000000000000000000000..4c3566ff562cd80c56c8f1c4c143f3f388ed573d Binary files /dev/null and b/code/datastudio/src/org.opengauss.mppdbide.view/icons/debug/debug_fail.png differ diff --git a/code/datastudio/src/org.opengauss.mppdbide.view/icons/debug/debug_pass.png b/code/datastudio/src/org.opengauss.mppdbide.view/icons/debug/debug_pass.png new file mode 100644 index 0000000000000000000000000000000000000000..451929c1a72a089169a6867c18af0c61c57bd2cd Binary files /dev/null and b/code/datastudio/src/org.opengauss.mppdbide.view/icons/debug/debug_pass.png differ diff --git a/code/datastudio/src/org.opengauss.mppdbide.view/icons/icon-remarkCoverage.png b/code/datastudio/src/org.opengauss.mppdbide.view/icons/icon-remarkCoverage.png new file mode 100644 index 0000000000000000000000000000000000000000..d90d6614769fe5d94cbd425aac517d878a007198 Binary files /dev/null and b/code/datastudio/src/org.opengauss.mppdbide.view/icons/icon-remarkCoverage.png differ diff --git a/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/core/sourceeditor/AnnotationHelper.java b/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/core/sourceeditor/AnnotationHelper.java index 41858e3f5f1c80e5c2cf830362c3ed0299316a83..a28cfebe42fc3c60b3265f31eca5f15ffca6e5ec 100644 --- a/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/core/sourceeditor/AnnotationHelper.java +++ b/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/core/sourceeditor/AnnotationHelper.java @@ -16,7 +16,6 @@ package org.opengauss.mppdbide.view.core.sourceeditor; import org.eclipse.swt.graphics.RGB; - import org.opengauss.mppdbide.utils.IMessagesConstants; import org.opengauss.mppdbide.utils.loader.MessageConfigLoader; @@ -52,15 +51,23 @@ public class AnnotationHelper { * debug position annotation type label */ public static final String DEBUG_POSITION_TYPE_LABEL = IMessagesConstants.DEBUG_POSITION_LABEL; + + public static final String DEBUG_POSITION_TYPE_PASS = IMessagesConstants.DEBUG_POSITION_LABEL_PASS; + + public static final String DEBUG_POSITION_TYPE_FAIL = IMessagesConstants.DEBUG_POSITION_LABEL_FAIL; /** * debug position annotation strategy id */ public static final String DEBUG_POSITION_STRATEGY_ID = "PLSQL_DEBUGGER_DEBUG_POSITION"; + + public static final String DEBUG_POSITION_STRATEGY_PASS_ID = "PLSQL_DEBUGGER_DEBUG_POSITION_PASS"; + + public static final String DEBUG_POSITION_STRATEGY_FAIL_ID = "PLSQL_DEBUGGER_DEBUG_POSITION_FAIL"; /** * debug position annotation rgb */ public static final RGB DEBUG_POSITION_RGB = new RGB(255, 153, 51); - + /** * error annotation layer */ @@ -94,6 +101,15 @@ public class AnnotationHelper { * error position annotation rgb */ public static final RGB ERROR_POSITION_RGB = new RGB(255, 255, 0); + + public static final int DEBUG_POSITION_LAYER_PASS = 4; + + public static final RGB DEBUG_POSITION_PASS_RGB = new RGB(40, 255, 15); + + public static final int DEBUG_POSITION_LAYER_FAIL = 5; + + public static final RGB DEBUG_POSITION_FAIL_RGB = new RGB(255, 30, 25); + /** * Title: AnnotationType enum this enum assocate with AnnotationWithLineNumber's instance @@ -104,6 +120,10 @@ public class AnnotationHelper { BREAKPOINT_RGB), DEBUG_POSITION(DEBUG_POSITION_LAYER, DEBUG_POSITION_TYPE_LABEL, DEBUG_POSITION_STRATEGY_ID, DEBUG_POSITION_RGB), + DEBUG_POSITION_PASS(DEBUG_POSITION_LAYER_PASS, DEBUG_POSITION_TYPE_PASS, DEBUG_POSITION_STRATEGY_PASS_ID, + DEBUG_POSITION_PASS_RGB), + DEBUG_POSITION_FAIL(DEBUG_POSITION_LAYER_FAIL, DEBUG_POSITION_TYPE_FAIL, DEBUG_POSITION_STRATEGY_FAIL_ID, + DEBUG_POSITION_FAIL_RGB), ERROR(ERROR_LAYER, ERROR_TYPE_LABEL, ERROR_STRATEGY_ID, ERROR_RGB), ERROR_POSITION(ERROR_POSITION_LAYER, ERROR_POSITION_TYPE_LABEL, ERROR_POSITION_STRATEGY_ID, diff --git a/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/core/sourceeditor/DebugFailPositionAnnotation.java b/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/core/sourceeditor/DebugFailPositionAnnotation.java new file mode 100644 index 0000000000000000000000000000000000000000..364f98178f8e0b88b7ea539eb0e94a8006b518d0 --- /dev/null +++ b/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/core/sourceeditor/DebugFailPositionAnnotation.java @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2022 Huawei Technologies Co.,Ltd. + * + * openGauss is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * + * http://license.coscl.org.cn/MulanPSL2 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + */ + +package org.opengauss.mppdbide.view.core.sourceeditor; + +import java.util.Optional; + +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.RGB; +import org.opengauss.mppdbide.view.core.sourceeditor.AnnotationHelper.AnnotationType; +import org.opengauss.mppdbide.view.utils.icon.IiconPath; + +/** + * Title: class + * Description: The Class DebugFailPositionAnnotation. + * + * @since 3.0.0 + */ +public class DebugFailPositionAnnotation extends AnnotationWithLineNumber { + private static final AnnotationType ANNOTATION_TYPE_FAIL = AnnotationType.DEBUG_POSITION_FAIL; + private static final RGB DEBUGPOSITION_RGB = new RGB(255, 153, 51); + + /** + * Instantiates a new debug position annotation. + * + * @param line the line + */ + public DebugFailPositionAnnotation(int line) { + super(ANNOTATION_TYPE_FAIL.getStrategy(), false, "[Line : " + line, line); + } + + /** + * Gets the layer. + * + * @return the layer + */ + public static int getLayer() { + return ANNOTATION_TYPE_FAIL.getLayer(); + } + + /** + * Gets the image. + * + * @return the image + */ + public Optional getImage() { + return Optional.of( + loadImage(IiconPath.ICO_EXECUTE_Fail) + ); + } + + /** + * Gets the breakpoint rgb. + * + * @return the breakpoint rgb + */ + public static RGB getBreakpointRgb() { + return DEBUGPOSITION_RGB; + } + + /** + * Gets the strategyid. + * + * @return the strategyid + */ + public static String getStrategyid() { + return ANNOTATION_TYPE_FAIL.getStrategy(); + } + + /** + * Gets the typelabel. + * + * @return the typelabel + */ + public static String getTypelabel() { + return ANNOTATION_TYPE_FAIL.getTypeLabel(); + } + + @Override + public AnnotationType getAnnotationType() { + return ANNOTATION_TYPE_FAIL; + } +} diff --git a/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/core/sourceeditor/DebugPassPositionAnnotation.java b/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/core/sourceeditor/DebugPassPositionAnnotation.java new file mode 100644 index 0000000000000000000000000000000000000000..8841fa9a7b02d34ce6bfaa9d82a79d7503cf2a65 --- /dev/null +++ b/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/core/sourceeditor/DebugPassPositionAnnotation.java @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2022 Huawei Technologies Co.,Ltd. + * + * openGauss is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * + * http://license.coscl.org.cn/MulanPSL2 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + */ + +package org.opengauss.mppdbide.view.core.sourceeditor; + +import java.util.Optional; + +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.RGB; +import org.opengauss.mppdbide.view.core.sourceeditor.AnnotationHelper.AnnotationType; +import org.opengauss.mppdbide.view.utils.icon.IiconPath; + +/** + * Title: class + * Description: The Class DebugPassPositionAnnotation. + * + * @since 3.0.0 + */ +public class DebugPassPositionAnnotation extends AnnotationWithLineNumber { + private static final AnnotationType ANNOTATION_TYPE_PASS = AnnotationType.DEBUG_POSITION_PASS; + private static final RGB DEBUGPOSITION_RGB = new RGB(255, 153, 51); + + /** + * Instantiates a new debug position annotation. + * + * @param line the line + */ + public DebugPassPositionAnnotation(int line) { + super(ANNOTATION_TYPE_PASS.getStrategy(), false, "[Line : " + line, line); + } + + /** + * Gets the layer. + * + * @return the layer + */ + public static int getLayer() { + return ANNOTATION_TYPE_PASS.getLayer(); + } + + /** + * Gets the image. + * + * @return the image + */ + public Optional getImage() { + return Optional.of( + loadImage(IiconPath.ICO_EXECUTE_PASS) + ); + } + + /** + * Gets the breakpoint rgb. + * + * @return the breakpoint rgb + */ + public static RGB getBreakpointRgb() { + return DEBUGPOSITION_RGB; + } + + /** + * Gets the strategyid. + * + * @return the strategyid + */ + public static String getStrategyid() { + return ANNOTATION_TYPE_PASS.getStrategy(); + } + + /** + * Gets the typelabel. + * + * @return the typelabel + */ + public static String getTypelabel() { + return ANNOTATION_TYPE_PASS.getTypeLabel(); + } + + @Override + public AnnotationType getAnnotationType() { + return ANNOTATION_TYPE_PASS; + } +} 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 b45bb730f3de1df20b62f77221f9c253725d4e05..fb0e159af225df99aeec58fcdff0a2c72cdf768e 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 @@ -1,4 +1,4 @@ -/* +/* * Copyright (c) 2022 Huawei Technologies Co.,Ltd. * * openGauss is licensed under Mulan PSL v2. @@ -6,7 +6,7 @@ * You may obtain a copy of Mulan PSL v2 at: * * http://license.coscl.org.cn/MulanPSL2 - * + * * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. @@ -15,9 +15,13 @@ package org.opengauss.mppdbide.view.core.sourceeditor; +import java.sql.SQLException; import java.util.ArrayList; import java.util.Iterator; +import java.util.List; import java.util.Locale; +import java.util.Optional; +import java.util.stream.Collectors; import javax.annotation.PreDestroy; @@ -63,8 +67,6 @@ import org.eclipse.jface.text.source.IOverviewRuler; import org.eclipse.jface.text.source.ISharedTextColors; import org.eclipse.jface.text.source.OverviewRuler; import org.eclipse.jface.text.source.SourceViewer; -import org.eclipse.jface.text.source.projection.ProjectionAnnotation; -import org.eclipse.jface.text.source.projection.ProjectionAnnotationModel; import org.eclipse.jface.text.source.projection.ProjectionSupport; import org.eclipse.jface.text.source.projection.ProjectionViewer; import org.eclipse.jface.util.IPropertyChangeListener; @@ -81,7 +83,6 @@ import org.eclipse.swt.events.KeyEvent; import org.eclipse.swt.events.KeyListener; import org.eclipse.swt.events.MouseAdapter; import org.eclipse.swt.events.MouseEvent; -import org.eclipse.swt.events.MouseListener; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.events.VerifyEvent; @@ -97,16 +98,20 @@ import org.eclipse.swt.widgets.MenuItem; import org.eclipse.swt.widgets.Widget; import org.eclipse.ui.internal.editors.text.EditorsPlugin; import org.eclipse.ui.texteditor.SourceViewerDecorationSupport; - import org.opengauss.mppdbide.adapter.keywordssyntax.SQLSyntax; import org.opengauss.mppdbide.bl.serverdatacache.Database; +import org.opengauss.mppdbide.common.IConnection; +import org.opengauss.mppdbide.common.IConnectionProvider; +import org.opengauss.mppdbide.common.VersionHelper; import org.opengauss.mppdbide.gauss.sqlparser.SQLFoldingConstants; +import org.opengauss.mppdbide.utils.DebuggerStartConstants; import org.opengauss.mppdbide.utils.IMessagesConstants; import org.opengauss.mppdbide.utils.MPPDBIDEConstants; 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.SelectMenuItem; -import org.opengauss.mppdbide.view.handler.debug.DebugHandlerUtils; +import org.opengauss.mppdbide.view.handler.debug.DBConnectionProvider; import org.opengauss.mppdbide.view.handler.debug.DebugServiceHelper; import org.opengauss.mppdbide.view.prefernces.DSFormatterPreferencePage; import org.opengauss.mppdbide.view.prefernces.FormatterPreferenceKeys; @@ -123,6 +128,7 @@ import org.opengauss.mppdbide.view.uidisplay.UIDisplayState; import org.opengauss.mppdbide.view.uidisplay.uidisplayif.UIDisplayStateIf; import org.opengauss.mppdbide.view.utils.IUserPreference; import org.opengauss.mppdbide.view.utils.TerminalStatusBar; +import org.opengauss.mppdbide.view.utils.UIElement; import org.opengauss.mppdbide.view.utils.dialog.MPPDBIDEDialogs; import org.opengauss.mppdbide.view.utils.dialog.MPPDBIDEDialogs.MESSAGEDIALOGTYPE; import org.opengauss.mppdbide.view.utils.icon.IconUtility; @@ -135,6 +141,7 @@ import org.opengauss.mppdbide.view.workerjob.UIWorkerJob; * @since 3.0.0 */ public final class PLSourceEditorCore extends SelectMenuItem implements IPropertyChangeListener { + private static final String FORMAT_COMMAND_ID = "org.opengauss.mppdbide.command.id.format"; private ECommandService commandService; @@ -337,10 +344,10 @@ public final class PLSourceEditorCore extends SelectMenuItem implements IPropert addPasteMenuItem(menu); addSelectAllMenuItem(menu); addToggleLineCommentMenuItem(menu); + addRemarkLineCommentMenuItem(menu); addToggleBlockCommentMenuItem(menu); addFormatMenuItem(menu); addExecStmtMenuItem(menu); - this.config = new SQLSourceViewerConfig(syntx); setTabStrategy(); @@ -1334,6 +1341,69 @@ public final class PLSourceEditorCore extends SelectMenuItem implements IPropert toggleLineComments.setImage(IconUtility.getIconImage(IiconPath.ICON_TOGGLE_LINE_COMMENTS, this.getClass())); } + private void addRemarkLineCommentMenuItem(Menu menuItem) { + toggleLineComments = new MenuItem(menuItem, SWT.PUSH); + toggleLineComments.setText(MessageConfigLoader + .getProperty(IMessagesConstants.REMARK_SHORTCUT_KEY_BINDING_TOGGLE_LINE_COMMENTS)); + toggleLineComments.addSelectionListener(new SelectionListener() { + + @Override + public void widgetSelected(SelectionEvent event) { + PLSourceEditor pl = UIElement.getInstance().getVisibleSourceViewer(); + IConnectionProvider prov = new DBConnectionProvider(pl.getDebugObject().getDatabase()); + Optional conn = prov.getFreeConnection(); + try { + boolean isPldebugger= VersionHelper.getDebuggerVersion(conn.get()).isPldebugger(); + if (isPldebugger) { + MPPDBIDEDialogs.generateOKMessageDialog(MESSAGEDIALOGTYPE.INFORMATION, true, + MessageConfigLoader.getProperty(IMessagesConstants.EXECDIALOG_HINT), + MessageConfigLoader.getProperty(IMessagesConstants.COVERAGE_CHECK)); + return; + } + ISelection res = viewer.getSelection(); + int start = Integer.valueOf(res.toString().split("startLine: ")[1].split(",")[0]); + String[] arr = res.toString().split("endLine: "); + int endLength = 1; + if (arr.length > 1) { + endLength = Integer.parseInt(arr[1].split(",")[0]); + } + List list = new ArrayList(); + for(int i = start; i< (endLength==1?start+1:endLength+1); i++) { + list.add(String.valueOf(i)); + } + long oid = pl.getDebugObject().getOid(); + DebuggerStartInfoVo startInfo=DebuggerStartConstants.getStartInfo(oid); + List remarkLines= startInfo.getRemarkList(); + List cancel = list.stream().filter(item -> remarkLines.contains(item)).collect(Collectors.toList()); + cancel.forEach(item -> viewer.getTextWidget().setLineBackground(Integer.parseInt(item), 1, SQLSyntaxColorProvider.BACKGROUND_COLOR)); + List newRemark = list.stream().filter(item -> !remarkLines.contains(item)).collect(Collectors.toList()); + newRemark.forEach(item -> viewer.getTextWidget().setLineBackground(Integer.parseInt(item), 1, SQLSyntaxColorProvider.BACKGROUND_COLOR_GREY)); + List oldRemark = remarkLines.stream().filter(item -> !list.contains(item)).collect(Collectors.toList()); + newRemark.addAll(oldRemark); + String remarLinesStr= newRemark.stream().map(String::valueOf).collect(Collectors.joining(",")); + startInfo.remarLinesStr=remarLinesStr; + DebuggerStartConstants.setStartInfo(oid, startInfo); + } catch (SQLException e) { + MPPDBIDELoggerUtility.error(e.getMessage()); + } finally { + try { + conn.get().close(); + } catch (SQLException e) { + MPPDBIDELoggerUtility.error(e.getMessage()); + } + } + } + + @Override + public void widgetDefaultSelected(SelectionEvent event) { + + } + }); + toggleLineComments.setImage(IconUtility.getIconImage(IiconPath.ICON_REMARK_COVERAGE, this.getClass())); + } + + + /** * Adds the toggle block comment menu item. * @@ -2463,7 +2533,7 @@ public final class PLSourceEditorCore extends SelectMenuItem implements IPropert /** * to remove completed Job - * + * * @param job which job need to be removed */ public void removeCompletedJob(UIWorkerJob job) { @@ -2482,7 +2552,7 @@ public final class PLSourceEditorCore extends SelectMenuItem implements IPropert public AnnotationModel getfAnnotationModel() { return fAnnotationModel; } - + /** * pre destroy */ diff --git a/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/core/sourceeditor/SQLSyntaxColorProvider.java b/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/core/sourceeditor/SQLSyntaxColorProvider.java index 7d67c146e265f73c9145b4586248a30ea2402c72..07dae8193229444072655a6cc53e3b83b3398b34 100644 --- a/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/core/sourceeditor/SQLSyntaxColorProvider.java +++ b/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/core/sourceeditor/SQLSyntaxColorProvider.java @@ -71,6 +71,8 @@ public class SQLSyntaxColorProvider { * The Constant BACKGROUND_COLOR. */ public static final Color BACKGROUND_COLOR = new Color(Display.getCurrent(), BACKGROUND); + + public static final Color BACKGROUND_COLOR_GREY = new Color(Display.getCurrent(), new RGB(167, 169, 169)); /** * use for debug position highlight 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 cdcecad51bc26a5d75d8b2dfccfc904c014012bd..56c17facc1d54ee55573ac5bfb1e5227bc5d82e2 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 @@ -15,6 +15,7 @@ package org.opengauss.mppdbide.view.handler; +import java.sql.SQLException; import java.util.ArrayList; import javax.inject.Inject; @@ -29,16 +30,18 @@ import org.eclipse.jface.text.BadLocationException; import org.eclipse.jface.text.Document; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; - import org.opengauss.mppdbide.adapter.gauss.DBConnection; import org.opengauss.mppdbide.adapter.keywordssyntax.SQLSyntax; import org.opengauss.mppdbide.bl.errorlocator.IErrorLocator; import org.opengauss.mppdbide.bl.serverdatacache.Database; import org.opengauss.mppdbide.bl.serverdatacache.DatabaseUtils; +import org.opengauss.mppdbide.bl.serverdatacache.DebugObjects; import org.opengauss.mppdbide.bl.serverdatacache.IDebugObject; import org.opengauss.mppdbide.bl.serverdatacache.OBJECTTYPE; import org.opengauss.mppdbide.bl.serverdatacache.ObjectChange; import org.opengauss.mppdbide.bl.serverdatacache.ObjectParameter; +import org.opengauss.mppdbide.common.IConnection; +import org.opengauss.mppdbide.common.VersionHelper; import org.opengauss.mppdbide.presentation.CanContextContinueExecuteRule; import org.opengauss.mppdbide.presentation.IExecutionContext; import org.opengauss.mppdbide.presentation.IResultDisplayUIManager; @@ -56,6 +59,7 @@ import org.opengauss.mppdbide.view.functionchange.ExecuteWrapper; import org.opengauss.mppdbide.view.functionchange.ObjectChangeEvent; import org.opengauss.mppdbide.view.functionchange.ObjectChangeEvent.ButtonPressed; import org.opengauss.mppdbide.view.functionchange.ObjectChangeWorker; +import org.opengauss.mppdbide.view.handler.debug.DBConnectionProvider; import org.opengauss.mppdbide.view.terminal.TerminalQueryExecutionWorker; import org.opengauss.mppdbide.view.terminal.executioncontext.FuncProcEditorTerminalExecutionContext; import org.opengauss.mppdbide.view.ui.PLSourceEditor; @@ -73,802 +77,829 @@ import org.opengauss.mppdbide.view.utils.dialog.MPPDBIDEDialogs.MESSAGEDIALOGTYP */ public class ExecuteEditorItem implements ExecuteWrapper { - /** - * Executor - * - * @param application - * @param service - */ - @Inject - private ECommandService commandService; - - @Inject - private EHandlerService handlerService; - - private QueryInfo queryInfo = new QueryInfo(); - - private static final String ERROR_POSITION_IDENTIFIER = "Position:"; - - /** - * Execute. - */ - @Execute - public void execute() { - - MPPDBIDELoggerUtility - .info(MessageConfigLoader.getProperty(IMessagesConstants.GUI_EXECUTEEDITORITEM_EXECUTE_CLICKED)); - PLSourceEditor editor = UIElement.getInstance().getVisibleSourceViewer(); - if (null == editor) { - Command command = commandService.getCommand("org.opengauss.mppdbide.command.id.executeobjectbrowseritem"); - ParameterizedCommand parameterizedCommand = ParameterizedCommand.generateCommand(command, null); - handlerService.executeHandler(parameterizedCommand); - return; - } - editor.setExecuteInProgress(true); - editor.enabledisableTextWidget(false); - IDebugObject debugObject = editor.getDebugObject(); - ObjectChangeWorker objWorker = new ObjectChangeWorker("Function Change Worker", - null, debugObject, editor, this, IMessagesConstants.FUNCTN_CHANGE_MSG, - IMessagesConstants.FUNCTN_CHANGE_OVERWRITE); - objWorker.schedule(); - } - - /** - * Handle execute. - * - * @param event the event - */ - @Override - public void handleExecute(ObjectChangeEvent event) { - PLSourceEditor editor = event.getEditor(); - IDebugObject debugObject = event.getDbgObj(); - Database db = debugObject.getDatabase(); - boolean iscontinue = true; - - if (validateForRefreshStatus(event)) { - iscontinue = refreshDebugObjectOnTerminal(editor, debugObject, db); - } else { - boolean codeChanged = editor.isCodeChanged(); - int returnVal = displayIfCodeChanged(codeChanged); - - boolean debugObjChanged = true; - debugObjChanged = getDebugObjectChanged(debugObject, debugObjChanged); - - iscontinue = executeIfCodeNotChanged(editor, debugObject, db, codeChanged, returnVal, debugObjChanged); - - iscontinue = executeIfCodeIsChanged(editor, iscontinue, codeChanged, returnVal, debugObjChanged); - } - if (iscontinue) { - editor.enabledisableTextWidget(true); - editor.setCompileInProgress(false); - editor.setExecuteInProgress(false); - executeSQLObjWindow(debugObject, false); - } - } - - /** - * Execute if code is changed. - * - * @param editor the editor - * @param iscontinue the iscontinue - * @param codeChanged the code changed - * @param returnVal the return val - * @param debugObjChanged the debug obj changed - * @return true, if successful - */ - private boolean executeIfCodeIsChanged(PLSourceEditor editor, boolean iscontinue, boolean codeChanged, - int returnVal, boolean debugObjChanged) { - iscontinue = refreshOnDebugObjChange(editor, iscontinue, codeChanged, returnVal, debugObjChanged); - if (iscontinue && codeChanged && (returnVal != 0)) { - editor.enabledisableTextWidget(true); - editor.setCompileInProgress(false); - editor.setExecuteInProgress(false); - return false; - } - return iscontinue; - } - - /** - * Refresh on debug obj change. - * - * @param editor the editor - * @param iscontinue the iscontinue - * @param codeChanged the code changed - * @param returnVal the return val - * @param debugObjChanged the debug obj changed - * @return true, if successful - */ - private boolean refreshOnDebugObjChange(PLSourceEditor editor, boolean iscontinue, boolean codeChanged, - int returnVal, boolean debugObjChanged) { - if (iscontinue && codeChanged && (returnVal == 0)) { - refreshDebugObjectOnChanged(editor, debugObjChanged); - editor.setCompileInProgress(false); - editor.setExecuteInProgress(false); - editor.enabledisableTextWidget(true); - editor.getConsoleMessageWindow(true) - .logInfo(MessageConfigLoader.getProperty(IMessagesConstants.STATUS_MSG_STATUS)); - iscontinue = executeIfDebugObjectIsNotChanged(editor, debugObjChanged); - } - return iscontinue; - } - - /** - * Execute if debug object is not changed. - * - * @param editor the editor - * @param debugObjChanged the debug obj changed - * @return true, if successful - */ - private boolean executeIfDebugObjectIsNotChanged(PLSourceEditor editor, boolean debugObjChanged) { - if (!debugObjChanged) { - - // source code changed, but the debug object didnt change as new - // debug object compiled open the new function in a new tab - - IExecutionContext context = generateContext(Display.getDefault().getActiveShell(), editor); - TerminalQueryExecutionWorker worker = new TerminalQueryExecutionWorker(context) { - - private boolean isExecuted = false; - - /** - * Final cleanup. - * - * @throws MPPDBIDEException the MPPDBIDE exception - */ - public void finalCleanup() throws MPPDBIDEException { - super.finalCleanup(); - if (this.context instanceof FuncProcEditorTerminalExecutionContext) { - FuncProcEditorTerminalExecutionContext funcContext = (FuncProcEditorTerminalExecutionContext) this.context; - IResultDisplayUIManager canExecute = funcContext.getResultDisplayUIManager(); - if (CanContextContinueExecuteRule.CONTEXT_EXECUTION_PROCEED == canExecute - .canContextExecutionContinue() && !isExecuted) { - Display.getDefault().syncExec(new Runnable() { - @Override - public void run() { - PLSourceEditor editor1 = UIElement.getInstance() - .getEditorModelById(funcContext.getDebugObject()); - if (editor1 != null) { - editor1.enabledisableTextWidget(true); - editor1.setCompileInProgress(false); - editor1.setExecuteInProgress(false); - executeSQLObjWindow(editor1.getDebugObject(), false); - } - } - }); - - isExecuted = true; - } - - } - - } - }; - worker.setTaskDB(context.getTermConnection().getDatabase()); - worker.schedule(); - return false; - } - return true; - } - - /** - * Refresh debug object on changed. - * - * @param editor the editor - * @param debugObjChanged the debug obj changed - */ - private void refreshDebugObjectOnChanged(PLSourceEditor editor, boolean debugObjChanged) { - if (debugObjChanged) { - editor.refreshDebugObjectAfterEdit(editor.getDebugObject()); - } - } - - /** - * Execute if code not changed. - * - * @param editor the editor - * @param debugObject the debug object - * @param db the db - * @param codeChanged the code changed - * @param returnVal the return val - * @param debugObjChanged the debug obj changed - * @return true, if successful - */ - private boolean executeIfCodeNotChanged(PLSourceEditor editor, IDebugObject debugObject, Database db, - boolean codeChanged, int returnVal, boolean debugObjChanged) { - if (validateIfCodeChanged(codeChanged, returnVal) && debugObjChanged) { - return executeOnCodeChange(editor, debugObject, db); - } - return true; - } - - /** - * Execute on code change. - * - * @param editor the editor - * @param debugObject the debug object - * @param db the db - * @return true, if successful - */ - private boolean executeOnCodeChange(PLSourceEditor editor, IDebugObject debugObject, Database db) { - try { - executeOnTerminal(editor, debugObject, db); - editor.enabledisableTextWidget(true); - } catch (DatabaseOperationException exception) { - MPPDBIDELoggerUtility.error("error while execute debug obj.", exception); - editor.enabledisableTextWidget(true); - return false; - } - return true; - } - - /** - * Validate if code changed. - * - * @param codeChanged the code changed - * @param returnVal the return val - * @return true, if successful - */ - private boolean validateIfCodeChanged(boolean codeChanged, int returnVal) { - return (!codeChanged) || (returnVal == 0); - } - - /** - * Display if code changed. - * - * @param codeChanged the code changed - * @return the int - */ - private int displayIfCodeChanged(boolean codeChanged) { - int returnVal = -1; - if (codeChanged) { - returnVal = MPPDBIDEDialogs.generateYesNoMessageDialog(MESSAGEDIALOGTYPE.QUESTION, true, - MessageConfigLoader.getProperty(IMessagesConstants.SOURCE_CODE_CHANGE), - MessageConfigLoader.getProperty(IMessagesConstants.SOURCE_HAS_BEEN_CHANGED)); - } - return returnVal; - } - - /** - * Gets the debug object changed. - * - * @param debugObject the debug object - * @param debugObjChanged the debug obj changed - * @return the debug object changed - */ - private boolean getDebugObjectChanged(IDebugObject debugObject, boolean debugObjChanged) { - try { - debugObjChanged = debugObject.isChanged(debugObject.getLatestInfo()); - } catch (DatabaseCriticalException exception) { - MPPDBIDELoggerUtility.error("error while comparing debug obj info with server", exception); - } catch (DatabaseOperationException exception) { - MPPDBIDELoggerUtility.error("error while comparing debug obj info with server", exception); - } - return debugObjChanged; - } - - /** - * Refresh debug object on terminal. - * - * @param editor the editor - * @param debugObject the debug object - * @param db the db - * @return true, if successful - */ - private boolean refreshDebugObjectOnTerminal(PLSourceEditor editor, IDebugObject debugObject, Database db) { - editor.setDocument(new Document(debugObject.getSourceCode().getCode())); - editor.registerModifyListener(); - try { - executeOnTerminal(editor, debugObject, db); - } catch (DatabaseOperationException exception) { - MPPDBIDELoggerUtility.error("error while execute debug obj.", exception); - editor.enabledisableTextWidget(true); - return false; - } - return true; - } - - /** - * Validate for refresh status. - * - * @param event the event - * @return true, if successful - */ - private boolean validateForRefreshStatus(ObjectChangeEvent event) { - return event.getStatus() != null && event.getStatus().equals(ButtonPressed.REFRESH); - } - - /** - * Generate context. - * - * @param shell the shell - * @param editor the editor - * @return the i execution context - */ - private IExecutionContext generateContext(Shell shell, PLSourceEditor editor) { - ExecuteSourceEditor executeSourceEditor = null; - executeSourceEditor = new ExecuteSourceEditor(shell, editor); - - return executeSourceEditor.getContextForNewEditor(); - - } - - /** - * Execute on terminal. - * - * @param editor the editor - * @param debugObject the debug object - * @param db the db - * @throws DatabaseOperationException the database operation exception - */ - private void executeOnTerminal(PLSourceEditor editor, IDebugObject debugObject, Database db) - throws DatabaseOperationException { - String query = editor.getDocument(); - DBConnection conn = null; - - try { - conn = executeOnTerminal(editor, debugObject, query); - } catch (DatabaseOperationException exception) { - editor.setExecuteInProgress(false); - String message = ""; - message = getServerMessageDetails(editor, query, exception); - message = getErrorMessage(message, exception); - editor.getConsoleMessageWindow(true).logErrorInUI(message); - MPPDBIDELoggerUtility.error("ExecuteEditorItem: execute on terminal failed.", exception); - throw new DatabaseOperationException("error occured."); - } catch (DatabaseCriticalException e) { - UIDisplayFactoryProvider.getUIDisplayStateIf().handleDBCriticalError(e, db); - return; - } finally { - releaseConnection(db, conn); - } - - } - - /** - * Execute on terminal. - * - * @param editor the editor - * @param debugObject the debug object - * @param query the query - * @return the DB connection - * @throws DatabaseCriticalException the database critical exception - * @throws DatabaseOperationException the database operation exception - */ - private DBConnection executeOnTerminal(PLSourceEditor editor, IDebugObject debugObject, String query) - throws DatabaseCriticalException, DatabaseOperationException { - DBConnection conn = null; - if (query.trim().isEmpty()) { - MPPDBIDEDialogs.generateOKMessageDialog(MESSAGEDIALOGTYPE.ERROR, true, - MessageConfigLoader.getProperty(IMessagesConstants.EMPTY_PLSOURCE_TITEL), - MessageConfigLoader.getProperty(IMessagesConstants.EMPTY_PLSOURCE_VIEWER)); - return conn; - } - - conn = debugObject.getDatabase().getConnectionManager().getObjBrowserConn(); - DatabaseUtils.executeOnSqlTerminalAndReturnNothing(query, 0, conn, editor.getConsoleMsgQueue(false)); - editor.setCriticalErr(true); - editor.refreshDebugObjectAfterEdit(debugObject); - editor.setModified(false); - editor.setModifiedAfterCreate(false); - editor.setExecuteInProgress(false); - return conn; - } - - /** - * Release connection. - * - * @param db the db - * @param conn the conn - */ - private void releaseConnection(Database db, DBConnection conn) { - if (conn != null) { - db.getConnectionManager().releaseAndDisconnection(conn); - } - } - - /** - * Gets the error message. - * - * @param message the message - * @param e the e - * @return the error message - */ - private String getErrorMessage(String message, DatabaseOperationException e) { - if (message.isEmpty()) { - message = MessageConfigLoader.getProperty(IMessagesConstants.EXECUTION_FAILED_ITEM, - MPPDBIDEConstants.LINE_SEPARATOR, e.getErrorCode(), - e.getServerMessage() == null ? e.getDBErrorMessage() : e.getServerMessage()); - } - return message; - } - - /** - * Gets the server message details. - * - * @param editor the editor - * @param query the query - * @param e the e - * @return the server message details - */ - private String getServerMessageDetails(PLSourceEditor editor, String query, DatabaseOperationException e) { - String message = ""; - if (validateServerMessage(e)) { - try { - getErrorDetailsForLocator(editor, query, e); - } catch (BadLocationException exception) { - MPPDBIDELoggerUtility.error("ExecuteEditorItem: execute on terminal failed.", exception); - } - - message = MessageConfigLoader.getProperty(IMessagesConstants.EXECUTION_FAILED_ITEM, - MPPDBIDEConstants.LINE_SEPARATOR, e.getErrorCode(), - (e.getServerMessage() == null ? e.getDBErrorMessage() : e.getServerMessage()) - + MPPDBIDEConstants.LINE_SEPARATOR + " Line Number: " + queryInfo.getErrLineNo()); - } - return message; - } - - /** - * Validate server message. - * - * @param e the e - * @return true, if successful - */ - private boolean validateServerMessage(DatabaseOperationException e) { - return e.getServerMessage() != null && e.getServerMessage().contains(ERROR_POSITION_IDENTIFIER); - } - - /** - * Gets the error details for locator. - * - * @param editor the editor - * @param query the query - * @param e the e - * @return the error details for locator - * @throws BadLocationException the bad location exception - */ - private void getErrorDetailsForLocator(PLSourceEditor editor, String query, DatabaseOperationException e) - throws BadLocationException { - Database database = editor.getDatabase(); - - if (database != null) { - IErrorLocator errorLocator = database.getErrorLocator(); - String msg = e.getServerMessage(); - int errorPos = -1; - errorPos = getErrorPOsition(msg, errorPos); - - errorPos = getErrorPositionForGreaterThanSize(query, errorPos); - queryInfo.setErrorPosition(errorPos); - int errLineNo = editor.getsourceViewerLineOfOffset(getErrorLineNumber(errorLocator)); - queryInfo.setErrLineNo(errLineNo + 1); - } - } - - /** - * Gets the error line number. - * - * @param errorLocator the error locator - * @return the error line number - */ - private int getErrorLineNumber(IErrorLocator errorLocator) { - return errorLocator.errorLineNumber(queryInfo.getStartOffset(), queryInfo.getErrorPosition()); - } - - /** - * Gets the error P osition. - * - * @param msg the msg - * @param errorPos the error pos - * @return the error P osition - */ - private int getErrorPOsition(String msg, int errorPos) { - if (null != msg) { - - int idx = msg.lastIndexOf(ERROR_POSITION_IDENTIFIER); - String newStr; - newStr = getErrorPositionString(msg, idx); - - newStr = getStringForNewLine(newStr); - errorPos = convertErrorPositionToInt(errorPos, newStr); - } - - else { - errorPos++; - } - return errorPos; - } - - /** - * Gets the error position for greater than size. - * - * @param query the query - * @param errorPos the error pos - * @return the error position for greater than size - */ - private int getErrorPositionForGreaterThanSize(String query, int errorPos) { - if (errorPos > query.length()) { - errorPos = query.length(); - } - return errorPos; - } - - /** - * Convert error position to int. - * - * @param errorPos the error pos - * @param newStr the new str - * @return the int - */ - private int convertErrorPositionToInt(int errorPos, String newStr) { - try { - errorPos = Integer.parseInt(newStr.trim()); - } catch (NumberFormatException ex) { - errorPos++; - } - return errorPos; - } - - /** - * Gets the error position string. - * - * @param msg the msg - * @param idx the idx - * @return the error position string - */ - private String getErrorPositionString(String msg, int idx) { - String newStr; - if (idx != -1) { - newStr = msg.substring(idx + ERROR_POSITION_IDENTIFIER.length() + 1); - } else { - newStr = msg.substring(ERROR_POSITION_IDENTIFIER.length() + 1); - } - return newStr; - } - - /** - * Gets the string for new line. - * - * @param newStr the new str - * @return the string for new line - */ - private String getStringForNewLine(String newStr) { - if (newStr.contains(MPPDBIDEConstants.LINE_SEPARATOR)) { - newStr = newStr.substring(0, newStr.indexOf(MPPDBIDEConstants.LINE_SEPARATOR)); - } - return newStr; - } - - /** - * Execute SQL obj window. - * - * @param debugObject the debug object - */ - public void executeSQLObjWindow(IDebugObject debugObject, boolean isCurrentTerminal) { - ExcuteSQLObjectTable executeSQLObjectWindowCoreEdit = new ExcuteSQLObjectTable( - Display.getDefault().getActiveShell()); - executeSQLObjectWindowCoreEdit.setSyntax(getSqlSyntax(debugObject)); - try { - executeSQLObjectWindowCoreEdit.setDebugObject(debugObject); - } catch (DatabaseCriticalException exception) { - UIDisplayFactoryProvider.getUIDisplayStateIf().handleDBCriticalError(exception, debugObject.getDatabase()); - return; - } catch (MPPDBIDEException exception) { - handleMppDbIdeException(exception); - return; - } catch (Exception exception) { - MPPDBIDELoggerUtility.error( - MessageConfigLoader.getProperty(IMessagesConstants.ERR_WHILE_STARTING_TO_EXECUTE_SQL_OBJECT), - exception); - MPPDBIDEDialogs.generateErrorDialog(MessageConfigLoader.getProperty(IMessagesConstants.PLSQL_ERR), - MessageConfigLoader.getProperty(IMessagesConstants.UNKNOWN_INTERNAL_ERR), exception); - } - executeSQLObjectWindowCoreEdit.defaultParameterValues(); - debugObject.setIsCurrentTerminal(isCurrentTerminal); - - openParameterWindow(debugObject, executeSQLObjectWindowCoreEdit); - } - - private void handleMppDbIdeException(MPPDBIDEException exception) { - UIDisplayUtil.getDebugConsole().logError(MessageConfigLoader - .getProperty(IMessagesConstants.OPERATION_CANNOT_BE_PERFOREMD, exception.getMessage())); - MPPDBIDEDialogs.generateDSErrorDialog(MessageConfigLoader.getProperty(IMessagesConstants.EXECUTE_DEBUGE), - MessageConfigLoader.getProperty(IMessagesConstants.OPERATION_CANNOT_BE_PERFOREMD_TITLE), - MessageConfigLoader.getProperty(IMessagesConstants.OPERATION_CANNOT_BE_PERFOREMD, - exception.getServerMessage()), - exception); - } - - /** - * Open parameter window. - * - * @param debugObject the debug object - * @param executeSQLObjectWindowCoreEdit the execute SQL object window core - * edit - */ - private void openParameterWindow(IDebugObject debugObject, ExcuteSQLObjectTable executeSQLObjectWindowCoreEdit) { - if (executeFunctionProcedure(debugObject, executeSQLObjectWindowCoreEdit)) { - - executeSQLObjectWindowCoreEdit.open(); - } - } - - /** - * Gets the sql syntax. - * - * @param debugObject the debug object - * @return the sql syntax - */ - private SQLSyntax getSqlSyntax(IDebugObject debugObject) { - return debugObject.getDatabase() == null ? null : debugObject.getDatabase().getSqlSyntax(); - } - - /** - * Execute function procedure. - * - * @param debugObject the debug object - * @param executeSQLObjectWindowCoreEdit the execute SQL object window core - * edit - * @return true, if successful - */ - private boolean executeFunctionProcedure(IDebugObject debugObject, - ExcuteSQLObjectTable executeSQLObjectWindowCoreEdit) { - boolean isContinue = true; - if (validateOlapFunctions(debugObject)) { - ArrayList params = debugObject.getTemplateParameters(); - - isContinue = executeForNoParameters(executeSQLObjectWindowCoreEdit, params); - - isContinue = validateExecutableFunction(isContinue, params); - } - return isContinue; - } - - /** - * Validate executable function. - * - * @param isContinue the is continue - * @param params the params - * @return true, if successful - */ - private boolean validateExecutableFunction(boolean isContinue, ArrayList params) { - if (isContinue && !IHandlerUtilities.isFunctionExecutable(false, params)) { - return false; - } - return isContinue; - } - - /** - * Execute for no parameters. - * - * @param executeSQLObjectWindowCoreEdit the execute SQL object window core - * edit - * @param params the params - * @return true, if successful - */ - private boolean executeForNoParameters(ExcuteSQLObjectTable executeSQLObjectWindowCoreEdit, - ArrayList params) { - if (params == null || params.size() == 0) { - executeSQLObjectWindowCoreEdit.executePressed(); - return false; - } - return true; - } - - /** - * Validate olap functions. - * - * @param debugObject the debug object - * @return true, if successful - */ - private boolean validateOlapFunctions(IDebugObject debugObject) { - return debugObject.getObjectType() == OBJECTTYPE.PLSQLFUNCTION - || debugObject.getObjectType() == OBJECTTYPE.PROCEDURE - || debugObject.getObjectType() == OBJECTTYPE.SQLFUNCTION - || debugObject.getObjectType() == OBJECTTYPE.CFUNCTION; - } - - /** - * Can execute. - * - * @return true, if successful - */ - @CanExecute - public boolean canExecute() { - IDebugObject object = IHandlerUtilities.getSelectedDebugObject(); - boolean isObjectBrowserActive = UIElement.getInstance().isObjectBrowserActive(); - - if (validatePlEditorExists(object)) { - return false; - } - - object = getDebugObject(object, isObjectBrowserActive); - - PLSourceEditor editor = UIElement.getInstance().getVisibleSourceViewer(); - - if (getDbConnected(object)) { - return validateOperationInProgress(editor); - } - return false; - - } - - /** - * Validate pl editor exists. - * - * @param object the object - * @return true, if successful - */ - private boolean validatePlEditorExists(IDebugObject object) { - return object == null && null == UIElement.getInstance().getVisibleSourceViewer(); - } - - /** - * Gets the db connected. - * - * @param object the object - * @return the db connected - */ - private boolean getDbConnected(IDebugObject object) { - return object != null && object.getDatabase().isConnected(); - } - - /** - * Validate operation in progress. - * - * @param editor the editor - * @return true, if successful - */ - private boolean validateOperationInProgress(PLSourceEditor editor) { - if (validateExecutionInProgress(editor)) { - return false; - } - return true; - } - - /** - * Validate execution in progress. - * - * @param editor the editor - * @return true, if successful - */ - private boolean validateExecutionInProgress(PLSourceEditor editor) { - return editor != null && (editor.isCompileInProgress() || editor.isExecuteInProgress()); - } - - /** - * Gets the debug object. - * - * @param object the object - * @param isObjectBrowserActive the is object browser active - * @return the debug object - */ - private IDebugObject getDebugObject(IDebugObject object, boolean isObjectBrowserActive) { - PLSourceEditor sourceViewerEditor = UIElement.getInstance().getVisibleSourceViewer(); - if (sourceViewerEditor != null && (object == null || !isObjectBrowserActive)) { - object = sourceViewerEditor.getDebugObject(); - } - return object; - } - - /** - * Handle exception. - * - * @param e the e - * @param event the event - */ - @Override - public void handleException(Throwable exception, ObjectChangeEvent event) { - MPPDBIDELoggerUtility.error(MessageConfigLoader.getProperty(IMessagesConstants.ERR_GUI_SOURCE_NOT_AVAILABLE), - exception); - ConsoleCoreWindow.getInstance() - .logWarning(MessageConfigLoader.getProperty(IMessagesConstants.ERR_GUI_SOURCE_NOT_AVAILABLE)); - String msg = MessageConfigLoader.getProperty(IMessagesConstants.FUNCT_CHANGE_EXECUTE_ERR) - + exception.getMessage(); - MPPDBIDEDialogs.generateOKMessageDialog(MESSAGEDIALOGTYPE.ERROR, true, - MessageConfigLoader.getProperty(IMessagesConstants.PL_SOURCE_VIEWER_ERROR), msg); - PLSourceEditor srcEditor = event.getEditor(); - srcEditor.setExecuteInProgress(false); - srcEditor.setCompileInProgress(false); - srcEditor.enabledisableTextWidget(true); - } + /** + * Executor + * + * @param application + * @param service + */ + @Inject + private ECommandService commandService; + + @Inject + private EHandlerService handlerService; + + private QueryInfo queryInfo = new QueryInfo(); + + private static final String ERROR_POSITION_IDENTIFIER = "Position:"; + + private volatile boolean isPldebugger = true; + + /** + * Execute. + */ + @Execute + public void execute() { + + MPPDBIDELoggerUtility + .info(MessageConfigLoader.getProperty(IMessagesConstants.GUI_EXECUTEEDITORITEM_EXECUTE_CLICKED)); + PLSourceEditor editor = UIElement.getInstance().getVisibleSourceViewer(); + if (null == editor) { + Command command = commandService.getCommand("org.opengauss.mppdbide.command.id.executeobjectbrowseritem"); + ParameterizedCommand parameterizedCommand = ParameterizedCommand.generateCommand(command, null); + handlerService.executeHandler(parameterizedCommand); + return; + } + editor.setExecuteInProgress(true); + editor.enabledisableTextWidget(false); + DebugObjects debugObject = null; + if (editor.getDebugObject() instanceof DebugObjects) { + debugObject = (DebugObjects)editor.getDebugObject(); + } + checkVersion(editor); + if (!isPldebugger) { + debugObject.setUsagehint(MessageConfigLoader.getProperty(IMessagesConstants.COVERAGE_HINT)); + } + ObjectChangeWorker objWorker = new ObjectChangeWorker("Function Change Worker", + null, debugObject, editor, this, IMessagesConstants.FUNCTN_CHANGE_MSG, + IMessagesConstants.FUNCTN_CHANGE_OVERWRITE); + objWorker.schedule(); + } + + /** + * Handle execute. + * + * @param event the event + */ + @Override + public void handleExecute(ObjectChangeEvent event) { + PLSourceEditor editor = event.getEditor(); + IDebugObject debugObject = event.getDbgObj(); + Database db = debugObject.getDatabase(); + boolean iscontinue = true; + + if (validateForRefreshStatus(event)) { + iscontinue = refreshDebugObjectOnTerminal(editor, debugObject, db); + } else { + boolean codeChanged = editor.isCodeChanged(); + int returnVal = displayIfCodeChanged(codeChanged); + + boolean debugObjChanged = true; + debugObjChanged = getDebugObjectChanged(debugObject, debugObjChanged); + + iscontinue = executeIfCodeNotChanged(editor, debugObject, db, codeChanged, returnVal, debugObjChanged); + + iscontinue = executeIfCodeIsChanged(editor, iscontinue, codeChanged, returnVal, debugObjChanged); + } + if (iscontinue) { + editor.enabledisableTextWidget(true); + editor.setCompileInProgress(false); + editor.setExecuteInProgress(false); + executeSQLObjWindow(debugObject, false); + } + } + + private void checkVersion(PLSourceEditor editor) { + IConnection conn = null; + try { + conn = new DBConnectionProvider(editor.getDebugObject().getDatabase()).getValidFreeConnection(); + isPldebugger = VersionHelper.getDebuggerVersion(conn).isPldebugger(); + } catch(SQLException e) { + MPPDBIDELoggerUtility.error(e.getMessage()); + } finally { + if (null != conn) { + try { + conn.close(); + } catch (SQLException e) { + MPPDBIDELoggerUtility.error(e.getMessage()); + } + } + } + } + + /** + * Execute if code is changed. + * + * @param editor the editor + * @param iscontinue the iscontinue + * @param codeChanged the code changed + * @param returnVal the return val + * @param debugObjChanged the debug obj changed + * @return true, if successful + */ + private boolean executeIfCodeIsChanged(PLSourceEditor editor, boolean iscontinue, boolean codeChanged, + int returnVal, boolean debugObjChanged) { + iscontinue = refreshOnDebugObjChange(editor, iscontinue, codeChanged, returnVal, debugObjChanged); + if (iscontinue && codeChanged && (returnVal != 0)) { + editor.enabledisableTextWidget(true); + editor.setCompileInProgress(false); + editor.setExecuteInProgress(false); + return false; + } + return iscontinue; + } + + /** + * Refresh on debug obj change. + * + * @param editor the editor + * @param iscontinue the iscontinue + * @param codeChanged the code changed + * @param returnVal the return val + * @param debugObjChanged the debug obj changed + * @return true, if successful + */ + private boolean refreshOnDebugObjChange(PLSourceEditor editor, boolean iscontinue, boolean codeChanged, + int returnVal, boolean debugObjChanged) { + if (iscontinue && codeChanged && (returnVal == 0)) { + refreshDebugObjectOnChanged(editor, debugObjChanged); + editor.setCompileInProgress(false); + editor.setExecuteInProgress(false); + editor.enabledisableTextWidget(true); + editor.getConsoleMessageWindow(true) + .logInfo(MessageConfigLoader.getProperty(IMessagesConstants.STATUS_MSG_STATUS)); + iscontinue = executeIfDebugObjectIsNotChanged(editor, debugObjChanged); + } + return iscontinue; + } + + /** + * Execute if debug object is not changed. + * + * @param editor the editor + * @param debugObjChanged the debug obj changed + * @return true, if successful + */ + private boolean executeIfDebugObjectIsNotChanged(PLSourceEditor editor, boolean debugObjChanged) { + if (!debugObjChanged) { + + // source code changed, but the debug object didnt change as new + // debug object compiled open the new function in a new tab + + IExecutionContext context = generateContext(Display.getDefault().getActiveShell(), editor); + TerminalQueryExecutionWorker worker = new TerminalQueryExecutionWorker(context) { + + private boolean isExecuted = false; + + /** + * Final cleanup. + * + * @throws MPPDBIDEException the MPPDBIDE exception + */ + public void finalCleanup() throws MPPDBIDEException { + super.finalCleanup(); + if (this.context instanceof FuncProcEditorTerminalExecutionContext) { + FuncProcEditorTerminalExecutionContext funcContext = (FuncProcEditorTerminalExecutionContext) this.context; + IResultDisplayUIManager canExecute = funcContext.getResultDisplayUIManager(); + if (CanContextContinueExecuteRule.CONTEXT_EXECUTION_PROCEED == canExecute + .canContextExecutionContinue() && !isExecuted) { + Display.getDefault().syncExec(new Runnable() { + @Override + public void run() { + PLSourceEditor editor1 = UIElement.getInstance() + .getEditorModelById(funcContext.getDebugObject()); + if (editor1 != null) { + editor1.enabledisableTextWidget(true); + editor1.setCompileInProgress(false); + editor1.setExecuteInProgress(false); + executeSQLObjWindow(editor1.getDebugObject(), false); + } + } + }); + + isExecuted = true; + } + + } + + } + }; + worker.setTaskDB(context.getTermConnection().getDatabase()); + worker.schedule(); + return false; + } + return true; + } + + /** + * Refresh debug object on changed. + * + * @param editor the editor + * @param debugObjChanged the debug obj changed + */ + private void refreshDebugObjectOnChanged(PLSourceEditor editor, boolean debugObjChanged) { + if (debugObjChanged) { + editor.refreshDebugObjectAfterEdit(editor.getDebugObject()); + } + } + + /** + * Execute if code not changed. + * + * @param editor the editor + * @param debugObject the debug object + * @param db the db + * @param codeChanged the code changed + * @param returnVal the return val + * @param debugObjChanged the debug obj changed + * @return true, if successful + */ + private boolean executeIfCodeNotChanged(PLSourceEditor editor, IDebugObject debugObject, Database db, + boolean codeChanged, int returnVal, boolean debugObjChanged) { + if (validateIfCodeChanged(codeChanged, returnVal) && debugObjChanged) { + return executeOnCodeChange(editor, debugObject, db); + } + return true; + } + + /** + * Execute on code change. + * + * @param editor the editor + * @param debugObject the debug object + * @param db the db + * @return true, if successful + */ + private boolean executeOnCodeChange(PLSourceEditor editor, IDebugObject debugObject, Database db) { + try { + executeOnTerminal(editor, debugObject, db); + editor.enabledisableTextWidget(true); + } catch (DatabaseOperationException exception) { + MPPDBIDELoggerUtility.error("error while execute debug obj.", exception); + editor.enabledisableTextWidget(true); + return false; + } + return true; + } + + /** + * Validate if code changed. + * + * @param codeChanged the code changed + * @param returnVal the return val + * @return true, if successful + */ + private boolean validateIfCodeChanged(boolean codeChanged, int returnVal) { + return (!codeChanged) || (returnVal == 0); + } + + /** + * Display if code changed. + * + * @param codeChanged the code changed + * @return the int + */ + private int displayIfCodeChanged(boolean codeChanged) { + int returnVal = -1; + if (codeChanged) { + returnVal = MPPDBIDEDialogs.generateYesNoMessageDialog(MESSAGEDIALOGTYPE.QUESTION, true, + MessageConfigLoader.getProperty(IMessagesConstants.SOURCE_CODE_CHANGE), + MessageConfigLoader.getProperty(IMessagesConstants.SOURCE_HAS_BEEN_CHANGED)); + } + return returnVal; + } + + /** + * Gets the debug object changed. + * + * @param debugObject the debug object + * @param debugObjChanged the debug obj changed + * @return the debug object changed + */ + private boolean getDebugObjectChanged(IDebugObject debugObject, boolean debugObjChanged) { + try { + debugObjChanged = debugObject.isChanged(debugObject.getLatestInfo()); + } catch (DatabaseCriticalException exception) { + MPPDBIDELoggerUtility.error("error while comparing debug obj info with server", exception); + } catch (DatabaseOperationException exception) { + MPPDBIDELoggerUtility.error("error while comparing debug obj info with server", exception); + } + return debugObjChanged; + } + + /** + * Refresh debug object on terminal. + * + * @param editor the editor + * @param debugObject the debug object + * @param db the db + * @return true, if successful + */ + private boolean refreshDebugObjectOnTerminal(PLSourceEditor editor, IDebugObject debugObject, Database db) { + editor.setDocument(new Document(debugObject.getSourceCode().getCode())); + editor.registerModifyListener(); + try { + executeOnTerminal(editor, debugObject, db); + } catch (DatabaseOperationException exception) { + MPPDBIDELoggerUtility.error("error while execute debug obj.", exception); + editor.enabledisableTextWidget(true); + return false; + } + return true; + } + + /** + * Validate for refresh status. + * + * @param event the event + * @return true, if successful + */ + private boolean validateForRefreshStatus(ObjectChangeEvent event) { + return event.getStatus() != null && event.getStatus().equals(ButtonPressed.REFRESH); + } + + /** + * Generate context. + * + * @param shell the shell + * @param editor the editor + * @return the i execution context + */ + private IExecutionContext generateContext(Shell shell, PLSourceEditor editor) { + ExecuteSourceEditor executeSourceEditor = null; + executeSourceEditor = new ExecuteSourceEditor(shell, editor); + + return executeSourceEditor.getContextForNewEditor(); + + } + + /** + * Execute on terminal. + * + * @param editor the editor + * @param debugObject the debug object + * @param db the db + * @throws DatabaseOperationException the database operation exception + */ + private void executeOnTerminal(PLSourceEditor editor, IDebugObject debugObject, Database db) + throws DatabaseOperationException { + String query = editor.getDocument(); + DBConnection conn = null; + + try { + conn = executeOnTerminal(editor, debugObject, query); + } catch (DatabaseOperationException exception) { + editor.setExecuteInProgress(false); + String message = ""; + message = getServerMessageDetails(editor, query, exception); + message = getErrorMessage(message, exception); + editor.getConsoleMessageWindow(true).logErrorInUI(message); + MPPDBIDELoggerUtility.error("ExecuteEditorItem: execute on terminal failed.", exception); + throw new DatabaseOperationException("error occured."); + } catch (DatabaseCriticalException e) { + UIDisplayFactoryProvider.getUIDisplayStateIf().handleDBCriticalError(e, db); + return; + } finally { + releaseConnection(db, conn); + } + + } + + /** + * Execute on terminal. + * + * @param editor the editor + * @param debugObject the debug object + * @param query the query + * @return the DB connection + * @throws DatabaseCriticalException the database critical exception + * @throws DatabaseOperationException the database operation exception + */ + private DBConnection executeOnTerminal(PLSourceEditor editor, IDebugObject debugObject, String query) + throws DatabaseCriticalException, DatabaseOperationException { + DBConnection conn = null; + if (query.trim().isEmpty()) { + MPPDBIDEDialogs.generateOKMessageDialog(MESSAGEDIALOGTYPE.ERROR, true, + MessageConfigLoader.getProperty(IMessagesConstants.EMPTY_PLSOURCE_TITEL), + MessageConfigLoader.getProperty(IMessagesConstants.EMPTY_PLSOURCE_VIEWER)); + return conn; + } + + conn = debugObject.getDatabase().getConnectionManager().getObjBrowserConn(); + DatabaseUtils.executeOnSqlTerminalAndReturnNothing(query, 0, conn, editor.getConsoleMsgQueue(false)); + editor.setCriticalErr(true); + editor.refreshDebugObjectAfterEdit(debugObject); + editor.setModified(false); + editor.setModifiedAfterCreate(false); + editor.setExecuteInProgress(false); + return conn; + } + + /** + * Release connection. + * + * @param db the db + * @param conn the conn + */ + private void releaseConnection(Database db, DBConnection conn) { + if (conn != null) { + db.getConnectionManager().releaseAndDisconnection(conn); + } + } + + /** + * Gets the error message. + * + * @param message the message + * @param e the e + * @return the error message + */ + private String getErrorMessage(String message, DatabaseOperationException e) { + if (message.isEmpty()) { + message = MessageConfigLoader.getProperty(IMessagesConstants.EXECUTION_FAILED_ITEM, + MPPDBIDEConstants.LINE_SEPARATOR, e.getErrorCode(), + e.getServerMessage() == null ? e.getDBErrorMessage() : e.getServerMessage()); + } + return message; + } + + /** + * Gets the server message details. + * + * @param editor the editor + * @param query the query + * @param e the e + * @return the server message details + */ + private String getServerMessageDetails(PLSourceEditor editor, String query, DatabaseOperationException e) { + String message = ""; + if (validateServerMessage(e)) { + try { + getErrorDetailsForLocator(editor, query, e); + } catch (BadLocationException exception) { + MPPDBIDELoggerUtility.error("ExecuteEditorItem: execute on terminal failed.", exception); + } + + message = MessageConfigLoader.getProperty(IMessagesConstants.EXECUTION_FAILED_ITEM, + MPPDBIDEConstants.LINE_SEPARATOR, e.getErrorCode(), + (e.getServerMessage() == null ? e.getDBErrorMessage() : e.getServerMessage()) + + MPPDBIDEConstants.LINE_SEPARATOR + " Line Number: " + queryInfo.getErrLineNo()); + } + return message; + } + + /** + * Validate server message. + * + * @param e the e + * @return true, if successful + */ + private boolean validateServerMessage(DatabaseOperationException e) { + return e.getServerMessage() != null && e.getServerMessage().contains(ERROR_POSITION_IDENTIFIER); + } + + /** + * Gets the error details for locator. + * + * @param editor the editor + * @param query the query + * @param e the e + * @return the error details for locator + * @throws BadLocationException the bad location exception + */ + private void getErrorDetailsForLocator(PLSourceEditor editor, String query, DatabaseOperationException e) + throws BadLocationException { + Database database = editor.getDatabase(); + + if (database != null) { + IErrorLocator errorLocator = database.getErrorLocator(); + String msg = e.getServerMessage(); + int errorPos = -1; + errorPos = getErrorPOsition(msg, errorPos); + + errorPos = getErrorPositionForGreaterThanSize(query, errorPos); + queryInfo.setErrorPosition(errorPos); + int errLineNo = editor.getsourceViewerLineOfOffset(getErrorLineNumber(errorLocator)); + queryInfo.setErrLineNo(errLineNo + 1); + } + } + + /** + * Gets the error line number. + * + * @param errorLocator the error locator + * @return the error line number + */ + private int getErrorLineNumber(IErrorLocator errorLocator) { + return errorLocator.errorLineNumber(queryInfo.getStartOffset(), queryInfo.getErrorPosition()); + } + + /** + * Gets the error P osition. + * + * @param msg the msg + * @param errorPos the error pos + * @return the error P osition + */ + private int getErrorPOsition(String msg, int errorPos) { + if (null != msg) { + + int idx = msg.lastIndexOf(ERROR_POSITION_IDENTIFIER); + String newStr; + newStr = getErrorPositionString(msg, idx); + + newStr = getStringForNewLine(newStr); + errorPos = convertErrorPositionToInt(errorPos, newStr); + } + + else { + errorPos++; + } + return errorPos; + } + + /** + * Gets the error position for greater than size. + * + * @param query the query + * @param errorPos the error pos + * @return the error position for greater than size + */ + private int getErrorPositionForGreaterThanSize(String query, int errorPos) { + if (errorPos > query.length()) { + errorPos = query.length(); + } + return errorPos; + } + + /** + * Convert error position to int. + * + * @param errorPos the error pos + * @param newStr the new str + * @return the int + */ + private int convertErrorPositionToInt(int errorPos, String newStr) { + try { + errorPos = Integer.parseInt(newStr.trim()); + } catch (NumberFormatException ex) { + errorPos++; + } + return errorPos; + } + + /** + * Gets the error position string. + * + * @param msg the msg + * @param idx the idx + * @return the error position string + */ + private String getErrorPositionString(String msg, int idx) { + String newStr; + if (idx != -1) { + newStr = msg.substring(idx + ERROR_POSITION_IDENTIFIER.length() + 1); + } else { + newStr = msg.substring(ERROR_POSITION_IDENTIFIER.length() + 1); + } + return newStr; + } + + /** + * Gets the string for new line. + * + * @param newStr the new str + * @return the string for new line + */ + private String getStringForNewLine(String newStr) { + if (newStr.contains(MPPDBIDEConstants.LINE_SEPARATOR)) { + newStr = newStr.substring(0, newStr.indexOf(MPPDBIDEConstants.LINE_SEPARATOR)); + } + return newStr; + } + + /** + * Execute SQL obj window. + * + * @param debugObject the debug object + */ + public void executeSQLObjWindow(IDebugObject debugObject, boolean isCurrentTerminal) { + ExcuteSQLObjectTable executeSQLObjectWindowCoreEdit = new ExcuteSQLObjectTable( + Display.getDefault().getActiveShell()); + executeSQLObjectWindowCoreEdit.setSyntax(getSqlSyntax(debugObject)); + try { + executeSQLObjectWindowCoreEdit.setDebugObject(debugObject); + } catch (DatabaseCriticalException exception) { + UIDisplayFactoryProvider.getUIDisplayStateIf().handleDBCriticalError(exception, debugObject.getDatabase()); + return; + } catch (MPPDBIDEException exception) { + handleMppDbIdeException(exception); + return; + } catch (Exception exception) { + MPPDBIDELoggerUtility.error( + MessageConfigLoader.getProperty(IMessagesConstants.ERR_WHILE_STARTING_TO_EXECUTE_SQL_OBJECT), + exception); + MPPDBIDEDialogs.generateErrorDialog(MessageConfigLoader.getProperty(IMessagesConstants.PLSQL_ERR), + MessageConfigLoader.getProperty(IMessagesConstants.UNKNOWN_INTERNAL_ERR), exception); + } + executeSQLObjectWindowCoreEdit.defaultParameterValues(); + debugObject.setIsCurrentTerminal(isCurrentTerminal); + + openParameterWindow(debugObject, executeSQLObjectWindowCoreEdit); + } + + private void handleMppDbIdeException(MPPDBIDEException exception) { + UIDisplayUtil.getDebugConsole().logError(MessageConfigLoader + .getProperty(IMessagesConstants.OPERATION_CANNOT_BE_PERFOREMD, exception.getMessage())); + MPPDBIDEDialogs.generateDSErrorDialog(MessageConfigLoader.getProperty(IMessagesConstants.EXECUTE_DEBUGE), + MessageConfigLoader.getProperty(IMessagesConstants.OPERATION_CANNOT_BE_PERFOREMD_TITLE), + MessageConfigLoader.getProperty(IMessagesConstants.OPERATION_CANNOT_BE_PERFOREMD, + exception.getServerMessage()), + exception); + } + + /** + * Open parameter window. + * + * @param debugObject the debug object + * @param executeSQLObjectWindowCoreEdit the execute SQL object window core + * edit + */ + private void openParameterWindow(IDebugObject debugObject, ExcuteSQLObjectTable executeSQLObjectWindowCoreEdit) { + if (executeFunctionProcedure(debugObject, executeSQLObjectWindowCoreEdit)) { + + executeSQLObjectWindowCoreEdit.open(); + } + } + + /** + * Gets the sql syntax. + * + * @param debugObject the debug object + * @return the sql syntax + */ + private SQLSyntax getSqlSyntax(IDebugObject debugObject) { + return debugObject.getDatabase() == null ? null : debugObject.getDatabase().getSqlSyntax(); + } + + /** + * Execute function procedure. + * + * @param debugObject the debug object + * @param executeSQLObjectWindowCoreEdit the execute SQL object window core + * edit + * @return true, if successful + */ + private boolean executeFunctionProcedure(IDebugObject debugObject, + ExcuteSQLObjectTable executeSQLObjectWindowCoreEdit) { + boolean isContinue = true; + if (validateOlapFunctions(debugObject)) { + ArrayList params = debugObject.getTemplateParameters(); + + isContinue = executeForNoParameters(executeSQLObjectWindowCoreEdit, params); + + isContinue = validateExecutableFunction(isContinue, params); + } + return isContinue; + } + + /** + * Validate executable function. + * + * @param isContinue the is continue + * @param params the params + * @return true, if successful + */ + private boolean validateExecutableFunction(boolean isContinue, ArrayList params) { + if (isContinue && !IHandlerUtilities.isFunctionExecutable(false, params)) { + return false; + } + return isContinue; + } + + /** + * Execute for no parameters. + * + * @param executeSQLObjectWindowCoreEdit the execute SQL object window core + * edit + * @param params the params + * @return true, if successful + */ + private boolean executeForNoParameters(ExcuteSQLObjectTable executeSQLObjectWindowCoreEdit, + ArrayList params) { + if (params == null || params.size() == 0) { + executeSQLObjectWindowCoreEdit.executePressed(); + return false; + } + return true; + } + + /** + * Validate olap functions. + * + * @param debugObject the debug object + * @return true, if successful + */ + private boolean validateOlapFunctions(IDebugObject debugObject) { + return debugObject.getObjectType() == OBJECTTYPE.PLSQLFUNCTION + || debugObject.getObjectType() == OBJECTTYPE.PROCEDURE + || debugObject.getObjectType() == OBJECTTYPE.SQLFUNCTION + || debugObject.getObjectType() == OBJECTTYPE.CFUNCTION; + } + + /** + * Can execute. + * + * @return true, if successful + */ + @CanExecute + public boolean canExecute() { + IDebugObject object = IHandlerUtilities.getSelectedDebugObject(); + boolean isObjectBrowserActive = UIElement.getInstance().isObjectBrowserActive(); + + if (validatePlEditorExists(object)) { + return false; + } + + object = getDebugObject(object, isObjectBrowserActive); + + PLSourceEditor editor = UIElement.getInstance().getVisibleSourceViewer(); + + if (getDbConnected(object)) { + return validateOperationInProgress(editor); + } + return false; + + } + + /** + * Validate pl editor exists. + * + * @param object the object + * @return true, if successful + */ + private boolean validatePlEditorExists(IDebugObject object) { + return object == null && null == UIElement.getInstance().getVisibleSourceViewer(); + } + + /** + * Gets the db connected. + * + * @param object the object + * @return the db connected + */ + private boolean getDbConnected(IDebugObject object) { + return object != null && object.getDatabase().isConnected(); + } + + /** + * Validate operation in progress. + * + * @param editor the editor + * @return true, if successful + */ + private boolean validateOperationInProgress(PLSourceEditor editor) { + if (validateExecutionInProgress(editor)) { + return false; + } + return true; + } + + /** + * Validate execution in progress. + * + * @param editor the editor + * @return true, if successful + */ + private boolean validateExecutionInProgress(PLSourceEditor editor) { + return editor != null && (editor.isCompileInProgress() || editor.isExecuteInProgress()); + } + + /** + * Gets the debug object. + * + * @param object the object + * @param isObjectBrowserActive the is object browser active + * @return the debug object + */ + private IDebugObject getDebugObject(IDebugObject object, boolean isObjectBrowserActive) { + PLSourceEditor sourceViewerEditor = UIElement.getInstance().getVisibleSourceViewer(); + if (sourceViewerEditor != null && (object == null || !isObjectBrowserActive)) { + object = sourceViewerEditor.getDebugObject(); + } + return object; + } + + /** + * Handle exception. + * + * @param e the e + * @param event the event + */ + @Override + public void handleException(Throwable exception, ObjectChangeEvent event) { + MPPDBIDELoggerUtility.error(MessageConfigLoader.getProperty(IMessagesConstants.ERR_GUI_SOURCE_NOT_AVAILABLE), + exception); + ConsoleCoreWindow.getInstance() + .logWarning(MessageConfigLoader.getProperty(IMessagesConstants.ERR_GUI_SOURCE_NOT_AVAILABLE)); + String msg = MessageConfigLoader.getProperty(IMessagesConstants.FUNCT_CHANGE_EXECUTE_ERR) + + exception.getMessage(); + MPPDBIDEDialogs.generateOKMessageDialog(MESSAGEDIALOGTYPE.ERROR, true, + MessageConfigLoader.getProperty(IMessagesConstants.PL_SOURCE_VIEWER_ERROR), msg); + PLSourceEditor srcEditor = event.getEditor(); + srcEditor.setExecuteInProgress(false); + srcEditor.setCompileInProgress(false); + srcEditor.enabledisableTextWidget(true); + } } diff --git a/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/handler/ViewSourceDebugObjectHandler.java b/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/handler/ViewSourceDebugObjectHandler.java index 7c1452899022c49e22a8efa8fb699c717eae7aff..b6b932908f4c3071b6c2f9698a9704999fad5917 100644 --- a/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/handler/ViewSourceDebugObjectHandler.java +++ b/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/handler/ViewSourceDebugObjectHandler.java @@ -19,6 +19,7 @@ import org.eclipse.e4.core.di.annotations.Execute; import org.opengauss.mppdbide.bl.serverdatacache.IDebugObject; import org.opengauss.mppdbide.bl.serverdatacache.ObjectChange; +import org.opengauss.mppdbide.utils.DebuggerStartConstants; import org.opengauss.mppdbide.utils.IMessagesConstants; import org.opengauss.mppdbide.utils.exceptions.DatabaseCriticalException; import org.opengauss.mppdbide.utils.exceptions.DatabaseOperationException; @@ -54,6 +55,10 @@ public class ViewSourceDebugObjectHandler implements ExecuteWrapper { PLSourceEditor editorObject = null; Object partObject = UIElement.getInstance().getActivePartObject(); IDebugObject debugObject = IHandlerUtilities.getSelectedDebugObject(); + if (null != debugObject) { + Long oid= debugObject.getOid(); + DebuggerStartConstants.getStartInfo(oid).remarLinesStr=""; + } if (debugObject != null) { if (!(UIElement.getInstance().isEditorExistByDbgObj(debugObject))) { try { diff --git a/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/handler/debug/ContinueDebugHandler.java b/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/handler/debug/ContinueDebugHandler.java index 64768372e27d95c7a4ddda59448b65ecb3d3ec81..9204248e4d53e192f167bbe315ab7c2caf2e5a2e 100644 --- a/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/handler/debug/ContinueDebugHandler.java +++ b/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/handler/debug/ContinueDebugHandler.java @@ -23,6 +23,7 @@ import org.eclipse.e4.core.di.annotations.Execute; import org.opengauss.mppdbide.debuger.exception.DebugExitException; import org.opengauss.mppdbide.debuger.vo.PositionVo; +import org.opengauss.mppdbide.utils.ConstantRunLine; /** * Title: class @@ -53,6 +54,7 @@ public class ContinueDebugHandler extends BaseDebugStepHandler { @Override public Optional debugRun() throws SQLException, DebugExitException { + ConstantRunLine.isContinue = true; return getDebugService().continueExec(); } } diff --git a/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/handler/debug/DebugHandlerUtils.java b/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/handler/debug/DebugHandlerUtils.java index 9c8d0ec75ac1f1296e6a14afde51bec5882337eb..d2d39b682d040bc04c55ead1ba8f54d841d3b306 100644 --- a/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/handler/debug/DebugHandlerUtils.java +++ b/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/handler/debug/DebugHandlerUtils.java @@ -20,10 +20,11 @@ import org.eclipse.core.commands.ParameterizedCommand; import org.eclipse.e4.core.commands.ECommandService; import org.eclipse.e4.core.commands.EHandlerService; import org.eclipse.e4.ui.model.application.ui.MUIElement; - import org.opengauss.mppdbide.bl.serverdatacache.IDebugObject; import org.opengauss.mppdbide.eclipse.dependent.EclipseInjections; +import org.opengauss.mppdbide.utils.ConstantRunLine; import org.opengauss.mppdbide.view.handler.IHandlerUtilities; +import org.opengauss.mppdbide.view.handler.debug.ui.UpdateDebugPositionTask; import org.opengauss.mppdbide.view.prefernces.PreferenceWrapper; import org.opengauss.mppdbide.view.ui.PLSourceEditor; import org.opengauss.mppdbide.view.utils.UIElement; @@ -93,6 +94,11 @@ public class DebugHandlerUtils { public void setDebugStart(boolean isDebugStart) { this.isDebugStart = isDebugStart; } + + public void terminateDebug() { + ConstantRunLine.isTerminate = false; + UpdateDebugPositionTask.terminateDebug(); + } /** * description: this use to show debug view partstack diff --git a/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/handler/debug/DebugHistoryCoverageHandler.java b/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/handler/debug/DebugHistoryCoverageHandler.java new file mode 100644 index 0000000000000000000000000000000000000000..235a1844ca80ecb390cd3ffb87bf573fd48f7f88 --- /dev/null +++ b/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/handler/debug/DebugHistoryCoverageHandler.java @@ -0,0 +1,90 @@ +package org.opengauss.mppdbide.view.handler.debug; + +import java.sql.SQLException; + +import org.eclipse.e4.core.di.annotations.CanExecute; +import org.eclipse.e4.core.di.annotations.Execute; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; +import org.opengauss.mppdbide.bl.serverdatacache.Server; +import org.opengauss.mppdbide.common.IConnection; +import org.opengauss.mppdbide.common.VersionHelper; +import org.opengauss.mppdbide.utils.IMessagesConstants; +import org.opengauss.mppdbide.utils.loader.MessageConfigLoader; +import org.opengauss.mppdbide.utils.logger.MPPDBIDELoggerUtility; +import org.opengauss.mppdbide.view.ui.CoverageHistory; +import org.opengauss.mppdbide.view.ui.PLSourceEditor; +import org.opengauss.mppdbide.view.utils.UIElement; +import org.opengauss.mppdbide.view.utils.dialog.MPPDBIDEDialogs; +import org.opengauss.mppdbide.view.utils.dialog.MPPDBIDEDialogs.MESSAGEDIALOGTYPE; + +public class DebugHistoryCoverageHandler { + private DebugHandlerUtils debugUtils = DebugHandlerUtils.getInstance(); + private DebugServiceHelper serviceHelper = DebugServiceHelper.getInstance(); + private PLSourceEditor plSourceEditor; + + /** + * description: can execute + * + * @return boolean true if can + */ + @CanExecute + public boolean canExecute() { + return debugUtils.canStartDebug(); + } + + /** + * description: excute the command + * + * @return void + */ + @Execute + public void execute() { + plSourceEditor = UIElement.getInstance().getVisibleSourceViewer(); + IConnection conn = null; + try { + conn = new DBConnectionProvider(plSourceEditor.getDebugObject().getDatabase()).getValidFreeConnection(); + boolean isPldebugger= VersionHelper.getDebuggerVersion(conn).isPldebugger(); + conn.close(); + if (isPldebugger) { + MPPDBIDEDialogs.generateOKMessageDialog(MESSAGEDIALOGTYPE.INFORMATION, true, + MessageConfigLoader.getProperty(IMessagesConstants.EXECDIALOG_HINT), + MessageConfigLoader.getProperty(IMessagesConstants.COVERAGE_CHECK)); + return; + } + } catch (SQLException e) { + MPPDBIDELoggerUtility.error(e.getMessage()); + } finally { + try { + if (null != conn) { + conn.close(); + } + } catch (SQLException e) { + MPPDBIDELoggerUtility.error(e.getMessage()); + } + } + MPPDBIDELoggerUtility.error("start debugint:" + "null"); + debugUtils.initDebugSourceView(); + Shell shell = Display.getDefault().getActiveShell(); + Server server = plSourceEditor.getDatabase().getServer(); + CoverageHistory coverageHistory=new CoverageHistory(shell,server.getServerConnectionInfo().getConectionName(), + server.getServerConnectionInfo().getProfileId()); + coverageHistory.open(); + + } + + + private void showMsg(String msg) { + Display.getDefault().asyncExec(new Runnable() { + @Override + public void run() { + MPPDBIDEDialogs.generateOKMessageDialog( + MESSAGEDIALOGTYPE.WARNING, + true, + "get debug history coverage data warning", + msg); + } + }); + } + +} 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 aae740dc58d0023c19ffdf04c61fb810aeeb05ff..1a9e6a975ab1e0573202c91c158c25b47899066a 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 @@ -21,6 +21,7 @@ import java.util.Optional; import org.eclipse.jface.preference.PreferenceStore; import org.opengauss.mppdbide.bl.serverdatacache.IDebugObject; +import org.opengauss.mppdbide.common.IConnectionProvider; import org.opengauss.mppdbide.debuger.event.Event; import org.opengauss.mppdbide.debuger.event.IHandlerManger; import org.opengauss.mppdbide.debuger.event.Event.EventMessage; @@ -29,12 +30,15 @@ import org.opengauss.mppdbide.debuger.service.ServiceFactory; import org.opengauss.mppdbide.debuger.service.SourceCodeService; 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.IMessagesConstants; import org.opengauss.mppdbide.utils.MPPDBIDEConstants; import org.opengauss.mppdbide.utils.loader.MessageConfigLoader; import org.opengauss.mppdbide.view.core.sourceeditor.BreakpointAnnotation; import org.opengauss.mppdbide.view.prefernces.PreferenceWrapper; +import org.opengauss.mppdbide.view.service.CoverageServiceFactory; +import org.opengauss.mppdbide.view.vo.CoverageService; /** * Title: class @@ -46,10 +50,13 @@ public class DebugServiceHelper { private static DebugServiceHelper debugServiceHelper = new DebugServiceHelper(); private IDebugObject debugObject = null; private ServiceFactory serviceFactory = null; + private CoverageServiceFactory coverageServiceFactory = null; private WrappedDebugService debugService = null; + private DebuggerReportService debuggerReportService=null; private FunctionVo functionVo = null; private QueryService queryService = null; private SourceCodeService codeService = null; + private CoverageService coverageService = null; private DebugServiceHelper() { } @@ -75,21 +82,28 @@ public class DebugServiceHelper { return false; } if (!isCommonDatabase(debugObject)) { - serviceFactory = new ServiceFactory(new DBConnectionProvider(debugObject.getDatabase())); + IConnectionProvider provider=new DBConnectionProvider(debugObject.getDatabase()); + serviceFactory = new ServiceFactory(provider); + coverageServiceFactory = new CoverageServiceFactory(provider); checkSupportDebug(); queryService = serviceFactory.getQueryService(); functionVo = queryService.queryFunction(debugObject.getName()); + debuggerReportService=DebuggerReportService.getInstance(); + debuggerReportService.setAttr(provider, functionVo); debugService = new WrappedDebugService(serviceFactory.getDebugService(functionVo)); debugService.addHandler(new UiEventHandler()); debugService.addHandler(new DebugEventHandler()); codeService = serviceFactory.getCodeService(); + coverageService = coverageServiceFactory.getCoverageService(); Optional sourceCode = queryService.getSourceCode(functionVo.oid); if (sourceCode.isPresent()) { codeService.setBaseCode(sourceCode.get().getSourceCode()); + debuggerReportService.setBaseCode(codeService.getBaseCodeDesc()); } else { throw new SQLException("get source code failed!"); } codeService.setTotalCode(debugObject.getSourceCode().getCode()); + debuggerReportService.setTotalCode(codeService.getTotalCodeDesc()); this.debugObject = debugObject; } if (debugService != null) { @@ -143,6 +157,11 @@ public class DebugServiceHelper { public QueryService getQueryService() { return queryService; } + + public CoverageService getCoverageService() { + return coverageService; + } + /** * description: get code service 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 14ad5dcedd8205fbf1f346740dbea3370d6bc40a..556e82a3bbf6d1ac45c3864729c20d901aad5db9 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 @@ -17,8 +17,10 @@ package org.opengauss.mppdbide.view.handler.debug; import java.sql.SQLException; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; +import java.util.stream.Stream; import org.eclipse.e4.core.di.annotations.CanExecute; import org.eclipse.e4.core.di.annotations.Execute; @@ -29,6 +31,8 @@ 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.debug.DebugConstants; +import org.opengauss.mppdbide.debuger.service.DebugService; import org.opengauss.mppdbide.utils.IMessagesConstants; import org.opengauss.mppdbide.utils.exceptions.DatabaseCriticalException; import org.opengauss.mppdbide.utils.exceptions.DatabaseOperationException; @@ -88,6 +92,11 @@ 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()); + DebugService.map.put(oid, paramNames); } private void startInputParamDialog() { @@ -142,9 +151,27 @@ public class StartDebugHandler { .getDefaulParametertMap() .get(debugObject.getOid()); debugParams = getDebugParams(serverParams); + StringBuffer buffer=new StringBuffer("("); + int count=0; + for(DefaultParameter a:serverParams) { + if(count!=0) { + buffer.append(","); + } + buffer.append(a.getDefaultParameterName()); + buffer.append(":=?").append(""); + count++; + } + buffer.append(")"); + } + if (serviceHelper.getDebugService() != null) { + serviceHelper.getDebugService().begin(debugParams); + debugUtils.setDebugStart(true); + } else { + MPPDBIDEDialogs.generateOKMessageDialog(MESSAGEDIALOGTYPE.INFORMATION, true, + MessageConfigLoader.getProperty(IMessagesConstants.EXECDIALOG_HINT), + "please wait for server running!"); + return; } - serviceHelper.getDebugService().begin(debugParams); - debugUtils.setDebugStart(true); } catch (DatabaseCriticalException exception) { UIDisplayFactoryProvider.getUIDisplayStateIf().handleDBCriticalError(exception, debugObject.getDatabase()); return; @@ -157,6 +184,9 @@ public class StartDebugHandler { exception); MPPDBIDEDialogs.generateErrorDialog(MessageConfigLoader.getProperty(IMessagesConstants.PLSQL_ERR), MessageConfigLoader.getProperty(IMessagesConstants.UNKNOWN_INTERNAL_ERR), exception); + MPPDBIDEDialogs.generateOKMessageDialog(MESSAGEDIALOGTYPE.INFORMATION, true, + MessageConfigLoader.getProperty(IMessagesConstants.EXECDIALOG_HINT) + ,"please wait for server running!"); } } diff --git a/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/handler/debug/TerminateDebugHandler.java b/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/handler/debug/TerminateDebugHandler.java index 5308fc591c1ecafe839ec32317f486bb8327ac28..91be62a928562565b3033364ef3b2d58f01867ff 100644 --- a/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/handler/debug/TerminateDebugHandler.java +++ b/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/handler/debug/TerminateDebugHandler.java @@ -17,8 +17,9 @@ package org.opengauss.mppdbide.view.handler.debug; import org.eclipse.e4.core.di.annotations.CanExecute; import org.eclipse.e4.core.di.annotations.Execute; - +import org.opengauss.mppdbide.utils.DebuggerStartConstants; import org.opengauss.mppdbide.utils.logger.MPPDBIDELoggerUtility; +import org.opengauss.mppdbide.utils.vo.DebuggerStartInfoVo; import org.opengauss.mppdbide.view.ui.PLSourceEditor; import org.opengauss.mppdbide.view.utils.UIElement; @@ -53,11 +54,16 @@ public class TerminateDebugHandler { MPPDBIDELoggerUtility.error("terminate debugint:" + "null"); debugUtils.showAllDebugView(false); PLSourceEditor plSourceEditor = UIElement.getInstance().getVisibleSourceViewer(); + Long oid= plSourceEditor.getDebugObject().getOid(); + DebuggerStartInfoVo debuggerStartInfoVo=DebuggerStartConstants.getStartInfo(oid); + debuggerStartInfoVo.ifMakeReport=false; + DebuggerStartConstants.setStartInfo(oid, debuggerStartInfoVo); if (plSourceEditor != null) { plSourceEditor.setEditable(true); plSourceEditor.setExecuteInProgress(false); } debugUtils.setDebugStart(false); + debugUtils.terminateDebug(); serviceHelper.closeService(); } } 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 a77b0468a51f76e496749664a9ddb55220f22e6e..a2836e7b32fd0e5601dce36b272abfa0ff3e6c43 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 @@ -19,7 +19,9 @@ import org.eclipse.swt.widgets.Display; import org.opengauss.mppdbide.debuger.event.Event; import org.opengauss.mppdbide.debuger.event.Event.EventMessage; +import org.opengauss.mppdbide.debuger.service.DebuggerReportService; import org.opengauss.mppdbide.debuger.service.chain.IMsgChain; +import org.opengauss.mppdbide.utils.ConstantRunLine; import org.opengauss.mppdbide.utils.logger.MPPDBIDELoggerUtility; import org.opengauss.mppdbide.view.handler.debug.DebugHandlerUtils; import org.opengauss.mppdbide.view.handler.debug.DebugServiceHelper; @@ -37,6 +39,7 @@ public class ServerExitChain extends IMsgChain { private boolean isResultUpdated = false; private DebugHandlerUtils debugUtils = DebugHandlerUtils.getInstance(); private DebugServiceHelper serviceHelper = DebugServiceHelper.getInstance(); + public DebuggerReportService reportService = DebuggerReportService.getInstance(); @Override public boolean matchMsg(Event event) { @@ -52,6 +55,12 @@ public class ServerExitChain extends IMsgChain { } Display.getDefault().asyncExec(new UpdateDebugPositionTask(-1)); Display.getDefault().asyncExec(new UpdateHighlightLineNumTask()); + reportService.makeReport(); + if (null != ConstantRunLine.isContinue && ConstantRunLine.isContinue) { + Display.getDefault().asyncExec(()->{ + UpdateDebugPositionTask.continueDebug(); + }); + } if (!isResultUpdated) { isResultUpdated = true; Display.getDefault().asyncExec(new UpdateDebugResultTask(event)); diff --git a/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/handler/debug/ui/UpdateDebugPositionTask.java b/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/handler/debug/ui/UpdateDebugPositionTask.java index 16dd684bd01bfddc1ff1e5e79133a2d07db08ecb..a85867d92f09d47a1d2c0a5fead5a0fa8c913c21 100644 --- a/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/handler/debug/ui/UpdateDebugPositionTask.java +++ b/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/handler/debug/ui/UpdateDebugPositionTask.java @@ -1,4 +1,4 @@ -/* +/* * Copyright (c) 2022 Huawei Technologies Co.,Ltd. * * openGauss is licensed under Mulan PSL v2. @@ -6,7 +6,7 @@ * You may obtain a copy of Mulan PSL v2 at: * * http://license.coscl.org.cn/MulanPSL2 - * + * * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. @@ -15,9 +15,22 @@ package org.opengauss.mppdbide.view.handler.debug.ui; -import org.eclipse.jface.text.BadLocationException; +import java.util.Arrays; +import java.util.HashSet; +import java.util.List; +import java.util.Locale; +import java.util.Set; +import org.eclipse.jface.text.BadLocationException; +import org.opengauss.mppdbide.debuger.service.SourceCodeService; +import org.opengauss.mppdbide.debuger.vo.VersionVo; +import org.opengauss.mppdbide.utils.ConstantRunLine; +import org.opengauss.mppdbide.utils.DebuggerStartConstants; +import org.opengauss.mppdbide.utils.exceptions.DatabaseCriticalException; +import org.opengauss.mppdbide.utils.exceptions.DatabaseOperationException; +import org.opengauss.mppdbide.utils.exceptions.MPPDBIDEException; import org.opengauss.mppdbide.utils.logger.MPPDBIDELoggerUtility; +import org.opengauss.mppdbide.view.core.sourceeditor.SQLSyntaxColorProvider; import org.opengauss.mppdbide.view.ui.PLSourceEditor; import org.opengauss.mppdbide.view.utils.UIElement; @@ -28,26 +41,151 @@ import org.opengauss.mppdbide.view.utils.UIElement; * @since 3.0.0 */ public class UpdateDebugPositionTask implements Runnable { - private int showLine = -1; - - public UpdateDebugPositionTask(int showLine) { - this.showLine = showLine; - } - - @Override - public void run() { - PLSourceEditor plSourceEditor = UIElement.getInstance().getVisibleSourceViewer(); - if (plSourceEditor == null) { - return; - } - - plSourceEditor.removeDebugPosition(); - try { - if (showLine >= 0) { - plSourceEditor.createDebugPosition(showLine); - } - } catch (BadLocationException e) { - MPPDBIDELoggerUtility.error("set debugPostion at " + showLine + " failed,err=" + e.getMessage()); - } - } + private int showLine = -1; + + public UpdateDebugPositionTask(int showLine) { + this.showLine = showLine; + ConstantRunLine.passLine.add(showLine); + } + + @Override + public void run() { + PLSourceEditor plSourceEditor = UIElement.getInstance().getVisibleSourceViewer(); + if (plSourceEditor == null) { + return; + } + Boolean isPlDebugger = true; + try { + VersionVo vo = new VersionVo(); + vo.version = plSourceEditor.getDatabase().getServerVersion(); + isPlDebugger = vo.isPldebugger(); + if (isPlDebugger) { + plSourceEditor.removeDebugPosition(); + if (showLine >= 0) { + plSourceEditor.createDebugPosition(showLine); + } + }else { + //dbedebugger + if(ConstantRunLine.isTerminate) { + debDebuggerRemark(plSourceEditor); + } + } + } catch (MPPDBIDEException e) { + MPPDBIDELoggerUtility.error("get version failed,err=" + e.getMessage()); + } catch (BadLocationException e) { + MPPDBIDELoggerUtility.error("set debugPostion at " + showLine + " failed,err=" + e.getMessage()); + } + } + + public static PLSourceEditor terminateDebug() { + PLSourceEditor plSourceEditor = UIElement.getInstance().getVisibleSourceViewer(); + plSourceEditor.removeDebugPosition(); + long oid = plSourceEditor.getDebugObject().getOid(); + String covs=DebuggerStartConstants.getStartInfo(oid).remarLinesStr; + if(covs!= null && !covs.isEmpty()) { + List lines = Arrays.asList(covs.split(",")); + lines.forEach(item -> { + plSourceEditor.getSourceEditorCore().getSourceViewer().getTextWidget().setLineBackground(Integer.parseInt(item), 1, SQLSyntaxColorProvider.BACKGROUND_COLOR_GREY); + }); + } + return plSourceEditor; + } + + public static void continueDebug() { + try { + Thread.sleep(200); + PLSourceEditor pl = terminateDebug(); + getToatlLineNo(pl).forEach(item-> { + try { + if (ConstantRunLine.runList.contains(String.valueOf(item))) { + pl.createPassPosition(item); + }else { + pl.createFailPosition(item); + } + } catch (BadLocationException e) { + MPPDBIDELoggerUtility.error(e.getMessage()); + } + }); + } catch (Exception e) { + MPPDBIDELoggerUtility.error(e.getMessage()); + } + } + + private void remarkBack(PLSourceEditor plSourceEditor) { + long oid = plSourceEditor.getDebugObject().getOid(); + String covs=DebuggerStartConstants.getStartInfo(oid).remarLinesStr; + if(covs!= null && !covs.isEmpty()) { + List lines = Arrays.asList(covs.split(",")); + lines.forEach(item -> { + if (!String.valueOf(showLine).equals(item)) { + plSourceEditor.getSourceEditorCore().getSourceViewer().getTextWidget().setLineBackground(Integer.parseInt(item), 1, SQLSyntaxColorProvider.BACKGROUND_COLOR_GREY); + } + }); + } + } + + private void debDebuggerRemark(PLSourceEditor plSourceEditor) { + plSourceEditor.removeDebugPosition(); + try { + remarkBack(plSourceEditor); + if (showLine >= 0) { + plSourceEditor.createDebugPosition(showLine); + } + remark(showLine,plSourceEditor); + } catch (BadLocationException e) { + MPPDBIDELoggerUtility.error("set debugPostion at " + showLine + " failed,err=" + e.getMessage()); + } catch (Exception e) { + MPPDBIDELoggerUtility.error(e.getMessage()); + } + } + + private void remark(int line, PLSourceEditor plSourceEditor) { + getToatlLineNo(plSourceEditor).forEach(item-> { + try { + if (item != showLine && ConstantRunLine.passLine.contains(item)) { + plSourceEditor.createPassPosition(item); + }else if(item != showLine){ + plSourceEditor.createFailPosition(item); + } + } catch (BadLocationException e) { + MPPDBIDELoggerUtility.error(e.getMessage()); + } + }); + } + + public static Set getToatlLineNo(PLSourceEditor plSourceEditor){ + Set record = new HashSet<>(); + int begin = -1; + int end = -1;; + try { + String sourceCode = plSourceEditor.getDebugObject().getLatestSouceCode().getCode(); + List total = SourceCodeService.CodeDescription.getLines(sourceCode); + + for(int i=0;i ls =coverageService.getCoverageInfoByOid(oid); + setInput(ls); + } catch (SQLException e) { + MPPDBIDELoggerUtility.error(e.getMessage()); + } finally { + if (null != coverageService) { + coverageService.closeService(); + } + } + } + + public void setInput(List items) { + int index = 1; + for (CoverageVo item : items) { + TableItem row = new TableItem(table, SWT.NONE); + setColValues(row, item, index); + index++; + row.setData(item); + } + if (table != null) { + if (table.getItems().length > 0) { + enablebuttons(true); + } + } + } + + private void setColValues(TableItem row, CoverageVo item, Integer count) { + row.setText(SERIAL_NUMBER_COLUMN, count.toString()); + row.setText(PIN_STATUS_COLUMN, String.valueOf(item.totalLineNum)); + row.setText(SQL_QUERY_COLUMN, String.valueOf(item.coverageLineNum)); + row.setText(NUMBER_OF_ROWS_COLUMN, String.valueOf(item.totalPercent)); + row.setText(START_TIME_COLUMN, String.valueOf(item.remarkLinesArr)); + row.setText(ELAPSED_TIME, String.valueOf(item.remarkCoverageLinesArr)); + row.setText(DATABASE_NAME_COLUMN, String.valueOf(item.remarkPercent)); + row.setText(UPDATE_TIME, item.parseDate()); + } + + private void loadQuerytoSQLTerminal() { + String query = null; + StringBuilder sb = new StringBuilder(MPPDBIDEConstants.STRING_BUILDER_CAPACITY); + SQLTerminal terminal = UIElement.getInstance().getTerminal(terminalParentId); + TableItem[] items = table.getSelection(); + for (TableItem t : items) { + query = t.getText(SQL_QUERY_COLUMN); + sb.append(query); + sb.append(EnvirnmentVariableValidator.validateAndGetLineSeperator()); + } + + if (null != terminal) { + terminal.getTerminalCore().setSelectedQuery(sb.toString()); + terminal.resetSQLTerminalButton(); + terminal.resetAutoCommitButton(); + terminal.setModified(true); + terminal.setModifiedAfterCreate(true); + } + } + + public SQLSyntax getSyntax() { + return syntax; + } + + public void setSyntax(SQLSyntax syntax) { + this.syntax = syntax; + } + + public CompositeRuler getCompositeRuler() { + fCompositeRuler = new CompositeRuler(SPACE_BETWEEN_RULER); + fCompositeRuler.addDecorator(1, new LineNumberRulerColumn()); + + return fCompositeRuler; + } + + public void setDocument(IDocument document) { + sourceViewer.setDocument(document); + } + + private void createToolbar(final Composite parent) { + + final ToolBar bar = new ToolBar(parent, SWT.FLAT | SWT.FOCUSED); + + final Image sqlcloseIcon = IconUtility.getIconImage(IiconPath.LOAD_QUERY_SQL_CLOSE, getClass()); + final Image deleteIcon = IconUtility.getIconImage(IiconPath.DELETE_SELECTED, getClass()); + + final Image deleteallIcon = IconUtility.getIconImage(IiconPath.DELETE_ALL, getClass()); + + saveToolItem = new ToolItem(bar, SWT.PUSH); + saveToolItem.setEnabled(false); + saveToolItem.setImage(sqlcloseIcon); + saveToolItem.setToolTipText(MessageConfigLoader.getProperty(IMessagesConstants.EXPORT_REPORT)); + saveToolItem.addSelectionListener(new ExportCoverageReport()); + + deleteToolItem = new ToolItem(bar, SWT.PUSH); + deleteToolItem.setEnabled(false); + deleteToolItem.setImage(deleteIcon); + deleteToolItem.setToolTipText(MessageConfigLoader.getProperty(IMessagesConstants.DELETE_Coverage)); + deleteToolItem.addSelectionListener(new DeletesqlClass()); + + deleteAllToolItem = new ToolItem(bar, SWT.PUSH); + deleteAllToolItem.setEnabled(false); + deleteAllToolItem.setImage(deleteallIcon); + deleteAllToolItem.setToolTipText(MessageConfigLoader.getProperty(IMessagesConstants.DELETE_Coverage_All)); + deleteAllToolItem.addSelectionListener(new DeleteAllsqlClass()); + } + + private final class DeletesqlClass implements SelectionListener { + + @Override + public void widgetSelected(SelectionEvent event) { + TableItem[] tableItems = table.getSelection(); + if (tableItems.length == 0) { + MPPDBIDEDialogs.generateOKMessageDialog(MESSAGEDIALOGTYPE.INFORMATION, true, + MessageConfigLoader.getProperty(IMessagesConstants.DELETE_COVERAGE_REPORT_TITLE), + MessageConfigLoader.getProperty(IMessagesConstants.SELECT_QUERY_TO_DELETE)); + return; + } + int type = MPPDBIDEDialogs.generateOKCancelMessageDialog(MESSAGEDIALOGTYPE.WARNING, true, + MessageConfigLoader.getProperty(IMessagesConstants.DELETE_COVERAGE_REPORT_TITLE), + MessageConfigLoader.getProperty(IMessagesConstants.DELETE_SELECTED_COVERAGE_HISTORY_ALERT, profileName, + MPPDBIDEConstants.LINE_SEPARATOR)); + deleteSQLHistory(type, tableItems); + resetSerialNumber(); + } + + private void displayInfoMessage() { + MPPDBIDEDialogs.generateOKMessageDialog(MESSAGEDIALOGTYPE.INFORMATION, true, + MessageConfigLoader.getProperty(IMessagesConstants.DELETE_SQL), + MessageConfigLoader.getProperty(IMessagesConstants.PINNED_DELETION)); + } + + @Override + public void widgetDefaultSelected(SelectionEvent event) { + + } + } + + private final class ExportCoverageReport implements SelectionListener { + + @Override + public void widgetSelected(SelectionEvent event) { + TableItem[] items = table.getSelection(); + if (items.length == 0) { + MPPDBIDEDialogs.generateOKMessageDialog(MESSAGEDIALOGTYPE.INFORMATION, true, + MessageConfigLoader.getProperty(IMessagesConstants.EXPORT_REPORT), + MessageConfigLoader.getProperty(IMessagesConstants.COVERAGE_REPORT_TO_SELECT)); + return; + } + int type = MPPDBIDEDialogs.generateOKCancelMessageDialog(MESSAGEDIALOGTYPE.WARNING, true, + MessageConfigLoader.getProperty(IMessagesConstants.EXPORT_REPORT), + MessageConfigLoader.getProperty(IMessagesConstants.SURE_EXPORT_REPORT)); + if (type == 0) { + Boolean flag = true; + String html = null; + String serialNum; + for (int index=0; index< items.length; index++) { + TableItem item =items[index]; + List list = getData(item); + serialNum = String.valueOf(index+1); + list.add(0, serialNum); + Map code = new HashMap(); + if (item.getData() instanceof CoverageVo) { + CoverageVo vo = (CoverageVo)item.getData(); + List codes = SourceCodeService.CodeDescription.getLines(vo.sourceCode); + for (int i =0;i getData(TableItem item) { + if (item.getData() instanceof CoverageVo) { + CoverageVo coverageVo = (CoverageVo) item.getData(); + return Stream.of(String.valueOf(coverageVo.totalLineNum),String.valueOf(coverageVo.coverageLineNum),coverageVo.totalPercent, + String.valueOf(coverageVo.remarkLinesArr),String.valueOf(coverageVo.remarkCoverageLinesArr), + coverageVo.remarkPercent, coverageVo.parseDate()).collect(Collectors.toList()); + } else { + return Collections.emptyList(); + } + } + + private final class DeleteAllsqlClass implements SelectionListener { + + @Override + public void widgetSelected(SelectionEvent event) { + TableItem[] items = table.getItems(); + int type = MPPDBIDEDialogs.generateOKCancelMessageDialog(MESSAGEDIALOGTYPE.WARNING, true, + MessageConfigLoader.getProperty(IMessagesConstants.DELETE_COVERAGE_REPORT_TITLE), + MessageConfigLoader.getProperty(IMessagesConstants.DELETE_ALL_COVERAGE_HISTORY_ALERT, profileName, + MPPDBIDEConstants.LINE_SEPARATOR)); + deleteSQLHistory(type, items); + resetSerialNumber(); + } + + @Override + public void widgetDefaultSelected(SelectionEvent event) { + + } + } + + private void deleteSQLHistory(int type, TableItem[] items) { + if (type == 0) { + List historyItems = new LinkedList(); + int counter = 0; + for (TableItem item : items) { + if (item.getData() instanceof CoverageVo) { + historyItems.add((CoverageVo) item.getData()); + item.dispose(); + counter++; + } + } + if (counter != 0) { + CoverageService[] service = new CoverageService[1]; + try { + service[0] = coverageServiceFactory.getCoverageService(); + historyItems.forEach(item -> { + service[0].delCoverageInfoByOid(item.oid, item.cid); + }); + } catch(SQLException e) { + MPPDBIDELoggerUtility.error(e.getMessage()); + } finally { + service[0].closeService(); + } + } + sourceViewer.getDocument().set(""); + } + } + + private void resetSerialNumber() { + if (table != null) { + TableItem[] items = table.getItems(); + int size = items.length; + if (size <= 0) { + enablebuttons(false); + return; + } + + for (int indx = 0; indx < size; indx++) { + items[indx].setText(0, Integer.toString(indx + 1)); + } + } + } + + protected void enablebuttons(boolean value) { + saveToolItem.setEnabled(value); + deleteAllToolItem.setEnabled(value); + deleteToolItem.setEnabled(value); + } +} 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 d919022039e91ee3041eaeda2d58c98ae2bef21e..9916adafe70f60e9331a7b42f5e744eac2e75a3c 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 @@ -45,10 +45,8 @@ import org.eclipse.jface.text.DocumentEvent; import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.IDocumentExtension3; import org.eclipse.jface.text.IDocumentListener; -import org.eclipse.jface.text.IDocumentPartitioner; import org.eclipse.jface.text.IInformationControl; import org.eclipse.jface.text.IInformationControlCreator; -import org.eclipse.jface.text.IRegion; import org.eclipse.jface.text.ITextSelection; import org.eclipse.jface.text.Position; import org.eclipse.jface.text.source.Annotation; @@ -60,10 +58,6 @@ import org.eclipse.jface.text.source.CompositeRuler; import org.eclipse.jface.text.source.IAnnotationAccess; import org.eclipse.jface.text.source.LineNumberRulerColumn; import org.eclipse.jface.text.source.SourceViewer; -import org.eclipse.jface.text.source.projection.ProjectionViewer; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.ISelectionChangedListener; -import org.eclipse.jface.viewers.SelectionChangedEvent; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.SashForm; import org.eclipse.swt.dnd.Clipboard; @@ -77,7 +71,6 @@ import org.eclipse.swt.events.MouseListener; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.RGB; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; @@ -86,8 +79,6 @@ import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Menu; import org.eclipse.swt.widgets.MenuItem; import org.eclipse.swt.widgets.Shell; -import org.eclipse.ui.texteditor.AnnotationPreference; - import org.opengauss.mppdbide.adapter.keywordssyntax.SQLSyntax; import org.opengauss.mppdbide.bl.errorlocator.IErrorLocator; import org.opengauss.mppdbide.bl.serverdatacache.Database; @@ -102,6 +93,7 @@ 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.DebuggerStartConstants; import org.opengauss.mppdbide.utils.IMessagesConstants; import org.opengauss.mppdbide.utils.MPPDBIDEConstants; import org.opengauss.mppdbide.utils.MemoryCleaner; @@ -112,13 +104,16 @@ 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; import org.opengauss.mppdbide.view.core.sourceeditor.AnnotationHover; import org.opengauss.mppdbide.view.core.sourceeditor.BreakpointAnnotation; +import org.opengauss.mppdbide.view.core.sourceeditor.DebugFailPositionAnnotation; +import org.opengauss.mppdbide.view.core.sourceeditor.DebugPassPositionAnnotation; import org.opengauss.mppdbide.view.core.sourceeditor.DebugPositionAnnotation; import org.opengauss.mppdbide.view.core.sourceeditor.ErrorAnnotation; -import org.opengauss.mppdbide.view.core.sourceeditor.ErrorPositionAnnotation; import org.opengauss.mppdbide.view.core.sourceeditor.PLAnnotationMarkerAccess; import org.opengauss.mppdbide.view.core.sourceeditor.PLSourceEditorCore; import org.opengauss.mppdbide.view.core.sourceeditor.SQLDocumentPartitioner; @@ -126,12 +121,9 @@ import org.opengauss.mppdbide.view.core.sourceeditor.SQLEditorPlugin; import org.opengauss.mppdbide.view.core.sourceeditor.SQLPartitionScanner; import org.opengauss.mppdbide.view.core.sourceeditor.SQLSourceViewerConfig; import org.opengauss.mppdbide.view.core.sourceeditor.SQLSyntaxColorProvider; -import org.opengauss.mppdbide.view.core.sourceeditor.AnnotationHelper.AnnotationType; import org.opengauss.mppdbide.view.handler.ExecuteEditorItem; import org.opengauss.mppdbide.view.handler.HandlerUtilities; -import org.opengauss.mppdbide.view.handler.debug.DebugHandlerUtils; import org.opengauss.mppdbide.view.handler.debug.DebugServiceHelper; -import org.opengauss.mppdbide.view.prefernces.PreferenceWrapper; import org.opengauss.mppdbide.view.terminal.executioncontext.FuncProcEditorTerminalExecutionContext; import org.opengauss.mppdbide.view.ui.autosave.AbstractAutoSaveObject; import org.opengauss.mppdbide.view.ui.autosave.IAutoSaveDbgObject; @@ -140,8 +132,6 @@ import org.opengauss.mppdbide.view.ui.terminal.FuncProcTerminalResultDisplayUIMa import org.opengauss.mppdbide.view.ui.terminal.resulttab.ResultTabManager; import org.opengauss.mppdbide.view.ui.uiif.PLSourceEditorIf; import org.opengauss.mppdbide.view.uidisplay.UIDisplayFactoryProvider; -import org.opengauss.mppdbide.view.uidisplay.UIDisplayState; -import org.opengauss.mppdbide.view.utils.IUserPreference; import org.opengauss.mppdbide.view.utils.UIElement; import org.opengauss.mppdbide.view.utils.UserPreference; import org.opengauss.mppdbide.view.utils.common.SourceViewerUtil; @@ -697,6 +687,9 @@ public class PLSourceEditor extends AbstractAutoSaveObject sourceEditor.setDocument(new Document(debugObject.getLatestSouceCode().getCode()), 0); debugObject.setCodeReloaded(false); } + String sourceCode=debugObject.getLatestSouceCode().getCode(); + DebuggerStartInfoVo info= DebuggerStartConstants.getStartInfo(debugObject.getOid()); + info.sourceCode=sourceCode; registerModifyListener(); setSourceChangedInEditor(false); setSourceViewerConfiguration(); @@ -1335,17 +1328,40 @@ public class PLSourceEditor extends AbstractAutoSaveObject */ public void removeDebugPosition() { Iterator annoIterator = fAnnotationModel.getAnnotationIterator(); - List needRemoveAnnotations = - new ArrayList(1); + List needRemoveAnnotations = + new ArrayList(1); while (annoIterator.hasNext()) { Annotation annotation = annoIterator.next(); if (annotation instanceof DebugPositionAnnotation) { needRemoveAnnotations.add((DebugPositionAnnotation) annotation); } + if (annotation instanceof DebugPassPositionAnnotation) { + needRemoveAnnotations.add((DebugPassPositionAnnotation) annotation); + } + if (annotation instanceof DebugFailPositionAnnotation) { + needRemoveAnnotations.add((DebugFailPositionAnnotation) annotation); + } } - for (DebugPositionAnnotation anno: needRemoveAnnotations) { - fAnnotationModel.removeAnnotation(anno); - deHighlightLine(anno.getLine()); + for (Object anno: needRemoveAnnotations) { + Annotation annotation = null; + int line = -1; + if (anno instanceof DebugPositionAnnotation) { + DebugPositionAnnotation debug = (DebugPositionAnnotation)anno; + annotation = debug; + line = debug.getLine(); + } + if (anno instanceof DebugPassPositionAnnotation) { + DebugPassPositionAnnotation pass = (DebugPassPositionAnnotation)anno; + annotation = pass; + line = pass.getLine(); + } + if (anno instanceof DebugFailPositionAnnotation) { + DebugFailPositionAnnotation fail = (DebugFailPositionAnnotation)anno; + annotation = fail; + line = fail.getLine(); + } + fAnnotationModel.removeAnnotation(annotation); + deHighlightLine(line); } } @@ -1361,9 +1377,23 @@ public class PLSourceEditor extends AbstractAutoSaveObject new Position(sourceEditor.getDocument().getLineOffset(line)) ); sourceEditor.goToLineNumber(line); - highlightLine(line); + highlightLine(line); setDebugPositionLine(line); } + + public void createPassPosition(int line) throws BadLocationException { + DebugPassPositionAnnotation annotation = new DebugPassPositionAnnotation(line); + fAnnotationModel.addAnnotation(annotation, + new Position(sourceEditor.getDocument().getLineOffset(line)) + ); + } + + public void createFailPosition(int line) throws BadLocationException { + DebugFailPositionAnnotation annotation = new DebugFailPositionAnnotation(line); + fAnnotationModel.addAnnotation(annotation, + new Position(sourceEditor.getDocument().getLineOffset(line)) + ); + } /** * Search for any annotation for given line. 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 new file mode 100644 index 0000000000000000000000000000000000000000..581ead8a068f49d940e8412d717b0805f937da3d --- /dev/null +++ b/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/utils/ExportUtil.java @@ -0,0 +1,103 @@ +package org.opengauss.mppdbide.view.utils; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.net.URL; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; + +import org.eclipse.core.runtime.FileLocator; +import org.jsoup.Jsoup; +import org.jsoup.nodes.Document; +import org.jsoup.nodes.Element; +import org.opengauss.mppdbide.utils.logger.MPPDBIDELoggerUtility; + +public final class ExportUtil { + + private static String outpath; + private static File file; + + private ExportUtil() { + + } + + public static String getPath() { + return outpath; + } + + public static String exportReport(long oid, String index, Map executeSql,Set remarkLines, Set coveragePassLines, List list, String html) { + URL url = ExportUtil.class.getClassLoader().getResource("exportTemplate.html"); + Document parse = null; + try { + if (null == html) { + String path = FileLocator.toFileURL(url).getPath().substring(1); + file = new File(path); + outpath = path.substring(0, path.indexOf("/")+1)+oid+"_"+ System.currentTimeMillis()+".html"; + parse = Jsoup.parse(file, "gbk"); + }else { + parse = Jsoup.parse(html); + } + Element data = parse.getElementById("data"); + Element datatr = data.appendElement("tr"); + list.forEach(item -> { + Element td = datatr.appendElement("td"); + td.text(item); + }); + int[] begin=new int[]{-1}; + int[] end=new int[]{-1}; + Element excuteSql = parse.getElementById("executeSql"); + List val = executeSql.values().stream().collect(Collectors.toList()); + for(int i=0;i { + Element tr = excuteSql.appendElement("tr"); + if (flag[0]) { + Element td0 = tr.appendElement("td"); + td0.attr("rowspan", val.size()+""); + td0.text(index); + flag[0] = false; + } + Element td = tr.appendElement("td"); + Element td2 = tr.appendElement("td"); + Element div = td.appendElement("div"); + td2.text(v); + if (remarkLines.contains(k.toString())) { + td2.addClass("bac_remark"); + } + if (coveragePassLines.contains((k-1)+"")) { + div.addClass("bac_pass"); + }else if (k> (begin[0]+1) && k< (end[0]+1)) { + div.addClass("bac_fail"); + } + }); + } catch (IOException e) { + MPPDBIDELoggerUtility.error(e.getMessage()); + } + return parse.outerHtml(); + } + + public static void loadStr(String path,String text_description) throws IOException{ + BufferedWriter bw = new BufferedWriter(new FileWriter(new File(path))); + String[] split = text_description.split(" "); + for (String str : split) { + bw.write(str+System.getProperty("line.separator")); + } + if(bw!=null){ + bw.close(); + } + } +} diff --git a/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/utils/icon/IiconPath.java b/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/utils/icon/IiconPath.java index b5e1d7ae38c5de75230bffb4ad056ea87a89a645..739bbd2b61d09089251c99475cc9897c60a92cd9 100644 --- a/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/utils/icon/IiconPath.java +++ b/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/utils/icon/IiconPath.java @@ -979,4 +979,10 @@ public interface IiconPath { * The ico breakpoint arrow. */ String ICO_BREAKPOINT_ARROW = PRE_DEBUG_PATH + "debugarrows.png"; + + String ICO_EXECUTE_PASS = PRE_DEBUG_PATH + "debug_pass.png"; + + String ICO_EXECUTE_Fail = PRE_DEBUG_PATH + "debug_fail.png"; + + String ICON_REMARK_COVERAGE = "icon-remarkCoverage.png"; } diff --git a/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/vo/CoverageService.java b/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/vo/CoverageService.java new file mode 100644 index 0000000000000000000000000000000000000000..8ea52131b09ac68493e1cf9b5b28f9e248154724 --- /dev/null +++ b/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/vo/CoverageService.java @@ -0,0 +1,130 @@ +package org.opengauss.mppdbide.view.vo; + +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.Comparator; +import java.util.List; +import java.util.stream.Collectors; + +import org.opengauss.mppdbide.common.IConnection; +import org.opengauss.mppdbide.debuger.annotation.ParseVo; +import org.opengauss.mppdbide.debuger.service.IService; +import org.opengauss.mppdbide.debuger.service.SourceCodeService; +import org.opengauss.mppdbide.utils.DebuggerStartConstants; +import org.opengauss.mppdbide.utils.logger.MPPDBIDELoggerUtility; +import org.opengauss.mppdbide.utils.vo.DebuggerEndInfoVo; +import org.opengauss.mppdbide.utils.vo.DebuggerStartInfoVo; + +public class CoverageService implements IService { + + private IConnection conn = null; + + public void setConn(IConnection conn) { + this.conn = conn; + } + + public void setRemarkInfo(long oid, String rowLines) throws SQLException { + DebuggerStartInfoVo startInfo = DebuggerStartConstants.getStartInfo(oid); + startInfo.remarLinesStr = rowLines; + DebuggerStartConstants.setStartInfo(oid, startInfo); + } + + public String getRemarkInfo(long oid) throws SQLException { + DebuggerStartInfoVo startInfo = DebuggerStartConstants.getStartInfo(oid); + return startInfo.remarLinesStr; + } + + public List getCoverageInfoByOid(long oid) { + String sql="select * from his_coverage where oid="+oid+" order by cid desc;"; + try { + List res=this.queryList(sql, CoverageVo.class); + res.stream().forEach(coverageVo->{ + if (null != coverageVo.sourceCode) { + List toRunLines=SourceCodeService.CodeDescription.getRunLinesNums(coverageVo.sourceCode); + coverageVo.totalLineNum=toRunLines.size(); + coverageVo.coverageLineNum=coverageVo.getRunList().size(); + coverageVo.coverageLinesArr=coverageVo.getRunList(); + coverageVo.totalPercent=Double.parseDouble(String.format("%.2f", ((double)coverageVo.coverageLineNum* 100 / (double)coverageVo.totalLineNum))) + "%"; + //if not remark + if(coverageVo.remarkLines==null || "".equals(coverageVo.remarkLines)) { + coverageVo.remarkLines=toRunLines.stream().map(String::valueOf).collect(Collectors.joining(",")); + coverageVo.remarkLinesArr=coverageVo.getRemarkList(); + }else { + coverageVo.remarkLinesArr = coverageVo.getRemarkList().stream().map(item -> Integer.parseInt(item) + 1).sorted().map(item-> String.valueOf(item)).collect(Collectors.toList()); + } + coverageVo.remarkLineNum=coverageVo.remarkLinesArr.size(); + coverageVo.remarkCoverageLinesArr=coverageVo.coverageLinesArr.stream().map(item-> Integer.parseInt(item)+1+"").filter(ite -> coverageVo.remarkLinesArr.contains(ite)).collect(Collectors.toList()); + coverageVo.remarkCoverageLineNum=coverageVo.remarkCoverageLinesArr.size(); + coverageVo.remarkPercent=Double.parseDouble(String.format("%.2f", ((double)coverageVo.remarkCoverageLineNum* 100 / (double)coverageVo.remarkLineNum))) + "%"; + } + }); + return res.stream().sorted(Comparator.comparing(CoverageVo::getEndTime).reversed()).collect(Collectors.toList()); + } catch (SQLException e) { + return new ArrayList(); + } + } + + public void delCoverageInfoByOid(long oid, Long cid) { + String sql="delete from his_coverage where oid="+oid+" and cid="+cid+";"; + try { + conn.getStatement(sql).executeUpdate(); + } catch (SQLException e) { + MPPDBIDELoggerUtility.error(e.getMessage()); + } + + List historyList=DebuggerStartConstants.getHistoryList(oid); + historyList=historyList.stream().filter(a->!a.cid.equals(cid)).collect(Collectors.toList()); + DebuggerStartConstants.setHistoryList(oid, historyList); + } + + private Boolean executeSql(String sql) throws SQLException { + Boolean flag = false; + try (PreparedStatement ps = conn.getStatement(sql)) { + flag = ps.execute(sql); + } catch (SQLException e) { + throw new SQLException("sql execute exception!"); + } + return flag; + } + + private T queryObj(String sql, Class clazz) throws SQLException { + T t = null; + try (PreparedStatement ps = conn.getStatement(sql)) { + try (ResultSet rs = ps.executeQuery()) { + if (rs.next()) { + t = ParseVo.parse(rs, clazz); + } + } + } catch (SQLException e) { + throw new SQLException("sql execute exception!"); + } + return t; + } + + private List queryList(String sql, Class clazz) throws SQLException { + List list = null; + try (PreparedStatement ps = conn.getStatement(sql)) { + try (ResultSet rs = ps.executeQuery()) { + list = ParseVo.parseList(rs, clazz); + } + } catch (SQLException e) { + throw new SQLException("sql execute exception!"); + } + return list; + } + + @Override + public void closeService() { + try { + if (this.conn != null) { + this.conn.close(); + this.conn = null; + } + } catch (SQLException e) { + MPPDBIDELoggerUtility.warn("close conn with err:" + e.toString()); + } + + } +} diff --git a/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/vo/CoverageVo.java b/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/vo/CoverageVo.java new file mode 100644 index 0000000000000000000000000000000000000000..36e20b697b9cf7db31f4ae3b28d86ba98d729600 --- /dev/null +++ b/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/vo/CoverageVo.java @@ -0,0 +1,154 @@ +package org.opengauss.mppdbide.view.vo; + +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Date; +import java.util.List; + +import org.opengauss.mppdbide.debuger.annotation.DumpFiled; + +public class CoverageVo { + + private final SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + + /** + * 存储过程key + */ + @DumpFiled + public long oid; + + /** + * 覆盖率报告key + */ + @DumpFiled + public long cid; + + /** + * 存储过程总行数 + */ + public int totalLineNum; + + /** + * 执行到的语句的数量 + */ + public int coverageLineNum; + + /** + * 执行到的语句行号 + */ + @DumpFiled + public String coverageLines; + + /** + * 执行到的语句行号集合 + */ + public List coverageLinesArr; + + /** + * 总覆盖率 + */ + public String totalPercent; + + /** + * 标记的行数量 + */ + public int remarkLineNum; + + /** + * 标记的行号 + */ + @DumpFiled + public String remarkLines; + + /** + * 标记的行号集合 + */ + public List remarkLinesArr; + + /** + * 标记执行到的行数量 + */ + public int remarkCoverageLineNum; + + /** + * 标志执行到的行号集合 + */ + public List remarkCoverageLinesArr; + + /** + * 标记覆盖率 + */ + public String remarkPercent; + + /** + * 结束时间 + */ + @DumpFiled + public long endTime; + + /** + * 执行语句 + */ + @DumpFiled + public String sourceCode; + + public CoverageVo() { + + } + + public List getRemarkList() { + if (remarkLines==null || "".equals(remarkLines)){ + return new ArrayList(); + }else { + remarkLinesArr =new ArrayList<>(Arrays.asList(remarkLines.split(","))); + } + return remarkLinesArr; + } + + public List getRunList() { + if (coverageLines==null || "".equals(coverageLines)){ + return new ArrayList(); + }else { + coverageLinesArr =new ArrayList<>(Arrays.asList(coverageLines.split(","))); + } + return coverageLinesArr; + } + + public CoverageVo(long cid, + long oid, + int totalLineNum, + int coverageLineNum, + String coverageLines, + String totalPercent, + int remarkLineNum, + String remarkLines, + int remarkCoverageLineNum, + String remarkCoverageLineNo, + String remarkPercent, + long endTime, + String sourceCode) { + this.cid = cid; + this.oid = oid; + this.totalLineNum = totalLineNum; + this.coverageLineNum = coverageLineNum; + this.coverageLines = coverageLines; + this.totalPercent = totalPercent; + this.remarkLineNum = remarkLineNum; + this.remarkLines = remarkLines; + this.remarkCoverageLineNum = remarkCoverageLineNum; + this.remarkPercent = remarkPercent; + this.endTime = endTime; + this.sourceCode = sourceCode; + } + + public String parseDate() { + Date date = new Date(this.endTime); + return df.format(date); + } + + public long getEndTime() { + return endTime; + } + +} diff --git "a/information/datastudio/DataStudio\346\226\260\345\242\236\345\212\237\350\203\275\350\257\264\346\230\216.docx" "b/information/datastudio/DataStudio\346\226\260\345\242\236\345\212\237\350\203\275\350\257\264\346\230\216.docx" new file mode 100644 index 0000000000000000000000000000000000000000..92cd323cac53b4d225a095df45623bb903f751ca Binary files /dev/null and "b/information/datastudio/DataStudio\346\226\260\345\242\236\345\212\237\350\203\275\350\257\264\346\230\216.docx" differ diff --git a/information/datastudio/New features to DataStudio.docx b/information/datastudio/New features to DataStudio.docx new file mode 100644 index 0000000000000000000000000000000000000000..d6bfb4dd46239d057dca0cbca7e7416b5e7ddc15 Binary files /dev/null and b/information/datastudio/New features to DataStudio.docx differ