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