001    /**
002     * Copyright (c) 2000-2010 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.NoSuchResourceCodeException;
019    import com.liferay.portal.kernel.annotation.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.ModelListener;
039    import com.liferay.portal.model.ResourceCode;
040    import com.liferay.portal.model.impl.ResourceCodeImpl;
041    import com.liferay.portal.model.impl.ResourceCodeModelImpl;
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 for the resource code service.
052     *
053     * <p>
054     * Never modify this class directly. Modify <code>service.xml</code> and rerun ServiceBuilder to regnerate this class.
055     * </p>
056     *
057     * <p>
058     * Caching information and settings can be found in <code>portal.properties</code>
059     * </p>
060     *
061     * @author Brian Wing Shun Chan
062     * @see ResourceCodePersistence
063     * @see ResourceCodeUtil
064     * @generated
065     */
066    public class ResourceCodePersistenceImpl extends BasePersistenceImpl<ResourceCode>
067            implements ResourceCodePersistence {
068            public static final String FINDER_CLASS_NAME_ENTITY = ResourceCodeImpl.class.getName();
069            public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
070                    ".List";
071            public static final FinderPath FINDER_PATH_FIND_BY_COMPANYID = new FinderPath(ResourceCodeModelImpl.ENTITY_CACHE_ENABLED,
072                            ResourceCodeModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
073                            "findByCompanyId",
074                            new String[] {
075                                    Long.class.getName(),
076                                    
077                            "java.lang.Integer", "java.lang.Integer",
078                                    "com.liferay.portal.kernel.util.OrderByComparator"
079                            });
080            public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(ResourceCodeModelImpl.ENTITY_CACHE_ENABLED,
081                            ResourceCodeModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
082                            "countByCompanyId", new String[] { Long.class.getName() });
083            public static final FinderPath FINDER_PATH_FIND_BY_NAME = new FinderPath(ResourceCodeModelImpl.ENTITY_CACHE_ENABLED,
084                            ResourceCodeModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
085                            "findByName",
086                            new String[] {
087                                    String.class.getName(),
088                                    
089                            "java.lang.Integer", "java.lang.Integer",
090                                    "com.liferay.portal.kernel.util.OrderByComparator"
091                            });
092            public static final FinderPath FINDER_PATH_COUNT_BY_NAME = new FinderPath(ResourceCodeModelImpl.ENTITY_CACHE_ENABLED,
093                            ResourceCodeModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
094                            "countByName", new String[] { String.class.getName() });
095            public static final FinderPath FINDER_PATH_FETCH_BY_C_N_S = new FinderPath(ResourceCodeModelImpl.ENTITY_CACHE_ENABLED,
096                            ResourceCodeModelImpl.FINDER_CACHE_ENABLED,
097                            FINDER_CLASS_NAME_ENTITY, "fetchByC_N_S",
098                            new String[] {
099                                    Long.class.getName(), String.class.getName(),
100                                    Integer.class.getName()
101                            });
102            public static final FinderPath FINDER_PATH_COUNT_BY_C_N_S = new FinderPath(ResourceCodeModelImpl.ENTITY_CACHE_ENABLED,
103                            ResourceCodeModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
104                            "countByC_N_S",
105                            new String[] {
106                                    Long.class.getName(), String.class.getName(),
107                                    Integer.class.getName()
108                            });
109            public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(ResourceCodeModelImpl.ENTITY_CACHE_ENABLED,
110                            ResourceCodeModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
111                            "findAll", new String[0]);
112            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ResourceCodeModelImpl.ENTITY_CACHE_ENABLED,
113                            ResourceCodeModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
114                            "countAll", new String[0]);
115    
116            /**
117             * Caches the resource code in the entity cache if it is enabled.
118             *
119             * @param resourceCode the resource code to cache
120             */
121            public void cacheResult(ResourceCode resourceCode) {
122                    EntityCacheUtil.putResult(ResourceCodeModelImpl.ENTITY_CACHE_ENABLED,
123                            ResourceCodeImpl.class, resourceCode.getPrimaryKey(), resourceCode);
124    
125                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N_S,
126                            new Object[] {
127                                    new Long(resourceCode.getCompanyId()),
128                                    
129                            resourceCode.getName(), new Integer(resourceCode.getScope())
130                            }, resourceCode);
131            }
132    
133            /**
134             * Caches the resource codes in the entity cache if it is enabled.
135             *
136             * @param resourceCodes the resource codes to cache
137             */
138            public void cacheResult(List<ResourceCode> resourceCodes) {
139                    for (ResourceCode resourceCode : resourceCodes) {
140                            if (EntityCacheUtil.getResult(
141                                                    ResourceCodeModelImpl.ENTITY_CACHE_ENABLED,
142                                                    ResourceCodeImpl.class, resourceCode.getPrimaryKey(),
143                                                    this) == null) {
144                                    cacheResult(resourceCode);
145                            }
146                    }
147            }
148    
149            /**
150             * Clears the cache for all resource codes.
151             *
152             * <p>
153             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
154             * </p>
155             */
156            public void clearCache() {
157                    CacheRegistryUtil.clear(ResourceCodeImpl.class.getName());
158                    EntityCacheUtil.clearCache(ResourceCodeImpl.class.getName());
159                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
160                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
161            }
162    
163            /**
164             * Clears the cache for the resource code.
165             *
166             * <p>
167             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
168             * </p>
169             */
170            public void clearCache(ResourceCode resourceCode) {
171                    EntityCacheUtil.removeResult(ResourceCodeModelImpl.ENTITY_CACHE_ENABLED,
172                            ResourceCodeImpl.class, resourceCode.getPrimaryKey());
173    
174                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N_S,
175                            new Object[] {
176                                    new Long(resourceCode.getCompanyId()),
177                                    
178                            resourceCode.getName(), new Integer(resourceCode.getScope())
179                            });
180            }
181    
182            /**
183             * Creates a new resource code with the primary key.
184             *
185             * @param codeId the primary key for the new resource code
186             * @return the new resource code
187             */
188            public ResourceCode create(long codeId) {
189                    ResourceCode resourceCode = new ResourceCodeImpl();
190    
191                    resourceCode.setNew(true);
192                    resourceCode.setPrimaryKey(codeId);
193    
194                    return resourceCode;
195            }
196    
197            /**
198             * Removes the resource code with the primary key from the database. Also notifies the appropriate model listeners.
199             *
200             * @param primaryKey the primary key of the resource code to remove
201             * @return the resource code that was removed
202             * @throws com.liferay.portal.NoSuchModelException if a resource code with the primary key could not be found
203             * @throws SystemException if a system exception occurred
204             */
205            public ResourceCode remove(Serializable primaryKey)
206                    throws NoSuchModelException, SystemException {
207                    return remove(((Long)primaryKey).longValue());
208            }
209    
210            /**
211             * Removes the resource code with the primary key from the database. Also notifies the appropriate model listeners.
212             *
213             * @param codeId the primary key of the resource code to remove
214             * @return the resource code that was removed
215             * @throws com.liferay.portal.NoSuchResourceCodeException if a resource code with the primary key could not be found
216             * @throws SystemException if a system exception occurred
217             */
218            public ResourceCode remove(long codeId)
219                    throws NoSuchResourceCodeException, SystemException {
220                    Session session = null;
221    
222                    try {
223                            session = openSession();
224    
225                            ResourceCode resourceCode = (ResourceCode)session.get(ResourceCodeImpl.class,
226                                            new Long(codeId));
227    
228                            if (resourceCode == null) {
229                                    if (_log.isWarnEnabled()) {
230                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + codeId);
231                                    }
232    
233                                    throw new NoSuchResourceCodeException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
234                                            codeId);
235                            }
236    
237                            return remove(resourceCode);
238                    }
239                    catch (NoSuchResourceCodeException nsee) {
240                            throw nsee;
241                    }
242                    catch (Exception e) {
243                            throw processException(e);
244                    }
245                    finally {
246                            closeSession(session);
247                    }
248            }
249    
250            protected ResourceCode removeImpl(ResourceCode resourceCode)
251                    throws SystemException {
252                    resourceCode = toUnwrappedModel(resourceCode);
253    
254                    Session session = null;
255    
256                    try {
257                            session = openSession();
258    
259                            if (resourceCode.isCachedModel() || BatchSessionUtil.isEnabled()) {
260                                    Object staleObject = session.get(ResourceCodeImpl.class,
261                                                    resourceCode.getPrimaryKeyObj());
262    
263                                    if (staleObject != null) {
264                                            session.evict(staleObject);
265                                    }
266                            }
267    
268                            session.delete(resourceCode);
269    
270                            session.flush();
271                    }
272                    catch (Exception e) {
273                            throw processException(e);
274                    }
275                    finally {
276                            closeSession(session);
277                    }
278    
279                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
280    
281                    ResourceCodeModelImpl resourceCodeModelImpl = (ResourceCodeModelImpl)resourceCode;
282    
283                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N_S,
284                            new Object[] {
285                                    new Long(resourceCodeModelImpl.getOriginalCompanyId()),
286                                    
287                            resourceCodeModelImpl.getOriginalName(),
288                                    new Integer(resourceCodeModelImpl.getOriginalScope())
289                            });
290    
291                    EntityCacheUtil.removeResult(ResourceCodeModelImpl.ENTITY_CACHE_ENABLED,
292                            ResourceCodeImpl.class, resourceCode.getPrimaryKey());
293    
294                    return resourceCode;
295            }
296    
297            public ResourceCode updateImpl(
298                    com.liferay.portal.model.ResourceCode resourceCode, boolean merge)
299                    throws SystemException {
300                    resourceCode = toUnwrappedModel(resourceCode);
301    
302                    boolean isNew = resourceCode.isNew();
303    
304                    ResourceCodeModelImpl resourceCodeModelImpl = (ResourceCodeModelImpl)resourceCode;
305    
306                    Session session = null;
307    
308                    try {
309                            session = openSession();
310    
311                            BatchSessionUtil.update(session, resourceCode, merge);
312    
313                            resourceCode.setNew(false);
314                    }
315                    catch (Exception e) {
316                            throw processException(e);
317                    }
318                    finally {
319                            closeSession(session);
320                    }
321    
322                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
323    
324                    EntityCacheUtil.putResult(ResourceCodeModelImpl.ENTITY_CACHE_ENABLED,
325                            ResourceCodeImpl.class, resourceCode.getPrimaryKey(), resourceCode);
326    
327                    if (!isNew &&
328                                    ((resourceCode.getCompanyId() != resourceCodeModelImpl.getOriginalCompanyId()) ||
329                                    !Validator.equals(resourceCode.getName(),
330                                            resourceCodeModelImpl.getOriginalName()) ||
331                                    (resourceCode.getScope() != resourceCodeModelImpl.getOriginalScope()))) {
332                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N_S,
333                                    new Object[] {
334                                            new Long(resourceCodeModelImpl.getOriginalCompanyId()),
335                                            
336                                    resourceCodeModelImpl.getOriginalName(),
337                                            new Integer(resourceCodeModelImpl.getOriginalScope())
338                                    });
339                    }
340    
341                    if (isNew ||
342                                    ((resourceCode.getCompanyId() != resourceCodeModelImpl.getOriginalCompanyId()) ||
343                                    !Validator.equals(resourceCode.getName(),
344                                            resourceCodeModelImpl.getOriginalName()) ||
345                                    (resourceCode.getScope() != resourceCodeModelImpl.getOriginalScope()))) {
346                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N_S,
347                                    new Object[] {
348                                            new Long(resourceCode.getCompanyId()),
349                                            
350                                    resourceCode.getName(), new Integer(resourceCode.getScope())
351                                    }, resourceCode);
352                    }
353    
354                    return resourceCode;
355            }
356    
357            protected ResourceCode toUnwrappedModel(ResourceCode resourceCode) {
358                    if (resourceCode instanceof ResourceCodeImpl) {
359                            return resourceCode;
360                    }
361    
362                    ResourceCodeImpl resourceCodeImpl = new ResourceCodeImpl();
363    
364                    resourceCodeImpl.setNew(resourceCode.isNew());
365                    resourceCodeImpl.setPrimaryKey(resourceCode.getPrimaryKey());
366    
367                    resourceCodeImpl.setCodeId(resourceCode.getCodeId());
368                    resourceCodeImpl.setCompanyId(resourceCode.getCompanyId());
369                    resourceCodeImpl.setName(resourceCode.getName());
370                    resourceCodeImpl.setScope(resourceCode.getScope());
371    
372                    return resourceCodeImpl;
373            }
374    
375            /**
376             * Finds the resource code with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
377             *
378             * @param primaryKey the primary key of the resource code to find
379             * @return the resource code
380             * @throws com.liferay.portal.NoSuchModelException if a resource code with the primary key could not be found
381             * @throws SystemException if a system exception occurred
382             */
383            public ResourceCode findByPrimaryKey(Serializable primaryKey)
384                    throws NoSuchModelException, SystemException {
385                    return findByPrimaryKey(((Long)primaryKey).longValue());
386            }
387    
388            /**
389             * Finds the resource code with the primary key or throws a {@link com.liferay.portal.NoSuchResourceCodeException} if it could not be found.
390             *
391             * @param codeId the primary key of the resource code to find
392             * @return the resource code
393             * @throws com.liferay.portal.NoSuchResourceCodeException if a resource code with the primary key could not be found
394             * @throws SystemException if a system exception occurred
395             */
396            public ResourceCode findByPrimaryKey(long codeId)
397                    throws NoSuchResourceCodeException, SystemException {
398                    ResourceCode resourceCode = fetchByPrimaryKey(codeId);
399    
400                    if (resourceCode == null) {
401                            if (_log.isWarnEnabled()) {
402                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + codeId);
403                            }
404    
405                            throw new NoSuchResourceCodeException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
406                                    codeId);
407                    }
408    
409                    return resourceCode;
410            }
411    
412            /**
413             * Finds the resource code with the primary key or returns <code>null</code> if it could not be found.
414             *
415             * @param primaryKey the primary key of the resource code to find
416             * @return the resource code, or <code>null</code> if a resource code with the primary key could not be found
417             * @throws SystemException if a system exception occurred
418             */
419            public ResourceCode fetchByPrimaryKey(Serializable primaryKey)
420                    throws SystemException {
421                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
422            }
423    
424            /**
425             * Finds the resource code with the primary key or returns <code>null</code> if it could not be found.
426             *
427             * @param codeId the primary key of the resource code to find
428             * @return the resource code, or <code>null</code> if a resource code with the primary key could not be found
429             * @throws SystemException if a system exception occurred
430             */
431            public ResourceCode fetchByPrimaryKey(long codeId)
432                    throws SystemException {
433                    ResourceCode resourceCode = (ResourceCode)EntityCacheUtil.getResult(ResourceCodeModelImpl.ENTITY_CACHE_ENABLED,
434                                    ResourceCodeImpl.class, codeId, this);
435    
436                    if (resourceCode == null) {
437                            Session session = null;
438    
439                            try {
440                                    session = openSession();
441    
442                                    resourceCode = (ResourceCode)session.get(ResourceCodeImpl.class,
443                                                    new Long(codeId));
444                            }
445                            catch (Exception e) {
446                                    throw processException(e);
447                            }
448                            finally {
449                                    if (resourceCode != null) {
450                                            cacheResult(resourceCode);
451                                    }
452    
453                                    closeSession(session);
454                            }
455                    }
456    
457                    return resourceCode;
458            }
459    
460            /**
461             * Finds all the resource codes where companyId = &#63;.
462             *
463             * @param companyId the company id to search with
464             * @return the matching resource codes
465             * @throws SystemException if a system exception occurred
466             */
467            public List<ResourceCode> findByCompanyId(long companyId)
468                    throws SystemException {
469                    return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
470                            null);
471            }
472    
473            /**
474             * Finds a range of all the resource codes where companyId = &#63;.
475             *
476             * <p>
477             * 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.
478             * </p>
479             *
480             * @param companyId the company id to search with
481             * @param start the lower bound of the range of resource codes to return
482             * @param end the upper bound of the range of resource codes to return (not inclusive)
483             * @return the range of matching resource codes
484             * @throws SystemException if a system exception occurred
485             */
486            public List<ResourceCode> findByCompanyId(long companyId, int start, int end)
487                    throws SystemException {
488                    return findByCompanyId(companyId, start, end, null);
489            }
490    
491            /**
492             * Finds an ordered range of all the resource codes where companyId = &#63;.
493             *
494             * <p>
495             * 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.
496             * </p>
497             *
498             * @param companyId the company id to search with
499             * @param start the lower bound of the range of resource codes to return
500             * @param end the upper bound of the range of resource codes to return (not inclusive)
501             * @param orderByComparator the comparator to order the results by
502             * @return the ordered range of matching resource codes
503             * @throws SystemException if a system exception occurred
504             */
505            public List<ResourceCode> findByCompanyId(long companyId, int start,
506                    int end, OrderByComparator orderByComparator) throws SystemException {
507                    Object[] finderArgs = new Object[] {
508                                    companyId,
509                                    
510                                    String.valueOf(start), String.valueOf(end),
511                                    String.valueOf(orderByComparator)
512                            };
513    
514                    List<ResourceCode> list = (List<ResourceCode>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_COMPANYID,
515                                    finderArgs, this);
516    
517                    if (list == null) {
518                            Session session = null;
519    
520                            try {
521                                    session = openSession();
522    
523                                    StringBundler query = null;
524    
525                                    if (orderByComparator != null) {
526                                            query = new StringBundler(3 +
527                                                            (orderByComparator.getOrderByFields().length * 3));
528                                    }
529                                    else {
530                                            query = new StringBundler(2);
531                                    }
532    
533                                    query.append(_SQL_SELECT_RESOURCECODE_WHERE);
534    
535                                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
536    
537                                    if (orderByComparator != null) {
538                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
539                                                    orderByComparator);
540                                    }
541    
542                                    String sql = query.toString();
543    
544                                    Query q = session.createQuery(sql);
545    
546                                    QueryPos qPos = QueryPos.getInstance(q);
547    
548                                    qPos.add(companyId);
549    
550                                    list = (List<ResourceCode>)QueryUtil.list(q, getDialect(),
551                                                    start, end);
552                            }
553                            catch (Exception e) {
554                                    throw processException(e);
555                            }
556                            finally {
557                                    if (list == null) {
558                                            list = new ArrayList<ResourceCode>();
559                                    }
560    
561                                    cacheResult(list);
562    
563                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_COMPANYID,
564                                            finderArgs, list);
565    
566                                    closeSession(session);
567                            }
568                    }
569    
570                    return list;
571            }
572    
573            /**
574             * Finds the first resource code in the ordered set where companyId = &#63;.
575             *
576             * <p>
577             * 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.
578             * </p>
579             *
580             * @param companyId the company id to search with
581             * @param orderByComparator the comparator to order the set by
582             * @return the first matching resource code
583             * @throws com.liferay.portal.NoSuchResourceCodeException if a matching resource code could not be found
584             * @throws SystemException if a system exception occurred
585             */
586            public ResourceCode findByCompanyId_First(long companyId,
587                    OrderByComparator orderByComparator)
588                    throws NoSuchResourceCodeException, SystemException {
589                    List<ResourceCode> list = findByCompanyId(companyId, 0, 1,
590                                    orderByComparator);
591    
592                    if (list.isEmpty()) {
593                            StringBundler msg = new StringBundler(4);
594    
595                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
596    
597                            msg.append("companyId=");
598                            msg.append(companyId);
599    
600                            msg.append(StringPool.CLOSE_CURLY_BRACE);
601    
602                            throw new NoSuchResourceCodeException(msg.toString());
603                    }
604                    else {
605                            return list.get(0);
606                    }
607            }
608    
609            /**
610             * Finds the last resource code in the ordered set where companyId = &#63;.
611             *
612             * <p>
613             * 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.
614             * </p>
615             *
616             * @param companyId the company id to search with
617             * @param orderByComparator the comparator to order the set by
618             * @return the last matching resource code
619             * @throws com.liferay.portal.NoSuchResourceCodeException if a matching resource code could not be found
620             * @throws SystemException if a system exception occurred
621             */
622            public ResourceCode findByCompanyId_Last(long companyId,
623                    OrderByComparator orderByComparator)
624                    throws NoSuchResourceCodeException, SystemException {
625                    int count = countByCompanyId(companyId);
626    
627                    List<ResourceCode> list = findByCompanyId(companyId, count - 1, count,
628                                    orderByComparator);
629    
630                    if (list.isEmpty()) {
631                            StringBundler msg = new StringBundler(4);
632    
633                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
634    
635                            msg.append("companyId=");
636                            msg.append(companyId);
637    
638                            msg.append(StringPool.CLOSE_CURLY_BRACE);
639    
640                            throw new NoSuchResourceCodeException(msg.toString());
641                    }
642                    else {
643                            return list.get(0);
644                    }
645            }
646    
647            /**
648             * Finds the resource codes before and after the current resource code in the ordered set where companyId = &#63;.
649             *
650             * <p>
651             * 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.
652             * </p>
653             *
654             * @param codeId the primary key of the current resource code
655             * @param companyId the company id to search with
656             * @param orderByComparator the comparator to order the set by
657             * @return the previous, current, and next resource code
658             * @throws com.liferay.portal.NoSuchResourceCodeException if a resource code with the primary key could not be found
659             * @throws SystemException if a system exception occurred
660             */
661            public ResourceCode[] findByCompanyId_PrevAndNext(long codeId,
662                    long companyId, OrderByComparator orderByComparator)
663                    throws NoSuchResourceCodeException, SystemException {
664                    ResourceCode resourceCode = findByPrimaryKey(codeId);
665    
666                    Session session = null;
667    
668                    try {
669                            session = openSession();
670    
671                            ResourceCode[] array = new ResourceCodeImpl[3];
672    
673                            array[0] = getByCompanyId_PrevAndNext(session, resourceCode,
674                                            companyId, orderByComparator, true);
675    
676                            array[1] = resourceCode;
677    
678                            array[2] = getByCompanyId_PrevAndNext(session, resourceCode,
679                                            companyId, orderByComparator, false);
680    
681                            return array;
682                    }
683                    catch (Exception e) {
684                            throw processException(e);
685                    }
686                    finally {
687                            closeSession(session);
688                    }
689            }
690    
691            protected ResourceCode getByCompanyId_PrevAndNext(Session session,
692                    ResourceCode resourceCode, long companyId,
693                    OrderByComparator orderByComparator, boolean previous) {
694                    StringBundler query = null;
695    
696                    if (orderByComparator != null) {
697                            query = new StringBundler(6 +
698                                            (orderByComparator.getOrderByFields().length * 6));
699                    }
700                    else {
701                            query = new StringBundler(3);
702                    }
703    
704                    query.append(_SQL_SELECT_RESOURCECODE_WHERE);
705    
706                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
707    
708                    if (orderByComparator != null) {
709                            String[] orderByFields = orderByComparator.getOrderByFields();
710    
711                            if (orderByFields.length > 0) {
712                                    query.append(WHERE_AND);
713                            }
714    
715                            for (int i = 0; i < orderByFields.length; i++) {
716                                    query.append(_ORDER_BY_ENTITY_ALIAS);
717                                    query.append(orderByFields[i]);
718    
719                                    if ((i + 1) < orderByFields.length) {
720                                            if (orderByComparator.isAscending() ^ previous) {
721                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
722                                            }
723                                            else {
724                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
725                                            }
726                                    }
727                                    else {
728                                            if (orderByComparator.isAscending() ^ previous) {
729                                                    query.append(WHERE_GREATER_THAN);
730                                            }
731                                            else {
732                                                    query.append(WHERE_LESSER_THAN);
733                                            }
734                                    }
735                            }
736    
737                            query.append(ORDER_BY_CLAUSE);
738    
739                            for (int i = 0; i < orderByFields.length; i++) {
740                                    query.append(_ORDER_BY_ENTITY_ALIAS);
741                                    query.append(orderByFields[i]);
742    
743                                    if ((i + 1) < orderByFields.length) {
744                                            if (orderByComparator.isAscending() ^ previous) {
745                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
746                                            }
747                                            else {
748                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
749                                            }
750                                    }
751                                    else {
752                                            if (orderByComparator.isAscending() ^ previous) {
753                                                    query.append(ORDER_BY_ASC);
754                                            }
755                                            else {
756                                                    query.append(ORDER_BY_DESC);
757                                            }
758                                    }
759                            }
760                    }
761    
762                    String sql = query.toString();
763    
764                    Query q = session.createQuery(sql);
765    
766                    q.setFirstResult(0);
767                    q.setMaxResults(2);
768    
769                    QueryPos qPos = QueryPos.getInstance(q);
770    
771                    qPos.add(companyId);
772    
773                    if (orderByComparator != null) {
774                            Object[] values = orderByComparator.getOrderByValues(resourceCode);
775    
776                            for (Object value : values) {
777                                    qPos.add(value);
778                            }
779                    }
780    
781                    List<ResourceCode> list = q.list();
782    
783                    if (list.size() == 2) {
784                            return list.get(1);
785                    }
786                    else {
787                            return null;
788                    }
789            }
790    
791            /**
792             * Finds all the resource codes where name = &#63;.
793             *
794             * @param name the name to search with
795             * @return the matching resource codes
796             * @throws SystemException if a system exception occurred
797             */
798            public List<ResourceCode> findByName(String name) throws SystemException {
799                    return findByName(name, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
800            }
801    
802            /**
803             * Finds a range of all the resource codes where name = &#63;.
804             *
805             * <p>
806             * 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.
807             * </p>
808             *
809             * @param name the name to search with
810             * @param start the lower bound of the range of resource codes to return
811             * @param end the upper bound of the range of resource codes to return (not inclusive)
812             * @return the range of matching resource codes
813             * @throws SystemException if a system exception occurred
814             */
815            public List<ResourceCode> findByName(String name, int start, int end)
816                    throws SystemException {
817                    return findByName(name, start, end, null);
818            }
819    
820            /**
821             * Finds an ordered range of all the resource codes where name = &#63;.
822             *
823             * <p>
824             * 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.
825             * </p>
826             *
827             * @param name the name to search with
828             * @param start the lower bound of the range of resource codes to return
829             * @param end the upper bound of the range of resource codes to return (not inclusive)
830             * @param orderByComparator the comparator to order the results by
831             * @return the ordered range of matching resource codes
832             * @throws SystemException if a system exception occurred
833             */
834            public List<ResourceCode> findByName(String name, int start, int end,
835                    OrderByComparator orderByComparator) throws SystemException {
836                    Object[] finderArgs = new Object[] {
837                                    name,
838                                    
839                                    String.valueOf(start), String.valueOf(end),
840                                    String.valueOf(orderByComparator)
841                            };
842    
843                    List<ResourceCode> list = (List<ResourceCode>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_NAME,
844                                    finderArgs, this);
845    
846                    if (list == null) {
847                            Session session = null;
848    
849                            try {
850                                    session = openSession();
851    
852                                    StringBundler query = null;
853    
854                                    if (orderByComparator != null) {
855                                            query = new StringBundler(3 +
856                                                            (orderByComparator.getOrderByFields().length * 3));
857                                    }
858                                    else {
859                                            query = new StringBundler(2);
860                                    }
861    
862                                    query.append(_SQL_SELECT_RESOURCECODE_WHERE);
863    
864                                    if (name == null) {
865                                            query.append(_FINDER_COLUMN_NAME_NAME_1);
866                                    }
867                                    else {
868                                            if (name.equals(StringPool.BLANK)) {
869                                                    query.append(_FINDER_COLUMN_NAME_NAME_3);
870                                            }
871                                            else {
872                                                    query.append(_FINDER_COLUMN_NAME_NAME_2);
873                                            }
874                                    }
875    
876                                    if (orderByComparator != null) {
877                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
878                                                    orderByComparator);
879                                    }
880    
881                                    String sql = query.toString();
882    
883                                    Query q = session.createQuery(sql);
884    
885                                    QueryPos qPos = QueryPos.getInstance(q);
886    
887                                    if (name != null) {
888                                            qPos.add(name);
889                                    }
890    
891                                    list = (List<ResourceCode>)QueryUtil.list(q, getDialect(),
892                                                    start, end);
893                            }
894                            catch (Exception e) {
895                                    throw processException(e);
896                            }
897                            finally {
898                                    if (list == null) {
899                                            list = new ArrayList<ResourceCode>();
900                                    }
901    
902                                    cacheResult(list);
903    
904                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_NAME, finderArgs,
905                                            list);
906    
907                                    closeSession(session);
908                            }
909                    }
910    
911                    return list;
912            }
913    
914            /**
915             * Finds the first resource code in the ordered set where name = &#63;.
916             *
917             * <p>
918             * 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.
919             * </p>
920             *
921             * @param name the name to search with
922             * @param orderByComparator the comparator to order the set by
923             * @return the first matching resource code
924             * @throws com.liferay.portal.NoSuchResourceCodeException if a matching resource code could not be found
925             * @throws SystemException if a system exception occurred
926             */
927            public ResourceCode findByName_First(String name,
928                    OrderByComparator orderByComparator)
929                    throws NoSuchResourceCodeException, SystemException {
930                    List<ResourceCode> list = findByName(name, 0, 1, orderByComparator);
931    
932                    if (list.isEmpty()) {
933                            StringBundler msg = new StringBundler(4);
934    
935                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
936    
937                            msg.append("name=");
938                            msg.append(name);
939    
940                            msg.append(StringPool.CLOSE_CURLY_BRACE);
941    
942                            throw new NoSuchResourceCodeException(msg.toString());
943                    }
944                    else {
945                            return list.get(0);
946                    }
947            }
948    
949            /**
950             * Finds the last resource code in the ordered set where name = &#63;.
951             *
952             * <p>
953             * 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.
954             * </p>
955             *
956             * @param name the name to search with
957             * @param orderByComparator the comparator to order the set by
958             * @return the last matching resource code
959             * @throws com.liferay.portal.NoSuchResourceCodeException if a matching resource code could not be found
960             * @throws SystemException if a system exception occurred
961             */
962            public ResourceCode findByName_Last(String name,
963                    OrderByComparator orderByComparator)
964                    throws NoSuchResourceCodeException, SystemException {
965                    int count = countByName(name);
966    
967                    List<ResourceCode> list = findByName(name, count - 1, count,
968                                    orderByComparator);
969    
970                    if (list.isEmpty()) {
971                            StringBundler msg = new StringBundler(4);
972    
973                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
974    
975                            msg.append("name=");
976                            msg.append(name);
977    
978                            msg.append(StringPool.CLOSE_CURLY_BRACE);
979    
980                            throw new NoSuchResourceCodeException(msg.toString());
981                    }
982                    else {
983                            return list.get(0);
984                    }
985            }
986    
987            /**
988             * Finds the resource codes before and after the current resource code in the ordered set where name = &#63;.
989             *
990             * <p>
991             * 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.
992             * </p>
993             *
994             * @param codeId the primary key of the current resource code
995             * @param name the name to search with
996             * @param orderByComparator the comparator to order the set by
997             * @return the previous, current, and next resource code
998             * @throws com.liferay.portal.NoSuchResourceCodeException if a resource code with the primary key could not be found
999             * @throws SystemException if a system exception occurred
1000             */
1001            public ResourceCode[] findByName_PrevAndNext(long codeId, String name,
1002                    OrderByComparator orderByComparator)
1003                    throws NoSuchResourceCodeException, SystemException {
1004                    ResourceCode resourceCode = findByPrimaryKey(codeId);
1005    
1006                    Session session = null;
1007    
1008                    try {
1009                            session = openSession();
1010    
1011                            ResourceCode[] array = new ResourceCodeImpl[3];
1012    
1013                            array[0] = getByName_PrevAndNext(session, resourceCode, name,
1014                                            orderByComparator, true);
1015    
1016                            array[1] = resourceCode;
1017    
1018                            array[2] = getByName_PrevAndNext(session, resourceCode, name,
1019                                            orderByComparator, false);
1020    
1021                            return array;
1022                    }
1023                    catch (Exception e) {
1024                            throw processException(e);
1025                    }
1026                    finally {
1027                            closeSession(session);
1028                    }
1029            }
1030    
1031            protected ResourceCode getByName_PrevAndNext(Session session,
1032                    ResourceCode resourceCode, String name,
1033                    OrderByComparator orderByComparator, boolean previous) {
1034                    StringBundler query = null;
1035    
1036                    if (orderByComparator != null) {
1037                            query = new StringBundler(6 +
1038                                            (orderByComparator.getOrderByFields().length * 6));
1039                    }
1040                    else {
1041                            query = new StringBundler(3);
1042                    }
1043    
1044                    query.append(_SQL_SELECT_RESOURCECODE_WHERE);
1045    
1046                    if (name == null) {
1047                            query.append(_FINDER_COLUMN_NAME_NAME_1);
1048                    }
1049                    else {
1050                            if (name.equals(StringPool.BLANK)) {
1051                                    query.append(_FINDER_COLUMN_NAME_NAME_3);
1052                            }
1053                            else {
1054                                    query.append(_FINDER_COLUMN_NAME_NAME_2);
1055                            }
1056                    }
1057    
1058                    if (orderByComparator != null) {
1059                            String[] orderByFields = orderByComparator.getOrderByFields();
1060    
1061                            if (orderByFields.length > 0) {
1062                                    query.append(WHERE_AND);
1063                            }
1064    
1065                            for (int i = 0; i < orderByFields.length; i++) {
1066                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1067                                    query.append(orderByFields[i]);
1068    
1069                                    if ((i + 1) < orderByFields.length) {
1070                                            if (orderByComparator.isAscending() ^ previous) {
1071                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1072                                            }
1073                                            else {
1074                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1075                                            }
1076                                    }
1077                                    else {
1078                                            if (orderByComparator.isAscending() ^ previous) {
1079                                                    query.append(WHERE_GREATER_THAN);
1080                                            }
1081                                            else {
1082                                                    query.append(WHERE_LESSER_THAN);
1083                                            }
1084                                    }
1085                            }
1086    
1087                            query.append(ORDER_BY_CLAUSE);
1088    
1089                            for (int i = 0; i < orderByFields.length; i++) {
1090                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1091                                    query.append(orderByFields[i]);
1092    
1093                                    if ((i + 1) < orderByFields.length) {
1094                                            if (orderByComparator.isAscending() ^ previous) {
1095                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1096                                            }
1097                                            else {
1098                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1099                                            }
1100                                    }
1101                                    else {
1102                                            if (orderByComparator.isAscending() ^ previous) {
1103                                                    query.append(ORDER_BY_ASC);
1104                                            }
1105                                            else {
1106                                                    query.append(ORDER_BY_DESC);
1107                                            }
1108                                    }
1109                            }
1110                    }
1111    
1112                    String sql = query.toString();
1113    
1114                    Query q = session.createQuery(sql);
1115    
1116                    q.setFirstResult(0);
1117                    q.setMaxResults(2);
1118    
1119                    QueryPos qPos = QueryPos.getInstance(q);
1120    
1121                    if (name != null) {
1122                            qPos.add(name);
1123                    }
1124    
1125                    if (orderByComparator != null) {
1126                            Object[] values = orderByComparator.getOrderByValues(resourceCode);
1127    
1128                            for (Object value : values) {
1129                                    qPos.add(value);
1130                            }
1131                    }
1132    
1133                    List<ResourceCode> list = q.list();
1134    
1135                    if (list.size() == 2) {
1136                            return list.get(1);
1137                    }
1138                    else {
1139                            return null;
1140                    }
1141            }
1142    
1143            /**
1144             * Finds the resource code where companyId = &#63; and name = &#63; and scope = &#63; or throws a {@link com.liferay.portal.NoSuchResourceCodeException} if it could not be found.
1145             *
1146             * @param companyId the company id to search with
1147             * @param name the name to search with
1148             * @param scope the scope to search with
1149             * @return the matching resource code
1150             * @throws com.liferay.portal.NoSuchResourceCodeException if a matching resource code could not be found
1151             * @throws SystemException if a system exception occurred
1152             */
1153            public ResourceCode findByC_N_S(long companyId, String name, int scope)
1154                    throws NoSuchResourceCodeException, SystemException {
1155                    ResourceCode resourceCode = fetchByC_N_S(companyId, name, scope);
1156    
1157                    if (resourceCode == null) {
1158                            StringBundler msg = new StringBundler(8);
1159    
1160                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1161    
1162                            msg.append("companyId=");
1163                            msg.append(companyId);
1164    
1165                            msg.append(", name=");
1166                            msg.append(name);
1167    
1168                            msg.append(", scope=");
1169                            msg.append(scope);
1170    
1171                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1172    
1173                            if (_log.isWarnEnabled()) {
1174                                    _log.warn(msg.toString());
1175                            }
1176    
1177                            throw new NoSuchResourceCodeException(msg.toString());
1178                    }
1179    
1180                    return resourceCode;
1181            }
1182    
1183            /**
1184             * Finds the resource code where companyId = &#63; and name = &#63; and scope = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
1185             *
1186             * @param companyId the company id to search with
1187             * @param name the name to search with
1188             * @param scope the scope to search with
1189             * @return the matching resource code, or <code>null</code> if a matching resource code could not be found
1190             * @throws SystemException if a system exception occurred
1191             */
1192            public ResourceCode fetchByC_N_S(long companyId, String name, int scope)
1193                    throws SystemException {
1194                    return fetchByC_N_S(companyId, name, scope, true);
1195            }
1196    
1197            /**
1198             * Finds the resource code where companyId = &#63; and name = &#63; and scope = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
1199             *
1200             * @param companyId the company id to search with
1201             * @param name the name to search with
1202             * @param scope the scope to search with
1203             * @return the matching resource code, or <code>null</code> if a matching resource code could not be found
1204             * @throws SystemException if a system exception occurred
1205             */
1206            public ResourceCode fetchByC_N_S(long companyId, String name, int scope,
1207                    boolean retrieveFromCache) throws SystemException {
1208                    Object[] finderArgs = new Object[] { companyId, name, scope };
1209    
1210                    Object result = null;
1211    
1212                    if (retrieveFromCache) {
1213                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_N_S,
1214                                            finderArgs, this);
1215                    }
1216    
1217                    if (result == null) {
1218                            Session session = null;
1219    
1220                            try {
1221                                    session = openSession();
1222    
1223                                    StringBundler query = new StringBundler(4);
1224    
1225                                    query.append(_SQL_SELECT_RESOURCECODE_WHERE);
1226    
1227                                    query.append(_FINDER_COLUMN_C_N_S_COMPANYID_2);
1228    
1229                                    if (name == null) {
1230                                            query.append(_FINDER_COLUMN_C_N_S_NAME_1);
1231                                    }
1232                                    else {
1233                                            if (name.equals(StringPool.BLANK)) {
1234                                                    query.append(_FINDER_COLUMN_C_N_S_NAME_3);
1235                                            }
1236                                            else {
1237                                                    query.append(_FINDER_COLUMN_C_N_S_NAME_2);
1238                                            }
1239                                    }
1240    
1241                                    query.append(_FINDER_COLUMN_C_N_S_SCOPE_2);
1242    
1243                                    String sql = query.toString();
1244    
1245                                    Query q = session.createQuery(sql);
1246    
1247                                    QueryPos qPos = QueryPos.getInstance(q);
1248    
1249                                    qPos.add(companyId);
1250    
1251                                    if (name != null) {
1252                                            qPos.add(name);
1253                                    }
1254    
1255                                    qPos.add(scope);
1256    
1257                                    List<ResourceCode> list = q.list();
1258    
1259                                    result = list;
1260    
1261                                    ResourceCode resourceCode = null;
1262    
1263                                    if (list.isEmpty()) {
1264                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N_S,
1265                                                    finderArgs, list);
1266                                    }
1267                                    else {
1268                                            resourceCode = list.get(0);
1269    
1270                                            cacheResult(resourceCode);
1271    
1272                                            if ((resourceCode.getCompanyId() != companyId) ||
1273                                                            (resourceCode.getName() == null) ||
1274                                                            !resourceCode.getName().equals(name) ||
1275                                                            (resourceCode.getScope() != scope)) {
1276                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N_S,
1277                                                            finderArgs, resourceCode);
1278                                            }
1279                                    }
1280    
1281                                    return resourceCode;
1282                            }
1283                            catch (Exception e) {
1284                                    throw processException(e);
1285                            }
1286                            finally {
1287                                    if (result == null) {
1288                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N_S,
1289                                                    finderArgs, new ArrayList<ResourceCode>());
1290                                    }
1291    
1292                                    closeSession(session);
1293                            }
1294                    }
1295                    else {
1296                            if (result instanceof List<?>) {
1297                                    return null;
1298                            }
1299                            else {
1300                                    return (ResourceCode)result;
1301                            }
1302                    }
1303            }
1304    
1305            /**
1306             * Finds all the resource codes.
1307             *
1308             * @return the resource codes
1309             * @throws SystemException if a system exception occurred
1310             */
1311            public List<ResourceCode> findAll() throws SystemException {
1312                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1313            }
1314    
1315            /**
1316             * Finds a range of all the resource codes.
1317             *
1318             * <p>
1319             * 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.
1320             * </p>
1321             *
1322             * @param start the lower bound of the range of resource codes to return
1323             * @param end the upper bound of the range of resource codes to return (not inclusive)
1324             * @return the range of resource codes
1325             * @throws SystemException if a system exception occurred
1326             */
1327            public List<ResourceCode> findAll(int start, int end)
1328                    throws SystemException {
1329                    return findAll(start, end, null);
1330            }
1331    
1332            /**
1333             * Finds an ordered range of all the resource codes.
1334             *
1335             * <p>
1336             * 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.
1337             * </p>
1338             *
1339             * @param start the lower bound of the range of resource codes to return
1340             * @param end the upper bound of the range of resource codes to return (not inclusive)
1341             * @param orderByComparator the comparator to order the results by
1342             * @return the ordered range of resource codes
1343             * @throws SystemException if a system exception occurred
1344             */
1345            public List<ResourceCode> findAll(int start, int end,
1346                    OrderByComparator orderByComparator) throws SystemException {
1347                    Object[] finderArgs = new Object[] {
1348                                    String.valueOf(start), String.valueOf(end),
1349                                    String.valueOf(orderByComparator)
1350                            };
1351    
1352                    List<ResourceCode> list = (List<ResourceCode>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1353                                    finderArgs, this);
1354    
1355                    if (list == null) {
1356                            Session session = null;
1357    
1358                            try {
1359                                    session = openSession();
1360    
1361                                    StringBundler query = null;
1362                                    String sql = null;
1363    
1364                                    if (orderByComparator != null) {
1365                                            query = new StringBundler(2 +
1366                                                            (orderByComparator.getOrderByFields().length * 3));
1367    
1368                                            query.append(_SQL_SELECT_RESOURCECODE);
1369    
1370                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1371                                                    orderByComparator);
1372    
1373                                            sql = query.toString();
1374                                    }
1375                                    else {
1376                                            sql = _SQL_SELECT_RESOURCECODE;
1377                                    }
1378    
1379                                    Query q = session.createQuery(sql);
1380    
1381                                    if (orderByComparator == null) {
1382                                            list = (List<ResourceCode>)QueryUtil.list(q, getDialect(),
1383                                                            start, end, false);
1384    
1385                                            Collections.sort(list);
1386                                    }
1387                                    else {
1388                                            list = (List<ResourceCode>)QueryUtil.list(q, getDialect(),
1389                                                            start, end);
1390                                    }
1391                            }
1392                            catch (Exception e) {
1393                                    throw processException(e);
1394                            }
1395                            finally {
1396                                    if (list == null) {
1397                                            list = new ArrayList<ResourceCode>();
1398                                    }
1399    
1400                                    cacheResult(list);
1401    
1402                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1403    
1404                                    closeSession(session);
1405                            }
1406                    }
1407    
1408                    return list;
1409            }
1410    
1411            /**
1412             * Removes all the resource codes where companyId = &#63; from the database.
1413             *
1414             * @param companyId the company id to search with
1415             * @throws SystemException if a system exception occurred
1416             */
1417            public void removeByCompanyId(long companyId) throws SystemException {
1418                    for (ResourceCode resourceCode : findByCompanyId(companyId)) {
1419                            remove(resourceCode);
1420                    }
1421            }
1422    
1423            /**
1424             * Removes all the resource codes where name = &#63; from the database.
1425             *
1426             * @param name the name to search with
1427             * @throws SystemException if a system exception occurred
1428             */
1429            public void removeByName(String name) throws SystemException {
1430                    for (ResourceCode resourceCode : findByName(name)) {
1431                            remove(resourceCode);
1432                    }
1433            }
1434    
1435            /**
1436             * Removes the resource code where companyId = &#63; and name = &#63; and scope = &#63; from the database.
1437             *
1438             * @param companyId the company id to search with
1439             * @param name the name to search with
1440             * @param scope the scope to search with
1441             * @throws SystemException if a system exception occurred
1442             */
1443            public void removeByC_N_S(long companyId, String name, int scope)
1444                    throws NoSuchResourceCodeException, SystemException {
1445                    ResourceCode resourceCode = findByC_N_S(companyId, name, scope);
1446    
1447                    remove(resourceCode);
1448            }
1449    
1450            /**
1451             * Removes all the resource codes from the database.
1452             *
1453             * @throws SystemException if a system exception occurred
1454             */
1455            public void removeAll() throws SystemException {
1456                    for (ResourceCode resourceCode : findAll()) {
1457                            remove(resourceCode);
1458                    }
1459            }
1460    
1461            /**
1462             * Counts all the resource codes where companyId = &#63;.
1463             *
1464             * @param companyId the company id to search with
1465             * @return the number of matching resource codes
1466             * @throws SystemException if a system exception occurred
1467             */
1468            public int countByCompanyId(long companyId) throws SystemException {
1469                    Object[] finderArgs = new Object[] { companyId };
1470    
1471                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
1472                                    finderArgs, this);
1473    
1474                    if (count == null) {
1475                            Session session = null;
1476    
1477                            try {
1478                                    session = openSession();
1479    
1480                                    StringBundler query = new StringBundler(2);
1481    
1482                                    query.append(_SQL_COUNT_RESOURCECODE_WHERE);
1483    
1484                                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1485    
1486                                    String sql = query.toString();
1487    
1488                                    Query q = session.createQuery(sql);
1489    
1490                                    QueryPos qPos = QueryPos.getInstance(q);
1491    
1492                                    qPos.add(companyId);
1493    
1494                                    count = (Long)q.uniqueResult();
1495                            }
1496                            catch (Exception e) {
1497                                    throw processException(e);
1498                            }
1499                            finally {
1500                                    if (count == null) {
1501                                            count = Long.valueOf(0);
1502                                    }
1503    
1504                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
1505                                            finderArgs, count);
1506    
1507                                    closeSession(session);
1508                            }
1509                    }
1510    
1511                    return count.intValue();
1512            }
1513    
1514            /**
1515             * Counts all the resource codes where name = &#63;.
1516             *
1517             * @param name the name to search with
1518             * @return the number of matching resource codes
1519             * @throws SystemException if a system exception occurred
1520             */
1521            public int countByName(String name) throws SystemException {
1522                    Object[] finderArgs = new Object[] { name };
1523    
1524                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_NAME,
1525                                    finderArgs, this);
1526    
1527                    if (count == null) {
1528                            Session session = null;
1529    
1530                            try {
1531                                    session = openSession();
1532    
1533                                    StringBundler query = new StringBundler(2);
1534    
1535                                    query.append(_SQL_COUNT_RESOURCECODE_WHERE);
1536    
1537                                    if (name == null) {
1538                                            query.append(_FINDER_COLUMN_NAME_NAME_1);
1539                                    }
1540                                    else {
1541                                            if (name.equals(StringPool.BLANK)) {
1542                                                    query.append(_FINDER_COLUMN_NAME_NAME_3);
1543                                            }
1544                                            else {
1545                                                    query.append(_FINDER_COLUMN_NAME_NAME_2);
1546                                            }
1547                                    }
1548    
1549                                    String sql = query.toString();
1550    
1551                                    Query q = session.createQuery(sql);
1552    
1553                                    QueryPos qPos = QueryPos.getInstance(q);
1554    
1555                                    if (name != null) {
1556                                            qPos.add(name);
1557                                    }
1558    
1559                                    count = (Long)q.uniqueResult();
1560                            }
1561                            catch (Exception e) {
1562                                    throw processException(e);
1563                            }
1564                            finally {
1565                                    if (count == null) {
1566                                            count = Long.valueOf(0);
1567                                    }
1568    
1569                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_NAME,
1570                                            finderArgs, count);
1571    
1572                                    closeSession(session);
1573                            }
1574                    }
1575    
1576                    return count.intValue();
1577            }
1578    
1579            /**
1580             * Counts all the resource codes where companyId = &#63; and name = &#63; and scope = &#63;.
1581             *
1582             * @param companyId the company id to search with
1583             * @param name the name to search with
1584             * @param scope the scope to search with
1585             * @return the number of matching resource codes
1586             * @throws SystemException if a system exception occurred
1587             */
1588            public int countByC_N_S(long companyId, String name, int scope)
1589                    throws SystemException {
1590                    Object[] finderArgs = new Object[] { companyId, name, scope };
1591    
1592                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_N_S,
1593                                    finderArgs, this);
1594    
1595                    if (count == null) {
1596                            Session session = null;
1597    
1598                            try {
1599                                    session = openSession();
1600    
1601                                    StringBundler query = new StringBundler(4);
1602    
1603                                    query.append(_SQL_COUNT_RESOURCECODE_WHERE);
1604    
1605                                    query.append(_FINDER_COLUMN_C_N_S_COMPANYID_2);
1606    
1607                                    if (name == null) {
1608                                            query.append(_FINDER_COLUMN_C_N_S_NAME_1);
1609                                    }
1610                                    else {
1611                                            if (name.equals(StringPool.BLANK)) {
1612                                                    query.append(_FINDER_COLUMN_C_N_S_NAME_3);
1613                                            }
1614                                            else {
1615                                                    query.append(_FINDER_COLUMN_C_N_S_NAME_2);
1616                                            }
1617                                    }
1618    
1619                                    query.append(_FINDER_COLUMN_C_N_S_SCOPE_2);
1620    
1621                                    String sql = query.toString();
1622    
1623                                    Query q = session.createQuery(sql);
1624    
1625                                    QueryPos qPos = QueryPos.getInstance(q);
1626    
1627                                    qPos.add(companyId);
1628    
1629                                    if (name != null) {
1630                                            qPos.add(name);
1631                                    }
1632    
1633                                    qPos.add(scope);
1634    
1635                                    count = (Long)q.uniqueResult();
1636                            }
1637                            catch (Exception e) {
1638                                    throw processException(e);
1639                            }
1640                            finally {
1641                                    if (count == null) {
1642                                            count = Long.valueOf(0);
1643                                    }
1644    
1645                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_N_S,
1646                                            finderArgs, count);
1647    
1648                                    closeSession(session);
1649                            }
1650                    }
1651    
1652                    return count.intValue();
1653            }
1654    
1655            /**
1656             * Counts all the resource codes.
1657             *
1658             * @return the number of resource codes
1659             * @throws SystemException if a system exception occurred
1660             */
1661            public int countAll() throws SystemException {
1662                    Object[] finderArgs = new Object[0];
1663    
1664                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1665                                    finderArgs, this);
1666    
1667                    if (count == null) {
1668                            Session session = null;
1669    
1670                            try {
1671                                    session = openSession();
1672    
1673                                    Query q = session.createQuery(_SQL_COUNT_RESOURCECODE);
1674    
1675                                    count = (Long)q.uniqueResult();
1676                            }
1677                            catch (Exception e) {
1678                                    throw processException(e);
1679                            }
1680                            finally {
1681                                    if (count == null) {
1682                                            count = Long.valueOf(0);
1683                                    }
1684    
1685                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1686                                            count);
1687    
1688                                    closeSession(session);
1689                            }
1690                    }
1691    
1692                    return count.intValue();
1693            }
1694    
1695            /**
1696             * Initializes the resource code persistence.
1697             */
1698            public void afterPropertiesSet() {
1699                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1700                                            com.liferay.portal.util.PropsUtil.get(
1701                                                    "value.object.listener.com.liferay.portal.model.ResourceCode")));
1702    
1703                    if (listenerClassNames.length > 0) {
1704                            try {
1705                                    List<ModelListener<ResourceCode>> listenersList = new ArrayList<ModelListener<ResourceCode>>();
1706    
1707                                    for (String listenerClassName : listenerClassNames) {
1708                                            listenersList.add((ModelListener<ResourceCode>)InstanceFactory.newInstance(
1709                                                            listenerClassName));
1710                                    }
1711    
1712                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1713                            }
1714                            catch (Exception e) {
1715                                    _log.error(e);
1716                            }
1717                    }
1718            }
1719    
1720            @BeanReference(type = AccountPersistence.class)
1721            protected AccountPersistence accountPersistence;
1722            @BeanReference(type = AddressPersistence.class)
1723            protected AddressPersistence addressPersistence;
1724            @BeanReference(type = BrowserTrackerPersistence.class)
1725            protected BrowserTrackerPersistence browserTrackerPersistence;
1726            @BeanReference(type = ClassNamePersistence.class)
1727            protected ClassNamePersistence classNamePersistence;
1728            @BeanReference(type = CompanyPersistence.class)
1729            protected CompanyPersistence companyPersistence;
1730            @BeanReference(type = ContactPersistence.class)
1731            protected ContactPersistence contactPersistence;
1732            @BeanReference(type = CountryPersistence.class)
1733            protected CountryPersistence countryPersistence;
1734            @BeanReference(type = EmailAddressPersistence.class)
1735            protected EmailAddressPersistence emailAddressPersistence;
1736            @BeanReference(type = GroupPersistence.class)
1737            protected GroupPersistence groupPersistence;
1738            @BeanReference(type = ImagePersistence.class)
1739            protected ImagePersistence imagePersistence;
1740            @BeanReference(type = LayoutPersistence.class)
1741            protected LayoutPersistence layoutPersistence;
1742            @BeanReference(type = LayoutPrototypePersistence.class)
1743            protected LayoutPrototypePersistence layoutPrototypePersistence;
1744            @BeanReference(type = LayoutSetPersistence.class)
1745            protected LayoutSetPersistence layoutSetPersistence;
1746            @BeanReference(type = LayoutSetPrototypePersistence.class)
1747            protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
1748            @BeanReference(type = ListTypePersistence.class)
1749            protected ListTypePersistence listTypePersistence;
1750            @BeanReference(type = LockPersistence.class)
1751            protected LockPersistence lockPersistence;
1752            @BeanReference(type = MembershipRequestPersistence.class)
1753            protected MembershipRequestPersistence membershipRequestPersistence;
1754            @BeanReference(type = OrganizationPersistence.class)
1755            protected OrganizationPersistence organizationPersistence;
1756            @BeanReference(type = OrgGroupPermissionPersistence.class)
1757            protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
1758            @BeanReference(type = OrgGroupRolePersistence.class)
1759            protected OrgGroupRolePersistence orgGroupRolePersistence;
1760            @BeanReference(type = OrgLaborPersistence.class)
1761            protected OrgLaborPersistence orgLaborPersistence;
1762            @BeanReference(type = PasswordPolicyPersistence.class)
1763            protected PasswordPolicyPersistence passwordPolicyPersistence;
1764            @BeanReference(type = PasswordPolicyRelPersistence.class)
1765            protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
1766            @BeanReference(type = PasswordTrackerPersistence.class)
1767            protected PasswordTrackerPersistence passwordTrackerPersistence;
1768            @BeanReference(type = PermissionPersistence.class)
1769            protected PermissionPersistence permissionPersistence;
1770            @BeanReference(type = PhonePersistence.class)
1771            protected PhonePersistence phonePersistence;
1772            @BeanReference(type = PluginSettingPersistence.class)
1773            protected PluginSettingPersistence pluginSettingPersistence;
1774            @BeanReference(type = PortletPersistence.class)
1775            protected PortletPersistence portletPersistence;
1776            @BeanReference(type = PortletItemPersistence.class)
1777            protected PortletItemPersistence portletItemPersistence;
1778            @BeanReference(type = PortletPreferencesPersistence.class)
1779            protected PortletPreferencesPersistence portletPreferencesPersistence;
1780            @BeanReference(type = RegionPersistence.class)
1781            protected RegionPersistence regionPersistence;
1782            @BeanReference(type = ReleasePersistence.class)
1783            protected ReleasePersistence releasePersistence;
1784            @BeanReference(type = ResourcePersistence.class)
1785            protected ResourcePersistence resourcePersistence;
1786            @BeanReference(type = ResourceActionPersistence.class)
1787            protected ResourceActionPersistence resourceActionPersistence;
1788            @BeanReference(type = ResourceCodePersistence.class)
1789            protected ResourceCodePersistence resourceCodePersistence;
1790            @BeanReference(type = ResourcePermissionPersistence.class)
1791            protected ResourcePermissionPersistence resourcePermissionPersistence;
1792            @BeanReference(type = RolePersistence.class)
1793            protected RolePersistence rolePersistence;
1794            @BeanReference(type = ServiceComponentPersistence.class)
1795            protected ServiceComponentPersistence serviceComponentPersistence;
1796            @BeanReference(type = ShardPersistence.class)
1797            protected ShardPersistence shardPersistence;
1798            @BeanReference(type = SubscriptionPersistence.class)
1799            protected SubscriptionPersistence subscriptionPersistence;
1800            @BeanReference(type = TicketPersistence.class)
1801            protected TicketPersistence ticketPersistence;
1802            @BeanReference(type = TeamPersistence.class)
1803            protected TeamPersistence teamPersistence;
1804            @BeanReference(type = UserPersistence.class)
1805            protected UserPersistence userPersistence;
1806            @BeanReference(type = UserGroupPersistence.class)
1807            protected UserGroupPersistence userGroupPersistence;
1808            @BeanReference(type = UserGroupGroupRolePersistence.class)
1809            protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
1810            @BeanReference(type = UserGroupRolePersistence.class)
1811            protected UserGroupRolePersistence userGroupRolePersistence;
1812            @BeanReference(type = UserIdMapperPersistence.class)
1813            protected UserIdMapperPersistence userIdMapperPersistence;
1814            @BeanReference(type = UserTrackerPersistence.class)
1815            protected UserTrackerPersistence userTrackerPersistence;
1816            @BeanReference(type = UserTrackerPathPersistence.class)
1817            protected UserTrackerPathPersistence userTrackerPathPersistence;
1818            @BeanReference(type = WebDAVPropsPersistence.class)
1819            protected WebDAVPropsPersistence webDAVPropsPersistence;
1820            @BeanReference(type = WebsitePersistence.class)
1821            protected WebsitePersistence websitePersistence;
1822            @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
1823            protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
1824            @BeanReference(type = WorkflowInstanceLinkPersistence.class)
1825            protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
1826            private static final String _SQL_SELECT_RESOURCECODE = "SELECT resourceCode FROM ResourceCode resourceCode";
1827            private static final String _SQL_SELECT_RESOURCECODE_WHERE = "SELECT resourceCode FROM ResourceCode resourceCode WHERE ";
1828            private static final String _SQL_COUNT_RESOURCECODE = "SELECT COUNT(resourceCode) FROM ResourceCode resourceCode";
1829            private static final String _SQL_COUNT_RESOURCECODE_WHERE = "SELECT COUNT(resourceCode) FROM ResourceCode resourceCode WHERE ";
1830            private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "resourceCode.companyId = ?";
1831            private static final String _FINDER_COLUMN_NAME_NAME_1 = "resourceCode.name IS NULL";
1832            private static final String _FINDER_COLUMN_NAME_NAME_2 = "resourceCode.name = ?";
1833            private static final String _FINDER_COLUMN_NAME_NAME_3 = "(resourceCode.name IS NULL OR resourceCode.name = ?)";
1834            private static final String _FINDER_COLUMN_C_N_S_COMPANYID_2 = "resourceCode.companyId = ? AND ";
1835            private static final String _FINDER_COLUMN_C_N_S_NAME_1 = "resourceCode.name IS NULL AND ";
1836            private static final String _FINDER_COLUMN_C_N_S_NAME_2 = "resourceCode.name = ? AND ";
1837            private static final String _FINDER_COLUMN_C_N_S_NAME_3 = "(resourceCode.name IS NULL OR resourceCode.name = ?) AND ";
1838            private static final String _FINDER_COLUMN_C_N_S_SCOPE_2 = "resourceCode.scope = ?";
1839            private static final String _ORDER_BY_ENTITY_ALIAS = "resourceCode.";
1840            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ResourceCode exists with the primary key ";
1841            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ResourceCode exists with the key {";
1842            private static Log _log = LogFactoryUtil.getLog(ResourceCodePersistenceImpl.class);
1843    }