Commit dde99e52 authored by Ajit Deshmukh's avatar Ajit Deshmukh

Updated the condition for creating functions, procedures, views, and sequences.

Updated the code to resolve the issue of duplicate SQL log screen entries with the same schema name
parent b4daf2d8
......@@ -326,13 +326,71 @@ public class ManageSqlConf extends ActionHandlerEJB
}
if ("A".equalsIgnoreCase(execRights))
{
BaseLogger.log("3", null, null, "multiple schema execution for provided enterprise:: oracleStatment::" + oracleStatment + " enterprise:: "+selectedEnterprise+ "]");//Added by Ashish.J
processSqlForEnterprise(con, selectedEnterprise, oracleStatment, tranId, linNo, requestID, userId, chgTerm);
if ("A".equalsIgnoreCase(execRights)) {
BaseLogger.log(
"3",
null,
null,
"Multiple schema execution :: SQL :: " + oracleStatment +
" :: enterprises :: [" + selectedEnterprise + "]"
);
// VERY IMPORTANT
con.setAutoCommit(false);
String[] enterpriseArr = selectedEnterprise.split(",");
for (String enterpriseForExec : enterpriseArr) {
String ent = enterpriseForExec.trim();
if (ent.isEmpty()) {
continue;
}
Savepoint entSavepoint = null;
try {
// ✅ ENTERPRISE-LEVEL SAVEPOINT
entSavepoint = con.setSavepoint("SP_" + ent);
processSqlForEnterprise(
con,
ent,
oracleStatment,
tranId,
linNo,
requestID,
userId,
chgTerm
);
// ✅ commit enterprise success
con.commit();
} catch (Exception e) {
// ❌ rollback ONLY this enterprise
if (entSavepoint != null) {
con.rollback(entSavepoint);
}
BaseLogger.log(
"1",
null,
null,
"Enterprise execution failed :: " + ent + " :: " + e.getMessage()
);
// continue next enterprise
}
}
continue;
}
//if( oracleStatment.toUpperCase().startsWith("ALTER") || oracleStatment.toUpperCase().startsWith("INSERT INTO") || oracleStatment.toUpperCase().startsWith("UPDATE") || oracleStatment.toUpperCase().startsWith("DELETE"))
//{
......@@ -753,6 +811,8 @@ public class ManageSqlConf extends ActionHandlerEJB
try
{
System.out.println("inside try of method");
System.out.println("Sql_log SQL :: "+Sql);
GenericUtility genericUtility = GenericUtility.getInstance();
String Aformat= genericUtility.getApplDateFormat();
java.text.SimpleDateFormat dtf= new java.text.SimpleDateFormat(Aformat);
......@@ -1317,7 +1377,7 @@ public class ManageSqlConf extends ActionHandlerEJB
public void processSqlForEnterprise(Connection conn, String enterpriseCode, String inputSql, String tranId, String linNo, String requestID, String userId, String chgTerm) throws Exception {
inputSql = injectSchemaPlaceholder(inputSql);
System.out.println("inputSqllklklk ::::::::" + inputSql);
System.out.println("inputSqllklklk ::::::::>>>>>" + inputSql);
/* -------------------------------
* Fetch schemas
......@@ -1370,7 +1430,6 @@ public class ManageSqlConf extends ActionHandlerEJB
if (rule.equals("ALL")) {
executeAndLog(
conn,
schemaName,
inputSql,
tranId,
......@@ -1390,7 +1449,6 @@ public class ManageSqlConf extends ActionHandlerEJB
" FOR " + dbMain + "." + objectName;
executeAndLog(
conn,
schemaName,
synonymSql,
tranId,
......@@ -1413,7 +1471,6 @@ public class ManageSqlConf extends ActionHandlerEJB
if (grantSql != null) {
executeAndLog(
conn,
schemaName,
grantSql,
tranId,
......@@ -1440,7 +1497,6 @@ public class ManageSqlConf extends ActionHandlerEJB
}
executeAndLog(
conn,
schemaName,
inputSql,
tranId,
......@@ -1450,7 +1506,7 @@ public class ManageSqlConf extends ActionHandlerEJB
userId,
chgTerm,
dbMain,
true
false
);
}
......@@ -1461,7 +1517,6 @@ public class ManageSqlConf extends ActionHandlerEJB
private void executeAndLog(
Connection conn,
String schemaName,
String inputSql,
String tranId,
......@@ -1472,9 +1527,14 @@ public class ManageSqlConf extends ActionHandlerEJB
String chgTerm,
String dbMainSchema,
boolean rethrow
) {
) throws Exception {
Connection conn = null;
ConnDriver connDriver = new ConnDriver();
conn = connDriver.getConnectDB(schemaName);
String finalSql = applySchema(inputSql, schemaName);
System.out.println("finalSql:: "+finalSql);
System.out.println("schemaName:: "+schemaName);
int updCount = 0;
String error = null;
......@@ -1482,6 +1542,7 @@ public class ManageSqlConf extends ActionHandlerEJB
updCount = stmt.executeUpdate(finalSql);
conn.commit();
logSqlExecution(
tranId, enterpriseCode, linNo, requestID,
finalSql, updCount, "C", userId, chgTerm, null,dbMainSchema
......@@ -1489,6 +1550,12 @@ public class ManageSqlConf extends ActionHandlerEJB
} catch (SQLException e) {
try {
conn.rollback();
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
error = e.getMessage();
logSqlExecution(
......@@ -1519,10 +1586,8 @@ public class ManageSqlConf extends ActionHandlerEJB
Connection logConn = null;
try {
ConnDriver connDriver = new ConnDriver();
// ✅ Always log using MAIN / APP schema
logConn = connDriver.getConnectDB("APPVIS");
logConn = getConnection();
logConn.setAutoCommit(true);
insertIntoSqlExectionLog(
......@@ -1555,15 +1620,19 @@ public class ManageSqlConf extends ActionHandlerEJB
if (sql == null) return null;
// Normalize
// Normalize whitespace
String s = sql.replace("\n", " ")
.replace("\t", " ")
.trim()
.toUpperCase();
// Remove multiple spaces
s = s.replaceAll("\\s+", " ");
// IMPORTANT: normalize CREATE OR REPLACE
if (s.startsWith("CREATE OR REPLACE")) {
s = s.replaceFirst("CREATE\\s+OR\\s+REPLACE\\s+", "CREATE ");
}
String objectType = getCreateObjectType(s);
if (objectType == null) return null;
......@@ -1608,13 +1677,13 @@ public class ManageSqlConf extends ActionHandlerEJB
after = after.substring(after.indexOf(".") + 1);
}
// Stop at first delimiter
// (, AS, IS
// Stop at first delimiter: space, (, 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
......@@ -1658,8 +1727,16 @@ public class ManageSqlConf extends ActionHandlerEJB
private String getCreateObjectType(String sql) {
if (sql == null) return null;
String s = sql.trim().toUpperCase();
// 🔴 Normalize CREATE OR REPLACE
if (s.startsWith("CREATE OR REPLACE")) {
s = s.replaceFirst("CREATE\\s+OR\\s+REPLACE\\s+", "CREATE ");
}
if (s.startsWith("CREATE TABLE")) return "TABLE";
if (s.startsWith("CREATE SEQUENCE")) return "SEQUENCE";
if (s.startsWith("CREATE TYPE")) return "TYPE";
......@@ -1672,6 +1749,8 @@ public class ManageSqlConf extends ActionHandlerEJB
return null;
}
private String applySchema(String sql, String schema) {
String s = sql.trim();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment