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            /**
904             * Caches the plugin setting in the entity cache if it is enabled.
905             *
906             * @param pluginSetting the plugin setting
907             */
908            @Override
909            public void cacheResult(PluginSetting pluginSetting) {
910                    EntityCacheUtil.putResult(PluginSettingModelImpl.ENTITY_CACHE_ENABLED,
911                            PluginSettingImpl.class, pluginSetting.getPrimaryKey(),
912                            pluginSetting);
913    
914                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_I_T,
915                            new Object[] {
916                                    pluginSetting.getCompanyId(), pluginSetting.getPluginId(),
917                                    pluginSetting.getPluginType()
918                            }, pluginSetting);
919    
920                    pluginSetting.resetOriginalValues();
921            }
922    
923            /**
924             * Caches the plugin settings in the entity cache if it is enabled.
925             *
926             * @param pluginSettings the plugin settings
927             */
928            @Override
929            public void cacheResult(List<PluginSetting> pluginSettings) {
930                    for (PluginSetting pluginSetting : pluginSettings) {
931                            if (EntityCacheUtil.getResult(
932                                                    PluginSettingModelImpl.ENTITY_CACHE_ENABLED,
933                                                    PluginSettingImpl.class, pluginSetting.getPrimaryKey()) == null) {
934                                    cacheResult(pluginSetting);
935                            }
936                            else {
937                                    pluginSetting.resetOriginalValues();
938                            }
939                    }
940            }
941    
942            /**
943             * Clears the cache for all plugin settings.
944             *
945             * <p>
946             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
947             * </p>
948             */
949            @Override
950            public void clearCache() {
951                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
952                            CacheRegistryUtil.clear(PluginSettingImpl.class.getName());
953                    }
954    
955                    EntityCacheUtil.clearCache(PluginSettingImpl.class.getName());
956    
957                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
958                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
959                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
960            }
961    
962            /**
963             * Clears the cache for the plugin setting.
964             *
965             * <p>
966             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
967             * </p>
968             */
969            @Override
970            public void clearCache(PluginSetting pluginSetting) {
971                    EntityCacheUtil.removeResult(PluginSettingModelImpl.ENTITY_CACHE_ENABLED,
972                            PluginSettingImpl.class, pluginSetting.getPrimaryKey());
973    
974                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
975                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
976    
977                    clearUniqueFindersCache(pluginSetting);
978            }
979    
980            @Override
981            public void clearCache(List<PluginSetting> pluginSettings) {
982                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
983                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
984    
985                    for (PluginSetting pluginSetting : pluginSettings) {
986                            EntityCacheUtil.removeResult(PluginSettingModelImpl.ENTITY_CACHE_ENABLED,
987                                    PluginSettingImpl.class, pluginSetting.getPrimaryKey());
988    
989                            clearUniqueFindersCache(pluginSetting);
990                    }
991            }
992    
993            protected void cacheUniqueFindersCache(PluginSetting pluginSetting) {
994                    if (pluginSetting.isNew()) {
995                            Object[] args = new Object[] {
996                                            pluginSetting.getCompanyId(), pluginSetting.getPluginId(),
997                                            pluginSetting.getPluginType()
998                                    };
999    
1000                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_I_T, args,
1001                                    Long.valueOf(1));
1002                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_I_T, args,
1003                                    pluginSetting);
1004                    }
1005                    else {
1006                            PluginSettingModelImpl pluginSettingModelImpl = (PluginSettingModelImpl)pluginSetting;
1007    
1008                            if ((pluginSettingModelImpl.getColumnBitmask() &
1009                                            FINDER_PATH_FETCH_BY_C_I_T.getColumnBitmask()) != 0) {
1010                                    Object[] args = new Object[] {
1011                                                    pluginSetting.getCompanyId(),
1012                                                    pluginSetting.getPluginId(),
1013                                                    pluginSetting.getPluginType()
1014                                            };
1015    
1016                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_I_T, args,
1017                                            Long.valueOf(1));
1018                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_I_T, args,
1019                                            pluginSetting);
1020                            }
1021                    }
1022            }
1023    
1024            protected void clearUniqueFindersCache(PluginSetting pluginSetting) {
1025                    PluginSettingModelImpl pluginSettingModelImpl = (PluginSettingModelImpl)pluginSetting;
1026    
1027                    Object[] args = new Object[] {
1028                                    pluginSetting.getCompanyId(), pluginSetting.getPluginId(),
1029                                    pluginSetting.getPluginType()
1030                            };
1031    
1032                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_I_T, args);
1033                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_I_T, args);
1034    
1035                    if ((pluginSettingModelImpl.getColumnBitmask() &
1036                                    FINDER_PATH_FETCH_BY_C_I_T.getColumnBitmask()) != 0) {
1037                            args = new Object[] {
1038                                            pluginSettingModelImpl.getOriginalCompanyId(),
1039                                            pluginSettingModelImpl.getOriginalPluginId(),
1040                                            pluginSettingModelImpl.getOriginalPluginType()
1041                                    };
1042    
1043                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_I_T, args);
1044                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_I_T, args);
1045                    }
1046            }
1047    
1048            /**
1049             * Creates a new plugin setting with the primary key. Does not add the plugin setting to the database.
1050             *
1051             * @param pluginSettingId the primary key for the new plugin setting
1052             * @return the new plugin setting
1053             */
1054            @Override
1055            public PluginSetting create(long pluginSettingId) {
1056                    PluginSetting pluginSetting = new PluginSettingImpl();
1057    
1058                    pluginSetting.setNew(true);
1059                    pluginSetting.setPrimaryKey(pluginSettingId);
1060    
1061                    return pluginSetting;
1062            }
1063    
1064            /**
1065             * Removes the plugin setting with the primary key from the database. Also notifies the appropriate model listeners.
1066             *
1067             * @param pluginSettingId the primary key of the plugin setting
1068             * @return the plugin setting that was removed
1069             * @throws com.liferay.portal.NoSuchPluginSettingException if a plugin setting with the primary key could not be found
1070             * @throws SystemException if a system exception occurred
1071             */
1072            @Override
1073            public PluginSetting remove(long pluginSettingId)
1074                    throws NoSuchPluginSettingException, SystemException {
1075                    return remove((Serializable)pluginSettingId);
1076            }
1077    
1078            /**
1079             * Removes the plugin setting with the primary key from the database. Also notifies the appropriate model listeners.
1080             *
1081             * @param primaryKey the primary key of the plugin setting
1082             * @return the plugin setting that was removed
1083             * @throws com.liferay.portal.NoSuchPluginSettingException if a plugin setting with the primary key could not be found
1084             * @throws SystemException if a system exception occurred
1085             */
1086            @Override
1087            public PluginSetting remove(Serializable primaryKey)
1088                    throws NoSuchPluginSettingException, SystemException {
1089                    Session session = null;
1090    
1091                    try {
1092                            session = openSession();
1093    
1094                            PluginSetting pluginSetting = (PluginSetting)session.get(PluginSettingImpl.class,
1095                                            primaryKey);
1096    
1097                            if (pluginSetting == null) {
1098                                    if (_log.isWarnEnabled()) {
1099                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1100                                    }
1101    
1102                                    throw new NoSuchPluginSettingException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1103                                            primaryKey);
1104                            }
1105    
1106                            return remove(pluginSetting);
1107                    }
1108                    catch (NoSuchPluginSettingException nsee) {
1109                            throw nsee;
1110                    }
1111                    catch (Exception e) {
1112                            throw processException(e);
1113                    }
1114                    finally {
1115                            closeSession(session);
1116                    }
1117            }
1118    
1119            @Override
1120            protected PluginSetting removeImpl(PluginSetting pluginSetting)
1121                    throws SystemException {
1122                    pluginSetting = toUnwrappedModel(pluginSetting);
1123    
1124                    Session session = null;
1125    
1126                    try {
1127                            session = openSession();
1128    
1129                            if (!session.contains(pluginSetting)) {
1130                                    pluginSetting = (PluginSetting)session.get(PluginSettingImpl.class,
1131                                                    pluginSetting.getPrimaryKeyObj());
1132                            }
1133    
1134                            if (pluginSetting != null) {
1135                                    session.delete(pluginSetting);
1136                            }
1137                    }
1138                    catch (Exception e) {
1139                            throw processException(e);
1140                    }
1141                    finally {
1142                            closeSession(session);
1143                    }
1144    
1145                    if (pluginSetting != null) {
1146                            clearCache(pluginSetting);
1147                    }
1148    
1149                    return pluginSetting;
1150            }
1151    
1152            @Override
1153            public PluginSetting updateImpl(
1154                    com.liferay.portal.model.PluginSetting pluginSetting)
1155                    throws SystemException {
1156                    pluginSetting = toUnwrappedModel(pluginSetting);
1157    
1158                    boolean isNew = pluginSetting.isNew();
1159    
1160                    PluginSettingModelImpl pluginSettingModelImpl = (PluginSettingModelImpl)pluginSetting;
1161    
1162                    Session session = null;
1163    
1164                    try {
1165                            session = openSession();
1166    
1167                            if (pluginSetting.isNew()) {
1168                                    session.save(pluginSetting);
1169    
1170                                    pluginSetting.setNew(false);
1171                            }
1172                            else {
1173                                    session.merge(pluginSetting);
1174                            }
1175                    }
1176                    catch (Exception e) {
1177                            throw processException(e);
1178                    }
1179                    finally {
1180                            closeSession(session);
1181                    }
1182    
1183                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1184    
1185                    if (isNew || !PluginSettingModelImpl.COLUMN_BITMASK_ENABLED) {
1186                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1187                    }
1188    
1189                    else {
1190                            if ((pluginSettingModelImpl.getColumnBitmask() &
1191                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
1192                                    Object[] args = new Object[] {
1193                                                    pluginSettingModelImpl.getOriginalCompanyId()
1194                                            };
1195    
1196                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
1197                                            args);
1198                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
1199                                            args);
1200    
1201                                    args = new Object[] { pluginSettingModelImpl.getCompanyId() };
1202    
1203                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
1204                                            args);
1205                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
1206                                            args);
1207                            }
1208                    }
1209    
1210                    EntityCacheUtil.putResult(PluginSettingModelImpl.ENTITY_CACHE_ENABLED,
1211                            PluginSettingImpl.class, pluginSetting.getPrimaryKey(),
1212                            pluginSetting);
1213    
1214                    clearUniqueFindersCache(pluginSetting);
1215                    cacheUniqueFindersCache(pluginSetting);
1216    
1217                    return pluginSetting;
1218            }
1219    
1220            protected PluginSetting toUnwrappedModel(PluginSetting pluginSetting) {
1221                    if (pluginSetting instanceof PluginSettingImpl) {
1222                            return pluginSetting;
1223                    }
1224    
1225                    PluginSettingImpl pluginSettingImpl = new PluginSettingImpl();
1226    
1227                    pluginSettingImpl.setNew(pluginSetting.isNew());
1228                    pluginSettingImpl.setPrimaryKey(pluginSetting.getPrimaryKey());
1229    
1230                    pluginSettingImpl.setPluginSettingId(pluginSetting.getPluginSettingId());
1231                    pluginSettingImpl.setCompanyId(pluginSetting.getCompanyId());
1232                    pluginSettingImpl.setPluginId(pluginSetting.getPluginId());
1233                    pluginSettingImpl.setPluginType(pluginSetting.getPluginType());
1234                    pluginSettingImpl.setRoles(pluginSetting.getRoles());
1235                    pluginSettingImpl.setActive(pluginSetting.isActive());
1236    
1237                    return pluginSettingImpl;
1238            }
1239    
1240            /**
1241             * Returns the plugin setting with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
1242             *
1243             * @param primaryKey the primary key of the plugin setting
1244             * @return the plugin setting
1245             * @throws com.liferay.portal.NoSuchPluginSettingException if a plugin setting with the primary key could not be found
1246             * @throws SystemException if a system exception occurred
1247             */
1248            @Override
1249            public PluginSetting findByPrimaryKey(Serializable primaryKey)
1250                    throws NoSuchPluginSettingException, SystemException {
1251                    PluginSetting pluginSetting = fetchByPrimaryKey(primaryKey);
1252    
1253                    if (pluginSetting == null) {
1254                            if (_log.isWarnEnabled()) {
1255                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1256                            }
1257    
1258                            throw new NoSuchPluginSettingException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1259                                    primaryKey);
1260                    }
1261    
1262                    return pluginSetting;
1263            }
1264    
1265            /**
1266             * Returns the plugin setting with the primary key or throws a {@link com.liferay.portal.NoSuchPluginSettingException} if it could not be found.
1267             *
1268             * @param pluginSettingId the primary key of the plugin setting
1269             * @return the plugin setting
1270             * @throws com.liferay.portal.NoSuchPluginSettingException if a plugin setting with the primary key could not be found
1271             * @throws SystemException if a system exception occurred
1272             */
1273            @Override
1274            public PluginSetting findByPrimaryKey(long pluginSettingId)
1275                    throws NoSuchPluginSettingException, SystemException {
1276                    return findByPrimaryKey((Serializable)pluginSettingId);
1277            }
1278    
1279            /**
1280             * Returns the plugin setting with the primary key or returns <code>null</code> if it could not be found.
1281             *
1282             * @param primaryKey the primary key of the plugin setting
1283             * @return the plugin setting, or <code>null</code> if a plugin setting with the primary key could not be found
1284             * @throws SystemException if a system exception occurred
1285             */
1286            @Override
1287            public PluginSetting fetchByPrimaryKey(Serializable primaryKey)
1288                    throws SystemException {
1289                    PluginSetting pluginSetting = (PluginSetting)EntityCacheUtil.getResult(PluginSettingModelImpl.ENTITY_CACHE_ENABLED,
1290                                    PluginSettingImpl.class, primaryKey);
1291    
1292                    if (pluginSetting == _nullPluginSetting) {
1293                            return null;
1294                    }
1295    
1296                    if (pluginSetting == null) {
1297                            Session session = null;
1298    
1299                            try {
1300                                    session = openSession();
1301    
1302                                    pluginSetting = (PluginSetting)session.get(PluginSettingImpl.class,
1303                                                    primaryKey);
1304    
1305                                    if (pluginSetting != null) {
1306                                            cacheResult(pluginSetting);
1307                                    }
1308                                    else {
1309                                            EntityCacheUtil.putResult(PluginSettingModelImpl.ENTITY_CACHE_ENABLED,
1310                                                    PluginSettingImpl.class, primaryKey, _nullPluginSetting);
1311                                    }
1312                            }
1313                            catch (Exception e) {
1314                                    EntityCacheUtil.removeResult(PluginSettingModelImpl.ENTITY_CACHE_ENABLED,
1315                                            PluginSettingImpl.class, primaryKey);
1316    
1317                                    throw processException(e);
1318                            }
1319                            finally {
1320                                    closeSession(session);
1321                            }
1322                    }
1323    
1324                    return pluginSetting;
1325            }
1326    
1327            /**
1328             * Returns the plugin setting with the primary key or returns <code>null</code> if it could not be found.
1329             *
1330             * @param pluginSettingId the primary key of the plugin setting
1331             * @return the plugin setting, or <code>null</code> if a plugin setting with the primary key could not be found
1332             * @throws SystemException if a system exception occurred
1333             */
1334            @Override
1335            public PluginSetting fetchByPrimaryKey(long pluginSettingId)
1336                    throws SystemException {
1337                    return fetchByPrimaryKey((Serializable)pluginSettingId);
1338            }
1339    
1340            /**
1341             * Returns all the plugin settings.
1342             *
1343             * @return the plugin settings
1344             * @throws SystemException if a system exception occurred
1345             */
1346            @Override
1347            public List<PluginSetting> findAll() throws SystemException {
1348                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1349            }
1350    
1351            /**
1352             * Returns a range of all the plugin settings.
1353             *
1354             * <p>
1355             * 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.
1356             * </p>
1357             *
1358             * @param start the lower bound of the range of plugin settings
1359             * @param end the upper bound of the range of plugin settings (not inclusive)
1360             * @return the range of plugin settings
1361             * @throws SystemException if a system exception occurred
1362             */
1363            @Override
1364            public List<PluginSetting> findAll(int start, int end)
1365                    throws SystemException {
1366                    return findAll(start, end, null);
1367            }
1368    
1369            /**
1370             * Returns an ordered range of all the plugin settings.
1371             *
1372             * <p>
1373             * 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.
1374             * </p>
1375             *
1376             * @param start the lower bound of the range of plugin settings
1377             * @param end the upper bound of the range of plugin settings (not inclusive)
1378             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1379             * @return the ordered range of plugin settings
1380             * @throws SystemException if a system exception occurred
1381             */
1382            @Override
1383            public List<PluginSetting> findAll(int start, int end,
1384                    OrderByComparator orderByComparator) throws SystemException {
1385                    boolean pagination = true;
1386                    FinderPath finderPath = null;
1387                    Object[] finderArgs = null;
1388    
1389                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1390                                    (orderByComparator == null)) {
1391                            pagination = false;
1392                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1393                            finderArgs = FINDER_ARGS_EMPTY;
1394                    }
1395                    else {
1396                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1397                            finderArgs = new Object[] { start, end, orderByComparator };
1398                    }
1399    
1400                    List<PluginSetting> list = (List<PluginSetting>)FinderCacheUtil.getResult(finderPath,
1401                                    finderArgs, this);
1402    
1403                    if (list == null) {
1404                            StringBundler query = null;
1405                            String sql = null;
1406    
1407                            if (orderByComparator != null) {
1408                                    query = new StringBundler(2 +
1409                                                    (orderByComparator.getOrderByFields().length * 3));
1410    
1411                                    query.append(_SQL_SELECT_PLUGINSETTING);
1412    
1413                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1414                                            orderByComparator);
1415    
1416                                    sql = query.toString();
1417                            }
1418                            else {
1419                                    sql = _SQL_SELECT_PLUGINSETTING;
1420    
1421                                    if (pagination) {
1422                                            sql = sql.concat(PluginSettingModelImpl.ORDER_BY_JPQL);
1423                                    }
1424                            }
1425    
1426                            Session session = null;
1427    
1428                            try {
1429                                    session = openSession();
1430    
1431                                    Query q = session.createQuery(sql);
1432    
1433                                    if (!pagination) {
1434                                            list = (List<PluginSetting>)QueryUtil.list(q, getDialect(),
1435                                                            start, end, false);
1436    
1437                                            Collections.sort(list);
1438    
1439                                            list = new UnmodifiableList<PluginSetting>(list);
1440                                    }
1441                                    else {
1442                                            list = (List<PluginSetting>)QueryUtil.list(q, getDialect(),
1443                                                            start, end);
1444                                    }
1445    
1446                                    cacheResult(list);
1447    
1448                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1449                            }
1450                            catch (Exception e) {
1451                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1452    
1453                                    throw processException(e);
1454                            }
1455                            finally {
1456                                    closeSession(session);
1457                            }
1458                    }
1459    
1460                    return list;
1461            }
1462    
1463            /**
1464             * Removes all the plugin settings from the database.
1465             *
1466             * @throws SystemException if a system exception occurred
1467             */
1468            @Override
1469            public void removeAll() throws SystemException {
1470                    for (PluginSetting pluginSetting : findAll()) {
1471                            remove(pluginSetting);
1472                    }
1473            }
1474    
1475            /**
1476             * Returns the number of plugin settings.
1477             *
1478             * @return the number of plugin settings
1479             * @throws SystemException if a system exception occurred
1480             */
1481            @Override
1482            public int countAll() throws SystemException {
1483                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1484                                    FINDER_ARGS_EMPTY, this);
1485    
1486                    if (count == null) {
1487                            Session session = null;
1488    
1489                            try {
1490                                    session = openSession();
1491    
1492                                    Query q = session.createQuery(_SQL_COUNT_PLUGINSETTING);
1493    
1494                                    count = (Long)q.uniqueResult();
1495    
1496                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1497                                            FINDER_ARGS_EMPTY, count);
1498                            }
1499                            catch (Exception e) {
1500                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
1501                                            FINDER_ARGS_EMPTY);
1502    
1503                                    throw processException(e);
1504                            }
1505                            finally {
1506                                    closeSession(session);
1507                            }
1508                    }
1509    
1510                    return count.intValue();
1511            }
1512    
1513            @Override
1514            protected Set<String> getBadColumnNames() {
1515                    return _badColumnNames;
1516            }
1517    
1518            /**
1519             * Initializes the plugin setting persistence.
1520             */
1521            public void afterPropertiesSet() {
1522                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1523                                            com.liferay.portal.util.PropsUtil.get(
1524                                                    "value.object.listener.com.liferay.portal.model.PluginSetting")));
1525    
1526                    if (listenerClassNames.length > 0) {
1527                            try {
1528                                    List<ModelListener<PluginSetting>> listenersList = new ArrayList<ModelListener<PluginSetting>>();
1529    
1530                                    for (String listenerClassName : listenerClassNames) {
1531                                            listenersList.add((ModelListener<PluginSetting>)InstanceFactory.newInstance(
1532                                                            getClassLoader(), listenerClassName));
1533                                    }
1534    
1535                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1536                            }
1537                            catch (Exception e) {
1538                                    _log.error(e);
1539                            }
1540                    }
1541            }
1542    
1543            public void destroy() {
1544                    EntityCacheUtil.removeCache(PluginSettingImpl.class.getName());
1545                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1546                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1547                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1548            }
1549    
1550            private static final String _SQL_SELECT_PLUGINSETTING = "SELECT pluginSetting FROM PluginSetting pluginSetting";
1551            private static final String _SQL_SELECT_PLUGINSETTING_WHERE = "SELECT pluginSetting FROM PluginSetting pluginSetting WHERE ";
1552            private static final String _SQL_COUNT_PLUGINSETTING = "SELECT COUNT(pluginSetting) FROM PluginSetting pluginSetting";
1553            private static final String _SQL_COUNT_PLUGINSETTING_WHERE = "SELECT COUNT(pluginSetting) FROM PluginSetting pluginSetting WHERE ";
1554            private static final String _ORDER_BY_ENTITY_ALIAS = "pluginSetting.";
1555            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No PluginSetting exists with the primary key ";
1556            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No PluginSetting exists with the key {";
1557            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1558            private static Log _log = LogFactoryUtil.getLog(PluginSettingPersistenceImpl.class);
1559            private static Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
1560                                    "active"
1561                            });
1562            private static PluginSetting _nullPluginSetting = new PluginSettingImpl() {
1563                            @Override
1564                            public Object clone() {
1565                                    return this;
1566                            }
1567    
1568                            @Override
1569                            public CacheModel<PluginSetting> toCacheModel() {
1570                                    return _nullPluginSettingCacheModel;
1571                            }
1572                    };
1573    
1574            private static CacheModel<PluginSetting> _nullPluginSettingCacheModel = new CacheModel<PluginSetting>() {
1575                            @Override
1576                            public PluginSetting toEntityModel() {
1577                                    return _nullPluginSetting;
1578                            }
1579                    };
1580    }