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