No longer throwing DataAccessException from ContextSource.
This commit is contained in:
@@ -27,8 +27,8 @@ import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.commons.pool.impl.GenericKeyedObjectPool;
|
||||
import org.apache.commons.pool.impl.GenericObjectPool;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.dao.DataAccessResourceFailureException;
|
||||
import org.springframework.ldap.NamingException;
|
||||
import org.springframework.ldap.core.ContextSource;
|
||||
import org.springframework.ldap.validation.DirContextValidator;
|
||||
|
||||
@@ -428,18 +428,18 @@ public class PoolingContextSource implements ContextSource {
|
||||
/**
|
||||
* @see org.springframework.ldap.ContextSource#getReadOnlyContext()
|
||||
*/
|
||||
public DirContext getReadOnlyContext() throws DataAccessException {
|
||||
public DirContext getReadOnlyContext() throws NamingException {
|
||||
return this.getContext(DirContextType.READ_ONLY);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.springframework.ldap.ContextSource#getReadWriteContext()
|
||||
*/
|
||||
public DirContext getReadWriteContext() throws DataAccessException {
|
||||
public DirContext getReadWriteContext() throws NamingException {
|
||||
return this.getContext(DirContextType.READ_WRITE);
|
||||
}
|
||||
|
||||
protected DirContext getContext(DirContextType dirContextType) throws DataAccessException {
|
||||
protected DirContext getContext(DirContextType dirContextType) throws NamingException {
|
||||
final DirContext dirContext;
|
||||
try {
|
||||
dirContext = (DirContext)this.keyedObjectPool.borrowObject(dirContextType);
|
||||
|
||||
@@ -18,7 +18,7 @@ package org.springframework.ldap.core;
|
||||
|
||||
import javax.naming.directory.DirContext;
|
||||
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.ldap.NamingException;
|
||||
|
||||
/**
|
||||
* Interface used to retrieve and authenticate LDAP contexts.
|
||||
@@ -35,17 +35,17 @@ public interface ContextSource {
|
||||
* perform read-only operations on.
|
||||
*
|
||||
* @return A DirContext instance, never null.
|
||||
* @throws DataAccessException
|
||||
* @throws NamingException
|
||||
* if some error occurs creating an DirContext.
|
||||
*/
|
||||
public DirContext getReadOnlyContext() throws DataAccessException;
|
||||
public DirContext getReadOnlyContext() throws NamingException;
|
||||
|
||||
/**
|
||||
* Gets a read-write DirContext.
|
||||
*
|
||||
* @return A DirContext instance, never null.
|
||||
* @throws DataAccessException
|
||||
* @throws NamingException
|
||||
* if some error occurs creating an DirContext.
|
||||
*/
|
||||
public DirContext getReadWriteContext() throws DataAccessException;
|
||||
public DirContext getReadWriteContext() throws NamingException;
|
||||
}
|
||||
@@ -1,83 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2005 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.support;
|
||||
|
||||
import javax.naming.CommunicationException;
|
||||
import javax.naming.ContextNotEmptyException;
|
||||
import javax.naming.LimitExceededException;
|
||||
import javax.naming.NameAlreadyBoundException;
|
||||
import javax.naming.NameNotFoundException;
|
||||
import javax.naming.NamingException;
|
||||
import javax.naming.directory.InvalidAttributesException;
|
||||
import javax.naming.directory.InvalidSearchControlsException;
|
||||
import javax.naming.directory.InvalidSearchFilterException;
|
||||
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.dao.DataIntegrityViolationException;
|
||||
import org.springframework.dao.DataRetrievalFailureException;
|
||||
import org.springframework.dao.InvalidDataAccessApiUsageException;
|
||||
import org.springframework.dao.UncategorizedDataAccessException;
|
||||
import org.springframework.ldap.BadLdapGrammarException;
|
||||
|
||||
/**
|
||||
* The default implementation of NamingExceptionTranslator.
|
||||
*
|
||||
* @author Mattias Arthursson
|
||||
*/
|
||||
public class DefaultNamingExceptionTranslator implements
|
||||
NamingExceptionTranslator {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.springframework.ldap.NamingExceptionTranslator#translate(java.lang.String,
|
||||
* java.lang.String, java.lang.String, javax.naming.NamingException)
|
||||
*/
|
||||
public DataAccessException translate(NamingException namingException) {
|
||||
|
||||
if (namingException instanceof NameNotFoundException) {
|
||||
return new EntryNotFoundException("Entry not found",
|
||||
namingException);
|
||||
}
|
||||
|
||||
if (namingException instanceof InvalidSearchControlsException) {
|
||||
return new InvalidDataAccessApiUsageException(
|
||||
"Invalid search controls supplied by internal API",
|
||||
namingException);
|
||||
}
|
||||
|
||||
if (namingException instanceof NameAlreadyBoundException) {
|
||||
return new DataIntegrityViolationException("Name already bound",
|
||||
namingException);
|
||||
}
|
||||
|
||||
if (namingException instanceof ContextNotEmptyException) {
|
||||
return new DataIntegrityViolationException(
|
||||
"The context needs to be empty in order to be removed",
|
||||
namingException);
|
||||
}
|
||||
|
||||
if (namingException instanceof CommunicationException) {
|
||||
throw new DataRetrievalFailureException(
|
||||
"Unable to communicate with LDAP server", namingException);
|
||||
}
|
||||
|
||||
// Fallback - other type of NamingException encountered.
|
||||
return new UncategorizedDataAccessException("Operation failed",
|
||||
namingException) {};
|
||||
}
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2005 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.support;
|
||||
|
||||
import org.springframework.dao.DataRetrievalFailureException;
|
||||
|
||||
/**
|
||||
* Represents that an entry could not be found.
|
||||
*
|
||||
* @author Mattias Arthursson
|
||||
* @deprecated Should be replaced with the matching mirrored NamingException
|
||||
*/
|
||||
public class EntryNotFoundException extends DataRetrievalFailureException {
|
||||
|
||||
private static final long serialVersionUID = -1268390922996332424L;
|
||||
|
||||
public EntryNotFoundException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
public EntryNotFoundException(String msg, Throwable cause) {
|
||||
super(msg, cause);
|
||||
}
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2005 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.support;
|
||||
|
||||
import javax.naming.NamingException;
|
||||
|
||||
import org.springframework.dao.DataAccessException;
|
||||
|
||||
/**
|
||||
* Interface to be implemented by classes that can translate between
|
||||
* NamingExceptions and DataAccessExceptions.
|
||||
*
|
||||
* @author Mattias Arthursson
|
||||
* @deprecated Use {@link LdapUtils#convertLdapException(NamingException)}
|
||||
* instead.
|
||||
*/
|
||||
public interface NamingExceptionTranslator {
|
||||
/**
|
||||
* Translate the given NamingException into a generic data access exception.
|
||||
*
|
||||
* @param namingException
|
||||
* the offending NamingException.
|
||||
*
|
||||
* @return the DataAccessException to throw.
|
||||
*/
|
||||
public DataAccessException translate(NamingException namingException);
|
||||
}
|
||||
@@ -25,7 +25,7 @@ import javax.naming.directory.DirContext;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.ldap.NamingException;
|
||||
import org.springframework.ldap.core.ContextSource;
|
||||
import org.springframework.ldap.core.LdapOperations;
|
||||
import org.springframework.ldap.core.LdapTemplate;
|
||||
@@ -109,7 +109,7 @@ public class LdapCompensatingTransactionOperationFactory implements
|
||||
*
|
||||
* @see org.springframework.ldap.ContextSource#getReadOnlyContext()
|
||||
*/
|
||||
public DirContext getReadOnlyContext() throws DataAccessException {
|
||||
public DirContext getReadOnlyContext() throws NamingException {
|
||||
return getNonClosingDirContextProxy(ctx);
|
||||
}
|
||||
|
||||
@@ -118,7 +118,7 @@ public class LdapCompensatingTransactionOperationFactory implements
|
||||
*
|
||||
* @see org.springframework.ldap.ContextSource#getReadWriteContext()
|
||||
*/
|
||||
public DirContext getReadWriteContext() throws DataAccessException {
|
||||
public DirContext getReadWriteContext() throws NamingException {
|
||||
return getNonClosingDirContextProxy(ctx);
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ import java.lang.reflect.Proxy;
|
||||
|
||||
import javax.naming.directory.DirContext;
|
||||
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.ldap.NamingException;
|
||||
import org.springframework.ldap.core.ContextSource;
|
||||
import org.springframework.ldap.support.LdapUtils;
|
||||
import org.springframework.transaction.support.TransactionSynchronizationManager;
|
||||
@@ -61,7 +61,7 @@ public class TransactionAwareContextSourceProxy implements ContextSource {
|
||||
*
|
||||
* @see org.springframework.ldap.core.ContextSource#getReadOnlyContext()
|
||||
*/
|
||||
public DirContext getReadOnlyContext() throws DataAccessException {
|
||||
public DirContext getReadOnlyContext() throws NamingException {
|
||||
return getReadWriteContext();
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ public class TransactionAwareContextSourceProxy implements ContextSource {
|
||||
*
|
||||
* @see org.springframework.ldap.core.ContextSource#getReadWriteContext()
|
||||
*/
|
||||
public DirContext getReadWriteContext() throws DataAccessException {
|
||||
public DirContext getReadWriteContext() throws NamingException {
|
||||
DirContextHolder contextHolder = (DirContextHolder) TransactionSynchronizationManager
|
||||
.getResource(target);
|
||||
DirContext ctx = null;
|
||||
|
||||
Reference in New Issue
Block a user