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