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