List of usage examples for java.lang StringBuffer delete
@Override public synchronized StringBuffer delete(int start, int end)
From source file:com.mysql.stresstool.RunnableQueryInsert.java
Vector getTablesValues(boolean refresh) { String longtextFld = ""; boolean lazy = false; int afld = 0; long counterFld = 0; if (refresh && !lazyInsert1.equals("")) { lazy = true;// w w w . j a v a2s . com longtextFld = lazyLongText; } else { if (operationShort) longtextFld = StressTool.getStringFromRandom(254).substring(0, 240); else longtextFld = StressTool.getStringFromRandom(40000); } Vector v = new Vector(); StringBuffer insert1 = new StringBuffer(); StringBuffer insert2 = new StringBuffer(); // String uuid = UUID.randomUUID().toString(); ArrayList<String> insertList1 = new ArrayList(); ArrayList<String> insertList2 = new ArrayList(); int pk = StressTool.getNumberFromRandom(2147483647).intValue(); String insert1Str = ""; if (dbType.endsWith("MySQL")) { for (int iTable = 1; iTable <= this.getNumberOfprimaryTables(); iTable++) { if (this.doSimplePk) { insert1.append("insert INTO tbtest" + iTable + " (uuid,a,b,c,counter,partitionid,strrecordtype) VALUES"); } else { insert1.append("insert INTO tbtest" + iTable + " (uuid,a,b,c,counter,partitionid,strrecordtype) VALUES"); } if (this.useBatchInsert) { insert1Str = ""; if (lazy) { insert1Str = lazyInsert1; } else { insert1Str = "\"" + (this.doSimplePk ? longtextFld.substring(0, 6) : longtextFld.substring(0, 99)) + "\","; insert1Str = insert1Str + "\"" + (this.doSimplePk ? longtextFld.substring(0, 10) : longtextFld.substring(0, 199)) + "\","; insert1Str = insert1Str + StressTool.getNumberFromRandom(2147483647) * StressTool.getNumberFromRandom(20) + ","; insert1Str = insert1Str + StressTool.getNumberFromRandom(20) + ","; insert1Str = insert1Str + "\"" + StressTool.getStringFromRandom(2) + "\""; insert1Str = insert1Str + ")"; lazyInsert1 = insert1Str; } for (int ibatch = 0; ibatch <= this.iBatchInsert; ibatch++) { // uuid = UUID.randomUUID().toString(); pk = StressTool.getNumberFromRandom(2147483647).intValue(); if (ibatch > 0) { insert1.append(",(UUID()," + pk + ","); } else { insert1.append("(UUID()," + pk + ","); } insert1.append(insert1Str); } } else { insert1Str = ""; insert1Str = insert1Str + "(UUID()," + pk + ","; if (lazy) { insert1Str = lazyInsert1; } else { insert1Str = insert1Str + "\"" + (this.doSimplePk ? longtextFld.substring(0, 6) : longtextFld.substring(0, 99)) + "\","; insert1Str = insert1Str + "\"" + (this.doSimplePk ? longtextFld.substring(0, 10) : longtextFld.substring(0, 199)) + "\","; insert1Str = insert1Str + StressTool.getNumberFromRandom(2147483647) * StressTool.getNumberFromRandom(20) + ","; insert1Str = insert1Str + StressTool.getNumberFromRandom(20) + ","; insert1Str = insert1Str + "\"" + StressTool.getStringFromRandom(2) + "\""; insert1Str = insert1Str + ")"; lazyInsert1 = insert1Str; } insert1.append(insert1Str); } if (!insertList1.equals("")) insertList1.add(insert1.toString()); insert1.delete(0, insert1.length()); } } if (!this.doSimplePk) { if (dbType.endsWith("MySQL")) { String insert2Str = ""; String insert2bStr = ""; for (int iTable = 1; iTable <= this.getNumberOfSecondaryTables(); iTable++) { insert2Str = ""; insert2Str = insert2Str + "insert INTO tbtest_child" + iTable + " (a,stroperation) VALUES("; insert2Str = insert2Str + pk + ","; if (lazy && !lazyInsert2.equals("")) { insert2bStr = lazyInsert2; } else { lazyInsert2 = "\"" + longtextFld + "\") ON DUPLICATE KEY UPDATE partitionid=0"; insert2bStr = lazyInsert2; // insert2Str = insert2Str + "\"" + longtextFld + "\") ON DUPLICATE KEY UPDATE partitionid=0"; // lazyInsert2 = insert2Str; } if (!insert2Str.equals("")) insertList2.add(insert2Str + insert2bStr); } } } v.add(0, insertList1); v.add(1, insertList2); // v.add(2, new Integer(pk)); return v; }
From source file:com.clustercontrol.collect.util.CollectGraphUtil.java
/** * ??????//from ww w . j a v a 2s. c o m * * @return */ private static String getEventFlagInfo() { StringBuffer sb = new StringBuffer(); List<String> managerList = new ArrayList<String>(getInstance().m_targetManagerFacilityCollectMap.keySet()); try { for (String managerName : managerList) { Map<String, List<Integer>> facilityMap = getInstance().m_targetManagerFacilityCollectMap .get(managerName); List<String> facilityIdList = new ArrayList<String>(facilityMap.keySet()); CollectEndpointWrapper wrapper = CollectEndpointWrapper.getWrapper(managerName); Map<String, List<EventDataInfo>> mapInfo; mapInfo = wrapper.getEventDataMap(facilityIdList); for (Entry<String, List<EventDataInfo>> entry : mapInfo.entrySet()) { List<EventDataInfo> eventInfoList = entry.getValue(); for (EventDataInfo eventInfo : eventInfoList) { // String application = eventInfo.getApplication(); // Boolean collectGraphFlg = eventInfo.isCollectGraphFlg(); // String comment = eventInfo.getComment(); // Long commentDate = eventInfo.getCommentDate(); // String commentUser = eventInfo.getCommentUser(); // Long confirmDate = eventInfo.getConfirmDate(); // String confirmUser = eventInfo.getConfirmUser(); // Integer confirmed = eventInfo.getConfirmed(); // Integer duplicationCount = eventInfo.getDuplicationCount(); String facilityId = eventInfo.getFacilityId(); Long generationDate = eventInfo.getGenerationDate(); // String managerName; String message = HinemosMessage.replace(eventInfo.getMessage()); // String messageOrg = eventInfo.getMessageOrg(); String monitorDetailId = eventInfo.getMonitorDetailId(); String monitorId = eventInfo.getMonitorId(); Long outputDate = eventInfo.getOutputDate(); // String ownerRoleId = eventInfo.getOwnerRoleId(); String pluginId = eventInfo.getPluginId(); Integer priority = eventInfo.getPriority(); // String scopeText = eventInfo.getScopeText(); String facilityName = getInstance().m_managerFacilityIdNameMap .get(managerName + SQUARE_SEPARATOR + facilityId); String dummyFacilityId = getInstance().m_managerFacilityIdDummyNameMap .get(managerName + SQUARE_SEPARATOR + facilityId); String dummyManagerName = getInstance().m_managerDummyNameMap.get(managerName); String ret = "{\'managername\':\'" + dummyManagerName + "\', "// DUMMY + "\'realmanagername\':\'" + managerName + "\', "// real + "\'generationdate\':\'" + generationDate + "\', " // ?? + "\'outputdate\':\'" + outputDate + "\', "// ???????? + "\'date\':\'" + generationDate + "\', " + "\'message\':\'" + message + "\', " + "\'monitorid\':\'" + monitorId + "\', " + "\'displayname\':\'" + monitorDetailId + "\', " + "\'priority\':\'" + PriorityMessage.typeToString(priority) + "\', " + "\'eventdetailid\':\'" + monitorId + facilityId + outputDate + "\', " // graph original value + "\'facilityname\':\'" + facilityName + "\', " + "\'pluginid\':\'" + pluginId + "\', " + "\'facilityid\':\'" + dummyFacilityId + "\', " + "\'realfacilityid\':\'" + facilityId + "\'}"; sb.append(ret); sb.append(","); } } } } catch (HinemosUnknown_Exception e) { m_log.error(e.getMessage()); // sb?????? sb.delete(0, sb.length()); } String ret = sb.toString(); if (ret != null && ret.length() != 0) { ret = ret.substring(0, ret.length() - 1); } m_log.info("eventFlagInfo:" + ret); return ret; }
From source file:com.mysql.stresstool.RunnableClusterQueryInsert.java
Vector getTablesValues(boolean refresh) { String longtextFld = ""; boolean lazy = false; int afld = 0; long counterFld = 0; if (refresh && !lazyInsert1.equals("")) { lazy = true;// w ww .j a va 2 s. c o m longtextFld = lazyLongText; } else { if (operationShort) longtextFld = StressTool.getStringFromRandom(254).substring(0, 240); else longtextFld = StressTool.getStringFromRandom(40000); } Vector v = new Vector(); StringBuffer insert1 = new StringBuffer(); StringBuffer insert2 = new StringBuffer(); ArrayList<String> insertList1 = new ArrayList(); ArrayList<String> insertList2 = new ArrayList(); // String uuid = UUID.randomUUID().toString(); int pk = StressTool.getNumberFromRandom(2147483647).intValue(); String insert1Str = ""; // INSERT INTO tbtest1 ("A","B","C","RECORDTYPE") VALUES(24351216,'d',14447453184,'mba'); if (dbType.endsWith("MySQL")) { for (int iTable = 1; iTable <= this.getNumberOfprimaryTables(); iTable++) { if (this.doSimplePk) { insert1.append("insert INTO tbtest" + iTable + " (uuid,a,b,c,counter,partitionid,strrecordtype) VALUES"); } else { insert1.append("insert INTO tbtest" + iTable + " (uuid,a,b,c,counter,partitionid,strrecordtype) VALUES"); } if (this.useBatchInsert) { insert1Str = ""; if (lazy) { insert1Str = lazyInsert1; } else { insert1Str = "\"" + (this.doSimplePk ? longtextFld.substring(0, 6) : longtextFld.substring(0, 99)) + "\","; insert1Str = insert1Str + "\"" + (this.doSimplePk ? longtextFld.substring(0, 10) : longtextFld.substring(0, 199)) + "\","; insert1Str = insert1Str + StressTool.getNumberFromRandom(2147483647) * StressTool.getNumberFromRandom(20) + ","; insert1Str = insert1Str + StressTool.getNumberFromRandom(20) + ","; insert1Str = insert1Str + "\"" + StressTool.getStringFromRandom(2) + "\""; insert1Str = insert1Str + ")"; lazyInsert1 = insert1Str; } for (int ibatch = 0; ibatch <= this.iBatchInsert; ibatch++) { // uuid = UUID.randomUUID().toString(); pk = StressTool.getNumberFromRandom(2147483647).intValue(); if (ibatch > 0) { insert1.append(",(UUID()," + pk + ","); } else { insert1.append("(UUID()," + pk + ","); } insert1.append(insert1Str); } } else { insert1Str = ""; insert1Str = insert1Str + "(UUID()," + pk + ","; if (lazy) { insert1Str = lazyInsert1; } else { insert1Str = insert1Str + "\"" + (this.doSimplePk ? longtextFld.substring(0, 6) : longtextFld.substring(0, 99)) + "\","; insert1Str = insert1Str + "\"" + (this.doSimplePk ? longtextFld.substring(0, 10) : longtextFld.substring(0, 199)) + "\","; insert1Str = insert1Str + StressTool.getNumberFromRandom(2147483647) * StressTool.getNumberFromRandom(20) + ","; insert1Str = insert1Str + StressTool.getNumberFromRandom(20) + ","; insert1Str = insert1Str + "\"" + StressTool.getStringFromRandom(2) + "\""; insert1Str = insert1Str + ")"; lazyInsert1 = insert1Str; } insert1.append(insert1Str); } if (!insertList1.equals("")) insertList1.add(insert1.toString()); insert1.delete(0, insert1.length()); } } if (!this.doSimplePk) { if (dbType.endsWith("MySQL")) { String insert2Str = ""; String insert2bStr = ""; for (int iTable = 1; iTable <= this.getNumberOfSecondaryTables(); iTable++) { insert2Str = ""; insert2Str = insert2Str + "insert INTO tbtest_child" + iTable + " (a,stroperation) VALUES("; insert2Str = insert2Str + pk + ","; if (lazy && !lazyInsert2.equals("")) { insert2bStr = lazyInsert2; } else { lazyInsert2 = "\"" + longtextFld + "\") ON DUPLICATE KEY UPDATE partitionid=0"; insert2bStr = lazyInsert2; // insert2Str = insert2Str + "\"" + longtextFld + "\") ON DUPLICATE KEY UPDATE partitionid=0"; // lazyInsert2 = insert2Str; } if (!insert2Str.equals("")) insertList2.add(insert2Str + insert2bStr); } } } v.add(0, insertList1); v.add(1, insertList2); // v.add(2, new Integer(pk)); return v; }
From source file:com.mysql.stresstool.RunnableSC2013QueryInsert.java
Vector getTablesValues(boolean refresh) { String longtextFld = ""; boolean lazy = false; int afld = 0; long counterFld = 0; if (refresh && !lazyInsert1.equals("")) { lazy = true;/* w w w . j a v a 2 s.com*/ longtextFld = lazyLongText; } else { if (operationShort) longtextFld = StressTool.getStringFromRandom(254).substring(0, 240); else longtextFld = StressTool.getStringFromRandom(40000); } Vector v = new Vector(); StringBuffer insert1 = new StringBuffer(); StringBuffer insert2 = new StringBuffer(); ArrayList<String> insertList1 = new ArrayList(); ArrayList<String> insertList2 = new ArrayList(); // String uuid = UUID.randomUUID().toString(); int pk = StressTool.getNumberFromRandom(2147483647).intValue(); String insert1Str = ""; // INSERT INTO tbtest1 ("A","B","C","RECORDTYPE") VALUES(24351216,'d',14447453184,'mba'); if (dbType.endsWith("MySQL")) { for (int iTable = 1; iTable <= this.getNumberOfprimaryTables(); iTable++) { if (this.doSimplePk) { insert1.append("insert INTO tbtest" + iTable + " (uuid,a,b,c,counter,partitionid,strrecordtype) VALUES"); } else { insert1.append("insert INTO tbtest" + iTable + " (uuid,a,b,c,counter,partitionid,strrecordtype) VALUES"); } if (this.useBatchInsert) { insert1Str = ""; if (lazy) { insert1Str = lazyInsert1; } else { insert1Str = "\"" + (this.doSimplePk ? longtextFld.substring(0, 6) : longtextFld.substring(0, 99)) + "\","; insert1Str = insert1Str + "\"" + (this.doSimplePk ? longtextFld.substring(0, 10) : longtextFld.substring(0, 199)) + "\","; insert1Str = insert1Str + StressTool.getNumberFromRandom(2147483647) * StressTool.getNumberFromRandom(20) + ","; insert1Str = insert1Str + " FROM_DAYS(" + StressTool.getNumberFromRandomMinMax(735325, 735384) + "),"; insert1Str = insert1Str + "\"" + StressTool.getStringFromRandom(2) + "\""; insert1Str = insert1Str + ")"; lazyInsert1 = insert1Str; } for (int ibatch = 0; ibatch <= this.iBatchInsert; ibatch++) { // uuid = UUID.randomUUID().toString(); pk = StressTool.getNumberFromRandom(2147483647).intValue(); if (ibatch > 0) { insert1.append(",(UUID()," + pk + ","); } else { insert1.append("(UUID()," + pk + ","); } insert1.append(insert1Str); } } else { insert1Str = ""; insert1Str = insert1Str + "(UUID()," + pk + ","; if (lazy) { insert1Str = lazyInsert1; } else { insert1Str = insert1Str + "\"" + (this.doSimplePk ? longtextFld.substring(0, 6) : longtextFld.substring(0, 99)) + "\","; insert1Str = insert1Str + "\"" + (this.doSimplePk ? longtextFld.substring(0, 10) : longtextFld.substring(0, 199)) + "\","; insert1Str = insert1Str + StressTool.getNumberFromRandom(2147483647) * StressTool.getNumberFromRandom(20) + ","; insert1Str = insert1Str + StressTool.getNumberFromRandom(20) + ","; insert1Str = insert1Str + "\"" + StressTool.getStringFromRandom(2) + "\""; insert1Str = insert1Str + ")"; lazyInsert1 = insert1Str; } insert1.append(insert1Str); } if (!insertList1.equals("")) insertList1.add(insert1.toString()); insert1.delete(0, insert1.length()); } } if (!this.doSimplePk) { if (dbType.endsWith("MySQL")) { String insert2Str = ""; String insert2bStr = ""; for (int iTable = 1; iTable <= this.getNumberOfSecondaryTables(); iTable++) { insert2Str = ""; insert2Str = insert2Str + "insert INTO tbtest_child" + iTable + " (a,stroperation) VALUES("; insert2Str = insert2Str + pk + ","; if (lazy && !lazyInsert2.equals("")) { insert2bStr = lazyInsert2; } else { lazyInsert2 = "\"" + longtextFld + "\") ON DUPLICATE KEY UPDATE partitionid=0"; insert2bStr = lazyInsert2; // insert2Str = insert2Str + "\"" + longtextFld + "\") ON DUPLICATE KEY UPDATE partitionid=0"; // lazyInsert2 = insert2Str; } if (!insert2Str.equals("")) insertList2.add(insert2Str + insert2bStr); } } } v.add(0, insertList1); v.add(1, insertList2); // v.add(2, new Integer(pk)); return v; }
From source file:com.mysql.stresstool.RunnableQueryInsertPartRange.java
Vector getTablesValues(boolean refresh) { String longtextFld = ""; boolean lazy = false; int afld = 0; long counterFld = 0; if (refresh && !lazyInsert1.equals("")) { lazy = true;/*from ww w . j a va2 s .c om*/ longtextFld = lazyLongText; } else { if (operationShort) longtextFld = StressTool.getStringFromRandom(254).substring(0, 240); else longtextFld = StressTool.getStringFromRandom(40000); } Vector v = new Vector(); StringBuffer insert1 = new StringBuffer(); StringBuffer insert2 = new StringBuffer(); // String uuid = UUID.randomUUID().toString(); ArrayList<String> insertList1 = new ArrayList(); ArrayList<String> insertList2 = new ArrayList(); int pk = StressTool.getNumberFromRandom(2147483647).intValue(); String insert1Str = ""; if (dbType.endsWith("MySQL")) { for (int iTable = 1; iTable <= this.getNumberOfprimaryTables(); iTable++) { insert1.append("insert INTO tbtest" + iTable + " (uuid,date,a,b,c,counter,partitionid,strrecordtype) VALUES"); if (this.useBatchInsert) { insert1Str = ""; if (lazy) { insert1Str = lazyInsert1; } else { insert1Str = "\"" + (this.doSimplePk ? longtextFld.substring(0, 6) : longtextFld.substring(0, 99)) + "\","; insert1Str = insert1Str + "\"" + (this.doSimplePk ? longtextFld.substring(0, 10) : longtextFld.substring(0, 199)) + "\","; insert1Str = insert1Str + StressTool.getNumberFromRandom(2147483647) * StressTool.getNumberFromRandom(20) + ","; insert1Str = insert1Str + StressTool.getNumberFromRandom(20) + ","; insert1Str = insert1Str + "\"" + StressTool.getStringFromRandom(2) + "\""; insert1Str = insert1Str + ")"; lazyInsert1 = insert1Str; } for (int ibatch = 0; ibatch <= this.iBatchInsert; ibatch++) { String thisDate = getRangeDate(); // uuid = UUID.randomUUID().toString(); pk = StressTool.getNumberFromRandom(2147483647).intValue(); if (ibatch > 0) { insert1.append(",(UUID(),'" + thisDate + "'," + pk + ","); } else { insert1.append("(UUID(),'" + thisDate + "'," + pk + ","); } insert1.append(insert1Str); } } else { String thisDate = getRangeDate(); insert1Str = ""; insert1Str = insert1Str + "(UUID(),'" + thisDate + "'," + pk + ","; if (lazy) { insert1Str = lazyInsert1; } else { insert1Str = insert1Str + "\"" + (this.doSimplePk ? longtextFld.substring(0, 6) : longtextFld.substring(0, 99)) + "\","; insert1Str = insert1Str + "\"" + (this.doSimplePk ? longtextFld.substring(0, 10) : longtextFld.substring(0, 199)) + "\","; insert1Str = insert1Str + StressTool.getNumberFromRandom(2147483647) * StressTool.getNumberFromRandom(20) + ","; insert1Str = insert1Str + StressTool.getNumberFromRandom(20) + ","; insert1Str = insert1Str + "\"" + StressTool.getStringFromRandom(2) + "\""; insert1Str = insert1Str + ")"; lazyInsert1 = insert1Str; } insert1.append(insert1Str); } if (!insertList1.equals("")) insertList1.add(insert1.toString()); insert1.delete(0, insert1.length()); } } if (!this.doSimplePk) { if (dbType.endsWith("MySQL")) { String insert2Str = ""; String insert2bStr = ""; String thisDate = getRangeDate(); for (int iTable = 1; iTable <= this.getNumberOfSecondaryTables(); iTable++) { insert2Str = ""; insert2Str = insert2Str + "insert INTO tbtest_child" + iTable + " (a,date,stroperation) VALUES("; insert2Str = insert2Str + pk + ",'" + thisDate + "',"; if (lazy && !lazyInsert2.equals("")) { insert2bStr = lazyInsert2; } else { if (this.getOnDuplicateKey() == 0) { lazyInsert2 = "\"" + longtextFld + "\")"; } else { lazyInsert2 = "\"" + longtextFld + "\") ON DUPLICATE KEY UPDATE partitionid=0"; } insert2bStr = lazyInsert2; // insert2Str = insert2Str + "\"" + longtextFld + "\") ON DUPLICATE KEY UPDATE partitionid=0"; // lazyInsert2 = insert2Str; } if (!insert2Str.equals("")) insertList2.add(insert2Str + insert2bStr); } } } v.add(0, insertList1); v.add(1, insertList2); // v.add(2, new Integer(pk)); return v; }
From source file:com.mysql.stresstool.RunnableQueryInsertPCH.java
Vector getTablesValues(boolean refresh, int ServerId) { String longtextFld = ""; boolean lazy = false; int afld = 0; long counterFld = 0; if (refresh && !lazyInsert1.equals("")) { lazy = true;//from www . j a v a 2 s . com longtextFld = lazyLongText; } else { if (operationShort) longtextFld = StressTool.getStringFromRandom(254).substring(0, 240); else longtextFld = StressTool.getStringFromRandom(40000); } Vector v = new Vector(); StringBuffer insert1 = new StringBuffer(); StringBuffer insert2 = new StringBuffer(); // String uuid = UUID.randomUUID().toString(); ArrayList<String> insertList1 = new ArrayList(); ArrayList<String> insertList2 = new ArrayList(); int pk = StressTool.getNumberFromRandom(2147483647).intValue(); String insert1Str = ""; if (dbType.endsWith("MySQL")) { for (int iTable = 1; iTable <= this.getNumberOfprimaryTables(); iTable++) { if (this.doSimplePk) { insert1.append("insert INTO tbtest" + iTable + " (uuid,a,serverid,b,c,counter,partitionid,strrecordtype) VALUES"); } else { insert1.append("insert INTO tbtest" + iTable + " (uuid,a,serverid,b,c,counter,partitionid,strrecordtype) VALUES"); } if (this.useBatchInsert) { insert1Str = ""; if (lazy) { insert1Str = lazyInsert1;//.substring(0, lazyInsert1.length() - 2 ) + ServerId +")"; } else { insert1Str = "\"" + (this.doSimplePk ? longtextFld.substring(0, 6) : longtextFld.substring(0, 99)) + "\","; insert1Str = insert1Str + "\"" + (this.doSimplePk ? longtextFld.substring(0, 10) : longtextFld.substring(0, 199)) + "\","; insert1Str = insert1Str + StressTool.getNumberFromRandom(2147483647) * StressTool.getNumberFromRandom(20) + ","; insert1Str = insert1Str + StressTool.getNumberFromRandom(20) + ","; insert1Str = insert1Str + "\"" + StressTool.getStringFromRandom(2) + "\""; insert1Str = insert1Str + ")"; lazyInsert1 = insert1Str; } for (int ibatch = 0; ibatch <= this.iBatchInsert; ibatch++) { // uuid = UUID.randomUUID().toString(); pk = StressTool.getNumberFromRandom(2147483647).intValue(); if (ibatch > 0) { insert1.append(",(UUID()," + pk + "," + ServerId + ","); } else { insert1.append("(UUID()," + pk + "," + ServerId + ","); } insert1.append(insert1Str); } } else { insert1Str = ""; insert1Str = insert1Str + "(UUID()," + pk + "," + ServerId + ","; if (lazy) { insert1Str = lazyInsert1;//.substring(0, lazyInsert1.length() - 2 ) + ServerId +")"; } else { insert1Str = insert1Str + "\"" + (this.doSimplePk ? longtextFld.substring(0, 6) : longtextFld.substring(0, 99)) + "\","; insert1Str = insert1Str + "\"" + (this.doSimplePk ? longtextFld.substring(0, 10) : longtextFld.substring(0, 199)) + "\","; insert1Str = insert1Str + StressTool.getNumberFromRandom(2147483647) * StressTool.getNumberFromRandom(20) + ","; insert1Str = insert1Str + StressTool.getNumberFromRandom(20) + ","; insert1Str = insert1Str + "\"" + StressTool.getStringFromRandom(2) + "\""; insert1Str = insert1Str + ")"; lazyInsert1 = insert1Str; } insert1.append(insert1Str); } if (!insertList1.equals("")) insertList1.add(insert1.toString()); insert1.delete(0, insert1.length()); } } if (!this.doSimplePk) { if (dbType.endsWith("MySQL")) { String insert2Str = ""; String insert2bStr = ""; for (int iTable = 1; iTable <= this.getNumberOfSecondaryTables(); iTable++) { insert2Str = ""; insert2Str = insert2Str + "insert INTO tbtest_child" + iTable + " (a,serverid,stroperation) VALUES("; insert2Str = insert2Str + pk + "," + ServerId + ","; if (lazy && !lazyInsert2.equals("")) { insert2bStr = lazyInsert2; } else { lazyInsert2 = "\"" + longtextFld + "\") ON DUPLICATE KEY UPDATE partitionid=0"; insert2bStr = lazyInsert2; // insert2Str = insert2Str + "\"" + longtextFld + "\") ON DUPLICATE KEY UPDATE partitionid=0"; // lazyInsert2 = insert2Str; } if (!insert2Str.equals("")) insertList2.add(insert2Str + insert2bStr); } } } v.add(0, insertList1); v.add(1, insertList2); // v.add(2, new Integer(pk)); return v; }
From source file:cgeo.geocaching.cgBase.java
public String requestJSONgc(String host, String path, String params) { int httpCode = -1; String httpLocation = null;/*from w w w . j av a 2 s. c o m*/ final String cookiesDone = CookieJar.getCookiesAsString(prefs); URLConnection uc = null; HttpURLConnection connection = null; Integer timeout = 30000; final StringBuffer buffer = new StringBuffer(); for (int i = 0; i < 3; i++) { if (i > 0) { Log.w(cgSettings.tag, "Failed to download data, retrying. Attempt #" + (i + 1)); } buffer.delete(0, buffer.length()); timeout = 30000 + (i * 15000); try { // POST final URL u = new URL("http://" + host + path); uc = u.openConnection(); uc.setRequestProperty("Host", host); uc.setRequestProperty("Cookie", cookiesDone); uc.setRequestProperty("Content-Type", "application/json; charset=UTF-8"); uc.setRequestProperty("X-Requested-With", "XMLHttpRequest"); uc.setRequestProperty("Accept", "application/json, text/javascript, */*; q=0.01"); uc.setRequestProperty("Referer", host + "/" + path); if (settings.asBrowser == 1) { uc.setRequestProperty("Accept-Charset", "utf-8, iso-8859-1, utf-16, *;q=0.7"); uc.setRequestProperty("Accept-Language", "en-US"); uc.setRequestProperty("User-Agent", idBrowser); uc.setRequestProperty("Connection", "keep-alive"); uc.setRequestProperty("Keep-Alive", "300"); } connection = (HttpURLConnection) uc; connection.setReadTimeout(timeout); connection.setRequestMethod("POST"); HttpURLConnection.setFollowRedirects(false); // TODO: Fix these (FilCab) connection.setDoInput(true); connection.setDoOutput(true); final OutputStream out = connection.getOutputStream(); final OutputStreamWriter wr = new OutputStreamWriter(out); wr.write(params); wr.flush(); wr.close(); CookieJar.setCookies(prefs, uc); InputStream ins = getInputstreamFromConnection(connection); final InputStreamReader inr = new InputStreamReader(ins); final BufferedReader br = new BufferedReader(inr); readIntoBuffer(br, buffer); httpCode = connection.getResponseCode(); httpLocation = uc.getHeaderField("Location"); final String paramsLog = params.replaceAll(passMatch, "password=***"); Log.i(cgSettings.tag + " | JSON", "[POST " + (int) (params.length() / 1024) + "k | " + httpCode + " | " + (int) (buffer.length() / 1024) + "k] Downloaded " + "http://" + host + path + "?" + paramsLog); connection.disconnect(); br.close(); ins.close(); inr.close(); } catch (IOException e) { Log.e(cgSettings.tag, "cgeoBase.requestJSONgc.IOException: " + e.toString()); } catch (Exception e) { Log.e(cgSettings.tag, "cgeoBase.requestJSONgc: " + e.toString()); } if (buffer != null && buffer.length() > 0) { break; } } String page = null; if (httpCode == 302 && httpLocation != null) { final Uri newLocation = Uri.parse(httpLocation); if (newLocation.isRelative()) { page = requestJSONgc(host, path, params); } else { page = requestJSONgc(newLocation.getHost(), newLocation.getPath(), params); } } else { replaceWhitespace(buffer); page = buffer.toString(); } if (page != null) { return page; } else { return ""; } }
From source file:com.arksoft.epamms.ZGlobal1_Operation.java
public int SetStringUpperLowerCase(StringBuilder sbName) { String string;// w w w . j ava 2 s. c o m boolean bSuffix = false; int nBlankFound = 0; @SuppressWarnings("unused") int nLth; int k; int j; // Eliminate leading and trailing blanks. string = sbName.toString(); string = string.trim(); // Force first character to be upper case StringBuffer sb = new StringBuffer(string.toLowerCase()); // force string to lower case sb.setCharAt(0, Character.toUpperCase(sb.charAt(0))); for (k = 1; k < sb.length(); k++) { // Eliminate multiple consecutive blanks. if (sb.charAt(k) == ' ') { j = k; while (sb.charAt(j + 1) == ' ') j++; if (j > k) sb.delete(k + 1, j); } else // if ( sb.charAt( k ) != ' ' ) { if (sb.charAt(k - 1) == ' ') { nBlankFound++; char ch = Character.toUpperCase(sb.charAt(k)); sb.setCharAt(k, ch); if (ch == 'I' || ch == 'V') bSuffix = true; else bSuffix = false; } else { if (nBlankFound > 1 && bSuffix) // checking for II or III or IV or V or VI or VII or VIII { if ((sb.charAt(k) == 'i' || sb.charAt(k) == 'v') && (sb.charAt(k + 1) == '\0' || sb.charAt(k + 1) == 'i' || sb.charAt(k + 1) == 'v')) { sb.setCharAt(k, Character.toUpperCase(sb.charAt(k))); } else bSuffix = false; } else { bSuffix = false; // can't start with suffix } } } } zstrcpy(sbName, sb.toString()); return sbName.length(); }
From source file:com.mysql.stresstool.RunnableQueryInsertDR.java
Vector getTablesValues(boolean refresh) { String longtextFld = ""; boolean lazy = false; int afld = 0; long counterFld = 0; // if(refresh && !lazyInsert1.equals("")) // {/*from w w w.j a v a 2 s . c o m*/ // lazy = true; // longtextFld = lazyLongText; // } // else{ // if(operationShort) // longtextFld = StressTool.getStringFromRandom(254).substring(0,240); // else // longtextFld = StressTool.getStringFromRandom(40000); // } Vector v = new Vector(); StringBuffer insert1 = new StringBuffer(); StringBuffer insert2 = new StringBuffer(); // String uuid = UUID.randomUUID().toString(); ArrayList<String> insertList1 = new ArrayList(); ArrayList<String> insertList2 = new ArrayList(); int pk = StressTool.getNumberFromRandom(2147483647).intValue(); String insert1Str = ""; if (dbType.endsWith("MySQL")) { for (int iTable = 1; iTable <= this.getNumberOfprimaryTables(); iTable++) { // +--------+------------+------------+-----------+--------+------------+---------+ // * | emp_no | birth_date | first_name | last_name | gender | hire_date | city_id | // * +--------+------------+------------+-----------+--------+------------+---------+ insert1.append("insert INTO tbtest" + iTable + " (emp_no,birth_date,first_name,last_name,gender,hire_date,city_id,CityName,CountryCode,UUID) VALUES"); if (this.useBatchInsert) { for (int ibatch = 0; ibatch <= this.iBatchInsert; ibatch++) { String nameString = Name .get(StressTool.getNumberFromRandomMinMax(0, Name.size() - 1).intValue()); String lastNString = LastName .get(StressTool.getNumberFromRandomMinMax(0, LastName.size() - 1).intValue()); String cityString = (String) city.keySet().toArray()[StressTool .getNumberFromRandomMinMax(0, city.size() - 1).intValue()]; String[] cityN_ISO = ((String) city.get(cityString)).split("-"); int fromDaysBirth = StressTool.getNumberFromRandomMinMax(712223, 735630).intValue(); int fromDaysHire = StressTool.getNumberFromRandomMinMax(712223, 735630).intValue(); String gender = ""; if (fromDaysBirth % 2 == 0) { gender = "M"; } else { gender = "F"; } if (ibatch > 0) { insert1.append(","); } insert1.append("(NULL,FROM_DAYS(" + fromDaysBirth + ")," + "'" + nameString + "'," + "'" + lastNString + "'," + "'" + gender + "'," + "FROM_DAYS(" + fromDaysHire + ")," + cityN_ISO[0] + "," + "'" + cityString + "'," + "'" + cityN_ISO[1] + "'," + "UUID())"); } } else { String nameString = Name .get(StressTool.getNumberFromRandomMinMax(0, Name.size() - 1).intValue()); String lastNString = LastName .get(StressTool.getNumberFromRandomMinMax(0, LastName.size() - 1).intValue()); String cityString = (String) city.keySet().toArray()[StressTool .getNumberFromRandomMinMax(0, city.size() - 1).intValue()]; String[] cityN_ISO = ((String) city.get(cityString)).split("-"); int fromDaysBirth = StressTool.getNumberFromRandomMinMax(712223, 735630).intValue(); int fromDaysHire = StressTool.getNumberFromRandomMinMax(712223, 735630).intValue(); String gender = ""; if (fromDaysBirth % 2 == 0) { gender = "M"; } else { gender = "F"; } insert1.append("(NULL,FROM_DAYS(" + fromDaysBirth + ")," + "'" + nameString + "'," + "'" + lastNString + "'," + "'" + gender + "'," + "FROM_DAYS(" + fromDaysHire + ")," + cityN_ISO[0] + "," + "'" + cityString + "'," + "'" + cityN_ISO[1] + "'," + "UUID())"); } if (!insertList1.equals("")) insertList1.add(insert1.toString()); insert1.delete(0, insert1.length()); } } // if(!this.doSimplePk) // { // if(dbType.endsWith("MySQL")) // { // String insert2Str = ""; // String insert2bStr = ""; // String thisDate = getRangeDate(); // // for(int iTable = 1; iTable <= this.getNumberOfSecondaryTables(); iTable++){ // insert2Str = ""; // // insert2Str = insert2Str +"insert INTO tbtest_child" + iTable + " (a,date,stroperation) VALUES("; // insert2Str = insert2Str + pk + ",'" + thisDate + "',"; // if(lazy && !lazyInsert2.equals("")){ // insert2bStr = lazyInsert2; // } // else{ // lazyInsert2 = "\"" + longtextFld + "\") ON DUPLICATE KEY UPDATE partitionid=0"; // insert2bStr = lazyInsert2; // // insert2Str = insert2Str + "\"" + longtextFld + "\") ON DUPLICATE KEY UPDATE partitionid=0"; // // lazyInsert2 = insert2Str; // } // // if(!insert2Str.equals("")) // insertList2.add(insert2Str + insert2bStr); // // } // // } // } v.add(0, insertList1); v.add(1, insertList2); // v.add(2, new Integer(pk)); return v; }
From source file:org.agnitas.beans.impl.MailingImpl.java
@Override public String getPreview(String input_org, int inputType, int customerID, boolean overwriteMailtype, ApplicationContext con) throws Exception { DynamicTag aktTag = null;/*from w ww .j a v a2 s . co m*/ DynamicTag tmpTag = null; DynamicTag contentTag = null; String contentString = null; DynamicTagContent aContent = null; DynamicTagContent aTmpContent = null; Target aTarget = null; int aTargetID = 0; Hashtable<String, DynamicTag> allTags = new Hashtable<String, DynamicTag>(); Hashtable<String, Target> allTargets = new Hashtable<String, Target>(); Interpreter aBsh = null; String input = input_org; TargetDao tDao = (TargetDao) con.getBean("TargetDao"); StringBuffer output = new StringBuffer(this.personalizeText(input, customerID, con)); searchPos = 0; aBsh = AgnUtils.getBshInterpreter(companyID, customerID, con); if (overwriteMailtype) { aBsh.set("mailtype", new Integer(inputType)); } if (aBsh == null) { throw new Exception("error.template.dyntags"); } Iterator<DynamicTag> it = this.dynTags.values().iterator(); while (it.hasNext()) { aktTag = it.next(); tmpTag = (DynamicTag) con.getBean("DynamicTag"); tmpTag.setDynName(aktTag.getDynName()); Map<String, DynamicTagContent> contentMap = aktTag.getDynContent(); if (contentMap != null) { Iterator<DynamicTagContent> it2 = contentMap.values().iterator(); while (it2.hasNext()) { aContent = it2.next(); aTmpContent = (DynamicTagContent) con.getBean("DynamicTagContent"); aTmpContent.setDynName(aContent.getDynName()); aTmpContent.setDynOrder(aContent.getDynOrder()); aTmpContent.setDynContent(this.personalizeText(aContent.getDynContent(), customerID, con)); aTmpContent.setTargetID(aContent.getTargetID()); aTmpContent.setId(aContent.getId()); tmpTag.addContent(aTmpContent); } } allTags.put(aktTag.getDynName(), tmpTag); } aContent = null; this.searchPos = 0; while ((aktTag = findNextDynTag(output.toString(), con)) != null) { searchPos = aktTag.getStartTagStart(); // always search from // beginning of last found // tag if (allTags.containsKey(aktTag.getDynName())) { contentTag = (DynamicTag) allTags.get(aktTag.getDynName()); Map<String, DynamicTagContent> contentMap = contentTag.getDynContent(); contentString = null; // reset always if (contentMap != null) { Iterator<DynamicTagContent> it3 = contentMap.values().iterator(); while (it3.hasNext()) { aContent = it3.next(); aTargetID = aContent.getTargetID(); if (allTargets.containsKey(Integer.toString(aTargetID))) { aTarget = (Target) allTargets.get(Integer.toString(aTargetID)); } else { aTarget = tDao.getTarget(aTargetID, this.companyID); if (aTarget == null) { aTarget = (Target) con.getBean("Target"); aTarget.setCompanyID(this.companyID); aTarget.setId(aTargetID); } allTargets.put(Integer.toString(aTarget.getId()), aTarget); } aTargetID = aTarget.getId(); if (aTargetID == 0) { // Target fits contentString = aContent.getDynContent(); break; // stop processing list of content } else { if (aTarget.isCustomerInGroup(aBsh)) { contentString = aContent.getDynContent(); break; // stop processing list of content } } } } // insert content if found content if (contentString != null) { if (aktTag.isComplex()) { output.delete(aktTag.getEndTagStart(), aktTag.getEndTagEnd()); output.replace(aktTag.getValueTagStart(), aktTag.getValueTagEnd(), contentString); output.delete(aktTag.getStartTagStart(), aktTag.getStartTagEnd()); } else { output.replace(aktTag.getStartTagStart(), aktTag.getStartTagEnd(), contentString); } } else { if (aktTag.isComplex()) { output.delete(aktTag.getStartTagStart(), aktTag.getEndTagEnd()); } else { output.delete(aktTag.getStartTagStart(), aktTag.getStartTagEnd()); } } } else { // dyntag not found in list, throw exception! throw new Exception("error.template.dyntags"); } } if (inputType == MailingImpl.INPUT_TYPE_TEXT) { if (this.getEmailParam().getLinefeed() > 0) { output = new StringBuffer(SafeString.cutLineLength(SafeString.removeHTMLTags(output.toString()), this.getEmailParam().getLinefeed())); } else { output = new StringBuffer(SafeString.removeHTMLTags(output.toString())); } } output = new StringBuffer(this.insertTrackableLinks(output.toString(), customerID, con)); return output.toString(); }