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