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