Java Code Examples for org.apache.directory.api.ldap.model.message.SearchRequest#getSizeLimit()
The following examples show how to use
org.apache.directory.api.ldap.model.message.SearchRequest#getSizeLimit() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LdapConnectionTemplate.java From directory-ldap-api with Apache License 2.0 | 6 votes |
/** * {@inheritDoc} */ @Override public <T> T searchFirst( SearchRequest searchRequest, EntryMapper<T> entryMapper ) { // in case the caller did not set size limit, we cache original value, // set to 1, then set back to original value before returning... long originalSizeLimit = searchRequest.getSizeLimit(); try { searchRequest.setSizeLimit( 1 ); List<T> entries = search( searchRequest, entryMapper ); return entries.isEmpty() ? null : entries.get( 0 ); } finally { searchRequest.setSizeLimit( originalSizeLimit ); } }
Example 2
Source File: SearchRequestHandler.java From MyVirtualDirectory with Apache License 2.0 | 6 votes |
/** * Return the server size limit */ private long getServerSizeLimit( LdapSession session, SearchRequest request ) { if ( session.getCoreSession().isAnAdministrator() ) { if ( request.getSizeLimit() == NO_SIZE_LIMIT ) { return Long.MAX_VALUE; } else { return request.getSizeLimit(); } } else { if ( ldapServer.getMaxSizeLimit() == NO_SIZE_LIMIT ) { return Long.MAX_VALUE; } else { return ldapServer.getMaxSizeLimit(); } } }
Example 3
Source File: SearchRequestHandler.java From MyVirtualDirectory with Apache License 2.0 | 6 votes |
/** * Return the server size limit */ private long getServerSizeLimit( LdapSession session, SearchRequest request ) { if ( session.getCoreSession().isAnAdministrator() ) { if ( request.getSizeLimit() == NO_SIZE_LIMIT ) { return Long.MAX_VALUE; } else { return request.getSizeLimit(); } } else { if ( ldapServer.getMaxSizeLimit() == NO_SIZE_LIMIT ) { return Long.MAX_VALUE; } else { return ldapServer.getMaxSizeLimit(); } } }
Example 4
Source File: SearchRequestDsml.java From directory-ldap-api with Apache License 2.0 | 4 votes |
/** * {@inheritDoc} */ @Override public Element toDsml( Element root ) { Element element = super.toDsml( root ); SearchRequest request = getDecorated(); // Dn if ( request.getBase() != null ) { element.addAttribute( "dn", request.getBase().getName() ); } // Scope SearchScope scope = request.getScope(); if ( scope != null ) { if ( scope == SearchScope.OBJECT ) { element.addAttribute( "scope", "baseObject" ); } else if ( scope == SearchScope.ONELEVEL ) { element.addAttribute( "scope", "singleLevel" ); } else if ( scope == SearchScope.SUBTREE ) { element.addAttribute( "scope", "wholeSubtree" ); } } // DerefAliases AliasDerefMode derefAliases = request.getDerefAliases(); switch ( derefAliases ) { case NEVER_DEREF_ALIASES: element.addAttribute( DEREF_ALIASES, "neverDerefAliases" ); break; case DEREF_ALWAYS: element.addAttribute( DEREF_ALIASES, "derefAlways" ); break; case DEREF_FINDING_BASE_OBJ: element.addAttribute( DEREF_ALIASES, "derefFindingBaseObj" ); break; case DEREF_IN_SEARCHING: element.addAttribute( DEREF_ALIASES, "derefInSearching" ); break; default: throw new IllegalStateException( I18n.err( I18n.ERR_03043_UNEXPECTED_DEREF_ALIAS, derefAliases ) ); } // SizeLimit if ( request.getSizeLimit() != 0L ) { element.addAttribute( "sizeLimit", Long.toString( request.getSizeLimit() ) ); } // TimeLimit if ( request.getTimeLimit() != 0 ) { element.addAttribute( "timeLimit", Integer.toString( request.getTimeLimit() ) ); } // TypesOnly if ( request.getTypesOnly() ) { element.addAttribute( "typesOnly", "true" ); } // Filter Element filterElement = element.addElement( "filter" ); toDsml( filterElement, request.getFilter() ); // Attributes List<String> attributes = request.getAttributes(); if ( !attributes.isEmpty() ) { Element attributesElement = element.addElement( "attributes" ); for ( String entryAttribute : attributes ) { attributesElement.addElement( "attribute" ).addAttribute( NAME, entryAttribute ); } } return element; }
Example 5
Source File: SearchRequestHandler.java From MyVirtualDirectory with Apache License 2.0 | 4 votes |
/** * Conducts a simple search across the result set returning each entry * back except for the search response done. This is calculated but not * returned so the persistent search mechanism can leverage this method * along with standard search.<br> * <br> * @param session the LDAP session object for this request * @param req the search request * @return the result done * @throws Exception if there are failures while processing the request */ private SearchResultDone doSimpleSearch( LdapSession session, SearchRequest req ) throws Exception { LdapResult ldapResult = req.getResultResponse().getLdapResult(); // Check if we are using the Paged Search Control Object control = req.getControls().get( PagedResults.OID ); if ( control != null ) { // Let's deal with the pagedControl return doPagedSearch( session, req, ( PagedResultsDecorator ) control ); } // A normal search // Check that we have a cursor or not. // No cursor : do a search. EntryFilteringCursor cursor = session.getCoreSession().search( req ); // register the request in the session session.registerSearchRequest( req, cursor ); // Position the cursor at the beginning cursor.beforeFirst(); /* * Iterate through all search results building and sending back responses * for each search result returned. */ try { // Get the size limits // Don't bother setting size limits for administrators that don't ask for it long serverLimit = getServerSizeLimit( session, req ); long requestLimit = req.getSizeLimit() == 0L ? Long.MAX_VALUE : req.getSizeLimit(); req.addAbandonListener( new SearchAbandonListener( ldapServer, cursor ) ); setTimeLimitsOnCursor( req, session, cursor ); if ( IS_DEBUG ) { LOG.debug( "using <{},{}> for size limit", requestLimit, serverLimit ); } long sizeLimit = min( requestLimit, serverLimit ); writeResults( session, req, ldapResult, cursor, sizeLimit ); } finally { if ( ( cursor != null ) && !cursor.isClosed() ) { try { cursor.close(); } catch ( Exception e ) { LOG.error( I18n.err( I18n.ERR_168 ), e ); } } } return req.getResultResponse(); }