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