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