List of usage examples for java.util ArrayList iterator
public Iterator<E> iterator()
From source file:com.sun.faces.util.Util.java
/** * <p>Return an Iterator over {@link SelectItemWrapper} instances representing the * available options for this component, assembled from the set of * {@link UISelectItem} and/or {@link UISelectItems} components that are * direct children of this component. If there are no such children, a * zero-length array is returned.</p> * * @param context The {@link FacesContext} for the current request. * If null, the UISelectItems behavior will not work. * @throws NullPointerException if <code>context</code> * is <code>null</code> *//* w ww . jav a2s.c o m*/ public static Iterator getSelectItems(FacesContext context, UIComponent component) { ArrayList list = new ArrayList(); Iterator kids = component.getChildren().iterator(); while (kids.hasNext()) { UIComponent kid = (UIComponent) kids.next(); if (kid instanceof UISelectItem) { Object value = ((UISelectItem) kid).getValue(); if (value == null) { UISelectItem item = (UISelectItem) kid; list.add(new SelectItem(item.getItemValue(), item.getItemLabel(), item.getItemDescription(), item.isItemDisabled())); } else if (value instanceof SelectItem) { list.add(value); } else { throw new IllegalArgumentException( Util.getExceptionMessageString(Util.CONVERSION_ERROR_MESSAGE_ID)); } } else if (kid instanceof UISelectItems && null != context) { Object value = ((UISelectItems) kid).getValue(); if (value instanceof SelectItem) { list.add(value); } else if (value instanceof SelectItem[]) { SelectItem items[] = (SelectItem[]) value; for (int i = 0; i < items.length; i++) { list.add(items[i]); } } else if (value instanceof Collection) { Iterator elements = ((Collection) value).iterator(); while (elements.hasNext()) { list.add(elements.next()); } } else if (value instanceof Map) { Iterator keys = ((Map) value).keySet().iterator(); while (keys.hasNext()) { Object key = keys.next(); if (key == null) { continue; } Object val = ((Map) value).get(key); if (val == null) { continue; } list.add(new SelectItem(val.toString(), key.toString(), null)); } } else { throw new IllegalArgumentException( Util.getExceptionMessageString(Util.CONVERSION_ERROR_MESSAGE_ID)); } } } return (list.iterator()); }
From source file:org.alfresco.reporting.processor.NodeRefBasedPropertyProcessor.java
/** * Harvests 1) objects 2) closed tasks after date x *//*from ww w . j a v a 2 s . c o m*/ public void havestNodes(final NodeRef harvestDefinition) { /* * for each store:stores for each table:tables while continue search * continue = search.size>0 for each result:resultset if isVersioned * addAllOlderVersionsToQueue(result) addToQueue(result) processQueue() * // end while continue // end for each table // end for each store */ logger.info("harvest run start..."); ; try { final ArrayList<StoreRef> storeList = getStoreRefList(); final Properties queries = getTableQueries(harvestDefinition); final String language = reportingHelper.getSearchLanguage(harvestDefinition); // Make sure there is a connection dbhb.openReportingConnection(); Enumeration<Object> keys = queries.keys(); String fullQuery; // is the actual query appending orderby // node-dbid, and lastmodifued clause // Cycle all Lucene queries while (keys.hasMoreElements()) { String tableName = (String) keys.nextElement(); String query = (String) queries.get(tableName); tableName = dbhb.fixTableColumnName(tableName); if (logger.isDebugEnabled()) logger.debug("harvest: preparing table =" + tableName); // get a clean iterator to cycle all stores Iterator<StoreRef> storeIterator = storeList.iterator(); Date lastModified = null; boolean archiveAllowed = false; // prevent having two threads doing the same if (!dbhb.tableIsRunning(tableName)) { String nowFormattedDate = getNowAsFormattedString(); String timestamp = ""; // old school all-in-one harvesting if (!getBatchTimestampEnabled()) { dbhb.setLastTimestampStatusRunning(tableName); timestamp = dbhb.getLastTimestamp(tableName); } // else, see 5 lines below dbhb.createEmptyTables(tableName); int maxItems = getMaxLoopSize(); while (storeIterator.hasNext()) { StoreRef storeRef = storeIterator.next(); // mew insight, limit the number of loops, treat // mechanism with more care if (getBatchTimestampEnabled()) { dbhb.setLastTimestampStatusRunning( tableName + "_" + storeRef.getProtocol().substring(0, 1)); timestamp = dbhb .getLastTimestamp(tableName + "_" + storeRef.getProtocol().substring(0, 1)); } if (logger.isDebugEnabled()) logger.debug("harvest: StoreRef=" + storeRef.getProtocol() + ", archiveAllowed=" + archiveAllowed); // (re)set some essential process markers. // These are local to the run-per-storeRef long startDbId = 0; // the original database id of // the noderef long loopcount = 0; // count the number of // harvesting loops. Should be // <=2 for initial harvesting // agaist factory repo boolean letsContinue = true; // break if we process the archive before the // workspace is done... if (storeRef.getProtocol().equals(StoreRef.PROTOCOL_ARCHIVE) && !archiveAllowed) { letsContinue = false; } if (logger.isDebugEnabled()) logger.debug("harvest: before while, letsContinue=" + letsContinue); while (letsContinue) { loopcount++; // hasEverRun is needed to determine if an // update of lastModifiedTimestamp has occured // ever in a batch, or never. boolean hasEverRun = false; if (logger.isInfoEnabled()) { logger.info("++ Loop number: " + loopcount + ", tablename: " + tableName + ", archive: " + archiveAllowed); } if (getBatchTimestampEnabled()) { // default = // true nowFormattedDate = getNowAsFormattedString(); } fullQuery = query + queryClauseTimestamp(language, timestamp, storeRef.getProtocol()) + queryClauseOrderBy(language, startDbId, storeRef.getProtocol()); if (logger.isDebugEnabled()) { logger.debug("harvest: StoreProtocol = " + storeRef.getProtocol() + ", archive: " + archiveAllowed + "\nfullQuery = " + fullQuery); } SearchParameters sp = new SearchParameters(); sp.setLanguage(language); sp.addStore(storeRef); sp.setQuery(fullQuery); // sp.addSort(getOrderBy(language), true); if (maxItems > 0) { sp.setMaxItems(maxItems); } if (logger.isDebugEnabled()) { logger.debug("Searchparameter query: " + sp.getQuery()); } ResultSet results = getSearchService().query(sp); if (logger.isDebugEnabled()) logger.debug("harvest: prepare flipping: archiveAllowed=" + archiveAllowed + ", length=" + results.length()); // allow harvesting the archive if the workspace // has been done! // workspace is done if there are no more search // results if (results.length() == 0 && !archiveAllowed) { if (logger.isDebugEnabled()) logger.debug("harvest: flipping to archiveAllowed=true"); archiveAllowed = true; } letsContinue = stillContinueHarvesting(loopcount, results.length()); logger.debug("harvest: loopcount= " + loopcount + "\n" + "harvest: resultsize = " + results.length() + "\n" + "harvest: letsContinue = " + letsContinue + "\n" + "harvest: archiveAllow = " + archiveAllowed + "\n" + "harvest: tablename = " + tableName); SimpleDateFormat sdf = getSimpleDateFormat(); if (letsContinue) { Iterator<ResultSetRow> resultsIterator = results.iterator(); while (resultsIterator.hasNext()) { try { // be tolerant for non-existing // nodes... happens to hurt // leaving status=Running NodeRef result = resultsIterator.next().getNodeRef(); logger.debug("harvest noderef " + result); if (!storeRef.getProtocol().equalsIgnoreCase("archive")) { if (getNodeService().hasAspect(result, ContentModel.ASPECT_VERSIONABLE) // versionService.isVersioned(result) && versionService.getVersionHistory(result).getAllVersions() .size() > 1) { VersionHistory vh = versionService.getVersionHistory(result); Iterator<Version> vhi = vh.getAllVersions().iterator(); String latestVersionLabel = (String) nodeService.getProperty( vh.getHeadVersion().getVersionedNodeRef(), ContentModel.PROP_VERSION_LABEL); // Date latestDate = // (Date)nodeService.getProperty(result, // ContentModel.PROP_MODIFIED); while (vhi.hasNext()) { Version version = vhi.next(); String currentVersionLabel = version.getVersionLabel(); // Date versionDate = // version.getFrozenModifiedDate(); // logger.debug("comparing: // " + // currentVersionLabel + // "/" + // latestVersionLabel // );//+ " and " + // sdf.format(versionDate) // +"/"+ // sdf.format(latestDate)); if (!currentVersionLabel.equals(latestVersionLabel)) { if (logger.isInfoEnabled()) logger.info( "harvest: Adding Version " + currentVersionLabel + " " + version.getFrozenStateNodeRef() + " - " + result.toString()); // version.getVersionedNodeRef()); addToQueue(version.getFrozenStateNodeRef(), result); } else { if (logger.isDebugEnabled()) logger.info("Ignoring version " + currentVersionLabel); } // end ifelse } // end while } // id if // hasAspect(versionable) } // end exclude Archive // all versions should be post-fixed // with their head version workspace // ref if (!result.toString().startsWith("version")) { if (logger.isDebugEnabled()) logger.debug("harvest: " + " adding NodeRef " + result); addToQueue(result); } } catch (Exception e) { // ignore, we need to buffer for // non-existing nodes... logger.info("NodeRef appears broken: " + e.getMessage()); logger.info(" " + e.getStackTrace()); } } // end resultsIterator try { // process the current queue Properties props = processQueueDefinition(tableName); if (logger.isDebugEnabled()) logger.debug("harvest: queueDef done, setting tableDefinition"); setTableDefinition(tableName, props); if (logger.isDebugEnabled()) logger.debug("harvest: tableDef done. Processing queue Values"); processQueueValues(tableName); // prep the queue for the next run resetQueue(); if (results.length() > 0) { // prepare the dbid for the next run startDbId = Long.parseLong(String.valueOf(getNodeService().getProperty( results.getNodeRef(results.length() - 1), ContentModel.PROP_NODE_DBID))); lastModified = (Date) getNodeService().getProperty( results.getNodeRef(results.length() - 1), ContentModel.PROP_MODIFIED); if (logger.isDebugEnabled()) { logger.debug("harvest: StoreProtocol = " + storeRef.getProtocol()); logger.debug("harvest: New start DBID=" + startDbId); logger.debug("harvest: New lastModified=" + lastModified); } } } catch (Exception e) { logger.info("harvest: something wrong with the noderef, skipping"); } if ((results.length() > 0) && getBatchTimestampEnabled() && (lastModified != null)) { if (logger.isDebugEnabled()) logger.debug("Setting Batch-based timestamp: " + getDateAsFormattedString(lastModified)); dbhb.setLastTimestamp(tableName + "_" + storeRef.getProtocol().substring(0, 1), getDateAsFormattedString(lastModified)); hasEverRun = true; } } // end if(letsContinue) if ((!letsContinue) && (results.length() == 0)) { // register lastruntimestamp anyway if (hasEverRun) { dbhb.setAllStatusesDoneForTable(); } else { dbhb.setLastTimestampAndStatusDone( tableName + "_" + storeRef.getProtocol().substring(0, 1), nowFormattedDate); } } letsContinue = stillContinueHarvesting(loopcount, results.length()); } // end while letsContinue } // end storeProtocol if (getBatchTimestampEnabled()) { // dbhb.setLastTimestamp(tableName, // getDateAsFormattedString(lastModified)); if (lastModified != null) { if (logger.isDebugEnabled()) logger.debug("Setting Batch-based status to done"); dbhb.setAllStatusesDoneForTable(); } } else { if (logger.isDebugEnabled()) logger.debug("Setting end-last-run-based timestamp"); dbhb.setLastTimestampAndStatusDone(tableName, nowFormattedDate); } // startDbId=0; } // end if tableIsRunning else { if (logger.isDebugEnabled()) logger.debug("harvest: table is running; leaving..."); } } // end while keys } catch (Exception e) { // e.printStackTrace(); logger.info("Fatality: " + e); } finally { // make sure we gently close the connection dbhb.closeReportingConnection(); } logger.info("harvest run done..."); }
From source file:com.google.enterprise.connector.sharepoint.spiimpl.SharepointConnectorType.java
private void addAliasMap(StringBuffer buf, String key, Map<String, String> configMap) { appendTableForAliasMapping(buf);//from w ww . ja va 2 s .c om if (configMap == null) { appendRowForAliasMapping(buf, SPConstants.BLANK_STRING, SPConstants.BLANK_STRING, false); } else { final String aliasMapString = configMap.get(key); parseAlias(aliasMapString, null); if (aliasMap == null) { appendRowForAliasMapping(buf, SPConstants.BLANK_STRING, SPConstants.BLANK_STRING, false); } else { final Set<String> aliasValues = aliasMap.keySet(); int i = 0; for (final Iterator<String> aliasItr = aliasValues.iterator(); aliasItr.hasNext();) { final String alias_source_pattern = aliasItr.next(); String alias_host_port = ""; final ArrayList<String> aliases = aliasMap.get(alias_source_pattern); if (aliases.size() == 0) { if (i % 2 == 0) { appendRowForAliasMapping(buf, SPConstants.BLANK_STRING, SPConstants.BLANK_STRING, false); } else { appendRowForAliasMapping(buf, SPConstants.BLANK_STRING, SPConstants.BLANK_STRING, true); } ++i; } else { try { for (final Iterator<String> it = aliases.iterator(); it.hasNext();) { alias_host_port = it.next(); if (it.hasNext() || aliasItr.hasNext()) { if (i % 2 == 0) { appendRowForAliasMapping(buf, alias_source_pattern, alias_host_port, false); } else { appendRowForAliasMapping(buf, alias_source_pattern, alias_host_port, true); } } else { if (i % 2 == 0) { appendRowForAliasMapping(buf, alias_source_pattern, alias_host_port, false); } else { appendRowForAliasMapping(buf, alias_source_pattern, alias_host_port, true); } } ++i; } } catch (final Exception e) { final String logMessage = "Could not find the alias value for the pattern [" + alias_source_pattern + "]."; LOGGER.log(Level.WARNING, logMessage, e); } } } } } buf.append(SPConstants.TR_START); buf.append(SPConstants.TD_START_ADDMRE); buf.append(SPConstants.OPEN_ELEMENT); buf.append(SPConstants.INPUT); appendAttribute(buf, SPConstants.TYPE, SPConstants.SUBMIT); appendAttribute(buf, SPConstants.VALUE, rb.getString(SPConstants.ADD_MORE)); appendAttribute(buf, SPConstants.ONCLICK, "addRow(); return false"); buf.append(SPConstants.SLASH + SPConstants.CLOSE_ELEMENT); buf.append(SPConstants.TD_END); buf.append(SPConstants.TR_END); buf.append(SPConstants.END_TABLE); }
From source file:com.aol.framework.helper.report.CustomizedReporter.java
synchronized private void generateModuleWiseTestReport(String testName, List<ISuite> suites, String newFileName, String passedModule, String nodeIp) throws IOException { final PrintWriter pw = TestHelper.createFileWriter(TestHelper.customReportDir + newFileName); startHtmlPage(pw);/*from w ww . jav a2s . c om*/ pw.println("<button class=\"sexybutton sexysimple sexylarge sexyblack\" onClick=\"location.href='" + passedModule + "-Overall-customized-report.html" + "'\"><span class=\"prev\">Back to Modulewise Test Execution Summary</span></button>"); pw.println( "<br/><br/><br/><fieldset><legend><b>Modulewise Execution Details</b></legend><br/><table class=\"details\" cellspacing=0 cellpadding=0><tr><td><b>Test Name: </b></td><td>" + testName + "</td></tr>"); pw.println("<tr><td><b>Node IP: </b></td><td>" + nodeIp + "</td></tr></table></fieldset><br/><br/>"); pw.println("<table id=\"myTable\" width=\"100%\" cellspacing=0 cellpadding=0 class=\"tablesorter\">"); pw.println("<thead><tr><th>Module Name</th><th># Passed</th>" + "<th># Failed</th><th># Warning</th>" + "<th># Skipped</th><th># Total</th><th>Success Rate</th></tr></thead>"); HashMap<String, ArrayList<ITestNGMethod>> moduleMap = new HashMap<String, ArrayList<ITestNGMethod>>(); ITestContext overview = null; for (ISuite suite : suites) { Map<String, ISuiteResult> tests = suite.getResults(); for (ISuiteResult r : tests.values()) { overview = r.getTestContext(); if ((overview.getName()).equalsIgnoreCase(testName)) { ITestNGMethod[] testngMethods = overview.getAllTestMethods(); ArrayList<HashMap<String, ITestNGMethod>> moduleMethods = new ArrayList<HashMap<String, ITestNGMethod>>(); for (ITestNGMethod testngMethod : testngMethods) { String[] groups = testngMethod.getGroups(); for (String group : groups) { for (String module : TestHelper.MODULES) { if (group.equalsIgnoreCase(module)) { HashMap<String, ITestNGMethod> tempMap = new HashMap<String, ITestNGMethod>(); tempMap.put(module, testngMethod); moduleMethods.add(tempMap); } } } } for (String module : TestHelper.MODULES) { ArrayList<ITestNGMethod> moduleTestMethods = new ArrayList<ITestNGMethod>(); Iterator<HashMap<String, ITestNGMethod>> it = moduleMethods.iterator(); while (it.hasNext()) { String moduleName = ""; ITestNGMethod testMethod = null; HashMap<String, ITestNGMethod> moduleWithTestMethod = it.next(); if (moduleWithTestMethod.containsKey(module)) { moduleName = module; testMethod = moduleWithTestMethod.get(module); } if (module.equalsIgnoreCase(moduleName)) { moduleTestMethods.add(testMethod); } } moduleMap.put(module, moduleTestMethods); } } } } Set<String> keySet = moduleMap.keySet(); Iterator<String> it = keySet.iterator(); for (ISuite suite : suites) { Map<String, ISuiteResult> tests = suite.getResults(); for (ISuiteResult r : tests.values()) { overview = r.getTestContext(); if ((overview.getName()).equalsIgnoreCase(testName)) { while (it.hasNext()) { String moduleName = it.next(); int totalPassedMethods = 0; int totalFailedMethods = 0; int totalAutomationErrors = 0; int totalSkippedMethods = 0; int totalSkippedConfigurations = 0; int totalFailedConfigurations = 0; ArrayList<ITestNGMethod> values = moduleMap.get(moduleName); ListIterator<ITestNGMethod> it2 = values.listIterator(); while (it2.hasNext()) { ITestNGMethod method = it2.next(); int failedMethods = overview.getFailedTests().getResults(method).size(); int failedAutomationErrors = overview.getFailedButWithinSuccessPercentageTests() .getResults(method).size(); int passedMethods = overview.getPassedTests().getResults(method).size(); int skippedMethods = overview.getSkippedTests().getResults(method).size(); int failedConfiguration = overview.getFailedConfigurations().getResults(method).size(); int skippedConfiguration = overview.getSkippedConfigurations().getResults(method) .size(); totalPassedMethods += passedMethods; totalFailedMethods += failedMethods; totalAutomationErrors += failedAutomationErrors; totalSkippedMethods += skippedMethods; totalFailedConfigurations += failedConfiguration; totalSkippedConfigurations += skippedConfiguration; } if (values.size() > 0) { String fileName = testName + "-" + moduleName + "-customized-report.html"; try { generateModuleTestMethodSummary(testName, moduleName, suites, fileName, values, nodeIp); } catch (IOException e) { e.printStackTrace(); } int totalMethods = totalPassedMethods + totalFailedMethods + totalAutomationErrors + totalSkippedMethods; NumberFormat nf = NumberFormat.getInstance(); nf.setMaximumFractionDigits(2); nf.setGroupingUsed(false); String passPercentage = getPercentage(nf, totalPassedMethods, totalMethods); generateModulesRow(pw, fileName, moduleName, totalPassedMethods, totalFailedMethods, totalAutomationErrors, totalSkippedMethods, totalSkippedConfigurations, totalFailedConfigurations, totalMethods, passPercentage); } } break; } } } pw.println("</table>"); endHtmlPage(pw); pw.flush(); pw.close(); }
From source file:com.microsoft.tfs.client.eclipse.sync.SynchronizeSubscriber.java
/** * Refresh the given resources for the given RecursionType. * * @param resources//from www . ja v a 2 s . co m * Resources to refresh * @param recursionType * RecursionType to update with * @param monitor * An IProgressMonitor to display status * @return An IStatus containing the refresh status */ private IStatus refresh(final IResource[] resources, final RecursionType recursionType, final IProgressMonitor monitor) { Check.notNull(resources, "resources"); //$NON-NLS-1$ Check.notNull(recursionType, "recursionType"); //$NON-NLS-1$ Check.notNull(monitor, "monitor"); //$NON-NLS-1$ // a collection of changed resources to fire changed events for // (use a hashset since a resource could have multiple changes and we // only want to fire once) final Collection<IResource> changedResources = new HashSet<IResource>(); // any errors final ArrayList<IStatus> errors = new ArrayList<IStatus>(); // one tick for updating the pending changes, // one tick for each resource... monitor.beginTask(Messages.getString("SynchronizeSubscriber.RefreshingTFSResources"), //$NON-NLS-1$ (resources.length + 1)); // refresh the pending changes caches final SubProgressMonitor pcMonitor = new SubProgressMonitor(monitor, 1); refreshPendingChanges(resources, pcMonitor); pcMonitor.done(); // refresh each named resource for (int i = 0; i < resources.length; i++) { if (monitor.isCanceled()) { return Status.CANCEL_STATUS; } // update the progress monitor monitor.subTask(resources[i].getName()); final SubProgressMonitor resourceMonitor = new SubProgressMonitor(monitor, 1); // refresh a single resource final IStatus status = refreshResource(resources[i], recursionType, changedResources, resourceMonitor); if (!status.isOK()) { errors.add(status); } resourceMonitor.done(); } monitor.done(); if (!changedResources.isEmpty()) { fireTeamResourceChange(changedResources); } if (!errors.isEmpty()) { /* * If all resources failed for the same reason, consolidate the * error messages. */ if (errors.size() == resources.length) { int errorCode = -1; for (final Iterator<IStatus> i = errors.iterator(); i.hasNext();) { final IStatus error = i.next(); if ((error.getCode() & PROJECT_REPOSITORY_STATUS_CODE) == 0) { errorCode = -1; break; } final int thisErrorCode = (error.getCode() & (~PROJECT_REPOSITORY_STATUS_CODE)); if (errorCode < 0) { errorCode = thisErrorCode; } else if (thisErrorCode != errorCode) { errorCode = -1; break; } } if (errorCode >= 0) { String message = Messages.getString("SynchronizeSubscriber.ProjectsNotCurrentlyConnectedToTFS"); //$NON-NLS-1$ if (errorCode == ProjectRepositoryStatus.CONNECTING.getValue()) { //@formatter:off message = Messages .getString("SynchronizeSubscriber.ProjectsBeingConnectedToTFSWaitBeforeRefreshing"); //$NON-NLS-1$ //@formatter:on } else if (errorCode == ProjectRepositoryStatus.OFFLINE.getValue()) { //@formatter:off message = Messages.getString( "SynchronizeSubscriber.CurrentlyOfflinePleaseReturnOnlineBeforeRefreshing"); //$NON-NLS-1$ //@formatter:on } else if (errorCode == ProjectRepositoryStatus.INITIALIZING.getValue()) { //@formatter:off message = Messages.getString( "SynchronizeSubscriber.ProjectsNotConnectedToTFSOrHaveBeenPermanentlyDisconnected"); //$NON-NLS-1$ //@formatter:on } return new Status(IStatus.ERROR, TFSEclipseClientPlugin.PLUGIN_ID, errorCode, message, null); } } /* Not all the same errors */ final IStatus[] status = errors.toArray(new IStatus[errors.size()]); return new MultiStatus(TFSEclipseClientPlugin.PLUGIN_ID, TeamException.NO_REMOTE_RESOURCE, status, Messages.getString("SynchronizeSubscriber.SomeResourcesCouldNotBeRefreshed"), //$NON-NLS-1$ null); } return Status.OK_STATUS; }
From source file:com.mysql.stresstool.RunnableClusterQueryInsert.java
public void run() { BufferedReader d = null;/*from w w w . ja va2s .com*/ Connection conn = null; try { if (jdbcUrlMap.get("dbType") != null && !((String) jdbcUrlMap.get("dbType")).equals("MySQL")) { conn = DriverManager.getConnection((String) jdbcUrlMap.get("dbType"), "test", "test"); } else conn = DriverManager.getConnection((String) jdbcUrlMap.get("jdbcUrl")); } catch (SQLException ex) { ex.printStackTrace(); } if (conn != null) { try { Statement stmt = null; // ResultSet rs = null; // ResultSet rs2 = null; conn.setAutoCommit(false); stmt = conn.createStatement(); stmt.execute("SET AUTOCOMMIT=0"); long execTime = 0; int pkStart = 0; int pkEnds = 0; int intDeleteInterval = 0; int intBlobInterval = 0; int intBlobIntervalLimit = StressTool.getNumberFromRandom(4).intValue(); ThreadInfo thInfo; long threadTimeStart = System.currentTimeMillis(); active = true; thInfo = new ThreadInfo(); thInfo.setId(this.ID); thInfo.setType("insert"); thInfo.setStatusActive(this.isActive()); StressTool.setInfo(this.ID, thInfo); boolean lazy = false; int lazyInterval = 0; for (int repeat = 0; repeat <= repeatNumber; repeat++) { String query = null; ArrayList insert1 = null; ArrayList insert2 = null; int pk = 0; if (repeat > 0 && lazyInterval < 500) { lazy = true; ++lazyInterval; } else { lazy = false; lazyInterval = 0; } intBlobInterval++; //IMPLEMENTING lazy Vector v = this.getTablesValues(lazy); insert1 = (ArrayList<String>) v.get(0); insert2 = (ArrayList<String>) v.get(1); // System.out.println(insert1); // System.out.println(insert2); // pk = ((Integer) v.get(2)).intValue(); int[] iLine = { 0, 0 }; // pkStart = StressTool.getNumberFromRandom(2147483647).intValue(); // pkEnds = StressTool.getNumberFromRandom(2147483647).intValue(); try { long timeStart = System.currentTimeMillis(); if (this.ignoreBinlog) stmt.execute("SET sql_log_bin=0"); // stmt.execute("SET GLOBAL max_allowed_packet=1073741824"); if (dbType.equals("MySQL") && !engine.toUpperCase().equals("BRIGHTHOUSE")) stmt.execute("BEGIN"); else stmt.execute("COMMIT"); // stmt.execute("SET TRANSACTION NAME 'TEST'"); { Iterator<String> it = insert1.iterator(); while (it.hasNext()) { stmt.addBatch(it.next()); } } if (!this.doSimplePk) { if (intBlobInterval > intBlobIntervalLimit) { Iterator<String> it = insert2.iterator(); while (it.hasNext()) { stmt.addBatch(it.next()); } intBlobInterval = 0; } } iLine = stmt.executeBatch(); stmt.clearBatch(); // System.out.println("Query1 = " + insert1); // System.out.println("Query2 = " + insert2); // stmt.execute("START TRANSACTION"); // stmt.execute(insert1); // iLine = stmt.executeBatch(); // conn.commit(); long timeEnds = System.currentTimeMillis(); execTime = (timeEnds - timeStart); } catch (Exception sqle) { conn.rollback(); System.out.println("FAILED QUERY1==" + insert1); System.out.println("FAILED QUERY2==" + insert2); sqle.printStackTrace(); System.exit(1); //conn.close(); //this.setJdbcUrl(jdbcUrl); //System.out.println("Query Insert TH RE-INIZIALIZING"); } finally { // conn.commit(); stmt.execute("COMMIT"); // intDeleteInterval++; if (doLog) { System.out.println("Query Insert TH = " + this.getID() + " Loop N = " + repeat + " " + iLine[0] + "|" + ((iLine.length > 1) ? iLine[1] : 0) + " Exec Time(ms) =" + execTime + " Running = " + repeat + " of " + repeatNumber + " to go =" + (repeatNumber - repeat) + " Using Lazy=" + lazy); } } thInfo.setExecutedLoops(repeat); if (sleepFor > 0 || this.getSleepWrite() > 0) { if (this.getSleepWrite() > 0) { Thread.sleep(getSleepWrite()); } else Thread.sleep(sleepFor); } } long threadTimeEnd = System.currentTimeMillis(); this.executionTime = (threadTimeEnd - threadTimeStart); // this.setExecutionTime(executionTime); active = false; // System.out.println("Query Insert TH = " + this.getID() + " COMPLETED! TOTAL TIME = " + execTime + "(ms) Sec =" + (execTime/1000)); thInfo.setExecutionTime(executionTime); thInfo.setStatusActive(false); StressTool.setInfo(this.ID, thInfo); return; } catch (Exception ex) { ex.printStackTrace(); try { conn.close(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } }
From source file:com.mysql.stresstool.RunnableSC2013QueryInsert.java
public void run() { BufferedReader d = null;/*from w ww . j a v a2s .c om*/ Connection conn = null; try { if (jdbcUrlMap.get("dbType") != null && !((String) jdbcUrlMap.get("dbType")).equals("MySQL")) { conn = DriverManager.getConnection((String) jdbcUrlMap.get("dbType"), "test", "test"); } else conn = DriverManager.getConnection((String) jdbcUrlMap.get("jdbcUrl")); } catch (SQLException ex) { ex.printStackTrace(); } if (conn != null) { try { Statement stmt = null; // ResultSet rs = null; // ResultSet rs2 = null; conn.setAutoCommit(false); stmt = conn.createStatement(); stmt.execute("SET AUTOCOMMIT=0"); long execTime = 0; int pkStart = 0; int pkEnds = 0; int intDeleteInterval = 0; int intBlobInterval = 0; int intBlobIntervalLimit = StressTool.getNumberFromRandom(4).intValue(); ThreadInfo thInfo; long threadTimeStart = System.currentTimeMillis(); active = true; thInfo = new ThreadInfo(); thInfo.setId(this.ID); thInfo.setType("insert"); thInfo.setStatusActive(this.isActive()); StressTool.setInfo(this.ID, thInfo); boolean lazy = false; int lazyInterval = 0; for (int repeat = 0; repeat <= repeatNumber; repeat++) { String query = null; ArrayList insert1 = null; ArrayList insert2 = null; int pk = 0; if (repeat > 0 && lazyInterval < 100) { lazy = true; ++lazyInterval; } else { lazy = false; lazyInterval = 0; } intBlobInterval++; //IMPLEMENTING lazy Vector v = this.getTablesValues(lazy); insert1 = (ArrayList<String>) v.get(0); insert2 = (ArrayList<String>) v.get(1); // System.out.println(insert1); // System.out.println(insert2); // pk = ((Integer) v.get(2)).intValue(); int[] iLine = { 0, 0 }; // pkStart = StressTool.getNumberFromRandom(2147483647).intValue(); // pkEnds = StressTool.getNumberFromRandom(2147483647).intValue(); try { long timeStart = System.currentTimeMillis(); if (this.ignoreBinlog) stmt.execute("SET sql_log_bin=0"); // stmt.execute("SET GLOBAL max_allowed_packet=1073741824"); if (dbType.equals("MySQL") && !engine.toUpperCase().equals("BRIGHTHOUSE")) stmt.execute("BEGIN"); else stmt.execute("COMMIT"); // stmt.execute("SET TRANSACTION NAME 'TEST'"); { Iterator<String> it = insert1.iterator(); while (it.hasNext()) { stmt.addBatch(it.next()); } } if (!this.doSimplePk) { if (intBlobInterval > intBlobIntervalLimit) { Iterator<String> it = insert2.iterator(); while (it.hasNext()) { stmt.addBatch(it.next()); } intBlobInterval = 0; } } iLine = stmt.executeBatch(); stmt.clearBatch(); // System.out.println("Query1 = " + insert1); // System.out.println("Query2 = " + insert2); // stmt.execute("START TRANSACTION"); // stmt.execute(insert1); // iLine = stmt.executeBatch(); // conn.commit(); long timeEnds = System.currentTimeMillis(); execTime = (timeEnds - timeStart); } catch (Exception sqle) { conn.rollback(); System.out.println("FAILED QUERY1==" + insert1); System.out.println("FAILED QUERY2==" + insert2); sqle.printStackTrace(); System.exit(1); //conn.close(); //this.setJdbcUrl(jdbcUrl); //System.out.println("Query Insert TH RE-INIZIALIZING"); } finally { // conn.commit(); stmt.execute("COMMIT"); // intDeleteInterval++; if (doLog) { System.out.println("Query Insert TH = " + this.getID() + " Loop N = " + repeat + " " + iLine[0] + "|" + ((iLine.length > 1) ? iLine[1] : 0) + " Exec Time(ms) =" + execTime + " Running = " + repeat + " of " + repeatNumber + " to go =" + (repeatNumber - repeat) + " Using Lazy=" + lazy); } } thInfo.setExecutedLoops(repeat); if (sleepFor > 0 || this.getSleepWrite() > 0) { if (this.getSleepWrite() > 0) { Thread.sleep(getSleepWrite()); } else Thread.sleep(sleepFor); } } long threadTimeEnd = System.currentTimeMillis(); this.executionTime = (threadTimeEnd - threadTimeStart); // this.setExecutionTime(executionTime); active = false; // System.out.println("Query Insert TH = " + this.getID() + " COMPLETED! TOTAL TIME = " + execTime + "(ms) Sec =" + (execTime/1000)); thInfo.setExecutionTime(executionTime); thInfo.setStatusActive(false); StressTool.setInfo(this.ID, thInfo); return; } catch (Exception ex) { ex.printStackTrace(); try { conn.close(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } }
From source file:com.mysql.stresstool.RunnableQueryInsert.java
public void run() { BufferedReader d = null;// w w w .j a v a2 s . com Connection conn = null; try { if (jdbcUrlMap.get("dbType") != null && !((String) jdbcUrlMap.get("dbType")).equals("MySQL")) { conn = DriverManager.getConnection((String) jdbcUrlMap.get("dbType"), "test", "test"); } else conn = DriverManager.getConnection((String) jdbcUrlMap.get("jdbcUrl")); } catch (SQLException ex) { ex.printStackTrace(); } if (conn != null) { try { Statement stmt = null; // ResultSet rs = null; // ResultSet rs2 = null; conn.setAutoCommit(false); stmt = conn.createStatement(); stmt.execute("SET AUTOCOMMIT=0"); long execTime = 0; int pkStart = 0; int pkEnds = 0; int intDeleteInterval = 0; int intBlobInterval = 0; int intBlobIntervalLimit = StressTool.getNumberFromRandom(4).intValue(); ThreadInfo thInfo; long threadTimeStart = System.currentTimeMillis(); active = true; thInfo = new ThreadInfo(); thInfo.setId(this.ID); thInfo.setType("insert"); thInfo.setStatusActive(this.isActive()); StressTool.setInfo(this.ID, thInfo); boolean lazy = false; int lazyInterval = 0; for (int repeat = 0; repeat <= repeatNumber; repeat++) { String query = null; ArrayList insert1 = null; ArrayList insert2 = null; int pk = 0; if (repeat > 0 && lazyInterval < 500) { lazy = true; ++lazyInterval; } else { lazy = false; lazyInterval = 0; } intBlobInterval++; //IMPLEMENTING lazy Vector v = this.getTablesValues(lazy); insert1 = (ArrayList<String>) v.get(0); insert2 = (ArrayList<String>) v.get(1); // System.out.println(insert1); // System.out.println(insert2); // pk = ((Integer) v.get(2)).intValue(); int[] iLine = { 0, 0 }; // pkStart = StressTool.getNumberFromRandom(2147483647).intValue(); // pkEnds = StressTool.getNumberFromRandom(2147483647).intValue(); try { long timeStart = System.currentTimeMillis(); if (this.ignoreBinlog) stmt.execute("SET sql_log_bin=0"); stmt.execute("SET GLOBAL max_allowed_packet=1073741824"); if (dbType.equals("MySQL") && !engine.toUpperCase().equals("BRIGHTHOUSE")) stmt.execute("BEGIN"); else stmt.execute("COMMIT"); // stmt.execute("SET TRANSACTION NAME 'TEST'"); { Iterator<String> it = insert1.iterator(); while (it.hasNext()) { stmt.addBatch(it.next()); } } if (!this.doSimplePk) { if (intBlobInterval > intBlobIntervalLimit) { Iterator<String> it = insert2.iterator(); while (it.hasNext()) { stmt.addBatch(it.next()); } intBlobInterval = 0; } } iLine = stmt.executeBatch(); stmt.clearBatch(); // System.out.println("Query1 = " + insert1); // System.out.println("Query2 = " + insert2); // stmt.execute("START TRANSACTION"); // stmt.execute(insert1); // iLine = stmt.executeBatch(); // conn.commit(); long timeEnds = System.currentTimeMillis(); execTime = (timeEnds - timeStart); } catch (Exception sqle) { conn.rollback(); System.out.println("FAILED QUERY1==" + insert1); System.out.println("FAILED QUERY2==" + insert2); sqle.printStackTrace(); System.exit(1); //conn.close(); //this.setJdbcUrl(jdbcUrl); //System.out.println("Query Insert TH RE-INIZIALIZING"); } finally { // conn.commit(); stmt.execute("COMMIT"); // intDeleteInterval++; if (doLog) { System.out.println("Query Insert TH = " + this.getID() + " Loop N = " + repeat + " " + iLine[0] + "|" + ((iLine.length > 1) ? iLine[1] : 0) + " Exec Time(ms) =" + execTime + " Running = " + repeat + " of " + repeatNumber + " to go =" + (repeatNumber - repeat) + " Using Lazy=" + lazy); } } thInfo.setExecutedLoops(repeat); if (sleepFor > 0 || this.getSleepWrite() > 0) { if (this.getSleepWrite() > 0) { Thread.sleep(getSleepWrite()); } else Thread.sleep(sleepFor); } } long threadTimeEnd = System.currentTimeMillis(); this.executionTime = (threadTimeEnd - threadTimeStart); // this.setExecutionTime(executionTime); active = false; // System.out.println("Query Insert TH = " + this.getID() + " COMPLETED! TOTAL TIME = " + execTime + "(ms) Sec =" + (execTime/1000)); thInfo.setExecutionTime(executionTime); thInfo.setStatusActive(false); StressTool.setInfo(this.ID, thInfo); return; } catch (Exception ex) { ex.printStackTrace(); try { conn.close(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } }
From source file:com.clustercontrol.repository.factory.FacilitySelector.java
/** * ???IPv4?????ID???<BR>// w w w. ja v a2 s . c o m * * @param hostname ?? * @param ipAddressV4 IPv4 * @return ID?? */ public static ArrayList<String> getFacilityIdList(String hostname, String ipAddress) { m_log.debug("getFacilityIdList() start : hostname = " + hostname + ", ipAddress = " + ipAddress); /** */ String key = hostname + "-," + ipAddress; try { _hostnameIpaddrFacilityIdCacheLock.readLock(); HashMap<String, ArrayList<String>> cache = getHostnameIpaddrFacilityIdCache(); ArrayList<String> facilityIds = cache.get(key); if (facilityIds != null) { return facilityIds; } } finally { _hostnameIpaddrFacilityIdCacheLock.readUnlock(); } ArrayList<String> facilityIds = new ArrayList<String>(); if (ipAddress == null || "".equals(ipAddress) || hostname == null || "".equals(hostname)) { return facilityIds; } /** ? */ try { _hostnameIpaddrFacilityIdCacheLock.writeLock(); new JpaTransactionManager().getEntityManager().clear(); // hostname?Node?nodename()LowerCase? List<NodeInfo> nodes = QueryUtil.getNodeByNodename(hostname); if (nodes != null) { for (NodeInfo node : nodes) { m_log.debug("getFacilityIdList() List " + " FacilityId = " + node.getFacilityId() + " NodeName = " + node.getNodeName() + " IpAddressV4 = " + node.getIpAddressV4() + " IpAddressV6 = " + node.getIpAddressV6()); // IPv6?? if (node.getIpAddressVersion() == 6) { if (Ipv6Util.expand(ipAddress).equals(Ipv6Util.expand(node.getIpAddressV6()))) { m_log.debug("getFacilityIdList() hit facilityId = " + node.getFacilityId()); facilityIds.add(node.getFacilityId()); } } else { if (ipAddress.equals(node.getIpAddressV4())) { m_log.debug("getFacilityIdList() hit facilityId = " + node.getFacilityId()); facilityIds.add(node.getFacilityId()); } } } } // Debug????????IP?? if (m_log.isDebugEnabled()) { for (Iterator<String> iter = facilityIds.iterator(); iter.hasNext();) { String facilityId = iter.next(); m_log.debug("getFacilityIdList() hostname = " + hostname + ", ipAddress = " + ipAddress + " has " + facilityId); } } HashMap<String, ArrayList<String>> cache = getHostnameIpaddrFacilityIdCache(); cache.put(key, facilityIds); storeHostnameIpaddrFacilityIdCache(cache); } finally { _hostnameIpaddrFacilityIdCacheLock.writeUnlock(); } return facilityIds; }
From source file:edu.harvard.lib.lcloud.ItemDAO.java
/** * Returns a SolrDocumentList for a given set of search parameters. Search parameters are parsed * and mapped into solr (solrj) query syntax, and solr query is performed. * @param queryParams query parameters to map to a solr query * @return the SolrDocumentList for this query * @see SolrDocumentList/*from ww w . j a v a 2 s . co m*/ */ private SolrDocumentList doQuery(MultivaluedMap<String, String> queryParams) { SolrDocumentList docs = null; HttpSolrServer server = null; String queryStr = ""; SolrQuery query = new SolrQuery(); System.out.println("queryParams: " + queryParams.size()); ArrayList<String> queryList = new ArrayList<String>(); server = SolrServer.getSolrConnection(); if (queryParams.size() > 0) { for (String key : queryParams.keySet()) { String value = queryParams.getFirst(key); System.out.println(key + " : " + queryParams.getFirst(key) + "\n"); if (key.equals("start")) { int startNo = Integer.parseInt(value); if (startNo < 0) startNo = 0; query.setStart(startNo); } else if (key.equals("limit")) { limit = Integer.parseInt(value); if (limit > 250) { limit = 250; } query.setRows(limit); } else if (key.equals("sort.asc") || key.equals("sort")) query.setSort(value, ORDER.asc); else if (key.equals("sort.desc")) query.setSort(value, ORDER.desc); else if (key.startsWith("facet")) { query.setFacet(true); String[] facetArray = value.split(","); for (String f : facetArray) { query.addFacetField(f); } } else { if (key.endsWith("_exact")) queryList.add(key.replace("_exact", "") + ":\"" + value + "\""); else { value = value.trim(); if (value.contains(" OR ")) value = "(" + value.replaceAll(" OR ", "+OR+") + ")"; if (value.contains(" ")) value = "( " + value.replaceAll(" ", " AND ") + ")"; if (value.contains(":")) value = "\"" + value + "\""; if (key.equals("q")) { if (!value.equals("*")) { queryList.add("keyword:" + value); } } else if (!key.equals("callback")) queryList.add(key + "_keyword:" + value); } } } Iterator<String> it = queryList.iterator(); while (it.hasNext()) { String qTerm = (String) it.next(); System.out.print("QT: " + qTerm + "\n"); queryStr += qTerm; System.out.print("QS: " + queryStr + "\n"); if (it.hasNext()) queryStr += " AND "; } if (queryList.size() == 0) queryStr = "*:*"; } else { queryStr = "*:*"; } System.out.print("queryStr: " + queryStr); query.setQuery(queryStr); QueryResponse response = null; try { response = server.query(query); } catch (SolrServerException se) { log.error(se.getMessage()); throw new BadParameterException(se.getMessage()); } catch (RemoteSolrException rse) { if (rse.getMessage().contains("SyntaxError")) { log.error("solr syntax error"); throw new BadParameterException("Incorrect query syntax"); } else { String msg = rse.getMessage().replace("_keyword", ""); log.error(msg); throw new BadParameterException("Incorrect query syntax:" + msg); } } List<FacetField> facets = response.getFacetFields(); facet = null; if (facets != null) { facet = new Facet(); List<FacetType> facetTypes = new ArrayList<FacetType>(); for (FacetField facetField : facets) { List<FacetTerm> facetTerms = new ArrayList<FacetTerm>(); FacetType facetType = new FacetType(); facetType.setFacetName(facetField.getName()); List<FacetField.Count> facetEntries = facetField.getValues(); for (FacetField.Count fcount : facetEntries) { if (fcount.getCount() > 0) { FacetTerm facetTerm = new FacetTerm(); facetTerm.setTermName(fcount.getName()); facetTerm.setTermCount(fcount.getCount()); //System.out.println(fcount.getName() + ": " + fcount.getCount()); facetTerms.add(facetTerm); } } facetType.setFacetTerms(facetTerms); facetTypes.add(facetType); } facet.setFacetTypes(facetTypes); } docs = response.getResults(); return docs; }