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