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