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