Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
Component Sharing
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
CI / CD Analytics
Repository Analytics
Value Stream Analytics
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Gagandeep Singh Bhatia
Component Sharing
Commits
30b90110
Commit
30b90110
authored
Dec 19, 2025
by
Ajit Deshmukh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updated the code for SQL Log entry for Admin-level transaction approval.
Updated the case for create function query.
parent
f5e149d0
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
271 additions
and
82 deletions
+271
-82
Ajit/Manage SQL/Manage SQL/ManageSqlConf.java
Ajit/Manage SQL/Manage SQL/ManageSqlConf.java
+271
-82
No files found.
Ajit/Manage SQL/Manage SQL/ManageSqlConf.java
View file @
30b90110
...
@@ -329,7 +329,7 @@ public class ManageSqlConf extends ActionHandlerEJB
...
@@ -329,7 +329,7 @@ public class ManageSqlConf extends ActionHandlerEJB
if
(
"A"
.
equalsIgnoreCase
(
execRights
))
if
(
"A"
.
equalsIgnoreCase
(
execRights
))
{
{
BaseLogger
.
log
(
"3"
,
null
,
null
,
"multiple schema execution for provided enterprise:: oracleStatment::"
+
oracleStatment
+
" enterprise:: "
+
selectedEnterprise
+
"]"
);
//Added by Ashish.J
BaseLogger
.
log
(
"3"
,
null
,
null
,
"multiple schema execution for provided enterprise:: oracleStatment::"
+
oracleStatment
+
" enterprise:: "
+
selectedEnterprise
+
"]"
);
//Added by Ashish.J
processSqlForEnterprise
(
con
,
selectedEnterprise
,
oracleStatment
);
processSqlForEnterprise
(
con
,
selectedEnterprise
,
oracleStatment
,
tranId
,
linNo
,
requestID
,
userId
,
chgTerm
);
continue
;
continue
;
}
}
...
@@ -1314,12 +1314,14 @@ public class ManageSqlConf extends ActionHandlerEJB
...
@@ -1314,12 +1314,14 @@ public class ManageSqlConf extends ActionHandlerEJB
//Created a method to execute the SQL in the schemas stored in the Enterprise table for the provided enterprise value by Ajit on 03-DEC-25 -- START
//Created a method to execute the SQL in the schemas stored in the Enterprise table for the provided enterprise value by Ajit on 03-DEC-25 -- START
public
void
processSqlForEnterprise
(
Connection
conn
,
String
enterpriseCode
,
String
inputSql
)
throws
Exception
{
public
void
processSqlForEnterprise
(
Connection
conn
,
String
enterpriseCode
,
String
inputSql
,
String
tranId
,
String
linNo
,
String
requestID
,
String
userId
,
String
chgTerm
)
throws
Exception
{
inputSql
=
injectSchemaPlaceholder
(
inputSql
);
inputSql
=
injectSchemaPlaceholder
(
inputSql
);
System
.
out
.
println
(
"inputSql ::::::::"
+
inputSql
);
System
.
out
.
println
(
"inputSql
lklklk
::::::::"
+
inputSql
);
// Step 1: Fetch schemas
/* -------------------------------
* Fetch schemas
* ------------------------------- */
String
query
=
"SELECT DB_DEV, DB_MAIN, DB_READ, DB_PILOT FROM enterprise WHERE enterprise = ?"
;
String
query
=
"SELECT DB_DEV, DB_MAIN, DB_READ, DB_PILOT FROM enterprise WHERE enterprise = ?"
;
PreparedStatement
ps
=
conn
.
prepareStatement
(
query
);
PreparedStatement
ps
=
conn
.
prepareStatement
(
query
);
ps
.
setString
(
1
,
enterpriseCode
);
ps
.
setString
(
1
,
enterpriseCode
);
...
@@ -1337,7 +1339,9 @@ public class ManageSqlConf extends ActionHandlerEJB
...
@@ -1337,7 +1339,9 @@ public class ManageSqlConf extends ActionHandlerEJB
rs
.
close
();
rs
.
close
();
ps
.
close
();
ps
.
close
();
// Step 2: Schema execution rules
/* -------------------------------
* Schema execution rules
* ------------------------------- */
Map
<
String
,
String
>
schemaRules
=
new
LinkedHashMap
<>();
Map
<
String
,
String
>
schemaRules
=
new
LinkedHashMap
<>();
schemaRules
.
put
(
dbMain
,
"ALL"
);
schemaRules
.
put
(
dbMain
,
"ALL"
);
schemaRules
.
put
(
dbDev
,
"ALL"
);
schemaRules
.
put
(
dbDev
,
"ALL"
);
...
@@ -1346,13 +1350,11 @@ public class ManageSqlConf extends ActionHandlerEJB
...
@@ -1346,13 +1350,11 @@ public class ManageSqlConf extends ActionHandlerEJB
String
createObjectType
=
getCreateObjectType
(
inputSql
);
String
createObjectType
=
getCreateObjectType
(
inputSql
);
boolean
isCreateObject
=
createObjectType
!=
null
;
boolean
isCreateObject
=
createObjectType
!=
null
;
String
objectName
=
isCreateObject
?
extractObjectName
(
inputSql
)
:
null
;
String
objectName
=
null
;
/* -------------------------------
if
(
isCreateObject
)
{
* Execute per schema
objectName
=
extractObjectName
(
inputSql
);
* ------------------------------- */
}
// Step 3: Execute based on rule
for
(
Map
.
Entry
<
String
,
String
>
entry
:
schemaRules
.
entrySet
())
{
for
(
Map
.
Entry
<
String
,
String
>
entry
:
schemaRules
.
entrySet
())
{
String
schemaName
=
entry
.
getKey
();
String
schemaName
=
entry
.
getKey
();
...
@@ -1361,75 +1363,192 @@ public class ManageSqlConf extends ActionHandlerEJB
...
@@ -1361,75 +1363,192 @@ public class ManageSqlConf extends ActionHandlerEJB
if
(
schemaName
==
null
||
schemaName
.
trim
().
isEmpty
())
if
(
schemaName
==
null
||
schemaName
.
trim
().
isEmpty
())
continue
;
continue
;
/* =====================================
* CREATE / DDL FLOW
* ===================================== */
if
(
isCreateObject
)
{
if
(
isCreateObject
)
{
if
(
rule
.
equals
(
"ALL"
))
{
if
(
rule
.
equals
(
"ALL"
))
{
String
finalSql
=
applySchema
(
inputSql
,
schemaName
);
executeAndLog
(
System
.
out
.
println
(
"Executing for schema: "
+
schemaName
);
conn
,
System
.
out
.
println
(
"SQL: "
+
finalSql
);
schemaName
,
try
(
Statement
stmt
=
conn
.
createStatement
())
{
inputSql
,
stmt
.
execute
(
finalSql
);
tranId
,
}
enterpriseCode
,
linNo
,
requestID
,
userId
,
chgTerm
,
dbMain
,
true
);
}
}
else
if
(
rule
.
equals
(
"SYN"
))
{
else
if
(
rule
.
equals
(
"SYN"
))
{
System
.
out
.
println
(
"Processing CREATE "
+
createObjectType
+
" special logic for schema: "
+
schemaName
);
// 1. Create Synonym
String
synonymSql
=
String
synonymSql
=
"CREATE SYNONYM "
+
schemaName
+
"."
+
objectName
+
"CREATE SYNONYM "
+
schemaName
+
"."
+
objectName
+
" FOR "
+
dbMain
+
"."
+
objectName
;
" FOR "
+
dbMain
+
"."
+
objectName
;
System
.
out
.
println
(
"SQL: "
+
synonymSql
);
executeAndLog
(
try
(
Statement
stmt
=
conn
.
createStatement
())
{
conn
,
stmt
.
execute
(
synonymSql
);
schemaName
,
}
synonymSql
,
tranId
,
enterpriseCode
,
linNo
,
requestID
,
userId
,
chgTerm
,
dbMain
,
false
);
// 2. Grant privileges (only where applicable)
String
grantSql
=
null
;
String
grantSql
=
null
;
if
(
schemaName
.
equals
(
dbRead
))
{
if
(
schemaName
.
equals
(
dbRead
))
{
grantSql
=
"GRANT SELECT ON "
+
dbMain
+
"."
+
objectName
+
" TO "
+
dbRead
;
grantSql
=
"GRANT SELECT ON "
+
dbMain
+
"."
+
objectName
+
" TO "
+
dbRead
;
}
}
else
if
(
schemaName
.
equals
(
dbPilot
))
{
else
if
(
schemaName
.
equals
(
dbPilot
))
{
grantSql
=
"GRANT EXECUTE ON "
+
dbMain
+
"."
+
objectName
+
" TO "
+
dbPilot
;
grantSql
=
"GRANT EXECUTE ON "
+
dbMain
+
"."
+
objectName
+
" TO "
+
dbPilot
;
}
}
if
(
grantSql
!=
null
)
{
if
(
grantSql
!=
null
)
{
System
.
out
.
println
(
"SQL: "
+
grantSql
);
executeAndLog
(
try
(
Statement
stmt
=
conn
.
createStatement
())
{
conn
,
stmt
.
execute
(
grantSql
);
schemaName
,
}
grantSql
,
tranId
,
enterpriseCode
,
linNo
,
requestID
,
userId
,
chgTerm
,
dbMain
,
false
);
}
}
}
}
continue
;
// skip
normal execution
continue
;
// skip
DML flow
}
}
/
/
===========================
/
* ==========
===========================
// Normal Flow (non CREATE TABLE)
* INSERT / UPDATE / DELETE FLOW
// ===========================
* ===================================== */
if
(
rule
.
equals
(
"SYN"
))
{
if
(
rule
.
equals
(
"SYN"
))
{
// Only allow CREATE SYNONYM
boolean
isSynonymSql
=
inputSql
.
trim
().
toUpperCase
().
startsWith
(
"CREATE SYNONYM"
);
if
(!
isSynonymSql
)
{
System
.
out
.
println
(
"Skipping SQL for schema (only SYN allowed): "
+
schemaName
);
System
.
out
.
println
(
"Skipping SQL for schema (only SYN allowed): "
+
schemaName
);
continue
;
continue
;
}
}
executeAndLog
(
conn
,
schemaName
,
inputSql
,
tranId
,
enterpriseCode
,
linNo
,
requestID
,
userId
,
chgTerm
,
dbMain
,
true
);
}
}
System
.
out
.
println
(
"Execution completed successfully."
);
}
//Created a method to execute the SQL in the schemas stored in the Enterprise table for the provided enterprise value by Ajit on 03-DEC-25 -- END
private
void
executeAndLog
(
Connection
conn
,
String
schemaName
,
String
inputSql
,
String
tranId
,
String
enterpriseCode
,
String
linNo
,
String
requestID
,
String
userId
,
String
chgTerm
,
String
dbMainSchema
,
boolean
rethrow
)
{
String
finalSql
=
applySchema
(
inputSql
,
schemaName
);
String
finalSql
=
applySchema
(
inputSql
,
schemaName
);
System
.
out
.
println
(
"Executing for schema: "
+
schemaName
)
;
int
updCount
=
0
;
System
.
out
.
println
(
"SQL: "
+
finalSql
)
;
String
error
=
null
;
try
(
Statement
stmt
=
conn
.
createStatement
())
{
try
(
Statement
stmt
=
conn
.
createStatement
())
{
stmt
.
execute
(
finalSql
);
updCount
=
stmt
.
executeUpdate
(
finalSql
);
logSqlExecution
(
tranId
,
enterpriseCode
,
linNo
,
requestID
,
finalSql
,
updCount
,
"C"
,
userId
,
chgTerm
,
null
,
dbMainSchema
);
}
catch
(
SQLException
e
)
{
error
=
e
.
getMessage
();
logSqlExecution
(
tranId
,
enterpriseCode
,
linNo
,
requestID
,
finalSql
,
updCount
,
"E"
,
userId
,
chgTerm
,
error
,
dbMainSchema
);
if
(
rethrow
)
{
throw
new
RuntimeException
(
e
);
}
}
}
}
}
System
.
out
.
println
(
"Execution completed successfully."
);
private
void
logSqlExecution
(
String
tranId
,
String
enterpriseCode
,
String
linNo
,
String
requestID
,
String
sql
,
int
updCount
,
String
status
,
String
userId
,
String
chgTerm
,
String
error
,
String
schemaName
)
{
Connection
logConn
=
null
;
try
{
ConnDriver
connDriver
=
new
ConnDriver
();
// ✅ Always log using MAIN / APP schema
logConn
=
connDriver
.
getConnectDB
(
"APPVIS"
);
logConn
.
setAutoCommit
(
true
);
insertIntoSqlExectionLog
(
logConn
,
tranId
,
enterpriseCode
,
linNo
,
requestID
,
sql
,
updCount
,
status
,
userId
,
chgTerm
,
error
);
}
catch
(
Exception
ex
)
{
System
.
out
.
println
(
"SQL LOGGING FAILED: "
+
ex
.
getMessage
());
ex
.
printStackTrace
();
}
finally
{
try
{
if
(
logConn
!=
null
)
logConn
.
close
();
}
catch
(
Exception
ignore
)
{}
}
}
//Created a method to execute the SQL in the schemas stored in the Enterprise table for the provided enterprise value by Ajit on 03-DEC-25 -- END
}
//Created a method to fetch the table name from provided SQL string by Ajit on 03-DEC-25 -- START
//Created a method to fetch the table name from provided SQL string by Ajit on 03-DEC-25 -- START
private
String
extractObjectName
(
String
sql
)
{
private
String
extractObjectName
(
String
sql
)
{
...
@@ -1500,17 +1619,41 @@ public class ManageSqlConf extends ActionHandlerEJB
...
@@ -1500,17 +1619,41 @@ public class ManageSqlConf extends ActionHandlerEJB
//Created a method to add a placeholder before the table name which will be replaced by the schema name by Ajit on 03-DEC-25 -- START
//Created a method to add a placeholder before the table name which will be replaced by the schema name by Ajit on 03-DEC-25 -- START
public
static
String
injectSchemaPlaceholder
(
String
sql
)
{
public
static
String
injectSchemaPlaceholder
(
String
sql
)
{
String
trimmed
=
sql
.
trim
().
toUpperCase
();
// For CREATE SYNONYM → It already contains schema explicitly
String
s
=
sql
.
trim
();
if
(
trimmed
.
startsWith
(
"CREATE SYNONYM"
))
{
return
sql
;
// Do NOT modify
// Skip CREATE SYNONYM
if
(
s
.
toUpperCase
().
startsWith
(
"CREATE SYNONYM"
))
{
return
sql
;
}
}
// Patterns: UPDATE table, DELETE FROM table, INSERT INTO table
// INSERT INTO table
String
regex
=
"(UPDATE|INTO|FROM)\\s+([A-Za-z0-9_]+)"
;
s
=
s
.
replaceAll
(
return
sql
.
replaceAll
(
regex
,
"$1 {SCHEMA}.$2"
);
"(?i)INSERT\\s+INTO\\s+(?!\\{SCHEMA\\}|[A-Z0-9_]+\\.)"
,
"INSERT INTO {SCHEMA}."
);
// UPDATE table
s
=
s
.
replaceAll
(
"(?i)UPDATE\\s+(?!\\{SCHEMA\\}|[A-Z0-9_]+\\.)"
,
"UPDATE {SCHEMA}."
);
// DELETE FROM table
s
=
s
.
replaceAll
(
"(?i)DELETE\\s+FROM\\s+(?!\\{SCHEMA\\}|[A-Z0-9_]+\\.)"
,
"DELETE FROM {SCHEMA}."
);
// SELECT ... FROM table
s
=
s
.
replaceAll
(
"(?i)FROM\\s+(?!\\{SCHEMA\\}|[A-Z0-9_]+\\.)"
,
"FROM {SCHEMA}."
);
return
s
;
}
}
//Created a method to add a placeholder before the table name which will be replaced by the schema name by Ajit on 03-DEC-25 -- END
//Created a method to add a placeholder before the table name which will be replaced by the schema name by Ajit on 03-DEC-25 -- END
...
@@ -1533,33 +1676,79 @@ public class ManageSqlConf extends ActionHandlerEJB
...
@@ -1533,33 +1676,79 @@ public class ManageSqlConf extends ActionHandlerEJB
String
s
=
sql
.
trim
();
String
s
=
sql
.
trim
();
// Replace placeholder first (DML)
if
(
s
.
contains
(
"{SCHEMA}"
))
{
s
=
s
.
replace
(
"{SCHEMA}"
,
schema
);
}
// CREATE TABLE
// CREATE TABLE
if
(
s
.
toUpperCase
().
startsWith
(
"CREATE TABLE
"
))
{
if
(
s
.
matches
(
"(?is)^CREATE\\s+TABLE\\s+.*
"
))
{
return
s
.
replaceFirst
(
return
s
.
replaceFirst
(
"(?i)CREATE\\s+TABLE\\s+"
,
"(?i
s
)CREATE\\s+TABLE\\s+"
,
"CREATE TABLE "
+
schema
+
"."
"CREATE TABLE "
+
schema
+
"."
);
);
}
}
// CREATE VIEW
// CREATE VIEW
if
(
s
.
toUpperCase
().
startsWith
(
"CREATE VIEW
"
))
{
if
(
s
.
matches
(
"(?is)^CREATE\\s+(OR\\s+REPLACE\\s+)?VIEW\\s+.*
"
))
{
return
s
.
replaceFirst
(
return
s
.
replaceFirst
(
"(?i
)CREATE\\s+
VIEW\\s+"
,
"(?i
s)CREATE\\s+(OR\\s+REPLACE\\s+)?
VIEW\\s+"
,
"CREATE VIEW "
+
schema
+
"."
"CREATE
OR REPLACE
VIEW "
+
schema
+
"."
);
);
}
}
// CREATE SEQUENCE
// CREATE SEQUENCE
if
(
s
.
toUpperCase
().
startsWith
(
"CREATE SEQUENCE
"
))
{
if
(
s
.
matches
(
"(?is)^CREATE\\s+SEQUENCE\\s+.*
"
))
{
return
s
.
replaceFirst
(
return
s
.
replaceFirst
(
"(?i)CREATE\\s+SEQUENCE\\s+"
,
"(?i
s
)CREATE\\s+SEQUENCE\\s+"
,
"CREATE SEQUENCE "
+
schema
+
"."
"CREATE SEQUENCE "
+
schema
+
"."
);
);
}
}
// fallback
// CREATE FUNCTION
return
sql
;
if
(
s
.
matches
(
"(?is)^CREATE\\s+(OR\\s+REPLACE\\s+)?FUNCTION\\s+.*"
))
{
return
s
.
replaceFirst
(
"(?is)CREATE\\s+(OR\\s+REPLACE\\s+)?FUNCTION\\s+"
,
"CREATE OR REPLACE FUNCTION "
+
schema
+
"."
);
}
// CREATE PROCEDURE
if
(
s
.
matches
(
"(?is)^CREATE\\s+(OR\\s+REPLACE\\s+)?PROCEDURE\\s+.*"
))
{
return
s
.
replaceFirst
(
"(?is)CREATE\\s+(OR\\s+REPLACE\\s+)?PROCEDURE\\s+"
,
"CREATE OR REPLACE PROCEDURE "
+
schema
+
"."
);
}
}
// CREATE PACKAGE
if
(
s
.
matches
(
"(?is)^CREATE\\s+(OR\\s+REPLACE\\s+)?PACKAGE\\s+.*"
))
{
return
s
.
replaceFirst
(
"(?is)CREATE\\s+(OR\\s+REPLACE\\s+)?PACKAGE\\s+"
,
"CREATE OR REPLACE PACKAGE "
+
schema
+
"."
);
}
// CREATE PACKAGE BODY
if
(
s
.
matches
(
"(?is)^CREATE\\s+(OR\\s+REPLACE\\s+)?PACKAGE\\s+BODY\\s+.*"
))
{
return
s
.
replaceFirst
(
"(?is)CREATE\\s+(OR\\s+REPLACE\\s+)?PACKAGE\\s+BODY\\s+"
,
"CREATE OR REPLACE PACKAGE BODY "
+
schema
+
"."
);
}
// CREATE TYPE
if
(
s
.
matches
(
"(?is)^CREATE\\s+(OR\\s+REPLACE\\s+)?TYPE\\s+.*"
))
{
return
s
.
replaceFirst
(
"(?is)CREATE\\s+(OR\\s+REPLACE\\s+)?TYPE\\s+"
,
"CREATE OR REPLACE TYPE "
+
schema
+
"."
);
}
return
s
;
}
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment