/** * Construct a SingleContextSource and execute the LdapOperationsCallback using the created instance. * This makes sure the same connection will be used for all operations inside the LdapOperationsCallback, * which is particularly useful when working with e.g. Paged Results as these typically require the exact * same connection to be used for all requests involving the same cookie. * The SingleContextSource instance will be properly disposed of once the operation has been completed. * <p>By default, the {@link org.springframework.ldap.core.ContextSource#getReadWriteContext()} method * will be used to create the DirContext instance to operate on.</p> * * @param contextSource The target ContextSource to retrieve a DirContext from. * @param callback the callback to perform the Ldap operations. * @return the result returned from the callback. * @see #doWithSingleContext(org.springframework.ldap.core.ContextSource, LdapOperationsCallback, boolean, boolean, boolean) * @since 2.0 */ public static <T> T doWithSingleContext(ContextSource contextSource, LdapOperationsCallback<T> callback) { return doWithSingleContext(contextSource, callback, DONT_USE_READ_ONLY, DONT_IGNORE_PARTIAL_RESULT, DONT_IGNORE_NAME_NOT_FOUND); }
LdapOperations createLdapOperationsInstance(DirContext ctx) { return new LdapTemplate(new SingleContextSource(ctx)); } }
public DirContext getReadOnlyContext() { return getNonClosingDirContextProxy(ctx); }
SingleContextSource singleContextSource; if (useReadOnly) { singleContextSource = new SingleContextSource(contextSource.getReadOnlyContext()); } else { singleContextSource = new SingleContextSource(contextSource.getReadWriteContext()); return callback.doWithLdapOperations(ldapTemplate); } finally { singleContextSource.destroy();
SingleContextSource singleContextSource; if (useReadOnly) { singleContextSource = new SingleContextSource(contextSource.getReadOnlyContext()); } else { singleContextSource = new SingleContextSource(contextSource.getReadWriteContext()); return callback.doWithLdapOperations(ldapTemplate); } finally { singleContextSource.destroy();
SingleContextSource singleContextSource; if (useReadOnly) { singleContextSource = new SingleContextSource(contextSource.getReadOnlyContext()); } else { singleContextSource = new SingleContextSource(contextSource.getReadWriteContext()); return callback.doWithLdapOperations(ldapTemplate); } finally { singleContextSource.destroy();
/** * Construct a SingleContextSource and execute the LdapOperationsCallback using the created instance. * This makes sure the same connection will be used for all operations inside the LdapOperationsCallback, * which is particularly useful when working with e.g. Paged Results as these typically require the exact * same connection to be used for all requests involving the same cookie. * The SingleContextSource instance will be properly disposed of once the operation has been completed. * <p>By default, the {@link org.springframework.ldap.core.ContextSource#getReadWriteContext()} method * will be used to create the DirContext instance to operate on.</p> * * @param contextSource The target ContextSource to retrieve a DirContext from. * @param callback the callback to perform the Ldap operations. * @return the result returned from the callback. * @see #doWithSingleContext(org.springframework.ldap.core.ContextSource, LdapOperationsCallback, boolean, boolean, boolean) * @since 2.0 */ public static <T> T doWithSingleContext(ContextSource contextSource, LdapOperationsCallback<T> callback) { return doWithSingleContext(contextSource, callback, DONT_USE_READ_ONLY, DONT_IGNORE_PARTIAL_RESULT, DONT_IGNORE_NAME_NOT_FOUND); }
public DirContext getReadWriteContext() { return getNonClosingDirContextProxy(ctx); }
LdapOperations createLdapOperationsInstance(DirContext ctx) { return new LdapTemplate(new SingleContextSource(ctx)); } }
SingleContextSource singleContextSource; if (useReadOnly) { singleContextSource = new SingleContextSource(contextSource.getReadOnlyContext()); } else { singleContextSource = new SingleContextSource(contextSource.getReadWriteContext()); return callback.doWithLdapOperations(ldapTemplate); } finally { singleContextSource.destroy();
/** * Construct a SingleContextSource and execute the LdapOperationsCallback using the created instance. * This makes sure the same connection will be used for all operations inside the LdapOperationsCallback, * which is particularly useful when working with e.g. Paged Results as these typically require the exact * same connection to be used for all requests involving the same cookie. * The SingleContextSource instance will be properly disposed of once the operation has been completed. * <p>By default, the {@link org.springframework.ldap.core.ContextSource#getReadWriteContext()} method * will be used to create the DirContext instance to operate on.</p> * * @param contextSource The target ContextSource to retrieve a DirContext from. * @param callback the callback to perform the Ldap operations. * @return the result returned from the callback. * @see #doWithSingleContext(org.springframework.ldap.core.ContextSource, LdapOperationsCallback, boolean, boolean, boolean) * @since 2.0 */ public static <T> T doWithSingleContext(ContextSource contextSource, LdapOperationsCallback<T> callback) { return doWithSingleContext(contextSource, callback, DONT_USE_READ_ONLY, DONT_IGNORE_PARTIAL_RESULT, DONT_IGNORE_NAME_NOT_FOUND); }
public DirContext getReadOnlyContext() { return getNonClosingDirContextProxy(ctx); }
LdapOperations createLdapOperationsInstance(DirContext ctx) { return new LdapTemplate(new SingleContextSource(ctx)); } }
final SingleContextSource singleContextSource = new SingleContextSource(contextSource.getReadOnlyContext()); final LdapTemplate ldapTemplate = new LdapTemplate(singleContextSource); singleContextSource.destroy();
/** * Construct a SingleContextSource and execute the LdapOperationsCallback using the created instance. * This makes sure the same connection will be used for all operations inside the LdapOperationsCallback, * which is particularly useful when working with e.g. Paged Results as these typically require the exact * same connection to be used for all requests involving the same cookie. * The SingleContextSource instance will be properly disposed of once the operation has been completed. * <p>By default, the {@link org.springframework.ldap.core.ContextSource#getReadWriteContext()} method * will be used to create the DirContext instance to operate on.</p> * * @param contextSource The target ContextSource to retrieve a DirContext from. * @param callback the callback to perform the Ldap operations. * @return the result returned from the callback. * @see #doWithSingleContext(org.springframework.ldap.core.ContextSource, LdapOperationsCallback, boolean, boolean, boolean) * @since 2.0 */ public static <T> T doWithSingleContext(ContextSource contextSource, LdapOperationsCallback<T> callback) { return doWithSingleContext(contextSource, callback, DONT_USE_READ_ONLY, DONT_IGNORE_PARTIAL_RESULT, DONT_IGNORE_NAME_NOT_FOUND); }
public DirContext getReadWriteContext() { return getNonClosingDirContextProxy(ctx); }
LdapOperations createLdapOperationsInstance(DirContext ctx) { return new LdapTemplate(new SingleContextSource(ctx)); } }
@Test public void testDoWithSingleContext() { when(contextSourceMock.getReadWriteContext()).thenReturn(dirContextMock); verifyNoMoreInteractions(contextSourceMock); SingleContextSource.doWithSingleContext(contextSourceMock, new LdapOperationsCallback<Object>() { @Override public Object doWithLdapOperations(LdapOperations operations) { operations.executeReadOnly(new ContextExecutor<Object>() { @Override public Object executeWithContext(DirContext ctx) throws NamingException { Object targetContex = Whitebox.getInternalState(Proxy.getInvocationHandler(ctx), "target"); assertThat(targetContex).isSameAs(dirContextMock); return false; } }); // Second operation will have retrieved new DirContext from the SingleContextSource. // It should be the same instance. operations.executeReadOnly(new ContextExecutor<Object>() { @Override public Object executeWithContext(DirContext ctx) throws NamingException { Object targetContex = Whitebox.getInternalState(Proxy.getInvocationHandler(ctx), "target"); assertThat(targetContex).isSameAs(dirContextMock); return false; } }); return null; } }); }
public DirContext getReadWriteContext() { return getNonClosingDirContextProxy(ctx); }
SingleContextSource.doWithSingleContext(contextSource, new LdapOperationsCallback<Object>() { @Override public Object doWithLdapOperations(LdapOperations operations) {