001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.kernel.util;
016    
017    import com.liferay.portal.kernel.log.Log;
018    import com.liferay.portal.kernel.log.LogFactoryUtil;
019    import com.liferay.portal.model.GroupConstants;
020    
021    /**
022     * @author Shinn Lok
023     */
024    public class GroupThreadLocal {
025    
026            public static Long getGroupId() {
027                    Long groupId = _groupId.get();
028    
029                    if (_log.isDebugEnabled()) {
030                            _log.debug("getGroupId " + groupId);
031                    }
032    
033                    return groupId;
034            }
035    
036            public static boolean isDeleteInProcess() {
037                    return _deleteInProcess.get();
038            }
039    
040            public static void setDeleteInProcess(boolean deleteInProcess) {
041                    _deleteInProcess.set(deleteInProcess);
042            }
043    
044            public static void setGroupId(Long groupId) {
045                    if (_log.isDebugEnabled()) {
046                            _log.debug("setGroupId " + groupId);
047                    }
048    
049                    if (groupId > 0) {
050                            _groupId.set(groupId);
051                    }
052                    else {
053                            _groupId.set(GroupConstants.DEFAULT_LIVE_GROUP_ID);
054                    }
055            }
056    
057            private static Log _log = LogFactoryUtil.getLog(GroupThreadLocal.class);
058    
059            private static ThreadLocal<Boolean> _deleteInProcess =
060                    new AutoResetThreadLocal<Boolean>(
061                            GroupThreadLocal.class + "._deleteInProcess", false);
062            private static ThreadLocal<Long> _groupId =
063                    new AutoResetThreadLocal<Long>(
064                            GroupThreadLocal.class + "._groupId",
065                            GroupConstants.DEFAULT_LIVE_GROUP_ID);
066    
067    }