[
https://issues.apache.org/jira/browse/DIRAPI-163?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13852979#comment-13852979
]
lucas theisen commented on DIRAPI-163:
--------------------------------------
Currently you must do something like this:
{code:java}
LdapConnection connection = null;
try {
connection = ldapConnections.borrowObject()
AddRequest request = new AddRequestImpl();
request.setEntry( newEntry );
AddResponse respone = connection.add( addRequest );
}
catch ( LdapException e ) {
throw new LdapRuntimeException( e );
}
finally {
try {
ldapConnections.returnObject( connection );
}
catch ( Exception e ) {
logger.warn( "failed to close connection, possible connection
leak:", e );
}
}
{code}
Which could be this instead:
{code:java}
ldapConnectionTemplate.add( newEntry );
{code}
This type of application across all operations makes for a much cleaner
business model. The template could include other useful functions like:
{code:java}
public static <T extends ResultResponse> T responseOrException( T response
) {
if ( ResultCodeEnum.SUCCESS != response.getLdapResult().getResultCode()
) {
throw new LdapRequestUnsuccessfulException( response );
}
return response;
}
{code}
Which would allow for:
{code:java}
AddResponse response = LdapConnectionTemplate.responseOrException(
ldapConnectionTemplate.add( newEntry ) );
{code}
> Add an LdapConnectionTemplate (template design pattern)
> -------------------------------------------------------
>
> Key: DIRAPI-163
> URL: https://issues.apache.org/jira/browse/DIRAPI-163
> Project: Directory Client API
> Issue Type: New Feature
> Affects Versions: 1.0.0-M21
> Reporter: lucas theisen
>
> Create an LdapConnectionTemplate that can abstract the cookie cutter using
> callbacks.
--
This message was sent by Atlassian JIRA
(v6.1.4#6159)