// GHH 20080326 - set all batches as last batch after an exception // is thrown calling a method on the enumeration. Per Javadoc for // javax.naming.NamingEnumeration, enumeration is invalid after an // exception is thrown - by setting last batch indicator we prevent // it from being used again. // GHH 20080326 - also added return of explanation for generic // NamingException public List<?> next() throws TranslatorException { try { if (unwrapIterator != null) { if (unwrapIterator.hasNext()) { return unwrapIterator.next(); } unwrapIterator = null; } // The search has been executed, so process up to one batch of // results. List<?> result = null; while (result == null && searchEnumeration != null && searchEnumeration.hasMore()) { SearchResult searchResult = (SearchResult) searchEnumeration.next(); try { result = getRow(searchResult); } catch (InvalidNameException e) { } } if (result == null && this.executionFactory.usePagination()) { byte[] cookie = null; Control[] controls = ldapCtx.getResponseControls(); if (controls != null) { for (int i = 0; i < controls.length; i++) { if (controls[i] instanceof PagedResultsResponseControl) { PagedResultsResponseControl prrc = (PagedResultsResponseControl) controls[i]; cookie = prrc.getCookie(); } } } if (cookie == null) { return null; } setRequestControls(cookie); executeSearch(); return next(); } if (result != null) { resultCount++; } return result; } catch (SizeLimitExceededException e) { if (resultCount != searchDetails.getCountLimit()) { String msg = LDAPPlugin.Util.gs(LDAPPlugin.Event.TEIID12008); TranslatorException te = new TranslatorException(e, msg); if (executionFactory.isExceptionOnSizeLimitExceeded()) { throw te; } this.executionContext.addWarning(te); LogManager.logWarning(LogConstants.CTX_CONNECTOR, e, msg); } return null; // GHH 20080326 - if size limit exceeded don't try to read more results } catch (NamingException ne) { throw new TranslatorException(ne, LDAPPlugin.Util.gs("ldap_error")); // $NON-NLS-1$ } }
/** * Helper method for testing the provided LDAPSearchDetails against expected values * * @param searchDetails the LDAPSearchDetails object * @param expectedContextName the expected context name * @param expectedContextFilter the expected context filter string * @param expectedAttrNameList list of expected attribute names * @param expectedCountLimit the expected count limit * @param expectedSearchScope the expected search scope * @param expectedSortKeys the expected sortKeys list. */ public void helpTestSearchDetails( final LDAPSearchDetails searchDetails, final String expectedContextName, final String expectedContextFilter, final List<String> expectedAttrNameList, final long expectedCountLimit, final int expectedSearchScope, final SortKey[] expectedSortKeys) { // Get all of the actual values String contextName = searchDetails.getContextName(); String contextFilter = searchDetails.getContextFilter(); List<Column> attrList = searchDetails.getElementList(); long countLimit = searchDetails.getCountLimit(); int searchScope = searchDetails.getSearchScope(); SortKey[] sortKeys = searchDetails.getSortKeys(); // Compare actual with Expected assertEquals(expectedContextName, contextName); assertEquals(expectedContextFilter, contextFilter); assertEquals(attrList.size(), expectedAttrNameList.size()); Iterator<Column> iter = attrList.iterator(); Iterator<String> eIter = expectedAttrNameList.iterator(); while (iter.hasNext() && eIter.hasNext()) { String actualName = iter.next().getSourceName(); String expectedName = eIter.next(); assertEquals(actualName, expectedName); } assertEquals(expectedCountLimit, countLimit); assertEquals(expectedSearchScope, searchScope); assertArrayEquals(expectedSortKeys, sortKeys); }