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