001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.service.persistence;
016    
017    import com.liferay.portal.NoSuchModelException;
018    import com.liferay.portal.NoSuchPluginSettingException;
019    import com.liferay.portal.kernel.annotation.BeanReference;
020    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
021    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
023    import com.liferay.portal.kernel.dao.orm.FinderPath;
024    import com.liferay.portal.kernel.dao.orm.Query;
025    import com.liferay.portal.kernel.dao.orm.QueryPos;
026    import com.liferay.portal.kernel.dao.orm.QueryUtil;
027    import com.liferay.portal.kernel.dao.orm.Session;
028    import com.liferay.portal.kernel.exception.SystemException;
029    import com.liferay.portal.kernel.log.Log;
030    import com.liferay.portal.kernel.log.LogFactoryUtil;
031    import com.liferay.portal.kernel.util.GetterUtil;
032    import com.liferay.portal.kernel.util.InstanceFactory;
033    import com.liferay.portal.kernel.util.OrderByComparator;
034    import com.liferay.portal.kernel.util.StringBundler;
035    import com.liferay.portal.kernel.util.StringPool;
036    import com.liferay.portal.kernel.util.StringUtil;
037    import com.liferay.portal.kernel.util.Validator;
038    import com.liferay.portal.model.ModelListener;
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.impl.BasePersistenceImpl;
043    
044    import java.io.Serializable;
045    
046    import java.util.ArrayList;
047    import java.util.Collections;
048    import java.util.List;
049    
050    /**
051     * @author    Brian Wing Shun Chan
052     * @see       PluginSettingPersistence
053     * @see       PluginSettingUtil
054     * @generated
055     */
056    public class PluginSettingPersistenceImpl extends BasePersistenceImpl<PluginSetting>
057            implements PluginSettingPersistence {
058            public static final String FINDER_CLASS_NAME_ENTITY = PluginSettingImpl.class.getName();
059            public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
060                    ".List";
061            public static final FinderPath FINDER_PATH_FIND_BY_COMPANYID = new FinderPath(PluginSettingModelImpl.ENTITY_CACHE_ENABLED,
062                            PluginSettingModelImpl.FINDER_CACHE_ENABLED,
063                            FINDER_CLASS_NAME_LIST, "findByCompanyId",
064                            new String[] {
065                                    Long.class.getName(),
066                                    
067                            "java.lang.Integer", "java.lang.Integer",
068                                    "com.liferay.portal.kernel.util.OrderByComparator"
069                            });
070            public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(PluginSettingModelImpl.ENTITY_CACHE_ENABLED,
071                            PluginSettingModelImpl.FINDER_CACHE_ENABLED,
072                            FINDER_CLASS_NAME_LIST, "countByCompanyId",
073                            new String[] { Long.class.getName() });
074            public static final FinderPath FINDER_PATH_FETCH_BY_C_I_T = new FinderPath(PluginSettingModelImpl.ENTITY_CACHE_ENABLED,
075                            PluginSettingModelImpl.FINDER_CACHE_ENABLED,
076                            FINDER_CLASS_NAME_ENTITY, "fetchByC_I_T",
077                            new String[] {
078                                    Long.class.getName(), String.class.getName(),
079                                    String.class.getName()
080                            });
081            public static final FinderPath FINDER_PATH_COUNT_BY_C_I_T = new FinderPath(PluginSettingModelImpl.ENTITY_CACHE_ENABLED,
082                            PluginSettingModelImpl.FINDER_CACHE_ENABLED,
083                            FINDER_CLASS_NAME_LIST, "countByC_I_T",
084                            new String[] {
085                                    Long.class.getName(), String.class.getName(),
086                                    String.class.getName()
087                            });
088            public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(PluginSettingModelImpl.ENTITY_CACHE_ENABLED,
089                            PluginSettingModelImpl.FINDER_CACHE_ENABLED,
090                            FINDER_CLASS_NAME_LIST, "findAll", new String[0]);
091            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(PluginSettingModelImpl.ENTITY_CACHE_ENABLED,
092                            PluginSettingModelImpl.FINDER_CACHE_ENABLED,
093                            FINDER_CLASS_NAME_LIST, "countAll", new String[0]);
094    
095            public void cacheResult(PluginSetting pluginSetting) {
096                    EntityCacheUtil.putResult(PluginSettingModelImpl.ENTITY_CACHE_ENABLED,
097                            PluginSettingImpl.class, pluginSetting.getPrimaryKey(),
098                            pluginSetting);
099    
100                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_I_T,
101                            new Object[] {
102                                    new Long(pluginSetting.getCompanyId()),
103                                    
104                            pluginSetting.getPluginId(),
105                                    
106                            pluginSetting.getPluginType()
107                            }, pluginSetting);
108            }
109    
110            public void cacheResult(List<PluginSetting> pluginSettings) {
111                    for (PluginSetting pluginSetting : pluginSettings) {
112                            if (EntityCacheUtil.getResult(
113                                                    PluginSettingModelImpl.ENTITY_CACHE_ENABLED,
114                                                    PluginSettingImpl.class, pluginSetting.getPrimaryKey(),
115                                                    this) == null) {
116                                    cacheResult(pluginSetting);
117                            }
118                    }
119            }
120    
121            public void clearCache() {
122                    CacheRegistryUtil.clear(PluginSettingImpl.class.getName());
123                    EntityCacheUtil.clearCache(PluginSettingImpl.class.getName());
124                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
125                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
126            }
127    
128            public void clearCache(PluginSetting pluginSetting) {
129                    EntityCacheUtil.removeResult(PluginSettingModelImpl.ENTITY_CACHE_ENABLED,
130                            PluginSettingImpl.class, pluginSetting.getPrimaryKey());
131    
132                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_I_T,
133                            new Object[] {
134                                    new Long(pluginSetting.getCompanyId()),
135                                    
136                            pluginSetting.getPluginId(),
137                                    
138                            pluginSetting.getPluginType()
139                            });
140            }
141    
142            public PluginSetting create(long pluginSettingId) {
143                    PluginSetting pluginSetting = new PluginSettingImpl();
144    
145                    pluginSetting.setNew(true);
146                    pluginSetting.setPrimaryKey(pluginSettingId);
147    
148                    return pluginSetting;
149            }
150    
151            public PluginSetting remove(Serializable primaryKey)
152                    throws NoSuchModelException, SystemException {
153                    return remove(((Long)primaryKey).longValue());
154            }
155    
156            public PluginSetting remove(long pluginSettingId)
157                    throws NoSuchPluginSettingException, SystemException {
158                    Session session = null;
159    
160                    try {
161                            session = openSession();
162    
163                            PluginSetting pluginSetting = (PluginSetting)session.get(PluginSettingImpl.class,
164                                            new Long(pluginSettingId));
165    
166                            if (pluginSetting == null) {
167                                    if (_log.isWarnEnabled()) {
168                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
169                                                    pluginSettingId);
170                                    }
171    
172                                    throw new NoSuchPluginSettingException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
173                                            pluginSettingId);
174                            }
175    
176                            return remove(pluginSetting);
177                    }
178                    catch (NoSuchPluginSettingException nsee) {
179                            throw nsee;
180                    }
181                    catch (Exception e) {
182                            throw processException(e);
183                    }
184                    finally {
185                            closeSession(session);
186                    }
187            }
188    
189            protected PluginSetting removeImpl(PluginSetting pluginSetting)
190                    throws SystemException {
191                    pluginSetting = toUnwrappedModel(pluginSetting);
192    
193                    Session session = null;
194    
195                    try {
196                            session = openSession();
197    
198                            if (pluginSetting.isCachedModel() || BatchSessionUtil.isEnabled()) {
199                                    Object staleObject = session.get(PluginSettingImpl.class,
200                                                    pluginSetting.getPrimaryKeyObj());
201    
202                                    if (staleObject != null) {
203                                            session.evict(staleObject);
204                                    }
205                            }
206    
207                            session.delete(pluginSetting);
208    
209                            session.flush();
210                    }
211                    catch (Exception e) {
212                            throw processException(e);
213                    }
214                    finally {
215                            closeSession(session);
216                    }
217    
218                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
219    
220                    PluginSettingModelImpl pluginSettingModelImpl = (PluginSettingModelImpl)pluginSetting;
221    
222                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_I_T,
223                            new Object[] {
224                                    new Long(pluginSettingModelImpl.getOriginalCompanyId()),
225                                    
226                            pluginSettingModelImpl.getOriginalPluginId(),
227                                    
228                            pluginSettingModelImpl.getOriginalPluginType()
229                            });
230    
231                    EntityCacheUtil.removeResult(PluginSettingModelImpl.ENTITY_CACHE_ENABLED,
232                            PluginSettingImpl.class, pluginSetting.getPrimaryKey());
233    
234                    return pluginSetting;
235            }
236    
237            public PluginSetting updateImpl(
238                    com.liferay.portal.model.PluginSetting pluginSetting, boolean merge)
239                    throws SystemException {
240                    pluginSetting = toUnwrappedModel(pluginSetting);
241    
242                    boolean isNew = pluginSetting.isNew();
243    
244                    PluginSettingModelImpl pluginSettingModelImpl = (PluginSettingModelImpl)pluginSetting;
245    
246                    Session session = null;
247    
248                    try {
249                            session = openSession();
250    
251                            BatchSessionUtil.update(session, pluginSetting, merge);
252    
253                            pluginSetting.setNew(false);
254                    }
255                    catch (Exception e) {
256                            throw processException(e);
257                    }
258                    finally {
259                            closeSession(session);
260                    }
261    
262                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
263    
264                    EntityCacheUtil.putResult(PluginSettingModelImpl.ENTITY_CACHE_ENABLED,
265                            PluginSettingImpl.class, pluginSetting.getPrimaryKey(),
266                            pluginSetting);
267    
268                    if (!isNew &&
269                                    ((pluginSetting.getCompanyId() != pluginSettingModelImpl.getOriginalCompanyId()) ||
270                                    !Validator.equals(pluginSetting.getPluginId(),
271                                            pluginSettingModelImpl.getOriginalPluginId()) ||
272                                    !Validator.equals(pluginSetting.getPluginType(),
273                                            pluginSettingModelImpl.getOriginalPluginType()))) {
274                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_I_T,
275                                    new Object[] {
276                                            new Long(pluginSettingModelImpl.getOriginalCompanyId()),
277                                            
278                                    pluginSettingModelImpl.getOriginalPluginId(),
279                                            
280                                    pluginSettingModelImpl.getOriginalPluginType()
281                                    });
282                    }
283    
284                    if (isNew ||
285                                    ((pluginSetting.getCompanyId() != pluginSettingModelImpl.getOriginalCompanyId()) ||
286                                    !Validator.equals(pluginSetting.getPluginId(),
287                                            pluginSettingModelImpl.getOriginalPluginId()) ||
288                                    !Validator.equals(pluginSetting.getPluginType(),
289                                            pluginSettingModelImpl.getOriginalPluginType()))) {
290                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_I_T,
291                                    new Object[] {
292                                            new Long(pluginSetting.getCompanyId()),
293                                            
294                                    pluginSetting.getPluginId(),
295                                            
296                                    pluginSetting.getPluginType()
297                                    }, pluginSetting);
298                    }
299    
300                    return pluginSetting;
301            }
302    
303            protected PluginSetting toUnwrappedModel(PluginSetting pluginSetting) {
304                    if (pluginSetting instanceof PluginSettingImpl) {
305                            return pluginSetting;
306                    }
307    
308                    PluginSettingImpl pluginSettingImpl = new PluginSettingImpl();
309    
310                    pluginSettingImpl.setNew(pluginSetting.isNew());
311                    pluginSettingImpl.setPrimaryKey(pluginSetting.getPrimaryKey());
312    
313                    pluginSettingImpl.setPluginSettingId(pluginSetting.getPluginSettingId());
314                    pluginSettingImpl.setCompanyId(pluginSetting.getCompanyId());
315                    pluginSettingImpl.setPluginId(pluginSetting.getPluginId());
316                    pluginSettingImpl.setPluginType(pluginSetting.getPluginType());
317                    pluginSettingImpl.setRoles(pluginSetting.getRoles());
318                    pluginSettingImpl.setActive(pluginSetting.isActive());
319    
320                    return pluginSettingImpl;
321            }
322    
323            public PluginSetting findByPrimaryKey(Serializable primaryKey)
324                    throws NoSuchModelException, SystemException {
325                    return findByPrimaryKey(((Long)primaryKey).longValue());
326            }
327    
328            public PluginSetting findByPrimaryKey(long pluginSettingId)
329                    throws NoSuchPluginSettingException, SystemException {
330                    PluginSetting pluginSetting = fetchByPrimaryKey(pluginSettingId);
331    
332                    if (pluginSetting == null) {
333                            if (_log.isWarnEnabled()) {
334                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + pluginSettingId);
335                            }
336    
337                            throw new NoSuchPluginSettingException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
338                                    pluginSettingId);
339                    }
340    
341                    return pluginSetting;
342            }
343    
344            public PluginSetting fetchByPrimaryKey(Serializable primaryKey)
345                    throws SystemException {
346                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
347            }
348    
349            public PluginSetting fetchByPrimaryKey(long pluginSettingId)
350                    throws SystemException {
351                    PluginSetting pluginSetting = (PluginSetting)EntityCacheUtil.getResult(PluginSettingModelImpl.ENTITY_CACHE_ENABLED,
352                                    PluginSettingImpl.class, pluginSettingId, this);
353    
354                    if (pluginSetting == null) {
355                            Session session = null;
356    
357                            try {
358                                    session = openSession();
359    
360                                    pluginSetting = (PluginSetting)session.get(PluginSettingImpl.class,
361                                                    new Long(pluginSettingId));
362                            }
363                            catch (Exception e) {
364                                    throw processException(e);
365                            }
366                            finally {
367                                    if (pluginSetting != null) {
368                                            cacheResult(pluginSetting);
369                                    }
370    
371                                    closeSession(session);
372                            }
373                    }
374    
375                    return pluginSetting;
376            }
377    
378            public List<PluginSetting> findByCompanyId(long companyId)
379                    throws SystemException {
380                    return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
381                            null);
382            }
383    
384            public List<PluginSetting> findByCompanyId(long companyId, int start,
385                    int end) throws SystemException {
386                    return findByCompanyId(companyId, start, end, null);
387            }
388    
389            public List<PluginSetting> findByCompanyId(long companyId, int start,
390                    int end, OrderByComparator orderByComparator) throws SystemException {
391                    Object[] finderArgs = new Object[] {
392                                    companyId,
393                                    
394                                    String.valueOf(start), String.valueOf(end),
395                                    String.valueOf(orderByComparator)
396                            };
397    
398                    List<PluginSetting> list = (List<PluginSetting>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_COMPANYID,
399                                    finderArgs, this);
400    
401                    if (list == null) {
402                            Session session = null;
403    
404                            try {
405                                    session = openSession();
406    
407                                    StringBundler query = null;
408    
409                                    if (orderByComparator != null) {
410                                            query = new StringBundler(3 +
411                                                            (orderByComparator.getOrderByFields().length * 3));
412                                    }
413                                    else {
414                                            query = new StringBundler(2);
415                                    }
416    
417                                    query.append(_SQL_SELECT_PLUGINSETTING_WHERE);
418    
419                                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
420    
421                                    if (orderByComparator != null) {
422                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
423                                                    orderByComparator);
424                                    }
425    
426                                    String sql = query.toString();
427    
428                                    Query q = session.createQuery(sql);
429    
430                                    QueryPos qPos = QueryPos.getInstance(q);
431    
432                                    qPos.add(companyId);
433    
434                                    list = (List<PluginSetting>)QueryUtil.list(q, getDialect(),
435                                                    start, end);
436                            }
437                            catch (Exception e) {
438                                    throw processException(e);
439                            }
440                            finally {
441                                    if (list == null) {
442                                            list = new ArrayList<PluginSetting>();
443                                    }
444    
445                                    cacheResult(list);
446    
447                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_COMPANYID,
448                                            finderArgs, list);
449    
450                                    closeSession(session);
451                            }
452                    }
453    
454                    return list;
455            }
456    
457            public PluginSetting findByCompanyId_First(long companyId,
458                    OrderByComparator orderByComparator)
459                    throws NoSuchPluginSettingException, SystemException {
460                    List<PluginSetting> list = findByCompanyId(companyId, 0, 1,
461                                    orderByComparator);
462    
463                    if (list.isEmpty()) {
464                            StringBundler msg = new StringBundler(4);
465    
466                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
467    
468                            msg.append("companyId=");
469                            msg.append(companyId);
470    
471                            msg.append(StringPool.CLOSE_CURLY_BRACE);
472    
473                            throw new NoSuchPluginSettingException(msg.toString());
474                    }
475                    else {
476                            return list.get(0);
477                    }
478            }
479    
480            public PluginSetting findByCompanyId_Last(long companyId,
481                    OrderByComparator orderByComparator)
482                    throws NoSuchPluginSettingException, SystemException {
483                    int count = countByCompanyId(companyId);
484    
485                    List<PluginSetting> list = findByCompanyId(companyId, count - 1, count,
486                                    orderByComparator);
487    
488                    if (list.isEmpty()) {
489                            StringBundler msg = new StringBundler(4);
490    
491                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
492    
493                            msg.append("companyId=");
494                            msg.append(companyId);
495    
496                            msg.append(StringPool.CLOSE_CURLY_BRACE);
497    
498                            throw new NoSuchPluginSettingException(msg.toString());
499                    }
500                    else {
501                            return list.get(0);
502                    }
503            }
504    
505            public PluginSetting[] findByCompanyId_PrevAndNext(long pluginSettingId,
506                    long companyId, OrderByComparator orderByComparator)
507                    throws NoSuchPluginSettingException, SystemException {
508                    PluginSetting pluginSetting = findByPrimaryKey(pluginSettingId);
509    
510                    Session session = null;
511    
512                    try {
513                            session = openSession();
514    
515                            PluginSetting[] array = new PluginSettingImpl[3];
516    
517                            array[0] = getByCompanyId_PrevAndNext(session, pluginSetting,
518                                            companyId, orderByComparator, true);
519    
520                            array[1] = pluginSetting;
521    
522                            array[2] = getByCompanyId_PrevAndNext(session, pluginSetting,
523                                            companyId, orderByComparator, false);
524    
525                            return array;
526                    }
527                    catch (Exception e) {
528                            throw processException(e);
529                    }
530                    finally {
531                            closeSession(session);
532                    }
533            }
534    
535            protected PluginSetting getByCompanyId_PrevAndNext(Session session,
536                    PluginSetting pluginSetting, long companyId,
537                    OrderByComparator orderByComparator, boolean previous) {
538                    StringBundler query = null;
539    
540                    if (orderByComparator != null) {
541                            query = new StringBundler(6 +
542                                            (orderByComparator.getOrderByFields().length * 6));
543                    }
544                    else {
545                            query = new StringBundler(3);
546                    }
547    
548                    query.append(_SQL_SELECT_PLUGINSETTING_WHERE);
549    
550                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
551    
552                    if (orderByComparator != null) {
553                            String[] orderByFields = orderByComparator.getOrderByFields();
554    
555                            if (orderByFields.length > 0) {
556                                    query.append(WHERE_AND);
557                            }
558    
559                            for (int i = 0; i < orderByFields.length; i++) {
560                                    query.append(_ORDER_BY_ENTITY_ALIAS);
561                                    query.append(orderByFields[i]);
562    
563                                    if ((i + 1) < orderByFields.length) {
564                                            if (orderByComparator.isAscending() ^ previous) {
565                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
566                                            }
567                                            else {
568                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
569                                            }
570                                    }
571                                    else {
572                                            if (orderByComparator.isAscending() ^ previous) {
573                                                    query.append(WHERE_GREATER_THAN);
574                                            }
575                                            else {
576                                                    query.append(WHERE_LESSER_THAN);
577                                            }
578                                    }
579                            }
580    
581                            query.append(ORDER_BY_CLAUSE);
582    
583                            for (int i = 0; i < orderByFields.length; i++) {
584                                    query.append(_ORDER_BY_ENTITY_ALIAS);
585                                    query.append(orderByFields[i]);
586    
587                                    if ((i + 1) < orderByFields.length) {
588                                            if (orderByComparator.isAscending() ^ previous) {
589                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
590                                            }
591                                            else {
592                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
593                                            }
594                                    }
595                                    else {
596                                            if (orderByComparator.isAscending() ^ previous) {
597                                                    query.append(ORDER_BY_ASC);
598                                            }
599                                            else {
600                                                    query.append(ORDER_BY_DESC);
601                                            }
602                                    }
603                            }
604                    }
605    
606                    String sql = query.toString();
607    
608                    Query q = session.createQuery(sql);
609    
610                    q.setFirstResult(0);
611                    q.setMaxResults(2);
612    
613                    QueryPos qPos = QueryPos.getInstance(q);
614    
615                    qPos.add(companyId);
616    
617                    if (orderByComparator != null) {
618                            Object[] values = orderByComparator.getOrderByValues(pluginSetting);
619    
620                            for (Object value : values) {
621                                    qPos.add(value);
622                            }
623                    }
624    
625                    List<PluginSetting> list = q.list();
626    
627                    if (list.size() == 2) {
628                            return list.get(1);
629                    }
630                    else {
631                            return null;
632                    }
633            }
634    
635            public PluginSetting findByC_I_T(long companyId, String pluginId,
636                    String pluginType) throws NoSuchPluginSettingException, SystemException {
637                    PluginSetting pluginSetting = fetchByC_I_T(companyId, pluginId,
638                                    pluginType);
639    
640                    if (pluginSetting == null) {
641                            StringBundler msg = new StringBundler(8);
642    
643                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
644    
645                            msg.append("companyId=");
646                            msg.append(companyId);
647    
648                            msg.append(", pluginId=");
649                            msg.append(pluginId);
650    
651                            msg.append(", pluginType=");
652                            msg.append(pluginType);
653    
654                            msg.append(StringPool.CLOSE_CURLY_BRACE);
655    
656                            if (_log.isWarnEnabled()) {
657                                    _log.warn(msg.toString());
658                            }
659    
660                            throw new NoSuchPluginSettingException(msg.toString());
661                    }
662    
663                    return pluginSetting;
664            }
665    
666            public PluginSetting fetchByC_I_T(long companyId, String pluginId,
667                    String pluginType) throws SystemException {
668                    return fetchByC_I_T(companyId, pluginId, pluginType, true);
669            }
670    
671            public PluginSetting fetchByC_I_T(long companyId, String pluginId,
672                    String pluginType, boolean retrieveFromCache) throws SystemException {
673                    Object[] finderArgs = new Object[] { companyId, pluginId, pluginType };
674    
675                    Object result = null;
676    
677                    if (retrieveFromCache) {
678                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_I_T,
679                                            finderArgs, this);
680                    }
681    
682                    if (result == null) {
683                            Session session = null;
684    
685                            try {
686                                    session = openSession();
687    
688                                    StringBundler query = new StringBundler(4);
689    
690                                    query.append(_SQL_SELECT_PLUGINSETTING_WHERE);
691    
692                                    query.append(_FINDER_COLUMN_C_I_T_COMPANYID_2);
693    
694                                    if (pluginId == null) {
695                                            query.append(_FINDER_COLUMN_C_I_T_PLUGINID_1);
696                                    }
697                                    else {
698                                            if (pluginId.equals(StringPool.BLANK)) {
699                                                    query.append(_FINDER_COLUMN_C_I_T_PLUGINID_3);
700                                            }
701                                            else {
702                                                    query.append(_FINDER_COLUMN_C_I_T_PLUGINID_2);
703                                            }
704                                    }
705    
706                                    if (pluginType == null) {
707                                            query.append(_FINDER_COLUMN_C_I_T_PLUGINTYPE_1);
708                                    }
709                                    else {
710                                            if (pluginType.equals(StringPool.BLANK)) {
711                                                    query.append(_FINDER_COLUMN_C_I_T_PLUGINTYPE_3);
712                                            }
713                                            else {
714                                                    query.append(_FINDER_COLUMN_C_I_T_PLUGINTYPE_2);
715                                            }
716                                    }
717    
718                                    String sql = query.toString();
719    
720                                    Query q = session.createQuery(sql);
721    
722                                    QueryPos qPos = QueryPos.getInstance(q);
723    
724                                    qPos.add(companyId);
725    
726                                    if (pluginId != null) {
727                                            qPos.add(pluginId);
728                                    }
729    
730                                    if (pluginType != null) {
731                                            qPos.add(pluginType);
732                                    }
733    
734                                    List<PluginSetting> list = q.list();
735    
736                                    result = list;
737    
738                                    PluginSetting pluginSetting = null;
739    
740                                    if (list.isEmpty()) {
741                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_I_T,
742                                                    finderArgs, list);
743                                    }
744                                    else {
745                                            pluginSetting = list.get(0);
746    
747                                            cacheResult(pluginSetting);
748    
749                                            if ((pluginSetting.getCompanyId() != companyId) ||
750                                                            (pluginSetting.getPluginId() == null) ||
751                                                            !pluginSetting.getPluginId().equals(pluginId) ||
752                                                            (pluginSetting.getPluginType() == null) ||
753                                                            !pluginSetting.getPluginType().equals(pluginType)) {
754                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_I_T,
755                                                            finderArgs, pluginSetting);
756                                            }
757                                    }
758    
759                                    return pluginSetting;
760                            }
761                            catch (Exception e) {
762                                    throw processException(e);
763                            }
764                            finally {
765                                    if (result == null) {
766                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_I_T,
767                                                    finderArgs, new ArrayList<PluginSetting>());
768                                    }
769    
770                                    closeSession(session);
771                            }
772                    }
773                    else {
774                            if (result instanceof List<?>) {
775                                    return null;
776                            }
777                            else {
778                                    return (PluginSetting)result;
779                            }
780                    }
781            }
782    
783            public List<PluginSetting> findAll() throws SystemException {
784                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
785            }
786    
787            public List<PluginSetting> findAll(int start, int end)
788                    throws SystemException {
789                    return findAll(start, end, null);
790            }
791    
792            public List<PluginSetting> findAll(int start, int end,
793                    OrderByComparator orderByComparator) throws SystemException {
794                    Object[] finderArgs = new Object[] {
795                                    String.valueOf(start), String.valueOf(end),
796                                    String.valueOf(orderByComparator)
797                            };
798    
799                    List<PluginSetting> list = (List<PluginSetting>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
800                                    finderArgs, this);
801    
802                    if (list == null) {
803                            Session session = null;
804    
805                            try {
806                                    session = openSession();
807    
808                                    StringBundler query = null;
809                                    String sql = null;
810    
811                                    if (orderByComparator != null) {
812                                            query = new StringBundler(2 +
813                                                            (orderByComparator.getOrderByFields().length * 3));
814    
815                                            query.append(_SQL_SELECT_PLUGINSETTING);
816    
817                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
818                                                    orderByComparator);
819    
820                                            sql = query.toString();
821                                    }
822                                    else {
823                                            sql = _SQL_SELECT_PLUGINSETTING;
824                                    }
825    
826                                    Query q = session.createQuery(sql);
827    
828                                    if (orderByComparator == null) {
829                                            list = (List<PluginSetting>)QueryUtil.list(q, getDialect(),
830                                                            start, end, false);
831    
832                                            Collections.sort(list);
833                                    }
834                                    else {
835                                            list = (List<PluginSetting>)QueryUtil.list(q, getDialect(),
836                                                            start, end);
837                                    }
838                            }
839                            catch (Exception e) {
840                                    throw processException(e);
841                            }
842                            finally {
843                                    if (list == null) {
844                                            list = new ArrayList<PluginSetting>();
845                                    }
846    
847                                    cacheResult(list);
848    
849                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
850    
851                                    closeSession(session);
852                            }
853                    }
854    
855                    return list;
856            }
857    
858            public void removeByCompanyId(long companyId) throws SystemException {
859                    for (PluginSetting pluginSetting : findByCompanyId(companyId)) {
860                            remove(pluginSetting);
861                    }
862            }
863    
864            public void removeByC_I_T(long companyId, String pluginId, String pluginType)
865                    throws NoSuchPluginSettingException, SystemException {
866                    PluginSetting pluginSetting = findByC_I_T(companyId, pluginId,
867                                    pluginType);
868    
869                    remove(pluginSetting);
870            }
871    
872            public void removeAll() throws SystemException {
873                    for (PluginSetting pluginSetting : findAll()) {
874                            remove(pluginSetting);
875                    }
876            }
877    
878            public int countByCompanyId(long companyId) throws SystemException {
879                    Object[] finderArgs = new Object[] { companyId };
880    
881                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
882                                    finderArgs, this);
883    
884                    if (count == null) {
885                            Session session = null;
886    
887                            try {
888                                    session = openSession();
889    
890                                    StringBundler query = new StringBundler(2);
891    
892                                    query.append(_SQL_COUNT_PLUGINSETTING_WHERE);
893    
894                                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
895    
896                                    String sql = query.toString();
897    
898                                    Query q = session.createQuery(sql);
899    
900                                    QueryPos qPos = QueryPos.getInstance(q);
901    
902                                    qPos.add(companyId);
903    
904                                    count = (Long)q.uniqueResult();
905                            }
906                            catch (Exception e) {
907                                    throw processException(e);
908                            }
909                            finally {
910                                    if (count == null) {
911                                            count = Long.valueOf(0);
912                                    }
913    
914                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
915                                            finderArgs, count);
916    
917                                    closeSession(session);
918                            }
919                    }
920    
921                    return count.intValue();
922            }
923    
924            public int countByC_I_T(long companyId, String pluginId, String pluginType)
925                    throws SystemException {
926                    Object[] finderArgs = new Object[] { companyId, pluginId, pluginType };
927    
928                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_I_T,
929                                    finderArgs, this);
930    
931                    if (count == null) {
932                            Session session = null;
933    
934                            try {
935                                    session = openSession();
936    
937                                    StringBundler query = new StringBundler(4);
938    
939                                    query.append(_SQL_COUNT_PLUGINSETTING_WHERE);
940    
941                                    query.append(_FINDER_COLUMN_C_I_T_COMPANYID_2);
942    
943                                    if (pluginId == null) {
944                                            query.append(_FINDER_COLUMN_C_I_T_PLUGINID_1);
945                                    }
946                                    else {
947                                            if (pluginId.equals(StringPool.BLANK)) {
948                                                    query.append(_FINDER_COLUMN_C_I_T_PLUGINID_3);
949                                            }
950                                            else {
951                                                    query.append(_FINDER_COLUMN_C_I_T_PLUGINID_2);
952                                            }
953                                    }
954    
955                                    if (pluginType == null) {
956                                            query.append(_FINDER_COLUMN_C_I_T_PLUGINTYPE_1);
957                                    }
958                                    else {
959                                            if (pluginType.equals(StringPool.BLANK)) {
960                                                    query.append(_FINDER_COLUMN_C_I_T_PLUGINTYPE_3);
961                                            }
962                                            else {
963                                                    query.append(_FINDER_COLUMN_C_I_T_PLUGINTYPE_2);
964                                            }
965                                    }
966    
967                                    String sql = query.toString();
968    
969                                    Query q = session.createQuery(sql);
970    
971                                    QueryPos qPos = QueryPos.getInstance(q);
972    
973                                    qPos.add(companyId);
974    
975                                    if (pluginId != null) {
976                                            qPos.add(pluginId);
977                                    }
978    
979                                    if (pluginType != null) {
980                                            qPos.add(pluginType);
981                                    }
982    
983                                    count = (Long)q.uniqueResult();
984                            }
985                            catch (Exception e) {
986                                    throw processException(e);
987                            }
988                            finally {
989                                    if (count == null) {
990                                            count = Long.valueOf(0);
991                                    }
992    
993                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_I_T,
994                                            finderArgs, count);
995    
996                                    closeSession(session);
997                            }
998                    }
999    
1000                    return count.intValue();
1001            }
1002    
1003            public int countAll() throws SystemException {
1004                    Object[] finderArgs = new Object[0];
1005    
1006                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1007                                    finderArgs, this);
1008    
1009                    if (count == null) {
1010                            Session session = null;
1011    
1012                            try {
1013                                    session = openSession();
1014    
1015                                    Query q = session.createQuery(_SQL_COUNT_PLUGINSETTING);
1016    
1017                                    count = (Long)q.uniqueResult();
1018                            }
1019                            catch (Exception e) {
1020                                    throw processException(e);
1021                            }
1022                            finally {
1023                                    if (count == null) {
1024                                            count = Long.valueOf(0);
1025                                    }
1026    
1027                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1028                                            count);
1029    
1030                                    closeSession(session);
1031                            }
1032                    }
1033    
1034                    return count.intValue();
1035            }
1036    
1037            public void afterPropertiesSet() {
1038                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1039                                            com.liferay.portal.util.PropsUtil.get(
1040                                                    "value.object.listener.com.liferay.portal.model.PluginSetting")));
1041    
1042                    if (listenerClassNames.length > 0) {
1043                            try {
1044                                    List<ModelListener<PluginSetting>> listenersList = new ArrayList<ModelListener<PluginSetting>>();
1045    
1046                                    for (String listenerClassName : listenerClassNames) {
1047                                            listenersList.add((ModelListener<PluginSetting>)InstanceFactory.newInstance(
1048                                                            listenerClassName));
1049                                    }
1050    
1051                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1052                            }
1053                            catch (Exception e) {
1054                                    _log.error(e);
1055                            }
1056                    }
1057            }
1058    
1059            @BeanReference(type = AccountPersistence.class)
1060            protected AccountPersistence accountPersistence;
1061            @BeanReference(type = AddressPersistence.class)
1062            protected AddressPersistence addressPersistence;
1063            @BeanReference(type = BrowserTrackerPersistence.class)
1064            protected BrowserTrackerPersistence browserTrackerPersistence;
1065            @BeanReference(type = ClassNamePersistence.class)
1066            protected ClassNamePersistence classNamePersistence;
1067            @BeanReference(type = CompanyPersistence.class)
1068            protected CompanyPersistence companyPersistence;
1069            @BeanReference(type = ContactPersistence.class)
1070            protected ContactPersistence contactPersistence;
1071            @BeanReference(type = CountryPersistence.class)
1072            protected CountryPersistence countryPersistence;
1073            @BeanReference(type = EmailAddressPersistence.class)
1074            protected EmailAddressPersistence emailAddressPersistence;
1075            @BeanReference(type = GroupPersistence.class)
1076            protected GroupPersistence groupPersistence;
1077            @BeanReference(type = ImagePersistence.class)
1078            protected ImagePersistence imagePersistence;
1079            @BeanReference(type = LayoutPersistence.class)
1080            protected LayoutPersistence layoutPersistence;
1081            @BeanReference(type = LayoutPrototypePersistence.class)
1082            protected LayoutPrototypePersistence layoutPrototypePersistence;
1083            @BeanReference(type = LayoutSetPersistence.class)
1084            protected LayoutSetPersistence layoutSetPersistence;
1085            @BeanReference(type = LayoutSetPrototypePersistence.class)
1086            protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
1087            @BeanReference(type = ListTypePersistence.class)
1088            protected ListTypePersistence listTypePersistence;
1089            @BeanReference(type = LockPersistence.class)
1090            protected LockPersistence lockPersistence;
1091            @BeanReference(type = MembershipRequestPersistence.class)
1092            protected MembershipRequestPersistence membershipRequestPersistence;
1093            @BeanReference(type = OrganizationPersistence.class)
1094            protected OrganizationPersistence organizationPersistence;
1095            @BeanReference(type = OrgGroupPermissionPersistence.class)
1096            protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
1097            @BeanReference(type = OrgGroupRolePersistence.class)
1098            protected OrgGroupRolePersistence orgGroupRolePersistence;
1099            @BeanReference(type = OrgLaborPersistence.class)
1100            protected OrgLaborPersistence orgLaborPersistence;
1101            @BeanReference(type = PasswordPolicyPersistence.class)
1102            protected PasswordPolicyPersistence passwordPolicyPersistence;
1103            @BeanReference(type = PasswordPolicyRelPersistence.class)
1104            protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
1105            @BeanReference(type = PasswordTrackerPersistence.class)
1106            protected PasswordTrackerPersistence passwordTrackerPersistence;
1107            @BeanReference(type = PermissionPersistence.class)
1108            protected PermissionPersistence permissionPersistence;
1109            @BeanReference(type = PhonePersistence.class)
1110            protected PhonePersistence phonePersistence;
1111            @BeanReference(type = PluginSettingPersistence.class)
1112            protected PluginSettingPersistence pluginSettingPersistence;
1113            @BeanReference(type = PortletPersistence.class)
1114            protected PortletPersistence portletPersistence;
1115            @BeanReference(type = PortletItemPersistence.class)
1116            protected PortletItemPersistence portletItemPersistence;
1117            @BeanReference(type = PortletPreferencesPersistence.class)
1118            protected PortletPreferencesPersistence portletPreferencesPersistence;
1119            @BeanReference(type = RegionPersistence.class)
1120            protected RegionPersistence regionPersistence;
1121            @BeanReference(type = ReleasePersistence.class)
1122            protected ReleasePersistence releasePersistence;
1123            @BeanReference(type = ResourcePersistence.class)
1124            protected ResourcePersistence resourcePersistence;
1125            @BeanReference(type = ResourceActionPersistence.class)
1126            protected ResourceActionPersistence resourceActionPersistence;
1127            @BeanReference(type = ResourceCodePersistence.class)
1128            protected ResourceCodePersistence resourceCodePersistence;
1129            @BeanReference(type = ResourcePermissionPersistence.class)
1130            protected ResourcePermissionPersistence resourcePermissionPersistence;
1131            @BeanReference(type = RolePersistence.class)
1132            protected RolePersistence rolePersistence;
1133            @BeanReference(type = ServiceComponentPersistence.class)
1134            protected ServiceComponentPersistence serviceComponentPersistence;
1135            @BeanReference(type = ShardPersistence.class)
1136            protected ShardPersistence shardPersistence;
1137            @BeanReference(type = SubscriptionPersistence.class)
1138            protected SubscriptionPersistence subscriptionPersistence;
1139            @BeanReference(type = TicketPersistence.class)
1140            protected TicketPersistence ticketPersistence;
1141            @BeanReference(type = TeamPersistence.class)
1142            protected TeamPersistence teamPersistence;
1143            @BeanReference(type = UserPersistence.class)
1144            protected UserPersistence userPersistence;
1145            @BeanReference(type = UserGroupPersistence.class)
1146            protected UserGroupPersistence userGroupPersistence;
1147            @BeanReference(type = UserGroupGroupRolePersistence.class)
1148            protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
1149            @BeanReference(type = UserGroupRolePersistence.class)
1150            protected UserGroupRolePersistence userGroupRolePersistence;
1151            @BeanReference(type = UserIdMapperPersistence.class)
1152            protected UserIdMapperPersistence userIdMapperPersistence;
1153            @BeanReference(type = UserTrackerPersistence.class)
1154            protected UserTrackerPersistence userTrackerPersistence;
1155            @BeanReference(type = UserTrackerPathPersistence.class)
1156            protected UserTrackerPathPersistence userTrackerPathPersistence;
1157            @BeanReference(type = WebDAVPropsPersistence.class)
1158            protected WebDAVPropsPersistence webDAVPropsPersistence;
1159            @BeanReference(type = WebsitePersistence.class)
1160            protected WebsitePersistence websitePersistence;
1161            @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
1162            protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
1163            @BeanReference(type = WorkflowInstanceLinkPersistence.class)
1164            protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
1165            private static final String _SQL_SELECT_PLUGINSETTING = "SELECT pluginSetting FROM PluginSetting pluginSetting";
1166            private static final String _SQL_SELECT_PLUGINSETTING_WHERE = "SELECT pluginSetting FROM PluginSetting pluginSetting WHERE ";
1167            private static final String _SQL_COUNT_PLUGINSETTING = "SELECT COUNT(pluginSetting) FROM PluginSetting pluginSetting";
1168            private static final String _SQL_COUNT_PLUGINSETTING_WHERE = "SELECT COUNT(pluginSetting) FROM PluginSetting pluginSetting WHERE ";
1169            private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "pluginSetting.companyId = ?";
1170            private static final String _FINDER_COLUMN_C_I_T_COMPANYID_2 = "pluginSetting.companyId = ? AND ";
1171            private static final String _FINDER_COLUMN_C_I_T_PLUGINID_1 = "pluginSetting.pluginId IS NULL AND ";
1172            private static final String _FINDER_COLUMN_C_I_T_PLUGINID_2 = "pluginSetting.pluginId = ? AND ";
1173            private static final String _FINDER_COLUMN_C_I_T_PLUGINID_3 = "(pluginSetting.pluginId IS NULL OR pluginSetting.pluginId = ?) AND ";
1174            private static final String _FINDER_COLUMN_C_I_T_PLUGINTYPE_1 = "pluginSetting.pluginType IS NULL";
1175            private static final String _FINDER_COLUMN_C_I_T_PLUGINTYPE_2 = "pluginSetting.pluginType = ?";
1176            private static final String _FINDER_COLUMN_C_I_T_PLUGINTYPE_3 = "(pluginSetting.pluginType IS NULL OR pluginSetting.pluginType = ?)";
1177            private static final String _ORDER_BY_ENTITY_ALIAS = "pluginSetting.";
1178            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No PluginSetting exists with the primary key ";
1179            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No PluginSetting exists with the key {";
1180            private static Log _log = LogFactoryUtil.getLog(PluginSettingPersistenceImpl.class);
1181    }