Skip to content

Commit

Permalink
Merge pull request #313 from janfh/feature/object_locks
Browse files Browse the repository at this point in the history
Right click option on SQL objects to view object locks
  • Loading branch information
worksofliam authored Jan 17, 2025
2 parents 838ad1a + d1a4cf1 commit 7cc1671
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 3 deletions.
10 changes: 10 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,11 @@
"title": "Get Authorities",
"category": "Db2 for i"
},
{
"command": "vscode-db2i.getObjectLocks",
"title": "Get Object Locks",
"category": "Db2 for i"
},
{
"command": "vscode-db2i.clearData",
"title": "Clear...",
Expand Down Expand Up @@ -963,6 +968,11 @@
"when": "viewItem == table || viewItem == view || viewItem == alias || viewItem == constraint || viewItem == function || viewItem == variable || viewItem == index || viewItem == procedure || viewItem == sequence || viewItem == package || viewItem == trigger || viewItem == type",
"group": "db2workWith@4"
},
{
"command": "vscode-db2i.getObjectLocks",
"when": "viewItem == table || viewItem == view || viewItem == alias || viewItem == constraint || viewItem == function || viewItem == variable || viewItem == index || viewItem == procedure || viewItem == sequence || viewItem == package || viewItem == trigger || viewItem == type",
"group": "db2workWith@5"
},
{
"command": "vscode-db2i.clearData",
"when": "viewItem == table",
Expand Down
10 changes: 10 additions & 0 deletions src/views/schemaBrowser/contributes.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@
"title": "Get Authorities",
"category": "Db2 for i"
},
{
"command": "vscode-db2i.getObjectLocks",
"title": "Get Object Locks",
"category": "Db2 for i"
},
{
"command": "vscode-db2i.clearData",
"title": "Clear...",
Expand Down Expand Up @@ -167,6 +172,11 @@
"when": "viewItem == table || viewItem == view || viewItem == alias || viewItem == constraint || viewItem == function || viewItem == variable || viewItem == index || viewItem == procedure || viewItem == sequence || viewItem == package || viewItem == trigger || viewItem == type",
"group": "db2workWith@4"
},
{
"command": "vscode-db2i.getObjectLocks",
"when": "viewItem == table || viewItem == view || viewItem == alias || viewItem == function || viewItem == variable || viewItem == index || viewItem == procedure || viewItem == sequence || viewItem == package || viewItem == trigger || viewItem == type",
"group": "db2workWith@5"
},
{
"command": "vscode-db2i.clearData",
"when": "viewItem == table",
Expand Down
15 changes: 13 additions & 2 deletions src/views/schemaBrowser/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Configuration from "../../configuration";
import Types from "../types";
import Statement from "../../database/statement";
import { getCopyUi } from "./copyUI";
import { getAdvisedIndexesStatement, getIndexesStatement, getMTIStatement, getAuthoritiesStatement } from "./statements";
import { getAdvisedIndexesStatement, getIndexesStatement, getMTIStatement, getAuthoritiesStatement, getObjectLocksStatement } from "./statements";

const viewItem = {
"tables": `table`,
Expand Down Expand Up @@ -197,7 +197,18 @@ export default class schemaBrowser {
});
}
}),


vscode.commands.registerCommand(`vscode-db2i.getObjectLocks`, async (object: SQLObject) => {
if (object) {
const content = getObjectLocksStatement(object.schema, object.name, object.type.toUpperCase(), object.tableType);
vscode.commands.executeCommand(`vscode-db2i.runEditorStatement`, {
content,
qualifier: `statement`,
open: false,
});
}
}),

vscode.commands.registerCommand(`vscode-db2i.advisedIndexes`, async (object: SQLObject|SchemaItem) => { //table
if (object) {
let content: string|undefined;
Expand Down
35 changes: 34 additions & 1 deletion src/views/schemaBrowser/statements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,40 @@ export function getAuthoritiesStatement(schema: string, table: string, objectTyp
if (objectType === 'TABLE' && tableType != 'T') {
sql += ` and object_type = '*FILE'`;
} else {
sql += ` and sql_object_type = '${objectType}'`;
sql += ` and sql_object_type = '${objectType}'`;
}
return sql;
}

export function getObjectLocksStatement(schema: string, table: string, objectType: string, tableType: string): string {
let sql: string = `
select
system_table_member "Member",
member_lock_type "Member Lock Type",
lock_state "Lock State",
lock_status "Lock Status",
lock_scope "Scope",
substr(job_name, locate_in_string(job_name, '/', -1) + 1) "Job Name",
substr(job_name, locate_in_string(job_name, '/', 1) + 1, locate_in_string(job_name, '/', -1) - locate_in_string(job_name, '/', 1) - 1) "Job User",
substr(job_name, 1, locate_in_string(job_name, '/', 1) - 1) "Job Number",
thread_id "Thread",
lock_space_id "Lock Space",
lock_count "Lock Count",
program_library_name "Program Library",
program_name "Program Name",
module_library_name "Module Library",
module_name "Module Name",
procedure_name "Procedure Name",
statement_id "Statement ID",
machine_instruction "Instruction"
from qsys2.object_lock_info
where object_schema = '${schema}'
and object_name = '${table}'
`;
if (objectType === 'TABLE' && tableType != 'T') {
sql += ` and object_type = '*FILE'`;
} else {
sql += ` and sql_object_type = '${objectType.toUpperCase()}'`;
}
return sql;
}

0 comments on commit 7cc1671

Please sign in to comment.