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