Commit 9f499896 authored by Ajit Deshmukh's avatar Ajit Deshmukh

Rresolved the issue reported by the QC for duplicate records in SQL Log screen

parent f9a9cae0
...@@ -569,7 +569,6 @@ public class ManageSqlConf extends ActionHandlerEJB { ...@@ -569,7 +569,6 @@ public class ManageSqlConf extends ActionHandlerEJB {
BaseLogger.log("1", null, null, BaseLogger.log("1", null, null,
"Before Savepoint"); "Before Savepoint");
String sanitizedEnterprise = mainEnterprise.replaceAll("[^a-zA-Z0-9_]", ""); String sanitizedEnterprise = mainEnterprise.replaceAll("[^a-zA-Z0-9_]", "");
BaseLogger.log("1", null, null, BaseLogger.log("1", null, null,
"Savepoint Name :: SP_" + sanitizedEnterprise); "Savepoint Name :: SP_" + sanitizedEnterprise);
...@@ -626,17 +625,22 @@ public class ManageSqlConf extends ActionHandlerEJB { ...@@ -626,17 +625,22 @@ public class ManageSqlConf extends ActionHandlerEJB {
con.setAutoCommit(false); con.setAutoCommit(false);
// TO fetch the schemaName and enterprise for live[START] // TO fetch the schemaName and enterprise for live[START]
ArrayList<String> enterpriseArrayListForP = new ArrayList<>(); ArrayList<String> enterpriseArrayListForP = new ArrayList<>();
Connection entCon = null; Connection entCon = null;
ConnDriver connDriver = new ConnDriver(); ConnDriver connDriver = new ConnDriver();
entCon = connDriver.getConnectDB("Driver"); entCon = connDriver.getConnectDB("Driver");
ResultSet rsToFetchEntForP = null; ResultSet rsToFetchEntForP = null;
// Added by Gagan B. on 13-NOV-25 [make connection with Driver for ENTERPRISE] // Added by Gagan B. on 13-NOV-25 [make connection with Driver for ENTERPRISE]
// -- END // -- END
BaseLogger.log("1", null, null,
"enterpriser<><<> "+enterpriser);
String EnterPriseInFormat = getFormattedStringBuff(mainEnterprise); String EnterPriseInFormat = getFormattedStringBuff(mainEnterprise);
sql = "SELECT SCHEMA_NAME,ENTERPRISE FROM ENTERPRISE WHERE ENTERPRISE IN(" sql = "SELECT SCHEMA_NAME, ENTERPRISE " +
+ EnterPriseInFormat + ") "; "FROM ENTERPRISE " +
"WHERE ENTERPRISE = ?";
pstmt = entCon.prepareStatement(sql); pstmt = entCon.prepareStatement(sql);
pstmt.setString(1, enterpriser);
rsToFetchEntForP = pstmt.executeQuery(); rsToFetchEntForP = pstmt.executeQuery();
while (rsToFetchEntForP.next()) { while (rsToFetchEntForP.next()) {
// schemaName = checkNull( rs.getString("SCHEMA_NAME") ); // schemaName = checkNull( rs.getString("SCHEMA_NAME") );
...@@ -747,7 +751,8 @@ public class ManageSqlConf extends ActionHandlerEJB { ...@@ -747,7 +751,8 @@ public class ManageSqlConf extends ActionHandlerEJB {
"P", "P",
false); false);
} }
} else if ("C".equalsIgnoreCase(execRights)) { }
else if ("C".equalsIgnoreCase(execRights)) {
// CLIENT DEV: DB_DEV is a schema name, not an enterprise code, // CLIENT DEV: DB_DEV is a schema name, not an enterprise code,
// so processSqlForEnterprise cannot look it up. Instead, apply // so processSqlForEnterprise cannot look it up. Instead, apply
// schema injection and call executeAndLog directly using the // schema injection and call executeAndLog directly using the
...@@ -1844,321 +1849,328 @@ public class ManageSqlConf extends ActionHandlerEJB { ...@@ -1844,321 +1849,328 @@ public class ManageSqlConf extends ActionHandlerEJB {
String chgTerm, String chgTerm,
String execRights) throws Exception { String execRights) throws Exception {
try {
try{ BaseLogger.log(
"3",
null,
null,
// Change by Gagan B. on 16-JAN-26 "processSqlForEnterprise START -> enterpriseCode="
// --- FIX: Don't inject placeholders into PL/SQL Bodies --- + enterpriseCode
String upperSql = checkNull(inputSql).trim().toUpperCase(); + ", tranId="
boolean isPlSqlBody = upperSql.startsWith("CREATE OR REPLACE FUNCTION") + tranId
|| upperSql.startsWith("CREATE FUNCTION") + ", execRights="
|| upperSql.startsWith("CREATE OR REPLACE PROCEDURE") + execRights);
|| upperSql.startsWith("CREATE PROCEDURE") System.out.println("processSqlForEnterprise START :: " + enterpriseCode);
|| upperSql.startsWith("CREATE OR REPLACE PACKAGE") // Change by Gagan B. on 16-JAN-26
|| upperSql.startsWith("CREATE PACKAGE") // --- FIX: Don't inject placeholders into PL/SQL Bodies ---
|| upperSql.startsWith("CREATE OR REPLACE TYPE") String upperSql = checkNull(inputSql).trim().toUpperCase();
|| upperSql.startsWith("CREATE TYPE") boolean isPlSqlBody = upperSql.startsWith("CREATE OR REPLACE FUNCTION")
|| upperSql.startsWith("CREATE OR REPLACE TRIGGER") || upperSql.startsWith("CREATE FUNCTION")
|| upperSql.startsWith("CREATE TRIGGER") || upperSql.startsWith("CREATE OR REPLACE PROCEDURE")
|| upperSql.contains("NONEDITIONABLE"); // Catch the specific case || upperSql.startsWith("CREATE PROCEDURE")
|| upperSql.startsWith("CREATE OR REPLACE PACKAGE")
if (!isPlSqlBody) { || upperSql.startsWith("CREATE PACKAGE")
inputSql = injectSchemaPlaceholderSafe(inputSql); || upperSql.startsWith("CREATE OR REPLACE TYPE")
} || upperSql.startsWith("CREATE TYPE")
System.out.println("inputSql gsb:::::>>>><<<<< " + inputSql); || upperSql.startsWith("CREATE OR REPLACE TRIGGER")
|| upperSql.startsWith("CREATE TRIGGER")
|| upperSql.contains("NONEDITIONABLE"); // Catch the specific case
if (!isPlSqlBody) {
inputSql = injectSchemaPlaceholderSafe(inputSql);
}
System.out.println("inputSql gsb:::::>>>><<<<< " + inputSql);
/* /*
* ------------------------------- * -------------------------------
* Fetch schemas * Fetch schemas
* ------------------------------- * -------------------------------
*/ */
String query = "SELECT DB_DEV, DB_MAIN, DB_READ, DB_PILOT " + String query = "SELECT DB_DEV, DB_MAIN, DB_READ, DB_PILOT " +
"FROM enterprise WHERE enterprise = ?"; "FROM enterprise WHERE enterprise = ?";
String dbMain, dbRead, dbPilot; String dbMain, dbRead, dbPilot;
try (PreparedStatement ps = conn.prepareStatement(query)) { try (PreparedStatement ps = conn.prepareStatement(query)) {
ps.setString(1, enterpriseCode); ps.setString(1, enterpriseCode);
try (ResultSet rs = ps.executeQuery()) { try (ResultSet rs = ps.executeQuery()) {
if (!rs.next()) { if (!rs.next()) {
throw new Exception("No enterprise found for: " + enterpriseCode); throw new Exception("No enterprise found for: " + enterpriseCode);
}
dbMain = rs.getString("DB_MAIN");
dbRead = rs.getString("DB_READ");
dbPilot = rs.getString("DB_PILOT");
} }
dbMain = rs.getString("DB_MAIN");
dbRead = rs.getString("DB_READ");
dbPilot = rs.getString("DB_PILOT");
} }
} BaseLogger.log("3", null, null, "dbMain:: " + dbMain + " dbRead:: " + dbRead + " dbPilot:: " + dbPilot);
BaseLogger.log("3", null, null, "dbMain:: " + dbMain + " dbRead:: " + dbRead + " dbPilot:: " + dbPilot); /*
/* * -------------------------------
* ------------------------------- * Get CURRENT_USER
* Get CURRENT_USER * -------------------------------
* ------------------------------- */
*/ String currentUser;
String currentUser; try (PreparedStatement ps = conn.prepareStatement("SELECT USER FROM DUAL");
try (PreparedStatement ps = conn.prepareStatement("SELECT USER FROM DUAL"); ResultSet rs = ps.executeQuery()) {
ResultSet rs = ps.executeQuery()) {
rs.next();
currentUser = rs.getString(1);
}
System.out.println("CURRENT_USER :::: " + currentUser);
/*
* -------------------------------
* Schema execution rules
* -------------------------------
*/
Map<String, String> schemaRules = new LinkedHashMap<>();
schemaRules.put(dbMain, "ALL");
// schemaRules.put(dbDev, "ALL");
schemaRules.put(dbRead, "SYN");
// schemaRules.put(dbPilot, "SYN");
System.out.println("execRights ::: " + execRights);
if ("P".equalsIgnoreCase(execRights)
&& dbPilot != null
&& !dbPilot.trim().isEmpty()) {
schemaRules.put(dbPilot, "SYN");
}
String createObjectType = getCreateObjectType(inputSql); rs.next();
boolean isCreateObject = createObjectType != null; currentUser = rs.getString(1);
String objectName = isCreateObject ? extractObjectName(inputSql) : null; }
System.out.println("objectName ::: " + objectName); System.out.println("CURRENT_USER :::: " + currentUser);
System.out.println("createObjectType ::: " + createObjectType);
System.out.println("schemaRules:: " + schemaRules);
/*
* -------------------------------
* Execute per schema
* -------------------------------
*/
for (Map.Entry<String, String> entry : schemaRules.entrySet()) {
String schemaName = entry.getKey(); /*
String rule = entry.getValue(); * -------------------------------
System.out.println("schemaName ::: " + schemaName); * Schema execution rules
System.out.println("dbPilot ::: " + dbPilot); * -------------------------------
System.out.println("rule ::: " + rule); */
Map<String, String> schemaRules = new LinkedHashMap<>();
schemaRules.put(dbMain, "ALL");
// schemaRules.put(dbDev, "ALL");
schemaRules.put(dbRead, "SYN");
// schemaRules.put(dbPilot, "SYN");
System.out.println("execRights ::: " + execRights);
if ("P".equalsIgnoreCase(execRights)
&& dbPilot != null
&& !dbPilot.trim().isEmpty()) {
schemaRules.put(dbPilot, "SYN");
}
if (schemaName == null || schemaName.trim().isEmpty()) String createObjectType = getCreateObjectType(inputSql);
continue; boolean isCreateObject = createObjectType != null;
String objectName = isCreateObject ? extractObjectName(inputSql) : null;
System.out.println("objectName ::: " + objectName);
System.out.println("createObjectType ::: " + createObjectType);
System.out.println("schemaRules:: " + schemaRules);
/* /*
* ===================================== * -------------------------------
* CREATE / DDL FLOW * Execute per schema
* ===================================== * -------------------------------
*/ */
if (isCreateObject) { for (Map.Entry<String, String> entry : schemaRules.entrySet()) {
if ("ALL".equals(rule)) {
executeAndLog(
schemaName,
inputSql,
tranId,
enterpriseCode,
linNo,
requestID,
userId,
chgTerm,
dbMain,
"",
true);
} else if ("SYN".equals(rule)) {
// // Skip synonym & grant if CURRENT_USER is owner
// if (currentUser.equalsIgnoreCase(dbMain)) {
// System.out.println(
// "Skipping SYN. CURRENT_USER is DB_MAIN."
// );
// continue;
// }
/*
* -----------------------------
* Create synonym in CURRENT_USER
* -----------------------------
*/
System.out.println("dbMain ::: " + dbMain); String schemaName = entry.getKey();
System.out.println("schemaName ::: " + schemaName); String rule = entry.getValue();
System.out.println("schemaName ::: " + schemaName);
System.out.println("dbPilot ::: " + dbPilot);
System.out.println("rule ::: " + rule);
String schemaForPilot = schemaName; if (schemaName == null || schemaName.trim().isEmpty())
String schemaForMain = dbMain; continue;
if ("P".equalsIgnoreCase(execRights) && schemaName.equalsIgnoreCase(dbPilot)) { /*
* =====================================
* CREATE / DDL FLOW
* =====================================
*/
if (isCreateObject) {
ConnDriver connDriverForPilotSchema = new ConnDriver(); if ("ALL".equals(rule)) {
Connection connForPilotSchema = null;
connForPilotSchema = connDriverForPilotSchema.getConnectDB(schemaName); executeAndLog(
schemaName,
inputSql,
tranId,
enterpriseCode,
linNo,
requestID,
userId,
chgTerm,
dbMain,
"",
true);
String schemaForPilotSql = "SELECT USER FROM DUAL"; } else if ("SYN".equals(rule)) {
PreparedStatement schemaForPilotPs = connForPilotSchema.prepareStatement(schemaForPilotSql); // // Skip synonym & grant if CURRENT_USER is owner
// if (currentUser.equalsIgnoreCase(dbMain)) {
// System.out.println(
// "Skipping SYN. CURRENT_USER is DB_MAIN."
// );
// continue;
// }
ResultSet schemaForPilotRs = schemaForPilotPs.executeQuery(); /*
* -----------------------------
* Create synonym in CURRENT_USER
* -----------------------------
*/
if (schemaForPilotRs.next()) { System.out.println("dbMain ::: " + dbMain);
schemaForPilot = checkNull(schemaForPilotRs.getString(1)); System.out.println("schemaName ::: " + schemaName);
}
BaseLogger.log( String schemaForPilot = schemaName;
"3", String schemaForMain = dbMain;
null,
null,
"Pilot actual schema user : [" + schemaForPilot + "]");
if(connForPilotSchema!=null){ if ("P".equalsIgnoreCase(execRights) && schemaName.equalsIgnoreCase(dbPilot)) {
connForPilotSchema.close();
connForPilotSchema = null;
}
}
ConnDriver connDriverForPilotSchema = new ConnDriver();
Connection connForPilotSchema = null;
/* connForPilotSchema = connDriverForPilotSchema.getConnectDB(schemaName);
* Fetch actual Main schema user
* Required for execRights = P and A
*/
if ("P".equalsIgnoreCase(execRights)
|| "A".equalsIgnoreCase(execRights)) {
ConnDriver connDriverForMainSchema = new ConnDriver(); String schemaForPilotSql = "SELECT USER FROM DUAL";
Connection connForMainSchema = null;
connForMainSchema = connDriverForMainSchema.getConnectDB(dbMain); PreparedStatement schemaForPilotPs = connForPilotSchema.prepareStatement(schemaForPilotSql);
String schemaForMainSql = "SELECT USER FROM DUAL"; ResultSet schemaForPilotRs = schemaForPilotPs.executeQuery();
PreparedStatement schemaForMainPs = connForMainSchema.prepareStatement(schemaForMainSql); if (schemaForPilotRs.next()) {
schemaForPilot = checkNull(schemaForPilotRs.getString(1));
}
ResultSet schemaForMainRs = schemaForMainPs.executeQuery(); BaseLogger.log(
"3",
null,
null,
"Pilot actual schema user : [" + schemaForPilot + "]");
if (schemaForMainRs.next()) { if (connForPilotSchema != null) {
schemaForMain = checkNull(schemaForMainRs.getString(1)); connForPilotSchema.close();
connForPilotSchema = null;
}
} }
BaseLogger.log( /*
"3", * Fetch actual Main schema user
null, * Required for execRights = P and A
null, */
"Main actual schema user ::::::::: [" + schemaForMain + "]"); if ("P".equalsIgnoreCase(execRights)
|| "A".equalsIgnoreCase(execRights)) {
if (connForMainSchema != null) { ConnDriver connDriverForMainSchema = new ConnDriver();
connForMainSchema.close(); Connection connForMainSchema = null;
connForMainSchema = null; System.out.println("dbMain hashcode = " + dbMain.hashCode());
} System.out.println("dbMain value = " + dbMain);
} connForMainSchema = connDriverForMainSchema.getConnectDB(dbMain);
String targetSchema = schemaName; String schemaForMainSql = "SELECT USER FROM DUAL";
if ("P".equalsIgnoreCase(execRights) PreparedStatement schemaForMainPs = connForMainSchema.prepareStatement(schemaForMainSql);
&& schemaName.equalsIgnoreCase(dbPilot)) {
targetSchema = schemaForPilot;
}
String synonymSql = "CREATE SYNONYM " + targetSchema + "." + objectName + ResultSet schemaForMainRs = schemaForMainPs.executeQuery();
" FOR " + schemaForMain + "." + objectName;
executeAndLog(
schemaName,
synonymSql,
tranId,
enterpriseCode,
linNo,
requestID,
userId,
chgTerm,
dbMain,
"",
false);
/* if (schemaForMainRs.next()) {
* ----------------------------- schemaForMain = checkNull(schemaForMainRs.getString(1));
* Grant based on object type }
* -----------------------------
*/
String grantSql = null;
BaseLogger.log(
// For Pilot transaction Create Table query grant rights of SELECT, INSERT, "3",
// UPDATE, DELETE null,
if ("TABLE".equalsIgnoreCase(createObjectType)) { null,
"Main actual schema user ::::::::: [" + schemaForMain + "]");
if (connForMainSchema != null) {
connForMainSchema.close();
connForMainSchema = null;
}
}
targetSchema = schemaName; String targetSchema = schemaName;
if ("P".equalsIgnoreCase(execRights) if ("P".equalsIgnoreCase(execRights)
&& schemaName.equalsIgnoreCase(dbPilot)) { && schemaName.equalsIgnoreCase(dbPilot)) {
targetSchema = schemaForPilot; targetSchema = schemaForPilot;
} }
if ("P".equalsIgnoreCase(execRights) String synonymSql = "CREATE SYNONYM " + targetSchema + "." + objectName +
&& schemaName.equalsIgnoreCase(dbPilot)) { " FOR " + schemaForMain + "." + objectName;
grantSql = "GRANT SELECT, INSERT, UPDATE, DELETE ON " executeAndLog(
+ schemaForMain + "." + objectName schemaName,
+ " TO " + targetSchema; synonymSql,
tranId,
enterpriseCode,
linNo,
requestID,
userId,
chgTerm,
dbMain,
"",
false);
/*
* -----------------------------
* Grant based on object type
* -----------------------------
*/
String grantSql = null;
// For Pilot transaction Create Table query grant rights of SELECT, INSERT,
// UPDATE, DELETE
if ("TABLE".equalsIgnoreCase(createObjectType)) {
targetSchema = schemaName;
if ("P".equalsIgnoreCase(execRights)
&& schemaName.equalsIgnoreCase(dbPilot)) {
targetSchema = schemaForPilot;
}
if ("P".equalsIgnoreCase(execRights)
&& schemaName.equalsIgnoreCase(dbPilot)) {
} else { grantSql = "GRANT SELECT, INSERT, UPDATE, DELETE ON "
+ schemaForMain + "." + objectName
+ " TO " + targetSchema;
} else {
grantSql = "GRANT SELECT ON "
+ schemaForMain + "." + objectName
+ " TO " + targetSchema;
}
} else if ("VIEW".equalsIgnoreCase(createObjectType)
|| "SEQUENCE".equalsIgnoreCase(createObjectType)) {
targetSchema = ("P".equalsIgnoreCase(execRights)
&& schemaName.equalsIgnoreCase(dbPilot))
? schemaForPilot
: schemaName;
grantSql = "GRANT SELECT ON " grantSql = "GRANT SELECT ON "
+ schemaForMain + "." + objectName + schemaForMain + "." + objectName
+ " TO " + targetSchema; + " TO " + targetSchema;
}
} else if ("VIEW".equalsIgnoreCase(createObjectType)
|| "SEQUENCE".equalsIgnoreCase(createObjectType)) {
targetSchema = ("P".equalsIgnoreCase(execRights) } else if ("PROCEDURE".equalsIgnoreCase(createObjectType)
&& schemaName.equalsIgnoreCase(dbPilot)) || "FUNCTION".equalsIgnoreCase(createObjectType)
? schemaForPilot || "PACKAGE".equalsIgnoreCase(createObjectType)
: schemaName; || "TYPE".equalsIgnoreCase(createObjectType)) {
grantSql = "GRANT SELECT ON " targetSchema = ("P".equalsIgnoreCase(execRights)
+ schemaForMain + "." + objectName && schemaName.equalsIgnoreCase(dbPilot))
+ " TO " + targetSchema; ? schemaForPilot
: schemaName;
} else if ("PROCEDURE".equalsIgnoreCase(createObjectType) grantSql = "GRANT EXECUTE ON "
|| "FUNCTION".equalsIgnoreCase(createObjectType) + schemaForMain + "." + objectName
|| "PACKAGE".equalsIgnoreCase(createObjectType) + " TO " + targetSchema;
|| "TYPE".equalsIgnoreCase(createObjectType)) {
targetSchema = ("P".equalsIgnoreCase(execRights)
&& schemaName.equalsIgnoreCase(dbPilot))
? schemaForPilot
: schemaName;
grantSql = "GRANT EXECUTE ON "
+ schemaForMain + "." + objectName
+ " TO " + targetSchema;
} }
BaseLogger.log( BaseLogger.log(
"3", "3",
null, null,
null, null,
"grantSql [[" + grantSql + "]"); "grantSql [[" + grantSql + "]");
BaseLogger.log( BaseLogger.log(
"3", "3",
null, null,
null, null,
"schemaName [" + schemaName + "]"); "schemaName [" + schemaName + "]");
BaseLogger.log( BaseLogger.log(
"3", "3",
null, null,
null, null,
"dbMain [" + dbMain + "]"); "dbMain [" + dbMain + "]");
BaseLogger.log( BaseLogger.log(
"3", "3",
null, null,
null, null,
"dbRead [[" + dbRead + "]"); "dbRead [[" + dbRead + "]");
if (grantSql != null) { if (grantSql != null) {
executeAndLog( executeAndLog(
...@@ -2174,47 +2186,46 @@ public class ManageSqlConf extends ActionHandlerEJB { ...@@ -2174,47 +2186,46 @@ public class ManageSqlConf extends ActionHandlerEJB {
"", "",
false); false);
} }
}
continue; // Skip DML flow
} }
continue; // Skip DML flow /*
} * =====================================
* INSERT / UPDATE / DELETE FLOW
* =====================================
*/
if ("SYN".equals(rule)) {
System.out.println(
"Skipping DML for SYN-only schema: " + schemaName);
continue;
}
/* executeAndLog(
* ===================================== schemaName,
* INSERT / UPDATE / DELETE FLOW inputSql,
* ===================================== tranId,
*/ enterpriseCode,
if ("SYN".equals(rule)) { linNo,
System.out.println( requestID,
"Skipping DML for SYN-only schema: " + schemaName); userId,
continue; chgTerm,
dbMain,
"",
false);
} }
executeAndLog( System.out.println("Execution completed successfully.");
schemaName,
inputSql,
tranId,
enterpriseCode,
linNo,
requestID,
userId,
chgTerm,
dbMain,
"",
false);
}
System.out.println("Execution completed successfully."); } catch (Exception e) {
}
catch(Exception e){
String error = (e.getMessage() != null) String error = (e.getMessage() != null)
? e.getMessage() ? e.getMessage()
: e.toString(); : e.toString();
System.out.println("Catch block for processSqlForEnterprise method...." + error); System.out.println("Catch block for processSqlForEnterprise method...." + error);
logSqlExecution(tranId, enterpriseCode, "0", requestID, inputSql, 0, "E", userId, chgTerm, error, ""); logSqlExecution(tranId, enterpriseCode, "0", requestID, inputSql, 0, "E", userId, chgTerm, error, "");
} }
} }
// Created a method to execute the SQL in the schemas stored in the Enterprise // Created a method to execute the SQL in the schemas stored in the Enterprise
...@@ -2259,85 +2270,86 @@ public class ManageSqlConf extends ActionHandlerEJB { ...@@ -2259,85 +2270,86 @@ public class ManageSqlConf extends ActionHandlerEJB {
logSqlExecution(tranId, enterpriseCode, "0", requestID, inputSql, 0, "E", userId, chgTerm, error, ""); logSqlExecution(tranId, enterpriseCode, "0", requestID, inputSql, 0, "E", userId, chgTerm, error, "");
return; // Stop execution if connection fails return; // Stop execution if connection fails
} }
// Changes by Ajit D. on 08-JUNE-26 for the query execution schema name fetched it // Changes by Ajit D. on 08-JUNE-26 for the query execution schema name fetched
// it
// from USERS // from USERS
BaseLogger.log("3", null, null, "For schemaName: [" + schemaName + "]"); BaseLogger.log("3", null, null, "For schemaName: [" + schemaName + "]");
BaseLogger.log("3", null, null, "executeAndLog inputSql: [" + inputSql + "]"); BaseLogger.log("3", null, null, "executeAndLog inputSql: [" + inputSql + "]");
String dbReadForCheck = ""; String dbReadForCheck = "";
/* /*
* Fetch DB_READ for the current enterprise * Fetch DB_READ for the current enterprise
*/ */
String dbReadSql = "SELECT DB_READ FROM ENTERPRISE WHERE ENTERPRISE = ?"; String dbReadSql = "SELECT DB_READ FROM ENTERPRISE WHERE ENTERPRISE = ?";
PreparedStatement dbReadPs = conn.prepareStatement(dbReadSql); PreparedStatement dbReadPs = conn.prepareStatement(dbReadSql);
dbReadPs.setString(1, enterpriseCode); dbReadPs.setString(1, enterpriseCode);
ResultSet dbReadRs = dbReadPs.executeQuery(); ResultSet dbReadRs = dbReadPs.executeQuery();
if (dbReadRs.next()) { if (dbReadRs.next()) {
dbReadForCheck = checkNull(dbReadRs.getString("DB_READ")); dbReadForCheck = checkNull(dbReadRs.getString("DB_READ"));
} }
BaseLogger.log(
"3",
null,
null,
"DB_READ fetched from enterprise : [" + dbReadForCheck + "]");
/*
* For DB_READ use configured value directly.
* For all other schemas fetch actual Oracle USER.
*/
if (schemaName.equalsIgnoreCase(dbReadForCheck)) {
schemaForPlaceHolder = schemaName;
BaseLogger.log( BaseLogger.log(
"3", "3",
null, null,
null, null,
"DB_READ fetched from enterprise : [" + dbReadForCheck + "]"); "Using DB_READ directly as schema : ["
+ schemaForPlaceHolder + "]");
/*
* For DB_READ use configured value directly.
* For all other schemas fetch actual Oracle USER.
*/
if (schemaName.equalsIgnoreCase(dbReadForCheck)) {
schemaForPlaceHolder = schemaName;
BaseLogger.log(
"3",
null,
null,
"Using DB_READ directly as schema : ["
+ schemaForPlaceHolder + "]");
} else {
connForSchema = connDriverForSchema.getConnectDB(schemaName); } else {
String schemaSql = "SELECT USER FROM DUAL"; connForSchema = connDriverForSchema.getConnectDB(schemaName);
PreparedStatement schemaForPs = connForSchema.prepareStatement(schemaSql); String schemaSql = "SELECT USER FROM DUAL";
ResultSet schemaForRs = schemaForPs.executeQuery(); PreparedStatement schemaForPs = connForSchema.prepareStatement(schemaSql);
if (schemaForRs.next()) { ResultSet schemaForRs = schemaForPs.executeQuery();
schemaForPlaceHolder = checkNull(schemaForRs.getString(1));
}
BaseLogger.log( if (schemaForRs.next()) {
"3", schemaForPlaceHolder = checkNull(schemaForRs.getString(1));
null,
null,
"Actual Oracle USER : ["
+ schemaForPlaceHolder + "]");
} }
if(schemaName.equalsIgnoreCase("APPVIS")){
BaseLogger.log(
"3",
null,
null,
"For std database");
schemaForPlaceHolder = "APPVIS";
}
BaseLogger.log( BaseLogger.log(
"3", "3",
null, null,
null, null,
"schemaForPlaceHolder : [" "Actual Oracle USER : ["
+ schemaForPlaceHolder + "]"); + schemaForPlaceHolder + "]");
}
if (schemaName.equalsIgnoreCase("APPVIS")) {
BaseLogger.log(
"3",
null,
null,
"For std database");
schemaForPlaceHolder = "APPVIS";
}
BaseLogger.log(
"3",
null,
null,
"schemaForPlaceHolder : ["
+ schemaForPlaceHolder + "]");
String finalSql = applySchema(inputSql, schemaForPlaceHolder); String finalSql = applySchema(inputSql, schemaForPlaceHolder);
...@@ -2361,8 +2373,6 @@ public class ManageSqlConf extends ActionHandlerEJB { ...@@ -2361,8 +2373,6 @@ public class ManageSqlConf extends ActionHandlerEJB {
System.out.println("execSchema:: " + execSchema); System.out.println("execSchema:: " + execSchema);
System.out.println("enterpriseCode:: " + enterpriseCode); System.out.println("enterpriseCode:: " + enterpriseCode);
// 1. Get the Connection String for the Main Execution // 1. Get the Connection String for the Main Execution
String connForExecSql = "select schema_name from enterprise where enterprise = ?"; String connForExecSql = "select schema_name from enterprise where enterprise = ?";
PreparedStatement connForExecPstmt = conn.prepareStatement(connForExecSql); PreparedStatement connForExecPstmt = conn.prepareStatement(connForExecSql);
...@@ -2377,8 +2387,18 @@ public class ManageSqlConf extends ActionHandlerEJB { ...@@ -2377,8 +2387,18 @@ public class ManageSqlConf extends ActionHandlerEJB {
} }
System.out.println("connForExec:: " + connForExec); System.out.println("connForExec:: " + connForExec);
// Connect to the specific schema try {
connForQueryExec = connDriver.getConnectDB(connForExec); // Connect to the specific schema
connForQueryExec = connDriver.getConnectDB(connForExec);
} catch (Exception e) {
String error = (e.getMessage() != null)
? e.getMessage()
: e.toString();
System.out.println("Catch block for executeAndLog method for creating connection...." + error);
logSqlExecution(tranId, enterpriseCode, "0", requestID, inputSql, 0, "E", userId, chgTerm, error, "");
}
int updCount = 0; int updCount = 0;
String error = null; String error = null;
......
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