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