/** * Checks whether any duplicate results (with respect to a key template) were * received. * * @param template the template key. * @throws Exception if duplicate results are detected */ protected void checkForDuplicateKeys(Object[] template) throws Exception { Hashtable<Object, Object> hash = new Hashtable<Object, Object>(); int numMatches = 0; for (int i = 0; i < m_Keys.size(); i++) { Object[] current = m_Keys.get(i); // Skip non-matching keys if (!matchesTemplate(template, current)) { continue; } if (hash.containsKey(current[m_KeyIndex])) { throw new Exception("Duplicate result received:" + DatabaseUtils.arrayToString(current)); } numMatches++; hash.put(current[m_KeyIndex], current[m_KeyIndex]); } if (numMatches != m_ExpectedResultsPerAverage) { throw new Exception("Expected " + m_ExpectedResultsPerAverage + " results matching key \"" + DatabaseUtils.arrayToString(template) + "\" but got " + numMatches); } }
/** * Checks whether any duplicate results (with respect to a key template) were * received. * * @param template the template key. * @throws Exception if duplicate results are detected */ protected void checkForDuplicateKeys(Object[] template) throws Exception { Hashtable<Object, Object> hash = new Hashtable<Object, Object>(); int numMatches = 0; for (int i = 0; i < m_Keys.size(); i++) { Object[] current = m_Keys.get(i); // Skip non-matching keys if (!matchesTemplate(template, current)) { continue; } if (hash.containsKey(current[m_KeyIndex])) { throw new Exception("Duplicate result received:" + DatabaseUtils.arrayToString(current)); } numMatches++; hash.put(current[m_KeyIndex], current[m_KeyIndex]); } if (numMatches != m_ExpectedResultsPerAverage) { throw new Exception("Expected " + m_ExpectedResultsPerAverage + " results matching key \"" + DatabaseUtils.arrayToString(template) + "\" but got " + numMatches); } }
/** * Determines whether the results for a specified key must be generated. * * @param rp the ResultProducer wanting to generate the results * @param key an array of Objects (Strings or Doubles) that uniquely identify * a result for a given ResultProducer with given compatibilityState * @return true if the result should be generated * @throws Exception if it could not be determined if the result is needed. */ @Override public boolean isResultRequired(ResultProducer rp, Object[] key) throws Exception { if (m_ResultProducer != rp) { throw new Error("Unrecognized ResultProducer sending results!!"); } // System.err.println("DBRP::isResultRequired"); // Is the result needed by the listener? boolean isRequiredByListener = m_ResultListener.isResultRequired(this, key); // Is the result already in the database? boolean isRequiredByDatabase = super.isResultRequired(rp, key); if (!isRequiredByDatabase && isRequiredByListener) { // Pass the result through to the listener Object[] result = getResultFromTable(m_ResultsTableName, rp, key); System.err.println("Got result from database: " + DatabaseUtils.arrayToString(result)); m_ResultListener.acceptResult(this, key, result); return false; } return (isRequiredByListener || isRequiredByDatabase); }
/** * Determines whether the results for a specified key must be generated. * * @param rp the ResultProducer wanting to generate the results * @param key an array of Objects (Strings or Doubles) that uniquely identify * a result for a given ResultProducer with given compatibilityState * @return true if the result should be generated * @throws Exception if it could not be determined if the result is needed. */ @Override public boolean isResultRequired(ResultProducer rp, Object[] key) throws Exception { if (m_ResultProducer != rp) { throw new Error("Unrecognized ResultProducer sending results!!"); } // System.err.println("DBRP::isResultRequired"); // Is the result needed by the listener? boolean isRequiredByListener = m_ResultListener.isResultRequired(this, key); // Is the result already in the database? boolean isRequiredByDatabase = super.isResultRequired(rp, key); if (!isRequiredByDatabase && isRequiredByListener) { // Pass the result through to the listener Object[] result = getResultFromTable(m_ResultsTableName, rp, key); System.err.println("Got result from database: " + DatabaseUtils.arrayToString(result)); m_ResultListener.acceptResult(this, key, result); return false; } return (isRequiredByListener || isRequiredByDatabase); }
+ " results matching key \"" + DatabaseUtils.arrayToString(template) + "\" but got " + numMatches);
+ " results matching key \"" + DatabaseUtils.arrayToString(template) + "\" but got " + numMatches);