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