Commit 95b596ed authored by Ajit Deshmukh's avatar Ajit Deshmukh

Added a logic for Live and Client Developer transaction the schema name will...

Added a logic for Live and Client Developer transaction the schema name will be fetch from the curren user
parent c88c0ade
......@@ -348,7 +348,7 @@ public class ManageSqlConf extends ActionHandlerEJB {
ArrayList<String> enterpriseArrayList = new ArrayList<>();
sql = "SELECT APPL_DB,ENTERPRISES,REQ_ID FROM SQL_CHANGES WHERE TRAN_ID=?";
pstmt = con.prepareStatement(sql);
pstmt.setString(1, tranId);
pstmt.setString(1, tranIdRef);
rs = pstmt.executeQuery();
if (rs.next()) {
applDB = checkNull(rs.getString("APPL_DB"));
......@@ -626,7 +626,7 @@ public class ManageSqlConf extends ActionHandlerEJB {
con.setAutoCommit(false);
// TO fetch the schemaName and enterprise for live[START]
ArrayList<String> enterpriseArrayListForP = new ArrayList<>();
Connection entCon = null;
ConnDriver connDriver = new ConnDriver();
entCon = connDriver.getConnectDB("Driver");
......@@ -643,7 +643,7 @@ public class ManageSqlConf extends ActionHandlerEJB {
// enterpriseSQL = checkNull( rs.getString("ENTERPRISE") );
// schemaListMap.put(schemaName,enterpriseSQL);
enterpriseArrayList
enterpriseArrayListForP
.add(checkNull(rsToFetchEntForP.getString("ENTERPRISE")));
}
if (pstmt != null) {
......@@ -666,10 +666,10 @@ public class ManageSqlConf extends ActionHandlerEJB {
// TO fetch the enterprise for live[START]
BaseLogger.log("1", null, null,
"enterpriseArrayList :: " + enterpriseArrayList);
"enterpriseArrayListForP :: " + enterpriseArrayListForP);
String[] enterpriseArr = null;
enterpriseArr = enterpriseArrayList.toArray(new String[0]);
enterpriseArr = enterpriseArrayListForP.toArray(new String[0]);
// Commented by Gagan B. on 02-FEB-26 to resolve the issue of when multiple
// enterprise selected using checkbox, SQL only got executed in one single
......@@ -1985,11 +1985,13 @@ public class ManageSqlConf extends ActionHandlerEJB {
* -----------------------------
*/
System.out.println("dbMain ::: " + dbMain);
System.out.println("schemaName ::: " + schemaName);
String schemaForPilot = schemaName;
String schemaForMain = dbMain;
if ("P".equalsIgnoreCase(execRights)
&& schemaName.equalsIgnoreCase(dbPilot)) {
if ("P".equalsIgnoreCase(execRights) && schemaName.equalsIgnoreCase(dbPilot)) {
ConnDriver connDriverForPilotSchema = new ConnDriver();
Connection connForPilotSchema = null;
......@@ -2011,6 +2013,46 @@ public class ManageSqlConf extends ActionHandlerEJB {
null,
null,
"Pilot actual schema user : [" + schemaForPilot + "]");
if(connForPilotSchema!=null){
connForPilotSchema.close();
connForPilotSchema = null;
}
}
/*
* Fetch actual Main schema user
* Required for execRights = P and A
*/
if ("P".equalsIgnoreCase(execRights)
|| "A".equalsIgnoreCase(execRights)) {
ConnDriver connDriverForMainSchema = new ConnDriver();
Connection connForMainSchema = null;
connForMainSchema = connDriverForMainSchema.getConnectDB(dbMain);
String schemaForMainSql = "SELECT USER FROM DUAL";
PreparedStatement schemaForMainPs = connForMainSchema.prepareStatement(schemaForMainSql);
ResultSet schemaForMainRs = schemaForMainPs.executeQuery();
if (schemaForMainRs.next()) {
schemaForMain = checkNull(schemaForMainRs.getString(1));
}
BaseLogger.log(
"3",
null,
null,
"Main actual schema user ::::::::: [" + schemaForMain + "]");
if (connForMainSchema != null) {
connForMainSchema.close();
connForMainSchema = null;
}
}
String targetSchema = schemaName;
......@@ -2021,7 +2063,7 @@ public class ManageSqlConf extends ActionHandlerEJB {
}
String synonymSql = "CREATE SYNONYM " + targetSchema + "." + objectName +
" FOR " + dbMain + "." + objectName;
" FOR " + schemaForMain + "." + objectName;
executeAndLog(
schemaName,
......@@ -2059,13 +2101,13 @@ public class ManageSqlConf extends ActionHandlerEJB {
&& schemaName.equalsIgnoreCase(dbPilot)) {
grantSql = "GRANT SELECT, INSERT, UPDATE, DELETE ON "
+ dbMain + "." + objectName
+ schemaForMain + "." + objectName
+ " TO " + targetSchema;
} else {
grantSql = "GRANT SELECT ON "
+ dbMain + "." + objectName
+ schemaForMain + "." + objectName
+ " TO " + targetSchema;
}
} else if ("VIEW".equalsIgnoreCase(createObjectType)
......@@ -2077,7 +2119,7 @@ public class ManageSqlConf extends ActionHandlerEJB {
: schemaName;
grantSql = "GRANT SELECT ON "
+ dbMain + "." + objectName
+ schemaForMain + "." + objectName
+ " TO " + targetSchema;
} else if ("PROCEDURE".equalsIgnoreCase(createObjectType)
......@@ -2091,7 +2133,7 @@ public class ManageSqlConf extends ActionHandlerEJB {
: schemaName;
grantSql = "GRANT EXECUTE ON "
+ dbMain + "." + objectName
+ schemaForMain + "." + objectName
+ " TO " + targetSchema;
}
......@@ -2197,36 +2239,107 @@ public class ManageSqlConf extends ActionHandlerEJB {
boolean rethrow) throws Exception {
Connection conn = null;
Connection connForQueryExec = null;
Connection connForPilotSchema = null;
ConnDriver connDriverForPilotSchema = new ConnDriver();
Connection connForSchema = null;
ConnDriver connDriverForSchema = new ConnDriver();
ConnDriver connDriver = new ConnDriver();
ConnDriver connDriver1 = new ConnDriver();
String connForExec = "";
String schemaForPilot = "";
String schemaForPlaceHolder = "";
BaseLogger.log("3", null, null, "executeAndLog dbMainSchema: [" + dbMainSchema + "]");
BaseLogger.log("3", null, null, "executeAndLog inputSql: [" + inputSql + "]");
BaseLogger.log("3", null, null, "executeAndLog execRights: [" + execRights + "]");
// Changes by Ajit D. on 08-JUNE-26 for Pilot Transaction schema name fetched it
BaseLogger.log("3", null, null, "executeAndLog schemaName: [" + schemaName + "]");
try {
conn = connDriver1.getConnectDB("Driver");
} catch (Exception e) {
System.out.println("Catch block for connection failed...." + e.getMessage());
String error = e.getMessage();
logSqlExecution(tranId, enterpriseCode, "0", requestID, inputSql, 0, "E", userId, chgTerm, error, "");
return; // Stop execution if connection fails
}
// Changes by Ajit D. on 08-JUNE-26 for the query execution schema name fetched it
// from USERS
if (execRights.trim().equalsIgnoreCase("P")) {
BaseLogger.log("3", null, null, "For Pilot schemaName: [" + schemaName + "]");
BaseLogger.log("3", null, null, "For schemaName: [" + schemaName + "]");
BaseLogger.log("3", null, null, "executeAndLog inputSql: [" + inputSql + "]");
connForPilotSchema = connDriverForPilotSchema.getConnectDB(schemaName);
String schemaForPilotSql = "SELECT USER FROM DUAL";
PreparedStatement schemaForPilotPs = connForPilotSchema.prepareStatement(schemaForPilotSql);
ResultSet schemaForPilotRs = schemaForPilotPs.executeQuery();
while (schemaForPilotRs.next()) {
schemaForPilot = checkNull(schemaForPilotRs.getString("USER"));
String dbReadForCheck = "";
/*
* Fetch DB_READ for the current enterprise
*/
String dbReadSql = "SELECT DB_READ FROM ENTERPRISE WHERE ENTERPRISE = ?";
PreparedStatement dbReadPs = conn.prepareStatement(dbReadSql);
dbReadPs.setString(1, enterpriseCode);
ResultSet dbReadRs = dbReadPs.executeQuery();
if (dbReadRs.next()) {
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(
"3",
null,
null,
"Using DB_READ directly as schema : ["
+ schemaForPlaceHolder + "]");
} else {
connForSchema = connDriverForSchema.getConnectDB(schemaName);
String schemaSql = "SELECT USER FROM DUAL";
PreparedStatement schemaForPs = connForSchema.prepareStatement(schemaSql);
ResultSet schemaForRs = schemaForPs.executeQuery();
if (schemaForRs.next()) {
schemaForPlaceHolder = checkNull(schemaForRs.getString(1));
}
BaseLogger.log("3", null, null, "schemaForPilot: [" + schemaForPilot + "]");
schemaName = schemaForPilot;
BaseLogger.log(
"3",
null,
null,
"Actual Oracle USER : ["
+ 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, schemaName);
String finalSql = applySchema(inputSql, schemaForPlaceHolder);
// Change by Gagan B. on 16-JAN-26
finalSql = finalSql.trim();
......@@ -2248,14 +2361,7 @@ public class ManageSqlConf extends ActionHandlerEJB {
System.out.println("execSchema:: " + execSchema);
System.out.println("enterpriseCode:: " + enterpriseCode);
try {
conn = connDriver1.getConnectDB("Driver");
} catch (Exception e) {
System.out.println("Catch block for connection failed...." + e.getMessage());
String error = e.getMessage();
logSqlExecution(tranId, enterpriseCode, "0", requestID, finalSql, 0, "E", userId, chgTerm, error, "");
return; // Stop execution if connection fails
}
// 1. Get the Connection String for the Main Execution
String connForExecSql = "select schema_name from enterprise where enterprise = ?";
......
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