org.acegisecurity.domain.dao.DetachmentContextHolder Maven / Gradle / Ivy
/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
*
* 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.acegisecurity.domain.dao;
/**
* InheritableThreadLocal
which indicates whether a {@link Dao} implementation should be forced to
* return a detached instance.A detached instance is one which is no longer associated with the ORM mapper and
* changes will therefore not be transparently persisted to the database.
* Not all Dao
implementations support the concept of detached instances.
*
* @author Ben Alex
* @version $Id: DetachmentContextHolder.java 1496 2006-05-23 13:38:33Z benalex $
*
* @see java.lang.InheritableThreadLocal
*/
public class DetachmentContextHolder {
//~ Static fields/initializers =====================================================================================
private static InheritableThreadLocal contextHolder = new InheritableThreadLocal();
//~ Methods ========================================================================================================
/**
* Returns the boolean value detachment policy which has been set for the current thread (defaults to
* false).
*
* @return DOCUMENT ME!
*/
public static boolean isForceReturnOfDetachedInstances() {
if (contextHolder.get() == null) {
contextHolder.set(Boolean.FALSE);
}
return contextHolder.get().booleanValue();
}
/**
* Sets whether or not detached domain object instances should be returned within the current thread of
* execution.
*
* @param alwaysReturnDetached if true then detached instances should be returned.
*/
public static void setForceReturnOfDetachedInstances(boolean alwaysReturnDetached) {
contextHolder.set(new Boolean(alwaysReturnDetached));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy