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