null cookie being returned from the server.
+ * When this happen, the internal status will set to false.
+ *
+ * @return true if there are more results to retrieve, false otherwise.
+ * @since 2.0
+ */
+ public boolean hasMore() {
+ return more;
+ }
+
/*
* @seeorg.springframework.ldap.control.
* AbstractFallbackRequestAndResponseControlDirContextProcessor
@@ -129,6 +143,9 @@ public class PagedResultsDirContextProcessor extends AbstractFallbackRequestAndR
*/
protected void handleResponse(Object control) {
byte[] result = (byte[]) invokeMethod("getCookie", responseControlClass, control);
+ if(result == null) {
+ more = false;
+ }
this.cookie = new PagedResultsCookie(result);
this.resultSize = (Integer) invokeMethod("getResultSize", responseControlClass, control);
}
diff --git a/core/src/main/java/org/springframework/ldap/control/SortControlDirContextProcessor.java b/core/src/main/java/org/springframework/ldap/control/SortControlDirContextProcessor.java
index 7900494b..ce226720 100644
--- a/core/src/main/java/org/springframework/ldap/control/SortControlDirContextProcessor.java
+++ b/core/src/main/java/org/springframework/ldap/control/SortControlDirContextProcessor.java
@@ -103,7 +103,7 @@ public class SortControlDirContextProcessor extends AbstractFallbackRequestAndRe
* #createRequestControl()
*/
public Control createRequestControl() {
- return super.createRequestControl(new Class[] { String[].class, boolean.class }, new Object[] {
+ return super.createRequestControl(new Class>[] { String[].class, boolean.class }, new Object[] {
new String[] { sortKey }, critical});
}
diff --git a/core/src/main/java/org/springframework/ldap/core/support/LdapOperationsCallback.java b/core/src/main/java/org/springframework/ldap/core/support/LdapOperationsCallback.java
new file mode 100644
index 00000000..4e7026b3
--- /dev/null
+++ b/core/src/main/java/org/springframework/ldap/core/support/LdapOperationsCallback.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2005-2013 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.ldap.core.support;
+
+import org.springframework.ldap.core.LdapOperations;
+
+/**
+ * Callback interface to be used together with {@link SingleContextSource}.
+ *
+ * @author Mattias Hellborg Arthursson
+ * @since 2.0
+ * @see SingleContextSource#doWithSingleContext(org.springframework.ldap.core.ContextSource, LdapOperationsCallback)
+ * @see SingleContextSource#doWithSingleContext(org.springframework.ldap.core.ContextSource, LdapOperationsCallback, boolean, boolean, boolean)
+ */
+public interface LdapOperationsCallbackBy default, the {@link org.springframework.ldap.core.ContextSource#getReadWriteContext()} method + * will be used to create the DirContext instance to operate on.
+ * + * @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 statictrue, use the {@link org.springframework.ldap.core.ContextSource#getReadOnlyContext()}
+ * method on the target ContextSource to get the actual DirContext instance, if false,
+ * use {@link org.springframework.ldap.core.ContextSource#getReadWriteContext()}.
+ * @param ignorePartialResultException Used for populating this property on the created LdapTemplate instance.
+ * @param ignoreNameNotFoundException Used for populating this property on the created LdapTemplate instance.
+ * @return the result returned from the callback.
+ * @since 2.0
+ */
+ public static close operations will be performed.
diff --git a/core/src/test/java/org/springframework/ldap/core/support/SingleContextSourceTest.java b/core/src/test/java/org/springframework/ldap/core/support/SingleContextSourceTest.java
new file mode 100644
index 00000000..9fa00355
--- /dev/null
+++ b/core/src/test/java/org/springframework/ldap/core/support/SingleContextSourceTest.java
@@ -0,0 +1,83 @@
+/*
+ * Copyright 2005-2013 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.ldap.core.support;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.internal.util.reflection.Whitebox;
+import org.springframework.ldap.core.ContextExecutor;
+import org.springframework.ldap.core.ContextSource;
+import org.springframework.ldap.core.LdapOperations;
+
+import javax.naming.NamingException;
+import javax.naming.directory.DirContext;
+
+import java.lang.reflect.Proxy;
+
+import static org.junit.Assert.assertSame;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verifyNoMoreInteractions;
+import static org.mockito.Mockito.when;
+
+/**
+ * @author Mattias Hellborg Arthursson
+ */
+public class SingleContextSourceTest {
+
+ private ContextSource contextSourceMock;
+ private DirContext dirContextMock;
+
+ @Before
+ public void prepareMocks() {
+ contextSourceMock = mock(ContextSource.class);
+ dirContextMock = mock(DirContext.class);
+ }
+
+ @Test
+ public void testDoWithSingleContext() {
+ when(contextSourceMock.getReadWriteContext()).thenReturn(dirContextMock);
+ verifyNoMoreInteractions(contextSourceMock);
+
+ SingleContextSource.doWithSingleContext(contextSourceMock, new LdapOperationsCallback