001/* 002 * Copyright 2009-2020 Ping Identity Corporation 003 * All Rights Reserved. 004 */ 005/* 006 * Copyright 2009-2020 Ping Identity Corporation 007 * 008 * Licensed under the Apache License, Version 2.0 (the "License"); 009 * you may not use this file except in compliance with the License. 010 * You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, software 015 * distributed under the License is distributed on an "AS IS" BASIS, 016 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 017 * See the License for the specific language governing permissions and 018 * limitations under the License. 019 */ 020/* 021 * Copyright (C) 2009-2020 Ping Identity Corporation 022 * 023 * This program is free software; you can redistribute it and/or modify 024 * it under the terms of the GNU General Public License (GPLv2 only) 025 * or the terms of the GNU Lesser General Public License (LGPLv2.1 only) 026 * as published by the Free Software Foundation. 027 * 028 * This program is distributed in the hope that it will be useful, 029 * but WITHOUT ANY WARRANTY; without even the implied warranty of 030 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 031 * GNU General Public License for more details. 032 * 033 * You should have received a copy of the GNU General Public License 034 * along with this program; if not, see <http://www.gnu.org/licenses>. 035 */ 036package com.unboundid.ldap.sdk.migrate.ldapjdk; 037 038 039 040import com.unboundid.util.Mutable; 041import com.unboundid.util.NotExtensible; 042import com.unboundid.util.ThreadSafety; 043import com.unboundid.util.ThreadSafetyLevel; 044 045 046 047/** 048 * This class provides a data structure which may be used to define a set of 049 * constraints that may be used when processing search operations. 050 * <BR><BR> 051 * This class is primarily intended to be used in the process of updating 052 * applications which use the Netscape Directory SDK for Java to switch to or 053 * coexist with the UnboundID LDAP SDK for Java. For applications not written 054 * using the Netscape Directory SDK for Java, the 055 * {@link com.unboundid.ldap.sdk.LDAPConnectionOptions} class should be used 056 * instead. 057 */ 058@NotExtensible() 059@Mutable() 060@ThreadSafety(level=ThreadSafetyLevel.NOT_THREADSAFE) 061public class LDAPSearchConstraints 062 extends LDAPConstraints 063{ 064 /** 065 * The serial version UID for this serializable class. 066 */ 067 private static final long serialVersionUID = -487551577157782460L; 068 069 070 071 // The result batch size. 072 private int batchSize; 073 074 // The alias dereferencing policy. 075 private int derefPolicy; 076 077 // The maximum number of results to return for a search. 078 private int sizeLimit; 079 080 // The maximum length of time in seconds the server should spend processing a 081 // search. 082 private int timeLimit; 083 084 085 086 /** 087 * Creates a new set of search constraints with the default settings. 088 */ 089 public LDAPSearchConstraints() 090 { 091 super(); 092 093 batchSize = 1; 094 derefPolicy = LDAPConnection.DEREF_NEVER; 095 sizeLimit = 1000; 096 timeLimit = 0; 097 } 098 099 100 101 /** 102 * Creates a new set of search constraints with the specified information. 103 * 104 * @param msLimit The maximum length of time in milliseconds to spend 105 * waiting for the response. 106 * @param dereference The policy to use when dereferencing aliases. 107 * @param maxResults The maximum number of entries to return from the 108 * server. 109 * @param doReferrals Indicates whether to follow referrals. 110 * @param batchSize The batch size to use when retrieving results. 111 * @param rebindProc The object to use to obtain information for 112 * authenticating the connection for use when following 113 * referrals. 114 * @param hopLimit The maximum number of hops to take when following 115 * referrals. 116 */ 117 public LDAPSearchConstraints(final int msLimit, final int dereference, 118 final int maxResults, final boolean doReferrals, 119 final int batchSize, final LDAPRebind rebindProc, 120 final int hopLimit) 121 { 122 this(); 123 124 derefPolicy = dereference; 125 sizeLimit = maxResults; 126 this.batchSize = batchSize; 127 128 setTimeLimit(msLimit); 129 setReferrals(doReferrals); 130 setRebindProc(rebindProc); 131 setHopLimit(hopLimit); 132 } 133 134 135 136 /** 137 * Creates a new set of search constraints with the specified information. 138 * 139 * @param msLimit The maximum length of time in milliseconds to spend 140 * waiting for the response. 141 * @param timeLimit The maximum length of time in seconds the server 142 * should spend processing the request. 143 * @param dereference The policy to use when dereferencing aliases. 144 * @param maxResults The maximum number of entries to return from the 145 * server. 146 * @param doReferrals Indicates whether to follow referrals. 147 * @param batchSize The batch size to use when retrieving results. 148 * @param rebindProc The object to use to obtain information for 149 * authenticating the connection for use when following 150 * referrals. 151 * @param hopLimit The maximum number of hops to take when following 152 * referrals. 153 */ 154 public LDAPSearchConstraints(final int msLimit, final int timeLimit, 155 final int dereference, 156 final int maxResults, final boolean doReferrals, 157 final int batchSize, final LDAPRebind rebindProc, 158 final int hopLimit) 159 { 160 this(); 161 162 derefPolicy = dereference; 163 sizeLimit = maxResults; 164 this.timeLimit = timeLimit; 165 this.batchSize = batchSize; 166 167 setTimeLimit(msLimit); 168 setReferrals(doReferrals); 169 setRebindProc(rebindProc); 170 setHopLimit(hopLimit); 171 } 172 173 174 175 /** 176 * Creates a new set of search constraints with the specified information. 177 * 178 * @param msLimit The maximum length of time in milliseconds to spend 179 * waiting for the response. 180 * @param timeLimit The maximum length of time in seconds the server 181 * should spend processing the request. 182 * @param dereference The policy to use when dereferencing aliases. 183 * @param maxResults The maximum number of entries to return from the 184 * server. 185 * @param doReferrals Indicates whether to follow referrals. 186 * @param batchSize The batch size to use when retrieving results. 187 * @param bindProc The object to use to obtain authenticating the 188 * connection for use when following referrals. 189 * @param hopLimit The maximum number of hops to take when following 190 * referrals. 191 */ 192 public LDAPSearchConstraints(final int msLimit, final int timeLimit, 193 final int dereference, 194 final int maxResults, final boolean doReferrals, 195 final int batchSize, final LDAPBind bindProc, 196 final int hopLimit) 197 { 198 this(); 199 200 derefPolicy = dereference; 201 sizeLimit = maxResults; 202 this.timeLimit = timeLimit; 203 this.batchSize = batchSize; 204 205 setTimeLimit(msLimit); 206 setReferrals(doReferrals); 207 setBindProc(bindProc); 208 setHopLimit(hopLimit); 209 } 210 211 212 213 /** 214 * Retrieves the suggested batch size to use when retrieving results. 215 * 216 * @return The suggested batch size to use when retrieving results. 217 */ 218 public int getBatchSize() 219 { 220 return batchSize; 221 } 222 223 224 225 /** 226 * Specifies the suggested batch size to use when retrieving results. 227 * 228 * @param batchSize The suggested batch size to use when retrieving results. 229 */ 230 public void setBatchSize(final int batchSize) 231 { 232 if (batchSize < 1) 233 { 234 this.batchSize = 1; 235 } 236 else 237 { 238 this.batchSize = batchSize; 239 } 240 } 241 242 243 244 /** 245 * Retrieves the alias dereferencing policy that should be used. 246 * 247 * @return The alias dereferencing policy that should be used. 248 */ 249 public int getDereference() 250 { 251 return derefPolicy; 252 } 253 254 255 256 /** 257 * Specifies the alias dereferencing policy that should be used. 258 * 259 * @param dereference The alias dereferencing policy that should be used. 260 */ 261 public void setDereference(final int dereference) 262 { 263 derefPolicy = dereference; 264 } 265 266 267 268 /** 269 * Retrieves the maximum number of entries that should be returned for a 270 * search. 271 * 272 * @return The maximum number of entries that should be returned for a 273 * search. 274 */ 275 public int getMaxResults() 276 { 277 return sizeLimit; 278 } 279 280 281 282 /** 283 * Specifies the maximum number of entries that should be returned for a 284 * search. 285 * 286 * @param maxResults The maximum number of entries that should be returned 287 * for a search. 288 */ 289 public void setMaxResults(final int maxResults) 290 { 291 if (maxResults < 0) 292 { 293 sizeLimit = 0; 294 } 295 else 296 { 297 sizeLimit = maxResults; 298 } 299 } 300 301 302 303 /** 304 * Retrieves the maximum length of time in seconds that the server should 305 * spend processing a search. 306 * 307 * @return The maximum length of time in seconds that the server should spend 308 * processing a search. 309 */ 310 public int getServerTimeLimit() 311 { 312 return timeLimit; 313 } 314 315 316 317 /** 318 * Specifies the maximum length of time in seconds that the server should 319 * spend processing a search. 320 * 321 * @param limit The maximum length of time in seconds that the server should 322 * spend processing a search. 323 */ 324 public void setServerTimeLimit(final int limit) 325 { 326 if (limit < 0) 327 { 328 timeLimit = 0; 329 } 330 else 331 { 332 timeLimit = limit; 333 } 334 } 335 336 337 338 /** 339 * Creates a duplicate of this search constraints object. 340 * 341 * @return A duplicate of this search constraints object. 342 */ 343 @Override() 344 public LDAPSearchConstraints duplicate() 345 { 346 final LDAPSearchConstraints c = new LDAPSearchConstraints(); 347 348 c.batchSize = batchSize; 349 c.derefPolicy = derefPolicy; 350 c.sizeLimit = sizeLimit; 351 c.timeLimit = timeLimit; 352 353 c.setBindProc(getBindProc()); 354 c.setClientControls(getClientControls()); 355 c.setReferrals(getReferrals()); 356 c.setHopLimit(getHopLimit()); 357 c.setRebindProc(getRebindProc()); 358 c.setServerControls(getServerControls()); 359 c.setTimeLimit(getTimeLimit()); 360 361 return c; 362 } 363 364 365 366 /** 367 * Retrieves a string representation of this search constraints object. 368 * 369 * @return A string representation of this search constraints object. 370 */ 371 @Override() 372 public String toString() 373 { 374 final StringBuilder buffer = new StringBuilder(); 375 376 buffer.append("LDAPSearchConstraints(constraints="); 377 buffer.append(super.toString()); 378 buffer.append(", batchSize="); 379 buffer.append(batchSize); 380 buffer.append(", derefPolicy="); 381 buffer.append(derefPolicy); 382 buffer.append(", maxResults="); 383 buffer.append(sizeLimit); 384 buffer.append(", serverTimeLimit="); 385 buffer.append(timeLimit); 386 buffer.append(')'); 387 388 return buffer.toString(); 389 } 390}