-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
8 additions
and
210 deletions.
There are no files selected for viewing
37 changes: 1 addition & 36 deletions
37
.../com/valb3r/bpmn/intellij/activiti/plugin/actions/AttachActivitiBpmnDebuggerToDbAction.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |
90 changes: 2 additions & 88 deletions
90
...in/com/valb3r/bpmn/intellij/plugin/commons/actions/DefaultAttachBpmnDebuggerToDbAction.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,120 +1,34 @@ | ||
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() | ||
} | ||
} | ||
|
||
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<DasNamespace>() | ||
?.filterIsInstance<DbElement>() | ||
?.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<ExecutedElements?> = AtomicReference() | ||
private var cachedAtTime: AtomicReference<Instant?> = 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<String>): 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<String> { | ||
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<String> { | ||
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 1 addition & 36 deletions
37
...in/com/valb3r/bpmn/intellij/plugin/camunda/actions/AttachCamundaBpmnDebuggerToDbAction.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |
37 changes: 1 addition & 36 deletions
37
.../com/valb3r/bpmn/intellij/plugin/flowable/actions/AttachFlowableBpmnDebuggerToDbAction.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |