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