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