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            public WikiPageResourcePersistenceImpl() {
887                    setModelClass(WikiPageResource.class);
888            }
889    
890            /**
891             * Caches the wiki page resource in the entity cache if it is enabled.
892             *
893             * @param wikiPageResource the wiki page resource
894             */
895            @Override
896            public void cacheResult(WikiPageResource wikiPageResource) {
897                    EntityCacheUtil.putResult(WikiPageResourceModelImpl.ENTITY_CACHE_ENABLED,
898                            WikiPageResourceImpl.class, wikiPageResource.getPrimaryKey(),
899                            wikiPageResource);
900    
901                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_T,
902                            new Object[] {
903                                    wikiPageResource.getNodeId(), wikiPageResource.getTitle()
904                            }, wikiPageResource);
905    
906                    wikiPageResource.resetOriginalValues();
907            }
908    
909            /**
910             * Caches the wiki page resources in the entity cache if it is enabled.
911             *
912             * @param wikiPageResources the wiki page resources
913             */
914            @Override
915            public void cacheResult(List<WikiPageResource> wikiPageResources) {
916                    for (WikiPageResource wikiPageResource : wikiPageResources) {
917                            if (EntityCacheUtil.getResult(
918                                                    WikiPageResourceModelImpl.ENTITY_CACHE_ENABLED,
919                                                    WikiPageResourceImpl.class,
920                                                    wikiPageResource.getPrimaryKey()) == null) {
921                                    cacheResult(wikiPageResource);
922                            }
923                            else {
924                                    wikiPageResource.resetOriginalValues();
925                            }
926                    }
927            }
928    
929            /**
930             * Clears the cache for all wiki page resources.
931             *
932             * <p>
933             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
934             * </p>
935             */
936            @Override
937            public void clearCache() {
938                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
939                            CacheRegistryUtil.clear(WikiPageResourceImpl.class.getName());
940                    }
941    
942                    EntityCacheUtil.clearCache(WikiPageResourceImpl.class.getName());
943    
944                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
945                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
946                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
947            }
948    
949            /**
950             * Clears the cache for the wiki page resource.
951             *
952             * <p>
953             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
954             * </p>
955             */
956            @Override
957            public void clearCache(WikiPageResource wikiPageResource) {
958                    EntityCacheUtil.removeResult(WikiPageResourceModelImpl.ENTITY_CACHE_ENABLED,
959                            WikiPageResourceImpl.class, wikiPageResource.getPrimaryKey());
960    
961                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
962                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
963    
964                    clearUniqueFindersCache(wikiPageResource);
965            }
966    
967            @Override
968            public void clearCache(List<WikiPageResource> wikiPageResources) {
969                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
970                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
971    
972                    for (WikiPageResource wikiPageResource : wikiPageResources) {
973                            EntityCacheUtil.removeResult(WikiPageResourceModelImpl.ENTITY_CACHE_ENABLED,
974                                    WikiPageResourceImpl.class, wikiPageResource.getPrimaryKey());
975    
976                            clearUniqueFindersCache(wikiPageResource);
977                    }
978            }
979    
980            protected void cacheUniqueFindersCache(WikiPageResource wikiPageResource) {
981                    if (wikiPageResource.isNew()) {
982                            Object[] args = new Object[] {
983                                            wikiPageResource.getNodeId(), wikiPageResource.getTitle()
984                                    };
985    
986                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_N_T, args,
987                                    Long.valueOf(1));
988                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_T, args,
989                                    wikiPageResource);
990                    }
991                    else {
992                            WikiPageResourceModelImpl wikiPageResourceModelImpl = (WikiPageResourceModelImpl)wikiPageResource;
993    
994                            if ((wikiPageResourceModelImpl.getColumnBitmask() &
995                                            FINDER_PATH_FETCH_BY_N_T.getColumnBitmask()) != 0) {
996                                    Object[] args = new Object[] {
997                                                    wikiPageResource.getNodeId(),
998                                                    wikiPageResource.getTitle()
999                                            };
1000    
1001                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_N_T, args,
1002                                            Long.valueOf(1));
1003                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_T, args,
1004                                            wikiPageResource);
1005                            }
1006                    }
1007            }
1008    
1009            protected void clearUniqueFindersCache(WikiPageResource wikiPageResource) {
1010                    WikiPageResourceModelImpl wikiPageResourceModelImpl = (WikiPageResourceModelImpl)wikiPageResource;
1011    
1012                    Object[] args = new Object[] {
1013                                    wikiPageResource.getNodeId(), wikiPageResource.getTitle()
1014                            };
1015    
1016                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_T, args);
1017                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_N_T, args);
1018    
1019                    if ((wikiPageResourceModelImpl.getColumnBitmask() &
1020                                    FINDER_PATH_FETCH_BY_N_T.getColumnBitmask()) != 0) {
1021                            args = new Object[] {
1022                                            wikiPageResourceModelImpl.getOriginalNodeId(),
1023                                            wikiPageResourceModelImpl.getOriginalTitle()
1024                                    };
1025    
1026                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_T, args);
1027                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_N_T, args);
1028                    }
1029            }
1030    
1031            /**
1032             * Creates a new wiki page resource with the primary key. Does not add the wiki page resource to the database.
1033             *
1034             * @param resourcePrimKey the primary key for the new wiki page resource
1035             * @return the new wiki page resource
1036             */
1037            @Override
1038            public WikiPageResource create(long resourcePrimKey) {
1039                    WikiPageResource wikiPageResource = new WikiPageResourceImpl();
1040    
1041                    wikiPageResource.setNew(true);
1042                    wikiPageResource.setPrimaryKey(resourcePrimKey);
1043    
1044                    String uuid = PortalUUIDUtil.generate();
1045    
1046                    wikiPageResource.setUuid(uuid);
1047    
1048                    return wikiPageResource;
1049            }
1050    
1051            /**
1052             * Removes the wiki page resource with the primary key from the database. Also notifies the appropriate model listeners.
1053             *
1054             * @param resourcePrimKey the primary key of the wiki page resource
1055             * @return the wiki page resource that was removed
1056             * @throws com.liferay.portlet.wiki.NoSuchPageResourceException if a wiki page resource with the primary key could not be found
1057             * @throws SystemException if a system exception occurred
1058             */
1059            @Override
1060            public WikiPageResource remove(long resourcePrimKey)
1061                    throws NoSuchPageResourceException, SystemException {
1062                    return remove((Serializable)resourcePrimKey);
1063            }
1064    
1065            /**
1066             * Removes the wiki page resource with the primary key from the database. Also notifies the appropriate model listeners.
1067             *
1068             * @param primaryKey the primary key of the wiki page resource
1069             * @return the wiki page resource that was removed
1070             * @throws com.liferay.portlet.wiki.NoSuchPageResourceException if a wiki page resource with the primary key could not be found
1071             * @throws SystemException if a system exception occurred
1072             */
1073            @Override
1074            public WikiPageResource remove(Serializable primaryKey)
1075                    throws NoSuchPageResourceException, SystemException {
1076                    Session session = null;
1077    
1078                    try {
1079                            session = openSession();
1080    
1081                            WikiPageResource wikiPageResource = (WikiPageResource)session.get(WikiPageResourceImpl.class,
1082                                            primaryKey);
1083    
1084                            if (wikiPageResource == null) {
1085                                    if (_log.isWarnEnabled()) {
1086                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1087                                    }
1088    
1089                                    throw new NoSuchPageResourceException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1090                                            primaryKey);
1091                            }
1092    
1093                            return remove(wikiPageResource);
1094                    }
1095                    catch (NoSuchPageResourceException nsee) {
1096                            throw nsee;
1097                    }
1098                    catch (Exception e) {
1099                            throw processException(e);
1100                    }
1101                    finally {
1102                            closeSession(session);
1103                    }
1104            }
1105    
1106            @Override
1107            protected WikiPageResource removeImpl(WikiPageResource wikiPageResource)
1108                    throws SystemException {
1109                    wikiPageResource = toUnwrappedModel(wikiPageResource);
1110    
1111                    Session session = null;
1112    
1113                    try {
1114                            session = openSession();
1115    
1116                            if (!session.contains(wikiPageResource)) {
1117                                    wikiPageResource = (WikiPageResource)session.get(WikiPageResourceImpl.class,
1118                                                    wikiPageResource.getPrimaryKeyObj());
1119                            }
1120    
1121                            if (wikiPageResource != null) {
1122                                    session.delete(wikiPageResource);
1123                            }
1124                    }
1125                    catch (Exception e) {
1126                            throw processException(e);
1127                    }
1128                    finally {
1129                            closeSession(session);
1130                    }
1131    
1132                    if (wikiPageResource != null) {
1133                            clearCache(wikiPageResource);
1134                    }
1135    
1136                    return wikiPageResource;
1137            }
1138    
1139            @Override
1140            public WikiPageResource updateImpl(
1141                    com.liferay.portlet.wiki.model.WikiPageResource wikiPageResource)
1142                    throws SystemException {
1143                    wikiPageResource = toUnwrappedModel(wikiPageResource);
1144    
1145                    boolean isNew = wikiPageResource.isNew();
1146    
1147                    WikiPageResourceModelImpl wikiPageResourceModelImpl = (WikiPageResourceModelImpl)wikiPageResource;
1148    
1149                    if (Validator.isNull(wikiPageResource.getUuid())) {
1150                            String uuid = PortalUUIDUtil.generate();
1151    
1152                            wikiPageResource.setUuid(uuid);
1153                    }
1154    
1155                    Session session = null;
1156    
1157                    try {
1158                            session = openSession();
1159    
1160                            if (wikiPageResource.isNew()) {
1161                                    session.save(wikiPageResource);
1162    
1163                                    wikiPageResource.setNew(false);
1164                            }
1165                            else {
1166                                    session.merge(wikiPageResource);
1167                            }
1168                    }
1169                    catch (Exception e) {
1170                            throw processException(e);
1171                    }
1172                    finally {
1173                            closeSession(session);
1174                    }
1175    
1176                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1177    
1178                    if (isNew || !WikiPageResourceModelImpl.COLUMN_BITMASK_ENABLED) {
1179                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1180                    }
1181    
1182                    else {
1183                            if ((wikiPageResourceModelImpl.getColumnBitmask() &
1184                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
1185                                    Object[] args = new Object[] {
1186                                                    wikiPageResourceModelImpl.getOriginalUuid()
1187                                            };
1188    
1189                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
1190                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
1191                                            args);
1192    
1193                                    args = new Object[] { wikiPageResourceModelImpl.getUuid() };
1194    
1195                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
1196                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
1197                                            args);
1198                            }
1199                    }
1200    
1201                    EntityCacheUtil.putResult(WikiPageResourceModelImpl.ENTITY_CACHE_ENABLED,
1202                            WikiPageResourceImpl.class, wikiPageResource.getPrimaryKey(),
1203                            wikiPageResource);
1204    
1205                    clearUniqueFindersCache(wikiPageResource);
1206                    cacheUniqueFindersCache(wikiPageResource);
1207    
1208                    return wikiPageResource;
1209            }
1210    
1211            protected WikiPageResource toUnwrappedModel(
1212                    WikiPageResource wikiPageResource) {
1213                    if (wikiPageResource instanceof WikiPageResourceImpl) {
1214                            return wikiPageResource;
1215                    }
1216    
1217                    WikiPageResourceImpl wikiPageResourceImpl = new WikiPageResourceImpl();
1218    
1219                    wikiPageResourceImpl.setNew(wikiPageResource.isNew());
1220                    wikiPageResourceImpl.setPrimaryKey(wikiPageResource.getPrimaryKey());
1221    
1222                    wikiPageResourceImpl.setUuid(wikiPageResource.getUuid());
1223                    wikiPageResourceImpl.setResourcePrimKey(wikiPageResource.getResourcePrimKey());
1224                    wikiPageResourceImpl.setNodeId(wikiPageResource.getNodeId());
1225                    wikiPageResourceImpl.setTitle(wikiPageResource.getTitle());
1226    
1227                    return wikiPageResourceImpl;
1228            }
1229    
1230            /**
1231             * Returns the wiki page resource with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
1232             *
1233             * @param primaryKey the primary key of the wiki page resource
1234             * @return the wiki page resource
1235             * @throws com.liferay.portlet.wiki.NoSuchPageResourceException if a wiki page resource with the primary key could not be found
1236             * @throws SystemException if a system exception occurred
1237             */
1238            @Override
1239            public WikiPageResource findByPrimaryKey(Serializable primaryKey)
1240                    throws NoSuchPageResourceException, SystemException {
1241                    WikiPageResource wikiPageResource = fetchByPrimaryKey(primaryKey);
1242    
1243                    if (wikiPageResource == null) {
1244                            if (_log.isWarnEnabled()) {
1245                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1246                            }
1247    
1248                            throw new NoSuchPageResourceException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1249                                    primaryKey);
1250                    }
1251    
1252                    return wikiPageResource;
1253            }
1254    
1255            /**
1256             * Returns the wiki page resource with the primary key or throws a {@link com.liferay.portlet.wiki.NoSuchPageResourceException} if it could not be found.
1257             *
1258             * @param resourcePrimKey the primary key of the wiki page resource
1259             * @return the wiki page resource
1260             * @throws com.liferay.portlet.wiki.NoSuchPageResourceException if a wiki page resource with the primary key could not be found
1261             * @throws SystemException if a system exception occurred
1262             */
1263            @Override
1264            public WikiPageResource findByPrimaryKey(long resourcePrimKey)
1265                    throws NoSuchPageResourceException, SystemException {
1266                    return findByPrimaryKey((Serializable)resourcePrimKey);
1267            }
1268    
1269            /**
1270             * Returns the wiki page resource with the primary key or returns <code>null</code> if it could not be found.
1271             *
1272             * @param primaryKey the primary key of the wiki page resource
1273             * @return the wiki page resource, or <code>null</code> if a wiki page resource with the primary key could not be found
1274             * @throws SystemException if a system exception occurred
1275             */
1276            @Override
1277            public WikiPageResource fetchByPrimaryKey(Serializable primaryKey)
1278                    throws SystemException {
1279                    WikiPageResource wikiPageResource = (WikiPageResource)EntityCacheUtil.getResult(WikiPageResourceModelImpl.ENTITY_CACHE_ENABLED,
1280                                    WikiPageResourceImpl.class, primaryKey);
1281    
1282                    if (wikiPageResource == _nullWikiPageResource) {
1283                            return null;
1284                    }
1285    
1286                    if (wikiPageResource == null) {
1287                            Session session = null;
1288    
1289                            try {
1290                                    session = openSession();
1291    
1292                                    wikiPageResource = (WikiPageResource)session.get(WikiPageResourceImpl.class,
1293                                                    primaryKey);
1294    
1295                                    if (wikiPageResource != null) {
1296                                            cacheResult(wikiPageResource);
1297                                    }
1298                                    else {
1299                                            EntityCacheUtil.putResult(WikiPageResourceModelImpl.ENTITY_CACHE_ENABLED,
1300                                                    WikiPageResourceImpl.class, primaryKey,
1301                                                    _nullWikiPageResource);
1302                                    }
1303                            }
1304                            catch (Exception e) {
1305                                    EntityCacheUtil.removeResult(WikiPageResourceModelImpl.ENTITY_CACHE_ENABLED,
1306                                            WikiPageResourceImpl.class, primaryKey);
1307    
1308                                    throw processException(e);
1309                            }
1310                            finally {
1311                                    closeSession(session);
1312                            }
1313                    }
1314    
1315                    return wikiPageResource;
1316            }
1317    
1318            /**
1319             * Returns the wiki page resource with the primary key or returns <code>null</code> if it could not be found.
1320             *
1321             * @param resourcePrimKey the primary key of the wiki page resource
1322             * @return the wiki page resource, or <code>null</code> if a wiki page resource with the primary key could not be found
1323             * @throws SystemException if a system exception occurred
1324             */
1325            @Override
1326            public WikiPageResource fetchByPrimaryKey(long resourcePrimKey)
1327                    throws SystemException {
1328                    return fetchByPrimaryKey((Serializable)resourcePrimKey);
1329            }
1330    
1331            /**
1332             * Returns all the wiki page resources.
1333             *
1334             * @return the wiki page resources
1335             * @throws SystemException if a system exception occurred
1336             */
1337            @Override
1338            public List<WikiPageResource> findAll() throws SystemException {
1339                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1340            }
1341    
1342            /**
1343             * Returns a range of all the wiki page resources.
1344             *
1345             * <p>
1346             * 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.
1347             * </p>
1348             *
1349             * @param start the lower bound of the range of wiki page resources
1350             * @param end the upper bound of the range of wiki page resources (not inclusive)
1351             * @return the range of wiki page resources
1352             * @throws SystemException if a system exception occurred
1353             */
1354            @Override
1355            public List<WikiPageResource> findAll(int start, int end)
1356                    throws SystemException {
1357                    return findAll(start, end, null);
1358            }
1359    
1360            /**
1361             * Returns an ordered range of all the wiki page resources.
1362             *
1363             * <p>
1364             * 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.
1365             * </p>
1366             *
1367             * @param start the lower bound of the range of wiki page resources
1368             * @param end the upper bound of the range of wiki page resources (not inclusive)
1369             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1370             * @return the ordered range of wiki page resources
1371             * @throws SystemException if a system exception occurred
1372             */
1373            @Override
1374            public List<WikiPageResource> findAll(int start, int end,
1375                    OrderByComparator orderByComparator) throws SystemException {
1376                    boolean pagination = true;
1377                    FinderPath finderPath = null;
1378                    Object[] finderArgs = null;
1379    
1380                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1381                                    (orderByComparator == null)) {
1382                            pagination = false;
1383                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1384                            finderArgs = FINDER_ARGS_EMPTY;
1385                    }
1386                    else {
1387                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1388                            finderArgs = new Object[] { start, end, orderByComparator };
1389                    }
1390    
1391                    List<WikiPageResource> list = (List<WikiPageResource>)FinderCacheUtil.getResult(finderPath,
1392                                    finderArgs, this);
1393    
1394                    if (list == null) {
1395                            StringBundler query = null;
1396                            String sql = null;
1397    
1398                            if (orderByComparator != null) {
1399                                    query = new StringBundler(2 +
1400                                                    (orderByComparator.getOrderByFields().length * 3));
1401    
1402                                    query.append(_SQL_SELECT_WIKIPAGERESOURCE);
1403    
1404                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1405                                            orderByComparator);
1406    
1407                                    sql = query.toString();
1408                            }
1409                            else {
1410                                    sql = _SQL_SELECT_WIKIPAGERESOURCE;
1411    
1412                                    if (pagination) {
1413                                            sql = sql.concat(WikiPageResourceModelImpl.ORDER_BY_JPQL);
1414                                    }
1415                            }
1416    
1417                            Session session = null;
1418    
1419                            try {
1420                                    session = openSession();
1421    
1422                                    Query q = session.createQuery(sql);
1423    
1424                                    if (!pagination) {
1425                                            list = (List<WikiPageResource>)QueryUtil.list(q,
1426                                                            getDialect(), start, end, false);
1427    
1428                                            Collections.sort(list);
1429    
1430                                            list = new UnmodifiableList<WikiPageResource>(list);
1431                                    }
1432                                    else {
1433                                            list = (List<WikiPageResource>)QueryUtil.list(q,
1434                                                            getDialect(), start, end);
1435                                    }
1436    
1437                                    cacheResult(list);
1438    
1439                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1440                            }
1441                            catch (Exception e) {
1442                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1443    
1444                                    throw processException(e);
1445                            }
1446                            finally {
1447                                    closeSession(session);
1448                            }
1449                    }
1450    
1451                    return list;
1452            }
1453    
1454            /**
1455             * Removes all the wiki page resources from the database.
1456             *
1457             * @throws SystemException if a system exception occurred
1458             */
1459            @Override
1460            public void removeAll() throws SystemException {
1461                    for (WikiPageResource wikiPageResource : findAll()) {
1462                            remove(wikiPageResource);
1463                    }
1464            }
1465    
1466            /**
1467             * Returns the number of wiki page resources.
1468             *
1469             * @return the number of wiki page resources
1470             * @throws SystemException if a system exception occurred
1471             */
1472            @Override
1473            public int countAll() throws SystemException {
1474                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1475                                    FINDER_ARGS_EMPTY, this);
1476    
1477                    if (count == null) {
1478                            Session session = null;
1479    
1480                            try {
1481                                    session = openSession();
1482    
1483                                    Query q = session.createQuery(_SQL_COUNT_WIKIPAGERESOURCE);
1484    
1485                                    count = (Long)q.uniqueResult();
1486    
1487                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1488                                            FINDER_ARGS_EMPTY, count);
1489                            }
1490                            catch (Exception e) {
1491                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
1492                                            FINDER_ARGS_EMPTY);
1493    
1494                                    throw processException(e);
1495                            }
1496                            finally {
1497                                    closeSession(session);
1498                            }
1499                    }
1500    
1501                    return count.intValue();
1502            }
1503    
1504            @Override
1505            protected Set<String> getBadColumnNames() {
1506                    return _badColumnNames;
1507            }
1508    
1509            /**
1510             * Initializes the wiki page resource persistence.
1511             */
1512            public void afterPropertiesSet() {
1513                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1514                                            com.liferay.portal.util.PropsUtil.get(
1515                                                    "value.object.listener.com.liferay.portlet.wiki.model.WikiPageResource")));
1516    
1517                    if (listenerClassNames.length > 0) {
1518                            try {
1519                                    List<ModelListener<WikiPageResource>> listenersList = new ArrayList<ModelListener<WikiPageResource>>();
1520    
1521                                    for (String listenerClassName : listenerClassNames) {
1522                                            listenersList.add((ModelListener<WikiPageResource>)InstanceFactory.newInstance(
1523                                                            getClassLoader(), listenerClassName));
1524                                    }
1525    
1526                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1527                            }
1528                            catch (Exception e) {
1529                                    _log.error(e);
1530                            }
1531                    }
1532            }
1533    
1534            public void destroy() {
1535                    EntityCacheUtil.removeCache(WikiPageResourceImpl.class.getName());
1536                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1537                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1538                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1539            }
1540    
1541            private static final String _SQL_SELECT_WIKIPAGERESOURCE = "SELECT wikiPageResource FROM WikiPageResource wikiPageResource";
1542            private static final String _SQL_SELECT_WIKIPAGERESOURCE_WHERE = "SELECT wikiPageResource FROM WikiPageResource wikiPageResource WHERE ";
1543            private static final String _SQL_COUNT_WIKIPAGERESOURCE = "SELECT COUNT(wikiPageResource) FROM WikiPageResource wikiPageResource";
1544            private static final String _SQL_COUNT_WIKIPAGERESOURCE_WHERE = "SELECT COUNT(wikiPageResource) FROM WikiPageResource wikiPageResource WHERE ";
1545            private static final String _ORDER_BY_ENTITY_ALIAS = "wikiPageResource.";
1546            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No WikiPageResource exists with the primary key ";
1547            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No WikiPageResource exists with the key {";
1548            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1549            private static Log _log = LogFactoryUtil.getLog(WikiPageResourcePersistenceImpl.class);
1550            private static Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
1551                                    "uuid"
1552                            });
1553            private static WikiPageResource _nullWikiPageResource = new WikiPageResourceImpl() {
1554                            @Override
1555                            public Object clone() {
1556                                    return this;
1557                            }
1558    
1559                            @Override
1560                            public CacheModel<WikiPageResource> toCacheModel() {
1561                                    return _nullWikiPageResourceCacheModel;
1562                            }
1563                    };
1564    
1565            private static CacheModel<WikiPageResource> _nullWikiPageResourceCacheModel = new CacheModel<WikiPageResource>() {
1566                            @Override
1567                            public WikiPageResource toEntityModel() {
1568                                    return _nullWikiPageResource;
1569                            }
1570                    };
1571    }