001    /**
002     * Copyright (c) 2000-2012 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.portlet.wiki.service.persistence;
016    
017    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
018    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
019    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
020    import com.liferay.portal.kernel.dao.orm.FinderPath;
021    import com.liferay.portal.kernel.dao.orm.Query;
022    import com.liferay.portal.kernel.dao.orm.QueryPos;
023    import com.liferay.portal.kernel.dao.orm.QueryUtil;
024    import com.liferay.portal.kernel.dao.orm.Session;
025    import com.liferay.portal.kernel.exception.SystemException;
026    import com.liferay.portal.kernel.log.Log;
027    import com.liferay.portal.kernel.log.LogFactoryUtil;
028    import com.liferay.portal.kernel.util.GetterUtil;
029    import com.liferay.portal.kernel.util.InstanceFactory;
030    import com.liferay.portal.kernel.util.OrderByComparator;
031    import com.liferay.portal.kernel.util.StringBundler;
032    import com.liferay.portal.kernel.util.StringPool;
033    import com.liferay.portal.kernel.util.StringUtil;
034    import com.liferay.portal.kernel.util.UnmodifiableList;
035    import com.liferay.portal.kernel.util.Validator;
036    import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
037    import com.liferay.portal.model.CacheModel;
038    import com.liferay.portal.model.ModelListener;
039    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
040    
041    import com.liferay.portlet.wiki.NoSuchPageResourceException;
042    import com.liferay.portlet.wiki.model.WikiPageResource;
043    import com.liferay.portlet.wiki.model.impl.WikiPageResourceImpl;
044    import com.liferay.portlet.wiki.model.impl.WikiPageResourceModelImpl;
045    
046    import java.io.Serializable;
047    
048    import java.util.ArrayList;
049    import java.util.Collections;
050    import java.util.List;
051    
052    /**
053     * The persistence implementation for the wiki page resource service.
054     *
055     * <p>
056     * Caching information and settings can be found in <code>portal.properties</code>
057     * </p>
058     *
059     * @author Brian Wing Shun Chan
060     * @see WikiPageResourcePersistence
061     * @see WikiPageResourceUtil
062     * @generated
063     */
064    public class WikiPageResourcePersistenceImpl extends BasePersistenceImpl<WikiPageResource>
065            implements WikiPageResourcePersistence {
066            /*
067             * NOTE FOR DEVELOPERS:
068             *
069             * Never modify or reference this class directly. Always use {@link WikiPageResourceUtil} to access the wiki page resource persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
070             */
071            public static final String FINDER_CLASS_NAME_ENTITY = WikiPageResourceImpl.class.getName();
072            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
073                    ".List1";
074            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
075                    ".List2";
076            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(WikiPageResourceModelImpl.ENTITY_CACHE_ENABLED,
077                            WikiPageResourceModelImpl.FINDER_CACHE_ENABLED,
078                            WikiPageResourceImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
079                            "findAll", new String[0]);
080            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(WikiPageResourceModelImpl.ENTITY_CACHE_ENABLED,
081                            WikiPageResourceModelImpl.FINDER_CACHE_ENABLED,
082                            WikiPageResourceImpl.class,
083                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
084            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(WikiPageResourceModelImpl.ENTITY_CACHE_ENABLED,
085                            WikiPageResourceModelImpl.FINDER_CACHE_ENABLED, Long.class,
086                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
087            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(WikiPageResourceModelImpl.ENTITY_CACHE_ENABLED,
088                            WikiPageResourceModelImpl.FINDER_CACHE_ENABLED,
089                            WikiPageResourceImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
090                            "findByUuid",
091                            new String[] {
092                                    String.class.getName(),
093                                    
094                            Integer.class.getName(), Integer.class.getName(),
095                                    OrderByComparator.class.getName()
096                            });
097            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(WikiPageResourceModelImpl.ENTITY_CACHE_ENABLED,
098                            WikiPageResourceModelImpl.FINDER_CACHE_ENABLED,
099                            WikiPageResourceImpl.class,
100                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
101                            new String[] { String.class.getName() },
102                            WikiPageResourceModelImpl.UUID_COLUMN_BITMASK);
103            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(WikiPageResourceModelImpl.ENTITY_CACHE_ENABLED,
104                            WikiPageResourceModelImpl.FINDER_CACHE_ENABLED, Long.class,
105                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
106                            new String[] { String.class.getName() });
107    
108            /**
109             * Returns all the wiki page resources where uuid = &#63;.
110             *
111             * @param uuid the uuid
112             * @return the matching wiki page resources
113             * @throws SystemException if a system exception occurred
114             */
115            public List<WikiPageResource> findByUuid(String uuid)
116                    throws SystemException {
117                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
118            }
119    
120            /**
121             * Returns a range of all the wiki page resources where uuid = &#63;.
122             *
123             * <p>
124             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageResourceModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
125             * </p>
126             *
127             * @param uuid the uuid
128             * @param start the lower bound of the range of wiki page resources
129             * @param end the upper bound of the range of wiki page resources (not inclusive)
130             * @return the range of matching wiki page resources
131             * @throws SystemException if a system exception occurred
132             */
133            public List<WikiPageResource> findByUuid(String uuid, int start, int end)
134                    throws SystemException {
135                    return findByUuid(uuid, start, end, null);
136            }
137    
138            /**
139             * Returns an ordered range of all the wiki page resources where uuid = &#63;.
140             *
141             * <p>
142             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageResourceModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
143             * </p>
144             *
145             * @param uuid the uuid
146             * @param start the lower bound of the range of wiki page resources
147             * @param end the upper bound of the range of wiki page resources (not inclusive)
148             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
149             * @return the ordered range of matching wiki page resources
150             * @throws SystemException if a system exception occurred
151             */
152            public List<WikiPageResource> findByUuid(String uuid, int start, int end,
153                    OrderByComparator orderByComparator) throws SystemException {
154                    boolean pagination = true;
155                    FinderPath finderPath = null;
156                    Object[] finderArgs = null;
157    
158                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
159                                    (orderByComparator == null)) {
160                            pagination = false;
161                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
162                            finderArgs = new Object[] { uuid };
163                    }
164                    else {
165                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
166                            finderArgs = new Object[] { uuid, start, end, orderByComparator };
167                    }
168    
169                    List<WikiPageResource> list = (List<WikiPageResource>)FinderCacheUtil.getResult(finderPath,
170                                    finderArgs, this);
171    
172                    if ((list != null) && !list.isEmpty()) {
173                            for (WikiPageResource wikiPageResource : list) {
174                                    if (!Validator.equals(uuid, wikiPageResource.getUuid())) {
175                                            list = null;
176    
177                                            break;
178                                    }
179                            }
180                    }
181    
182                    if (list == null) {
183                            StringBundler query = null;
184    
185                            if (orderByComparator != null) {
186                                    query = new StringBundler(3 +
187                                                    (orderByComparator.getOrderByFields().length * 3));
188                            }
189                            else {
190                                    query = new StringBundler(3);
191                            }
192    
193                            query.append(_SQL_SELECT_WIKIPAGERESOURCE_WHERE);
194    
195                            boolean bindUuid = false;
196    
197                            if (uuid == null) {
198                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
199                            }
200                            else if (uuid.equals(StringPool.BLANK)) {
201                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
202                            }
203                            else {
204                                    bindUuid = true;
205    
206                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
207                            }
208    
209                            if (orderByComparator != null) {
210                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
211                                            orderByComparator);
212                            }
213                            else
214                             if (pagination) {
215                                    query.append(WikiPageResourceModelImpl.ORDER_BY_JPQL);
216                            }
217    
218                            String sql = query.toString();
219    
220                            Session session = null;
221    
222                            try {
223                                    session = openSession();
224    
225                                    Query q = session.createQuery(sql);
226    
227                                    QueryPos qPos = QueryPos.getInstance(q);
228    
229                                    if (bindUuid) {
230                                            qPos.add(uuid);
231                                    }
232    
233                                    if (!pagination) {
234                                            list = (List<WikiPageResource>)QueryUtil.list(q,
235                                                            getDialect(), start, end, false);
236    
237                                            Collections.sort(list);
238    
239                                            list = new UnmodifiableList<WikiPageResource>(list);
240                                    }
241                                    else {
242                                            list = (List<WikiPageResource>)QueryUtil.list(q,
243                                                            getDialect(), start, end);
244                                    }
245    
246                                    cacheResult(list);
247    
248                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
249                            }
250                            catch (Exception e) {
251                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
252    
253                                    throw processException(e);
254                            }
255                            finally {
256                                    closeSession(session);
257                            }
258                    }
259    
260                    return list;
261            }
262    
263            /**
264             * Returns the first wiki page resource in the ordered set where uuid = &#63;.
265             *
266             * @param uuid the uuid
267             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
268             * @return the first matching wiki page resource
269             * @throws com.liferay.portlet.wiki.NoSuchPageResourceException if a matching wiki page resource could not be found
270             * @throws SystemException if a system exception occurred
271             */
272            public WikiPageResource findByUuid_First(String uuid,
273                    OrderByComparator orderByComparator)
274                    throws NoSuchPageResourceException, SystemException {
275                    WikiPageResource wikiPageResource = fetchByUuid_First(uuid,
276                                    orderByComparator);
277    
278                    if (wikiPageResource != null) {
279                            return wikiPageResource;
280                    }
281    
282                    StringBundler msg = new StringBundler(4);
283    
284                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
285    
286                    msg.append("uuid=");
287                    msg.append(uuid);
288    
289                    msg.append(StringPool.CLOSE_CURLY_BRACE);
290    
291                    throw new NoSuchPageResourceException(msg.toString());
292            }
293    
294            /**
295             * Returns the first wiki page resource in the ordered set where uuid = &#63;.
296             *
297             * @param uuid the uuid
298             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
299             * @return the first matching wiki page resource, or <code>null</code> if a matching wiki page resource could not be found
300             * @throws SystemException if a system exception occurred
301             */
302            public WikiPageResource fetchByUuid_First(String uuid,
303                    OrderByComparator orderByComparator) throws SystemException {
304                    List<WikiPageResource> list = findByUuid(uuid, 0, 1, orderByComparator);
305    
306                    if (!list.isEmpty()) {
307                            return list.get(0);
308                    }
309    
310                    return null;
311            }
312    
313            /**
314             * Returns the last wiki page resource in the ordered set where uuid = &#63;.
315             *
316             * @param uuid the uuid
317             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
318             * @return the last matching wiki page resource
319             * @throws com.liferay.portlet.wiki.NoSuchPageResourceException if a matching wiki page resource could not be found
320             * @throws SystemException if a system exception occurred
321             */
322            public WikiPageResource findByUuid_Last(String uuid,
323                    OrderByComparator orderByComparator)
324                    throws NoSuchPageResourceException, SystemException {
325                    WikiPageResource wikiPageResource = fetchByUuid_Last(uuid,
326                                    orderByComparator);
327    
328                    if (wikiPageResource != null) {
329                            return wikiPageResource;
330                    }
331    
332                    StringBundler msg = new StringBundler(4);
333    
334                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
335    
336                    msg.append("uuid=");
337                    msg.append(uuid);
338    
339                    msg.append(StringPool.CLOSE_CURLY_BRACE);
340    
341                    throw new NoSuchPageResourceException(msg.toString());
342            }
343    
344            /**
345             * Returns the last wiki page resource in the ordered set where uuid = &#63;.
346             *
347             * @param uuid the uuid
348             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
349             * @return the last matching wiki page resource, or <code>null</code> if a matching wiki page resource could not be found
350             * @throws SystemException if a system exception occurred
351             */
352            public WikiPageResource fetchByUuid_Last(String uuid,
353                    OrderByComparator orderByComparator) throws SystemException {
354                    int count = countByUuid(uuid);
355    
356                    List<WikiPageResource> list = findByUuid(uuid, count - 1, count,
357                                    orderByComparator);
358    
359                    if (!list.isEmpty()) {
360                            return list.get(0);
361                    }
362    
363                    return null;
364            }
365    
366            /**
367             * Returns the wiki page resources before and after the current wiki page resource in the ordered set where uuid = &#63;.
368             *
369             * @param resourcePrimKey the primary key of the current wiki page resource
370             * @param uuid the uuid
371             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
372             * @return the previous, current, and next wiki page resource
373             * @throws com.liferay.portlet.wiki.NoSuchPageResourceException if a wiki page resource with the primary key could not be found
374             * @throws SystemException if a system exception occurred
375             */
376            public WikiPageResource[] findByUuid_PrevAndNext(long resourcePrimKey,
377                    String uuid, OrderByComparator orderByComparator)
378                    throws NoSuchPageResourceException, SystemException {
379                    WikiPageResource wikiPageResource = findByPrimaryKey(resourcePrimKey);
380    
381                    Session session = null;
382    
383                    try {
384                            session = openSession();
385    
386                            WikiPageResource[] array = new WikiPageResourceImpl[3];
387    
388                            array[0] = getByUuid_PrevAndNext(session, wikiPageResource, uuid,
389                                            orderByComparator, true);
390    
391                            array[1] = wikiPageResource;
392    
393                            array[2] = getByUuid_PrevAndNext(session, wikiPageResource, uuid,
394                                            orderByComparator, false);
395    
396                            return array;
397                    }
398                    catch (Exception e) {
399                            throw processException(e);
400                    }
401                    finally {
402                            closeSession(session);
403                    }
404            }
405    
406            protected WikiPageResource getByUuid_PrevAndNext(Session session,
407                    WikiPageResource wikiPageResource, String uuid,
408                    OrderByComparator orderByComparator, boolean previous) {
409                    StringBundler query = null;
410    
411                    if (orderByComparator != null) {
412                            query = new StringBundler(6 +
413                                            (orderByComparator.getOrderByFields().length * 6));
414                    }
415                    else {
416                            query = new StringBundler(3);
417                    }
418    
419                    query.append(_SQL_SELECT_WIKIPAGERESOURCE_WHERE);
420    
421                    boolean bindUuid = false;
422    
423                    if (uuid == null) {
424                            query.append(_FINDER_COLUMN_UUID_UUID_1);
425                    }
426                    else if (uuid.equals(StringPool.BLANK)) {
427                            query.append(_FINDER_COLUMN_UUID_UUID_3);
428                    }
429                    else {
430                            bindUuid = true;
431    
432                            query.append(_FINDER_COLUMN_UUID_UUID_2);
433                    }
434    
435                    if (orderByComparator != null) {
436                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
437    
438                            if (orderByConditionFields.length > 0) {
439                                    query.append(WHERE_AND);
440                            }
441    
442                            for (int i = 0; i < orderByConditionFields.length; i++) {
443                                    query.append(_ORDER_BY_ENTITY_ALIAS);
444                                    query.append(orderByConditionFields[i]);
445    
446                                    if ((i + 1) < orderByConditionFields.length) {
447                                            if (orderByComparator.isAscending() ^ previous) {
448                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
449                                            }
450                                            else {
451                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
452                                            }
453                                    }
454                                    else {
455                                            if (orderByComparator.isAscending() ^ previous) {
456                                                    query.append(WHERE_GREATER_THAN);
457                                            }
458                                            else {
459                                                    query.append(WHERE_LESSER_THAN);
460                                            }
461                                    }
462                            }
463    
464                            query.append(ORDER_BY_CLAUSE);
465    
466                            String[] orderByFields = orderByComparator.getOrderByFields();
467    
468                            for (int i = 0; i < orderByFields.length; i++) {
469                                    query.append(_ORDER_BY_ENTITY_ALIAS);
470                                    query.append(orderByFields[i]);
471    
472                                    if ((i + 1) < orderByFields.length) {
473                                            if (orderByComparator.isAscending() ^ previous) {
474                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
475                                            }
476                                            else {
477                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
478                                            }
479                                    }
480                                    else {
481                                            if (orderByComparator.isAscending() ^ previous) {
482                                                    query.append(ORDER_BY_ASC);
483                                            }
484                                            else {
485                                                    query.append(ORDER_BY_DESC);
486                                            }
487                                    }
488                            }
489                    }
490                    else {
491                            query.append(WikiPageResourceModelImpl.ORDER_BY_JPQL);
492                    }
493    
494                    String sql = query.toString();
495    
496                    Query q = session.createQuery(sql);
497    
498                    q.setFirstResult(0);
499                    q.setMaxResults(2);
500    
501                    QueryPos qPos = QueryPos.getInstance(q);
502    
503                    if (bindUuid) {
504                            qPos.add(uuid);
505                    }
506    
507                    if (orderByComparator != null) {
508                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPageResource);
509    
510                            for (Object value : values) {
511                                    qPos.add(value);
512                            }
513                    }
514    
515                    List<WikiPageResource> list = q.list();
516    
517                    if (list.size() == 2) {
518                            return list.get(1);
519                    }
520                    else {
521                            return null;
522                    }
523            }
524    
525            /**
526             * Removes all the wiki page resources where uuid = &#63; from the database.
527             *
528             * @param uuid the uuid
529             * @throws SystemException if a system exception occurred
530             */
531            public void removeByUuid(String uuid) throws SystemException {
532                    for (WikiPageResource wikiPageResource : findByUuid(uuid,
533                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
534                            remove(wikiPageResource);
535                    }
536            }
537    
538            /**
539             * Returns the number of wiki page resources where uuid = &#63;.
540             *
541             * @param uuid the uuid
542             * @return the number of matching wiki page resources
543             * @throws SystemException if a system exception occurred
544             */
545            public int countByUuid(String uuid) throws SystemException {
546                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
547    
548                    Object[] finderArgs = new Object[] { uuid };
549    
550                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
551                                    this);
552    
553                    if (count == null) {
554                            StringBundler query = new StringBundler(2);
555    
556                            query.append(_SQL_COUNT_WIKIPAGERESOURCE_WHERE);
557    
558                            boolean bindUuid = false;
559    
560                            if (uuid == null) {
561                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
562                            }
563                            else if (uuid.equals(StringPool.BLANK)) {
564                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
565                            }
566                            else {
567                                    bindUuid = true;
568    
569                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
570                            }
571    
572                            String sql = query.toString();
573    
574                            Session session = null;
575    
576                            try {
577                                    session = openSession();
578    
579                                    Query q = session.createQuery(sql);
580    
581                                    QueryPos qPos = QueryPos.getInstance(q);
582    
583                                    if (bindUuid) {
584                                            qPos.add(uuid);
585                                    }
586    
587                                    count = (Long)q.uniqueResult();
588    
589                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
590                            }
591                            catch (Exception e) {
592                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
593    
594                                    throw processException(e);
595                            }
596                            finally {
597                                    closeSession(session);
598                            }
599                    }
600    
601                    return count.intValue();
602            }
603    
604            private static final String _FINDER_COLUMN_UUID_UUID_1 = "wikiPageResource.uuid IS NULL";
605            private static final String _FINDER_COLUMN_UUID_UUID_2 = "wikiPageResource.uuid = ?";
606            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(wikiPageResource.uuid IS NULL OR wikiPageResource.uuid = '')";
607            public static final FinderPath FINDER_PATH_FETCH_BY_N_T = new FinderPath(WikiPageResourceModelImpl.ENTITY_CACHE_ENABLED,
608                            WikiPageResourceModelImpl.FINDER_CACHE_ENABLED,
609                            WikiPageResourceImpl.class, FINDER_CLASS_NAME_ENTITY, "fetchByN_T",
610                            new String[] { Long.class.getName(), String.class.getName() },
611                            WikiPageResourceModelImpl.NODEID_COLUMN_BITMASK |
612                            WikiPageResourceModelImpl.TITLE_COLUMN_BITMASK);
613            public static final FinderPath FINDER_PATH_COUNT_BY_N_T = new FinderPath(WikiPageResourceModelImpl.ENTITY_CACHE_ENABLED,
614                            WikiPageResourceModelImpl.FINDER_CACHE_ENABLED, Long.class,
615                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByN_T",
616                            new String[] { Long.class.getName(), String.class.getName() });
617    
618            /**
619             * Returns the wiki page resource where nodeId = &#63; and title = &#63; or throws a {@link com.liferay.portlet.wiki.NoSuchPageResourceException} if it could not be found.
620             *
621             * @param nodeId the node ID
622             * @param title the title
623             * @return the matching wiki page resource
624             * @throws com.liferay.portlet.wiki.NoSuchPageResourceException if a matching wiki page resource could not be found
625             * @throws SystemException if a system exception occurred
626             */
627            public WikiPageResource findByN_T(long nodeId, String title)
628                    throws NoSuchPageResourceException, SystemException {
629                    WikiPageResource wikiPageResource = fetchByN_T(nodeId, title);
630    
631                    if (wikiPageResource == null) {
632                            StringBundler msg = new StringBundler(6);
633    
634                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
635    
636                            msg.append("nodeId=");
637                            msg.append(nodeId);
638    
639                            msg.append(", title=");
640                            msg.append(title);
641    
642                            msg.append(StringPool.CLOSE_CURLY_BRACE);
643    
644                            if (_log.isWarnEnabled()) {
645                                    _log.warn(msg.toString());
646                            }
647    
648                            throw new NoSuchPageResourceException(msg.toString());
649                    }
650    
651                    return wikiPageResource;
652            }
653    
654            /**
655             * Returns the wiki page resource where nodeId = &#63; and title = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
656             *
657             * @param nodeId the node ID
658             * @param title the title
659             * @return the matching wiki page resource, or <code>null</code> if a matching wiki page resource could not be found
660             * @throws SystemException if a system exception occurred
661             */
662            public WikiPageResource fetchByN_T(long nodeId, String title)
663                    throws SystemException {
664                    return fetchByN_T(nodeId, title, true);
665            }
666    
667            /**
668             * Returns the wiki page resource where nodeId = &#63; and title = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
669             *
670             * @param nodeId the node ID
671             * @param title the title
672             * @param retrieveFromCache whether to use the finder cache
673             * @return the matching wiki page resource, or <code>null</code> if a matching wiki page resource could not be found
674             * @throws SystemException if a system exception occurred
675             */
676            public WikiPageResource fetchByN_T(long nodeId, String title,
677                    boolean retrieveFromCache) throws SystemException {
678                    Object[] finderArgs = new Object[] { nodeId, title };
679    
680                    Object result = null;
681    
682                    if (retrieveFromCache) {
683                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_N_T,
684                                            finderArgs, this);
685                    }
686    
687                    if (result instanceof WikiPageResource) {
688                            WikiPageResource wikiPageResource = (WikiPageResource)result;
689    
690                            if ((nodeId != wikiPageResource.getNodeId()) ||
691                                            !Validator.equals(title, wikiPageResource.getTitle())) {
692                                    result = null;
693                            }
694                    }
695    
696                    if (result == null) {
697                            StringBundler query = new StringBundler(4);
698    
699                            query.append(_SQL_SELECT_WIKIPAGERESOURCE_WHERE);
700    
701                            query.append(_FINDER_COLUMN_N_T_NODEID_2);
702    
703                            boolean bindTitle = false;
704    
705                            if (title == null) {
706                                    query.append(_FINDER_COLUMN_N_T_TITLE_1);
707                            }
708                            else if (title.equals(StringPool.BLANK)) {
709                                    query.append(_FINDER_COLUMN_N_T_TITLE_3);
710                            }
711                            else {
712                                    bindTitle = true;
713    
714                                    query.append(_FINDER_COLUMN_N_T_TITLE_2);
715                            }
716    
717                            String sql = query.toString();
718    
719                            Session session = null;
720    
721                            try {
722                                    session = openSession();
723    
724                                    Query q = session.createQuery(sql);
725    
726                                    QueryPos qPos = QueryPos.getInstance(q);
727    
728                                    qPos.add(nodeId);
729    
730                                    if (bindTitle) {
731                                            qPos.add(title);
732                                    }
733    
734                                    List<WikiPageResource> list = q.list();
735    
736                                    if (list.isEmpty()) {
737                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_T,
738                                                    finderArgs, list);
739                                    }
740                                    else {
741                                            WikiPageResource wikiPageResource = list.get(0);
742    
743                                            result = wikiPageResource;
744    
745                                            cacheResult(wikiPageResource);
746    
747                                            if ((wikiPageResource.getNodeId() != nodeId) ||
748                                                            (wikiPageResource.getTitle() == null) ||
749                                                            !wikiPageResource.getTitle().equals(title)) {
750                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_T,
751                                                            finderArgs, wikiPageResource);
752                                            }
753                                    }
754                            }
755                            catch (Exception e) {
756                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_N_T,
757                                            finderArgs);
758    
759                                    throw processException(e);
760                            }
761                            finally {
762                                    closeSession(session);
763                            }
764                    }
765    
766                    if (result instanceof List<?>) {
767                            return null;
768                    }
769                    else {
770                            return (WikiPageResource)result;
771                    }
772            }
773    
774            /**
775             * Removes the wiki page resource where nodeId = &#63; and title = &#63; from the database.
776             *
777             * @param nodeId the node ID
778             * @param title the title
779             * @return the wiki page resource that was removed
780             * @throws SystemException if a system exception occurred
781             */
782            public WikiPageResource removeByN_T(long nodeId, String title)
783                    throws NoSuchPageResourceException, SystemException {
784                    WikiPageResource wikiPageResource = findByN_T(nodeId, title);
785    
786                    return remove(wikiPageResource);
787            }
788    
789            /**
790             * Returns the number of wiki page resources where nodeId = &#63; and title = &#63;.
791             *
792             * @param nodeId the node ID
793             * @param title the title
794             * @return the number of matching wiki page resources
795             * @throws SystemException if a system exception occurred
796             */
797            public int countByN_T(long nodeId, String title) throws SystemException {
798                    FinderPath finderPath = FINDER_PATH_COUNT_BY_N_T;
799    
800                    Object[] finderArgs = new Object[] { nodeId, title };
801    
802                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
803                                    this);
804    
805                    if (count == null) {
806                            StringBundler query = new StringBundler(3);
807    
808                            query.append(_SQL_COUNT_WIKIPAGERESOURCE_WHERE);
809    
810                            query.append(_FINDER_COLUMN_N_T_NODEID_2);
811    
812                            boolean bindTitle = false;
813    
814                            if (title == null) {
815                                    query.append(_FINDER_COLUMN_N_T_TITLE_1);
816                            }
817                            else if (title.equals(StringPool.BLANK)) {
818                                    query.append(_FINDER_COLUMN_N_T_TITLE_3);
819                            }
820                            else {
821                                    bindTitle = true;
822    
823                                    query.append(_FINDER_COLUMN_N_T_TITLE_2);
824                            }
825    
826                            String sql = query.toString();
827    
828                            Session session = null;
829    
830                            try {
831                                    session = openSession();
832    
833                                    Query q = session.createQuery(sql);
834    
835                                    QueryPos qPos = QueryPos.getInstance(q);
836    
837                                    qPos.add(nodeId);
838    
839                                    if (bindTitle) {
840                                            qPos.add(title);
841                                    }
842    
843                                    count = (Long)q.uniqueResult();
844    
845                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
846                            }
847                            catch (Exception e) {
848                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
849    
850                                    throw processException(e);
851                            }
852                            finally {
853                                    closeSession(session);
854                            }
855                    }
856    
857                    return count.intValue();
858            }
859    
860            private static final String _FINDER_COLUMN_N_T_NODEID_2 = "wikiPageResource.nodeId = ? AND ";
861            private static final String _FINDER_COLUMN_N_T_TITLE_1 = "wikiPageResource.title IS NULL";
862            private static final String _FINDER_COLUMN_N_T_TITLE_2 = "wikiPageResource.title = ?";
863            private static final String _FINDER_COLUMN_N_T_TITLE_3 = "(wikiPageResource.title IS NULL OR wikiPageResource.title = '')";
864    
865            /**
866             * Caches the wiki page resource in the entity cache if it is enabled.
867             *
868             * @param wikiPageResource the wiki page resource
869             */
870            public void cacheResult(WikiPageResource wikiPageResource) {
871                    EntityCacheUtil.putResult(WikiPageResourceModelImpl.ENTITY_CACHE_ENABLED,
872                            WikiPageResourceImpl.class, wikiPageResource.getPrimaryKey(),
873                            wikiPageResource);
874    
875                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_T,
876                            new Object[] {
877                                    wikiPageResource.getNodeId(), wikiPageResource.getTitle()
878                            }, wikiPageResource);
879    
880                    wikiPageResource.resetOriginalValues();
881            }
882    
883            /**
884             * Caches the wiki page resources in the entity cache if it is enabled.
885             *
886             * @param wikiPageResources the wiki page resources
887             */
888            public void cacheResult(List<WikiPageResource> wikiPageResources) {
889                    for (WikiPageResource wikiPageResource : wikiPageResources) {
890                            if (EntityCacheUtil.getResult(
891                                                    WikiPageResourceModelImpl.ENTITY_CACHE_ENABLED,
892                                                    WikiPageResourceImpl.class,
893                                                    wikiPageResource.getPrimaryKey()) == null) {
894                                    cacheResult(wikiPageResource);
895                            }
896                            else {
897                                    wikiPageResource.resetOriginalValues();
898                            }
899                    }
900            }
901    
902            /**
903             * Clears the cache for all wiki page resources.
904             *
905             * <p>
906             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
907             * </p>
908             */
909            @Override
910            public void clearCache() {
911                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
912                            CacheRegistryUtil.clear(WikiPageResourceImpl.class.getName());
913                    }
914    
915                    EntityCacheUtil.clearCache(WikiPageResourceImpl.class.getName());
916    
917                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
918                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
919                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
920            }
921    
922            /**
923             * Clears the cache for the wiki page resource.
924             *
925             * <p>
926             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
927             * </p>
928             */
929            @Override
930            public void clearCache(WikiPageResource wikiPageResource) {
931                    EntityCacheUtil.removeResult(WikiPageResourceModelImpl.ENTITY_CACHE_ENABLED,
932                            WikiPageResourceImpl.class, wikiPageResource.getPrimaryKey());
933    
934                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
935                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
936    
937                    clearUniqueFindersCache(wikiPageResource);
938            }
939    
940            @Override
941            public void clearCache(List<WikiPageResource> wikiPageResources) {
942                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
943                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
944    
945                    for (WikiPageResource wikiPageResource : wikiPageResources) {
946                            EntityCacheUtil.removeResult(WikiPageResourceModelImpl.ENTITY_CACHE_ENABLED,
947                                    WikiPageResourceImpl.class, wikiPageResource.getPrimaryKey());
948    
949                            clearUniqueFindersCache(wikiPageResource);
950                    }
951            }
952    
953            protected void cacheUniqueFindersCache(WikiPageResource wikiPageResource) {
954                    if (wikiPageResource.isNew()) {
955                            Object[] args = new Object[] {
956                                            wikiPageResource.getNodeId(), wikiPageResource.getTitle()
957                                    };
958    
959                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_N_T, args,
960                                    Long.valueOf(1));
961                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_T, args,
962                                    wikiPageResource);
963                    }
964                    else {
965                            WikiPageResourceModelImpl wikiPageResourceModelImpl = (WikiPageResourceModelImpl)wikiPageResource;
966    
967                            if ((wikiPageResourceModelImpl.getColumnBitmask() &
968                                            FINDER_PATH_FETCH_BY_N_T.getColumnBitmask()) != 0) {
969                                    Object[] args = new Object[] {
970                                                    wikiPageResource.getNodeId(),
971                                                    wikiPageResource.getTitle()
972                                            };
973    
974                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_N_T, args,
975                                            Long.valueOf(1));
976                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_T, args,
977                                            wikiPageResource);
978                            }
979                    }
980            }
981    
982            protected void clearUniqueFindersCache(WikiPageResource wikiPageResource) {
983                    WikiPageResourceModelImpl wikiPageResourceModelImpl = (WikiPageResourceModelImpl)wikiPageResource;
984    
985                    Object[] args = new Object[] {
986                                    wikiPageResource.getNodeId(), wikiPageResource.getTitle()
987                            };
988    
989                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_T, args);
990                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_N_T, args);
991    
992                    if ((wikiPageResourceModelImpl.getColumnBitmask() &
993                                    FINDER_PATH_FETCH_BY_N_T.getColumnBitmask()) != 0) {
994                            args = new Object[] {
995                                            wikiPageResourceModelImpl.getOriginalNodeId(),
996                                            wikiPageResourceModelImpl.getOriginalTitle()
997                                    };
998    
999                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_T, args);
1000                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_N_T, args);
1001                    }
1002            }
1003    
1004            /**
1005             * Creates a new wiki page resource with the primary key. Does not add the wiki page resource to the database.
1006             *
1007             * @param resourcePrimKey the primary key for the new wiki page resource
1008             * @return the new wiki page resource
1009             */
1010            public WikiPageResource create(long resourcePrimKey) {
1011                    WikiPageResource wikiPageResource = new WikiPageResourceImpl();
1012    
1013                    wikiPageResource.setNew(true);
1014                    wikiPageResource.setPrimaryKey(resourcePrimKey);
1015    
1016                    String uuid = PortalUUIDUtil.generate();
1017    
1018                    wikiPageResource.setUuid(uuid);
1019    
1020                    return wikiPageResource;
1021            }
1022    
1023            /**
1024             * Removes the wiki page resource with the primary key from the database. Also notifies the appropriate model listeners.
1025             *
1026             * @param resourcePrimKey the primary key of the wiki page resource
1027             * @return the wiki page resource that was removed
1028             * @throws com.liferay.portlet.wiki.NoSuchPageResourceException if a wiki page resource with the primary key could not be found
1029             * @throws SystemException if a system exception occurred
1030             */
1031            public WikiPageResource remove(long resourcePrimKey)
1032                    throws NoSuchPageResourceException, SystemException {
1033                    return remove((Serializable)resourcePrimKey);
1034            }
1035    
1036            /**
1037             * Removes the wiki page resource with the primary key from the database. Also notifies the appropriate model listeners.
1038             *
1039             * @param primaryKey the primary key of the wiki page resource
1040             * @return the wiki page resource that was removed
1041             * @throws com.liferay.portlet.wiki.NoSuchPageResourceException if a wiki page resource with the primary key could not be found
1042             * @throws SystemException if a system exception occurred
1043             */
1044            @Override
1045            public WikiPageResource remove(Serializable primaryKey)
1046                    throws NoSuchPageResourceException, SystemException {
1047                    Session session = null;
1048    
1049                    try {
1050                            session = openSession();
1051    
1052                            WikiPageResource wikiPageResource = (WikiPageResource)session.get(WikiPageResourceImpl.class,
1053                                            primaryKey);
1054    
1055                            if (wikiPageResource == null) {
1056                                    if (_log.isWarnEnabled()) {
1057                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1058                                    }
1059    
1060                                    throw new NoSuchPageResourceException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1061                                            primaryKey);
1062                            }
1063    
1064                            return remove(wikiPageResource);
1065                    }
1066                    catch (NoSuchPageResourceException nsee) {
1067                            throw nsee;
1068                    }
1069                    catch (Exception e) {
1070                            throw processException(e);
1071                    }
1072                    finally {
1073                            closeSession(session);
1074                    }
1075            }
1076    
1077            @Override
1078            protected WikiPageResource removeImpl(WikiPageResource wikiPageResource)
1079                    throws SystemException {
1080                    wikiPageResource = toUnwrappedModel(wikiPageResource);
1081    
1082                    Session session = null;
1083    
1084                    try {
1085                            session = openSession();
1086    
1087                            if (!session.contains(wikiPageResource)) {
1088                                    wikiPageResource = (WikiPageResource)session.get(WikiPageResourceImpl.class,
1089                                                    wikiPageResource.getPrimaryKeyObj());
1090                            }
1091    
1092                            if (wikiPageResource != null) {
1093                                    session.delete(wikiPageResource);
1094                            }
1095                    }
1096                    catch (Exception e) {
1097                            throw processException(e);
1098                    }
1099                    finally {
1100                            closeSession(session);
1101                    }
1102    
1103                    if (wikiPageResource != null) {
1104                            clearCache(wikiPageResource);
1105                    }
1106    
1107                    return wikiPageResource;
1108            }
1109    
1110            @Override
1111            public WikiPageResource updateImpl(
1112                    com.liferay.portlet.wiki.model.WikiPageResource wikiPageResource)
1113                    throws SystemException {
1114                    wikiPageResource = toUnwrappedModel(wikiPageResource);
1115    
1116                    boolean isNew = wikiPageResource.isNew();
1117    
1118                    WikiPageResourceModelImpl wikiPageResourceModelImpl = (WikiPageResourceModelImpl)wikiPageResource;
1119    
1120                    if (Validator.isNull(wikiPageResource.getUuid())) {
1121                            String uuid = PortalUUIDUtil.generate();
1122    
1123                            wikiPageResource.setUuid(uuid);
1124                    }
1125    
1126                    Session session = null;
1127    
1128                    try {
1129                            session = openSession();
1130    
1131                            if (wikiPageResource.isNew()) {
1132                                    session.save(wikiPageResource);
1133    
1134                                    wikiPageResource.setNew(false);
1135                            }
1136                            else {
1137                                    session.merge(wikiPageResource);
1138                            }
1139                    }
1140                    catch (Exception e) {
1141                            throw processException(e);
1142                    }
1143                    finally {
1144                            closeSession(session);
1145                    }
1146    
1147                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1148    
1149                    if (isNew || !WikiPageResourceModelImpl.COLUMN_BITMASK_ENABLED) {
1150                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1151                    }
1152    
1153                    else {
1154                            if ((wikiPageResourceModelImpl.getColumnBitmask() &
1155                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
1156                                    Object[] args = new Object[] {
1157                                                    wikiPageResourceModelImpl.getOriginalUuid()
1158                                            };
1159    
1160                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
1161                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
1162                                            args);
1163    
1164                                    args = new Object[] { wikiPageResourceModelImpl.getUuid() };
1165    
1166                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
1167                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
1168                                            args);
1169                            }
1170                    }
1171    
1172                    EntityCacheUtil.putResult(WikiPageResourceModelImpl.ENTITY_CACHE_ENABLED,
1173                            WikiPageResourceImpl.class, wikiPageResource.getPrimaryKey(),
1174                            wikiPageResource);
1175    
1176                    clearUniqueFindersCache(wikiPageResource);
1177                    cacheUniqueFindersCache(wikiPageResource);
1178    
1179                    return wikiPageResource;
1180            }
1181    
1182            protected WikiPageResource toUnwrappedModel(
1183                    WikiPageResource wikiPageResource) {
1184                    if (wikiPageResource instanceof WikiPageResourceImpl) {
1185                            return wikiPageResource;
1186                    }
1187    
1188                    WikiPageResourceImpl wikiPageResourceImpl = new WikiPageResourceImpl();
1189    
1190                    wikiPageResourceImpl.setNew(wikiPageResource.isNew());
1191                    wikiPageResourceImpl.setPrimaryKey(wikiPageResource.getPrimaryKey());
1192    
1193                    wikiPageResourceImpl.setUuid(wikiPageResource.getUuid());
1194                    wikiPageResourceImpl.setResourcePrimKey(wikiPageResource.getResourcePrimKey());
1195                    wikiPageResourceImpl.setNodeId(wikiPageResource.getNodeId());
1196                    wikiPageResourceImpl.setTitle(wikiPageResource.getTitle());
1197    
1198                    return wikiPageResourceImpl;
1199            }
1200    
1201            /**
1202             * Returns the wiki page resource with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
1203             *
1204             * @param primaryKey the primary key of the wiki page resource
1205             * @return the wiki page resource
1206             * @throws com.liferay.portlet.wiki.NoSuchPageResourceException if a wiki page resource with the primary key could not be found
1207             * @throws SystemException if a system exception occurred
1208             */
1209            @Override
1210            public WikiPageResource findByPrimaryKey(Serializable primaryKey)
1211                    throws NoSuchPageResourceException, SystemException {
1212                    WikiPageResource wikiPageResource = fetchByPrimaryKey(primaryKey);
1213    
1214                    if (wikiPageResource == null) {
1215                            if (_log.isWarnEnabled()) {
1216                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1217                            }
1218    
1219                            throw new NoSuchPageResourceException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1220                                    primaryKey);
1221                    }
1222    
1223                    return wikiPageResource;
1224            }
1225    
1226            /**
1227             * Returns the wiki page resource with the primary key or throws a {@link com.liferay.portlet.wiki.NoSuchPageResourceException} if it could not be found.
1228             *
1229             * @param resourcePrimKey the primary key of the wiki page resource
1230             * @return the wiki page resource
1231             * @throws com.liferay.portlet.wiki.NoSuchPageResourceException if a wiki page resource with the primary key could not be found
1232             * @throws SystemException if a system exception occurred
1233             */
1234            public WikiPageResource findByPrimaryKey(long resourcePrimKey)
1235                    throws NoSuchPageResourceException, SystemException {
1236                    return findByPrimaryKey((Serializable)resourcePrimKey);
1237            }
1238    
1239            /**
1240             * Returns the wiki page resource with the primary key or returns <code>null</code> if it could not be found.
1241             *
1242             * @param primaryKey the primary key of the wiki page resource
1243             * @return the wiki page resource, or <code>null</code> if a wiki page resource with the primary key could not be found
1244             * @throws SystemException if a system exception occurred
1245             */
1246            @Override
1247            public WikiPageResource fetchByPrimaryKey(Serializable primaryKey)
1248                    throws SystemException {
1249                    WikiPageResource wikiPageResource = (WikiPageResource)EntityCacheUtil.getResult(WikiPageResourceModelImpl.ENTITY_CACHE_ENABLED,
1250                                    WikiPageResourceImpl.class, primaryKey);
1251    
1252                    if (wikiPageResource == _nullWikiPageResource) {
1253                            return null;
1254                    }
1255    
1256                    if (wikiPageResource == null) {
1257                            Session session = null;
1258    
1259                            try {
1260                                    session = openSession();
1261    
1262                                    wikiPageResource = (WikiPageResource)session.get(WikiPageResourceImpl.class,
1263                                                    primaryKey);
1264    
1265                                    if (wikiPageResource != null) {
1266                                            cacheResult(wikiPageResource);
1267                                    }
1268                                    else {
1269                                            EntityCacheUtil.putResult(WikiPageResourceModelImpl.ENTITY_CACHE_ENABLED,
1270                                                    WikiPageResourceImpl.class, primaryKey,
1271                                                    _nullWikiPageResource);
1272                                    }
1273                            }
1274                            catch (Exception e) {
1275                                    EntityCacheUtil.removeResult(WikiPageResourceModelImpl.ENTITY_CACHE_ENABLED,
1276                                            WikiPageResourceImpl.class, primaryKey);
1277    
1278                                    throw processException(e);
1279                            }
1280                            finally {
1281                                    closeSession(session);
1282                            }
1283                    }
1284    
1285                    return wikiPageResource;
1286            }
1287    
1288            /**
1289             * Returns the wiki page resource with the primary key or returns <code>null</code> if it could not be found.
1290             *
1291             * @param resourcePrimKey the primary key of the wiki page resource
1292             * @return the wiki page resource, or <code>null</code> if a wiki page resource with the primary key could not be found
1293             * @throws SystemException if a system exception occurred
1294             */
1295            public WikiPageResource fetchByPrimaryKey(long resourcePrimKey)
1296                    throws SystemException {
1297                    return fetchByPrimaryKey((Serializable)resourcePrimKey);
1298            }
1299    
1300            /**
1301             * Returns all the wiki page resources.
1302             *
1303             * @return the wiki page resources
1304             * @throws SystemException if a system exception occurred
1305             */
1306            public List<WikiPageResource> findAll() throws SystemException {
1307                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1308            }
1309    
1310            /**
1311             * Returns a range of all the wiki page resources.
1312             *
1313             * <p>
1314             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageResourceModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1315             * </p>
1316             *
1317             * @param start the lower bound of the range of wiki page resources
1318             * @param end the upper bound of the range of wiki page resources (not inclusive)
1319             * @return the range of wiki page resources
1320             * @throws SystemException if a system exception occurred
1321             */
1322            public List<WikiPageResource> findAll(int start, int end)
1323                    throws SystemException {
1324                    return findAll(start, end, null);
1325            }
1326    
1327            /**
1328             * Returns an ordered range of all the wiki page resources.
1329             *
1330             * <p>
1331             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageResourceModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1332             * </p>
1333             *
1334             * @param start the lower bound of the range of wiki page resources
1335             * @param end the upper bound of the range of wiki page resources (not inclusive)
1336             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1337             * @return the ordered range of wiki page resources
1338             * @throws SystemException if a system exception occurred
1339             */
1340            public List<WikiPageResource> findAll(int start, int end,
1341                    OrderByComparator orderByComparator) throws SystemException {
1342                    boolean pagination = true;
1343                    FinderPath finderPath = null;
1344                    Object[] finderArgs = null;
1345    
1346                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1347                                    (orderByComparator == null)) {
1348                            pagination = false;
1349                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1350                            finderArgs = FINDER_ARGS_EMPTY;
1351                    }
1352                    else {
1353                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1354                            finderArgs = new Object[] { start, end, orderByComparator };
1355                    }
1356    
1357                    List<WikiPageResource> list = (List<WikiPageResource>)FinderCacheUtil.getResult(finderPath,
1358                                    finderArgs, this);
1359    
1360                    if (list == null) {
1361                            StringBundler query = null;
1362                            String sql = null;
1363    
1364                            if (orderByComparator != null) {
1365                                    query = new StringBundler(2 +
1366                                                    (orderByComparator.getOrderByFields().length * 3));
1367    
1368                                    query.append(_SQL_SELECT_WIKIPAGERESOURCE);
1369    
1370                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1371                                            orderByComparator);
1372    
1373                                    sql = query.toString();
1374                            }
1375                            else {
1376                                    sql = _SQL_SELECT_WIKIPAGERESOURCE;
1377    
1378                                    if (pagination) {
1379                                            sql = sql.concat(WikiPageResourceModelImpl.ORDER_BY_JPQL);
1380                                    }
1381                            }
1382    
1383                            Session session = null;
1384    
1385                            try {
1386                                    session = openSession();
1387    
1388                                    Query q = session.createQuery(sql);
1389    
1390                                    if (!pagination) {
1391                                            list = (List<WikiPageResource>)QueryUtil.list(q,
1392                                                            getDialect(), start, end, false);
1393    
1394                                            Collections.sort(list);
1395    
1396                                            list = new UnmodifiableList<WikiPageResource>(list);
1397                                    }
1398                                    else {
1399                                            list = (List<WikiPageResource>)QueryUtil.list(q,
1400                                                            getDialect(), start, end);
1401                                    }
1402    
1403                                    cacheResult(list);
1404    
1405                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1406                            }
1407                            catch (Exception e) {
1408                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1409    
1410                                    throw processException(e);
1411                            }
1412                            finally {
1413                                    closeSession(session);
1414                            }
1415                    }
1416    
1417                    return list;
1418            }
1419    
1420            /**
1421             * Removes all the wiki page resources from the database.
1422             *
1423             * @throws SystemException if a system exception occurred
1424             */
1425            public void removeAll() throws SystemException {
1426                    for (WikiPageResource wikiPageResource : findAll()) {
1427                            remove(wikiPageResource);
1428                    }
1429            }
1430    
1431            /**
1432             * Returns the number of wiki page resources.
1433             *
1434             * @return the number of wiki page resources
1435             * @throws SystemException if a system exception occurred
1436             */
1437            public int countAll() throws SystemException {
1438                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1439                                    FINDER_ARGS_EMPTY, this);
1440    
1441                    if (count == null) {
1442                            Session session = null;
1443    
1444                            try {
1445                                    session = openSession();
1446    
1447                                    Query q = session.createQuery(_SQL_COUNT_WIKIPAGERESOURCE);
1448    
1449                                    count = (Long)q.uniqueResult();
1450    
1451                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1452                                            FINDER_ARGS_EMPTY, count);
1453                            }
1454                            catch (Exception e) {
1455                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
1456                                            FINDER_ARGS_EMPTY);
1457    
1458                                    throw processException(e);
1459                            }
1460                            finally {
1461                                    closeSession(session);
1462                            }
1463                    }
1464    
1465                    return count.intValue();
1466            }
1467    
1468            /**
1469             * Initializes the wiki page resource persistence.
1470             */
1471            public void afterPropertiesSet() {
1472                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1473                                            com.liferay.portal.util.PropsUtil.get(
1474                                                    "value.object.listener.com.liferay.portlet.wiki.model.WikiPageResource")));
1475    
1476                    if (listenerClassNames.length > 0) {
1477                            try {
1478                                    List<ModelListener<WikiPageResource>> listenersList = new ArrayList<ModelListener<WikiPageResource>>();
1479    
1480                                    for (String listenerClassName : listenerClassNames) {
1481                                            listenersList.add((ModelListener<WikiPageResource>)InstanceFactory.newInstance(
1482                                                            listenerClassName));
1483                                    }
1484    
1485                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1486                            }
1487                            catch (Exception e) {
1488                                    _log.error(e);
1489                            }
1490                    }
1491            }
1492    
1493            public void destroy() {
1494                    EntityCacheUtil.removeCache(WikiPageResourceImpl.class.getName());
1495                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1496                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1497                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1498            }
1499    
1500            private static final String _SQL_SELECT_WIKIPAGERESOURCE = "SELECT wikiPageResource FROM WikiPageResource wikiPageResource";
1501            private static final String _SQL_SELECT_WIKIPAGERESOURCE_WHERE = "SELECT wikiPageResource FROM WikiPageResource wikiPageResource WHERE ";
1502            private static final String _SQL_COUNT_WIKIPAGERESOURCE = "SELECT COUNT(wikiPageResource) FROM WikiPageResource wikiPageResource";
1503            private static final String _SQL_COUNT_WIKIPAGERESOURCE_WHERE = "SELECT COUNT(wikiPageResource) FROM WikiPageResource wikiPageResource WHERE ";
1504            private static final String _ORDER_BY_ENTITY_ALIAS = "wikiPageResource.";
1505            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No WikiPageResource exists with the primary key ";
1506            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No WikiPageResource exists with the key {";
1507            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1508            private static Log _log = LogFactoryUtil.getLog(WikiPageResourcePersistenceImpl.class);
1509            private static WikiPageResource _nullWikiPageResource = new WikiPageResourceImpl() {
1510                            @Override
1511                            public Object clone() {
1512                                    return this;
1513                            }
1514    
1515                            @Override
1516                            public CacheModel<WikiPageResource> toCacheModel() {
1517                                    return _nullWikiPageResourceCacheModel;
1518                            }
1519                    };
1520    
1521            private static CacheModel<WikiPageResource> _nullWikiPageResourceCacheModel = new CacheModel<WikiPageResource>() {
1522                            public WikiPageResource toEntityModel() {
1523                                    return _nullWikiPageResource;
1524                            }
1525                    };
1526    }