001    /**
002     * Copyright (c) 2000-present 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.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    @Deprecated
028    public class BatchSessionImpl implements BatchSession {
029    
030            @Override
031            public void delete(Session session, BaseModel<?> model)
032                    throws ORMException {
033    
034                    if (!session.contains(model)) {
035                            model = (BaseModel<?>)session.get(
036                                    model.getClass(), model.getPrimaryKeyObj());
037                    }
038    
039                    if (model != null) {
040                            session.delete(model);
041                    }
042            }
043    
044            @Override
045            public boolean isEnabled() {
046                    return _enabled.get();
047            }
048    
049            @Override
050            public void setEnabled(boolean enabled) {
051                    _enabled.set(enabled);
052            }
053    
054            @Override
055            public void update(Session session, BaseModel<?> model, boolean merge)
056                    throws ORMException {
057    
058                    if (model.isNew()) {
059                            session.save(model);
060    
061                            model.setNew(false);
062                    }
063                    else {
064                            session.merge(model);
065                    }
066            }
067    
068            private static final ThreadLocal<Boolean> _enabled =
069                    new InitialThreadLocal<>(BatchSessionImpl.class + "._enabled", false);
070    
071    }