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