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