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