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
f5e149d0
Commit
f5e149d0
authored
Dec 16, 2025
by
Ajit Deshmukh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Replace ManageSqlConf.java
parent
d166049d
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
144 additions
and
56 deletions
+144
-56
Ajit/Manage SQL/Manage SQL/ManageSqlConf.java
Ajit/Manage SQL/Manage SQL/ManageSqlConf.java
+144
-56
No files found.
Ajit/Manage SQL/Manage SQL/ManageSqlConf.java
View file @
f5e149d0
...
...
@@ -328,8 +328,8 @@ public class ManageSqlConf extends ActionHandlerEJB
if
(
"A"
.
equalsIgnoreCase
(
execRights
))
{
BaseLogger
.
log
(
"3"
,
null
,
null
,
"multiple schema execution for provided enterprise:: oracleStatment::"
+
oracleStatment
+
" enterprise:: "
+
e
nterprise
+
"]"
);
//Added by Ashish.J
processSqlForEnterprise
(
con
,
e
nterprise
,
oracleStatment
);
BaseLogger
.
log
(
"3"
,
null
,
null
,
"multiple schema execution for provided enterprise:: oracleStatment::"
+
oracleStatment
+
" enterprise:: "
+
selectedE
nterprise
+
"]"
);
//Added by Ashish.J
processSqlForEnterprise
(
con
,
selectedE
nterprise
,
oracleStatment
);
continue
;
}
...
...
@@ -1317,7 +1317,7 @@ public class ManageSqlConf extends ActionHandlerEJB
public
void
processSqlForEnterprise
(
Connection
conn
,
String
enterpriseCode
,
String
inputSql
)
throws
Exception
{
inputSql
=
injectSchemaPlaceholder
(
inputSql
);
System
.
out
.
println
(
"inputSql :"
+
inputSql
);
System
.
out
.
println
(
"inputSql :
:::::::
"
+
inputSql
);
// Step 1: Fetch schemas
String
query
=
"SELECT DB_DEV, DB_MAIN, DB_READ, DB_PILOT FROM enterprise WHERE enterprise = ?"
;
...
...
@@ -1344,12 +1344,12 @@ public class ManageSqlConf extends ActionHandlerEJB
schemaRules
.
put
(
dbRead
,
"SYN"
);
schemaRules
.
put
(
dbPilot
,
"SYN"
);
boolean
isCreateTable
=
inputSql
.
trim
().
toUpperCase
().
startsWith
(
"CREATE TABLE"
);
String
createObjectType
=
getCreateObjectType
(
inputSql
);
boolean
isCreateObject
=
createObjectType
!=
null
;
// Extract table name from CREATE TABLE SCHEMA.TABLE pattern
String
tableName
=
null
;
if
(
isCreateTable
)
{
tableName
=
extractTableName
(
inputSql
);
String
objectName
=
null
;
if
(
isCreateObject
)
{
objectName
=
extractObjectName
(
inputSql
);
}
// Step 3: Execute based on rule
...
...
@@ -1361,51 +1361,48 @@ public class ManageSqlConf extends ActionHandlerEJB
if
(
schemaName
==
null
||
schemaName
.
trim
().
isEmpty
())
continue
;
if
(
isCreateTable
)
{
// ===========================
// SPECIAL LOGIC FOR CREATE TABLE
// ===========================
if
(
isCreateObject
)
{
if
(
rule
.
equals
(
"ALL"
))
{
// Execute CREATE TABLE normally for MAIN + DEV
String
finalSql
=
inputSql
.
replace
(
"{SCHEMA}"
,
schemaName
);
System
.
out
.
println
(
"Executing CREATE TABLE for schema: "
+
schemaName
);
String
finalSql
=
applySchema
(
inputSql
,
schemaName
);
System
.
out
.
println
(
"Executing for schema: "
+
schemaName
);
System
.
out
.
println
(
"SQL: "
+
finalSql
);
try
(
Statement
stmt
=
conn
.
createStatement
())
{
stmt
.
execute
(
finalSql
);
}
}
else
if
(
rule
.
equals
(
"SYN"
))
{
// READ / PILOT special handling:
System
.
out
.
println
(
"Processing CREATE TABLE special logic for schema: "
+
schemaName
);
System
.
out
.
println
(
"Processing CREATE "
+
createObjectType
+
" special logic for schema: "
+
schemaName
);
// 1. Create Synonym
String
synonymSql
=
"CREATE SYNONYM "
+
schemaName
+
"."
+
table
Name
+
" FOR "
+
dbMain
+
"."
+
table
Name
;
"CREATE SYNONYM "
+
schemaName
+
"."
+
object
Name
+
" FOR "
+
dbMain
+
"."
+
object
Name
;
System
.
out
.
println
(
"SQL: "
+
synonymSql
);
try
(
Statement
stmt
=
conn
.
createStatement
())
{
stmt
.
execute
(
synonymSql
);
}
// 2. Grant Privileges
String
grantSql
=
""
;
// 2. Grant privileges (only where applicable)
String
grantSql
=
null
;
if
(
schemaName
.
equals
(
dbRead
))
{
grantSql
=
"GRANT SELECT ON "
+
dbMain
+
"."
+
tableName
+
" TO "
+
dbRead
;
grantSql
=
"GRANT SELECT ON "
+
dbMain
+
"."
+
objectName
+
" TO "
+
dbRead
;
}
else
if
(
schemaName
.
equals
(
dbPilot
))
{
grantSql
=
"GRANT INSERT, UPDATE, DELETE ON "
+
dbMain
+
"."
+
tableName
+
" TO "
+
dbPilot
;
grantSql
=
"GRANT EXECUTE ON "
+
dbMain
+
"."
+
objectName
+
" TO "
+
dbPilot
;
}
if
(
grantSql
!=
null
)
{
System
.
out
.
println
(
"SQL: "
+
grantSql
);
try
(
Statement
stmt
=
conn
.
createStatement
())
{
stmt
.
execute
(
grantSql
);
}
}
}
continue
;
// skip normal execution
}
...
...
@@ -1421,7 +1418,7 @@ public class ManageSqlConf extends ActionHandlerEJB
}
}
String
finalSql
=
inputSql
.
replace
(
"{SCHEMA}"
,
schemaName
);
String
finalSql
=
applySchema
(
inputSql
,
schemaName
);
System
.
out
.
println
(
"Executing for schema: "
+
schemaName
);
System
.
out
.
println
(
"SQL: "
+
finalSql
);
...
...
@@ -1435,28 +1432,70 @@ 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 -- END
//Created a method to fetch the table name from provided SQL string by Ajit on 03-DEC-25 -- START
private
String
extractTableName
(
String
sql
)
{
sql
=
sql
.
replace
(
"\n"
,
" "
).
replace
(
"\t"
,
" "
);
sql
=
sql
.
toUpperCase
();
// Expected: CREATE TABLE {SCHEMA}.TABLE_NAME
int
idx
=
sql
.
indexOf
(
"CREATE TABLE"
);
private
String
extractObjectName
(
String
sql
)
{
if
(
sql
==
null
)
return
null
;
// Normalize
String
s
=
sql
.
replace
(
"\n"
,
" "
)
.
replace
(
"\t"
,
" "
)
.
trim
()
.
toUpperCase
();
// Remove multiple spaces
s
=
s
.
replaceAll
(
"\\s+"
,
" "
);
String
objectType
=
getCreateObjectType
(
s
);
if
(
objectType
==
null
)
return
null
;
String
keyword
;
switch
(
objectType
)
{
case
"TABLE"
:
keyword
=
"CREATE TABLE"
;
break
;
case
"SEQUENCE"
:
keyword
=
"CREATE SEQUENCE"
;
break
;
case
"TYPE"
:
keyword
=
"CREATE TYPE"
;
break
;
case
"FUNCTION"
:
keyword
=
"CREATE FUNCTION"
;
break
;
case
"PROCEDURE"
:
keyword
=
"CREATE PROCEDURE"
;
break
;
case
"PACKAGE BODY"
:
keyword
=
"CREATE PACKAGE BODY"
;
break
;
case
"PACKAGE"
:
keyword
=
"CREATE PACKAGE"
;
break
;
case
"VIEW"
:
keyword
=
"CREATE VIEW"
;
break
;
default
:
return
null
;
}
int
idx
=
s
.
indexOf
(
keyword
);
if
(
idx
==
-
1
)
return
null
;
String
after
=
s
ql
.
substring
(
idx
+
"CREATE TABLE"
.
length
()).
trim
();
String
after
=
s
.
substring
(
idx
+
keyword
.
length
()).
trim
();
// Remove schema
// Remove schema
if present (SCHEMA.OBJECT)
if
(
after
.
contains
(
"."
))
{
after
=
after
.
substring
(
after
.
indexOf
(
"."
)
+
1
)
.
trim
()
;
after
=
after
.
substring
(
after
.
indexOf
(
"."
)
+
1
);
}
// Remove ( column definitions
if
(
after
.
contains
(
"("
))
{
after
=
after
.
substring
(
0
,
after
.
indexOf
(
"("
)).
trim
();
}
// Stop at first delimiter
// (, AS, IS
after
=
after
.
split
(
"\\s|\\(|AS|IS"
,
2
)[
0
].
trim
();
return
after
;
}
//Created a method to fetch the table name from provided SQL string 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 -- START
...
...
@@ -1474,4 +1513,53 @@ 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 -- END
private
String
getCreateObjectType
(
String
sql
)
{
String
s
=
sql
.
trim
().
toUpperCase
();
if
(
s
.
startsWith
(
"CREATE TABLE"
))
return
"TABLE"
;
if
(
s
.
startsWith
(
"CREATE SEQUENCE"
))
return
"SEQUENCE"
;
if
(
s
.
startsWith
(
"CREATE TYPE"
))
return
"TYPE"
;
if
(
s
.
startsWith
(
"CREATE FUNCTION"
))
return
"FUNCTION"
;
if
(
s
.
startsWith
(
"CREATE PROCEDURE"
))
return
"PROCEDURE"
;
if
(
s
.
startsWith
(
"CREATE PACKAGE BODY"
))
return
"PACKAGE BODY"
;
if
(
s
.
startsWith
(
"CREATE PACKAGE"
))
return
"PACKAGE"
;
if
(
s
.
startsWith
(
"CREATE VIEW"
))
return
"VIEW"
;
return
null
;
}
private
String
applySchema
(
String
sql
,
String
schema
)
{
String
s
=
sql
.
trim
();
// CREATE TABLE
if
(
s
.
toUpperCase
().
startsWith
(
"CREATE TABLE"
))
{
return
s
.
replaceFirst
(
"(?i)CREATE\\s+TABLE\\s+"
,
"CREATE TABLE "
+
schema
+
"."
);
}
// CREATE VIEW
if
(
s
.
toUpperCase
().
startsWith
(
"CREATE VIEW"
))
{
return
s
.
replaceFirst
(
"(?i)CREATE\\s+VIEW\\s+"
,
"CREATE VIEW "
+
schema
+
"."
);
}
// CREATE SEQUENCE
if
(
s
.
toUpperCase
().
startsWith
(
"CREATE SEQUENCE"
))
{
return
s
.
replaceFirst
(
"(?i)CREATE\\s+SEQUENCE\\s+"
,
"CREATE SEQUENCE "
+
schema
+
"."
);
}
// fallback
return
sql
;
}
}
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