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.service.persistence;
016    
017    import com.liferay.portal.kernel.dao.orm.ORMException;
018    import com.liferay.portal.kernel.dao.orm.Session;
019    import com.liferay.portal.kernel.util.InitialThreadLocal;
020    import com.liferay.portal.model.BaseModel;
021    
022    /**
023     * @author     Raymond Aug??
024     * @author     Brian Wing Shun Chan
025     * @deprecated As of 6.2.0, see LPS-30598.
026     */
027    public class BatchSessionImpl implements BatchSession {
028    
029            @Override
030            public void delete(Session session, BaseModel<?> model)
031                    throws ORMException {
032    
033                    if (!session.contains(model)) {
034                            model = (BaseModel<?>)session.get(
035                                    model.getClass(), model.getPrimaryKeyObj());
036                    }
037    
038                    if (model != null) {
039                            session.delete(model);
040                    }
041            }
042    
043            @Override
044            public boolean isEnabled() {
045                    return _enabled.get();
046            }
047    
048            @Override
049            public void setEnabled(boolean enabled) {
050                    _enabled.set(enabled);
051            }
052    
053            @Override
054            public void update(Session session, BaseModel<?> model, boolean merge)
055                    throws ORMException {
056    
057                    if (model.isNew()) {
058                            session.save(model);
059    
060                            model.setNew(false);
061                    }
062                    else {
063                            session.merge(model);
064                    }
065            }
066    
067            private static ThreadLocal<Boolean> _enabled =
068                    new InitialThreadLocal<Boolean>(
069                            BatchSessionImpl.class + "._enabled", false);
070    
071    }