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.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.model.BaseModel;
020    
021    /**
022     * Tracks database updates and flushes them from the session in batches.
023     *
024     * <p>
025     * Although all database updates ultimately pass through this class, its
026     * batching functionality is only used for large sets of contiguous updates. For
027     * usage examples see {@link
028     * com.liferay.portal.service.impl.LayoutLocalServiceImpl#importLayouts(long,
029     * long, boolean, java.util.Map, java.io.File)}, and {@link
030     * com.liferay.portal.verify.VerifyProcessUtil#verifyProcess(boolean, boolean)}.
031     * </p>
032     *
033     * @author     Raymond Aug??
034     * @author     Brian Wing Shun Chan
035     * @deprecated As of 6.2.0, see LPS-30598.
036     */
037    public interface BatchSession {
038    
039            /**
040             * Deletes the model instance in the database, and possibly flushes the
041             * session.
042             *
043             * <p>
044             * The session will be flushed if one of the following is <code>true</code>:
045             * </p>
046             *
047             * <ul>
048             * <li>
049             * Update batching is disabled
050             * </li>
051             * <li>
052             * The batch size is set to zero
053             * </li>
054             * <li>
055             * Enough updates and/or deletions have been queued to fill another batch
056             * </li>
057             * </ul>
058             *
059             * <p>
060             * The batch size may be set in portal.properties with the key
061             * <code>hibernate.jdbc.batch_size</code>.
062             * </p>
063             *
064             * @param  session the session to perform the update on
065             * @param  model the model instance to update
066             * @throws ORMException if a database exception occurred
067             */
068            public void delete(Session session, BaseModel<?> model) throws ORMException;
069    
070            /**
071             * Returns <code>true</code> if update batching is enabled
072             *
073             * @return <code>true</code> if update batching is enabled;
074             *         <code>false</code> otherwise
075             */
076            public boolean isEnabled();
077    
078            /**
079             * Sets whether update batching is enabled.
080             *
081             * @param enabled whether update batching is enabled.
082             */
083            public void setEnabled(boolean enabled);
084    
085            /**
086             * Updates the model instance in the database or adds it if it does not yet
087             * exist, and possibly flushes the session.
088             *
089             * <p>
090             * The session will be flushed if one of the following is <code>true</code>:
091             * </p>
092             *
093             * <ul>
094             * <li>
095             * Update batching is disabled
096             * </li>
097             * <li>
098             * The batch size is set to zero
099             * </li>
100             * <li>
101             * Enough updates/or deletions have been queued to fill another batch
102             * </li>
103             * </ul>
104             *
105             * <p>
106             * The batch size may be set in portal.properties with the key
107             * <code>hibernate.jdbc.batch_size</code>.
108             * </p>
109             *
110             * <p>
111             * The <code>merge</code> parameter controls a special case of persistence.
112             * If the session that a model instance was originally loaded from is
113             * closed, that instance becomes &quot;detached&quot;, and changes to it
114             * will not be persisted automatically. To persist its changes, the detached
115             * instance must be merged with the current session. This will load a new
116             * copy of the model instance from the database, copy the changes to it, and
117             * persist it.
118             * </p>
119             *
120             * <p>
121             * This process is most commonly necessary if a model instance is modified
122             * in the controller or view, as the database session is closed when control
123             * leaves the model layer. However, local service update model methods use
124             * merging by default, so in most cases this nuance is handled
125             * automatically. See {@link
126             * com.liferay.portal.service.UserLocalService#updateUser(
127             * com.liferay.portal.model.User)} for an example.
128             * </p>
129             *
130             * @param  session the session
131             * @param  model the model instance
132             * @param  merge whether to merge the model instance with the current
133             *         session
134             * @throws ORMException if a database exception occurred
135             */
136            public void update(Session session, BaseModel<?> model, boolean merge)
137                    throws ORMException;
138    
139    }