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