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 * 3));
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(6 +
435                                            (orderByComparator.getOrderByFields().length * 6));
436                    }
437                    else {
438                            query = new StringBundler(3);
439                    }
440    
441                    query.append(_SQL_SELECT_PLUGINSETTING_WHERE);
442    
443                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
444    
445                    if (orderByComparator != null) {
446                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
447    
448                            if (orderByConditionFields.length > 0) {
449                                    query.append(WHERE_AND);
450                            }
451    
452                            for (int i = 0; i < orderByConditionFields.length; i++) {
453                                    query.append(_ORDER_BY_ENTITY_ALIAS);
454                                    query.append(orderByConditionFields[i]);
455    
456                                    if ((i + 1) < orderByConditionFields.length) {
457                                            if (orderByComparator.isAscending() ^ previous) {
458                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
459                                            }
460                                            else {
461                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
462                                            }
463                                    }
464                                    else {
465                                            if (orderByComparator.isAscending() ^ previous) {
466                                                    query.append(WHERE_GREATER_THAN);
467                                            }
468                                            else {
469                                                    query.append(WHERE_LESSER_THAN);
470                                            }
471                                    }
472                            }
473    
474                            query.append(ORDER_BY_CLAUSE);
475    
476                            String[] orderByFields = orderByComparator.getOrderByFields();
477    
478                            for (int i = 0; i < orderByFields.length; i++) {
479                                    query.append(_ORDER_BY_ENTITY_ALIAS);
480                                    query.append(orderByFields[i]);
481    
482                                    if ((i + 1) < orderByFields.length) {
483                                            if (orderByComparator.isAscending() ^ previous) {
484                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
485                                            }
486                                            else {
487                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
488                                            }
489                                    }
490                                    else {
491                                            if (orderByComparator.isAscending() ^ previous) {
492                                                    query.append(ORDER_BY_ASC);
493                                            }
494                                            else {
495                                                    query.append(ORDER_BY_DESC);
496                                            }
497                                    }
498                            }
499                    }
500                    else {
501                            query.append(PluginSettingModelImpl.ORDER_BY_JPQL);
502                    }
503    
504                    String sql = query.toString();
505    
506                    Query q = session.createQuery(sql);
507    
508                    q.setFirstResult(0);
509                    q.setMaxResults(2);
510    
511                    QueryPos qPos = QueryPos.getInstance(q);
512    
513                    qPos.add(companyId);
514    
515                    if (orderByComparator != null) {
516                            Object[] values = orderByComparator.getOrderByConditionValues(pluginSetting);
517    
518                            for (Object value : values) {
519                                    qPos.add(value);
520                            }
521                    }
522    
523                    List<PluginSetting> list = q.list();
524    
525                    if (list.size() == 2) {
526                            return list.get(1);
527                    }
528                    else {
529                            return null;
530                    }
531            }
532    
533            /**
534             * Removes all the plugin settings where companyId = &#63; from the database.
535             *
536             * @param companyId the company ID
537             */
538            @Override
539            public void removeByCompanyId(long companyId) {
540                    for (PluginSetting pluginSetting : findByCompanyId(companyId,
541                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
542                            remove(pluginSetting);
543                    }
544            }
545    
546            /**
547             * Returns the number of plugin settings where companyId = &#63;.
548             *
549             * @param companyId the company ID
550             * @return the number of matching plugin settings
551             */
552            @Override
553            public int countByCompanyId(long companyId) {
554                    FinderPath finderPath = FINDER_PATH_COUNT_BY_COMPANYID;
555    
556                    Object[] finderArgs = new Object[] { companyId };
557    
558                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
559    
560                    if (count == null) {
561                            StringBundler query = new StringBundler(2);
562    
563                            query.append(_SQL_COUNT_PLUGINSETTING_WHERE);
564    
565                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
566    
567                            String sql = query.toString();
568    
569                            Session session = null;
570    
571                            try {
572                                    session = openSession();
573    
574                                    Query q = session.createQuery(sql);
575    
576                                    QueryPos qPos = QueryPos.getInstance(q);
577    
578                                    qPos.add(companyId);
579    
580                                    count = (Long)q.uniqueResult();
581    
582                                    finderCache.putResult(finderPath, finderArgs, count);
583                            }
584                            catch (Exception e) {
585                                    finderCache.removeResult(finderPath, finderArgs);
586    
587                                    throw processException(e);
588                            }
589                            finally {
590                                    closeSession(session);
591                            }
592                    }
593    
594                    return count.intValue();
595            }
596    
597            private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "pluginSetting.companyId = ?";
598            public static final FinderPath FINDER_PATH_FETCH_BY_C_I_T = new FinderPath(PluginSettingModelImpl.ENTITY_CACHE_ENABLED,
599                            PluginSettingModelImpl.FINDER_CACHE_ENABLED,
600                            PluginSettingImpl.class, FINDER_CLASS_NAME_ENTITY, "fetchByC_I_T",
601                            new String[] {
602                                    Long.class.getName(), String.class.getName(),
603                                    String.class.getName()
604                            },
605                            PluginSettingModelImpl.COMPANYID_COLUMN_BITMASK |
606                            PluginSettingModelImpl.PLUGINID_COLUMN_BITMASK |
607                            PluginSettingModelImpl.PLUGINTYPE_COLUMN_BITMASK);
608            public static final FinderPath FINDER_PATH_COUNT_BY_C_I_T = new FinderPath(PluginSettingModelImpl.ENTITY_CACHE_ENABLED,
609                            PluginSettingModelImpl.FINDER_CACHE_ENABLED, Long.class,
610                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_I_T",
611                            new String[] {
612                                    Long.class.getName(), String.class.getName(),
613                                    String.class.getName()
614                            });
615    
616            /**
617             * Returns the plugin setting where companyId = &#63; and pluginId = &#63; and pluginType = &#63; or throws a {@link NoSuchPluginSettingException} if it could not be found.
618             *
619             * @param companyId the company ID
620             * @param pluginId the plugin ID
621             * @param pluginType the plugin type
622             * @return the matching plugin setting
623             * @throws NoSuchPluginSettingException if a matching plugin setting could not be found
624             */
625            @Override
626            public PluginSetting findByC_I_T(long companyId, String pluginId,
627                    String pluginType) throws NoSuchPluginSettingException {
628                    PluginSetting pluginSetting = fetchByC_I_T(companyId, pluginId,
629                                    pluginType);
630    
631                    if (pluginSetting == null) {
632                            StringBundler msg = new StringBundler(8);
633    
634                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
635    
636                            msg.append("companyId=");
637                            msg.append(companyId);
638    
639                            msg.append(", pluginId=");
640                            msg.append(pluginId);
641    
642                            msg.append(", pluginType=");
643                            msg.append(pluginType);
644    
645                            msg.append(StringPool.CLOSE_CURLY_BRACE);
646    
647                            if (_log.isWarnEnabled()) {
648                                    _log.warn(msg.toString());
649                            }
650    
651                            throw new NoSuchPluginSettingException(msg.toString());
652                    }
653    
654                    return pluginSetting;
655            }
656    
657            /**
658             * 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.
659             *
660             * @param companyId the company ID
661             * @param pluginId the plugin ID
662             * @param pluginType the plugin type
663             * @return the matching plugin setting, or <code>null</code> if a matching plugin setting could not be found
664             */
665            @Override
666            public PluginSetting fetchByC_I_T(long companyId, String pluginId,
667                    String pluginType) {
668                    return fetchByC_I_T(companyId, pluginId, pluginType, true);
669            }
670    
671            /**
672             * 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.
673             *
674             * @param companyId the company ID
675             * @param pluginId the plugin ID
676             * @param pluginType the plugin type
677             * @param retrieveFromCache whether to retrieve from the finder cache
678             * @return the matching plugin setting, or <code>null</code> if a matching plugin setting could not be found
679             */
680            @Override
681            public PluginSetting fetchByC_I_T(long companyId, String pluginId,
682                    String pluginType, boolean retrieveFromCache) {
683                    Object[] finderArgs = new Object[] { companyId, pluginId, pluginType };
684    
685                    Object result = null;
686    
687                    if (retrieveFromCache) {
688                            result = finderCache.getResult(FINDER_PATH_FETCH_BY_C_I_T,
689                                            finderArgs, this);
690                    }
691    
692                    if (result instanceof PluginSetting) {
693                            PluginSetting pluginSetting = (PluginSetting)result;
694    
695                            if ((companyId != pluginSetting.getCompanyId()) ||
696                                            !Validator.equals(pluginId, pluginSetting.getPluginId()) ||
697                                            !Validator.equals(pluginType, pluginSetting.getPluginType())) {
698                                    result = null;
699                            }
700                    }
701    
702                    if (result == null) {
703                            StringBundler query = new StringBundler(5);
704    
705                            query.append(_SQL_SELECT_PLUGINSETTING_WHERE);
706    
707                            query.append(_FINDER_COLUMN_C_I_T_COMPANYID_2);
708    
709                            boolean bindPluginId = false;
710    
711                            if (pluginId == null) {
712                                    query.append(_FINDER_COLUMN_C_I_T_PLUGINID_1);
713                            }
714                            else if (pluginId.equals(StringPool.BLANK)) {
715                                    query.append(_FINDER_COLUMN_C_I_T_PLUGINID_3);
716                            }
717                            else {
718                                    bindPluginId = true;
719    
720                                    query.append(_FINDER_COLUMN_C_I_T_PLUGINID_2);
721                            }
722    
723                            boolean bindPluginType = false;
724    
725                            if (pluginType == null) {
726                                    query.append(_FINDER_COLUMN_C_I_T_PLUGINTYPE_1);
727                            }
728                            else if (pluginType.equals(StringPool.BLANK)) {
729                                    query.append(_FINDER_COLUMN_C_I_T_PLUGINTYPE_3);
730                            }
731                            else {
732                                    bindPluginType = true;
733    
734                                    query.append(_FINDER_COLUMN_C_I_T_PLUGINTYPE_2);
735                            }
736    
737                            String sql = query.toString();
738    
739                            Session session = null;
740    
741                            try {
742                                    session = openSession();
743    
744                                    Query q = session.createQuery(sql);
745    
746                                    QueryPos qPos = QueryPos.getInstance(q);
747    
748                                    qPos.add(companyId);
749    
750                                    if (bindPluginId) {
751                                            qPos.add(pluginId);
752                                    }
753    
754                                    if (bindPluginType) {
755                                            qPos.add(pluginType);
756                                    }
757    
758                                    List<PluginSetting> list = q.list();
759    
760                                    if (list.isEmpty()) {
761                                            finderCache.putResult(FINDER_PATH_FETCH_BY_C_I_T,
762                                                    finderArgs, list);
763                                    }
764                                    else {
765                                            PluginSetting pluginSetting = list.get(0);
766    
767                                            result = pluginSetting;
768    
769                                            cacheResult(pluginSetting);
770    
771                                            if ((pluginSetting.getCompanyId() != companyId) ||
772                                                            (pluginSetting.getPluginId() == null) ||
773                                                            !pluginSetting.getPluginId().equals(pluginId) ||
774                                                            (pluginSetting.getPluginType() == null) ||
775                                                            !pluginSetting.getPluginType().equals(pluginType)) {
776                                                    finderCache.putResult(FINDER_PATH_FETCH_BY_C_I_T,
777                                                            finderArgs, pluginSetting);
778                                            }
779                                    }
780                            }
781                            catch (Exception e) {
782                                    finderCache.removeResult(FINDER_PATH_FETCH_BY_C_I_T, finderArgs);
783    
784                                    throw processException(e);
785                            }
786                            finally {
787                                    closeSession(session);
788                            }
789                    }
790    
791                    if (result instanceof List<?>) {
792                            return null;
793                    }
794                    else {
795                            return (PluginSetting)result;
796                    }
797            }
798    
799            /**
800             * Removes the plugin setting where companyId = &#63; and pluginId = &#63; and pluginType = &#63; from the database.
801             *
802             * @param companyId the company ID
803             * @param pluginId the plugin ID
804             * @param pluginType the plugin type
805             * @return the plugin setting that was removed
806             */
807            @Override
808            public PluginSetting removeByC_I_T(long companyId, String pluginId,
809                    String pluginType) throws NoSuchPluginSettingException {
810                    PluginSetting pluginSetting = findByC_I_T(companyId, pluginId,
811                                    pluginType);
812    
813                    return remove(pluginSetting);
814            }
815    
816            /**
817             * Returns the number of plugin settings where companyId = &#63; and pluginId = &#63; and pluginType = &#63;.
818             *
819             * @param companyId the company ID
820             * @param pluginId the plugin ID
821             * @param pluginType the plugin type
822             * @return the number of matching plugin settings
823             */
824            @Override
825            public int countByC_I_T(long companyId, String pluginId, String pluginType) {
826                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_I_T;
827    
828                    Object[] finderArgs = new Object[] { companyId, pluginId, pluginType };
829    
830                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
831    
832                    if (count == null) {
833                            StringBundler query = new StringBundler(4);
834    
835                            query.append(_SQL_COUNT_PLUGINSETTING_WHERE);
836    
837                            query.append(_FINDER_COLUMN_C_I_T_COMPANYID_2);
838    
839                            boolean bindPluginId = false;
840    
841                            if (pluginId == null) {
842                                    query.append(_FINDER_COLUMN_C_I_T_PLUGINID_1);
843                            }
844                            else if (pluginId.equals(StringPool.BLANK)) {
845                                    query.append(_FINDER_COLUMN_C_I_T_PLUGINID_3);
846                            }
847                            else {
848                                    bindPluginId = true;
849    
850                                    query.append(_FINDER_COLUMN_C_I_T_PLUGINID_2);
851                            }
852    
853                            boolean bindPluginType = false;
854    
855                            if (pluginType == null) {
856                                    query.append(_FINDER_COLUMN_C_I_T_PLUGINTYPE_1);
857                            }
858                            else if (pluginType.equals(StringPool.BLANK)) {
859                                    query.append(_FINDER_COLUMN_C_I_T_PLUGINTYPE_3);
860                            }
861                            else {
862                                    bindPluginType = true;
863    
864                                    query.append(_FINDER_COLUMN_C_I_T_PLUGINTYPE_2);
865                            }
866    
867                            String sql = query.toString();
868    
869                            Session session = null;
870    
871                            try {
872                                    session = openSession();
873    
874                                    Query q = session.createQuery(sql);
875    
876                                    QueryPos qPos = QueryPos.getInstance(q);
877    
878                                    qPos.add(companyId);
879    
880                                    if (bindPluginId) {
881                                            qPos.add(pluginId);
882                                    }
883    
884                                    if (bindPluginType) {
885                                            qPos.add(pluginType);
886                                    }
887    
888                                    count = (Long)q.uniqueResult();
889    
890                                    finderCache.putResult(finderPath, finderArgs, count);
891                            }
892                            catch (Exception e) {
893                                    finderCache.removeResult(finderPath, finderArgs);
894    
895                                    throw processException(e);
896                            }
897                            finally {
898                                    closeSession(session);
899                            }
900                    }
901    
902                    return count.intValue();
903            }
904    
905            private static final String _FINDER_COLUMN_C_I_T_COMPANYID_2 = "pluginSetting.companyId = ? AND ";
906            private static final String _FINDER_COLUMN_C_I_T_PLUGINID_1 = "pluginSetting.pluginId IS NULL AND ";
907            private static final String _FINDER_COLUMN_C_I_T_PLUGINID_2 = "pluginSetting.pluginId = ? AND ";
908            private static final String _FINDER_COLUMN_C_I_T_PLUGINID_3 = "(pluginSetting.pluginId IS NULL OR pluginSetting.pluginId = '') AND ";
909            private static final String _FINDER_COLUMN_C_I_T_PLUGINTYPE_1 = "pluginSetting.pluginType IS NULL";
910            private static final String _FINDER_COLUMN_C_I_T_PLUGINTYPE_2 = "pluginSetting.pluginType = ?";
911            private static final String _FINDER_COLUMN_C_I_T_PLUGINTYPE_3 = "(pluginSetting.pluginType IS NULL OR pluginSetting.pluginType = '')";
912    
913            public PluginSettingPersistenceImpl() {
914                    setModelClass(PluginSetting.class);
915            }
916    
917            /**
918             * Caches the plugin setting in the entity cache if it is enabled.
919             *
920             * @param pluginSetting the plugin setting
921             */
922            @Override
923            public void cacheResult(PluginSetting pluginSetting) {
924                    entityCache.putResult(PluginSettingModelImpl.ENTITY_CACHE_ENABLED,
925                            PluginSettingImpl.class, pluginSetting.getPrimaryKey(),
926                            pluginSetting);
927    
928                    finderCache.putResult(FINDER_PATH_FETCH_BY_C_I_T,
929                            new Object[] {
930                                    pluginSetting.getCompanyId(), pluginSetting.getPluginId(),
931                                    pluginSetting.getPluginType()
932                            }, pluginSetting);
933    
934                    pluginSetting.resetOriginalValues();
935            }
936    
937            /**
938             * Caches the plugin settings in the entity cache if it is enabled.
939             *
940             * @param pluginSettings the plugin settings
941             */
942            @Override
943            public void cacheResult(List<PluginSetting> pluginSettings) {
944                    for (PluginSetting pluginSetting : pluginSettings) {
945                            if (entityCache.getResult(
946                                                    PluginSettingModelImpl.ENTITY_CACHE_ENABLED,
947                                                    PluginSettingImpl.class, pluginSetting.getPrimaryKey()) == null) {
948                                    cacheResult(pluginSetting);
949                            }
950                            else {
951                                    pluginSetting.resetOriginalValues();
952                            }
953                    }
954            }
955    
956            /**
957             * Clears the cache for all plugin settings.
958             *
959             * <p>
960             * The {@link EntityCache} and {@link FinderCache} are both cleared by this method.
961             * </p>
962             */
963            @Override
964            public void clearCache() {
965                    entityCache.clearCache(PluginSettingImpl.class);
966    
967                    finderCache.clearCache(FINDER_CLASS_NAME_ENTITY);
968                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
969                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
970            }
971    
972            /**
973             * Clears the cache for the plugin setting.
974             *
975             * <p>
976             * The {@link EntityCache} and {@link FinderCache} are both cleared by this method.
977             * </p>
978             */
979            @Override
980            public void clearCache(PluginSetting pluginSetting) {
981                    entityCache.removeResult(PluginSettingModelImpl.ENTITY_CACHE_ENABLED,
982                            PluginSettingImpl.class, pluginSetting.getPrimaryKey());
983    
984                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
985                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
986    
987                    clearUniqueFindersCache((PluginSettingModelImpl)pluginSetting);
988            }
989    
990            @Override
991            public void clearCache(List<PluginSetting> pluginSettings) {
992                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
993                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
994    
995                    for (PluginSetting pluginSetting : pluginSettings) {
996                            entityCache.removeResult(PluginSettingModelImpl.ENTITY_CACHE_ENABLED,
997                                    PluginSettingImpl.class, pluginSetting.getPrimaryKey());
998    
999                            clearUniqueFindersCache((PluginSettingModelImpl)pluginSetting);
1000                    }
1001            }
1002    
1003            protected void cacheUniqueFindersCache(
1004                    PluginSettingModelImpl pluginSettingModelImpl, boolean isNew) {
1005                    if (isNew) {
1006                            Object[] args = new Object[] {
1007                                            pluginSettingModelImpl.getCompanyId(),
1008                                            pluginSettingModelImpl.getPluginId(),
1009                                            pluginSettingModelImpl.getPluginType()
1010                                    };
1011    
1012                            finderCache.putResult(FINDER_PATH_COUNT_BY_C_I_T, args,
1013                                    Long.valueOf(1));
1014                            finderCache.putResult(FINDER_PATH_FETCH_BY_C_I_T, args,
1015                                    pluginSettingModelImpl);
1016                    }
1017                    else {
1018                            if ((pluginSettingModelImpl.getColumnBitmask() &
1019                                            FINDER_PATH_FETCH_BY_C_I_T.getColumnBitmask()) != 0) {
1020                                    Object[] args = new Object[] {
1021                                                    pluginSettingModelImpl.getCompanyId(),
1022                                                    pluginSettingModelImpl.getPluginId(),
1023                                                    pluginSettingModelImpl.getPluginType()
1024                                            };
1025    
1026                                    finderCache.putResult(FINDER_PATH_COUNT_BY_C_I_T, args,
1027                                            Long.valueOf(1));
1028                                    finderCache.putResult(FINDER_PATH_FETCH_BY_C_I_T, args,
1029                                            pluginSettingModelImpl);
1030                            }
1031                    }
1032            }
1033    
1034            protected void clearUniqueFindersCache(
1035                    PluginSettingModelImpl pluginSettingModelImpl) {
1036                    Object[] args = new Object[] {
1037                                    pluginSettingModelImpl.getCompanyId(),
1038                                    pluginSettingModelImpl.getPluginId(),
1039                                    pluginSettingModelImpl.getPluginType()
1040                            };
1041    
1042                    finderCache.removeResult(FINDER_PATH_COUNT_BY_C_I_T, args);
1043                    finderCache.removeResult(FINDER_PATH_FETCH_BY_C_I_T, args);
1044    
1045                    if ((pluginSettingModelImpl.getColumnBitmask() &
1046                                    FINDER_PATH_FETCH_BY_C_I_T.getColumnBitmask()) != 0) {
1047                            args = new Object[] {
1048                                            pluginSettingModelImpl.getOriginalCompanyId(),
1049                                            pluginSettingModelImpl.getOriginalPluginId(),
1050                                            pluginSettingModelImpl.getOriginalPluginType()
1051                                    };
1052    
1053                            finderCache.removeResult(FINDER_PATH_COUNT_BY_C_I_T, args);
1054                            finderCache.removeResult(FINDER_PATH_FETCH_BY_C_I_T, args);
1055                    }
1056            }
1057    
1058            /**
1059             * Creates a new plugin setting with the primary key. Does not add the plugin setting to the database.
1060             *
1061             * @param pluginSettingId the primary key for the new plugin setting
1062             * @return the new plugin setting
1063             */
1064            @Override
1065            public PluginSetting create(long pluginSettingId) {
1066                    PluginSetting pluginSetting = new PluginSettingImpl();
1067    
1068                    pluginSetting.setNew(true);
1069                    pluginSetting.setPrimaryKey(pluginSettingId);
1070    
1071                    pluginSetting.setCompanyId(companyProvider.getCompanyId());
1072    
1073                    return pluginSetting;
1074            }
1075    
1076            /**
1077             * Removes the plugin setting with the primary key from the database. Also notifies the appropriate model listeners.
1078             *
1079             * @param pluginSettingId the primary key of the plugin setting
1080             * @return the plugin setting that was removed
1081             * @throws NoSuchPluginSettingException if a plugin setting with the primary key could not be found
1082             */
1083            @Override
1084            public PluginSetting remove(long pluginSettingId)
1085                    throws NoSuchPluginSettingException {
1086                    return remove((Serializable)pluginSettingId);
1087            }
1088    
1089            /**
1090             * Removes the plugin setting with the primary key from the database. Also notifies the appropriate model listeners.
1091             *
1092             * @param primaryKey the primary key of the plugin setting
1093             * @return the plugin setting that was removed
1094             * @throws NoSuchPluginSettingException if a plugin setting with the primary key could not be found
1095             */
1096            @Override
1097            public PluginSetting remove(Serializable primaryKey)
1098                    throws NoSuchPluginSettingException {
1099                    Session session = null;
1100    
1101                    try {
1102                            session = openSession();
1103    
1104                            PluginSetting pluginSetting = (PluginSetting)session.get(PluginSettingImpl.class,
1105                                            primaryKey);
1106    
1107                            if (pluginSetting == null) {
1108                                    if (_log.isWarnEnabled()) {
1109                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1110                                    }
1111    
1112                                    throw new NoSuchPluginSettingException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1113                                            primaryKey);
1114                            }
1115    
1116                            return remove(pluginSetting);
1117                    }
1118                    catch (NoSuchPluginSettingException nsee) {
1119                            throw nsee;
1120                    }
1121                    catch (Exception e) {
1122                            throw processException(e);
1123                    }
1124                    finally {
1125                            closeSession(session);
1126                    }
1127            }
1128    
1129            @Override
1130            protected PluginSetting removeImpl(PluginSetting pluginSetting) {
1131                    pluginSetting = toUnwrappedModel(pluginSetting);
1132    
1133                    Session session = null;
1134    
1135                    try {
1136                            session = openSession();
1137    
1138                            if (!session.contains(pluginSetting)) {
1139                                    pluginSetting = (PluginSetting)session.get(PluginSettingImpl.class,
1140                                                    pluginSetting.getPrimaryKeyObj());
1141                            }
1142    
1143                            if (pluginSetting != null) {
1144                                    session.delete(pluginSetting);
1145                            }
1146                    }
1147                    catch (Exception e) {
1148                            throw processException(e);
1149                    }
1150                    finally {
1151                            closeSession(session);
1152                    }
1153    
1154                    if (pluginSetting != null) {
1155                            clearCache(pluginSetting);
1156                    }
1157    
1158                    return pluginSetting;
1159            }
1160    
1161            @Override
1162            public PluginSetting updateImpl(PluginSetting pluginSetting) {
1163                    pluginSetting = toUnwrappedModel(pluginSetting);
1164    
1165                    boolean isNew = pluginSetting.isNew();
1166    
1167                    PluginSettingModelImpl pluginSettingModelImpl = (PluginSettingModelImpl)pluginSetting;
1168    
1169                    Session session = null;
1170    
1171                    try {
1172                            session = openSession();
1173    
1174                            if (pluginSetting.isNew()) {
1175                                    session.save(pluginSetting);
1176    
1177                                    pluginSetting.setNew(false);
1178                            }
1179                            else {
1180                                    pluginSetting = (PluginSetting)session.merge(pluginSetting);
1181                            }
1182                    }
1183                    catch (Exception e) {
1184                            throw processException(e);
1185                    }
1186                    finally {
1187                            closeSession(session);
1188                    }
1189    
1190                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1191    
1192                    if (isNew || !PluginSettingModelImpl.COLUMN_BITMASK_ENABLED) {
1193                            finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1194                    }
1195    
1196                    else {
1197                            if ((pluginSettingModelImpl.getColumnBitmask() &
1198                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
1199                                    Object[] args = new Object[] {
1200                                                    pluginSettingModelImpl.getOriginalCompanyId()
1201                                            };
1202    
1203                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_COMPANYID, args);
1204                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
1205                                            args);
1206    
1207                                    args = new Object[] { pluginSettingModelImpl.getCompanyId() };
1208    
1209                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_COMPANYID, args);
1210                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
1211                                            args);
1212                            }
1213                    }
1214    
1215                    entityCache.putResult(PluginSettingModelImpl.ENTITY_CACHE_ENABLED,
1216                            PluginSettingImpl.class, pluginSetting.getPrimaryKey(),
1217                            pluginSetting, false);
1218    
1219                    clearUniqueFindersCache(pluginSettingModelImpl);
1220                    cacheUniqueFindersCache(pluginSettingModelImpl, isNew);
1221    
1222                    pluginSetting.resetOriginalValues();
1223    
1224                    return pluginSetting;
1225            }
1226    
1227            protected PluginSetting toUnwrappedModel(PluginSetting pluginSetting) {
1228                    if (pluginSetting instanceof PluginSettingImpl) {
1229                            return pluginSetting;
1230                    }
1231    
1232                    PluginSettingImpl pluginSettingImpl = new PluginSettingImpl();
1233    
1234                    pluginSettingImpl.setNew(pluginSetting.isNew());
1235                    pluginSettingImpl.setPrimaryKey(pluginSetting.getPrimaryKey());
1236    
1237                    pluginSettingImpl.setMvccVersion(pluginSetting.getMvccVersion());
1238                    pluginSettingImpl.setPluginSettingId(pluginSetting.getPluginSettingId());
1239                    pluginSettingImpl.setCompanyId(pluginSetting.getCompanyId());
1240                    pluginSettingImpl.setPluginId(pluginSetting.getPluginId());
1241                    pluginSettingImpl.setPluginType(pluginSetting.getPluginType());
1242                    pluginSettingImpl.setRoles(pluginSetting.getRoles());
1243                    pluginSettingImpl.setActive(pluginSetting.isActive());
1244    
1245                    return pluginSettingImpl;
1246            }
1247    
1248            /**
1249             * Returns the plugin setting with the primary key or throws a {@link com.liferay.portal.exception.NoSuchModelException} if it could not be found.
1250             *
1251             * @param primaryKey the primary key of the plugin setting
1252             * @return the plugin setting
1253             * @throws NoSuchPluginSettingException if a plugin setting with the primary key could not be found
1254             */
1255            @Override
1256            public PluginSetting findByPrimaryKey(Serializable primaryKey)
1257                    throws NoSuchPluginSettingException {
1258                    PluginSetting pluginSetting = fetchByPrimaryKey(primaryKey);
1259    
1260                    if (pluginSetting == null) {
1261                            if (_log.isWarnEnabled()) {
1262                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1263                            }
1264    
1265                            throw new NoSuchPluginSettingException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1266                                    primaryKey);
1267                    }
1268    
1269                    return pluginSetting;
1270            }
1271    
1272            /**
1273             * Returns the plugin setting with the primary key or throws a {@link NoSuchPluginSettingException} if it could not be found.
1274             *
1275             * @param pluginSettingId the primary key of the plugin setting
1276             * @return the plugin setting
1277             * @throws NoSuchPluginSettingException if a plugin setting with the primary key could not be found
1278             */
1279            @Override
1280            public PluginSetting findByPrimaryKey(long pluginSettingId)
1281                    throws NoSuchPluginSettingException {
1282                    return findByPrimaryKey((Serializable)pluginSettingId);
1283            }
1284    
1285            /**
1286             * Returns the plugin setting with the primary key or returns <code>null</code> if it could not be found.
1287             *
1288             * @param primaryKey the primary key of the plugin setting
1289             * @return the plugin setting, or <code>null</code> if a plugin setting with the primary key could not be found
1290             */
1291            @Override
1292            public PluginSetting fetchByPrimaryKey(Serializable primaryKey) {
1293                    PluginSetting pluginSetting = (PluginSetting)entityCache.getResult(PluginSettingModelImpl.ENTITY_CACHE_ENABLED,
1294                                    PluginSettingImpl.class, primaryKey);
1295    
1296                    if (pluginSetting == _nullPluginSetting) {
1297                            return null;
1298                    }
1299    
1300                    if (pluginSetting == null) {
1301                            Session session = null;
1302    
1303                            try {
1304                                    session = openSession();
1305    
1306                                    pluginSetting = (PluginSetting)session.get(PluginSettingImpl.class,
1307                                                    primaryKey);
1308    
1309                                    if (pluginSetting != null) {
1310                                            cacheResult(pluginSetting);
1311                                    }
1312                                    else {
1313                                            entityCache.putResult(PluginSettingModelImpl.ENTITY_CACHE_ENABLED,
1314                                                    PluginSettingImpl.class, primaryKey, _nullPluginSetting);
1315                                    }
1316                            }
1317                            catch (Exception e) {
1318                                    entityCache.removeResult(PluginSettingModelImpl.ENTITY_CACHE_ENABLED,
1319                                            PluginSettingImpl.class, primaryKey);
1320    
1321                                    throw processException(e);
1322                            }
1323                            finally {
1324                                    closeSession(session);
1325                            }
1326                    }
1327    
1328                    return pluginSetting;
1329            }
1330    
1331            /**
1332             * Returns the plugin setting with the primary key or returns <code>null</code> if it could not be found.
1333             *
1334             * @param pluginSettingId the primary key of the plugin setting
1335             * @return the plugin setting, or <code>null</code> if a plugin setting with the primary key could not be found
1336             */
1337            @Override
1338            public PluginSetting fetchByPrimaryKey(long pluginSettingId) {
1339                    return fetchByPrimaryKey((Serializable)pluginSettingId);
1340            }
1341    
1342            @Override
1343            public Map<Serializable, PluginSetting> fetchByPrimaryKeys(
1344                    Set<Serializable> primaryKeys) {
1345                    if (primaryKeys.isEmpty()) {
1346                            return Collections.emptyMap();
1347                    }
1348    
1349                    Map<Serializable, PluginSetting> map = new HashMap<Serializable, PluginSetting>();
1350    
1351                    if (primaryKeys.size() == 1) {
1352                            Iterator<Serializable> iterator = primaryKeys.iterator();
1353    
1354                            Serializable primaryKey = iterator.next();
1355    
1356                            PluginSetting pluginSetting = fetchByPrimaryKey(primaryKey);
1357    
1358                            if (pluginSetting != null) {
1359                                    map.put(primaryKey, pluginSetting);
1360                            }
1361    
1362                            return map;
1363                    }
1364    
1365                    Set<Serializable> uncachedPrimaryKeys = null;
1366    
1367                    for (Serializable primaryKey : primaryKeys) {
1368                            PluginSetting pluginSetting = (PluginSetting)entityCache.getResult(PluginSettingModelImpl.ENTITY_CACHE_ENABLED,
1369                                            PluginSettingImpl.class, primaryKey);
1370    
1371                            if (pluginSetting == null) {
1372                                    if (uncachedPrimaryKeys == null) {
1373                                            uncachedPrimaryKeys = new HashSet<Serializable>();
1374                                    }
1375    
1376                                    uncachedPrimaryKeys.add(primaryKey);
1377                            }
1378                            else {
1379                                    map.put(primaryKey, pluginSetting);
1380                            }
1381                    }
1382    
1383                    if (uncachedPrimaryKeys == null) {
1384                            return map;
1385                    }
1386    
1387                    StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
1388                                    1);
1389    
1390                    query.append(_SQL_SELECT_PLUGINSETTING_WHERE_PKS_IN);
1391    
1392                    for (Serializable primaryKey : uncachedPrimaryKeys) {
1393                            query.append(String.valueOf(primaryKey));
1394    
1395                            query.append(StringPool.COMMA);
1396                    }
1397    
1398                    query.setIndex(query.index() - 1);
1399    
1400                    query.append(StringPool.CLOSE_PARENTHESIS);
1401    
1402                    String sql = query.toString();
1403    
1404                    Session session = null;
1405    
1406                    try {
1407                            session = openSession();
1408    
1409                            Query q = session.createQuery(sql);
1410    
1411                            for (PluginSetting pluginSetting : (List<PluginSetting>)q.list()) {
1412                                    map.put(pluginSetting.getPrimaryKeyObj(), pluginSetting);
1413    
1414                                    cacheResult(pluginSetting);
1415    
1416                                    uncachedPrimaryKeys.remove(pluginSetting.getPrimaryKeyObj());
1417                            }
1418    
1419                            for (Serializable primaryKey : uncachedPrimaryKeys) {
1420                                    entityCache.putResult(PluginSettingModelImpl.ENTITY_CACHE_ENABLED,
1421                                            PluginSettingImpl.class, primaryKey, _nullPluginSetting);
1422                            }
1423                    }
1424                    catch (Exception e) {
1425                            throw processException(e);
1426                    }
1427                    finally {
1428                            closeSession(session);
1429                    }
1430    
1431                    return map;
1432            }
1433    
1434            /**
1435             * Returns all the plugin settings.
1436             *
1437             * @return the plugin settings
1438             */
1439            @Override
1440            public List<PluginSetting> findAll() {
1441                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1442            }
1443    
1444            /**
1445             * Returns a range of all the plugin settings.
1446             *
1447             * <p>
1448             * 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.
1449             * </p>
1450             *
1451             * @param start the lower bound of the range of plugin settings
1452             * @param end the upper bound of the range of plugin settings (not inclusive)
1453             * @return the range of plugin settings
1454             */
1455            @Override
1456            public List<PluginSetting> findAll(int start, int end) {
1457                    return findAll(start, end, null);
1458            }
1459    
1460            /**
1461             * Returns an ordered range of all the plugin settings.
1462             *
1463             * <p>
1464             * 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.
1465             * </p>
1466             *
1467             * @param start the lower bound of the range of plugin settings
1468             * @param end the upper bound of the range of plugin settings (not inclusive)
1469             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1470             * @return the ordered range of plugin settings
1471             */
1472            @Override
1473            public List<PluginSetting> findAll(int start, int end,
1474                    OrderByComparator<PluginSetting> orderByComparator) {
1475                    return findAll(start, end, orderByComparator, true);
1476            }
1477    
1478            /**
1479             * Returns an ordered range of all the plugin settings.
1480             *
1481             * <p>
1482             * 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.
1483             * </p>
1484             *
1485             * @param start the lower bound of the range of plugin settings
1486             * @param end the upper bound of the range of plugin settings (not inclusive)
1487             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1488             * @param retrieveFromCache whether to retrieve from the finder cache
1489             * @return the ordered range of plugin settings
1490             */
1491            @Override
1492            public List<PluginSetting> findAll(int start, int end,
1493                    OrderByComparator<PluginSetting> orderByComparator,
1494                    boolean retrieveFromCache) {
1495                    boolean pagination = true;
1496                    FinderPath finderPath = null;
1497                    Object[] finderArgs = null;
1498    
1499                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1500                                    (orderByComparator == null)) {
1501                            pagination = false;
1502                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1503                            finderArgs = FINDER_ARGS_EMPTY;
1504                    }
1505                    else {
1506                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1507                            finderArgs = new Object[] { start, end, orderByComparator };
1508                    }
1509    
1510                    List<PluginSetting> list = null;
1511    
1512                    if (retrieveFromCache) {
1513                            list = (List<PluginSetting>)finderCache.getResult(finderPath,
1514                                            finderArgs, this);
1515                    }
1516    
1517                    if (list == null) {
1518                            StringBundler query = null;
1519                            String sql = null;
1520    
1521                            if (orderByComparator != null) {
1522                                    query = new StringBundler(2 +
1523                                                    (orderByComparator.getOrderByFields().length * 3));
1524    
1525                                    query.append(_SQL_SELECT_PLUGINSETTING);
1526    
1527                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1528                                            orderByComparator);
1529    
1530                                    sql = query.toString();
1531                            }
1532                            else {
1533                                    sql = _SQL_SELECT_PLUGINSETTING;
1534    
1535                                    if (pagination) {
1536                                            sql = sql.concat(PluginSettingModelImpl.ORDER_BY_JPQL);
1537                                    }
1538                            }
1539    
1540                            Session session = null;
1541    
1542                            try {
1543                                    session = openSession();
1544    
1545                                    Query q = session.createQuery(sql);
1546    
1547                                    if (!pagination) {
1548                                            list = (List<PluginSetting>)QueryUtil.list(q, getDialect(),
1549                                                            start, end, false);
1550    
1551                                            Collections.sort(list);
1552    
1553                                            list = Collections.unmodifiableList(list);
1554                                    }
1555                                    else {
1556                                            list = (List<PluginSetting>)QueryUtil.list(q, getDialect(),
1557                                                            start, end);
1558                                    }
1559    
1560                                    cacheResult(list);
1561    
1562                                    finderCache.putResult(finderPath, finderArgs, list);
1563                            }
1564                            catch (Exception e) {
1565                                    finderCache.removeResult(finderPath, finderArgs);
1566    
1567                                    throw processException(e);
1568                            }
1569                            finally {
1570                                    closeSession(session);
1571                            }
1572                    }
1573    
1574                    return list;
1575            }
1576    
1577            /**
1578             * Removes all the plugin settings from the database.
1579             *
1580             */
1581            @Override
1582            public void removeAll() {
1583                    for (PluginSetting pluginSetting : findAll()) {
1584                            remove(pluginSetting);
1585                    }
1586            }
1587    
1588            /**
1589             * Returns the number of plugin settings.
1590             *
1591             * @return the number of plugin settings
1592             */
1593            @Override
1594            public int countAll() {
1595                    Long count = (Long)finderCache.getResult(FINDER_PATH_COUNT_ALL,
1596                                    FINDER_ARGS_EMPTY, this);
1597    
1598                    if (count == null) {
1599                            Session session = null;
1600    
1601                            try {
1602                                    session = openSession();
1603    
1604                                    Query q = session.createQuery(_SQL_COUNT_PLUGINSETTING);
1605    
1606                                    count = (Long)q.uniqueResult();
1607    
1608                                    finderCache.putResult(FINDER_PATH_COUNT_ALL, FINDER_ARGS_EMPTY,
1609                                            count);
1610                            }
1611                            catch (Exception e) {
1612                                    finderCache.removeResult(FINDER_PATH_COUNT_ALL,
1613                                            FINDER_ARGS_EMPTY);
1614    
1615                                    throw processException(e);
1616                            }
1617                            finally {
1618                                    closeSession(session);
1619                            }
1620                    }
1621    
1622                    return count.intValue();
1623            }
1624    
1625            @Override
1626            public Set<String> getBadColumnNames() {
1627                    return _badColumnNames;
1628            }
1629    
1630            @Override
1631            protected Map<String, Integer> getTableColumnsMap() {
1632                    return PluginSettingModelImpl.TABLE_COLUMNS_MAP;
1633            }
1634    
1635            /**
1636             * Initializes the plugin setting persistence.
1637             */
1638            public void afterPropertiesSet() {
1639            }
1640    
1641            public void destroy() {
1642                    entityCache.removeCache(PluginSettingImpl.class.getName());
1643                    finderCache.removeCache(FINDER_CLASS_NAME_ENTITY);
1644                    finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1645                    finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1646            }
1647    
1648            @BeanReference(type = CompanyProviderWrapper.class)
1649            protected CompanyProvider companyProvider;
1650            protected EntityCache entityCache = EntityCacheUtil.getEntityCache();
1651            protected FinderCache finderCache = FinderCacheUtil.getFinderCache();
1652            private static final String _SQL_SELECT_PLUGINSETTING = "SELECT pluginSetting FROM PluginSetting pluginSetting";
1653            private static final String _SQL_SELECT_PLUGINSETTING_WHERE_PKS_IN = "SELECT pluginSetting FROM PluginSetting pluginSetting WHERE pluginSettingId IN (";
1654            private static final String _SQL_SELECT_PLUGINSETTING_WHERE = "SELECT pluginSetting FROM PluginSetting pluginSetting WHERE ";
1655            private static final String _SQL_COUNT_PLUGINSETTING = "SELECT COUNT(pluginSetting) FROM PluginSetting pluginSetting";
1656            private static final String _SQL_COUNT_PLUGINSETTING_WHERE = "SELECT COUNT(pluginSetting) FROM PluginSetting pluginSetting WHERE ";
1657            private static final String _ORDER_BY_ENTITY_ALIAS = "pluginSetting.";
1658            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No PluginSetting exists with the primary key ";
1659            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No PluginSetting exists with the key {";
1660            private static final Log _log = LogFactoryUtil.getLog(PluginSettingPersistenceImpl.class);
1661            private static final Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
1662                                    "active"
1663                            });
1664            private static final PluginSetting _nullPluginSetting = new PluginSettingImpl() {
1665                            @Override
1666                            public Object clone() {
1667                                    return this;
1668                            }
1669    
1670                            @Override
1671                            public CacheModel<PluginSetting> toCacheModel() {
1672                                    return _nullPluginSettingCacheModel;
1673                            }
1674                    };
1675    
1676            private static final CacheModel<PluginSetting> _nullPluginSettingCacheModel = new NullCacheModel();
1677    
1678            private static class NullCacheModel implements CacheModel<PluginSetting>,
1679                    MVCCModel {
1680                    @Override
1681                    public long getMvccVersion() {
1682                            return -1;
1683                    }
1684    
1685                    @Override
1686                    public void setMvccVersion(long mvccVersion) {
1687                    }
1688    
1689                    @Override
1690                    public PluginSetting toEntityModel() {
1691                            return _nullPluginSetting;
1692                    }
1693            }
1694    }