Class AbstractConnection
- java.lang.Object
-
- org.forgerock.opendj.ldap.AbstractConnection
-
- All Implemented Interfaces:
Closeable
,AutoCloseable
,Connection
- Direct Known Subclasses:
AbstractAsynchronousConnection
,AbstractSynchronousConnection
public abstract class AbstractConnection extends Object implements Connection
This class provides a skeletal implementation of theConnection
interface, to minimize the effort required to implement this interface.
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractConnection()
Creates a new abstract connection.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description Result
add(String... ldifLines)
Adds an entry to the Directory Server using the provided lines of LDIF.Result
add(Entry entry)
Adds the provided entry to the Directory Server.LdapPromise<Result>
addAsync(AddRequest request)
Asynchronously adds an entry to the Directory Server using the provided add request.Result
applyChange(ChangeRecord request)
Applies the provided change request to the Directory Server.LdapPromise<Result>
applyChangeAsync(ChangeRecord request)
Asynchronously applies the provided change request to the Directory Server.LdapPromise<Result>
applyChangeAsync(ChangeRecord request, IntermediateResponseHandler intermediateResponseHandler)
Asynchronously applies the provided change request to the Directory Server.BindResult
bind(String name, char[] password)
Authenticates to the Directory Server using simple authentication and the provided user name and password.LdapPromise<BindResult>
bindAsync(BindRequest request)
Asynchronously authenticates to the Directory Server using the provided bind request.void
close()
Releases any resources associated with this connection.CompareResult
compare(String name, String attributeDescription, String assertionValue)
Compares the named entry in the Directory Server against the provided attribute value assertion.LdapPromise<CompareResult>
compareAsync(CompareRequest request)
Asynchronously compares an entry in the Directory Server using the provided compare request.Result
delete(String name)
Deletes the named entry from the Directory Server.LdapPromise<Result>
deleteAsync(DeleteRequest request)
Asynchronously deletes an entry from the Directory Server using the provided delete request.Result
deleteSubtree(String name)
Deletes the named entry and all of its subordinates from the Directory Server.GenericExtendedResult
extendedRequest(String requestName, ByteString requestValue)
Requests that the Directory Server performs the provided extended request.<R extends ExtendedResult>
RextendedRequest(ExtendedRequest<R> request)
Requests that the Directory Server performs the provided extended request.<R extends ExtendedResult>
LdapPromise<R>extendedRequestAsync(ExtendedRequest<R> request)
Asynchronously performs the provided extended request in the Directory Server.Result
modify(String... ldifLines)
Modifies an entry in the Directory Server using the provided lines of LDIF.LdapPromise<Result>
modifyAsync(ModifyRequest request)
Asynchronously modifies an entry in the Directory Server using the provided modify request.Result
modifyDn(String name, String newRDN)
Renames the named entry in the Directory Server using the provided new RDN.LdapPromise<Result>
modifyDnAsync(ModifyDnRequest request)
Asynchronously renames an entry in the Directory Server using the provided modify DN request.SearchResultEntry
readEntry(String baseObject, String... attributeDescriptions)
Reads the named entry from the Directory Server.SearchResultEntry
readEntry(Dn baseObject, String... attributeDescriptions)
Reads the named entry from the Directory Server.LdapPromise<SearchResultEntry>
readEntryAsync(Dn name, Collection<String> attributeDescriptions)
Asynchronously reads the named entry from the Directory Server.ConnectionEntryReader
search(String baseObject, SearchScope scope, String filter, String... attributeDescriptions)
Searches the Directory Server using the provided search parameters.ConnectionEntryReader
search(SearchRequest request)
Searches the Directory Server using the provided search parameters.Result
search(SearchRequest request, Collection<? super SearchResultEntry> entries)
Searches the Directory Server using the provided search request.Result
search(SearchRequest request, Collection<? super SearchResultEntry> entries, Collection<? super SearchResultReference> references)
Searches the Directory Server using the provided search request.LdapPromise<Result>
searchAsync(SearchRequest request, SearchResultHandler resultHandler)
Asynchronously searches the Directory Server using the provided search request.SearchResultEntry
searchSingleEntry(String baseObject, SearchScope scope, String filter, String... attributeDescriptions)
Searches the Directory Server for a single entry using the provided search parameters.SearchResultEntry
searchSingleEntry(SearchRequest request)
Searches the Directory Server for a single entry using the provided search request.LdapPromise<SearchResultEntry>
searchSingleEntryAsync(SearchRequest request)
Asynchronously searches the Directory Server for a single entry using the provided search request.abstract String
toString()
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.forgerock.opendj.ldap.Connection
abandonAsync, add, addAsync, addConnectionEventListener, bind, bindAsync, close, compare, compareAsync, delete, delete, deleteAsync, extendedRequest, extendedRequestAsync, isClosed, isValid, modify, modifyAsync, modifyDn, modifyDnAsync, removeConnectionEventListener, search, searchAsync
-
-
-
-
Method Detail
-
add
public Result add(Entry entry) throws LdapException
Description copied from interface:Connection
Adds the provided entry to the Directory Server.This method is equivalent to the following code:
AddRequest request = new AddRequest(entry); connection.add(request);
- Specified by:
add
in interfaceConnection
- Parameters:
entry
- The entry to be added.- Returns:
- The result of the operation.
- Throws:
LdapException
- If the result code indicates that the request failed for some reason.
-
add
public Result add(String... ldifLines) throws LdapException
Description copied from interface:Connection
Adds an entry to the Directory Server using the provided lines of LDIF.This method is equivalent to the following code:
AddRequest request = new AddRequest(ldifLines); connection.add(request);
- Specified by:
add
in interfaceConnection
- Parameters:
ldifLines
- Lines of LDIF containing the an LDIF add change record or an LDIF entry record.- Returns:
- The result of the operation.
- Throws:
LdapException
- If the result code indicates that the request failed for some reason.
-
addAsync
public LdapPromise<Result> addAsync(AddRequest request)
Description copied from interface:Connection
Asynchronously adds an entry to the Directory Server using the provided add request.- Specified by:
addAsync
in interfaceConnection
- Parameters:
request
- The add request.- Returns:
- A promise representing the result of the operation.
-
applyChange
public Result applyChange(ChangeRecord request) throws LdapException
Description copied from interface:Connection
Applies the provided change request to the Directory Server.- Specified by:
applyChange
in interfaceConnection
- Parameters:
request
- The change request.- Returns:
- The result of the operation.
- Throws:
LdapException
- If the result code indicates that the request failed for some reason.
-
applyChangeAsync
public LdapPromise<Result> applyChangeAsync(ChangeRecord request)
Description copied from interface:Connection
Asynchronously applies the provided change request to the Directory Server.- Specified by:
applyChangeAsync
in interfaceConnection
- Parameters:
request
- The change request.- Returns:
- A promise representing the result of the operation.
-
applyChangeAsync
public LdapPromise<Result> applyChangeAsync(ChangeRecord request, IntermediateResponseHandler intermediateResponseHandler)
Description copied from interface:Connection
Asynchronously applies the provided change request to the Directory Server.- Specified by:
applyChangeAsync
in interfaceConnection
- Parameters:
request
- The change request.intermediateResponseHandler
- An intermediate response handler which can be used to process any intermediate responses as they are received, may benull
.- Returns:
- A promise representing the result of the operation.
-
bind
public BindResult bind(String name, char[] password) throws LdapException
Description copied from interface:Connection
Authenticates to the Directory Server using simple authentication and the provided user name and password.This method is equivalent to the following code:
BindRequest request = new SimpleBindRequest(name, password); connection.bind(request);
- Specified by:
bind
in interfaceConnection
- Parameters:
name
- The distinguished name of the Directory object that the client wishes to bind as, which may be empty.password
- The password of the Directory object that the client wishes to bind as, which may be empty.- Returns:
- The result of the operation.
- Throws:
LdapException
- If the result code indicates that the request failed for some reason.
-
bindAsync
public LdapPromise<BindResult> bindAsync(BindRequest request)
Description copied from interface:Connection
Asynchronously authenticates to the Directory Server using the provided bind request.- Specified by:
bindAsync
in interfaceConnection
- Parameters:
request
- The bind request.- Returns:
- A promise representing the result of the operation.
-
close
public void close()
Description copied from interface:Connection
Releases any resources associated with this connection. For physical connections to a Directory Server this will mean that an unbind request is sent and the underlying socket is closed.Other connection implementations may behave differently, and may choose not to send an unbind request if its use is inappropriate (for example a pooled connection will be released and returned to its connection pool without ever issuing an unbind request).
This method is equivalent to the following code:
UnbindRequest request = new UnbindRequest(); connection.close(request);
Callingclose
on a connection that is already closed has no effect.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in interfaceConnection
- See Also:
Connections.uncloseable(Connection)
-
compare
public CompareResult compare(String name, String attributeDescription, String assertionValue) throws LdapException
Description copied from interface:Connection
Compares the named entry in the Directory Server against the provided attribute value assertion.This method is equivalent to the following code:
CompareRequest request = new CompareRequest(name, attributeDescription, assertionValue); connection.compare(request);
- Specified by:
compare
in interfaceConnection
- Parameters:
name
- The distinguished name of the entry to be compared.attributeDescription
- The name of the attribute to be compared.assertionValue
- The assertion value to be compared.- Returns:
- The result of the operation.
- Throws:
LdapException
- If the result code indicates that the request failed for some reason.
-
compareAsync
public LdapPromise<CompareResult> compareAsync(CompareRequest request)
Description copied from interface:Connection
Asynchronously compares an entry in the Directory Server using the provided compare request.- Specified by:
compareAsync
in interfaceConnection
- Parameters:
request
- The compare request.- Returns:
- A promise representing the result of the operation.
-
delete
public Result delete(String name) throws LdapException
Description copied from interface:Connection
Deletes the named entry from the Directory Server.This method is equivalent to the following code:
DeleteRequest request = new DeleteRequest(name); connection.delete(request);
- Specified by:
delete
in interfaceConnection
- Parameters:
name
- The distinguished name of the entry to be deleted.- Returns:
- The result of the operation.
- Throws:
LdapException
- If the result code indicates that the request failed for some reason.
-
deleteAsync
public LdapPromise<Result> deleteAsync(DeleteRequest request)
Description copied from interface:Connection
Asynchronously deletes an entry from the Directory Server using the provided delete request.- Specified by:
deleteAsync
in interfaceConnection
- Parameters:
request
- The delete request.- Returns:
- A promise representing the result of the operation.
-
deleteSubtree
public Result deleteSubtree(String name) throws LdapException
Description copied from interface:Connection
Deletes the named entry and all of its subordinates from the Directory Server.This method is equivalent to the following code:
DeleteRequest request = new DeleteRequest(name).addControl( connection.delete(request);
- Specified by:
deleteSubtree
in interfaceConnection
- Parameters:
name
- The distinguished name of the subtree base entry to be deleted.- Returns:
- The result of the operation.
- Throws:
LdapException
- If the result code indicates that the request failed for some reason.
-
extendedRequest
public <R extends ExtendedResult> R extendedRequest(ExtendedRequest<R> request) throws LdapException
Description copied from interface:Connection
Requests that the Directory Server performs the provided extended request.- Specified by:
extendedRequest
in interfaceConnection
- Type Parameters:
R
- The type of result returned by the extended request.- Parameters:
request
- The extended request.- Returns:
- The result of the operation.
- Throws:
LdapException
- If the result code indicates that the request failed for some reason.
-
extendedRequest
public GenericExtendedResult extendedRequest(String requestName, ByteString requestValue) throws LdapException
Description copied from interface:Connection
Requests that the Directory Server performs the provided extended request.This method is equivalent to the following code:
GenericExtendedRequest request = new GenericExtendedRequest(requestName, requestValue); connection.extendedRequest(request);
- Specified by:
extendedRequest
in interfaceConnection
- Parameters:
requestName
- The dotted-decimal representation of the unique OID corresponding to the extended request.requestValue
- The content of the extended request in a form defined by the extended operation, ornull
if there is no content.- Returns:
- The result of the operation.
- Throws:
LdapException
- If the result code indicates that the request failed for some reason.
-
extendedRequestAsync
public <R extends ExtendedResult> LdapPromise<R> extendedRequestAsync(ExtendedRequest<R> request)
Description copied from interface:Connection
Asynchronously performs the provided extended request in the Directory Server.- Specified by:
extendedRequestAsync
in interfaceConnection
- Type Parameters:
R
- The type of result returned by the extended request.- Parameters:
request
- The extended request.- Returns:
- A promise representing the result of the operation.
-
modify
public Result modify(String... ldifLines) throws LdapException
Description copied from interface:Connection
Modifies an entry in the Directory Server using the provided lines of LDIF.This method is equivalent to the following code:
ModifyRequest request = new ModifyRequest(name, ldifChanges); connection.modify(request);
- Specified by:
modify
in interfaceConnection
- Parameters:
ldifLines
- Lines of LDIF containing the a single LDIF modify change record.- Returns:
- The result of the operation.
- Throws:
LdapException
- If the result code indicates that the request failed for some reason.
-
modifyAsync
public LdapPromise<Result> modifyAsync(ModifyRequest request)
Description copied from interface:Connection
Asynchronously modifies an entry in the Directory Server using the provided modify request.- Specified by:
modifyAsync
in interfaceConnection
- Parameters:
request
- The modify request.- Returns:
- A promise representing the result of the operation.
-
modifyDn
public Result modifyDn(String name, String newRDN) throws LdapException
Description copied from interface:Connection
Renames the named entry in the Directory Server using the provided new RDN.This method is equivalent to the following code:
ModifyDNRequest request = new ModifyDNRequest(name, newRDN); connection.modifyDN(request);
- Specified by:
modifyDn
in interfaceConnection
- Parameters:
name
- The distinguished name of the entry to be renamed.newRDN
- The new RDN of the entry.- Returns:
- The result of the operation.
- Throws:
LdapException
- If the result code indicates that the request failed for some reason.
-
modifyDnAsync
public LdapPromise<Result> modifyDnAsync(ModifyDnRequest request)
Description copied from interface:Connection
Asynchronously renames an entry in the Directory Server using the provided modify DN request.- Specified by:
modifyDnAsync
in interfaceConnection
- Parameters:
request
- The modify DN request.- Returns:
- A promise representing the result of the operation.
-
readEntry
public SearchResultEntry readEntry(Dn baseObject, String... attributeDescriptions) throws LdapException
Description copied from interface:Connection
Reads the named entry from the Directory Server.If the requested entry is not returned by the Directory Server then the request will fail with an
EntryNotFoundException
. More specifically, this method will never returnnull
.This method is equivalent to the following code:
SearchRequest request = new SearchRequest(name, SearchScope.BASE_OBJECT, "(objectClass=*)", attributeDescriptions); connection.searchSingleEntry(request);
- Specified by:
readEntry
in interfaceConnection
- Parameters:
baseObject
- The distinguished name of the entry to be read.attributeDescriptions
- The names of the attributes to be included with the entry, which may benull
or empty indicating that all user attributes should be returned.- Returns:
- The single search result entry returned from the search.
- Throws:
LdapException
- If the result code indicates that the request failed for some reason.
-
readEntry
public SearchResultEntry readEntry(String baseObject, String... attributeDescriptions) throws LdapException
Description copied from interface:Connection
Reads the named entry from the Directory Server.If the requested entry is not returned by the Directory Server then the request will fail with an
EntryNotFoundException
. More specifically, this method will never returnnull
.This method is equivalent to the following code:
SearchRequest request = new SearchRequest(name, SearchScope.BASE_OBJECT, "(objectClass=*)", attributeDescriptions); connection.searchSingleEntry(request);
- Specified by:
readEntry
in interfaceConnection
- Parameters:
baseObject
- The distinguished name of the entry to be read.attributeDescriptions
- The names of the attributes to be included with the entry.- Returns:
- The single search result entry returned from the search.
- Throws:
LdapException
- If the result code indicates that the request failed for some reason.
-
readEntryAsync
public LdapPromise<SearchResultEntry> readEntryAsync(Dn name, Collection<String> attributeDescriptions)
Description copied from interface:Connection
Asynchronously reads the named entry from the Directory Server.If the requested entry is not returned by the Directory Server then the request will fail with an
EntryNotFoundException
. More specifically, the returned promise will never returnnull
.This method is equivalent to the following code:
SearchRequest request = new SearchRequest(name, SearchScope.BASE_OBJECT, "(objectClass=*)", attributeDescriptions); connection.searchSingleEntryAsync(request, resultHandler, p);
- Specified by:
readEntryAsync
in interfaceConnection
- Parameters:
name
- The distinguished name of the entry to be read.attributeDescriptions
- The names of the attributes to be included with the entry, which may benull
or empty indicating that all user attributes should be returned.- Returns:
- A promise representing the result of the operation.
-
search
public ConnectionEntryReader search(SearchRequest request)
Description copied from interface:Connection
Searches the Directory Server using the provided search parameters. Any matching entries returned by the search will be exposed through the returnedConnectionEntryReader
.Unless otherwise specified, calling this method is equivalent to:
ConnectionEntryReader reader = new ConnectionEntryReader(this, request);
- Specified by:
search
in interfaceConnection
- Parameters:
request
- The search request.- Returns:
- The result of the operation.
-
search
public Result search(SearchRequest request, Collection<? super SearchResultEntry> entries) throws LdapException
Description copied from interface:Connection
Searches the Directory Server using the provided search request. Any matching entries returned by the search will be added toentries
, even if the final search result indicates that the search failed. Search result references will be discarded.Warning: Usage of this method is discouraged if the search request is expected to yield a large number of search results since the entire set of results will be stored in memory, potentially causing an
OutOfMemoryError
.This method is equivalent to the following code:
connection.search(request, entries, null);
- Specified by:
search
in interfaceConnection
- Parameters:
request
- The search request.entries
- The collection to which matching entries should be added.- Returns:
- The result of the operation.
- Throws:
LdapException
- If the result code indicates that the request failed for some reason.
-
search
public Result search(SearchRequest request, Collection<? super SearchResultEntry> entries, Collection<? super SearchResultReference> references) throws LdapException
Description copied from interface:Connection
Searches the Directory Server using the provided search request. Any matching entries returned by the search will be added toentries
, even if the final search result indicates that the search failed. Similarly, search result references returned by the search will be added toreferences
.Warning: Usage of this method is discouraged if the search request is expected to yield a large number of search results since the entire set of results will be stored in memory, potentially causing an
OutOfMemoryError
.- Specified by:
search
in interfaceConnection
- Parameters:
request
- The search request.entries
- The collection to which matching entries should be added.references
- The collection to which search result references should be added, ornull
if references are to be discarded.- Returns:
- The result of the operation.
- Throws:
LdapException
- If the result code indicates that the request failed for some reason.
-
search
public ConnectionEntryReader search(String baseObject, SearchScope scope, String filter, String... attributeDescriptions)
Description copied from interface:Connection
Searches the Directory Server using the provided search parameters. Any matching entries returned by the search will be exposed through theEntryReader
interface.Warning: When using a queue with an optional capacity bound, the connection will stop reading responses and wait if necessary for space to become available.
This method is equivalent to the following code:
SearchRequest request = new SearchRequest(baseDN, scope, filter, attributeDescriptions); connection.search(request, new LinkedBlockingQueue<Response>());
- Specified by:
search
in interfaceConnection
- Parameters:
baseObject
- The distinguished name of the base entry relative to which the search is to be performed.scope
- The scope of the search.filter
- The filter that defines the conditions that must be fulfilled in order for an entry to be returned.attributeDescriptions
- The names of the attributes to be included with each entry.- Returns:
- An entry reader exposing the returned entries.
-
searchAsync
public LdapPromise<Result> searchAsync(SearchRequest request, SearchResultHandler resultHandler)
Description copied from interface:Connection
Asynchronously searches the Directory Server using the provided search request.- Specified by:
searchAsync
in interfaceConnection
- Parameters:
request
- The search request.resultHandler
- A search result handler which can be used to asynchronously process the search result entries and references as they are received, may benull
.- Returns:
- A promise representing the result of the operation.
-
searchSingleEntry
public SearchResultEntry searchSingleEntry(SearchRequest request) throws LdapException
Description copied from interface:Connection
Searches the Directory Server for a single entry using the provided search request.If the requested entry is not returned by the Directory Server then the request will fail with an
EntryNotFoundException
. More specifically, this method will never returnnull
. If multiple matching entries are returned by the Directory Server then the request will fail with anMultipleEntriesFoundException
.- Specified by:
searchSingleEntry
in interfaceConnection
- Parameters:
request
- The search request.- Returns:
- The single search result entry returned from the search.
- Throws:
LdapException
- If the result code indicates that the request failed for some reason.
-
searchSingleEntry
public SearchResultEntry searchSingleEntry(String baseObject, SearchScope scope, String filter, String... attributeDescriptions) throws LdapException
Description copied from interface:Connection
Searches the Directory Server for a single entry using the provided search parameters.If the requested entry is not returned by the Directory Server then the request will fail with an
EntryNotFoundException
. More specifically, this method will never returnnull
. If multiple matching entries are returned by the Directory Server then the request will fail with anMultipleEntriesFoundException
.This method is equivalent to the following code:
SearchRequest request = new SearchRequest(baseObject, scope, filter, attributeDescriptions); connection.searchSingleEntry(request);
- Specified by:
searchSingleEntry
in interfaceConnection
- Parameters:
baseObject
- The distinguished name of the base entry relative to which the search is to be performed.scope
- The scope of the search.filter
- The filter that defines the conditions that must be fulfilled in order for an entry to be returned.attributeDescriptions
- The names of the attributes to be included with each entry.- Returns:
- The single search result entry returned from the search.
- Throws:
LdapException
- If the result code indicates that the request failed for some reason.
-
searchSingleEntryAsync
public LdapPromise<SearchResultEntry> searchSingleEntryAsync(SearchRequest request)
Description copied from interface:Connection
Asynchronously searches the Directory Server for a single entry using the provided search request.If the requested entry is not returned by the Directory Server then the request will fail with an
EntryNotFoundException
. More specifically, the returned promise will never returnnull
. If multiple matching entries are returned by the Directory Server then the request will fail with anMultipleEntriesFoundException
.- Specified by:
searchSingleEntryAsync
in interfaceConnection
- Parameters:
request
- The search request.- Returns:
- A promise representing the result of the operation.
-
-