本文整理汇总了Java中org.springframework.ldap.core.ContextSource.getReadWriteContext方法的典型用法代码示例。如果您正苦于以下问题:Java ContextSource.getReadWriteContext方法的具体用法?Java ContextSource.getReadWriteContext怎么用?Java ContextSource.getReadWriteContext使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.ldap.core.ContextSource
的用法示例。
在下文中一共展示了ContextSource.getReadWriteContext方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doWithSingleContext
import org.springframework.ldap.core.ContextSource; //导入方法依赖的package包/类
/**
* 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.
*
* @param contextSource The target ContextSource to retrieve a DirContext from
* @param callback the callback to perform the Ldap operations
* @param useReadOnly if <code>true</code>, use the {@link org.springframework.ldap.core.ContextSource#getReadOnlyContext()}
* method on the target ContextSource to get the actual DirContext instance, if <code>false</code>,
* 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 <T> T doWithSingleContext(ContextSource contextSource,
LdapOperationsCallback<T> callback,
boolean useReadOnly,
boolean ignorePartialResultException,
boolean ignoreNameNotFoundException) {
SingleContextSource singleContextSource;
if (useReadOnly) {
singleContextSource = new SingleContextSource(contextSource.getReadOnlyContext());
} else {
singleContextSource = new SingleContextSource(contextSource.getReadWriteContext());
}
LdapTemplate ldapTemplate = new LdapTemplate(singleContextSource);
ldapTemplate.setIgnorePartialResultException(ignorePartialResultException);
ldapTemplate.setIgnoreNameNotFoundException(ignoreNameNotFoundException);
try {
return callback.doWithLdapOperations(ldapTemplate);
} finally {
singleContextSource.destroy();
}
}
示例2: clearSubContexts
import org.springframework.ldap.core.ContextSource; //导入方法依赖的package包/类
/**
* Clear the directory sub-tree starting with the node represented by the
* supplied distinguished name.
*
* @param contextSource the ContextSource to use for getting a DirContext.
* @param name the distinguished name of the root node.
* @throws NamingException if anything goes wrong removing the sub-tree.
*/
public static void clearSubContexts(ContextSource contextSource, Name name) throws NamingException {
DirContext ctx = null;
try {
ctx = contextSource.getReadWriteContext();
clearSubContexts(ctx, name);
} finally {
try {
ctx.close();
} catch (Exception e) {
// Never mind this
}
}
}
示例3: loadLdif
import org.springframework.ldap.core.ContextSource; //导入方法依赖的package包/类
/**
* Load an Ldif file into an LDAP server.
*
* @param contextSource ContextSource to use for getting a DirContext to
* interact with the LDAP server.
* @param ldifFile a Resource representing a valid LDIF file.
* @throws IOException if the Resource cannot be read.
*/
public static void loadLdif(ContextSource contextSource, Resource ldifFile) throws IOException {
DirContext context = contextSource.getReadWriteContext();
try {
loadLdif(context, ldifFile);
} finally {
try {
context.close();
} catch (Exception e) {
// This is not the exception we are interested in.
}
}
}