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