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