From d3ceb809e0c62a7fabefa0dd59e6ad4d7618bbe2 Mon Sep 17 00:00:00 2001 From: valb3r Date: Wed, 21 Aug 2024 11:53:07 +0300 Subject: [PATCH] How to use with IC --- .../AttachActivitiBpmnDebuggerToDbAction.kt | 37 +------- .../DefaultAttachBpmnDebuggerToDbAction.kt | 90 +------------------ .../DefaultDetachBpmnDebuggerFromDbAction.kt | 13 +-- build.gradle | 4 +- .../AttachCamundaBpmnDebuggerToDbAction.kt | 37 +------- .../AttachFlowableBpmnDebuggerToDbAction.kt | 37 +------- 6 files changed, 8 insertions(+), 210 deletions(-) diff --git a/activiti-intellij-plugin/src/main/kotlin/com/valb3r/bpmn/intellij/activiti/plugin/actions/AttachActivitiBpmnDebuggerToDbAction.kt b/activiti-intellij-plugin/src/main/kotlin/com/valb3r/bpmn/intellij/activiti/plugin/actions/AttachActivitiBpmnDebuggerToDbAction.kt index f92eb1753..24fd4d48c 100644 --- a/activiti-intellij-plugin/src/main/kotlin/com/valb3r/bpmn/intellij/activiti/plugin/actions/AttachActivitiBpmnDebuggerToDbAction.kt +++ b/activiti-intellij-plugin/src/main/kotlin/com/valb3r/bpmn/intellij/activiti/plugin/actions/AttachActivitiBpmnDebuggerToDbAction.kt @@ -1,40 +1,5 @@ package com.valb3r.bpmn.intellij.activiti.plugin.actions -import com.intellij.database.psi.DbElement import com.valb3r.bpmn.intellij.plugin.commons.actions.DefaultAttachBpmnDebuggerToDbAction -import com.valb3r.bpmn.intellij.plugin.commons.actions.IntelliJBpmnDebugger -class AttachActivitiBpmnDebuggerToDbAction : DefaultAttachBpmnDebuggerToDbAction({ ActivitiIntelliJBpmnDebugger(it) }) - -class ActivitiIntelliJBpmnDebugger(schema: DbElement): IntelliJBpmnDebugger(schema) { - - override fun statementForRuntimeSelection(schema: String): String { - return """ - SELECT re.act_id_ FROM ${"$schema."}act_ru_actinst re JOIN ${"$schema."}act_re_procdef def ON re.proc_def_id_ = def.id_ - WHERE re.proc_inst_id_ = ( - SELECT re.proc_inst_id_ FROM ${"$schema."}act_ru_actinst re JOIN ${"$schema."}act_re_procdef def ON re.proc_def_id_ = def.id_ - WHERE re.start_time_ = - ( - SELECT MAX(re.start_time_) FROM ${"$schema."}act_ru_actinst re JOIN ${"$schema."}act_re_procdef def ON re.proc_def_id_ = def.id_ WHERE def.key_ = ? - ) - LIMIT 1 - ) ORDER BY re.start_time_, re.id_ - - """.trimIndent() - } - - override fun statementForHistoricalSelection(schema: String): String { - return """ - SELECT re.act_id_ FROM ${"$schema."}act_hi_actinst re JOIN ${"$schema."}act_re_procdef def ON re.proc_def_id_ = def.id_ - WHERE re.proc_inst_id_ = ( - SELECT re.proc_inst_id_ FROM ${"$schema."}act_hi_actinst re JOIN ${"$schema."}act_re_procdef def ON re.proc_def_id_ = def.id_ - WHERE re.start_time_ = - ( - SELECT MAX(re.start_time_) FROM ${"$schema."}act_hi_actinst re JOIN ${"$schema."}act_re_procdef def ON re.proc_def_id_ = def.id_ WHERE def.key_ = ? - ) - LIMIT 1 - ) ORDER BY re.start_time_, re.id_ - - """.trimIndent() - } -} +class AttachActivitiBpmnDebuggerToDbAction : DefaultAttachBpmnDebuggerToDbAction() \ No newline at end of file diff --git a/bpmn-intellij-plugin-commons/src/main/kotlin/com/valb3r/bpmn/intellij/plugin/commons/actions/DefaultAttachBpmnDebuggerToDbAction.kt b/bpmn-intellij-plugin-commons/src/main/kotlin/com/valb3r/bpmn/intellij/plugin/commons/actions/DefaultAttachBpmnDebuggerToDbAction.kt index e2a3352f2..a6bc6a328 100644 --- a/bpmn-intellij-plugin-commons/src/main/kotlin/com/valb3r/bpmn/intellij/plugin/commons/actions/DefaultAttachBpmnDebuggerToDbAction.kt +++ b/bpmn-intellij-plugin-commons/src/main/kotlin/com/valb3r/bpmn/intellij/plugin/commons/actions/DefaultAttachBpmnDebuggerToDbAction.kt @@ -1,33 +1,18 @@ package com.valb3r.bpmn.intellij.plugin.commons.actions -import com.intellij.database.dataSource.connection.DGDepartment -import com.intellij.database.model.DasNamespace -import com.intellij.database.psi.DbElement -import com.intellij.database.remote.jdbc.RemoteConnection -import com.intellij.database.util.DbImplUtil import com.intellij.openapi.actionSystem.AnAction import com.intellij.openapi.actionSystem.AnActionEvent import com.intellij.openapi.actionSystem.LangDataKeys import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.project.Project -import com.valb3r.bpmn.intellij.plugin.bpmn.api.bpmn.BpmnElementId import com.valb3r.bpmn.intellij.plugin.core.CANVAS_PAINT_TOPIC import com.valb3r.bpmn.intellij.plugin.core.debugger.BpmnDebugger import com.valb3r.bpmn.intellij.plugin.core.debugger.ExecutedElements -import com.valb3r.bpmn.intellij.plugin.core.debugger.detachDebugger -import com.valb3r.bpmn.intellij.plugin.core.debugger.prepareDebugger -import java.sql.Connection -import java.time.Duration -import java.time.Instant -import java.util.concurrent.ForkJoinPool -import java.util.concurrent.atomic.AtomicReference -abstract class DefaultAttachBpmnDebuggerToDbAction(private val debugger: (schema: DbElement) -> BpmnDebugger) : AnAction() { +abstract class DefaultAttachBpmnDebuggerToDbAction() : AnAction() { override fun actionPerformed(anActionEvent: AnActionEvent) { val project = anActionEvent.project ?: return - val schema = properElem(anActionEvent) ?: return - prepareDebugger(project, debugger(schema)) ApplicationManager.getApplication().invokeLater { anActionEvent.project!!.messageBus.syncPublisher(CANVAS_PAINT_TOPIC).repaint() } @@ -35,86 +20,15 @@ abstract class DefaultAttachBpmnDebuggerToDbAction(private val debugger: (schema override fun update(anActionEvent: AnActionEvent) { val project = anActionEvent.project - anActionEvent.presentation.isEnabledAndVisible = project != null && null != properElem(anActionEvent) - } - - private fun properElem(anActionEvent: AnActionEvent): DbElement? { - return psiElements(anActionEvent) - ?.filterIsInstance() - ?.filterIsInstance() - ?.firstOrNull() } private fun psiElements(anActionEvent: AnActionEvent) = anActionEvent.getData(LangDataKeys.PSI_ELEMENT_ARRAY) } -abstract class IntelliJBpmnDebugger(private val schema: DbElement): BpmnDebugger { - - private val cacheTTL = Duration.ofSeconds(1) - private val worker: ForkJoinPool = ForkJoinPool(1) - - private var cachedResult: AtomicReference = AtomicReference() - private var cachedAtTime: AtomicReference = AtomicReference() +abstract class IntelliJBpmnDebugger: BpmnDebugger { override fun executionSequence(project: Project, processId: String): ExecutedElements? { - val cachedExpiry = cachedAtTime.get()?.plus(cacheTTL) - if (cachedExpiry?.isAfter(Instant.now()) == true) { - return cachedResult.get() - } - - worker.submit { - cachedResult.set(fetchFromDb(project, processId)) - cachedAtTime.set(Instant.now()) - } - - return cachedResult.get() - } - - private fun fetchFromDb(project: Project, processId: String): ExecutedElements? { - try { - val connProvider = DbImplUtil.getDatabaseConnection(schema, DGDepartment.INTROSPECTION)?.get() - val remoteConn = connProvider?.remoteConnection - try { - remoteConn?.let {return readExecutionIds { stmt -> listIds(processId, stmt, it) }} - } finally { - remoteConn?.close() - } - } catch (ex: RuntimeException) { - detachDebugger(project) - } - return null } - - private fun readExecutionIds(idsFetch: (statement: String) -> List): ExecutedElements? { - val ruIds = idsFetch(statementForRuntimeSelection(schema.name)) - if (ruIds.isNotEmpty()) { - return ExecutedElements(ruIds.map { BpmnElementId(it) }) - } - - val hiIds = idsFetch(statementForHistoricalSelection(schema.name)) - if (hiIds.isNotEmpty()) { - return ExecutedElements(hiIds.map { BpmnElementId(it) }) - } - - return null - } - - private fun listIds(processId: String, statement: String, conn: Connection): List { - val ruQuery = conn.prepareStatement(statement) - ruQuery.setString(1, processId) - val result = ruQuery.executeQuery() - return result.use {generateSequence { if (result.next()) result.getString(1) else null }.toList()} - } - - private fun listIds(processId: String, statement: String, conn: RemoteConnection): List { - val ruQuery = conn.prepareStatement(statement) - ruQuery.setString(1, processId) - val result = ruQuery.executeQuery() - return generateSequence { if (result.next()) result.getString(1) else null }.toList() - } - - protected abstract fun statementForRuntimeSelection(schema: String): String - protected abstract fun statementForHistoricalSelection(schema: String): String } diff --git a/bpmn-intellij-plugin-commons/src/main/kotlin/com/valb3r/bpmn/intellij/plugin/commons/actions/DefaultDetachBpmnDebuggerFromDbAction.kt b/bpmn-intellij-plugin-commons/src/main/kotlin/com/valb3r/bpmn/intellij/plugin/commons/actions/DefaultDetachBpmnDebuggerFromDbAction.kt index aa78578c1..096a69b6b 100644 --- a/bpmn-intellij-plugin-commons/src/main/kotlin/com/valb3r/bpmn/intellij/plugin/commons/actions/DefaultDetachBpmnDebuggerFromDbAction.kt +++ b/bpmn-intellij-plugin-commons/src/main/kotlin/com/valb3r/bpmn/intellij/plugin/commons/actions/DefaultDetachBpmnDebuggerFromDbAction.kt @@ -1,13 +1,10 @@ package com.valb3r.bpmn.intellij.plugin.commons.actions -import com.intellij.database.model.DasNamespace -import com.intellij.database.psi.DbElement import com.intellij.openapi.actionSystem.AnAction import com.intellij.openapi.actionSystem.AnActionEvent import com.intellij.openapi.actionSystem.LangDataKeys import com.intellij.openapi.application.ApplicationManager import com.valb3r.bpmn.intellij.plugin.core.CANVAS_PAINT_TOPIC -import com.valb3r.bpmn.intellij.plugin.core.debugger.currentDebugger import com.valb3r.bpmn.intellij.plugin.core.debugger.detachDebugger abstract class DefaultDetachBpmnDebuggerFromDbAction : AnAction() { @@ -21,17 +18,9 @@ abstract class DefaultDetachBpmnDebuggerFromDbAction : AnAction() { } override fun update(anActionEvent: AnActionEvent) { - val project = anActionEvent.project - anActionEvent.presentation.isEnabledAndVisible = - project != null && null != properElem(anActionEvent) && (null != currentDebugger(project)) + // NOP } - private fun properElem(anActionEvent: AnActionEvent): DbElement? { - return psiElements(anActionEvent) - ?.filterIsInstance() - ?.filterIsInstance() - ?.firstOrNull() - } private fun psiElements(anActionEvent: AnActionEvent) = anActionEvent.getData(LangDataKeys.PSI_ELEMENT_ARRAY) diff --git a/build.gradle b/build.gradle index 6a6e69876..441c56353 100644 --- a/build.gradle +++ b/build.gradle @@ -6,8 +6,8 @@ plugins { } ext { - intellijPlatform = 'IU-2022.3' - intellijPlatformPlugins = ['java', 'DatabaseTools'] // DatabaseTools is for BPMN process 'debugging' + intellijPlatform = 'IC-2022.3' + intellijPlatformPlugins = ['java'] // DatabaseTools is for BPMN process 'debugging' kotlinStdlib = '1.5.30' kotlinApiVersion = '1.3' // It must be same as JB supplied Kotlin STDLIB i.e. for 2018 = 1.3. See https://youtrack.jetbrains.com/issue/KT-37435 diff --git a/camunda-intellij-plugin/src/main/kotlin/com/valb3r/bpmn/intellij/plugin/camunda/actions/AttachCamundaBpmnDebuggerToDbAction.kt b/camunda-intellij-plugin/src/main/kotlin/com/valb3r/bpmn/intellij/plugin/camunda/actions/AttachCamundaBpmnDebuggerToDbAction.kt index 0598c2ca8..f0dde8b2b 100644 --- a/camunda-intellij-plugin/src/main/kotlin/com/valb3r/bpmn/intellij/plugin/camunda/actions/AttachCamundaBpmnDebuggerToDbAction.kt +++ b/camunda-intellij-plugin/src/main/kotlin/com/valb3r/bpmn/intellij/plugin/camunda/actions/AttachCamundaBpmnDebuggerToDbAction.kt @@ -1,40 +1,5 @@ package com.valb3r.bpmn.intellij.plugin.camunda.actions -import com.intellij.database.psi.DbElement import com.valb3r.bpmn.intellij.plugin.commons.actions.DefaultAttachBpmnDebuggerToDbAction -import com.valb3r.bpmn.intellij.plugin.commons.actions.IntelliJBpmnDebugger -class AttachCamundaBpmnDebuggerToDbAction : DefaultAttachBpmnDebuggerToDbAction({ CamundaIntelliJBpmnDebugger(it) }) - -class CamundaIntelliJBpmnDebugger(schema: DbElement): IntelliJBpmnDebugger(schema) { - - override fun statementForRuntimeSelection(schema: String): String { - return """ - SELECT re.act_id_ FROM ${"$schema."}act_ru_actinst re JOIN ${"$schema."}act_re_procdef def ON re.proc_def_id_ = def.id_ - WHERE re.proc_inst_id_ = ( - SELECT re.proc_inst_id_ FROM ${"$schema."}act_ru_actinst re JOIN ${"$schema."}act_re_procdef def ON re.proc_def_id_ = def.id_ - WHERE re.start_time_ = - ( - SELECT MAX(re.start_time_) FROM ${"$schema."}act_ru_actinst re JOIN ${"$schema."}act_re_procdef def ON re.proc_def_id_ = def.id_ WHERE def.key_ = ? - ) - LIMIT 1 - ) ORDER BY re.start_time_, re.id_ - - """.trimIndent() - } - - override fun statementForHistoricalSelection(schema: String): String { - return """ - SELECT re.act_id_ FROM ${"$schema."}act_hi_actinst re JOIN ${"$schema."}act_re_procdef def ON re.proc_def_id_ = def.id_ - WHERE re.proc_inst_id_ = ( - SELECT re.proc_inst_id_ FROM ${"$schema."}act_hi_actinst re JOIN ${"$schema."}act_re_procdef def ON re.proc_def_id_ = def.id_ - WHERE re.start_time_ = - ( - SELECT MAX(re.start_time_) FROM ${"$schema."}act_hi_actinst re JOIN ${"$schema."}act_re_procdef def ON re.proc_def_id_ = def.id_ WHERE def.key_ = ? - ) - LIMIT 1 - ) ORDER BY re.start_time_, re.id_ - - """.trimIndent() - } -} +class AttachCamundaBpmnDebuggerToDbAction : DefaultAttachBpmnDebuggerToDbAction() diff --git a/flowable-intellij-plugin/src/main/kotlin/com/valb3r/bpmn/intellij/plugin/flowable/actions/AttachFlowableBpmnDebuggerToDbAction.kt b/flowable-intellij-plugin/src/main/kotlin/com/valb3r/bpmn/intellij/plugin/flowable/actions/AttachFlowableBpmnDebuggerToDbAction.kt index 6914034e9..76a515393 100644 --- a/flowable-intellij-plugin/src/main/kotlin/com/valb3r/bpmn/intellij/plugin/flowable/actions/AttachFlowableBpmnDebuggerToDbAction.kt +++ b/flowable-intellij-plugin/src/main/kotlin/com/valb3r/bpmn/intellij/plugin/flowable/actions/AttachFlowableBpmnDebuggerToDbAction.kt @@ -1,40 +1,5 @@ package com.valb3r.bpmn.intellij.plugin.flowable.actions -import com.intellij.database.psi.DbElement import com.valb3r.bpmn.intellij.plugin.commons.actions.DefaultAttachBpmnDebuggerToDbAction -import com.valb3r.bpmn.intellij.plugin.commons.actions.IntelliJBpmnDebugger -class AttachFlowableBpmnDebuggerToDbAction : DefaultAttachBpmnDebuggerToDbAction({ FlowableIntelliJBpmnDebugger(it) }) - -class FlowableIntelliJBpmnDebugger(schema: DbElement): IntelliJBpmnDebugger(schema) { - - override fun statementForRuntimeSelection(schema: String): String { - return """ - SELECT re.act_id_ FROM ${"$schema."}act_ru_actinst re JOIN ${"$schema."}act_re_procdef def ON re.proc_def_id_ = def.id_ - WHERE re.proc_inst_id_ = ( - SELECT re.proc_inst_id_ FROM ${"$schema."}act_ru_actinst re JOIN ${"$schema."}act_re_procdef def ON re.proc_def_id_ = def.id_ - WHERE re.start_time_ = - ( - SELECT MAX(re.start_time_) FROM ${"$schema."}act_ru_actinst re JOIN ${"$schema."}act_re_procdef def ON re.proc_def_id_ = def.id_ WHERE def.key_ = ? - ) - LIMIT 1 - ) ORDER BY re.start_time_, re.id_ - - """.trimIndent() - } - - override fun statementForHistoricalSelection(schema: String): String { - return """ - SELECT re.act_id_ FROM ${"$schema."}act_hi_actinst re JOIN ${"$schema."}act_re_procdef def ON re.proc_def_id_ = def.id_ - WHERE re.proc_inst_id_ = ( - SELECT re.proc_inst_id_ FROM ${"$schema."}act_hi_actinst re JOIN ${"$schema."}act_re_procdef def ON re.proc_def_id_ = def.id_ - WHERE re.start_time_ = - ( - SELECT MAX(re.start_time_) FROM ${"$schema."}act_hi_actinst re JOIN ${"$schema."}act_re_procdef def ON re.proc_def_id_ = def.id_ WHERE def.key_ = ? - ) - LIMIT 1 - ) ORDER BY re.start_time_, re.id_ - - """.trimIndent() - } -} +class AttachFlowableBpmnDebuggerToDbAction : DefaultAttachBpmnDebuggerToDbAction()