001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
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    }