implemented masters apis and default case rule
This commit is contained in:
parent
05de042fb0
commit
c0238c2e3a
|
@ -261,5 +261,25 @@ public class MainController {
|
||||||
return service.getDBFunctions();
|
return service.getDBFunctions();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RequestMapping("/getMasterRules")
|
||||||
|
public List<String> getMasterRules() throws SQLException{
|
||||||
|
|
||||||
|
return service.getMasterRules();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping("/migrateBasedOnDefaultCaseRule")
|
||||||
|
public Map<String, Object> migrateBasedOnDefaultCaseRule(@RequestBody Map<String, String> map)
|
||||||
|
throws ClassNotFoundException, SQLException {
|
||||||
|
|
||||||
|
String status = service.migrateBasedOnDefaultCaseRule(map);
|
||||||
|
|
||||||
|
Map<String, Object> res = new HashMap<>();
|
||||||
|
|
||||||
|
res.put("status", status);
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1769,7 +1769,7 @@ public class CompareTwoTables {
|
||||||
destFinalScrCols = destFinalScrCols.replace("[", "");
|
destFinalScrCols = destFinalScrCols.replace("[", "");
|
||||||
destFinalScrCols = destFinalScrCols.replace("]", "");
|
destFinalScrCols = destFinalScrCols.replace("]", "");
|
||||||
|
|
||||||
List<Map<String, Object>> list = getSrcAggRuleData(srcTbl, srcCols, aggFunCol, groupBy);
|
List<Map<String, Object>> list = getSrcAggRuleData(srcTbl, srcCols);
|
||||||
|
|
||||||
for (Map<String, Object> map2 : list) {
|
for (Map<String, Object> map2 : list) {
|
||||||
int i = instertDestSumRuleData(destTbl, destFinalScrCols, map2);
|
int i = instertDestSumRuleData(destTbl, destFinalScrCols, map2);
|
||||||
|
@ -1854,8 +1854,7 @@ public class CompareTwoTables {
|
||||||
return rules;
|
return rules;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Map<String, Object>> getSrcAggRuleData(String srcTbl, String srcTblCols, String aggFunCol,
|
public List<Map<String, Object>> getSrcAggRuleData(String srcTbl, String srcTblCols) throws ClassNotFoundException, SQLException {
|
||||||
String groupBy) throws ClassNotFoundException, SQLException {
|
|
||||||
|
|
||||||
List<Map<String, Object>> rules = new LinkedList<>();
|
List<Map<String, Object>> rules = new LinkedList<>();
|
||||||
DataSource ds = dataSource.sourceDataSource();
|
DataSource ds = dataSource.sourceDataSource();
|
||||||
|
@ -1976,7 +1975,7 @@ public class CompareTwoTables {
|
||||||
|
|
||||||
Statement stmt = con.createStatement();
|
Statement stmt = con.createStatement();
|
||||||
|
|
||||||
String sql = "select * from DB_FUNCTIONS_MASTER";
|
String sql = "select FUNCTION_NAME from DB_FUNCTIONS_MASTER";
|
||||||
System.out.println(sql);
|
System.out.println(sql);
|
||||||
ResultSet rs_source = stmt.executeQuery(sql);
|
ResultSet rs_source = stmt.executeQuery(sql);
|
||||||
|
|
||||||
|
@ -1998,4 +1997,141 @@ public class CompareTwoTables {
|
||||||
return functions;
|
return functions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<String> getMasterRules() throws SQLException {
|
||||||
|
|
||||||
|
|
||||||
|
List<String> rules = new LinkedList<>();
|
||||||
|
|
||||||
|
DataSource ds = dataSource.appDataSource();
|
||||||
|
Connection con = ds.getConnection();
|
||||||
|
System.out.println("Connection established......");
|
||||||
|
|
||||||
|
con.prepareStatement("alter session set nls_date_format='YYYY-MM-DD HH24:MI:SS'").execute();
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
System.out.println("Connection established......");
|
||||||
|
|
||||||
|
Statement stmt = con.createStatement();
|
||||||
|
|
||||||
|
String sql = "select RULE from RULE_MASTER";
|
||||||
|
System.out.println(sql);
|
||||||
|
ResultSet rs_source = stmt.executeQuery(sql);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
while (rs_source.next()) {
|
||||||
|
|
||||||
|
rules.add(rs_source.getString(1));
|
||||||
|
|
||||||
|
}
|
||||||
|
con.close();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
con.close();
|
||||||
|
}
|
||||||
|
con.close();
|
||||||
|
System.out.println(rules);
|
||||||
|
return rules;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public String migrateBasedOnDefaultCaseRule(Map<String, String> map) {
|
||||||
|
|
||||||
|
String srcTbl = map.get("sourceTable");
|
||||||
|
|
||||||
|
String srcCols = map.get("SRC_COLUMNS");
|
||||||
|
|
||||||
|
String defaultCase = map.get("value1");
|
||||||
|
|
||||||
|
|
||||||
|
String destTbl = map.get("destTable");
|
||||||
|
|
||||||
|
String destCols = map.get("DEST_COLUMNS");
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
List<Map<String, Object>> list = getSrcAggRuleData(srcTbl, srcCols);
|
||||||
|
|
||||||
|
for (Map<String, Object> map2 : list) {
|
||||||
|
int i = instertDestDefaultRuleData(destTbl, destCols, map2,defaultCase);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
|
||||||
|
return "Migration fail";
|
||||||
|
}
|
||||||
|
|
||||||
|
return "Migration success";
|
||||||
|
}
|
||||||
|
|
||||||
|
public int instertDestDefaultRuleData(String destTbl, String destTblCols, Map<String, Object> map, String defaultCase)
|
||||||
|
throws ClassNotFoundException, SQLException {
|
||||||
|
|
||||||
|
System.out.println("--------------instertDestSumRuleData start------------------");
|
||||||
|
DataSource ds = dataSource.destinationDataSource();
|
||||||
|
Connection con = ds.getConnection();
|
||||||
|
System.out.println("Connection established......");
|
||||||
|
|
||||||
|
con.prepareStatement("alter session set nls_date_format='YYYY-MM-DD HH24:MI:SS'").execute();
|
||||||
|
|
||||||
|
String tempDestColsArray[] = destTblCols.split(",");
|
||||||
|
|
||||||
|
String sql1 = "INSERT INTO " + destTbl + " ( " + destTblCols + ") VALUES (";
|
||||||
|
|
||||||
|
String sql2 = "";
|
||||||
|
|
||||||
|
for (String col : tempDestColsArray) {
|
||||||
|
sql2 = sql2 + "?,";
|
||||||
|
}
|
||||||
|
|
||||||
|
StringBuilder sb = new StringBuilder(sql2);
|
||||||
|
sb.deleteCharAt(sb.length() - 1);
|
||||||
|
sb.append(")");
|
||||||
|
sql2 = sb.toString();
|
||||||
|
|
||||||
|
String finalsql = sql1 + sql2;
|
||||||
|
|
||||||
|
System.out.println(finalsql);
|
||||||
|
|
||||||
|
tempDestColsArray = destTblCols.split(",");
|
||||||
|
try {
|
||||||
|
|
||||||
|
PreparedStatement ps = con.prepareStatement(finalsql);
|
||||||
|
|
||||||
|
int i = 1;
|
||||||
|
|
||||||
|
for (String col : tempDestColsArray) {
|
||||||
|
String temp = col.trim();
|
||||||
|
try {
|
||||||
|
if(map.get(temp).equals(null)) {
|
||||||
|
ps.setObject(i, defaultCase);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
ps.setObject(i, map.get(temp));
|
||||||
|
}catch (Exception e) {
|
||||||
|
ps.setObject(i, defaultCase);
|
||||||
|
}
|
||||||
|
|
||||||
|
i++;
|
||||||
|
|
||||||
|
}
|
||||||
|
int j = ps.executeUpdate();
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
con.close();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("--------------instertDestSumRuleData end------------------");
|
||||||
|
con.close();
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user