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