001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.service.persistence;
016    
017    import com.liferay.portal.NoSuchModelException;
018    import com.liferay.portal.NoSuchResourceBlockException;
019    import com.liferay.portal.kernel.bean.BeanReference;
020    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
021    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
023    import com.liferay.portal.kernel.dao.orm.FinderPath;
024    import com.liferay.portal.kernel.dao.orm.Query;
025    import com.liferay.portal.kernel.dao.orm.QueryPos;
026    import com.liferay.portal.kernel.dao.orm.QueryUtil;
027    import com.liferay.portal.kernel.dao.orm.Session;
028    import com.liferay.portal.kernel.exception.SystemException;
029    import com.liferay.portal.kernel.log.Log;
030    import com.liferay.portal.kernel.log.LogFactoryUtil;
031    import com.liferay.portal.kernel.util.GetterUtil;
032    import com.liferay.portal.kernel.util.InstanceFactory;
033    import com.liferay.portal.kernel.util.OrderByComparator;
034    import com.liferay.portal.kernel.util.StringBundler;
035    import com.liferay.portal.kernel.util.StringPool;
036    import com.liferay.portal.kernel.util.StringUtil;
037    import com.liferay.portal.kernel.util.Validator;
038    import com.liferay.portal.model.CacheModel;
039    import com.liferay.portal.model.ModelListener;
040    import com.liferay.portal.model.ResourceBlock;
041    import com.liferay.portal.model.impl.ResourceBlockImpl;
042    import com.liferay.portal.model.impl.ResourceBlockModelImpl;
043    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
044    
045    import java.io.Serializable;
046    
047    import java.util.ArrayList;
048    import java.util.Collections;
049    import java.util.List;
050    
051    /**
052     * The persistence implementation for the resource block service.
053     *
054     * <p>
055     * Caching information and settings can be found in <code>portal.properties</code>
056     * </p>
057     *
058     * @author Brian Wing Shun Chan
059     * @see ResourceBlockPersistence
060     * @see ResourceBlockUtil
061     * @generated
062     */
063    public class ResourceBlockPersistenceImpl extends BasePersistenceImpl<ResourceBlock>
064            implements ResourceBlockPersistence {
065            /*
066             * NOTE FOR DEVELOPERS:
067             *
068             * Never modify or reference this class directly. Always use {@link ResourceBlockUtil} to access the resource block persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
069             */
070            public static final String FINDER_CLASS_NAME_ENTITY = ResourceBlockImpl.class.getName();
071            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
072                    ".List1";
073            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
074                    ".List2";
075            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_N = new FinderPath(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
076                            ResourceBlockModelImpl.FINDER_CACHE_ENABLED,
077                            ResourceBlockImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
078                            "findByC_N",
079                            new String[] {
080                                    Long.class.getName(), String.class.getName(),
081                                    
082                            "java.lang.Integer", "java.lang.Integer",
083                                    "com.liferay.portal.kernel.util.OrderByComparator"
084                            });
085            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N = new FinderPath(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
086                            ResourceBlockModelImpl.FINDER_CACHE_ENABLED,
087                            ResourceBlockImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
088                            "findByC_N",
089                            new String[] { Long.class.getName(), String.class.getName() },
090                            ResourceBlockModelImpl.COMPANYID_COLUMN_BITMASK |
091                            ResourceBlockModelImpl.NAME_COLUMN_BITMASK);
092            public static final FinderPath FINDER_PATH_COUNT_BY_C_N = new FinderPath(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
093                            ResourceBlockModelImpl.FINDER_CACHE_ENABLED, Long.class,
094                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_N",
095                            new String[] { Long.class.getName(), String.class.getName() });
096            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_G_N = new FinderPath(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
097                            ResourceBlockModelImpl.FINDER_CACHE_ENABLED,
098                            ResourceBlockImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
099                            "findByC_G_N",
100                            new String[] {
101                                    Long.class.getName(), Long.class.getName(),
102                                    String.class.getName(),
103                                    
104                            "java.lang.Integer", "java.lang.Integer",
105                                    "com.liferay.portal.kernel.util.OrderByComparator"
106                            });
107            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_G_N = new FinderPath(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
108                            ResourceBlockModelImpl.FINDER_CACHE_ENABLED,
109                            ResourceBlockImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
110                            "findByC_G_N",
111                            new String[] {
112                                    Long.class.getName(), Long.class.getName(),
113                                    String.class.getName()
114                            },
115                            ResourceBlockModelImpl.COMPANYID_COLUMN_BITMASK |
116                            ResourceBlockModelImpl.GROUPID_COLUMN_BITMASK |
117                            ResourceBlockModelImpl.NAME_COLUMN_BITMASK);
118            public static final FinderPath FINDER_PATH_COUNT_BY_C_G_N = new FinderPath(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
119                            ResourceBlockModelImpl.FINDER_CACHE_ENABLED, Long.class,
120                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_G_N",
121                            new String[] {
122                                    Long.class.getName(), Long.class.getName(),
123                                    String.class.getName()
124                            });
125            public static final FinderPath FINDER_PATH_FETCH_BY_C_G_N_P = new FinderPath(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
126                            ResourceBlockModelImpl.FINDER_CACHE_ENABLED,
127                            ResourceBlockImpl.class, FINDER_CLASS_NAME_ENTITY,
128                            "fetchByC_G_N_P",
129                            new String[] {
130                                    Long.class.getName(), Long.class.getName(),
131                                    String.class.getName(), String.class.getName()
132                            },
133                            ResourceBlockModelImpl.COMPANYID_COLUMN_BITMASK |
134                            ResourceBlockModelImpl.GROUPID_COLUMN_BITMASK |
135                            ResourceBlockModelImpl.NAME_COLUMN_BITMASK |
136                            ResourceBlockModelImpl.PERMISSIONSHASH_COLUMN_BITMASK);
137            public static final FinderPath FINDER_PATH_COUNT_BY_C_G_N_P = new FinderPath(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
138                            ResourceBlockModelImpl.FINDER_CACHE_ENABLED, Long.class,
139                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_G_N_P",
140                            new String[] {
141                                    Long.class.getName(), Long.class.getName(),
142                                    String.class.getName(), String.class.getName()
143                            });
144            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
145                            ResourceBlockModelImpl.FINDER_CACHE_ENABLED,
146                            ResourceBlockImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
147                            "findAll", new String[0]);
148            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
149                            ResourceBlockModelImpl.FINDER_CACHE_ENABLED,
150                            ResourceBlockImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
151                            "findAll", new String[0]);
152            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
153                            ResourceBlockModelImpl.FINDER_CACHE_ENABLED, Long.class,
154                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
155    
156            /**
157             * Caches the resource block in the entity cache if it is enabled.
158             *
159             * @param resourceBlock the resource block
160             */
161            public void cacheResult(ResourceBlock resourceBlock) {
162                    EntityCacheUtil.putResult(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
163                            ResourceBlockImpl.class, resourceBlock.getPrimaryKey(),
164                            resourceBlock);
165    
166                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_G_N_P,
167                            new Object[] {
168                                    Long.valueOf(resourceBlock.getCompanyId()),
169                                    Long.valueOf(resourceBlock.getGroupId()),
170                                    
171                            resourceBlock.getName(),
172                                    
173                            resourceBlock.getPermissionsHash()
174                            }, resourceBlock);
175    
176                    resourceBlock.resetOriginalValues();
177            }
178    
179            /**
180             * Caches the resource blocks in the entity cache if it is enabled.
181             *
182             * @param resourceBlocks the resource blocks
183             */
184            public void cacheResult(List<ResourceBlock> resourceBlocks) {
185                    for (ResourceBlock resourceBlock : resourceBlocks) {
186                            if (EntityCacheUtil.getResult(
187                                                    ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
188                                                    ResourceBlockImpl.class, resourceBlock.getPrimaryKey()) == null) {
189                                    cacheResult(resourceBlock);
190                            }
191                            else {
192                                    resourceBlock.resetOriginalValues();
193                            }
194                    }
195            }
196    
197            /**
198             * Clears the cache for all resource blocks.
199             *
200             * <p>
201             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
202             * </p>
203             */
204            @Override
205            public void clearCache() {
206                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
207                            CacheRegistryUtil.clear(ResourceBlockImpl.class.getName());
208                    }
209    
210                    EntityCacheUtil.clearCache(ResourceBlockImpl.class.getName());
211    
212                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
213                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
214                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
215            }
216    
217            /**
218             * Clears the cache for the resource block.
219             *
220             * <p>
221             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
222             * </p>
223             */
224            @Override
225            public void clearCache(ResourceBlock resourceBlock) {
226                    EntityCacheUtil.removeResult(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
227                            ResourceBlockImpl.class, resourceBlock.getPrimaryKey());
228    
229                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
230                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
231    
232                    clearUniqueFindersCache(resourceBlock);
233            }
234    
235            @Override
236            public void clearCache(List<ResourceBlock> resourceBlocks) {
237                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
238                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
239    
240                    for (ResourceBlock resourceBlock : resourceBlocks) {
241                            EntityCacheUtil.removeResult(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
242                                    ResourceBlockImpl.class, resourceBlock.getPrimaryKey());
243    
244                            clearUniqueFindersCache(resourceBlock);
245                    }
246            }
247    
248            protected void cacheUniqueFindersCache(ResourceBlock resourceBlock) {
249                    if (resourceBlock.isNew()) {
250                            Object[] args = new Object[] {
251                                            Long.valueOf(resourceBlock.getCompanyId()),
252                                            Long.valueOf(resourceBlock.getGroupId()),
253                                            
254                                            resourceBlock.getName(),
255                                            
256                                            resourceBlock.getPermissionsHash()
257                                    };
258    
259                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_G_N_P, args,
260                                    Long.valueOf(1));
261                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_G_N_P, args,
262                                    resourceBlock);
263                    }
264                    else {
265                            ResourceBlockModelImpl resourceBlockModelImpl = (ResourceBlockModelImpl)resourceBlock;
266    
267                            if ((resourceBlockModelImpl.getColumnBitmask() &
268                                            FINDER_PATH_FETCH_BY_C_G_N_P.getColumnBitmask()) != 0) {
269                                    Object[] args = new Object[] {
270                                                    Long.valueOf(resourceBlock.getCompanyId()),
271                                                    Long.valueOf(resourceBlock.getGroupId()),
272                                                    
273                                                    resourceBlock.getName(),
274                                                    
275                                                    resourceBlock.getPermissionsHash()
276                                            };
277    
278                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_G_N_P, args,
279                                            Long.valueOf(1));
280                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_G_N_P, args,
281                                            resourceBlock);
282                            }
283                    }
284            }
285    
286            protected void clearUniqueFindersCache(ResourceBlock resourceBlock) {
287                    ResourceBlockModelImpl resourceBlockModelImpl = (ResourceBlockModelImpl)resourceBlock;
288    
289                    Object[] args = new Object[] {
290                                    Long.valueOf(resourceBlock.getCompanyId()),
291                                    Long.valueOf(resourceBlock.getGroupId()),
292                                    
293                                    resourceBlock.getName(),
294                                    
295                                    resourceBlock.getPermissionsHash()
296                            };
297    
298                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_G_N_P, args);
299                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_G_N_P, args);
300    
301                    if ((resourceBlockModelImpl.getColumnBitmask() &
302                                    FINDER_PATH_FETCH_BY_C_G_N_P.getColumnBitmask()) != 0) {
303                            args = new Object[] {
304                                            Long.valueOf(resourceBlockModelImpl.getOriginalCompanyId()),
305                                            Long.valueOf(resourceBlockModelImpl.getOriginalGroupId()),
306                                            
307                                            resourceBlockModelImpl.getOriginalName(),
308                                            
309                                            resourceBlockModelImpl.getOriginalPermissionsHash()
310                                    };
311    
312                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_G_N_P, args);
313                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_G_N_P, args);
314                    }
315            }
316    
317            /**
318             * Creates a new resource block with the primary key. Does not add the resource block to the database.
319             *
320             * @param resourceBlockId the primary key for the new resource block
321             * @return the new resource block
322             */
323            public ResourceBlock create(long resourceBlockId) {
324                    ResourceBlock resourceBlock = new ResourceBlockImpl();
325    
326                    resourceBlock.setNew(true);
327                    resourceBlock.setPrimaryKey(resourceBlockId);
328    
329                    return resourceBlock;
330            }
331    
332            /**
333             * Removes the resource block with the primary key from the database. Also notifies the appropriate model listeners.
334             *
335             * @param resourceBlockId the primary key of the resource block
336             * @return the resource block that was removed
337             * @throws com.liferay.portal.NoSuchResourceBlockException if a resource block with the primary key could not be found
338             * @throws SystemException if a system exception occurred
339             */
340            public ResourceBlock remove(long resourceBlockId)
341                    throws NoSuchResourceBlockException, SystemException {
342                    return remove(Long.valueOf(resourceBlockId));
343            }
344    
345            /**
346             * Removes the resource block with the primary key from the database. Also notifies the appropriate model listeners.
347             *
348             * @param primaryKey the primary key of the resource block
349             * @return the resource block that was removed
350             * @throws com.liferay.portal.NoSuchResourceBlockException if a resource block with the primary key could not be found
351             * @throws SystemException if a system exception occurred
352             */
353            @Override
354            public ResourceBlock remove(Serializable primaryKey)
355                    throws NoSuchResourceBlockException, SystemException {
356                    Session session = null;
357    
358                    try {
359                            session = openSession();
360    
361                            ResourceBlock resourceBlock = (ResourceBlock)session.get(ResourceBlockImpl.class,
362                                            primaryKey);
363    
364                            if (resourceBlock == null) {
365                                    if (_log.isWarnEnabled()) {
366                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
367                                    }
368    
369                                    throw new NoSuchResourceBlockException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
370                                            primaryKey);
371                            }
372    
373                            return remove(resourceBlock);
374                    }
375                    catch (NoSuchResourceBlockException nsee) {
376                            throw nsee;
377                    }
378                    catch (Exception e) {
379                            throw processException(e);
380                    }
381                    finally {
382                            closeSession(session);
383                    }
384            }
385    
386            @Override
387            protected ResourceBlock removeImpl(ResourceBlock resourceBlock)
388                    throws SystemException {
389                    resourceBlock = toUnwrappedModel(resourceBlock);
390    
391                    Session session = null;
392    
393                    try {
394                            session = openSession();
395    
396                            BatchSessionUtil.delete(session, resourceBlock);
397                    }
398                    catch (Exception e) {
399                            throw processException(e);
400                    }
401                    finally {
402                            closeSession(session);
403                    }
404    
405                    clearCache(resourceBlock);
406    
407                    return resourceBlock;
408            }
409    
410            @Override
411            public ResourceBlock updateImpl(
412                    com.liferay.portal.model.ResourceBlock resourceBlock, boolean merge)
413                    throws SystemException {
414                    resourceBlock = toUnwrappedModel(resourceBlock);
415    
416                    boolean isNew = resourceBlock.isNew();
417    
418                    ResourceBlockModelImpl resourceBlockModelImpl = (ResourceBlockModelImpl)resourceBlock;
419    
420                    Session session = null;
421    
422                    try {
423                            session = openSession();
424    
425                            BatchSessionUtil.update(session, resourceBlock, merge);
426    
427                            resourceBlock.setNew(false);
428                    }
429                    catch (Exception e) {
430                            throw processException(e);
431                    }
432                    finally {
433                            closeSession(session);
434                    }
435    
436                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
437    
438                    if (isNew || !ResourceBlockModelImpl.COLUMN_BITMASK_ENABLED) {
439                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
440                    }
441    
442                    else {
443                            if ((resourceBlockModelImpl.getColumnBitmask() &
444                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N.getColumnBitmask()) != 0) {
445                                    Object[] args = new Object[] {
446                                                    Long.valueOf(resourceBlockModelImpl.getOriginalCompanyId()),
447                                                    
448                                                    resourceBlockModelImpl.getOriginalName()
449                                            };
450    
451                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_N, args);
452                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N,
453                                            args);
454    
455                                    args = new Object[] {
456                                                    Long.valueOf(resourceBlockModelImpl.getCompanyId()),
457                                                    
458                                                    resourceBlockModelImpl.getName()
459                                            };
460    
461                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_N, args);
462                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N,
463                                            args);
464                            }
465    
466                            if ((resourceBlockModelImpl.getColumnBitmask() &
467                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_G_N.getColumnBitmask()) != 0) {
468                                    Object[] args = new Object[] {
469                                                    Long.valueOf(resourceBlockModelImpl.getOriginalCompanyId()),
470                                                    Long.valueOf(resourceBlockModelImpl.getOriginalGroupId()),
471                                                    
472                                                    resourceBlockModelImpl.getOriginalName()
473                                            };
474    
475                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_G_N, args);
476                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_G_N,
477                                            args);
478    
479                                    args = new Object[] {
480                                                    Long.valueOf(resourceBlockModelImpl.getCompanyId()),
481                                                    Long.valueOf(resourceBlockModelImpl.getGroupId()),
482                                                    
483                                                    resourceBlockModelImpl.getName()
484                                            };
485    
486                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_G_N, args);
487                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_G_N,
488                                            args);
489                            }
490                    }
491    
492                    EntityCacheUtil.putResult(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
493                            ResourceBlockImpl.class, resourceBlock.getPrimaryKey(),
494                            resourceBlock);
495    
496                    clearUniqueFindersCache(resourceBlock);
497                    cacheUniqueFindersCache(resourceBlock);
498    
499                    return resourceBlock;
500            }
501    
502            protected ResourceBlock toUnwrappedModel(ResourceBlock resourceBlock) {
503                    if (resourceBlock instanceof ResourceBlockImpl) {
504                            return resourceBlock;
505                    }
506    
507                    ResourceBlockImpl resourceBlockImpl = new ResourceBlockImpl();
508    
509                    resourceBlockImpl.setNew(resourceBlock.isNew());
510                    resourceBlockImpl.setPrimaryKey(resourceBlock.getPrimaryKey());
511    
512                    resourceBlockImpl.setResourceBlockId(resourceBlock.getResourceBlockId());
513                    resourceBlockImpl.setCompanyId(resourceBlock.getCompanyId());
514                    resourceBlockImpl.setGroupId(resourceBlock.getGroupId());
515                    resourceBlockImpl.setName(resourceBlock.getName());
516                    resourceBlockImpl.setPermissionsHash(resourceBlock.getPermissionsHash());
517                    resourceBlockImpl.setReferenceCount(resourceBlock.getReferenceCount());
518    
519                    return resourceBlockImpl;
520            }
521    
522            /**
523             * Returns the resource block with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
524             *
525             * @param primaryKey the primary key of the resource block
526             * @return the resource block
527             * @throws com.liferay.portal.NoSuchModelException if a resource block with the primary key could not be found
528             * @throws SystemException if a system exception occurred
529             */
530            @Override
531            public ResourceBlock findByPrimaryKey(Serializable primaryKey)
532                    throws NoSuchModelException, SystemException {
533                    return findByPrimaryKey(((Long)primaryKey).longValue());
534            }
535    
536            /**
537             * Returns the resource block with the primary key or throws a {@link com.liferay.portal.NoSuchResourceBlockException} if it could not be found.
538             *
539             * @param resourceBlockId the primary key of the resource block
540             * @return the resource block
541             * @throws com.liferay.portal.NoSuchResourceBlockException if a resource block with the primary key could not be found
542             * @throws SystemException if a system exception occurred
543             */
544            public ResourceBlock findByPrimaryKey(long resourceBlockId)
545                    throws NoSuchResourceBlockException, SystemException {
546                    ResourceBlock resourceBlock = fetchByPrimaryKey(resourceBlockId);
547    
548                    if (resourceBlock == null) {
549                            if (_log.isWarnEnabled()) {
550                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + resourceBlockId);
551                            }
552    
553                            throw new NoSuchResourceBlockException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
554                                    resourceBlockId);
555                    }
556    
557                    return resourceBlock;
558            }
559    
560            /**
561             * Returns the resource block with the primary key or returns <code>null</code> if it could not be found.
562             *
563             * @param primaryKey the primary key of the resource block
564             * @return the resource block, or <code>null</code> if a resource block with the primary key could not be found
565             * @throws SystemException if a system exception occurred
566             */
567            @Override
568            public ResourceBlock fetchByPrimaryKey(Serializable primaryKey)
569                    throws SystemException {
570                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
571            }
572    
573            /**
574             * Returns the resource block with the primary key or returns <code>null</code> if it could not be found.
575             *
576             * @param resourceBlockId the primary key of the resource block
577             * @return the resource block, or <code>null</code> if a resource block with the primary key could not be found
578             * @throws SystemException if a system exception occurred
579             */
580            public ResourceBlock fetchByPrimaryKey(long resourceBlockId)
581                    throws SystemException {
582                    ResourceBlock resourceBlock = (ResourceBlock)EntityCacheUtil.getResult(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
583                                    ResourceBlockImpl.class, resourceBlockId);
584    
585                    if (resourceBlock == _nullResourceBlock) {
586                            return null;
587                    }
588    
589                    if (resourceBlock == null) {
590                            Session session = null;
591    
592                            boolean hasException = false;
593    
594                            try {
595                                    session = openSession();
596    
597                                    resourceBlock = (ResourceBlock)session.get(ResourceBlockImpl.class,
598                                                    Long.valueOf(resourceBlockId));
599                            }
600                            catch (Exception e) {
601                                    hasException = true;
602    
603                                    throw processException(e);
604                            }
605                            finally {
606                                    if (resourceBlock != null) {
607                                            cacheResult(resourceBlock);
608                                    }
609                                    else if (!hasException) {
610                                            EntityCacheUtil.putResult(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
611                                                    ResourceBlockImpl.class, resourceBlockId,
612                                                    _nullResourceBlock);
613                                    }
614    
615                                    closeSession(session);
616                            }
617                    }
618    
619                    return resourceBlock;
620            }
621    
622            /**
623             * Returns all the resource blocks where companyId = &#63; and name = &#63;.
624             *
625             * @param companyId the company ID
626             * @param name the name
627             * @return the matching resource blocks
628             * @throws SystemException if a system exception occurred
629             */
630            public List<ResourceBlock> findByC_N(long companyId, String name)
631                    throws SystemException {
632                    return findByC_N(companyId, name, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
633                            null);
634            }
635    
636            /**
637             * Returns a range of all the resource blocks where companyId = &#63; and name = &#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 companyId the company ID
644             * @param name the name
645             * @param start the lower bound of the range of resource blocks
646             * @param end the upper bound of the range of resource blocks (not inclusive)
647             * @return the range of matching resource blocks
648             * @throws SystemException if a system exception occurred
649             */
650            public List<ResourceBlock> findByC_N(long companyId, String name,
651                    int start, int end) throws SystemException {
652                    return findByC_N(companyId, name, start, end, null);
653            }
654    
655            /**
656             * Returns an ordered range of all the resource blocks where companyId = &#63; and name = &#63;.
657             *
658             * <p>
659             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
660             * </p>
661             *
662             * @param companyId the company ID
663             * @param name the name
664             * @param start the lower bound of the range of resource blocks
665             * @param end the upper bound of the range of resource blocks (not inclusive)
666             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
667             * @return the ordered range of matching resource blocks
668             * @throws SystemException if a system exception occurred
669             */
670            public List<ResourceBlock> findByC_N(long companyId, String name,
671                    int start, int end, OrderByComparator orderByComparator)
672                    throws SystemException {
673                    FinderPath finderPath = null;
674                    Object[] finderArgs = null;
675    
676                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
677                                    (orderByComparator == null)) {
678                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N;
679                            finderArgs = new Object[] { companyId, name };
680                    }
681                    else {
682                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_N;
683                            finderArgs = new Object[] {
684                                            companyId, name,
685                                            
686                                            start, end, orderByComparator
687                                    };
688                    }
689    
690                    List<ResourceBlock> list = (List<ResourceBlock>)FinderCacheUtil.getResult(finderPath,
691                                    finderArgs, this);
692    
693                    if ((list != null) && !list.isEmpty()) {
694                            for (ResourceBlock resourceBlock : list) {
695                                    if ((companyId != resourceBlock.getCompanyId()) ||
696                                                    !Validator.equals(name, resourceBlock.getName())) {
697                                            list = null;
698    
699                                            break;
700                                    }
701                            }
702                    }
703    
704                    if (list == null) {
705                            StringBundler query = null;
706    
707                            if (orderByComparator != null) {
708                                    query = new StringBundler(4 +
709                                                    (orderByComparator.getOrderByFields().length * 3));
710                            }
711                            else {
712                                    query = new StringBundler(3);
713                            }
714    
715                            query.append(_SQL_SELECT_RESOURCEBLOCK_WHERE);
716    
717                            query.append(_FINDER_COLUMN_C_N_COMPANYID_2);
718    
719                            if (name == null) {
720                                    query.append(_FINDER_COLUMN_C_N_NAME_1);
721                            }
722                            else {
723                                    if (name.equals(StringPool.BLANK)) {
724                                            query.append(_FINDER_COLUMN_C_N_NAME_3);
725                                    }
726                                    else {
727                                            query.append(_FINDER_COLUMN_C_N_NAME_2);
728                                    }
729                            }
730    
731                            if (orderByComparator != null) {
732                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
733                                            orderByComparator);
734                            }
735    
736                            String sql = query.toString();
737    
738                            Session session = null;
739    
740                            try {
741                                    session = openSession();
742    
743                                    Query q = session.createQuery(sql);
744    
745                                    QueryPos qPos = QueryPos.getInstance(q);
746    
747                                    qPos.add(companyId);
748    
749                                    if (name != null) {
750                                            qPos.add(name);
751                                    }
752    
753                                    list = (List<ResourceBlock>)QueryUtil.list(q, getDialect(),
754                                                    start, end);
755                            }
756                            catch (Exception e) {
757                                    throw processException(e);
758                            }
759                            finally {
760                                    if (list == null) {
761                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
762                                    }
763                                    else {
764                                            cacheResult(list);
765    
766                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
767                                    }
768    
769                                    closeSession(session);
770                            }
771                    }
772    
773                    return list;
774            }
775    
776            /**
777             * Returns the first resource block in the ordered set where companyId = &#63; and name = &#63;.
778             *
779             * @param companyId the company ID
780             * @param name the name
781             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
782             * @return the first matching resource block
783             * @throws com.liferay.portal.NoSuchResourceBlockException if a matching resource block could not be found
784             * @throws SystemException if a system exception occurred
785             */
786            public ResourceBlock findByC_N_First(long companyId, String name,
787                    OrderByComparator orderByComparator)
788                    throws NoSuchResourceBlockException, SystemException {
789                    ResourceBlock resourceBlock = fetchByC_N_First(companyId, name,
790                                    orderByComparator);
791    
792                    if (resourceBlock != null) {
793                            return resourceBlock;
794                    }
795    
796                    StringBundler msg = new StringBundler(6);
797    
798                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
799    
800                    msg.append("companyId=");
801                    msg.append(companyId);
802    
803                    msg.append(", name=");
804                    msg.append(name);
805    
806                    msg.append(StringPool.CLOSE_CURLY_BRACE);
807    
808                    throw new NoSuchResourceBlockException(msg.toString());
809            }
810    
811            /**
812             * Returns the first resource block in the ordered set where companyId = &#63; and name = &#63;.
813             *
814             * @param companyId the company ID
815             * @param name the name
816             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
817             * @return the first matching resource block, or <code>null</code> if a matching resource block could not be found
818             * @throws SystemException if a system exception occurred
819             */
820            public ResourceBlock fetchByC_N_First(long companyId, String name,
821                    OrderByComparator orderByComparator) throws SystemException {
822                    List<ResourceBlock> list = findByC_N(companyId, name, 0, 1,
823                                    orderByComparator);
824    
825                    if (!list.isEmpty()) {
826                            return list.get(0);
827                    }
828    
829                    return null;
830            }
831    
832            /**
833             * Returns the last resource block in the ordered set where companyId = &#63; and name = &#63;.
834             *
835             * @param companyId the company ID
836             * @param name the name
837             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
838             * @return the last matching resource block
839             * @throws com.liferay.portal.NoSuchResourceBlockException if a matching resource block could not be found
840             * @throws SystemException if a system exception occurred
841             */
842            public ResourceBlock findByC_N_Last(long companyId, String name,
843                    OrderByComparator orderByComparator)
844                    throws NoSuchResourceBlockException, SystemException {
845                    ResourceBlock resourceBlock = fetchByC_N_Last(companyId, name,
846                                    orderByComparator);
847    
848                    if (resourceBlock != null) {
849                            return resourceBlock;
850                    }
851    
852                    StringBundler msg = new StringBundler(6);
853    
854                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
855    
856                    msg.append("companyId=");
857                    msg.append(companyId);
858    
859                    msg.append(", name=");
860                    msg.append(name);
861    
862                    msg.append(StringPool.CLOSE_CURLY_BRACE);
863    
864                    throw new NoSuchResourceBlockException(msg.toString());
865            }
866    
867            /**
868             * Returns the last resource block in the ordered set where companyId = &#63; and name = &#63;.
869             *
870             * @param companyId the company ID
871             * @param name the name
872             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
873             * @return the last matching resource block, or <code>null</code> if a matching resource block could not be found
874             * @throws SystemException if a system exception occurred
875             */
876            public ResourceBlock fetchByC_N_Last(long companyId, String name,
877                    OrderByComparator orderByComparator) throws SystemException {
878                    int count = countByC_N(companyId, name);
879    
880                    List<ResourceBlock> list = findByC_N(companyId, name, count - 1, count,
881                                    orderByComparator);
882    
883                    if (!list.isEmpty()) {
884                            return list.get(0);
885                    }
886    
887                    return null;
888            }
889    
890            /**
891             * Returns the resource blocks before and after the current resource block in the ordered set where companyId = &#63; and name = &#63;.
892             *
893             * @param resourceBlockId the primary key of the current resource block
894             * @param companyId the company ID
895             * @param name the name
896             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
897             * @return the previous, current, and next resource block
898             * @throws com.liferay.portal.NoSuchResourceBlockException if a resource block with the primary key could not be found
899             * @throws SystemException if a system exception occurred
900             */
901            public ResourceBlock[] findByC_N_PrevAndNext(long resourceBlockId,
902                    long companyId, String name, OrderByComparator orderByComparator)
903                    throws NoSuchResourceBlockException, SystemException {
904                    ResourceBlock resourceBlock = findByPrimaryKey(resourceBlockId);
905    
906                    Session session = null;
907    
908                    try {
909                            session = openSession();
910    
911                            ResourceBlock[] array = new ResourceBlockImpl[3];
912    
913                            array[0] = getByC_N_PrevAndNext(session, resourceBlock, companyId,
914                                            name, orderByComparator, true);
915    
916                            array[1] = resourceBlock;
917    
918                            array[2] = getByC_N_PrevAndNext(session, resourceBlock, companyId,
919                                            name, orderByComparator, false);
920    
921                            return array;
922                    }
923                    catch (Exception e) {
924                            throw processException(e);
925                    }
926                    finally {
927                            closeSession(session);
928                    }
929            }
930    
931            protected ResourceBlock getByC_N_PrevAndNext(Session session,
932                    ResourceBlock resourceBlock, long companyId, String name,
933                    OrderByComparator orderByComparator, boolean previous) {
934                    StringBundler query = null;
935    
936                    if (orderByComparator != null) {
937                            query = new StringBundler(6 +
938                                            (orderByComparator.getOrderByFields().length * 6));
939                    }
940                    else {
941                            query = new StringBundler(3);
942                    }
943    
944                    query.append(_SQL_SELECT_RESOURCEBLOCK_WHERE);
945    
946                    query.append(_FINDER_COLUMN_C_N_COMPANYID_2);
947    
948                    if (name == null) {
949                            query.append(_FINDER_COLUMN_C_N_NAME_1);
950                    }
951                    else {
952                            if (name.equals(StringPool.BLANK)) {
953                                    query.append(_FINDER_COLUMN_C_N_NAME_3);
954                            }
955                            else {
956                                    query.append(_FINDER_COLUMN_C_N_NAME_2);
957                            }
958                    }
959    
960                    if (orderByComparator != null) {
961                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
962    
963                            if (orderByConditionFields.length > 0) {
964                                    query.append(WHERE_AND);
965                            }
966    
967                            for (int i = 0; i < orderByConditionFields.length; i++) {
968                                    query.append(_ORDER_BY_ENTITY_ALIAS);
969                                    query.append(orderByConditionFields[i]);
970    
971                                    if ((i + 1) < orderByConditionFields.length) {
972                                            if (orderByComparator.isAscending() ^ previous) {
973                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
974                                            }
975                                            else {
976                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
977                                            }
978                                    }
979                                    else {
980                                            if (orderByComparator.isAscending() ^ previous) {
981                                                    query.append(WHERE_GREATER_THAN);
982                                            }
983                                            else {
984                                                    query.append(WHERE_LESSER_THAN);
985                                            }
986                                    }
987                            }
988    
989                            query.append(ORDER_BY_CLAUSE);
990    
991                            String[] orderByFields = orderByComparator.getOrderByFields();
992    
993                            for (int i = 0; i < orderByFields.length; i++) {
994                                    query.append(_ORDER_BY_ENTITY_ALIAS);
995                                    query.append(orderByFields[i]);
996    
997                                    if ((i + 1) < orderByFields.length) {
998                                            if (orderByComparator.isAscending() ^ previous) {
999                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1000                                            }
1001                                            else {
1002                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1003                                            }
1004                                    }
1005                                    else {
1006                                            if (orderByComparator.isAscending() ^ previous) {
1007                                                    query.append(ORDER_BY_ASC);
1008                                            }
1009                                            else {
1010                                                    query.append(ORDER_BY_DESC);
1011                                            }
1012                                    }
1013                            }
1014                    }
1015    
1016                    String sql = query.toString();
1017    
1018                    Query q = session.createQuery(sql);
1019    
1020                    q.setFirstResult(0);
1021                    q.setMaxResults(2);
1022    
1023                    QueryPos qPos = QueryPos.getInstance(q);
1024    
1025                    qPos.add(companyId);
1026    
1027                    if (name != null) {
1028                            qPos.add(name);
1029                    }
1030    
1031                    if (orderByComparator != null) {
1032                            Object[] values = orderByComparator.getOrderByConditionValues(resourceBlock);
1033    
1034                            for (Object value : values) {
1035                                    qPos.add(value);
1036                            }
1037                    }
1038    
1039                    List<ResourceBlock> list = q.list();
1040    
1041                    if (list.size() == 2) {
1042                            return list.get(1);
1043                    }
1044                    else {
1045                            return null;
1046                    }
1047            }
1048    
1049            /**
1050             * Returns all the resource blocks where companyId = &#63; and groupId = &#63; and name = &#63;.
1051             *
1052             * @param companyId the company ID
1053             * @param groupId the group ID
1054             * @param name the name
1055             * @return the matching resource blocks
1056             * @throws SystemException if a system exception occurred
1057             */
1058            public List<ResourceBlock> findByC_G_N(long companyId, long groupId,
1059                    String name) throws SystemException {
1060                    return findByC_G_N(companyId, groupId, name, QueryUtil.ALL_POS,
1061                            QueryUtil.ALL_POS, null);
1062            }
1063    
1064            /**
1065             * Returns a range of all the resource blocks where companyId = &#63; and groupId = &#63; and name = &#63;.
1066             *
1067             * <p>
1068             * 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.
1069             * </p>
1070             *
1071             * @param companyId the company ID
1072             * @param groupId the group ID
1073             * @param name the name
1074             * @param start the lower bound of the range of resource blocks
1075             * @param end the upper bound of the range of resource blocks (not inclusive)
1076             * @return the range of matching resource blocks
1077             * @throws SystemException if a system exception occurred
1078             */
1079            public List<ResourceBlock> findByC_G_N(long companyId, long groupId,
1080                    String name, int start, int end) throws SystemException {
1081                    return findByC_G_N(companyId, groupId, name, start, end, null);
1082            }
1083    
1084            /**
1085             * Returns an ordered range of all the resource blocks where companyId = &#63; and groupId = &#63; and name = &#63;.
1086             *
1087             * <p>
1088             * 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.
1089             * </p>
1090             *
1091             * @param companyId the company ID
1092             * @param groupId the group ID
1093             * @param name the name
1094             * @param start the lower bound of the range of resource blocks
1095             * @param end the upper bound of the range of resource blocks (not inclusive)
1096             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1097             * @return the ordered range of matching resource blocks
1098             * @throws SystemException if a system exception occurred
1099             */
1100            public List<ResourceBlock> findByC_G_N(long companyId, long groupId,
1101                    String name, int start, int end, OrderByComparator orderByComparator)
1102                    throws SystemException {
1103                    FinderPath finderPath = null;
1104                    Object[] finderArgs = null;
1105    
1106                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1107                                    (orderByComparator == null)) {
1108                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_G_N;
1109                            finderArgs = new Object[] { companyId, groupId, name };
1110                    }
1111                    else {
1112                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_G_N;
1113                            finderArgs = new Object[] {
1114                                            companyId, groupId, name,
1115                                            
1116                                            start, end, orderByComparator
1117                                    };
1118                    }
1119    
1120                    List<ResourceBlock> list = (List<ResourceBlock>)FinderCacheUtil.getResult(finderPath,
1121                                    finderArgs, this);
1122    
1123                    if ((list != null) && !list.isEmpty()) {
1124                            for (ResourceBlock resourceBlock : list) {
1125                                    if ((companyId != resourceBlock.getCompanyId()) ||
1126                                                    (groupId != resourceBlock.getGroupId()) ||
1127                                                    !Validator.equals(name, resourceBlock.getName())) {
1128                                            list = null;
1129    
1130                                            break;
1131                                    }
1132                            }
1133                    }
1134    
1135                    if (list == null) {
1136                            StringBundler query = null;
1137    
1138                            if (orderByComparator != null) {
1139                                    query = new StringBundler(5 +
1140                                                    (orderByComparator.getOrderByFields().length * 3));
1141                            }
1142                            else {
1143                                    query = new StringBundler(4);
1144                            }
1145    
1146                            query.append(_SQL_SELECT_RESOURCEBLOCK_WHERE);
1147    
1148                            query.append(_FINDER_COLUMN_C_G_N_COMPANYID_2);
1149    
1150                            query.append(_FINDER_COLUMN_C_G_N_GROUPID_2);
1151    
1152                            if (name == null) {
1153                                    query.append(_FINDER_COLUMN_C_G_N_NAME_1);
1154                            }
1155                            else {
1156                                    if (name.equals(StringPool.BLANK)) {
1157                                            query.append(_FINDER_COLUMN_C_G_N_NAME_3);
1158                                    }
1159                                    else {
1160                                            query.append(_FINDER_COLUMN_C_G_N_NAME_2);
1161                                    }
1162                            }
1163    
1164                            if (orderByComparator != null) {
1165                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1166                                            orderByComparator);
1167                            }
1168    
1169                            String sql = query.toString();
1170    
1171                            Session session = null;
1172    
1173                            try {
1174                                    session = openSession();
1175    
1176                                    Query q = session.createQuery(sql);
1177    
1178                                    QueryPos qPos = QueryPos.getInstance(q);
1179    
1180                                    qPos.add(companyId);
1181    
1182                                    qPos.add(groupId);
1183    
1184                                    if (name != null) {
1185                                            qPos.add(name);
1186                                    }
1187    
1188                                    list = (List<ResourceBlock>)QueryUtil.list(q, getDialect(),
1189                                                    start, end);
1190                            }
1191                            catch (Exception e) {
1192                                    throw processException(e);
1193                            }
1194                            finally {
1195                                    if (list == null) {
1196                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1197                                    }
1198                                    else {
1199                                            cacheResult(list);
1200    
1201                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1202                                    }
1203    
1204                                    closeSession(session);
1205                            }
1206                    }
1207    
1208                    return list;
1209            }
1210    
1211            /**
1212             * Returns the first resource block in the ordered set where companyId = &#63; and groupId = &#63; and name = &#63;.
1213             *
1214             * @param companyId the company ID
1215             * @param groupId the group ID
1216             * @param name the name
1217             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1218             * @return the first matching resource block
1219             * @throws com.liferay.portal.NoSuchResourceBlockException if a matching resource block could not be found
1220             * @throws SystemException if a system exception occurred
1221             */
1222            public ResourceBlock findByC_G_N_First(long companyId, long groupId,
1223                    String name, OrderByComparator orderByComparator)
1224                    throws NoSuchResourceBlockException, SystemException {
1225                    ResourceBlock resourceBlock = fetchByC_G_N_First(companyId, groupId,
1226                                    name, orderByComparator);
1227    
1228                    if (resourceBlock != null) {
1229                            return resourceBlock;
1230                    }
1231    
1232                    StringBundler msg = new StringBundler(8);
1233    
1234                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1235    
1236                    msg.append("companyId=");
1237                    msg.append(companyId);
1238    
1239                    msg.append(", groupId=");
1240                    msg.append(groupId);
1241    
1242                    msg.append(", name=");
1243                    msg.append(name);
1244    
1245                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1246    
1247                    throw new NoSuchResourceBlockException(msg.toString());
1248            }
1249    
1250            /**
1251             * Returns the first resource block in the ordered set where companyId = &#63; and groupId = &#63; and name = &#63;.
1252             *
1253             * @param companyId the company ID
1254             * @param groupId the group ID
1255             * @param name the name
1256             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1257             * @return the first matching resource block, or <code>null</code> if a matching resource block could not be found
1258             * @throws SystemException if a system exception occurred
1259             */
1260            public ResourceBlock fetchByC_G_N_First(long companyId, long groupId,
1261                    String name, OrderByComparator orderByComparator)
1262                    throws SystemException {
1263                    List<ResourceBlock> list = findByC_G_N(companyId, groupId, name, 0, 1,
1264                                    orderByComparator);
1265    
1266                    if (!list.isEmpty()) {
1267                            return list.get(0);
1268                    }
1269    
1270                    return null;
1271            }
1272    
1273            /**
1274             * Returns the last resource block in the ordered set where companyId = &#63; and groupId = &#63; and name = &#63;.
1275             *
1276             * @param companyId the company ID
1277             * @param groupId the group ID
1278             * @param name the name
1279             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1280             * @return the last matching resource block
1281             * @throws com.liferay.portal.NoSuchResourceBlockException if a matching resource block could not be found
1282             * @throws SystemException if a system exception occurred
1283             */
1284            public ResourceBlock findByC_G_N_Last(long companyId, long groupId,
1285                    String name, OrderByComparator orderByComparator)
1286                    throws NoSuchResourceBlockException, SystemException {
1287                    ResourceBlock resourceBlock = fetchByC_G_N_Last(companyId, groupId,
1288                                    name, orderByComparator);
1289    
1290                    if (resourceBlock != null) {
1291                            return resourceBlock;
1292                    }
1293    
1294                    StringBundler msg = new StringBundler(8);
1295    
1296                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1297    
1298                    msg.append("companyId=");
1299                    msg.append(companyId);
1300    
1301                    msg.append(", groupId=");
1302                    msg.append(groupId);
1303    
1304                    msg.append(", name=");
1305                    msg.append(name);
1306    
1307                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1308    
1309                    throw new NoSuchResourceBlockException(msg.toString());
1310            }
1311    
1312            /**
1313             * Returns the last resource block in the ordered set where companyId = &#63; and groupId = &#63; and name = &#63;.
1314             *
1315             * @param companyId the company ID
1316             * @param groupId the group ID
1317             * @param name the name
1318             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1319             * @return the last matching resource block, or <code>null</code> if a matching resource block could not be found
1320             * @throws SystemException if a system exception occurred
1321             */
1322            public ResourceBlock fetchByC_G_N_Last(long companyId, long groupId,
1323                    String name, OrderByComparator orderByComparator)
1324                    throws SystemException {
1325                    int count = countByC_G_N(companyId, groupId, name);
1326    
1327                    List<ResourceBlock> list = findByC_G_N(companyId, groupId, name,
1328                                    count - 1, count, orderByComparator);
1329    
1330                    if (!list.isEmpty()) {
1331                            return list.get(0);
1332                    }
1333    
1334                    return null;
1335            }
1336    
1337            /**
1338             * Returns the resource blocks before and after the current resource block in the ordered set where companyId = &#63; and groupId = &#63; and name = &#63;.
1339             *
1340             * @param resourceBlockId the primary key of the current resource block
1341             * @param companyId the company ID
1342             * @param groupId the group ID
1343             * @param name the name
1344             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1345             * @return the previous, current, and next resource block
1346             * @throws com.liferay.portal.NoSuchResourceBlockException if a resource block with the primary key could not be found
1347             * @throws SystemException if a system exception occurred
1348             */
1349            public ResourceBlock[] findByC_G_N_PrevAndNext(long resourceBlockId,
1350                    long companyId, long groupId, String name,
1351                    OrderByComparator orderByComparator)
1352                    throws NoSuchResourceBlockException, SystemException {
1353                    ResourceBlock resourceBlock = findByPrimaryKey(resourceBlockId);
1354    
1355                    Session session = null;
1356    
1357                    try {
1358                            session = openSession();
1359    
1360                            ResourceBlock[] array = new ResourceBlockImpl[3];
1361    
1362                            array[0] = getByC_G_N_PrevAndNext(session, resourceBlock,
1363                                            companyId, groupId, name, orderByComparator, true);
1364    
1365                            array[1] = resourceBlock;
1366    
1367                            array[2] = getByC_G_N_PrevAndNext(session, resourceBlock,
1368                                            companyId, groupId, name, orderByComparator, false);
1369    
1370                            return array;
1371                    }
1372                    catch (Exception e) {
1373                            throw processException(e);
1374                    }
1375                    finally {
1376                            closeSession(session);
1377                    }
1378            }
1379    
1380            protected ResourceBlock getByC_G_N_PrevAndNext(Session session,
1381                    ResourceBlock resourceBlock, long companyId, long groupId, String name,
1382                    OrderByComparator orderByComparator, boolean previous) {
1383                    StringBundler query = null;
1384    
1385                    if (orderByComparator != null) {
1386                            query = new StringBundler(6 +
1387                                            (orderByComparator.getOrderByFields().length * 6));
1388                    }
1389                    else {
1390                            query = new StringBundler(3);
1391                    }
1392    
1393                    query.append(_SQL_SELECT_RESOURCEBLOCK_WHERE);
1394    
1395                    query.append(_FINDER_COLUMN_C_G_N_COMPANYID_2);
1396    
1397                    query.append(_FINDER_COLUMN_C_G_N_GROUPID_2);
1398    
1399                    if (name == null) {
1400                            query.append(_FINDER_COLUMN_C_G_N_NAME_1);
1401                    }
1402                    else {
1403                            if (name.equals(StringPool.BLANK)) {
1404                                    query.append(_FINDER_COLUMN_C_G_N_NAME_3);
1405                            }
1406                            else {
1407                                    query.append(_FINDER_COLUMN_C_G_N_NAME_2);
1408                            }
1409                    }
1410    
1411                    if (orderByComparator != null) {
1412                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1413    
1414                            if (orderByConditionFields.length > 0) {
1415                                    query.append(WHERE_AND);
1416                            }
1417    
1418                            for (int i = 0; i < orderByConditionFields.length; i++) {
1419                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1420                                    query.append(orderByConditionFields[i]);
1421    
1422                                    if ((i + 1) < orderByConditionFields.length) {
1423                                            if (orderByComparator.isAscending() ^ previous) {
1424                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1425                                            }
1426                                            else {
1427                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1428                                            }
1429                                    }
1430                                    else {
1431                                            if (orderByComparator.isAscending() ^ previous) {
1432                                                    query.append(WHERE_GREATER_THAN);
1433                                            }
1434                                            else {
1435                                                    query.append(WHERE_LESSER_THAN);
1436                                            }
1437                                    }
1438                            }
1439    
1440                            query.append(ORDER_BY_CLAUSE);
1441    
1442                            String[] orderByFields = orderByComparator.getOrderByFields();
1443    
1444                            for (int i = 0; i < orderByFields.length; i++) {
1445                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1446                                    query.append(orderByFields[i]);
1447    
1448                                    if ((i + 1) < orderByFields.length) {
1449                                            if (orderByComparator.isAscending() ^ previous) {
1450                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1451                                            }
1452                                            else {
1453                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1454                                            }
1455                                    }
1456                                    else {
1457                                            if (orderByComparator.isAscending() ^ previous) {
1458                                                    query.append(ORDER_BY_ASC);
1459                                            }
1460                                            else {
1461                                                    query.append(ORDER_BY_DESC);
1462                                            }
1463                                    }
1464                            }
1465                    }
1466    
1467                    String sql = query.toString();
1468    
1469                    Query q = session.createQuery(sql);
1470    
1471                    q.setFirstResult(0);
1472                    q.setMaxResults(2);
1473    
1474                    QueryPos qPos = QueryPos.getInstance(q);
1475    
1476                    qPos.add(companyId);
1477    
1478                    qPos.add(groupId);
1479    
1480                    if (name != null) {
1481                            qPos.add(name);
1482                    }
1483    
1484                    if (orderByComparator != null) {
1485                            Object[] values = orderByComparator.getOrderByConditionValues(resourceBlock);
1486    
1487                            for (Object value : values) {
1488                                    qPos.add(value);
1489                            }
1490                    }
1491    
1492                    List<ResourceBlock> list = q.list();
1493    
1494                    if (list.size() == 2) {
1495                            return list.get(1);
1496                    }
1497                    else {
1498                            return null;
1499                    }
1500            }
1501    
1502            /**
1503             * Returns the resource block where companyId = &#63; and groupId = &#63; and name = &#63; and permissionsHash = &#63; or throws a {@link com.liferay.portal.NoSuchResourceBlockException} if it could not be found.
1504             *
1505             * @param companyId the company ID
1506             * @param groupId the group ID
1507             * @param name the name
1508             * @param permissionsHash the permissions hash
1509             * @return the matching resource block
1510             * @throws com.liferay.portal.NoSuchResourceBlockException if a matching resource block could not be found
1511             * @throws SystemException if a system exception occurred
1512             */
1513            public ResourceBlock findByC_G_N_P(long companyId, long groupId,
1514                    String name, String permissionsHash)
1515                    throws NoSuchResourceBlockException, SystemException {
1516                    ResourceBlock resourceBlock = fetchByC_G_N_P(companyId, groupId, name,
1517                                    permissionsHash);
1518    
1519                    if (resourceBlock == null) {
1520                            StringBundler msg = new StringBundler(10);
1521    
1522                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1523    
1524                            msg.append("companyId=");
1525                            msg.append(companyId);
1526    
1527                            msg.append(", groupId=");
1528                            msg.append(groupId);
1529    
1530                            msg.append(", name=");
1531                            msg.append(name);
1532    
1533                            msg.append(", permissionsHash=");
1534                            msg.append(permissionsHash);
1535    
1536                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1537    
1538                            if (_log.isWarnEnabled()) {
1539                                    _log.warn(msg.toString());
1540                            }
1541    
1542                            throw new NoSuchResourceBlockException(msg.toString());
1543                    }
1544    
1545                    return resourceBlock;
1546            }
1547    
1548            /**
1549             * Returns the resource block where companyId = &#63; and groupId = &#63; and name = &#63; and permissionsHash = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
1550             *
1551             * @param companyId the company ID
1552             * @param groupId the group ID
1553             * @param name the name
1554             * @param permissionsHash the permissions hash
1555             * @return the matching resource block, or <code>null</code> if a matching resource block could not be found
1556             * @throws SystemException if a system exception occurred
1557             */
1558            public ResourceBlock fetchByC_G_N_P(long companyId, long groupId,
1559                    String name, String permissionsHash) throws SystemException {
1560                    return fetchByC_G_N_P(companyId, groupId, name, permissionsHash, true);
1561            }
1562    
1563            /**
1564             * Returns the resource block where companyId = &#63; and groupId = &#63; and name = &#63; and permissionsHash = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
1565             *
1566             * @param companyId the company ID
1567             * @param groupId the group ID
1568             * @param name the name
1569             * @param permissionsHash the permissions hash
1570             * @param retrieveFromCache whether to use the finder cache
1571             * @return the matching resource block, or <code>null</code> if a matching resource block could not be found
1572             * @throws SystemException if a system exception occurred
1573             */
1574            public ResourceBlock fetchByC_G_N_P(long companyId, long groupId,
1575                    String name, String permissionsHash, boolean retrieveFromCache)
1576                    throws SystemException {
1577                    Object[] finderArgs = new Object[] {
1578                                    companyId, groupId, name, permissionsHash
1579                            };
1580    
1581                    Object result = null;
1582    
1583                    if (retrieveFromCache) {
1584                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_G_N_P,
1585                                            finderArgs, this);
1586                    }
1587    
1588                    if (result instanceof ResourceBlock) {
1589                            ResourceBlock resourceBlock = (ResourceBlock)result;
1590    
1591                            if ((companyId != resourceBlock.getCompanyId()) ||
1592                                            (groupId != resourceBlock.getGroupId()) ||
1593                                            !Validator.equals(name, resourceBlock.getName()) ||
1594                                            !Validator.equals(permissionsHash,
1595                                                    resourceBlock.getPermissionsHash())) {
1596                                    result = null;
1597                            }
1598                    }
1599    
1600                    if (result == null) {
1601                            StringBundler query = new StringBundler(5);
1602    
1603                            query.append(_SQL_SELECT_RESOURCEBLOCK_WHERE);
1604    
1605                            query.append(_FINDER_COLUMN_C_G_N_P_COMPANYID_2);
1606    
1607                            query.append(_FINDER_COLUMN_C_G_N_P_GROUPID_2);
1608    
1609                            if (name == null) {
1610                                    query.append(_FINDER_COLUMN_C_G_N_P_NAME_1);
1611                            }
1612                            else {
1613                                    if (name.equals(StringPool.BLANK)) {
1614                                            query.append(_FINDER_COLUMN_C_G_N_P_NAME_3);
1615                                    }
1616                                    else {
1617                                            query.append(_FINDER_COLUMN_C_G_N_P_NAME_2);
1618                                    }
1619                            }
1620    
1621                            if (permissionsHash == null) {
1622                                    query.append(_FINDER_COLUMN_C_G_N_P_PERMISSIONSHASH_1);
1623                            }
1624                            else {
1625                                    if (permissionsHash.equals(StringPool.BLANK)) {
1626                                            query.append(_FINDER_COLUMN_C_G_N_P_PERMISSIONSHASH_3);
1627                                    }
1628                                    else {
1629                                            query.append(_FINDER_COLUMN_C_G_N_P_PERMISSIONSHASH_2);
1630                                    }
1631                            }
1632    
1633                            String sql = query.toString();
1634    
1635                            Session session = null;
1636    
1637                            try {
1638                                    session = openSession();
1639    
1640                                    Query q = session.createQuery(sql);
1641    
1642                                    QueryPos qPos = QueryPos.getInstance(q);
1643    
1644                                    qPos.add(companyId);
1645    
1646                                    qPos.add(groupId);
1647    
1648                                    if (name != null) {
1649                                            qPos.add(name);
1650                                    }
1651    
1652                                    if (permissionsHash != null) {
1653                                            qPos.add(permissionsHash);
1654                                    }
1655    
1656                                    List<ResourceBlock> list = q.list();
1657    
1658                                    result = list;
1659    
1660                                    ResourceBlock resourceBlock = null;
1661    
1662                                    if (list.isEmpty()) {
1663                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_G_N_P,
1664                                                    finderArgs, list);
1665                                    }
1666                                    else {
1667                                            resourceBlock = list.get(0);
1668    
1669                                            cacheResult(resourceBlock);
1670    
1671                                            if ((resourceBlock.getCompanyId() != companyId) ||
1672                                                            (resourceBlock.getGroupId() != groupId) ||
1673                                                            (resourceBlock.getName() == null) ||
1674                                                            !resourceBlock.getName().equals(name) ||
1675                                                            (resourceBlock.getPermissionsHash() == null) ||
1676                                                            !resourceBlock.getPermissionsHash()
1677                                                                                              .equals(permissionsHash)) {
1678                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_G_N_P,
1679                                                            finderArgs, resourceBlock);
1680                                            }
1681                                    }
1682    
1683                                    return resourceBlock;
1684                            }
1685                            catch (Exception e) {
1686                                    throw processException(e);
1687                            }
1688                            finally {
1689                                    if (result == null) {
1690                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_G_N_P,
1691                                                    finderArgs);
1692                                    }
1693    
1694                                    closeSession(session);
1695                            }
1696                    }
1697                    else {
1698                            if (result instanceof List<?>) {
1699                                    return null;
1700                            }
1701                            else {
1702                                    return (ResourceBlock)result;
1703                            }
1704                    }
1705            }
1706    
1707            /**
1708             * Returns all the resource blocks.
1709             *
1710             * @return the resource blocks
1711             * @throws SystemException if a system exception occurred
1712             */
1713            public List<ResourceBlock> findAll() throws SystemException {
1714                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1715            }
1716    
1717            /**
1718             * Returns a range of all the resource blocks.
1719             *
1720             * <p>
1721             * 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.
1722             * </p>
1723             *
1724             * @param start the lower bound of the range of resource blocks
1725             * @param end the upper bound of the range of resource blocks (not inclusive)
1726             * @return the range of resource blocks
1727             * @throws SystemException if a system exception occurred
1728             */
1729            public List<ResourceBlock> findAll(int start, int end)
1730                    throws SystemException {
1731                    return findAll(start, end, null);
1732            }
1733    
1734            /**
1735             * Returns an ordered range of all the resource blocks.
1736             *
1737             * <p>
1738             * 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.
1739             * </p>
1740             *
1741             * @param start the lower bound of the range of resource blocks
1742             * @param end the upper bound of the range of resource blocks (not inclusive)
1743             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1744             * @return the ordered range of resource blocks
1745             * @throws SystemException if a system exception occurred
1746             */
1747            public List<ResourceBlock> findAll(int start, int end,
1748                    OrderByComparator orderByComparator) throws SystemException {
1749                    FinderPath finderPath = null;
1750                    Object[] finderArgs = new Object[] { start, end, orderByComparator };
1751    
1752                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1753                                    (orderByComparator == null)) {
1754                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1755                            finderArgs = FINDER_ARGS_EMPTY;
1756                    }
1757                    else {
1758                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1759                            finderArgs = new Object[] { start, end, orderByComparator };
1760                    }
1761    
1762                    List<ResourceBlock> list = (List<ResourceBlock>)FinderCacheUtil.getResult(finderPath,
1763                                    finderArgs, this);
1764    
1765                    if (list == null) {
1766                            StringBundler query = null;
1767                            String sql = null;
1768    
1769                            if (orderByComparator != null) {
1770                                    query = new StringBundler(2 +
1771                                                    (orderByComparator.getOrderByFields().length * 3));
1772    
1773                                    query.append(_SQL_SELECT_RESOURCEBLOCK);
1774    
1775                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1776                                            orderByComparator);
1777    
1778                                    sql = query.toString();
1779                            }
1780                            else {
1781                                    sql = _SQL_SELECT_RESOURCEBLOCK;
1782                            }
1783    
1784                            Session session = null;
1785    
1786                            try {
1787                                    session = openSession();
1788    
1789                                    Query q = session.createQuery(sql);
1790    
1791                                    if (orderByComparator == null) {
1792                                            list = (List<ResourceBlock>)QueryUtil.list(q, getDialect(),
1793                                                            start, end, false);
1794    
1795                                            Collections.sort(list);
1796                                    }
1797                                    else {
1798                                            list = (List<ResourceBlock>)QueryUtil.list(q, getDialect(),
1799                                                            start, end);
1800                                    }
1801                            }
1802                            catch (Exception e) {
1803                                    throw processException(e);
1804                            }
1805                            finally {
1806                                    if (list == null) {
1807                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1808                                    }
1809                                    else {
1810                                            cacheResult(list);
1811    
1812                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1813                                    }
1814    
1815                                    closeSession(session);
1816                            }
1817                    }
1818    
1819                    return list;
1820            }
1821    
1822            /**
1823             * Removes all the resource blocks where companyId = &#63; and name = &#63; from the database.
1824             *
1825             * @param companyId the company ID
1826             * @param name the name
1827             * @throws SystemException if a system exception occurred
1828             */
1829            public void removeByC_N(long companyId, String name)
1830                    throws SystemException {
1831                    for (ResourceBlock resourceBlock : findByC_N(companyId, name)) {
1832                            remove(resourceBlock);
1833                    }
1834            }
1835    
1836            /**
1837             * Removes all the resource blocks where companyId = &#63; and groupId = &#63; and name = &#63; from the database.
1838             *
1839             * @param companyId the company ID
1840             * @param groupId the group ID
1841             * @param name the name
1842             * @throws SystemException if a system exception occurred
1843             */
1844            public void removeByC_G_N(long companyId, long groupId, String name)
1845                    throws SystemException {
1846                    for (ResourceBlock resourceBlock : findByC_G_N(companyId, groupId, name)) {
1847                            remove(resourceBlock);
1848                    }
1849            }
1850    
1851            /**
1852             * Removes the resource block where companyId = &#63; and groupId = &#63; and name = &#63; and permissionsHash = &#63; from the database.
1853             *
1854             * @param companyId the company ID
1855             * @param groupId the group ID
1856             * @param name the name
1857             * @param permissionsHash the permissions hash
1858             * @return the resource block that was removed
1859             * @throws SystemException if a system exception occurred
1860             */
1861            public ResourceBlock removeByC_G_N_P(long companyId, long groupId,
1862                    String name, String permissionsHash)
1863                    throws NoSuchResourceBlockException, SystemException {
1864                    ResourceBlock resourceBlock = findByC_G_N_P(companyId, groupId, name,
1865                                    permissionsHash);
1866    
1867                    return remove(resourceBlock);
1868            }
1869    
1870            /**
1871             * Removes all the resource blocks from the database.
1872             *
1873             * @throws SystemException if a system exception occurred
1874             */
1875            public void removeAll() throws SystemException {
1876                    for (ResourceBlock resourceBlock : findAll()) {
1877                            remove(resourceBlock);
1878                    }
1879            }
1880    
1881            /**
1882             * Returns the number of resource blocks where companyId = &#63; and name = &#63;.
1883             *
1884             * @param companyId the company ID
1885             * @param name the name
1886             * @return the number of matching resource blocks
1887             * @throws SystemException if a system exception occurred
1888             */
1889            public int countByC_N(long companyId, String name)
1890                    throws SystemException {
1891                    Object[] finderArgs = new Object[] { companyId, name };
1892    
1893                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_N,
1894                                    finderArgs, this);
1895    
1896                    if (count == null) {
1897                            StringBundler query = new StringBundler(3);
1898    
1899                            query.append(_SQL_COUNT_RESOURCEBLOCK_WHERE);
1900    
1901                            query.append(_FINDER_COLUMN_C_N_COMPANYID_2);
1902    
1903                            if (name == null) {
1904                                    query.append(_FINDER_COLUMN_C_N_NAME_1);
1905                            }
1906                            else {
1907                                    if (name.equals(StringPool.BLANK)) {
1908                                            query.append(_FINDER_COLUMN_C_N_NAME_3);
1909                                    }
1910                                    else {
1911                                            query.append(_FINDER_COLUMN_C_N_NAME_2);
1912                                    }
1913                            }
1914    
1915                            String sql = query.toString();
1916    
1917                            Session session = null;
1918    
1919                            try {
1920                                    session = openSession();
1921    
1922                                    Query q = session.createQuery(sql);
1923    
1924                                    QueryPos qPos = QueryPos.getInstance(q);
1925    
1926                                    qPos.add(companyId);
1927    
1928                                    if (name != null) {
1929                                            qPos.add(name);
1930                                    }
1931    
1932                                    count = (Long)q.uniqueResult();
1933                            }
1934                            catch (Exception e) {
1935                                    throw processException(e);
1936                            }
1937                            finally {
1938                                    if (count == null) {
1939                                            count = Long.valueOf(0);
1940                                    }
1941    
1942                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_N, finderArgs,
1943                                            count);
1944    
1945                                    closeSession(session);
1946                            }
1947                    }
1948    
1949                    return count.intValue();
1950            }
1951    
1952            /**
1953             * Returns the number of resource blocks where companyId = &#63; and groupId = &#63; and name = &#63;.
1954             *
1955             * @param companyId the company ID
1956             * @param groupId the group ID
1957             * @param name the name
1958             * @return the number of matching resource blocks
1959             * @throws SystemException if a system exception occurred
1960             */
1961            public int countByC_G_N(long companyId, long groupId, String name)
1962                    throws SystemException {
1963                    Object[] finderArgs = new Object[] { companyId, groupId, name };
1964    
1965                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_G_N,
1966                                    finderArgs, this);
1967    
1968                    if (count == null) {
1969                            StringBundler query = new StringBundler(4);
1970    
1971                            query.append(_SQL_COUNT_RESOURCEBLOCK_WHERE);
1972    
1973                            query.append(_FINDER_COLUMN_C_G_N_COMPANYID_2);
1974    
1975                            query.append(_FINDER_COLUMN_C_G_N_GROUPID_2);
1976    
1977                            if (name == null) {
1978                                    query.append(_FINDER_COLUMN_C_G_N_NAME_1);
1979                            }
1980                            else {
1981                                    if (name.equals(StringPool.BLANK)) {
1982                                            query.append(_FINDER_COLUMN_C_G_N_NAME_3);
1983                                    }
1984                                    else {
1985                                            query.append(_FINDER_COLUMN_C_G_N_NAME_2);
1986                                    }
1987                            }
1988    
1989                            String sql = query.toString();
1990    
1991                            Session session = null;
1992    
1993                            try {
1994                                    session = openSession();
1995    
1996                                    Query q = session.createQuery(sql);
1997    
1998                                    QueryPos qPos = QueryPos.getInstance(q);
1999    
2000                                    qPos.add(companyId);
2001    
2002                                    qPos.add(groupId);
2003    
2004                                    if (name != null) {
2005                                            qPos.add(name);
2006                                    }
2007    
2008                                    count = (Long)q.uniqueResult();
2009                            }
2010                            catch (Exception e) {
2011                                    throw processException(e);
2012                            }
2013                            finally {
2014                                    if (count == null) {
2015                                            count = Long.valueOf(0);
2016                                    }
2017    
2018                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_G_N,
2019                                            finderArgs, count);
2020    
2021                                    closeSession(session);
2022                            }
2023                    }
2024    
2025                    return count.intValue();
2026            }
2027    
2028            /**
2029             * Returns the number of resource blocks where companyId = &#63; and groupId = &#63; and name = &#63; and permissionsHash = &#63;.
2030             *
2031             * @param companyId the company ID
2032             * @param groupId the group ID
2033             * @param name the name
2034             * @param permissionsHash the permissions hash
2035             * @return the number of matching resource blocks
2036             * @throws SystemException if a system exception occurred
2037             */
2038            public int countByC_G_N_P(long companyId, long groupId, String name,
2039                    String permissionsHash) throws SystemException {
2040                    Object[] finderArgs = new Object[] {
2041                                    companyId, groupId, name, permissionsHash
2042                            };
2043    
2044                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_G_N_P,
2045                                    finderArgs, this);
2046    
2047                    if (count == null) {
2048                            StringBundler query = new StringBundler(5);
2049    
2050                            query.append(_SQL_COUNT_RESOURCEBLOCK_WHERE);
2051    
2052                            query.append(_FINDER_COLUMN_C_G_N_P_COMPANYID_2);
2053    
2054                            query.append(_FINDER_COLUMN_C_G_N_P_GROUPID_2);
2055    
2056                            if (name == null) {
2057                                    query.append(_FINDER_COLUMN_C_G_N_P_NAME_1);
2058                            }
2059                            else {
2060                                    if (name.equals(StringPool.BLANK)) {
2061                                            query.append(_FINDER_COLUMN_C_G_N_P_NAME_3);
2062                                    }
2063                                    else {
2064                                            query.append(_FINDER_COLUMN_C_G_N_P_NAME_2);
2065                                    }
2066                            }
2067    
2068                            if (permissionsHash == null) {
2069                                    query.append(_FINDER_COLUMN_C_G_N_P_PERMISSIONSHASH_1);
2070                            }
2071                            else {
2072                                    if (permissionsHash.equals(StringPool.BLANK)) {
2073                                            query.append(_FINDER_COLUMN_C_G_N_P_PERMISSIONSHASH_3);
2074                                    }
2075                                    else {
2076                                            query.append(_FINDER_COLUMN_C_G_N_P_PERMISSIONSHASH_2);
2077                                    }
2078                            }
2079    
2080                            String sql = query.toString();
2081    
2082                            Session session = null;
2083    
2084                            try {
2085                                    session = openSession();
2086    
2087                                    Query q = session.createQuery(sql);
2088    
2089                                    QueryPos qPos = QueryPos.getInstance(q);
2090    
2091                                    qPos.add(companyId);
2092    
2093                                    qPos.add(groupId);
2094    
2095                                    if (name != null) {
2096                                            qPos.add(name);
2097                                    }
2098    
2099                                    if (permissionsHash != null) {
2100                                            qPos.add(permissionsHash);
2101                                    }
2102    
2103                                    count = (Long)q.uniqueResult();
2104                            }
2105                            catch (Exception e) {
2106                                    throw processException(e);
2107                            }
2108                            finally {
2109                                    if (count == null) {
2110                                            count = Long.valueOf(0);
2111                                    }
2112    
2113                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_G_N_P,
2114                                            finderArgs, count);
2115    
2116                                    closeSession(session);
2117                            }
2118                    }
2119    
2120                    return count.intValue();
2121            }
2122    
2123            /**
2124             * Returns the number of resource blocks.
2125             *
2126             * @return the number of resource blocks
2127             * @throws SystemException if a system exception occurred
2128             */
2129            public int countAll() throws SystemException {
2130                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2131                                    FINDER_ARGS_EMPTY, this);
2132    
2133                    if (count == null) {
2134                            Session session = null;
2135    
2136                            try {
2137                                    session = openSession();
2138    
2139                                    Query q = session.createQuery(_SQL_COUNT_RESOURCEBLOCK);
2140    
2141                                    count = (Long)q.uniqueResult();
2142                            }
2143                            catch (Exception e) {
2144                                    throw processException(e);
2145                            }
2146                            finally {
2147                                    if (count == null) {
2148                                            count = Long.valueOf(0);
2149                                    }
2150    
2151                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
2152                                            FINDER_ARGS_EMPTY, count);
2153    
2154                                    closeSession(session);
2155                            }
2156                    }
2157    
2158                    return count.intValue();
2159            }
2160    
2161            /**
2162             * Initializes the resource block persistence.
2163             */
2164            public void afterPropertiesSet() {
2165                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2166                                            com.liferay.portal.util.PropsUtil.get(
2167                                                    "value.object.listener.com.liferay.portal.model.ResourceBlock")));
2168    
2169                    if (listenerClassNames.length > 0) {
2170                            try {
2171                                    List<ModelListener<ResourceBlock>> listenersList = new ArrayList<ModelListener<ResourceBlock>>();
2172    
2173                                    for (String listenerClassName : listenerClassNames) {
2174                                            Class<?> clazz = getClass();
2175    
2176                                            listenersList.add((ModelListener<ResourceBlock>)InstanceFactory.newInstance(
2177                                                            clazz.getClassLoader(), listenerClassName));
2178                                    }
2179    
2180                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2181                            }
2182                            catch (Exception e) {
2183                                    _log.error(e);
2184                            }
2185                    }
2186            }
2187    
2188            public void destroy() {
2189                    EntityCacheUtil.removeCache(ResourceBlockImpl.class.getName());
2190                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2191                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2192            }
2193    
2194            @BeanReference(type = AccountPersistence.class)
2195            protected AccountPersistence accountPersistence;
2196            @BeanReference(type = AddressPersistence.class)
2197            protected AddressPersistence addressPersistence;
2198            @BeanReference(type = BrowserTrackerPersistence.class)
2199            protected BrowserTrackerPersistence browserTrackerPersistence;
2200            @BeanReference(type = ClassNamePersistence.class)
2201            protected ClassNamePersistence classNamePersistence;
2202            @BeanReference(type = ClusterGroupPersistence.class)
2203            protected ClusterGroupPersistence clusterGroupPersistence;
2204            @BeanReference(type = CompanyPersistence.class)
2205            protected CompanyPersistence companyPersistence;
2206            @BeanReference(type = ContactPersistence.class)
2207            protected ContactPersistence contactPersistence;
2208            @BeanReference(type = CountryPersistence.class)
2209            protected CountryPersistence countryPersistence;
2210            @BeanReference(type = EmailAddressPersistence.class)
2211            protected EmailAddressPersistence emailAddressPersistence;
2212            @BeanReference(type = GroupPersistence.class)
2213            protected GroupPersistence groupPersistence;
2214            @BeanReference(type = ImagePersistence.class)
2215            protected ImagePersistence imagePersistence;
2216            @BeanReference(type = LayoutPersistence.class)
2217            protected LayoutPersistence layoutPersistence;
2218            @BeanReference(type = LayoutBranchPersistence.class)
2219            protected LayoutBranchPersistence layoutBranchPersistence;
2220            @BeanReference(type = LayoutPrototypePersistence.class)
2221            protected LayoutPrototypePersistence layoutPrototypePersistence;
2222            @BeanReference(type = LayoutRevisionPersistence.class)
2223            protected LayoutRevisionPersistence layoutRevisionPersistence;
2224            @BeanReference(type = LayoutSetPersistence.class)
2225            protected LayoutSetPersistence layoutSetPersistence;
2226            @BeanReference(type = LayoutSetBranchPersistence.class)
2227            protected LayoutSetBranchPersistence layoutSetBranchPersistence;
2228            @BeanReference(type = LayoutSetPrototypePersistence.class)
2229            protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
2230            @BeanReference(type = ListTypePersistence.class)
2231            protected ListTypePersistence listTypePersistence;
2232            @BeanReference(type = LockPersistence.class)
2233            protected LockPersistence lockPersistence;
2234            @BeanReference(type = MembershipRequestPersistence.class)
2235            protected MembershipRequestPersistence membershipRequestPersistence;
2236            @BeanReference(type = OrganizationPersistence.class)
2237            protected OrganizationPersistence organizationPersistence;
2238            @BeanReference(type = OrgGroupPermissionPersistence.class)
2239            protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
2240            @BeanReference(type = OrgGroupRolePersistence.class)
2241            protected OrgGroupRolePersistence orgGroupRolePersistence;
2242            @BeanReference(type = OrgLaborPersistence.class)
2243            protected OrgLaborPersistence orgLaborPersistence;
2244            @BeanReference(type = PasswordPolicyPersistence.class)
2245            protected PasswordPolicyPersistence passwordPolicyPersistence;
2246            @BeanReference(type = PasswordPolicyRelPersistence.class)
2247            protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
2248            @BeanReference(type = PasswordTrackerPersistence.class)
2249            protected PasswordTrackerPersistence passwordTrackerPersistence;
2250            @BeanReference(type = PermissionPersistence.class)
2251            protected PermissionPersistence permissionPersistence;
2252            @BeanReference(type = PhonePersistence.class)
2253            protected PhonePersistence phonePersistence;
2254            @BeanReference(type = PluginSettingPersistence.class)
2255            protected PluginSettingPersistence pluginSettingPersistence;
2256            @BeanReference(type = PortalPreferencesPersistence.class)
2257            protected PortalPreferencesPersistence portalPreferencesPersistence;
2258            @BeanReference(type = PortletPersistence.class)
2259            protected PortletPersistence portletPersistence;
2260            @BeanReference(type = PortletItemPersistence.class)
2261            protected PortletItemPersistence portletItemPersistence;
2262            @BeanReference(type = PortletPreferencesPersistence.class)
2263            protected PortletPreferencesPersistence portletPreferencesPersistence;
2264            @BeanReference(type = RegionPersistence.class)
2265            protected RegionPersistence regionPersistence;
2266            @BeanReference(type = ReleasePersistence.class)
2267            protected ReleasePersistence releasePersistence;
2268            @BeanReference(type = RepositoryPersistence.class)
2269            protected RepositoryPersistence repositoryPersistence;
2270            @BeanReference(type = RepositoryEntryPersistence.class)
2271            protected RepositoryEntryPersistence repositoryEntryPersistence;
2272            @BeanReference(type = ResourcePersistence.class)
2273            protected ResourcePersistence resourcePersistence;
2274            @BeanReference(type = ResourceActionPersistence.class)
2275            protected ResourceActionPersistence resourceActionPersistence;
2276            @BeanReference(type = ResourceBlockPersistence.class)
2277            protected ResourceBlockPersistence resourceBlockPersistence;
2278            @BeanReference(type = ResourceBlockPermissionPersistence.class)
2279            protected ResourceBlockPermissionPersistence resourceBlockPermissionPersistence;
2280            @BeanReference(type = ResourceCodePersistence.class)
2281            protected ResourceCodePersistence resourceCodePersistence;
2282            @BeanReference(type = ResourcePermissionPersistence.class)
2283            protected ResourcePermissionPersistence resourcePermissionPersistence;
2284            @BeanReference(type = ResourceTypePermissionPersistence.class)
2285            protected ResourceTypePermissionPersistence resourceTypePermissionPersistence;
2286            @BeanReference(type = RolePersistence.class)
2287            protected RolePersistence rolePersistence;
2288            @BeanReference(type = ServiceComponentPersistence.class)
2289            protected ServiceComponentPersistence serviceComponentPersistence;
2290            @BeanReference(type = ShardPersistence.class)
2291            protected ShardPersistence shardPersistence;
2292            @BeanReference(type = SubscriptionPersistence.class)
2293            protected SubscriptionPersistence subscriptionPersistence;
2294            @BeanReference(type = TeamPersistence.class)
2295            protected TeamPersistence teamPersistence;
2296            @BeanReference(type = TicketPersistence.class)
2297            protected TicketPersistence ticketPersistence;
2298            @BeanReference(type = UserPersistence.class)
2299            protected UserPersistence userPersistence;
2300            @BeanReference(type = UserGroupPersistence.class)
2301            protected UserGroupPersistence userGroupPersistence;
2302            @BeanReference(type = UserGroupGroupRolePersistence.class)
2303            protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
2304            @BeanReference(type = UserGroupRolePersistence.class)
2305            protected UserGroupRolePersistence userGroupRolePersistence;
2306            @BeanReference(type = UserIdMapperPersistence.class)
2307            protected UserIdMapperPersistence userIdMapperPersistence;
2308            @BeanReference(type = UserNotificationEventPersistence.class)
2309            protected UserNotificationEventPersistence userNotificationEventPersistence;
2310            @BeanReference(type = UserTrackerPersistence.class)
2311            protected UserTrackerPersistence userTrackerPersistence;
2312            @BeanReference(type = UserTrackerPathPersistence.class)
2313            protected UserTrackerPathPersistence userTrackerPathPersistence;
2314            @BeanReference(type = VirtualHostPersistence.class)
2315            protected VirtualHostPersistence virtualHostPersistence;
2316            @BeanReference(type = WebDAVPropsPersistence.class)
2317            protected WebDAVPropsPersistence webDAVPropsPersistence;
2318            @BeanReference(type = WebsitePersistence.class)
2319            protected WebsitePersistence websitePersistence;
2320            @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
2321            protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
2322            @BeanReference(type = WorkflowInstanceLinkPersistence.class)
2323            protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
2324            private static final String _SQL_SELECT_RESOURCEBLOCK = "SELECT resourceBlock FROM ResourceBlock resourceBlock";
2325            private static final String _SQL_SELECT_RESOURCEBLOCK_WHERE = "SELECT resourceBlock FROM ResourceBlock resourceBlock WHERE ";
2326            private static final String _SQL_COUNT_RESOURCEBLOCK = "SELECT COUNT(resourceBlock) FROM ResourceBlock resourceBlock";
2327            private static final String _SQL_COUNT_RESOURCEBLOCK_WHERE = "SELECT COUNT(resourceBlock) FROM ResourceBlock resourceBlock WHERE ";
2328            private static final String _FINDER_COLUMN_C_N_COMPANYID_2 = "resourceBlock.companyId = ? AND ";
2329            private static final String _FINDER_COLUMN_C_N_NAME_1 = "resourceBlock.name IS NULL";
2330            private static final String _FINDER_COLUMN_C_N_NAME_2 = "resourceBlock.name = ?";
2331            private static final String _FINDER_COLUMN_C_N_NAME_3 = "(resourceBlock.name IS NULL OR resourceBlock.name = ?)";
2332            private static final String _FINDER_COLUMN_C_G_N_COMPANYID_2 = "resourceBlock.companyId = ? AND ";
2333            private static final String _FINDER_COLUMN_C_G_N_GROUPID_2 = "resourceBlock.groupId = ? AND ";
2334            private static final String _FINDER_COLUMN_C_G_N_NAME_1 = "resourceBlock.name IS NULL";
2335            private static final String _FINDER_COLUMN_C_G_N_NAME_2 = "resourceBlock.name = ?";
2336            private static final String _FINDER_COLUMN_C_G_N_NAME_3 = "(resourceBlock.name IS NULL OR resourceBlock.name = ?)";
2337            private static final String _FINDER_COLUMN_C_G_N_P_COMPANYID_2 = "resourceBlock.companyId = ? AND ";
2338            private static final String _FINDER_COLUMN_C_G_N_P_GROUPID_2 = "resourceBlock.groupId = ? AND ";
2339            private static final String _FINDER_COLUMN_C_G_N_P_NAME_1 = "resourceBlock.name IS NULL AND ";
2340            private static final String _FINDER_COLUMN_C_G_N_P_NAME_2 = "resourceBlock.name = ? AND ";
2341            private static final String _FINDER_COLUMN_C_G_N_P_NAME_3 = "(resourceBlock.name IS NULL OR resourceBlock.name = ?) AND ";
2342            private static final String _FINDER_COLUMN_C_G_N_P_PERMISSIONSHASH_1 = "resourceBlock.permissionsHash IS NULL";
2343            private static final String _FINDER_COLUMN_C_G_N_P_PERMISSIONSHASH_2 = "resourceBlock.permissionsHash = ?";
2344            private static final String _FINDER_COLUMN_C_G_N_P_PERMISSIONSHASH_3 = "(resourceBlock.permissionsHash IS NULL OR resourceBlock.permissionsHash = ?)";
2345            private static final String _ORDER_BY_ENTITY_ALIAS = "resourceBlock.";
2346            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ResourceBlock exists with the primary key ";
2347            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ResourceBlock exists with the key {";
2348            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
2349            private static Log _log = LogFactoryUtil.getLog(ResourceBlockPersistenceImpl.class);
2350            private static ResourceBlock _nullResourceBlock = new ResourceBlockImpl() {
2351                            @Override
2352                            public Object clone() {
2353                                    return this;
2354                            }
2355    
2356                            @Override
2357                            public CacheModel<ResourceBlock> toCacheModel() {
2358                                    return _nullResourceBlockCacheModel;
2359                            }
2360                    };
2361    
2362            private static CacheModel<ResourceBlock> _nullResourceBlockCacheModel = new CacheModel<ResourceBlock>() {
2363                            public ResourceBlock toEntityModel() {
2364                                    return _nullResourceBlock;
2365                            }
2366                    };
2367    }