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