List of usage examples for org.dom4j DocumentHelper createDocument
public static Document createDocument()
From source file:cn.itcreator.android.reader.util.XMLUtil.java
License:Open Source License
/** * /*from ww w. j av a2 s. co m*/ * @param filePath * xml file path */ public XMLUtil(String filePath) { this.mFilePath = filePath; mFile = new File(mFilePath); if (!mFile.exists()) { try { mFile.createNewFile(); mDocument = DocumentHelper.createDocument(); // create new xml document } catch (IOException e) { mDocument = DocumentHelper.createDocument(); } } else { try { mDocument = new SAXReader().read(mFile); } catch (DocumentException e) { mDocument = DocumentHelper.createDocument(); } } System.gc(); }
From source file:com.aesirteam.smep.adc.simulator.TransletServlet.java
protected void doGet(HttpServletRequest arg0, HttpServletResponse arg1) throws ServletException, IOException { String message = ""; boolean body_flag = "on".equals(arg0.getParameter("body_flag")) ? true : false; arg0.setCharacterEncoding("GBK"); String tb_endpoint = arg0.getParameter("tb_endpoint"); String tb_secret = arg0.getParameter("teb_secret"); String tb_code = arg0.getParameter("tb_code"); Util util = new Util(); util.setEndpoint(tb_endpoint);// w w w . j a v a 2 s .co m util.setSecret(tb_secret); if ("CorpBind".equals(tb_code)) { try { Document document = DocumentHelper.createDocument(); Element root = document.addElement("CorpBindReq"); //PUD Element head = root.addElement("HEAD"); head.addElement("CODE").addText("CorpBind"); head.addElement("SID").addText(arg0.getParameter("tb_sid")); head.addElement("TIMESTAMP").addText(arg0.getParameter("tb_timestamp")); head.addElement("SERVICEID").addText(arg0.getParameter("tb_serviceid")); //PDU Document bodydocument = DocumentHelper.createDocument(); Element body = bodydocument.addElement("BODY"); body.addElement("CORPNAME").addText(arg0.getParameter("tb_corpname")); body.addElement("CORPACCOUNT").addText(arg0.getParameter("tb_corpaccount")); body.addElement("LICENSE").addText(arg0.getParameter("tb_license")); body.addElement("OPTYPE").addText(arg0.getParameter("tb_optype")); body.addElement("OPNOTE").addText(arg0.getParameter("tb_opnote")); Element paramlist = body.addElement("PARAMLIST"); String[] plist = arg0.getParameterValues("lb_paramlist"); if (null != plist && 1 <= plist.length) { for (int i = 0; i < plist.length; i++) { //System.out.println(plist[i]); String[] ppv = plist[i].split(":"); Element parammap = paramlist.addElement("PARAMMAP"); parammap.addElement("PARAMNAME").addText(ppv[0]); if (1 < ppv.length) parammap.addElement("PARAMVALUE").addText(ppv[1]); else parammap.addElement("PARAMVALUE"); } } Element corpinfolist = body.addElement("CORPINFOLIST"); String[] clist = arg0.getParameterValues("lb_corpinfolist"); if (null != clist && 1 <= clist.length) { for (int i = 0; i < clist.length; i++) { //System.out.println(clist[i]); String[] ppv = clist[i].split(":"); Element corpinfomap = corpinfolist.addElement("CORPINFOMAP"); corpinfomap.addElement("CORPINFONAME").addText(ppv[0]); if (1 < ppv.length) corpinfomap.addElement("CORPINFOVALUE").addText(ppv[1]); else corpinfomap.addElement("CORPINFOVALUE"); } } Element pointlist = body.addElement("POINTLIST"); String[] ilist = arg0.getParameterValues("lb_pointlist"); if (null != ilist && 1 <= ilist.length) { for (int i = 0; i < ilist.length; i++) { String[] ppv = ilist[i].split(":"); Element orderpointmap = pointlist.addElement("ORDERPOINTMAP"); orderpointmap.addElement("POINTNAME").addText(ppv[0]); if (1 < ppv.length) orderpointmap.addElement("POINTVALUE").addText(ppv[1]); else orderpointmap.addElement("POINTVALUE"); } } if (!body_flag) { root.addElement("BODY").setText(util.encrypt(util.getXmlText(bodydocument))); String rsqstr = util.soapHttpClient("CorpBinding", util.getXmlText(document)); message = util.decrypt(rsqstr); } else { message = util.getXmlText(bodydocument); } util = null; } catch (Exception ex) { ex.printStackTrace(); } } else if ("DeptBind".equals(tb_code)) { try { Document document = DocumentHelper.createDocument(); Element root = document.addElement("DeptBindReq"); //PUD Element head = root.addElement("HEAD"); head.addElement("CODE").addText("DeptBind"); head.addElement("SID").addText(arg0.getParameter("tb_sid")); head.addElement("TIMESTAMP").addText(arg0.getParameter("tb_timestamp")); head.addElement("SERVICEID").addText(arg0.getParameter("tb_serviceid")); //PDU Document bodydocument = DocumentHelper.createDocument(); Element body = bodydocument.addElement("BODY"); body.addElement("CORPACCOUNT").addText(arg0.getParameter("tb_corpaccount")); Element deptinfo = body.addElement("DEPS"); deptinfo.addElement("DEPTID").addText(arg0.getParameter("tb_deptid")); deptinfo.addElement("PARENTID").addText(arg0.getParameter("tb_parentid")); deptinfo.addElement("DEPNAME").addText(arg0.getParameter("tb_depname")); deptinfo.addElement("DEPDES").addText(arg0.getParameter("tb_depdes")); deptinfo.addElement("DEPADDRESS").addText(arg0.getParameter("tb_depaddress")); deptinfo.addElement("DEPTELNO").addText(arg0.getParameter("tb_deptelno")); deptinfo.addElement("DEPFAXNO").addText(arg0.getParameter("tb_depfaxno")); deptinfo.addElement("DEPMNGID").addText(arg0.getParameter("tb_depmngid")); deptinfo.addElement("BUILDTIME").addText(arg0.getParameter("tb_buildtime")); deptinfo.addElement("UPDATEDATE").addText(arg0.getParameter("tb_updatedate")); deptinfo.addElement("OPTYPE").addText(arg0.getParameter("tb_optype")); Element deptinfomaplist = deptinfo.addElement("DEPTINFOMAPLIST"); String[] diml = arg0.getParameterValues("lb_deptinfomaplist"); if (null != diml && 1 <= diml.length) { for (int i = 0; i < diml.length; i++) { //System.out.println(diml[i]); String[] ppv = diml[i].split(":"); Element deptinfomap = deptinfomaplist.addElement("DEPTINFOMAP"); deptinfomap.addElement("DEPTINFONAME").addText(ppv[0]); if (1 < ppv.length) deptinfomap.addElement("DEPTINFOVALUE").addText(ppv[1]); else deptinfomap.addElement("DEPTINFOVALUE"); } } Element deptinfo1 = body.addElement("DEPS"); deptinfo1.addElement("DEPTID").addText(arg0.getParameter("tb_deptid1")); deptinfo1.addElement("PARENTID").addText(arg0.getParameter("tb_parentid1")); deptinfo1.addElement("DEPNAME").addText(arg0.getParameter("tb_depname1")); deptinfo1.addElement("DEPDES").addText(arg0.getParameter("tb_depdes1")); deptinfo1.addElement("DEPADDRESS").addText(arg0.getParameter("tb_depaddress1")); deptinfo1.addElement("DEPTELNO").addText(arg0.getParameter("tb_deptelno1")); deptinfo1.addElement("DEPFAXNO").addText(arg0.getParameter("tb_depfaxno1")); deptinfo1.addElement("DEPMNGID").addText(arg0.getParameter("tb_depmngid1")); deptinfo1.addElement("BUILDTIME").addText(arg0.getParameter("tb_buildtime1")); deptinfo1.addElement("UPDATEDATE").addText(arg0.getParameter("tb_updatedate1")); deptinfo1.addElement("OPTYPE").addText(arg0.getParameter("tb_optype1")); Element deptinfomaplist1 = deptinfo1.addElement("DEPTINFOMAPLIST"); String[] diml1 = arg0.getParameterValues("lb_deptinfomaplist1"); if (null != diml1 && 1 <= diml1.length) { for (int i = 0; i < diml1.length; i++) { //System.out.println(diml1[i]); String[] ppv = diml1[i].split(":"); Element deptinfomap = deptinfomaplist1.addElement("DEPTINFOMAP"); deptinfomap.addElement("DEPTINFONAME").addText(ppv[0]); if (1 < ppv.length) deptinfomap.addElement("DEPTINFOVALUE").addText(ppv[1]); else deptinfomap.addElement("DEPTINFOVALUE"); } } if (!body_flag) { root.addElement("BODY").setText(util.encrypt(util.getXmlText(bodydocument))); String rsqstr = util.soapHttpClient("DeptBinding", util.getXmlText(document)); message = util.decrypt(rsqstr); } else { message = util.getXmlText(bodydocument); } util = null; } catch (Exception ex) { ex.printStackTrace(); } } else if ("StaffBind".equals(tb_code)) { try { Document document = DocumentHelper.createDocument(); Element root = document.addElement("StaffBindReq"); //PUD Element head = root.addElement("HEAD"); head.addElement("CODE").addText("StaffBind"); head.addElement("SID").addText(arg0.getParameter("tb_sid")); head.addElement("TIMESTAMP").addText(arg0.getParameter("tb_timestamp")); head.addElement("SERVICEID").addText(arg0.getParameter("tb_serviceid")); //PDU Document bodydocument = DocumentHelper.createDocument(); Element body = bodydocument.addElement("BODY"); body.addElement("CORPACCOUNT").addText(arg0.getParameter("tb_corpaccount")); Element stafflist = body.addElement("STAFFLIST"); Element staffinfo = stafflist.addElement("STAFFINFO"); staffinfo.addElement("UFID").addText(arg0.getParameter("tb_ufid")); staffinfo.addElement("USERTYPE").addText(arg0.getParameter("tb_usertype")); staffinfo.addElement("STAFFNAME").addText(arg0.getParameter("tb_staffname")); staffinfo.addElement("STAFFMOBILE").addText(arg0.getParameter("tb_staffmobile")); staffinfo.addElement("OPTYPE").addText(arg0.getParameter("tb_optype")); staffinfo.addElement("OPNOTE").addText(arg0.getParameter("tb_opnote")); Element userinfomaplist = staffinfo.addElement("USERINFOMAPLIST"); String[] ufml = arg0.getParameterValues("lb_userinfomaplist"); //System.out.println(diml.length); if (null != ufml && 1 <= ufml.length) { for (int i = 0; i < ufml.length; i++) { //System.out.println(diml[i]); String[] ppv = ufml[i].split(":"); Element userinfomap = userinfomaplist.addElement("USERINFOMAP"); userinfomap.addElement("USERINFONAME").addText(ppv[0]); if (1 < ppv.length) userinfomap.addElement("USERINFOVALUE").addText(ppv[1]); else userinfomap.addElement("USERINFOVALUE"); } } Element staffinfo1 = stafflist.addElement("STAFFINFO"); staffinfo1.addElement("UFID").addText(arg0.getParameter("tb_ufid1")); staffinfo1.addElement("USERTYPE").addText(arg0.getParameter("tb_usertype1")); staffinfo1.addElement("STAFFNAME").addText(arg0.getParameter("tb_staffname1")); staffinfo1.addElement("STAFFMOBILE").addText(arg0.getParameter("tb_staffmobile1")); staffinfo1.addElement("OPTYPE").addText(arg0.getParameter("tb_optype1")); staffinfo1.addElement("OPNOTE").addText(arg0.getParameter("tb_opnote1")); Element userinfomaplist1 = staffinfo1.addElement("USERINFOMAPLIST"); String[] ufml1 = arg0.getParameterValues("lb_userinfomaplist1"); if (null != ufml1 && 1 <= ufml1.length) { for (int i = 0; i < ufml1.length; i++) { //System.out.println(diml1[i]); String[] ppv = ufml1[i].split(":"); Element userinfomap = userinfomaplist1.addElement("USERINFOMAP"); userinfomap.addElement("USERINFONAME").addText(ppv[0]); if (1 < ppv.length) userinfomap.addElement("USERINFOVALUE").addText(ppv[1]); else userinfomap.addElement("USERINFOVALUE"); } } if (!body_flag) { root.addElement("BODY").setText(util.encrypt(util.getXmlText(bodydocument))); String rsqstr = util.soapHttpClient("StaffBinding", util.getXmlText(document)); message = util.decrypt(rsqstr); } else { message = util.getXmlText(bodydocument); } util = null; } catch (Exception ex) { ex.printStackTrace(); } } printPage(arg1, message); }
From source file:com.ah.be.admin.adminBackupUnit.AhBackupTool.java
private void backupDomainTable(String strPath, String strDomainName, String strTableName) { Connection con = null;// w ww. ja v a2s . c om XMLWriter output = null; ResultSet rsTable = null; Statement stTable = null; try { if (!(strPath.substring(strPath.length() - 1).equals(File.separator) || strPath.substring(strPath.length() - 1).equals("/"))) { strPath = strPath + File.separatorChar; } // Class.forName("org.postgresql.Driver").newInstance(); // // String strUrl = "jdbc:postgresql://localhost:5432/hm"; // // String strUsr = "hivemanager"; // // String strPsd = "aerohive"; AhBackupNewTool oTool = new AhBackupNewTool(); con = oTool.initCon(); try { stTable = con.createStatement(); String strSql; int intFileCount = 0; int intRecordNum; while (true) { intRecordNum = 0; strSql = "select * from " + strTableName + " where domainname='" + strDomainName + "'" + " limit " + 5000 + " offset " + intFileCount * 5000; if (!AhBackupNewTool.isValidCoon(con)) { con = oTool.initCon(); stTable = con.createStatement(); } rsTable = stTable.executeQuery(strSql); Document document = DocumentHelper.createDocument(); Element table = document.addElement("table").addAttribute("schema", strTableName); ResultSetMetaData rsmd = rsTable.getMetaData(); int iCount = rsmd.getColumnCount(); while (rsTable.next()) { intRecordNum++; Element row = table.addElement("row"); for (int icol = 1; icol <= iCount; icol++) { String newStr; if (rsTable.getString(icol) == null) { newStr = "NULL"; } else if ("null".equalsIgnoreCase(rsTable.getString(icol))) { newStr = "_" + rsTable.getString(icol) + "_"; } else { newStr = rsTable.getString(icol); } if (1 == intRecordNum) { row.addElement("field").addAttribute("name", rsmd.getColumnName(icol)) .addAttribute("value", newStr); } else { row.addElement("field").addAttribute("value", newStr); } } } if (intRecordNum <= 0 && 0 != intFileCount) break; File file; if (intFileCount == 0) { file = new File(strPath + strTableName.toLowerCase() + ".xml"); } else { file = new File(strPath + strTableName.toLowerCase() + "_" + intFileCount + ".xml"); } intFileCount++; output = new XMLWriter(new FileOutputStream(file)); output.write(document); output.close(); if (5000 > intRecordNum) break; } rsTable.close(); stTable.close(); } catch (Exception ex) { BeLogTools.restoreLog(BeLogTools.ERROR, ex.getMessage()); } } catch (Exception ex) { // add the debug msg BeLogTools.restoreLog(BeLogTools.ERROR, ex.getMessage()); } finally { if (null != con) { try { con.close(); } catch (Exception conex) { BeLogTools.restoreLog(BeLogTools.ERROR, conex.getMessage()); } } if (null != output) { try { output.close(); } catch (Exception outex) { BeLogTools.restoreLog(BeLogTools.ERROR, outex.getMessage()); } } if (null != rsTable) { try { rsTable.close(); } catch (Exception rsex) { BeLogTools.restoreLog(BeLogTools.ERROR, rsex.getMessage()); } } if (null != stTable) { try { stTable.close(); } catch (Exception stex) { BeLogTools.restoreLog(BeLogTools.ERROR, stex.getMessage()); } } } }
From source file:com.ah.be.admin.adminBackupUnit.AhBackupTool.java
private void backup1table(String strPath, String strTableName) { Connection con = null;//from w ww . ja v a2s . c o m XMLWriter output = null; ResultSet rsTable = null; Statement stTable = null; try { if (!(strPath.substring(strPath.length() - 1).equals(File.separator) || strPath.substring(strPath.length() - 1).equals("/"))) { strPath = strPath + File.separatorChar; } // Class.forName("org.postgresql.Driver").newInstance(); // // String strUrl = "jdbc:postgresql://localhost:5432/hm"; // // String strUsr = "hivemanager"; // // String strPsd = "aerohive"; // con = DriverManager // .getConnection(strUrl, strUsr, strPsd); AhBackupNewTool oTool = new AhBackupNewTool(); con = oTool.initCon(); //String strTableName = AhBackupTool.ahLicenseHistory.toLowerCase(); try { stTable = con.createStatement(); // String strSql = "select count(*) from " + strTableName; // // rsTable = stTable.executeQuery(strSql); // // rsTable = stTable.executeQuery(strSql); // // rsTable.next(); // // int iRowCount = rsTable.getInt(1); // // rsTable.close(); //int intFileCount = 1; String strSql; int intFileCount = 0; int intRecordNum; //for (int i = 0; i < iRowCount || i == 0; i = i + 5000) { while (true) { intRecordNum = 0; strSql = "select * from " + strTableName + " limit " + 5000 + " offset " + intFileCount * 5000; if (!AhBackupNewTool.isValidCoon(con)) { con = oTool.initCon(); stTable = con.createStatement(); } rsTable = stTable.executeQuery(strSql); Document document = DocumentHelper.createDocument(); Element table = document.addElement("table").addAttribute("schema", strTableName); ResultSetMetaData rsmd = rsTable.getMetaData(); int iCount = rsmd.getColumnCount(); while (rsTable.next()) { intRecordNum++; Element row = table.addElement("row"); for (int icol = 1; icol <= iCount; icol++) { String newStr; if (rsTable.getString(icol) == null) { newStr = "NULL"; } else if ("null".equalsIgnoreCase(rsTable.getString(icol))) { newStr = "_" + rsTable.getString(icol) + "_"; } else { newStr = rsTable.getString(icol); } if (1 == intRecordNum) { row.addElement("field").addAttribute("name", rsmd.getColumnName(icol)) .addAttribute("value", newStr); } else { row.addElement("field").addAttribute("value", newStr); } } } if (intRecordNum <= 0 && 0 != intFileCount) break; File file; if (intFileCount == 0) { file = new File(strPath + strTableName.toLowerCase() + ".xml"); } else { file = new File(strPath + strTableName.toLowerCase() + "_" + intFileCount + ".xml"); } intFileCount++; output = new XMLWriter(new FileOutputStream(file)); output.write(document); output.close(); if (5000 > intRecordNum) break; } rsTable.close(); stTable.close(); } catch (Exception ex) { BeLogTools.restoreLog(BeLogTools.ERROR, ex.getMessage()); } } catch (Exception ex) { // add the debug msg BeLogTools.restoreLog(BeLogTools.ERROR, ex.getMessage()); } finally { if (null != con) { try { con.close(); } catch (Exception conex) { BeLogTools.restoreLog(BeLogTools.ERROR, conex.getMessage()); } } if (null != output) { try { output.close(); } catch (Exception outex) { BeLogTools.restoreLog(BeLogTools.ERROR, outex.getMessage()); } } if (null != rsTable) { try { rsTable.close(); } catch (Exception rsex) { BeLogTools.restoreLog(BeLogTools.ERROR, rsex.getMessage()); } } if (null != stTable) { try { stTable.close(); } catch (Exception stex) { BeLogTools.restoreLog(BeLogTools.ERROR, stex.getMessage()); } } } }
From source file:com.ah.be.admin.adminBackupUnit.AhBackupTool.java
private void storeBriefDomainInfo(String strXmlPath, HmDomain oDomain) { String strDomainTable = AhBackupTool.ahDomain.toLowerCase(); Document document = DocumentHelper.createDocument(); Element table = document.addElement("table").addAttribute("schema", strDomainTable); File fDomain = new File(strXmlPath + strDomainTable.toLowerCase() + ".xml"); XMLWriter output = null;/*from ww w. ja v a 2 s . c om*/ try { output = new XMLWriter(new FileOutputStream(fDomain)); Element row = table.addElement("row"); String strDomainId = oDomain.getId().toString(); String strDomainName = oDomain.getDomainName(); row.addElement("field").addAttribute("name", "id").addAttribute("value", strDomainId); row.addElement("field").addAttribute("name", "domainname").addAttribute("value", strDomainName); output.write(document); output.close(); } catch (Exception ex) { BeLogTools.restoreLog(BeLogTools.ERROR, ex.getMessage()); } finally { if (null != output) { try { output.close(); } catch (Exception outex) { BeLogTools.restoreLog(BeLogTools.ERROR, outex.getMessage()); } } } }
From source file:com.ah.be.admin.adminBackupUnit.AhBackupTool.java
private void storeDomainTable(String strTableName, String strPath, HmDomain oDomain, Connection conTable) { String strSql = "select * from " + strTableName; XMLWriter output = null;//from w w w . ja v a2 s. c o m ResultSet rsTable = null; Statement stTable = null; try { stTable = conTable.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE); rsTable = stTable.executeQuery(strSql); Document document = DocumentHelper.createDocument(); Element table = document.addElement("table").addAttribute("schema", strTableName); File file = new File(strPath + strTableName.toLowerCase() + ".xml"); output = new XMLWriter(new FileOutputStream(file)); ResultSetMetaData rsmd = rsTable.getMetaData(); int iCount = rsmd.getColumnCount(); while (rsTable.next()) { Element row = table.addElement("row"); for (int icol = 1; icol <= iCount; icol++) { String newStr; if (rsTable.getString(icol) == null) { newStr = "NULL"; } else if ("null".equalsIgnoreCase(rsTable.getString(icol))) { newStr = "_" + rsTable.getString(icol) + "_"; } else { newStr = rsTable.getString(icol); } row.addElement("field").addAttribute("name", rsmd.getColumnName(icol)).addAttribute("value", newStr); } } output.write(document); output.close(); rsTable.close(); stTable.close(); } catch (Exception ex) { BeLogTools.restoreLog(BeLogTools.ERROR, ex.getMessage()); } finally { if (null != output) { try { output.close(); } catch (Exception outex) { BeLogTools.restoreLog(BeLogTools.ERROR, outex.getMessage()); } } if (null != rsTable) { try { rsTable.close(); } catch (Exception rsex) { BeLogTools.restoreLog(BeLogTools.ERROR, rsex.getMessage()); } } if (null != stTable) { try { stTable.close(); } catch (Exception stex) { BeLogTools.restoreLog(BeLogTools.ERROR, stex.getMessage()); } } } }
From source file:com.ah.be.admin.adminBackupUnit.AhBackupTool.java
private void storeCertainDomainTable(String strTableName, String strPath, HmDomain oDomain, Connection conTable) {//from w ww . ja v a 2s. co m String strSql = "select * from " + strTableName + " where domainname=" + "'" + oDomain.getDomainName() + "'"; XMLWriter output = null; ResultSet rsTable = null; Statement stTable = null; try { stTable = conTable.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE); rsTable = stTable.executeQuery(strSql); Document document = DocumentHelper.createDocument(); Element table = document.addElement("table").addAttribute("schema", strTableName); File file = new File(strPath + strTableName.toLowerCase() + ".xml"); output = new XMLWriter(new FileOutputStream(file)); ResultSetMetaData rsmd = rsTable.getMetaData(); int iCount = rsmd.getColumnCount(); while (rsTable.next()) { Element row = table.addElement("row"); for (int icol = 1; icol <= iCount; icol++) { String newStr; if (rsTable.getString(icol) == null) { newStr = "NULL"; } else if ("null".equalsIgnoreCase(rsTable.getString(icol))) { newStr = "_" + rsTable.getString(icol) + "_"; } else { newStr = rsTable.getString(icol); } row.addElement("field").addAttribute("name", rsmd.getColumnName(icol)).addAttribute("value", newStr); } } output.write(document); output.close(); rsTable.close(); stTable.close(); } catch (Exception ex) { BeLogTools.restoreLog(BeLogTools.ERROR, ex.getMessage()); } finally { if (null != output) { try { output.close(); } catch (Exception outex) { BeLogTools.restoreLog(BeLogTools.ERROR, outex.getMessage()); } } if (null != rsTable) { try { rsTable.close(); } catch (Exception rsex) { BeLogTools.restoreLog(BeLogTools.ERROR, rsex.getMessage()); } } if (null != stTable) { try { stTable.close(); } catch (Exception stex) { BeLogTools.restoreLog(BeLogTools.ERROR, stex.getMessage()); } } } }
From source file:com.ah.be.admin.adminBackupUnit.AhBackupTool.java
private void storeCommonTable(String strTableName, String strPath, HmDomain oDomain, Connection conTable) { XMLWriter output = null;//from w w w . ja v a 2s. c o m ResultSet rsTable = null; Statement stTable = null; try { stTable = conTable.createStatement(); boolean bOwnerFlag = false; String strSql = "select * from " + strTableName + " limit 1"; rsTable = stTable.executeQuery(strSql); rsTable.next(); ResultSetMetaData rsmd = rsTable.getMetaData(); int iColumnCount = rsmd.getColumnCount(); for (int i = 1; i <= iColumnCount; ++i) { if (rsmd.getColumnName(i).equalsIgnoreCase("owner")) { bOwnerFlag = true; break; } } rsTable.close(); // if (!bOwnerFlag) { // strSql = "select count(*) from " + strTableName; // } else { // strSql = "select count(*) from " + strTableName // + ", hm_domain where " + strTableName // + ".owner=hm_domain.id and (" + strTableName // + ".owner=" + oDomain.getId().toString() // + " or hm_domain.domainname='global')"; // } // rsTable = stTable.executeQuery(strSql); // rsTable.next(); // int iRowCount = rsTable.getInt(1); // rsTable.close(); int intFileCount = 0; int intRecordNum; strSql = "select id from hm_domain where domainname='global'"; rsTable = stTable.executeQuery(strSql); long global_id = 0; if (rsTable.next()) global_id = rsTable.getLong(1); String strId = String.valueOf(global_id); while (true) { intRecordNum = 0; //for (int i = 0; i < iRowCount || i == 0; i = i + 5000) { // if (!bOwnerFlag) { // strSql = "select * from " + strTableName + " limit " + 5000 // + " offset " + i; // } else { // strSql = "select " + strTableName + ".* from " // + strTableName + ", hm_domain where " // + strTableName + ".owner=hm_domain.id and (" // + strTableName + ".owner=" // + oDomain.getId().toString() // + " or hm_domain.domainname='global')" + " limit " // + 5000 + " offset " + i; // } if (!bOwnerFlag) { strSql = "select * from " + strTableName + " limit " + 5000 + " offset " + intFileCount * 5000; } else { strSql = "select * from " + strTableName + " where owner=" + oDomain.getId().toString() + " or owner=" + strId + " limit " + 5000 + " offset " + intFileCount * 5000; } rsTable = stTable.executeQuery(strSql); Document document = DocumentHelper.createDocument(); Element table = document.addElement("table").addAttribute("schema", strTableName); rsmd = rsTable.getMetaData(); int iCount = rsmd.getColumnCount(); while (rsTable.next()) { intRecordNum++; Element row = table.addElement("row"); for (int icol = 1; icol <= iCount; icol++) { String newStr; if (rsTable.getString(icol) == null) { newStr = "NULL"; } else if ("null".equalsIgnoreCase(rsTable.getString(icol))) { newStr = "_" + rsTable.getString(icol) + "_"; } else { newStr = rsTable.getString(icol); } // row.addElement("field").addAttribute("name", // rsmd.getColumnName(icol)).addAttribute("value", // newStr); if (1 == intRecordNum) { row.addElement("field").addAttribute("name", rsmd.getColumnName(icol)) .addAttribute("value", newStr); } else { row.addElement("field").addAttribute("value", newStr); } } } if (intRecordNum <= 0 && 0 != intFileCount) break; File file; if (intFileCount == 0) { file = new File(strPath + strTableName.toLowerCase() + ".xml"); } else { file = new File(strPath + strTableName.toLowerCase() + "_" + intFileCount + ".xml"); } intFileCount++; output = new XMLWriter(new FileOutputStream(file)); output.write(document); output.close(); if (5000 > intRecordNum) break; } rsTable.close(); stTable.close(); } catch (Exception ex) { BeLogTools.restoreLog(BeLogTools.ERROR, ex.getMessage()); } finally { if (null != output) { try { output.close(); } catch (Exception outex) { BeLogTools.restoreLog(BeLogTools.ERROR, outex.getMessage()); } } if (null != rsTable) { try { rsTable.close(); } catch (Exception rsex) { BeLogTools.restoreLog(BeLogTools.ERROR, rsex.getMessage()); } } if (null != stTable) { try { stTable.close(); } catch (Exception stex) { BeLogTools.restoreLog(BeLogTools.ERROR, stex.getMessage()); } } } }
From source file:com.ah.be.admin.adminBackupUnit.AhBackupTool.java
private void storeSpecialTable(String strTableName, String strPath, HmDomain oDomain, Connection conTable) { XMLWriter output = null;//from www . j a v a 2 s.c o m ResultSet rsTable = null; Statement stTable = null; try { if (!(strPath.substring(strPath.length() - 1).equals(File.separator) || strPath.substring(strPath.length() - 1).equals("/"))) { strPath = strPath + File.separatorChar; } stTable = conTable.createStatement(); // String strSql = "select count(*) from " + strTableName // + ", hm_domain where " + strTableName // + ".owner=hm_domain.id and (" + strTableName + ".owner=" // + oDomain.getId().toString() // + " or hm_domain.domainname='global')"; // // begin = System.currentTimeMillis(); // // rsTable = stTable.executeQuery(strSql); // // dbtime += System.currentTimeMillis() - begin; // // rsTable.next(); // // int iRowCount = rsTable.getInt(1); // // rsTable.close(); String strSql = "select id from " + strTableName + " where owner=" + oDomain.getId().toString() + " order by id asc limit 1"; rsTable = stTable.executeQuery(strSql); long id = 0; if (rsTable.next()) id = rsTable.getLong(1) - 1; // else // return; rsTable.close(); int intFileCount = 0; String strId = String.valueOf(id); int intRecordNum; while (true) { intRecordNum = 0; // strSql = "select * from " + strTableName // + " where owner=" + oDomain.getId().toString() // + " and id>" + strId +" order by id asc "+ " limit " + 5000; strSql = "select * from " + strTableName + " where id > " + strId + " and owner=" + oDomain.getId().toString() + " order by id asc " + " limit " + 5000; rsTable = stTable.executeQuery(strSql); Document document = DocumentHelper.createDocument(); Element table = document.addElement("table").addAttribute("schema", strTableName); ResultSetMetaData rsmd = rsTable.getMetaData(); int iCount = rsmd.getColumnCount(); while (rsTable.next()) { intRecordNum++; Element row = table.addElement("row"); for (int icol = 1; icol <= iCount; icol++) { String newStr; if (rsTable.getString(icol) == null) { newStr = "NULL"; } else if ("null".equalsIgnoreCase(rsTable.getString(icol))) { newStr = "_" + rsTable.getString(icol) + "_"; } else { newStr = rsTable.getString(icol); } if ("id".equalsIgnoreCase(rsmd.getColumnName(icol))) { strId = newStr; } if (1 == intRecordNum) { row.addElement("field").addAttribute("name", rsmd.getColumnName(icol)) .addAttribute("value", newStr); } else { row.addElement("field").addAttribute("value", newStr); } } } if (intRecordNum <= 0 && 0 != intFileCount) break; File file; if (intFileCount == 0) { file = new File(strPath + strTableName.toLowerCase() + ".xml"); } else { file = new File(strPath + strTableName.toLowerCase() + "_" + intFileCount + ".xml"); } intFileCount++; output = new XMLWriter(new FileOutputStream(file)); output.write(document); output.close(); if (5000 > intRecordNum) break; } rsTable.close(); stTable.close(); } catch (Exception ex) { BeLogTools.restoreLog(BeLogTools.ERROR, ex.getMessage()); } finally { if (null != output) { try { output.close(); } catch (Exception outex) { BeLogTools.restoreLog(BeLogTools.ERROR, outex.getMessage()); } } if (null != rsTable) { try { rsTable.close(); } catch (Exception rsex) { BeLogTools.restoreLog(BeLogTools.ERROR, rsex.getMessage()); } } if (null != stTable) { try { stTable.close(); } catch (Exception stex) { BeLogTools.restoreLog(BeLogTools.ERROR, stex.getMessage()); } } } }
From source file:com.ah.be.ls.stat.StatManager.java
private Document generateDocumentTemplate() { Document document = DocumentHelper.createDocument(); document.setXMLEncoding("UTF-8"); return document; }