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