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