/vms/java/com/stratify/apps/vms/dao/VMSMyDAO.java

https://github.com/rkshakya/RKSProjects · Java · 1277 lines · 1041 code · 201 blank · 35 comment · 59 complexity · 89f7ee51a919ea63695c14e6253efa9b MD5 · raw file

  1. /*
  2. * VMSMyDAO.java
  3. *
  4. * Created on November 22, 2007, 1:09 AM
  5. *
  6. * Stratify Inc P Ltd
  7. */
  8. package com.stratify.apps.vms.dao;
  9. import com.stratify.apps.vms.common.VMSCommonUtils;
  10. import com.stratify.apps.vms.common.VMSStaticParams;
  11. import com.stratify.apps.vms.common.exceptions.VMSDAOException;
  12. import com.stratify.apps.vms.common.vos.VMSCaseServer;
  13. import com.stratify.apps.vms.common.vos.VMSCaseBean;
  14. import com.stratify.apps.vms.common.vos.VMSCaseComponent;
  15. import com.stratify.apps.vms.common.vos.VMSCaseServerCombo;
  16. import com.stratify.apps.vms.common.vos.VMSCompoBean;
  17. import com.stratify.apps.vms.common.vos.VMSComponentBean;
  18. import com.stratify.apps.vms.common.vos.VMSServerBean;
  19. import com.stratify.apps.vms.common.vos.VMSServerComponent;
  20. import com.stratify.apps.vms.common.vos.VMSVersionBean;
  21. import com.stratify.apps.vms.common.vos.VMSVersionComponent;
  22. import com.stratify.apps.vms.common.vos.VMSRuleBean;
  23. import com.stratify.apps.vms.dao.common.VMSDAOQueries;
  24. import com.stratify.apps.vms.dao.common.VMSDAOUtils;
  25. import java.sql.CallableStatement;
  26. import java.sql.Connection;
  27. import java.sql.Date;
  28. import java.sql.PreparedStatement;
  29. import java.sql.ResultSet;
  30. import java.sql.SQLException;
  31. import java.sql.Statement;
  32. import java.text.SimpleDateFormat;
  33. import java.util.ArrayList;
  34. import java.util.HashMap;
  35. import com.stratify.common.logging.Logger;
  36. /**
  37. *
  38. * @author ravikishores
  39. */
  40. public class VMSMyDAO {
  41. static Logger logger = Logger.getLogger(VMSMyDAO.class.getName());
  42. Connection con = null;
  43. /**
  44. * Creates a new instance of VMSMyDAO
  45. */
  46. public VMSMyDAO(Connection con1) {
  47. this.con = con1;
  48. }
  49. public ArrayList getCaseServers(String dom) throws VMSDAOException{
  50. logger.traceEntry("getCaseServers");
  51. ArrayList temp = new ArrayList();
  52. PreparedStatement pstmtgetCaseServ = null;
  53. ResultSet rsgetCaseServ = null;
  54. String cName;
  55. String dbVersion;
  56. String serverName;
  57. String domain;
  58. try{
  59. pstmtgetCaseServ = con.prepareStatement(VMSDAOQueries.GET_CASE_SERVERS);
  60. logger.info("getCaseServers: GET_CASE_SERVERS" + VMSDAOQueries.GET_CASE_SERVERS);
  61. if(dom.equals("")){
  62. pstmtgetCaseServ.setString(1, VMSStaticParams.BEALIAS);
  63. pstmtgetCaseServ.setString(2, VMSStaticParams.FEALAIS);
  64. logger.info("Params: " + VMSStaticParams.BEALIAS + "," + VMSStaticParams.FEALAIS);
  65. }else{
  66. pstmtgetCaseServ.setString(1, dom + VMSStaticParams.BEALIAS);
  67. pstmtgetCaseServ.setString(2, dom + VMSStaticParams.FEALAIS);
  68. logger.info("Params: " + dom + VMSStaticParams.BEALIAS + "," + VMSStaticParams.FEALAIS);
  69. }
  70. rsgetCaseServ = pstmtgetCaseServ.executeQuery();
  71. while(rsgetCaseServ.next()){
  72. cName = null;
  73. dbVersion = null;
  74. serverName = null;
  75. domain = null;
  76. VMSCaseServer cs = new VMSCaseServer();
  77. cName = rsgetCaseServ.getString("CASENAME");
  78. dbVersion = rsgetCaseServ.getString("DB_VERSION");
  79. serverName = rsgetCaseServ.getString("SERVER_NAME");
  80. domain = rsgetCaseServ.getString("DOMAIN");
  81. if(serverName.toLowerCase().indexOf(VMSStaticParams.APACBEALIAS) > -1){
  82. serverName = serverName.toLowerCase().replaceAll(VMSStaticParams.APACBEALIAS.toLowerCase(), "");
  83. }else if(serverName.toLowerCase().indexOf(VMSStaticParams.APACFEALAIS) > -1){
  84. serverName = serverName.toLowerCase().replaceAll(VMSStaticParams.APACFEALAIS.toLowerCase(), "");
  85. }
  86. cs.setCaseName(cName);
  87. cs.setDbVersion(dbVersion);
  88. cs.setServerName(serverName);
  89. cs.setDomain(domain);
  90. temp.add(cs);
  91. }
  92. }catch(SQLException sqle){
  93. logger.error("getCaseServers: SQL Error: " + sqle);
  94. throw new VMSDAOException(sqle.getMessage());
  95. }catch(Exception ex){
  96. logger.error("getCaseServers: Error: " + ex);
  97. throw new VMSDAOException(ex.getMessage());
  98. }finally{
  99. VMSDAOUtils.freeUp(rsgetCaseServ, pstmtgetCaseServ);
  100. }
  101. return temp;
  102. }
  103. public int[] getFlags(String caseName, String serverName, String domain) throws VMSDAOException {
  104. logger.traceEntry("getFlags");
  105. int[] temp = {0,0,0};
  106. PreparedStatement pstmtGetFlags = null;
  107. ResultSet rsGetFlags = null;
  108. int compo1, compo2, compo3;
  109. try{
  110. pstmtGetFlags = con.prepareStatement(VMSDAOQueries.GET_INS_INFO);
  111. pstmtGetFlags.setString(1, caseName);
  112. pstmtGetFlags.setString(2, serverName);
  113. pstmtGetFlags.setString(3, domain);
  114. pstmtGetFlags.setString(4, caseName);
  115. pstmtGetFlags.setString(5, serverName);
  116. pstmtGetFlags.setString(6, domain);
  117. logger.info("getFlags: " + VMSDAOQueries.GET_INS_INFO + " Params: " + caseName + "," + serverName + "," + domain + "," + caseName + "," + serverName + "," + domain);
  118. rsGetFlags = pstmtGetFlags.executeQuery();
  119. while(rsGetFlags.next()){
  120. compo1 = 0; compo2 = 0; compo3 = 0;
  121. compo1 = rsGetFlags.getInt("CASE_GID");
  122. compo2 = rsGetFlags.getInt("SERVER_GID");
  123. compo3 = rsGetFlags.getInt("CASE_SERVER_GID");
  124. if((compo1 > 0) && (compo2 == 0) && (compo3 == 0)){
  125. //case exists
  126. temp[0] = compo1;
  127. }else if((compo1 == 0)&&(compo2 > 0)&&(compo3 ==0)){
  128. //server entry exists
  129. temp[1] = compo2;
  130. }else if((compo1 > 0 )&&(compo2 > 0)&&(compo3 > 0)){
  131. //all 3 exists
  132. temp[2] = compo3;
  133. }
  134. }
  135. }catch(SQLException sqle){
  136. logger.error("getFlags: DB related error: " + sqle);
  137. throw new VMSDAOException(VMSStaticParams.SEVERITY_2, VMSStaticParams.CRITICAL, "Error getting flags for caseserver sync", 0);
  138. }catch(Exception ex){
  139. logger.error("getFlags: DB related error: " + ex);
  140. throw new VMSDAOException(ex.getMessage());
  141. }finally{
  142. VMSDAOUtils.freeUp(rsGetFlags, pstmtGetFlags);
  143. }
  144. logger.traceExit("getFlags");
  145. return temp;
  146. }
  147. public int[] getServCompoFlags(String caseName, String serverName, String component, String domain) throws VMSDAOException{
  148. int[] temp = {0,0,0,0}; //first flag - servGID, 2nd - compoGid, 3rd - caseServerGID, 4rth -caseGID
  149. PreparedStatement pstmtGetFlags = null;
  150. ResultSet rsGetFlags = null;
  151. try{
  152. pstmtGetFlags = con.prepareStatement(VMSDAOQueries.GET_COMPO_SERVER_FLAGS);
  153. logger.debug("getServCompoFlags:Getting flags using Query: " + VMSDAOQueries.GET_COMPO_SERVER_FLAGS);
  154. logger.debug("getServCompoFlags:PARAMS: serverName " + serverName + " domain " + domain + " component " + component + " caseName " + caseName );
  155. pstmtGetFlags.setString(1, serverName);
  156. pstmtGetFlags.setString(2, domain);
  157. pstmtGetFlags.setString(3, component);
  158. pstmtGetFlags.setString(4, caseName);
  159. pstmtGetFlags.setString(5, serverName);
  160. pstmtGetFlags.setString(6, domain);
  161. pstmtGetFlags.setString(7, caseName);
  162. rsGetFlags = pstmtGetFlags.executeQuery();
  163. int compo1, compo2, compo3, compo4;
  164. while(rsGetFlags.next()){
  165. compo1 = 0; compo2 = 0; compo3 = 0; compo4 = 0;
  166. compo1 = rsGetFlags.getInt("SERVER_GID");
  167. compo2 = rsGetFlags.getInt("COMPO_GID");
  168. compo3 = rsGetFlags.getInt("CASE_SERVER_GID");
  169. compo4 = rsGetFlags.getInt("CASE_GID");
  170. if((compo1 > 0) && (compo2 == 0) && (compo3 == 0) && (compo4 == 0)){
  171. temp[0] = compo1;
  172. }else if((compo1 == 0)&&(compo2 > 0)&&(compo3 ==0) && (compo4 == 0)){
  173. temp[1] = compo2;
  174. }else if((compo1 > 0 )&&(compo2 == 0)&&(compo3 > 0) && (compo4 > 0)){
  175. temp[2] = compo3;
  176. }else if ((compo1 == 0 )&&(compo2 == 0)&&(compo3 == 0) && (compo4 > 0)){
  177. temp[3] = compo4;
  178. }
  179. }
  180. }catch(SQLException sqle){
  181. logger.error("getServCompoFlags:DB related error: ", sqle);
  182. throw new VMSDAOException(VMSStaticParams.SEVERITY_2, VMSStaticParams.ERROR, "Error getting server compo flag", caseName);
  183. }catch(Exception ex){
  184. logger.error("getServCompoFlags:System error: ", ex);
  185. throw new VMSDAOException(ex.getMessage());
  186. }finally{
  187. VMSDAOUtils.freeUp(rsGetFlags, pstmtGetFlags);
  188. }
  189. return temp;
  190. }
  191. public int insCase(String caseName) throws VMSDAOException{
  192. int insGid = 0;
  193. int noIns = 0;
  194. PreparedStatement pstmtInsCase = null;
  195. PreparedStatement pstmtGetGid = null;
  196. ResultSet rsGetGid = null;
  197. try{
  198. pstmtInsCase = con.prepareStatement(VMSDAOQueries.INS_CASE);
  199. pstmtInsCase.setString(1, caseName);
  200. logger.info("insCase : " + VMSDAOQueries.INS_CASE + " Params: " + caseName);
  201. noIns = pstmtInsCase.executeUpdate();
  202. if(noIns > 0){
  203. pstmtGetGid = con.prepareStatement(VMSDAOQueries.GET_LAST_GID);
  204. rsGetGid = pstmtGetGid.executeQuery();
  205. if(rsGetGid.next()){
  206. insGid = rsGetGid.getInt(1);
  207. }
  208. }
  209. }catch(SQLException sqle){
  210. logger.error("insCase: DB related error: " + sqle.getMessage());
  211. throw new VMSDAOException(VMSStaticParams.SEVERITY_2, VMSStaticParams.CRITICAL, "Unable to insert case info", caseName);
  212. }catch(Exception ex){
  213. logger.error("insCase: DB related error: " + ex.getMessage());
  214. throw new VMSDAOException(ex.getMessage());
  215. }finally{
  216. VMSDAOUtils.freeUp(rsGetGid, pstmtGetGid);
  217. VMSDAOUtils.freeUp(null, pstmtInsCase);
  218. }
  219. return insGid;
  220. }
  221. public int insServer(String serverName, String domain) throws VMSDAOException{
  222. int insGid = 0;
  223. int noIns = 0;
  224. PreparedStatement pstmtInsServer = null;
  225. PreparedStatement pstmtGetGid = null;
  226. ResultSet rsGetGid = null;
  227. try{
  228. pstmtInsServer = con.prepareStatement(VMSDAOQueries.INS_SERVER);
  229. pstmtInsServer.setString(1, serverName);
  230. pstmtInsServer.setString(2, domain);
  231. logger.info("insServer: Using query: " + VMSDAOQueries.INS_SERVER);
  232. logger.info("insServer: Params: " + serverName + "," + domain);
  233. noIns = pstmtInsServer.executeUpdate();
  234. if(noIns > 0){
  235. pstmtGetGid = con.prepareStatement(VMSDAOQueries.GET_LAST_GID);
  236. rsGetGid = pstmtGetGid.executeQuery();
  237. if(rsGetGid.next()){
  238. insGid = rsGetGid.getInt(1);
  239. }
  240. }
  241. }catch(SQLException sqle){
  242. logger.error("insServer: DB related error: " + sqle);
  243. throw new VMSDAOException(VMSStaticParams.SEVERITY_2, VMSStaticParams.ERROR, "Unable to insert Server info", serverName);
  244. }catch(Exception ex){
  245. logger.error("insServer: general error: " + ex);
  246. throw new VMSDAOException(ex.getMessage());
  247. }finally{
  248. VMSDAOUtils.freeUp(rsGetGid, pstmtGetGid);
  249. VMSDAOUtils.freeUp(null, pstmtInsServer);
  250. }
  251. return insGid;
  252. }
  253. public int insCaseServer(int caseGid, int serverGid) throws VMSDAOException{
  254. int insGid = 0;
  255. int noIns = 0;
  256. PreparedStatement pstmtInsCaseServer = null;
  257. PreparedStatement pstmtGetGid = null;
  258. ResultSet rsGetGid = null;
  259. try{
  260. pstmtInsCaseServer = con.prepareStatement(VMSDAOQueries.INS_CASE_SERVER);
  261. pstmtInsCaseServer.setInt(1, caseGid);
  262. pstmtInsCaseServer.setInt(2, serverGid);
  263. logger.info("insCaseServer: INS CASESERV" + VMSDAOQueries.INS_CASE_SERVER);
  264. logger.info("insCaseServer: Params" + caseGid + "," + serverGid);
  265. noIns = pstmtInsCaseServer.executeUpdate();
  266. if(noIns > 0){
  267. logger.info("CASESERV ROW INSERTED");
  268. pstmtGetGid = con.prepareStatement(VMSDAOQueries.GET_LAST_GID);
  269. rsGetGid = pstmtGetGid.executeQuery();
  270. if(rsGetGid.next()){
  271. insGid = rsGetGid.getInt(1);
  272. }
  273. }
  274. }catch(SQLException sqle){
  275. logger.error("insCaseServer: DB related error: " + sqle);
  276. throw new VMSDAOException(VMSStaticParams.SEVERITY_2, VMSStaticParams.ERROR, "Unable to insert caseserver info", caseGid + " " + serverGid);
  277. }catch(Exception ex){
  278. logger.error("insCaseServer: error: " + ex);
  279. throw new VMSDAOException(ex.getMessage());
  280. }finally{
  281. VMSDAOUtils.freeUp(rsGetGid, pstmtGetGid);
  282. VMSDAOUtils.freeUp(null, pstmtInsCaseServer);
  283. }
  284. return insGid;
  285. }
  286. //pass 0 to get BE caseServs, 1 to get FE caseServs
  287. public ArrayList getServers(int i) throws VMSDAOException{
  288. ArrayList temp = new ArrayList();
  289. PreparedStatement pstmtGetBEServs = null;
  290. ResultSet rsGetBEServs = null;
  291. int csGid ;
  292. String cName ;
  293. String servName ;
  294. String domain;
  295. try{
  296. if(i == 0){
  297. pstmtGetBEServs = con.prepareStatement(VMSDAOQueries.GET_BE_CASE_SERVS);
  298. logger.info("getServers: " + VMSDAOQueries.GET_BE_CASE_SERVS);
  299. }else if (i == 1){
  300. pstmtGetBEServs = con.prepareStatement(VMSDAOQueries.GET_FE_CASE_SERVS);
  301. logger.info("getServers: " + VMSDAOQueries.GET_FE_CASE_SERVS);
  302. }
  303. rsGetBEServs = pstmtGetBEServs.executeQuery();
  304. while(rsGetBEServs.next()){
  305. csGid = 0;
  306. cName = null;
  307. servName = null;
  308. domain = null;
  309. VMSCaseServer caseServBE = new VMSCaseServer();
  310. csGid = rsGetBEServs.getInt("GID");
  311. cName = rsGetBEServs.getString("CASENAME");
  312. servName = rsGetBEServs.getString("SERVER");
  313. domain = rsGetBEServs.getString("DOMAIN");
  314. caseServBE.setCaseName(cName);
  315. caseServBE.setServerName(servName);
  316. caseServBE.setDomain(domain);
  317. caseServBE.setCaseServGID(csGid);
  318. temp.add(caseServBE);
  319. }
  320. }catch(SQLException sqle){
  321. logger.error("getServers: DB related error: " + sqle);
  322. throw new VMSDAOException(sqle.getMessage());
  323. }catch(Exception ex){
  324. logger.error("getServers: Genaral error: " + ex);
  325. throw new VMSDAOException(ex.getMessage());
  326. }finally{
  327. VMSDAOUtils.freeUp(rsGetBEServs, pstmtGetBEServs);
  328. }
  329. return temp;
  330. }
  331. public int existsComponentVersion(int compoGID, int major, int minor, int build, int patch) throws VMSDAOException {
  332. int temp = 0;
  333. PreparedStatement pstmtGetCompoVer = null;
  334. ResultSet rsGetCompoVer = null;
  335. try{
  336. pstmtGetCompoVer = con.prepareStatement(VMSDAOQueries.GET_COMPO_VERSION_GID);
  337. pstmtGetCompoVer.setInt(1,compoGID);
  338. pstmtGetCompoVer.setInt(2,major);
  339. pstmtGetCompoVer.setInt(3,minor);
  340. pstmtGetCompoVer.setInt(4,build);
  341. pstmtGetCompoVer.setInt(5,patch);
  342. rsGetCompoVer = pstmtGetCompoVer.executeQuery();
  343. if(rsGetCompoVer.next()){
  344. temp = rsGetCompoVer.getInt("GID");
  345. }
  346. }catch(SQLException sqle){
  347. logger.error("existsComponentVersion: DB related error: " , sqle);
  348. throw new VMSDAOException(VMSStaticParams.SEVERITY_2, VMSStaticParams.ERROR, "Unable to get compo version info for compoGId", compoGID + "");
  349. }catch(Exception ex){
  350. logger.error("existsComponentVersion: Error: " , ex);
  351. throw new VMSDAOException(ex.getMessage());
  352. }finally{
  353. VMSDAOUtils.freeUp(rsGetCompoVer, pstmtGetCompoVer);
  354. }
  355. return temp;
  356. }
  357. public int insVersion(int compoGID, int major, int minor, int build, int patch) throws VMSDAOException {
  358. int temp = 0;
  359. int insCount = 0;
  360. PreparedStatement pstmtInsVersion = null;
  361. ResultSet rsLastGID = null;
  362. try{
  363. pstmtInsVersion = con.prepareStatement(VMSDAOQueries.INS_VERSION_INFO);
  364. pstmtInsVersion.setInt(1, compoGID);
  365. pstmtInsVersion.setInt(2, major);
  366. pstmtInsVersion.setInt(3, minor);
  367. pstmtInsVersion.setInt(4, build);
  368. pstmtInsVersion.setInt(5, patch);
  369. insCount = pstmtInsVersion.executeUpdate();
  370. logger.info("INSERTION QUERY: " + VMSDAOQueries.INS_VERSION_INFO);
  371. logger.info(compoGID + ":" + major + ":" + minor + ":" + build + ":" + patch);
  372. logger.info("INSCOUNT: " + insCount);
  373. if(insCount > 0){
  374. pstmtInsVersion = con.prepareStatement(VMSDAOQueries.GET_LAST_GID);
  375. rsLastGID = pstmtInsVersion.executeQuery();
  376. if (rsLastGID.next()){
  377. temp = rsLastGID.getInt(1);
  378. }
  379. }
  380. }catch(SQLException sqle){
  381. logger.error("insVersion: DB related error: " , sqle);
  382. throw new VMSDAOException(VMSStaticParams.SEVERITY_2, VMSStaticParams.ERROR, "Unable to insert version info", VMSStaticParams.NA);
  383. }catch(Exception ex){
  384. logger.error("insVersion: error: " , ex);
  385. throw new VMSDAOException(ex.getMessage());
  386. }finally{
  387. VMSDAOUtils.freeUp(rsLastGID, pstmtInsVersion);
  388. VMSDAOUtils.freeUp(null, pstmtInsVersion);
  389. }
  390. return temp;
  391. }
  392. public int existsComponentMapping(int caseServGID, int compoVerGID, String port) throws VMSDAOException {
  393. int temp = 0;
  394. PreparedStatement pstmtCompoMap = null;
  395. ResultSet rsCompoMap = null;
  396. try{
  397. pstmtCompoMap = con.prepareStatement(VMSDAOQueries.GET_COMPO_MAPPING);
  398. pstmtCompoMap.setInt(1, caseServGID);
  399. pstmtCompoMap.setInt(2, compoVerGID);
  400. pstmtCompoMap.setString(3, port);
  401. rsCompoMap = pstmtCompoMap.executeQuery();
  402. while(rsCompoMap.next()){
  403. temp = rsCompoMap.getInt("GID");
  404. }
  405. }catch(SQLException sqle){
  406. logger.error("existsComponentMapping: DB related error: " , sqle);
  407. throw new VMSDAOException(VMSStaticParams.SEVERITY_2, VMSStaticParams.ERROR, "Error in existsComponent Mapping check", caseServGID + " " + compoVerGID + " " + port);
  408. }catch(Exception ex){
  409. logger.error("existsComponentMapping: error: " , ex);
  410. throw new VMSDAOException(ex.getMessage());
  411. }finally{
  412. VMSDAOUtils.freeUp(rsCompoMap, pstmtCompoMap);
  413. }
  414. return temp;
  415. }
  416. public int insCompoMapping(int caseServGID, int compoVerGID, String port) throws VMSDAOException{
  417. int temp = 0;
  418. int insCount = 0;
  419. PreparedStatement pstmtInsCompoMapping = null;
  420. ResultSet rsInsCompoGid = null;
  421. try{
  422. pstmtInsCompoMapping = con.prepareStatement(VMSDAOQueries.INS_COMPO_MAPPING);
  423. pstmtInsCompoMapping.setInt(1, caseServGID);
  424. pstmtInsCompoMapping.setInt(2, compoVerGID);
  425. pstmtInsCompoMapping.setString(3, port);
  426. insCount = pstmtInsCompoMapping.executeUpdate();
  427. if(insCount > 0){
  428. pstmtInsCompoMapping = con.prepareStatement(VMSDAOQueries.GET_LAST_GID);
  429. rsInsCompoGid = pstmtInsCompoMapping.executeQuery();
  430. while(rsInsCompoGid.next()){
  431. temp = rsInsCompoGid.getInt(1);
  432. }
  433. }
  434. }catch(SQLException sqle){
  435. logger.error("insCompoMapping: DB related error: " , sqle);
  436. throw new VMSDAOException(VMSStaticParams.SEVERITY_2, VMSStaticParams.ERROR, "Error inserting compo mapping info", caseServGID + " " + compoVerGID + " " + port);
  437. }catch(Exception ex){
  438. logger.error("insCompoMapping: error: " , ex);
  439. throw new VMSDAOException(ex.getMessage());
  440. }finally{
  441. VMSDAOUtils.freeUp(rsInsCompoGid, pstmtInsCompoMapping);
  442. VMSDAOUtils.freeUp(null, pstmtInsCompoMapping);
  443. }
  444. return temp;
  445. }
  446. public ArrayList getCompoVerGID(int compoGID, int major, int minor, int build, int patch) throws VMSDAOException{
  447. ArrayList temp = new ArrayList();
  448. PreparedStatement pstmtGetCompoVer = null;
  449. ResultSet rsGetCompoVer = null;
  450. int compGID = 0;
  451. try{
  452. pstmtGetCompoVer = con.prepareStatement(VMSDAOQueries.GET_COMPO_VERSION_GID_EXC);
  453. pstmtGetCompoVer.setInt(1, compoGID);
  454. pstmtGetCompoVer.setInt(2, major);
  455. pstmtGetCompoVer.setInt(3, minor);
  456. pstmtGetCompoVer.setInt(4, build);
  457. pstmtGetCompoVer.setInt(5, patch);
  458. rsGetCompoVer = pstmtGetCompoVer.executeQuery();
  459. while(rsGetCompoVer.next()){
  460. compGID = rsGetCompoVer.getInt("GID");
  461. temp.add(new Integer(compGID));
  462. }
  463. }catch(SQLException sqle){
  464. logger.error("getCompoVerGID: DB related error: ", sqle);
  465. throw new VMSDAOException(sqle.getMessage());
  466. }catch(Exception ex){
  467. logger.error("getCompoVerGID: error: ", ex);
  468. throw new VMSDAOException(ex.getMessage());
  469. }finally{
  470. VMSDAOUtils.freeUp(rsGetCompoVer, pstmtGetCompoVer);
  471. }
  472. return temp;
  473. }
  474. public int updateMapping(int mapGID) throws VMSDAOException {
  475. int ret = 0;
  476. PreparedStatement pstmtUpdateMap = null;
  477. try{
  478. pstmtUpdateMap = con.prepareStatement(VMSDAOQueries.UPDATE_COMPO_MAPPING);
  479. pstmtUpdateMap.setInt(1, mapGID);
  480. ret = pstmtUpdateMap.executeUpdate();
  481. }catch(SQLException sqle){
  482. logger.error("updateMapping: DB related error: ", sqle);
  483. throw new VMSDAOException(VMSStaticParams.SEVERITY_2, VMSStaticParams.ERROR, "Error updating is_deleted flag ", mapGID + "");
  484. }catch(Exception ex){
  485. logger.error("updateMapping: error: ", ex);
  486. throw new VMSDAOException(ex.getMessage());
  487. }finally{
  488. VMSDAOUtils.freeUp(null, pstmtUpdateMap);
  489. }
  490. return ret;
  491. }
  492. public ArrayList getCompoBeans() throws VMSDAOException {
  493. ArrayList ret = new ArrayList();
  494. PreparedStatement pstmtGetCompo = null ;
  495. ResultSet rsGetCompo = null;
  496. int comVerGID = 0;
  497. int Major = 0;
  498. int Minor = 0;
  499. int Build = 0;
  500. int Patch = 0;
  501. String CompoName = null;
  502. try{
  503. pstmtGetCompo = con.prepareStatement(VMSDAOQueries.GET_COMPO_VER);
  504. rsGetCompo = pstmtGetCompo.executeQuery();
  505. logger.info("getCompoBeans: " + VMSDAOQueries.GET_COMPO_VER);
  506. while(rsGetCompo.next()){
  507. comVerGID = 0;
  508. Major = 0;
  509. Minor = 0;
  510. Build = 0;
  511. Patch = 0;
  512. CompoName = null;
  513. VMSCompoBean cBean = new VMSCompoBean();
  514. comVerGID = rsGetCompo.getInt("GID");
  515. Major = rsGetCompo.getInt("MAJOR");
  516. Minor = rsGetCompo.getInt("MINOR");
  517. Build = rsGetCompo.getInt("BUILD");
  518. Patch = rsGetCompo.getInt("PATCH");
  519. CompoName = rsGetCompo.getString("COMPONENT");
  520. cBean.setCompoVerGID(comVerGID);
  521. cBean.setMaj(Major);
  522. cBean.setMin(Minor);
  523. cBean.setBld(Build);
  524. cBean.setPatch(Patch);
  525. cBean.setCompoName(CompoName);
  526. ret.add(cBean);
  527. logger.info("getCompoBeans: Component Bean added in DAO");
  528. }
  529. }catch(SQLException sqle){
  530. logger.error("getCompoBeans: DB related error: ", sqle);
  531. throw new VMSDAOException(sqle.getMessage());
  532. }catch(Exception ex){
  533. logger.error("getCompoBeans: error: ", ex);
  534. throw new VMSDAOException(ex.getMessage());
  535. }finally{
  536. VMSDAOUtils.freeUp(rsGetCompo, pstmtGetCompo);
  537. }
  538. return ret;
  539. }
  540. public int getMaxRule() throws VMSDAOException{
  541. int ret = 0;
  542. PreparedStatement pstmtGetRule = null ;
  543. ResultSet rsGetRule = null;
  544. try{
  545. pstmtGetRule = con.prepareStatement(VMSDAOQueries.GET_MAX_RULE);
  546. rsGetRule = pstmtGetRule.executeQuery();
  547. logger.info("getMaxRule: " + VMSDAOQueries.GET_MAX_RULE);
  548. while(rsGetRule.next()){
  549. ret = rsGetRule.getInt(1);
  550. }
  551. }catch(SQLException sqle){
  552. logger.error("getMaxRule: MySQL DB related error: " , sqle);
  553. throw new VMSDAOException(sqle.getMessage());
  554. }catch(Exception ex){
  555. logger.error("getMaxRule: error: ", ex);
  556. throw new VMSDAOException(ex.getMessage());
  557. }finally{
  558. VMSDAOUtils.freeUp(rsGetRule, pstmtGetRule);
  559. }
  560. return ret;
  561. }
  562. public int insRule(int[] compoGIDs, String ruleName, String ruleDescription) throws VMSDAOException {
  563. int ret = 0;
  564. int maxRuleNum = 0;
  565. PreparedStatement pstmtInsRule = null;
  566. ResultSet rsInsRule = null;
  567. PreparedStatement pstmtInsRuleMetadata = null;
  568. ResultSet rsInsRuleMetadata = null;
  569. PreparedStatement pstmtMaxRule = null;
  570. ResultSet rsMaxRule = null;
  571. //execute these queries as atomic
  572. try{
  573. con.setAutoCommit(false);
  574. //get the max rule num
  575. pstmtMaxRule = con.prepareStatement(VMSDAOQueries.GET_MAX_RULE);
  576. rsMaxRule = pstmtMaxRule.executeQuery();
  577. logger.info("insRule: GET_MAX_RULE: " + VMSDAOQueries.GET_MAX_RULE);
  578. if(rsMaxRule.next()){
  579. maxRuleNum = rsMaxRule.getInt(1);
  580. }
  581. maxRuleNum++;
  582. // ins into vms_rules_info
  583. pstmtInsRuleMetadata = con.prepareStatement(VMSDAOQueries.INS_RULE_METADATA);
  584. pstmtInsRuleMetadata.setString(1, ruleName);
  585. pstmtInsRuleMetadata.setString(2, ruleDescription);
  586. pstmtInsRuleMetadata.setInt(3, maxRuleNum);
  587. //set it to system user - for future convenience
  588. pstmtInsRuleMetadata.setInt(4, 1);
  589. int cntIns2 = pstmtInsRuleMetadata.executeUpdate();
  590. logger.info("insRule: INS_RULE_METADATA Query: " + VMSDAOQueries.INS_RULE_METADATA);
  591. logger.info("insRule: params: " + ruleName + "," + ruleDescription + "," + maxRuleNum + "," + 1);
  592. pstmtInsRule = con.prepareStatement(VMSDAOQueries.INS_RULE);
  593. logger.info("insRule: INS_RULE Query: " + VMSDAOQueries.INS_RULE);
  594. for(int i = 0 ; i < compoGIDs.length; i++){
  595. pstmtInsRule.setInt(1, maxRuleNum);
  596. pstmtInsRule.setInt(2, compoGIDs[i]);
  597. pstmtInsRule.setInt(3, 1);
  598. pstmtInsRule.addBatch();
  599. }
  600. int[] cntIns = pstmtInsRule.executeBatch();
  601. con.commit();
  602. con.setAutoCommit(true);
  603. if(cntIns.length > 0 && cntIns2 > 0){
  604. ret = 1;
  605. }
  606. ret = cntIns.length;
  607. }catch(SQLException sqle){
  608. logger.error("insRule : DB related error ", sqle);
  609. throw new VMSDAOException(sqle.getMessage());
  610. }catch(Exception ex){
  611. logger.error("insRule : error " , ex);
  612. throw new VMSDAOException(ex.getMessage());
  613. }finally{
  614. VMSDAOUtils.freeUp(rsInsRule, pstmtInsRule);
  615. VMSDAOUtils.freeUp(rsInsRuleMetadata, pstmtInsRuleMetadata);
  616. VMSDAOUtils.freeUp(rsMaxRule, pstmtMaxRule);
  617. }
  618. return ret;
  619. }
  620. public int checkRuleExists(int[] compoGIDs) throws VMSDAOException {
  621. int ret = 0;
  622. Statement stmtcheckRule = null;
  623. ResultSet rscheckRule = null;
  624. String qry = null;
  625. String compVerGIDs = null;
  626. int count = 0;
  627. ArrayList temp = new ArrayList();
  628. //construct compVerGID string here
  629. for(int i = 0 ; i < compoGIDs.length; i++){
  630. temp.add(new Integer(compoGIDs[i]));
  631. }
  632. compVerGIDs = VMSCommonUtils.join(temp, ",");
  633. qry = "select RULE, count(GID) from vms_compatibility_rules where COMP_VER_GID "
  634. + "IN ( " + compVerGIDs + " ) AND IS_DELETED = 0 GROUP BY RULE ORDER BY count(GID) DESC";
  635. /*
  636. qry = "SELECT RULES.RULE, COUNT(RULES.GID) FROM vms_compatibility_rules RULES, vms_rules_info INFO"
  637. + " WHERE (RULES.COMP_VER_GID IN ( " + compVerGIDs + " ) AND RULES.IS_DELETED = 0)"
  638. + " OR(RULES.RULE = INFO.RULE AND RULES.IS_DELETED = 0 AND INFO.NAME = '" + rulename + "' )"
  639. + " GROUP BY RULES.RULE ORDER BY count(RULES.GID) DESC";
  640. **/
  641. logger.info("checkRuleExists: " + qry);
  642. try{
  643. stmtcheckRule = con.createStatement();
  644. rscheckRule = stmtcheckRule.executeQuery(qry);
  645. if(rscheckRule.next()){
  646. count = rscheckRule.getInt(2);
  647. }
  648. logger.info("checkRuleExists : COUNT: " + count);
  649. if(count == compoGIDs.length){
  650. ret = 1;
  651. }
  652. }catch(SQLException sqle){
  653. logger.error("checkRuleExists: MySQL DB related error: " , sqle);
  654. throw new VMSDAOException(sqle.getMessage());
  655. }catch(Exception ex){
  656. logger.error("checkRuleExists: error: " , ex);
  657. throw new VMSDAOException(ex.getMessage());
  658. }finally{
  659. try{
  660. VMSDAOUtils.cleanUp(rscheckRule, stmtcheckRule);
  661. }catch(SQLException sqle){
  662. logger.error("checkRuleExists: ", sqle);
  663. throw new VMSDAOException(sqle.getMessage());
  664. }
  665. }
  666. return ret;
  667. }
  668. public ArrayList getCompoBeans(int[] compoVerGIDs) throws VMSDAOException {
  669. ArrayList ret = new ArrayList();
  670. Statement stmtGetCompo = null ;
  671. ResultSet rsGetCompo = null;
  672. String qryGetIns = null;
  673. String suffix = null;
  674. ArrayList gids = new ArrayList();
  675. int comVerGID = 0;
  676. int Major = 0;
  677. int Minor = 0;
  678. int Build = 0;
  679. int Patch = 0;
  680. String CompoName = null;
  681. for(int i = 0; i < compoVerGIDs.length; i++){
  682. gids.add(new Integer(compoVerGIDs[i]));
  683. }
  684. suffix = VMSCommonUtils.join(gids, ",");
  685. qryGetIns = "SELECT A.GID, A.MAJOR, A.MINOR, A.BUILD, A.PATCH, B.COMPONENT "
  686. + " FROM vms_compo_version A, vms_components B "
  687. + " WHERE A.COMP_GID = B.GID "
  688. + " AND A.GID IN (" + suffix + ")"
  689. + " ORDER BY B.BE, B.COMPONENT,A.MAJOR, A.MINOR, A.BUILD, A.PATCH";
  690. logger.info("getCompoBeans: " + qryGetIns);
  691. try{
  692. stmtGetCompo = con.createStatement();
  693. rsGetCompo = stmtGetCompo.executeQuery(qryGetIns);
  694. while(rsGetCompo.next()){
  695. comVerGID = 0;
  696. Major = 0;
  697. Minor = 0;
  698. Build = 0;
  699. Patch = 0;
  700. CompoName = null;
  701. VMSCompoBean cBean = new VMSCompoBean();
  702. comVerGID = rsGetCompo.getInt("GID");
  703. Major = rsGetCompo.getInt("MAJOR");
  704. Minor = rsGetCompo.getInt("MINOR");
  705. Build = rsGetCompo.getInt("BUILD");
  706. Patch = rsGetCompo.getInt("PATCH");
  707. CompoName = rsGetCompo.getString("COMPONENT");
  708. cBean.setCompoVerGID(comVerGID);
  709. cBean.setMaj(Major);
  710. cBean.setMin(Minor);
  711. cBean.setBld(Build);
  712. cBean.setPatch(Patch);
  713. cBean.setCompoName(CompoName);
  714. ret.add(cBean);
  715. logger.info("getCompoBeans: Compo Bean added in DAO");
  716. }
  717. }catch(SQLException sqle){
  718. logger.error("getCompoBeans: DB related error: " , sqle);
  719. throw new VMSDAOException(sqle.getMessage());
  720. }catch(Exception ex){
  721. logger.error("getCompoBeans: error: " , ex);
  722. throw new VMSDAOException(ex.getMessage());
  723. }finally{
  724. try{
  725. VMSDAOUtils.cleanUp(rsGetCompo, stmtGetCompo);
  726. }catch(SQLException sqle){
  727. logger.error("getCompoBeans: error: " , sqle);
  728. throw new VMSDAOException(sqle.getMessage());
  729. }
  730. }
  731. return ret;
  732. }
  733. public ArrayList getRules() throws VMSDAOException{
  734. ArrayList ret = new ArrayList();
  735. PreparedStatement pstmtGetRule = null;
  736. ResultSet rsGetRule = null;
  737. int rule ;
  738. String name ;
  739. String desc ;
  740. try{
  741. pstmtGetRule = con.prepareStatement(VMSDAOQueries.GET_RULE);
  742. rsGetRule = pstmtGetRule.executeQuery();
  743. logger.info("getRules: " + VMSDAOQueries.GET_RULE);
  744. while(rsGetRule.next()){
  745. VMSRuleBean rb = new VMSRuleBean();
  746. rule = 0;
  747. name = null;
  748. desc = null;
  749. rule = rsGetRule.getInt("RULE");
  750. name = rsGetRule.getString("NAME");
  751. desc = rsGetRule.getString("DESCRIPTION");
  752. rb.setRule(rule);
  753. rb.setRuleName(name);
  754. rb.setRuleDescription(desc);
  755. ret.add(rb);
  756. }
  757. }catch(SQLException sqle){
  758. logger.error("getRules: MySQL DB related error: " , sqle);
  759. throw new VMSDAOException(sqle.getMessage());
  760. }catch(Exception ex){
  761. logger.error("getRules: error: " , ex);
  762. throw new VMSDAOException(ex.getMessage());
  763. }finally{
  764. VMSDAOUtils.freeUp(rsGetRule, pstmtGetRule);
  765. }
  766. return ret;
  767. }
  768. public ArrayList getCompoBeans(int rulNum) throws VMSDAOException{
  769. ArrayList ret = new ArrayList();
  770. PreparedStatement pstmtGetCompo = null ;
  771. ResultSet rsGetCompo = null;
  772. int comVerGID = 0;
  773. int Major = 0;
  774. int Minor = 0;
  775. int Build = 0;
  776. int Patch = 0;
  777. String CompoName = null;
  778. try{
  779. pstmtGetCompo = con.prepareStatement(VMSDAOQueries.GET_COMPO_VER_RULE);
  780. pstmtGetCompo.setInt(1, rulNum);
  781. rsGetCompo = pstmtGetCompo.executeQuery();
  782. logger.info("getCompoBeans: " + VMSDAOQueries.GET_COMPO_VER_RULE);
  783. while(rsGetCompo.next()){
  784. comVerGID = 0;
  785. Major = 0;
  786. Minor = 0;
  787. Build = 0;
  788. Patch = 0;
  789. CompoName = null;
  790. VMSCompoBean cBean = new VMSCompoBean();
  791. comVerGID = rsGetCompo.getInt("GID");
  792. Major = rsGetCompo.getInt("MAJOR");
  793. Minor = rsGetCompo.getInt("MINOR");
  794. Build = rsGetCompo.getInt("BUILD");
  795. Patch = rsGetCompo.getInt("PATCH");
  796. CompoName = rsGetCompo.getString("COMPONENT");
  797. cBean.setCompoVerGID(comVerGID);
  798. cBean.setMaj(Major);
  799. cBean.setMin(Minor);
  800. cBean.setBld(Build);
  801. cBean.setPatch(Patch);
  802. cBean.setCompoName(CompoName);
  803. ret.add(cBean);
  804. }
  805. }catch(SQLException sqle){
  806. logger.error("getCompoBeans: DB related error: ", sqle);
  807. throw new VMSDAOException(sqle.getMessage());
  808. }catch(Exception ex){
  809. logger.error("getCompoBeans: error: ", ex);
  810. throw new VMSDAOException(ex.getMessage());
  811. }finally{
  812. VMSDAOUtils.freeUp(rsGetCompo, pstmtGetCompo);
  813. }
  814. return ret;
  815. }
  816. public int deleteRule(int rulNum) throws VMSDAOException{
  817. int ret = 0;
  818. int ret1 = 0;
  819. PreparedStatement pstmtDelRule = null ;
  820. PreparedStatement pstmtDelRuleInfo = null;
  821. try{
  822. //all this in Xn
  823. con.setAutoCommit(false);
  824. //1 delete from vms_compatibility_rules
  825. pstmtDelRule = con.prepareStatement(VMSDAOQueries.DEL_RULE);
  826. pstmtDelRule.setInt(1, rulNum);
  827. ret = pstmtDelRule.executeUpdate();
  828. logger.info("deleteRule: " + VMSDAOQueries.DEL_RULE + " param : " + rulNum);
  829. //2 delete from vms_rules_info
  830. pstmtDelRuleInfo = con.prepareStatement(VMSDAOQueries.DEL_RULE_INFO);
  831. pstmtDelRuleInfo.setInt(1, rulNum);
  832. ret1 = pstmtDelRuleInfo.executeUpdate();
  833. logger.info("deleteRule: " + VMSDAOQueries.DEL_RULE_INFO + " param: " + rulNum);
  834. if (ret > 0 && ret1 > 0){
  835. con.commit();
  836. ret = 1;
  837. }else{
  838. con.rollback();
  839. }
  840. con.setAutoCommit(true);
  841. }catch(SQLException sqle){
  842. logger.info("deleteRule: MySQL DB related error: " , sqle);
  843. throw new VMSDAOException(sqle.getMessage());
  844. }catch(Exception ex){
  845. logger.info("deleteRule: error: " , ex);
  846. throw new VMSDAOException(ex.getMessage());
  847. }finally{
  848. VMSDAOUtils.freeUp(null, pstmtDelRule);
  849. VMSDAOUtils.freeUp(null, pstmtDelRuleInfo);
  850. }
  851. return ret;
  852. }
  853. public ArrayList getOtherCompoBeans(int rulNum) throws VMSDAOException {
  854. ArrayList ret = new ArrayList();
  855. PreparedStatement pstmtGetCompo = null ;
  856. ResultSet rsGetCompo = null;
  857. int comVerGID = 0;
  858. int Major = 0;
  859. int Minor = 0;
  860. int Build = 0;
  861. int Patch = 0;
  862. String CompoName = null;
  863. try{
  864. pstmtGetCompo = con.prepareStatement(VMSDAOQueries.GET_OTHER_COMPO_VER_RULE);
  865. pstmtGetCompo.setInt(1, rulNum);
  866. rsGetCompo = pstmtGetCompo.executeQuery();
  867. logger.info("getOtherCompoBeans: " + VMSDAOQueries.GET_OTHER_COMPO_VER_RULE + " Params: " + rulNum );
  868. while(rsGetCompo.next()){
  869. comVerGID = 0;
  870. Major = 0;
  871. Minor = 0;
  872. Build = 0;
  873. Patch = 0;
  874. CompoName = null;
  875. VMSCompoBean cBean = new VMSCompoBean();
  876. comVerGID = rsGetCompo.getInt("GID");
  877. Major = rsGetCompo.getInt("MAJOR");
  878. Minor = rsGetCompo.getInt("MINOR");
  879. Build = rsGetCompo.getInt("BUILD");
  880. Patch = rsGetCompo.getInt("PATCH");
  881. CompoName = rsGetCompo.getString("COMPONENT");
  882. cBean.setCompoVerGID(comVerGID);
  883. cBean.setMaj(Major);
  884. cBean.setMin(Minor);
  885. cBean.setBld(Build);
  886. cBean.setPatch(Patch);
  887. cBean.setCompoName(CompoName);
  888. ret.add(cBean);
  889. }
  890. }catch(SQLException sqle){
  891. logger.error("getOtherCompoBeans: DB related error: " , sqle);
  892. throw new VMSDAOException(sqle.getMessage());
  893. }catch(Exception ex){
  894. logger.error("getOtherCompoBeans: error: " , ex);
  895. throw new VMSDAOException(ex.getMessage());
  896. }finally{
  897. VMSDAOUtils.freeUp(rsGetCompo, pstmtGetCompo);
  898. }
  899. return ret;
  900. }
  901. public ArrayList getServers() throws VMSDAOException {
  902. ArrayList ret = new ArrayList();
  903. PreparedStatement pstmtGetRule = null;
  904. ResultSet rsGetRule = null;
  905. try{
  906. pstmtGetRule = con.prepareStatement(VMSDAOQueries.GET_SERVERS);
  907. rsGetRule = pstmtGetRule.executeQuery();
  908. logger.info("getServers: " + VMSDAOQueries.GET_SERVERS);
  909. int gid = 0;
  910. String name = null;
  911. String domain = null;
  912. while(rsGetRule.next()){
  913. VMSServerBean sb = new VMSServerBean();
  914. gid = rsGetRule.getInt("GID");
  915. name = rsGetRule.getString("SERVER");
  916. domain = rsGetRule.getString("DOMAIN");
  917. sb.setGid(gid);
  918. sb.setName(name);
  919. sb.setDomain(domain);
  920. ret.add(sb);
  921. }
  922. }catch(SQLException sqle){
  923. logger.error("getServers: MySQL DB related error in getServers: " , sqle);
  924. throw new VMSDAOException(sqle.getMessage());
  925. }catch(Exception ex){
  926. logger.error("getServers: " , ex);
  927. throw new VMSDAOException(ex.getMessage());
  928. }finally{
  929. VMSDAOUtils.freeUp(rsGetRule, pstmtGetRule);
  930. }
  931. return ret;
  932. }
  933. public ArrayList getCaseComponents(int serverGid) throws VMSDAOException {
  934. ArrayList ret = new ArrayList();
  935. PreparedStatement pstmtGetRule = null;
  936. ResultSet rsGetRule = null;
  937. int servGid ;
  938. int caseGid ;
  939. String casename;
  940. String component;
  941. int maj ;
  942. int min ;
  943. int build ;
  944. int patch ;
  945. String port;
  946. try{
  947. pstmtGetRule = con.prepareStatement(VMSDAOQueries.GET_CASE_COMPONENTS);
  948. pstmtGetRule.setInt(1,serverGid);
  949. rsGetRule = pstmtGetRule.executeQuery();
  950. while(rsGetRule.next()){
  951. VMSCaseComponent sb = new VMSCaseComponent();
  952. servGid = 0;
  953. caseGid = 0;
  954. casename = null;
  955. component = null;
  956. maj = 0;
  957. min = 0;
  958. build = 0;
  959. patch = 0;
  960. port = null;
  961. servGid = rsGetRule.getInt("SERVER_GID");
  962. caseGid = rsGetRule.getInt("GID");
  963. casename = rsGetRule.getString("CASENAME");
  964. component = rsGetRule.getString("COMPONENT");
  965. maj = rsGetRule.getInt("MAJOR");
  966. min = rsGetRule.getInt("MINOR");
  967. build = rsGetRule.getInt("BUILD");
  968. patch = rsGetRule.getInt("PATCH");
  969. port = rsGetRule.getString("PORT");
  970. sb.setServerGid(servGid);
  971. sb.setCaseGid(caseGid);
  972. sb.setCaseName(casename);
  973. sb.setComponent(component);
  974. sb.setMajor(maj);
  975. sb.setMinor(min);
  976. sb.setBuild(build);
  977. sb.setPatch(patch);
  978. sb.setPort(port);
  979. sb.setVersion();
  980. ret.add(sb);
  981. }
  982. }catch(SQLException sqle){
  983. logger.error("getCaseComponents: MySQL DB related error in getCaseCompo: " , sqle);
  984. throw new VMSDAOException(sqle.getMessage());
  985. }catch(Exception ex){
  986. logger.error("getCaseComponents: error : " , ex);
  987. throw new VMSDAOException(ex.getMessage());
  988. }finally{
  989. VMSDAOUtils.freeUp(rsGetRule, pstmtGetRule);
  990. }
  991. return ret;
  992. }
  993. public ArrayList getCases() throws VMSDAOException {
  994. ArrayList ret = new ArrayList();
  995. PreparedStatement pstmtGetRule = null;
  996. ResultSet rsGetRule = null;
  997. try{
  998. pstmtGetRule = con.prepareStatement(VMSDAOQueries.GET_CASES);
  999. rsGetRule = pstmtGetRule.executeQuery();
  1000. while(rsGetRule.next()){
  1001. VMSCaseBean cb = new VMSCaseBean();
  1002. int gid = 0;
  1003. String caseName = null;
  1004. gid = rsGetRule.getInt("GID");
  1005. caseName = rsGetRule.getString("CASENAME");
  1006. cb.setCaseGid(gid);
  1007. cb.setCaseName(caseName);
  1008. ret.add(cb);
  1009. }
  1010. }catch(SQLException sqle){
  1011. logger.error("getCases: MySQL DB related error in getCases: " , sqle);
  1012. throw new VMSDAOException(sqle.getMessage());
  1013. }catch(Exception ex){
  1014. logger.error("getCases: Error: " , ex);
  1015. throw new VMSDAOException(ex.getMessage());
  1016. }finally{
  1017. VMSDAOUtils.freeUp(rsGetRule, pstmtGetRule);
  1018. }
  1019. return ret;
  1020. }
  1021. public ArrayList getServerComponents(int[] caseGid) throws VMSDAOException, SQLException {
  1022. ArrayList ret = new ArrayList();
  1023. Statement stmtGetServerComponents = null;
  1024. ResultSet rsGetServerComponents = null;
  1025. String component;
  1026. String serverName;
  1027. int serverGid;
  1028. String caseName;
  1029. int caseGID;
  1030. String port;
  1031. int maj;
  1032. int min;
  1033. int build;
  1034. int patch;
  1035. int compoVerGid;
  1036. String query = null;
  1037. ArrayList caseGids = new ArrayList();
  1038. for(int m = 0; m < caseGid.length; m++){
  1039. caseGids.add(new Integer(caseGid[m]));
  1040. }
  1041. //form the appropriate query based on caseGid
  1042. if( (caseGid.length == 1)&&(caseGid[0] == -1) ){
  1043. //for all cases
  1044. query = VMSDAOQueries.GET_SERVER_COMPONENTS_GENERIC
  1045. + " ORDER BY C.GID,S.DOMAIN, CO.COMPONENT, CV.MAJOR";
  1046. }else{
  1047. //for single/multiple cases
  1048. query = VMSDAOQueries.GET_SERVER_COMPONENTS_GENERIC
  1049. + " AND CSM.CASE_GID IN (" + VMSCommonUtils.join(caseGids, ",") + ")"
  1050. + " ORDER BY C.GID,S.DOMAIN, CO.COMPONENT, CV.MAJOR";
  1051. }
  1052. logger.info("getServerComponents: Query used ServerComponents: " + query);
  1053. try{
  1054. stmtGetServerComponents = con.createStatement();
  1055. rsGetServerComponents = stmtGetServerComponents.executeQuery(query);
  1056. while(rsGetServerComponents.next()){
  1057. VMSServerComponent sc = new VMSServerComponent();
  1058. component = null;
  1059. serverName = null;
  1060. serverGid = 0;
  1061. caseName = null;
  1062. caseGID = 0;
  1063. port = null;
  1064. maj = 0;
  1065. min = 0;
  1066. build = 0;
  1067. patch = 0;
  1068. compoVerGid = 0;
  1069. caseName = rsGetServerComponents.getString("CASENAME");
  1070. caseGID = rsGetServerComponents.getInt("C.GID");
  1071. component = rsGetServerComponents.getString("COMPONENT");
  1072. serverGid = rsGetServerComponents.getInt("S.GID");
  1073. serverName = rsGetServerComponents.getString("SERVER");
  1074. port = rsGetServerComponents.getString("PORT");
  1075. maj = rsGetServerComponents.getInt("MAJOR");
  1076. min = rsGetServerComponents.getInt