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