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