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.NoSuchPluginSettingException;
018    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
019    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
020    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderPath;
022    import com.liferay.portal.kernel.dao.orm.Query;
023    import com.liferay.portal.kernel.dao.orm.QueryPos;
024    import com.liferay.portal.kernel.dao.orm.QueryUtil;
025    import com.liferay.portal.kernel.dao.orm.Session;
026    import com.liferay.portal.kernel.exception.SystemException;
027    import com.liferay.portal.kernel.log.Log;
028    import com.liferay.portal.kernel.log.LogFactoryUtil;
029    import com.liferay.portal.kernel.util.GetterUtil;
030    import com.liferay.portal.kernel.util.InstanceFactory;
031    import com.liferay.portal.kernel.util.OrderByComparator;
032    import com.liferay.portal.kernel.util.StringBundler;
033    import com.liferay.portal.kernel.util.StringPool;
034    import com.liferay.portal.kernel.util.StringUtil;
035    import com.liferay.portal.kernel.util.UnmodifiableList;
036    import com.liferay.portal.kernel.util.Validator;
037    import com.liferay.portal.model.CacheModel;
038    import com.liferay.portal.model.ModelListener;
039    import com.liferay.portal.model.PluginSetting;
040    import com.liferay.portal.model.impl.PluginSettingImpl;
041    import com.liferay.portal.model.impl.PluginSettingModelImpl;
042    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
043    
044    import java.io.Serializable;
045    
046    import java.util.ArrayList;
047    import java.util.Collections;
048    import java.util.List;
049    
050    /**
051     * The persistence implementation for the plugin setting service.
052     *
053     * <p>
054     * Caching information and settings can be found in <code>portal.properties</code>
055     * </p>
056     *
057     * @author Brian Wing Shun Chan
058     * @see PluginSettingPersistence
059     * @see PluginSettingUtil
060     * @generated
061     */
062    public class PluginSettingPersistenceImpl extends BasePersistenceImpl<PluginSetting>
063            implements PluginSettingPersistence {
064            /*
065             * NOTE FOR DEVELOPERS:
066             *
067             * Never modify or reference this class directly. Always use {@link PluginSettingUtil} to access the plugin setting persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
068             */
069            public static final String FINDER_CLASS_NAME_ENTITY = PluginSettingImpl.class.getName();
070            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
071                    ".List1";
072            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
073                    ".List2";
074            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(PluginSettingModelImpl.ENTITY_CACHE_ENABLED,
075                            PluginSettingModelImpl.FINDER_CACHE_ENABLED,
076                            PluginSettingImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
077                            "findAll", new String[0]);
078            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(PluginSettingModelImpl.ENTITY_CACHE_ENABLED,
079                            PluginSettingModelImpl.FINDER_CACHE_ENABLED,
080                            PluginSettingImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
081                            "findAll", new String[0]);
082            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(PluginSettingModelImpl.ENTITY_CACHE_ENABLED,
083                            PluginSettingModelImpl.FINDER_CACHE_ENABLED, Long.class,
084                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
085            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
086                    new FinderPath(PluginSettingModelImpl.ENTITY_CACHE_ENABLED,
087                            PluginSettingModelImpl.FINDER_CACHE_ENABLED,
088                            PluginSettingImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
089                            "findByCompanyId",
090                            new String[] {
091                                    Long.class.getName(),
092                                    
093                            Integer.class.getName(), Integer.class.getName(),
094                                    OrderByComparator.class.getName()
095                            });
096            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
097                    new FinderPath(PluginSettingModelImpl.ENTITY_CACHE_ENABLED,
098                            PluginSettingModelImpl.FINDER_CACHE_ENABLED,
099                            PluginSettingImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
100                            "findByCompanyId", new String[] { Long.class.getName() },
101                            PluginSettingModelImpl.COMPANYID_COLUMN_BITMASK);
102            public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(PluginSettingModelImpl.ENTITY_CACHE_ENABLED,
103                            PluginSettingModelImpl.FINDER_CACHE_ENABLED, Long.class,
104                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
105                            new String[] { Long.class.getName() });
106    
107            /**
108             * Returns all the plugin settings where companyId = &#63;.
109             *
110             * @param companyId the company ID
111             * @return the matching plugin settings
112             * @throws SystemException if a system exception occurred
113             */
114            public List<PluginSetting> findByCompanyId(long companyId)
115                    throws SystemException {
116                    return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
117                            null);
118            }
119    
120            /**
121             * Returns a range of all the plugin settings where companyId = &#63;.
122             *
123             * <p>
124             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.PluginSettingModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
125             * </p>
126             *
127             * @param companyId the company ID
128             * @param start the lower bound of the range of plugin settings
129             * @param end the upper bound of the range of plugin settings (not inclusive)
130             * @return the range of matching plugin settings
131             * @throws SystemException if a system exception occurred
132             */
133            public List<PluginSetting> findByCompanyId(long companyId, int start,
134                    int end) throws SystemException {
135                    return findByCompanyId(companyId, start, end, null);
136            }
137    
138            /**
139             * Returns an ordered range of all the plugin settings where companyId = &#63;.
140             *
141             * <p>
142             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.PluginSettingModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
143             * </p>
144             *
145             * @param companyId the company ID
146             * @param start the lower bound of the range of plugin settings
147             * @param end the upper bound of the range of plugin settings (not inclusive)
148             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
149             * @return the ordered range of matching plugin settings
150             * @throws SystemException if a system exception occurred
151             */
152            public List<PluginSetting> findByCompanyId(long companyId, int start,
153                    int end, OrderByComparator orderByComparator) throws SystemException {
154                    boolean pagination = true;
155                    FinderPath finderPath = null;
156                    Object[] finderArgs = null;
157    
158                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
159                                    (orderByComparator == null)) {
160                            pagination = false;
161                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
162                            finderArgs = new Object[] { companyId };
163                    }
164                    else {
165                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
166                            finderArgs = new Object[] { companyId, start, end, orderByComparator };
167                    }
168    
169                    List<PluginSetting> list = (List<PluginSetting>)FinderCacheUtil.getResult(finderPath,
170                                    finderArgs, this);
171    
172                    if ((list != null) && !list.isEmpty()) {
173                            for (PluginSetting pluginSetting : list) {
174                                    if ((companyId != pluginSetting.getCompanyId())) {
175                                            list = null;
176    
177                                            break;
178                                    }
179                            }
180                    }
181    
182                    if (list == null) {
183                            StringBundler query = null;
184    
185                            if (orderByComparator != null) {
186                                    query = new StringBundler(3 +
187                                                    (orderByComparator.getOrderByFields().length * 3));
188                            }
189                            else {
190                                    query = new StringBundler(3);
191                            }
192    
193                            query.append(_SQL_SELECT_PLUGINSETTING_WHERE);
194    
195                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
196    
197                            if (orderByComparator != null) {
198                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
199                                            orderByComparator);
200                            }
201                            else
202                             if (pagination) {
203                                    query.append(PluginSettingModelImpl.ORDER_BY_JPQL);
204                            }
205    
206                            String sql = query.toString();
207    
208                            Session session = null;
209    
210                            try {
211                                    session = openSession();
212    
213                                    Query q = session.createQuery(sql);
214    
215                                    QueryPos qPos = QueryPos.getInstance(q);
216    
217                                    qPos.add(companyId);
218    
219                                    if (!pagination) {
220                                            list = (List<PluginSetting>)QueryUtil.list(q, getDialect(),
221                                                            start, end, false);
222    
223                                            Collections.sort(list);
224    
225                                            list = new UnmodifiableList<PluginSetting>(list);
226                                    }
227                                    else {
228                                            list = (List<PluginSetting>)QueryUtil.list(q, getDialect(),
229                                                            start, end);
230                                    }
231    
232                                    cacheResult(list);
233    
234                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
235                            }
236                            catch (Exception e) {
237                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
238    
239                                    throw processException(e);
240                            }
241                            finally {
242                                    closeSession(session);
243                            }
244                    }
245    
246                    return list;
247            }
248    
249            /**
250             * Returns the first plugin setting in the ordered set where companyId = &#63;.
251             *
252             * @param companyId the company ID
253             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
254             * @return the first matching plugin setting
255             * @throws com.liferay.portal.NoSuchPluginSettingException if a matching plugin setting could not be found
256             * @throws SystemException if a system exception occurred
257             */
258            public PluginSetting findByCompanyId_First(long companyId,
259                    OrderByComparator orderByComparator)
260                    throws NoSuchPluginSettingException, SystemException {
261                    PluginSetting pluginSetting = fetchByCompanyId_First(companyId,
262                                    orderByComparator);
263    
264                    if (pluginSetting != null) {
265                            return pluginSetting;
266                    }
267    
268                    StringBundler msg = new StringBundler(4);
269    
270                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
271    
272                    msg.append("companyId=");
273                    msg.append(companyId);
274    
275                    msg.append(StringPool.CLOSE_CURLY_BRACE);
276    
277                    throw new NoSuchPluginSettingException(msg.toString());
278            }
279    
280            /**
281             * Returns the first plugin setting in the ordered set where companyId = &#63;.
282             *
283             * @param companyId the company ID
284             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
285             * @return the first matching plugin setting, or <code>null</code> if a matching plugin setting could not be found
286             * @throws SystemException if a system exception occurred
287             */
288            public PluginSetting fetchByCompanyId_First(long companyId,
289                    OrderByComparator orderByComparator) throws SystemException {
290                    List<PluginSetting> list = findByCompanyId(companyId, 0, 1,
291                                    orderByComparator);
292    
293                    if (!list.isEmpty()) {
294                            return list.get(0);
295                    }
296    
297                    return null;
298            }
299    
300            /**
301             * Returns the last plugin setting in the ordered set where companyId = &#63;.
302             *
303             * @param companyId the company ID
304             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
305             * @return the last matching plugin setting
306             * @throws com.liferay.portal.NoSuchPluginSettingException if a matching plugin setting could not be found
307             * @throws SystemException if a system exception occurred
308             */
309            public PluginSetting findByCompanyId_Last(long companyId,
310                    OrderByComparator orderByComparator)
311                    throws NoSuchPluginSettingException, SystemException {
312                    PluginSetting pluginSetting = fetchByCompanyId_Last(companyId,
313                                    orderByComparator);
314    
315                    if (pluginSetting != null) {
316                            return pluginSetting;
317                    }
318    
319                    StringBundler msg = new StringBundler(4);
320    
321                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
322    
323                    msg.append("companyId=");
324                    msg.append(companyId);
325    
326                    msg.append(StringPool.CLOSE_CURLY_BRACE);
327    
328                    throw new NoSuchPluginSettingException(msg.toString());
329            }
330    
331            /**
332             * Returns the last plugin setting in the ordered set where companyId = &#63;.
333             *
334             * @param companyId the company ID
335             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
336             * @return the last matching plugin setting, or <code>null</code> if a matching plugin setting could not be found
337             * @throws SystemException if a system exception occurred
338             */
339            public PluginSetting fetchByCompanyId_Last(long companyId,
340                    OrderByComparator orderByComparator) throws SystemException {
341                    int count = countByCompanyId(companyId);
342    
343                    List<PluginSetting> list = findByCompanyId(companyId, count - 1, count,
344                                    orderByComparator);
345    
346                    if (!list.isEmpty()) {
347                            return list.get(0);
348                    }
349    
350                    return null;
351            }
352    
353            /**
354             * Returns the plugin settings before and after the current plugin setting in the ordered set where companyId = &#63;.
355             *
356             * @param pluginSettingId the primary key of the current plugin setting
357             * @param companyId the company ID
358             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
359             * @return the previous, current, and next plugin setting
360             * @throws com.liferay.portal.NoSuchPluginSettingException if a plugin setting with the primary key could not be found
361             * @throws SystemException if a system exception occurred
362             */
363            public PluginSetting[] findByCompanyId_PrevAndNext(long pluginSettingId,
364                    long companyId, OrderByComparator orderByComparator)
365                    throws NoSuchPluginSettingException, SystemException {
366                    PluginSetting pluginSetting = findByPrimaryKey(pluginSettingId);
367    
368                    Session session = null;
369    
370                    try {
371                            session = openSession();
372    
373                            PluginSetting[] array = new PluginSettingImpl[3];
374    
375                            array[0] = getByCompanyId_PrevAndNext(session, pluginSetting,
376                                            companyId, orderByComparator, true);
377    
378                            array[1] = pluginSetting;
379    
380                            array[2] = getByCompanyId_PrevAndNext(session, pluginSetting,
381                                            companyId, orderByComparator, false);
382    
383                            return array;
384                    }
385                    catch (Exception e) {
386                            throw processException(e);
387                    }
388                    finally {
389                            closeSession(session);
390                    }
391            }
392    
393            protected PluginSetting getByCompanyId_PrevAndNext(Session session,
394                    PluginSetting pluginSetting, long companyId,
395                    OrderByComparator orderByComparator, boolean previous) {
396                    StringBundler query = null;
397    
398                    if (orderByComparator != null) {
399                            query = new StringBundler(6 +
400                                            (orderByComparator.getOrderByFields().length * 6));
401                    }
402                    else {
403                            query = new StringBundler(3);
404                    }
405    
406                    query.append(_SQL_SELECT_PLUGINSETTING_WHERE);
407    
408                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
409    
410                    if (orderByComparator != null) {
411                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
412    
413                            if (orderByConditionFields.length > 0) {
414                                    query.append(WHERE_AND);
415                            }
416    
417                            for (int i = 0; i < orderByConditionFields.length; i++) {
418                                    query.append(_ORDER_BY_ENTITY_ALIAS);
419                                    query.append(orderByConditionFields[i]);
420    
421                                    if ((i + 1) < orderByConditionFields.length) {
422                                            if (orderByComparator.isAscending() ^ previous) {
423                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
424                                            }
425                                            else {
426                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
427                                            }
428                                    }
429                                    else {
430                                            if (orderByComparator.isAscending() ^ previous) {
431                                                    query.append(WHERE_GREATER_THAN);
432                                            }
433                                            else {
434                                                    query.append(WHERE_LESSER_THAN);
435                                            }
436                                    }
437                            }
438    
439                            query.append(ORDER_BY_CLAUSE);
440    
441                            String[] orderByFields = orderByComparator.getOrderByFields();
442    
443                            for (int i = 0; i < orderByFields.length; i++) {
444                                    query.append(_ORDER_BY_ENTITY_ALIAS);
445                                    query.append(orderByFields[i]);
446    
447                                    if ((i + 1) < orderByFields.length) {
448                                            if (orderByComparator.isAscending() ^ previous) {
449                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
450                                            }
451                                            else {
452                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
453                                            }
454                                    }
455                                    else {
456                                            if (orderByComparator.isAscending() ^ previous) {
457                                                    query.append(ORDER_BY_ASC);
458                                            }
459                                            else {
460                                                    query.append(ORDER_BY_DESC);
461                                            }
462                                    }
463                            }
464                    }
465                    else {
466                            query.append(PluginSettingModelImpl.ORDER_BY_JPQL);
467                    }
468    
469                    String sql = query.toString();
470    
471                    Query q = session.createQuery(sql);
472    
473                    q.setFirstResult(0);
474                    q.setMaxResults(2);
475    
476                    QueryPos qPos = QueryPos.getInstance(q);
477    
478                    qPos.add(companyId);
479    
480                    if (orderByComparator != null) {
481                            Object[] values = orderByComparator.getOrderByConditionValues(pluginSetting);
482    
483                            for (Object value : values) {
484                                    qPos.add(value);
485                            }
486                    }
487    
488                    List<PluginSetting> list = q.list();
489    
490                    if (list.size() == 2) {
491                            return list.get(1);
492                    }
493                    else {
494                            return null;
495                    }
496            }
497    
498            /**
499             * Removes all the plugin settings where companyId = &#63; from the database.
500             *
501             * @param companyId the company ID
502             * @throws SystemException if a system exception occurred
503             */
504            public void removeByCompanyId(long companyId) throws SystemException {
505                    for (PluginSetting pluginSetting : findByCompanyId(companyId,
506                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
507                            remove(pluginSetting);
508                    }
509            }
510    
511            /**
512             * Returns the number of plugin settings where companyId = &#63;.
513             *
514             * @param companyId the company ID
515             * @return the number of matching plugin settings
516             * @throws SystemException if a system exception occurred
517             */
518            public int countByCompanyId(long companyId) throws SystemException {
519                    FinderPath finderPath = FINDER_PATH_COUNT_BY_COMPANYID;
520    
521                    Object[] finderArgs = new Object[] { companyId };
522    
523                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
524                                    this);
525    
526                    if (count == null) {
527                            StringBundler query = new StringBundler(2);
528    
529                            query.append(_SQL_COUNT_PLUGINSETTING_WHERE);
530    
531                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
532    
533                            String sql = query.toString();
534    
535                            Session session = null;
536    
537                            try {
538                                    session = openSession();
539    
540                                    Query q = session.createQuery(sql);
541    
542                                    QueryPos qPos = QueryPos.getInstance(q);
543    
544                                    qPos.add(companyId);
545    
546                                    count = (Long)q.uniqueResult();
547    
548                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
549                            }
550                            catch (Exception e) {
551                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
552    
553                                    throw processException(e);
554                            }
555                            finally {
556                                    closeSession(session);
557                            }
558                    }
559    
560                    return count.intValue();
561            }
562    
563            private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "pluginSetting.companyId = ?";
564            public static final FinderPath FINDER_PATH_FETCH_BY_C_I_T = new FinderPath(PluginSettingModelImpl.ENTITY_CACHE_ENABLED,
565                            PluginSettingModelImpl.FINDER_CACHE_ENABLED,
566                            PluginSettingImpl.class, FINDER_CLASS_NAME_ENTITY, "fetchByC_I_T",
567                            new String[] {
568                                    Long.class.getName(), String.class.getName(),
569                                    String.class.getName()
570                            },
571                            PluginSettingModelImpl.COMPANYID_COLUMN_BITMASK |
572                            PluginSettingModelImpl.PLUGINID_COLUMN_BITMASK |
573                            PluginSettingModelImpl.PLUGINTYPE_COLUMN_BITMASK);
574            public static final FinderPath FINDER_PATH_COUNT_BY_C_I_T = new FinderPath(PluginSettingModelImpl.ENTITY_CACHE_ENABLED,
575                            PluginSettingModelImpl.FINDER_CACHE_ENABLED, Long.class,
576                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_I_T",
577                            new String[] {
578                                    Long.class.getName(), String.class.getName(),
579                                    String.class.getName()
580                            });
581    
582            /**
583             * Returns the plugin setting where companyId = &#63; and pluginId = &#63; and pluginType = &#63; or throws a {@link com.liferay.portal.NoSuchPluginSettingException} if it could not be found.
584             *
585             * @param companyId the company ID
586             * @param pluginId the plugin ID
587             * @param pluginType the plugin type
588             * @return the matching plugin setting
589             * @throws com.liferay.portal.NoSuchPluginSettingException if a matching plugin setting could not be found
590             * @throws SystemException if a system exception occurred
591             */
592            public PluginSetting findByC_I_T(long companyId, String pluginId,
593                    String pluginType) throws NoSuchPluginSettingException, SystemException {
594                    PluginSetting pluginSetting = fetchByC_I_T(companyId, pluginId,
595                                    pluginType);
596    
597                    if (pluginSetting == null) {
598                            StringBundler msg = new StringBundler(8);
599    
600                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
601    
602                            msg.append("companyId=");
603                            msg.append(companyId);
604    
605                            msg.append(", pluginId=");
606                            msg.append(pluginId);
607    
608                            msg.append(", pluginType=");
609                            msg.append(pluginType);
610    
611                            msg.append(StringPool.CLOSE_CURLY_BRACE);
612    
613                            if (_log.isWarnEnabled()) {
614                                    _log.warn(msg.toString());
615                            }
616    
617                            throw new NoSuchPluginSettingException(msg.toString());
618                    }
619    
620                    return pluginSetting;
621            }
622    
623            /**
624             * Returns the plugin setting where companyId = &#63; and pluginId = &#63; and pluginType = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
625             *
626             * @param companyId the company ID
627             * @param pluginId the plugin ID
628             * @param pluginType the plugin type
629             * @return the matching plugin setting, or <code>null</code> if a matching plugin setting could not be found
630             * @throws SystemException if a system exception occurred
631             */
632            public PluginSetting fetchByC_I_T(long companyId, String pluginId,
633                    String pluginType) throws SystemException {
634                    return fetchByC_I_T(companyId, pluginId, pluginType, true);
635            }
636    
637            /**
638             * Returns the plugin setting where companyId = &#63; and pluginId = &#63; and pluginType = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
639             *
640             * @param companyId the company ID
641             * @param pluginId the plugin ID
642             * @param pluginType the plugin type
643             * @param retrieveFromCache whether to use the finder cache
644             * @return the matching plugin setting, or <code>null</code> if a matching plugin setting could not be found
645             * @throws SystemException if a system exception occurred
646             */
647            public PluginSetting fetchByC_I_T(long companyId, String pluginId,
648                    String pluginType, boolean retrieveFromCache) throws SystemException {
649                    Object[] finderArgs = new Object[] { companyId, pluginId, pluginType };
650    
651                    Object result = null;
652    
653                    if (retrieveFromCache) {
654                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_I_T,
655                                            finderArgs, this);
656                    }
657    
658                    if (result instanceof PluginSetting) {
659                            PluginSetting pluginSetting = (PluginSetting)result;
660    
661                            if ((companyId != pluginSetting.getCompanyId()) ||
662                                            !Validator.equals(pluginId, pluginSetting.getPluginId()) ||
663                                            !Validator.equals(pluginType, pluginSetting.getPluginType())) {
664                                    result = null;
665                            }
666                    }
667    
668                    if (result == null) {
669                            StringBundler query = new StringBundler(5);
670    
671                            query.append(_SQL_SELECT_PLUGINSETTING_WHERE);
672    
673                            query.append(_FINDER_COLUMN_C_I_T_COMPANYID_2);
674    
675                            boolean bindPluginId = false;
676    
677                            if (pluginId == null) {
678                                    query.append(_FINDER_COLUMN_C_I_T_PLUGINID_1);
679                            }
680                            else if (pluginId.equals(StringPool.BLANK)) {
681                                    query.append(_FINDER_COLUMN_C_I_T_PLUGINID_3);
682                            }
683                            else {
684                                    bindPluginId = true;
685    
686                                    query.append(_FINDER_COLUMN_C_I_T_PLUGINID_2);
687                            }
688    
689                            boolean bindPluginType = false;
690    
691                            if (pluginType == null) {
692                                    query.append(_FINDER_COLUMN_C_I_T_PLUGINTYPE_1);
693                            }
694                            else if (pluginType.equals(StringPool.BLANK)) {
695                                    query.append(_FINDER_COLUMN_C_I_T_PLUGINTYPE_3);
696                            }
697                            else {
698                                    bindPluginType = true;
699    
700                                    query.append(_FINDER_COLUMN_C_I_T_PLUGINTYPE_2);
701                            }
702    
703                            String sql = query.toString();
704    
705                            Session session = null;
706    
707                            try {
708                                    session = openSession();
709    
710                                    Query q = session.createQuery(sql);
711    
712                                    QueryPos qPos = QueryPos.getInstance(q);
713    
714                                    qPos.add(companyId);
715    
716                                    if (bindPluginId) {
717                                            qPos.add(pluginId);
718                                    }
719    
720                                    if (bindPluginType) {
721                                            qPos.add(pluginType);
722                                    }
723    
724                                    List<PluginSetting> list = q.list();
725    
726                                    if (list.isEmpty()) {
727                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_I_T,
728                                                    finderArgs, list);
729                                    }
730                                    else {
731                                            PluginSetting pluginSetting = list.get(0);
732    
733                                            result = pluginSetting;
734    
735                                            cacheResult(pluginSetting);
736    
737                                            if ((pluginSetting.getCompanyId() != companyId) ||
738                                                            (pluginSetting.getPluginId() == null) ||
739                                                            !pluginSetting.getPluginId().equals(pluginId) ||
740                                                            (pluginSetting.getPluginType() == null) ||
741                                                            !pluginSetting.getPluginType().equals(pluginType)) {
742                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_I_T,
743                                                            finderArgs, pluginSetting);
744                                            }
745                                    }
746                            }
747                            catch (Exception e) {
748                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_I_T,
749                                            finderArgs);
750    
751                                    throw processException(e);
752                            }
753                            finally {
754                                    closeSession(session);
755                            }
756                    }
757    
758                    if (result instanceof List<?>) {
759                            return null;
760                    }
761                    else {
762                            return (PluginSetting)result;
763                    }
764            }
765    
766            /**
767             * Removes the plugin setting where companyId = &#63; and pluginId = &#63; and pluginType = &#63; from the database.
768             *
769             * @param companyId the company ID
770             * @param pluginId the plugin ID
771             * @param pluginType the plugin type
772             * @return the plugin setting that was removed
773             * @throws SystemException if a system exception occurred
774             */
775            public PluginSetting removeByC_I_T(long companyId, String pluginId,
776                    String pluginType) throws NoSuchPluginSettingException, SystemException {
777                    PluginSetting pluginSetting = findByC_I_T(companyId, pluginId,
778                                    pluginType);
779    
780                    return remove(pluginSetting);
781            }
782    
783            /**
784             * Returns the number of plugin settings where companyId = &#63; and pluginId = &#63; and pluginType = &#63;.
785             *
786             * @param companyId the company ID
787             * @param pluginId the plugin ID
788             * @param pluginType the plugin type
789             * @return the number of matching plugin settings
790             * @throws SystemException if a system exception occurred
791             */
792            public int countByC_I_T(long companyId, String pluginId, String pluginType)
793                    throws SystemException {
794                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_I_T;
795    
796                    Object[] finderArgs = new Object[] { companyId, pluginId, pluginType };
797    
798                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
799                                    this);
800    
801                    if (count == null) {
802                            StringBundler query = new StringBundler(4);
803    
804                            query.append(_SQL_COUNT_PLUGINSETTING_WHERE);
805    
806                            query.append(_FINDER_COLUMN_C_I_T_COMPANYID_2);
807    
808                            boolean bindPluginId = false;
809    
810                            if (pluginId == null) {
811                                    query.append(_FINDER_COLUMN_C_I_T_PLUGINID_1);
812                            }
813                            else if (pluginId.equals(StringPool.BLANK)) {
814                                    query.append(_FINDER_COLUMN_C_I_T_PLUGINID_3);
815                            }
816                            else {
817                                    bindPluginId = true;
818    
819                                    query.append(_FINDER_COLUMN_C_I_T_PLUGINID_2);
820                            }
821    
822                            boolean bindPluginType = false;
823    
824                            if (pluginType == null) {
825                                    query.append(_FINDER_COLUMN_C_I_T_PLUGINTYPE_1);
826                            }
827                            else if (pluginType.equals(StringPool.BLANK)) {
828                                    query.append(_FINDER_COLUMN_C_I_T_PLUGINTYPE_3);
829                            }
830                            else {
831                                    bindPluginType = true;
832    
833                                    query.append(_FINDER_COLUMN_C_I_T_PLUGINTYPE_2);
834                            }
835    
836                            String sql = query.toString();
837    
838                            Session session = null;
839    
840                            try {
841                                    session = openSession();
842    
843                                    Query q = session.createQuery(sql);
844    
845                                    QueryPos qPos = QueryPos.getInstance(q);
846    
847                                    qPos.add(companyId);
848    
849                                    if (bindPluginId) {
850                                            qPos.add(pluginId);
851                                    }
852    
853                                    if (bindPluginType) {
854                                            qPos.add(pluginType);
855                                    }
856    
857                                    count = (Long)q.uniqueResult();
858    
859                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
860                            }
861                            catch (Exception e) {
862                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
863    
864                                    throw processException(e);
865                            }
866                            finally {
867                                    closeSession(session);
868                            }
869                    }
870    
871                    return count.intValue();
872            }
873    
874            private static final String _FINDER_COLUMN_C_I_T_COMPANYID_2 = "pluginSetting.companyId = ? AND ";
875            private static final String _FINDER_COLUMN_C_I_T_PLUGINID_1 = "pluginSetting.pluginId IS NULL AND ";
876            private static final String _FINDER_COLUMN_C_I_T_PLUGINID_2 = "pluginSetting.pluginId = ? AND ";
877            private static final String _FINDER_COLUMN_C_I_T_PLUGINID_3 = "(pluginSetting.pluginId IS NULL OR pluginSetting.pluginId = '') AND ";
878            private static final String _FINDER_COLUMN_C_I_T_PLUGINTYPE_1 = "pluginSetting.pluginType IS NULL";
879            private static final String _FINDER_COLUMN_C_I_T_PLUGINTYPE_2 = "pluginSetting.pluginType = ?";
880            private static final String _FINDER_COLUMN_C_I_T_PLUGINTYPE_3 = "(pluginSetting.pluginType IS NULL OR pluginSetting.pluginType = '')";
881    
882            /**
883             * Caches the plugin setting in the entity cache if it is enabled.
884             *
885             * @param pluginSetting the plugin setting
886             */
887            public void cacheResult(PluginSetting pluginSetting) {
888                    EntityCacheUtil.putResult(PluginSettingModelImpl.ENTITY_CACHE_ENABLED,
889                            PluginSettingImpl.class, pluginSetting.getPrimaryKey(),
890                            pluginSetting);
891    
892                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_I_T,
893                            new Object[] {
894                                    pluginSetting.getCompanyId(), pluginSetting.getPluginId(),
895                                    pluginSetting.getPluginType()
896                            }, pluginSetting);
897    
898                    pluginSetting.resetOriginalValues();
899            }
900    
901            /**
902             * Caches the plugin settings in the entity cache if it is enabled.
903             *
904             * @param pluginSettings the plugin settings
905             */
906            public void cacheResult(List<PluginSetting> pluginSettings) {
907                    for (PluginSetting pluginSetting : pluginSettings) {
908                            if (EntityCacheUtil.getResult(
909                                                    PluginSettingModelImpl.ENTITY_CACHE_ENABLED,
910                                                    PluginSettingImpl.class, pluginSetting.getPrimaryKey()) == null) {
911                                    cacheResult(pluginSetting);
912                            }
913                            else {
914                                    pluginSetting.resetOriginalValues();
915                            }
916                    }
917            }
918    
919            /**
920             * Clears the cache for all plugin settings.
921             *
922             * <p>
923             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
924             * </p>
925             */
926            @Override
927            public void clearCache() {
928                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
929                            CacheRegistryUtil.clear(PluginSettingImpl.class.getName());
930                    }
931    
932                    EntityCacheUtil.clearCache(PluginSettingImpl.class.getName());
933    
934                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
935                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
936                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
937            }
938    
939            /**
940             * Clears the cache for the plugin setting.
941             *
942             * <p>
943             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
944             * </p>
945             */
946            @Override
947            public void clearCache(PluginSetting pluginSetting) {
948                    EntityCacheUtil.removeResult(PluginSettingModelImpl.ENTITY_CACHE_ENABLED,
949                            PluginSettingImpl.class, pluginSetting.getPrimaryKey());
950    
951                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
952                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
953    
954                    clearUniqueFindersCache(pluginSetting);
955            }
956    
957            @Override
958            public void clearCache(List<PluginSetting> pluginSettings) {
959                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
960                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
961    
962                    for (PluginSetting pluginSetting : pluginSettings) {
963                            EntityCacheUtil.removeResult(PluginSettingModelImpl.ENTITY_CACHE_ENABLED,
964                                    PluginSettingImpl.class, pluginSetting.getPrimaryKey());
965    
966                            clearUniqueFindersCache(pluginSetting);
967                    }
968            }
969    
970            protected void cacheUniqueFindersCache(PluginSetting pluginSetting) {
971                    if (pluginSetting.isNew()) {
972                            Object[] args = new Object[] {
973                                            pluginSetting.getCompanyId(), pluginSetting.getPluginId(),
974                                            pluginSetting.getPluginType()
975                                    };
976    
977                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_I_T, args,
978                                    Long.valueOf(1));
979                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_I_T, args,
980                                    pluginSetting);
981                    }
982                    else {
983                            PluginSettingModelImpl pluginSettingModelImpl = (PluginSettingModelImpl)pluginSetting;
984    
985                            if ((pluginSettingModelImpl.getColumnBitmask() &
986                                            FINDER_PATH_FETCH_BY_C_I_T.getColumnBitmask()) != 0) {
987                                    Object[] args = new Object[] {
988                                                    pluginSetting.getCompanyId(),
989                                                    pluginSetting.getPluginId(),
990                                                    pluginSetting.getPluginType()
991                                            };
992    
993                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_I_T, args,
994                                            Long.valueOf(1));
995                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_I_T, args,
996                                            pluginSetting);
997                            }
998                    }
999            }
1000    
1001            protected void clearUniqueFindersCache(PluginSetting pluginSetting) {
1002                    PluginSettingModelImpl pluginSettingModelImpl = (PluginSettingModelImpl)pluginSetting;
1003    
1004                    Object[] args = new Object[] {
1005                                    pluginSetting.getCompanyId(), pluginSetting.getPluginId(),
1006                                    pluginSetting.getPluginType()
1007                            };
1008    
1009                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_I_T, args);
1010                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_I_T, args);
1011    
1012                    if ((pluginSettingModelImpl.getColumnBitmask() &
1013                                    FINDER_PATH_FETCH_BY_C_I_T.getColumnBitmask()) != 0) {
1014                            args = new Object[] {
1015                                            pluginSettingModelImpl.getOriginalCompanyId(),
1016                                            pluginSettingModelImpl.getOriginalPluginId(),
1017                                            pluginSettingModelImpl.getOriginalPluginType()
1018                                    };
1019    
1020                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_I_T, args);
1021                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_I_T, args);
1022                    }
1023            }
1024    
1025            /**
1026             * Creates a new plugin setting with the primary key. Does not add the plugin setting to the database.
1027             *
1028             * @param pluginSettingId the primary key for the new plugin setting
1029             * @return the new plugin setting
1030             */
1031            public PluginSetting create(long pluginSettingId) {
1032                    PluginSetting pluginSetting = new PluginSettingImpl();
1033    
1034                    pluginSetting.setNew(true);
1035                    pluginSetting.setPrimaryKey(pluginSettingId);
1036    
1037                    return pluginSetting;
1038            }
1039    
1040            /**
1041             * Removes the plugin setting with the primary key from the database. Also notifies the appropriate model listeners.
1042             *
1043             * @param pluginSettingId the primary key of the plugin setting
1044             * @return the plugin setting that was removed
1045             * @throws com.liferay.portal.NoSuchPluginSettingException if a plugin setting with the primary key could not be found
1046             * @throws SystemException if a system exception occurred
1047             */
1048            public PluginSetting remove(long pluginSettingId)
1049                    throws NoSuchPluginSettingException, SystemException {
1050                    return remove((Serializable)pluginSettingId);
1051            }
1052    
1053            /**
1054             * Removes the plugin setting with the primary key from the database. Also notifies the appropriate model listeners.
1055             *
1056             * @param primaryKey the primary key of the plugin setting
1057             * @return the plugin setting that was removed
1058             * @throws com.liferay.portal.NoSuchPluginSettingException if a plugin setting with the primary key could not be found
1059             * @throws SystemException if a system exception occurred
1060             */
1061            @Override
1062            public PluginSetting remove(Serializable primaryKey)
1063                    throws NoSuchPluginSettingException, SystemException {
1064                    Session session = null;
1065    
1066                    try {
1067                            session = openSession();
1068    
1069                            PluginSetting pluginSetting = (PluginSetting)session.get(PluginSettingImpl.class,
1070                                            primaryKey);
1071    
1072                            if (pluginSetting == null) {
1073                                    if (_log.isWarnEnabled()) {
1074                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1075                                    }
1076    
1077                                    throw new NoSuchPluginSettingException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1078                                            primaryKey);
1079                            }
1080    
1081                            return remove(pluginSetting);
1082                    }
1083                    catch (NoSuchPluginSettingException nsee) {
1084                            throw nsee;
1085                    }
1086                    catch (Exception e) {
1087                            throw processException(e);
1088                    }
1089                    finally {
1090                            closeSession(session);
1091                    }
1092            }
1093    
1094            @Override
1095            protected PluginSetting removeImpl(PluginSetting pluginSetting)
1096                    throws SystemException {
1097                    pluginSetting = toUnwrappedModel(pluginSetting);
1098    
1099                    Session session = null;
1100    
1101                    try {
1102                            session = openSession();
1103    
1104                            if (!session.contains(pluginSetting)) {
1105                                    pluginSetting = (PluginSetting)session.get(PluginSettingImpl.class,
1106                                                    pluginSetting.getPrimaryKeyObj());
1107                            }
1108    
1109                            if (pluginSetting != null) {
1110                                    session.delete(pluginSetting);
1111                            }
1112                    }
1113                    catch (Exception e) {
1114                            throw processException(e);
1115                    }
1116                    finally {
1117                            closeSession(session);
1118                    }
1119    
1120                    if (pluginSetting != null) {
1121                            clearCache(pluginSetting);
1122                    }
1123    
1124                    return pluginSetting;
1125            }
1126    
1127            @Override
1128            public PluginSetting updateImpl(
1129                    com.liferay.portal.model.PluginSetting pluginSetting)
1130                    throws SystemException {
1131                    pluginSetting = toUnwrappedModel(pluginSetting);
1132    
1133                    boolean isNew = pluginSetting.isNew();
1134    
1135                    PluginSettingModelImpl pluginSettingModelImpl = (PluginSettingModelImpl)pluginSetting;
1136    
1137                    Session session = null;
1138    
1139                    try {
1140                            session = openSession();
1141    
1142                            if (pluginSetting.isNew()) {
1143                                    session.save(pluginSetting);
1144    
1145                                    pluginSetting.setNew(false);
1146                            }
1147                            else {
1148                                    session.merge(pluginSetting);
1149                            }
1150                    }
1151                    catch (Exception e) {
1152                            throw processException(e);
1153                    }
1154                    finally {
1155                            closeSession(session);
1156                    }
1157    
1158                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1159    
1160                    if (isNew || !PluginSettingModelImpl.COLUMN_BITMASK_ENABLED) {
1161                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1162                    }
1163    
1164                    else {
1165                            if ((pluginSettingModelImpl.getColumnBitmask() &
1166                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
1167                                    Object[] args = new Object[] {
1168                                                    pluginSettingModelImpl.getOriginalCompanyId()
1169                                            };
1170    
1171                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
1172                                            args);
1173                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
1174                                            args);
1175    
1176                                    args = new Object[] { pluginSettingModelImpl.getCompanyId() };
1177    
1178                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
1179                                            args);
1180                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
1181                                            args);
1182                            }
1183                    }
1184    
1185                    EntityCacheUtil.putResult(PluginSettingModelImpl.ENTITY_CACHE_ENABLED,
1186                            PluginSettingImpl.class, pluginSetting.getPrimaryKey(),
1187                            pluginSetting);
1188    
1189                    clearUniqueFindersCache(pluginSetting);
1190                    cacheUniqueFindersCache(pluginSetting);
1191    
1192                    return pluginSetting;
1193            }
1194    
1195            protected PluginSetting toUnwrappedModel(PluginSetting pluginSetting) {
1196                    if (pluginSetting instanceof PluginSettingImpl) {
1197                            return pluginSetting;
1198                    }
1199    
1200                    PluginSettingImpl pluginSettingImpl = new PluginSettingImpl();
1201    
1202                    pluginSettingImpl.setNew(pluginSetting.isNew());
1203                    pluginSettingImpl.setPrimaryKey(pluginSetting.getPrimaryKey());
1204    
1205                    pluginSettingImpl.setPluginSettingId(pluginSetting.getPluginSettingId());
1206                    pluginSettingImpl.setCompanyId(pluginSetting.getCompanyId());
1207                    pluginSettingImpl.setPluginId(pluginSetting.getPluginId());
1208                    pluginSettingImpl.setPluginType(pluginSetting.getPluginType());
1209                    pluginSettingImpl.setRoles(pluginSetting.getRoles());
1210                    pluginSettingImpl.setActive(pluginSetting.isActive());
1211    
1212                    return pluginSettingImpl;
1213            }
1214    
1215            /**
1216             * Returns the plugin setting with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
1217             *
1218             * @param primaryKey the primary key of the plugin setting
1219             * @return the plugin setting
1220             * @throws com.liferay.portal.NoSuchPluginSettingException if a plugin setting with the primary key could not be found
1221             * @throws SystemException if a system exception occurred
1222             */
1223            @Override
1224            public PluginSetting findByPrimaryKey(Serializable primaryKey)
1225                    throws NoSuchPluginSettingException, SystemException {
1226                    PluginSetting pluginSetting = fetchByPrimaryKey(primaryKey);
1227    
1228                    if (pluginSetting == null) {
1229                            if (_log.isWarnEnabled()) {
1230                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1231                            }
1232    
1233                            throw new NoSuchPluginSettingException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1234                                    primaryKey);
1235                    }
1236    
1237                    return pluginSetting;
1238            }
1239    
1240            /**
1241             * Returns the plugin setting with the primary key or throws a {@link com.liferay.portal.NoSuchPluginSettingException} if it could not be found.
1242             *
1243             * @param pluginSettingId the primary key of the plugin setting
1244             * @return the plugin setting
1245             * @throws com.liferay.portal.NoSuchPluginSettingException if a plugin setting with the primary key could not be found
1246             * @throws SystemException if a system exception occurred
1247             */
1248            public PluginSetting findByPrimaryKey(long pluginSettingId)
1249                    throws NoSuchPluginSettingException, SystemException {
1250                    return findByPrimaryKey((Serializable)pluginSettingId);
1251            }
1252    
1253            /**
1254             * Returns the plugin setting with the primary key or returns <code>null</code> if it could not be found.
1255             *
1256             * @param primaryKey the primary key of the plugin setting
1257             * @return the plugin setting, or <code>null</code> if a plugin setting with the primary key could not be found
1258             * @throws SystemException if a system exception occurred
1259             */
1260            @Override
1261            public PluginSetting fetchByPrimaryKey(Serializable primaryKey)
1262                    throws SystemException {
1263                    PluginSetting pluginSetting = (PluginSetting)EntityCacheUtil.getResult(PluginSettingModelImpl.ENTITY_CACHE_ENABLED,
1264                                    PluginSettingImpl.class, primaryKey);
1265    
1266                    if (pluginSetting == _nullPluginSetting) {
1267                            return null;
1268                    }
1269    
1270                    if (pluginSetting == null) {
1271                            Session session = null;
1272    
1273                            try {
1274                                    session = openSession();
1275    
1276                                    pluginSetting = (PluginSetting)session.get(PluginSettingImpl.class,
1277                                                    primaryKey);
1278    
1279                                    if (pluginSetting != null) {
1280                                            cacheResult(pluginSetting);
1281                                    }
1282                                    else {
1283                                            EntityCacheUtil.putResult(PluginSettingModelImpl.ENTITY_CACHE_ENABLED,
1284                                                    PluginSettingImpl.class, primaryKey, _nullPluginSetting);
1285                                    }
1286                            }
1287                            catch (Exception e) {
1288                                    EntityCacheUtil.removeResult(PluginSettingModelImpl.ENTITY_CACHE_ENABLED,
1289                                            PluginSettingImpl.class, primaryKey);
1290    
1291                                    throw processException(e);
1292                            }
1293                            finally {
1294                                    closeSession(session);
1295                            }
1296                    }
1297    
1298                    return pluginSetting;
1299            }
1300    
1301            /**
1302             * Returns the plugin setting with the primary key or returns <code>null</code> if it could not be found.
1303             *
1304             * @param pluginSettingId the primary key of the plugin setting
1305             * @return the plugin setting, or <code>null</code> if a plugin setting with the primary key could not be found
1306             * @throws SystemException if a system exception occurred
1307             */
1308            public PluginSetting fetchByPrimaryKey(long pluginSettingId)
1309                    throws SystemException {
1310                    return fetchByPrimaryKey((Serializable)pluginSettingId);
1311            }
1312    
1313            /**
1314             * Returns all the plugin settings.
1315             *
1316             * @return the plugin settings
1317             * @throws SystemException if a system exception occurred
1318             */
1319            public List<PluginSetting> findAll() throws SystemException {
1320                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1321            }
1322    
1323            /**
1324             * Returns a range of all the plugin settings.
1325             *
1326             * <p>
1327             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.PluginSettingModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1328             * </p>
1329             *
1330             * @param start the lower bound of the range of plugin settings
1331             * @param end the upper bound of the range of plugin settings (not inclusive)
1332             * @return the range of plugin settings
1333             * @throws SystemException if a system exception occurred
1334             */
1335            public List<PluginSetting> findAll(int start, int end)
1336                    throws SystemException {
1337                    return findAll(start, end, null);
1338            }
1339    
1340            /**
1341             * Returns an ordered range of all the plugin settings.
1342             *
1343             * <p>
1344             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.PluginSettingModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1345             * </p>
1346             *
1347             * @param start the lower bound of the range of plugin settings
1348             * @param end the upper bound of the range of plugin settings (not inclusive)
1349             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1350             * @return the ordered range of plugin settings
1351             * @throws SystemException if a system exception occurred
1352             */
1353            public List<PluginSetting> findAll(int start, int end,
1354                    OrderByComparator orderByComparator) throws SystemException {
1355                    boolean pagination = true;
1356                    FinderPath finderPath = null;
1357                    Object[] finderArgs = null;
1358    
1359                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1360                                    (orderByComparator == null)) {
1361                            pagination = false;
1362                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1363                            finderArgs = FINDER_ARGS_EMPTY;
1364                    }
1365                    else {
1366                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1367                            finderArgs = new Object[] { start, end, orderByComparator };
1368                    }
1369    
1370                    List<PluginSetting> list = (List<PluginSetting>)FinderCacheUtil.getResult(finderPath,
1371                                    finderArgs, this);
1372    
1373                    if (list == null) {
1374                            StringBundler query = null;
1375                            String sql = null;
1376    
1377                            if (orderByComparator != null) {
1378                                    query = new StringBundler(2 +
1379                                                    (orderByComparator.getOrderByFields().length * 3));
1380    
1381                                    query.append(_SQL_SELECT_PLUGINSETTING);
1382    
1383                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1384                                            orderByComparator);
1385    
1386                                    sql = query.toString();
1387                            }
1388                            else {
1389                                    sql = _SQL_SELECT_PLUGINSETTING;
1390    
1391                                    if (pagination) {
1392                                            sql = sql.concat(PluginSettingModelImpl.ORDER_BY_JPQL);
1393                                    }
1394                            }
1395    
1396                            Session session = null;
1397    
1398                            try {
1399                                    session = openSession();
1400    
1401                                    Query q = session.createQuery(sql);
1402    
1403                                    if (!pagination) {
1404                                            list = (List<PluginSetting>)QueryUtil.list(q, getDialect(),
1405                                                            start, end, false);
1406    
1407                                            Collections.sort(list);
1408    
1409                                            list = new UnmodifiableList<PluginSetting>(list);
1410                                    }
1411                                    else {
1412                                            list = (List<PluginSetting>)QueryUtil.list(q, getDialect(),
1413                                                            start, end);
1414                                    }
1415    
1416                                    cacheResult(list);
1417    
1418                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1419                            }
1420                            catch (Exception e) {
1421                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1422    
1423                                    throw processException(e);
1424                            }
1425                            finally {
1426                                    closeSession(session);
1427                            }
1428                    }
1429    
1430                    return list;
1431            }
1432    
1433            /**
1434             * Removes all the plugin settings from the database.
1435             *
1436             * @throws SystemException if a system exception occurred
1437             */
1438            public void removeAll() throws SystemException {
1439                    for (PluginSetting pluginSetting : findAll()) {
1440                            remove(pluginSetting);
1441                    }
1442            }
1443    
1444            /**
1445             * Returns the number of plugin settings.
1446             *
1447             * @return the number of plugin settings
1448             * @throws SystemException if a system exception occurred
1449             */
1450            public int countAll() throws SystemException {
1451                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1452                                    FINDER_ARGS_EMPTY, this);
1453    
1454                    if (count == null) {
1455                            Session session = null;
1456    
1457                            try {
1458                                    session = openSession();
1459    
1460                                    Query q = session.createQuery(_SQL_COUNT_PLUGINSETTING);
1461    
1462                                    count = (Long)q.uniqueResult();
1463    
1464                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1465                                            FINDER_ARGS_EMPTY, count);
1466                            }
1467                            catch (Exception e) {
1468                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
1469                                            FINDER_ARGS_EMPTY);
1470    
1471                                    throw processException(e);
1472                            }
1473                            finally {
1474                                    closeSession(session);
1475                            }
1476                    }
1477    
1478                    return count.intValue();
1479            }
1480    
1481            /**
1482             * Initializes the plugin setting persistence.
1483             */
1484            public void afterPropertiesSet() {
1485                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1486                                            com.liferay.portal.util.PropsUtil.get(
1487                                                    "value.object.listener.com.liferay.portal.model.PluginSetting")));
1488    
1489                    if (listenerClassNames.length > 0) {
1490                            try {
1491                                    List<ModelListener<PluginSetting>> listenersList = new ArrayList<ModelListener<PluginSetting>>();
1492    
1493                                    for (String listenerClassName : listenerClassNames) {
1494                                            listenersList.add((ModelListener<PluginSetting>)InstanceFactory.newInstance(
1495                                                            listenerClassName));
1496                                    }
1497    
1498                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1499                            }
1500                            catch (Exception e) {
1501                                    _log.error(e);
1502                            }
1503                    }
1504            }
1505    
1506            public void destroy() {
1507                    EntityCacheUtil.removeCache(PluginSettingImpl.class.getName());
1508                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1509                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1510                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1511            }
1512    
1513            private static final String _SQL_SELECT_PLUGINSETTING = "SELECT pluginSetting FROM PluginSetting pluginSetting";
1514            private static final String _SQL_SELECT_PLUGINSETTING_WHERE = "SELECT pluginSetting FROM PluginSetting pluginSetting WHERE ";
1515            private static final String _SQL_COUNT_PLUGINSETTING = "SELECT COUNT(pluginSetting) FROM PluginSetting pluginSetting";
1516            private static final String _SQL_COUNT_PLUGINSETTING_WHERE = "SELECT COUNT(pluginSetting) FROM PluginSetting pluginSetting WHERE ";
1517            private static final String _ORDER_BY_ENTITY_ALIAS = "pluginSetting.";
1518            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No PluginSetting exists with the primary key ";
1519            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No PluginSetting exists with the key {";
1520            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1521            private static Log _log = LogFactoryUtil.getLog(PluginSettingPersistenceImpl.class);
1522            private static PluginSetting _nullPluginSetting = new PluginSettingImpl() {
1523                            @Override
1524                            public Object clone() {
1525                                    return this;
1526                            }
1527    
1528                            @Override
1529                            public CacheModel<PluginSetting> toCacheModel() {
1530                                    return _nullPluginSettingCacheModel;
1531                            }
1532                    };
1533    
1534            private static CacheModel<PluginSetting> _nullPluginSettingCacheModel = new CacheModel<PluginSetting>() {
1535                            public PluginSetting toEntityModel() {
1536                                    return _nullPluginSetting;
1537                            }
1538                    };
1539    }