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.NoSuchOrgGroupRoleException;
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.model.CacheModel;
036    import com.liferay.portal.model.MVCCModel;
037    import com.liferay.portal.model.OrgGroupRole;
038    import com.liferay.portal.model.impl.OrgGroupRoleImpl;
039    import com.liferay.portal.model.impl.OrgGroupRoleModelImpl;
040    import com.liferay.portal.service.persistence.CompanyProvider;
041    import com.liferay.portal.service.persistence.CompanyProviderWrapper;
042    import com.liferay.portal.service.persistence.OrgGroupRolePK;
043    import com.liferay.portal.service.persistence.OrgGroupRolePersistence;
044    
045    import java.io.Serializable;
046    
047    import java.util.Collections;
048    import java.util.HashMap;
049    import java.util.List;
050    import java.util.Map;
051    import java.util.Set;
052    
053    /**
054     * The persistence implementation for the org group role service.
055     *
056     * <p>
057     * Caching information and settings can be found in <code>portal.properties</code>
058     * </p>
059     *
060     * @author Brian Wing Shun Chan
061     * @see OrgGroupRolePersistence
062     * @see com.liferay.portal.service.persistence.OrgGroupRoleUtil
063     * @generated
064     */
065    @ProviderType
066    public class OrgGroupRolePersistenceImpl extends BasePersistenceImpl<OrgGroupRole>
067            implements OrgGroupRolePersistence {
068            /*
069             * NOTE FOR DEVELOPERS:
070             *
071             * Never modify or reference this class directly. Always use {@link OrgGroupRoleUtil} to access the org group role persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
072             */
073            public static final String FINDER_CLASS_NAME_ENTITY = OrgGroupRoleImpl.class.getName();
074            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
075                    ".List1";
076            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
077                    ".List2";
078            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
079                            OrgGroupRoleModelImpl.FINDER_CACHE_ENABLED, OrgGroupRoleImpl.class,
080                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
081            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
082                            OrgGroupRoleModelImpl.FINDER_CACHE_ENABLED, OrgGroupRoleImpl.class,
083                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
084            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
085                            OrgGroupRoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
086                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
087            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
088                            OrgGroupRoleModelImpl.FINDER_CACHE_ENABLED, OrgGroupRoleImpl.class,
089                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByGroupId",
090                            new String[] {
091                                    Long.class.getName(),
092                                    
093                            Integer.class.getName(), Integer.class.getName(),
094                                    OrderByComparator.class.getName()
095                            });
096            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
097                    new FinderPath(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
098                            OrgGroupRoleModelImpl.FINDER_CACHE_ENABLED, OrgGroupRoleImpl.class,
099                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
100                            new String[] { Long.class.getName() },
101                            OrgGroupRoleModelImpl.GROUPID_COLUMN_BITMASK);
102            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
103                            OrgGroupRoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
104                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
105                            new String[] { Long.class.getName() });
106    
107            /**
108             * Returns all the org group roles where groupId = &#63;.
109             *
110             * @param groupId the group ID
111             * @return the matching org group roles
112             */
113            @Override
114            public List<OrgGroupRole> findByGroupId(long groupId) {
115                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
116            }
117    
118            /**
119             * Returns a range of all the org group roles where groupId = &#63;.
120             *
121             * <p>
122             * 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 OrgGroupRoleModelImpl}. 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.
123             * </p>
124             *
125             * @param groupId the group ID
126             * @param start the lower bound of the range of org group roles
127             * @param end the upper bound of the range of org group roles (not inclusive)
128             * @return the range of matching org group roles
129             */
130            @Override
131            public List<OrgGroupRole> findByGroupId(long groupId, int start, int end) {
132                    return findByGroupId(groupId, start, end, null);
133            }
134    
135            /**
136             * Returns an ordered range of all the org group roles where groupId = &#63;.
137             *
138             * <p>
139             * 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 OrgGroupRoleModelImpl}. 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.
140             * </p>
141             *
142             * @param groupId the group ID
143             * @param start the lower bound of the range of org group roles
144             * @param end the upper bound of the range of org group roles (not inclusive)
145             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
146             * @return the ordered range of matching org group roles
147             */
148            @Override
149            public List<OrgGroupRole> findByGroupId(long groupId, int start, int end,
150                    OrderByComparator<OrgGroupRole> orderByComparator) {
151                    return findByGroupId(groupId, start, end, orderByComparator, true);
152            }
153    
154            /**
155             * Returns an ordered range of all the org group roles where groupId = &#63;.
156             *
157             * <p>
158             * 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 OrgGroupRoleModelImpl}. 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.
159             * </p>
160             *
161             * @param groupId the group ID
162             * @param start the lower bound of the range of org group roles
163             * @param end the upper bound of the range of org group roles (not inclusive)
164             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
165             * @param retrieveFromCache whether to retrieve from the finder cache
166             * @return the ordered range of matching org group roles
167             */
168            @Override
169            public List<OrgGroupRole> findByGroupId(long groupId, int start, int end,
170                    OrderByComparator<OrgGroupRole> orderByComparator,
171                    boolean retrieveFromCache) {
172                    boolean pagination = true;
173                    FinderPath finderPath = null;
174                    Object[] finderArgs = null;
175    
176                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
177                                    (orderByComparator == null)) {
178                            pagination = false;
179                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
180                            finderArgs = new Object[] { groupId };
181                    }
182                    else {
183                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
184                            finderArgs = new Object[] { groupId, start, end, orderByComparator };
185                    }
186    
187                    List<OrgGroupRole> list = null;
188    
189                    if (retrieveFromCache) {
190                            list = (List<OrgGroupRole>)finderCache.getResult(finderPath,
191                                            finderArgs, this);
192    
193                            if ((list != null) && !list.isEmpty()) {
194                                    for (OrgGroupRole orgGroupRole : list) {
195                                            if ((groupId != orgGroupRole.getGroupId())) {
196                                                    list = null;
197    
198                                                    break;
199                                            }
200                                    }
201                            }
202                    }
203    
204                    if (list == null) {
205                            StringBundler query = null;
206    
207                            if (orderByComparator != null) {
208                                    query = new StringBundler(3 +
209                                                    (orderByComparator.getOrderByFields().length * 3));
210                            }
211                            else {
212                                    query = new StringBundler(3);
213                            }
214    
215                            query.append(_SQL_SELECT_ORGGROUPROLE_WHERE);
216    
217                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
218    
219                            if (orderByComparator != null) {
220                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
221                                            orderByComparator);
222                            }
223                            else
224                             if (pagination) {
225                                    query.append(OrgGroupRoleModelImpl.ORDER_BY_JPQL);
226                            }
227    
228                            String sql = query.toString();
229    
230                            Session session = null;
231    
232                            try {
233                                    session = openSession();
234    
235                                    Query q = session.createQuery(sql);
236    
237                                    QueryPos qPos = QueryPos.getInstance(q);
238    
239                                    qPos.add(groupId);
240    
241                                    if (!pagination) {
242                                            list = (List<OrgGroupRole>)QueryUtil.list(q, getDialect(),
243                                                            start, end, false);
244    
245                                            Collections.sort(list);
246    
247                                            list = Collections.unmodifiableList(list);
248                                    }
249                                    else {
250                                            list = (List<OrgGroupRole>)QueryUtil.list(q, getDialect(),
251                                                            start, end);
252                                    }
253    
254                                    cacheResult(list);
255    
256                                    finderCache.putResult(finderPath, finderArgs, list);
257                            }
258                            catch (Exception e) {
259                                    finderCache.removeResult(finderPath, finderArgs);
260    
261                                    throw processException(e);
262                            }
263                            finally {
264                                    closeSession(session);
265                            }
266                    }
267    
268                    return list;
269            }
270    
271            /**
272             * Returns the first org group role in the ordered set where groupId = &#63;.
273             *
274             * @param groupId the group ID
275             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
276             * @return the first matching org group role
277             * @throws NoSuchOrgGroupRoleException if a matching org group role could not be found
278             */
279            @Override
280            public OrgGroupRole findByGroupId_First(long groupId,
281                    OrderByComparator<OrgGroupRole> orderByComparator)
282                    throws NoSuchOrgGroupRoleException {
283                    OrgGroupRole orgGroupRole = fetchByGroupId_First(groupId,
284                                    orderByComparator);
285    
286                    if (orgGroupRole != null) {
287                            return orgGroupRole;
288                    }
289    
290                    StringBundler msg = new StringBundler(4);
291    
292                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
293    
294                    msg.append("groupId=");
295                    msg.append(groupId);
296    
297                    msg.append(StringPool.CLOSE_CURLY_BRACE);
298    
299                    throw new NoSuchOrgGroupRoleException(msg.toString());
300            }
301    
302            /**
303             * Returns the first org group role in the ordered set where groupId = &#63;.
304             *
305             * @param groupId the group ID
306             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
307             * @return the first matching org group role, or <code>null</code> if a matching org group role could not be found
308             */
309            @Override
310            public OrgGroupRole fetchByGroupId_First(long groupId,
311                    OrderByComparator<OrgGroupRole> orderByComparator) {
312                    List<OrgGroupRole> list = findByGroupId(groupId, 0, 1, orderByComparator);
313    
314                    if (!list.isEmpty()) {
315                            return list.get(0);
316                    }
317    
318                    return null;
319            }
320    
321            /**
322             * Returns the last org group role in the ordered set where groupId = &#63;.
323             *
324             * @param groupId the group ID
325             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
326             * @return the last matching org group role
327             * @throws NoSuchOrgGroupRoleException if a matching org group role could not be found
328             */
329            @Override
330            public OrgGroupRole findByGroupId_Last(long groupId,
331                    OrderByComparator<OrgGroupRole> orderByComparator)
332                    throws NoSuchOrgGroupRoleException {
333                    OrgGroupRole orgGroupRole = fetchByGroupId_Last(groupId,
334                                    orderByComparator);
335    
336                    if (orgGroupRole != null) {
337                            return orgGroupRole;
338                    }
339    
340                    StringBundler msg = new StringBundler(4);
341    
342                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
343    
344                    msg.append("groupId=");
345                    msg.append(groupId);
346    
347                    msg.append(StringPool.CLOSE_CURLY_BRACE);
348    
349                    throw new NoSuchOrgGroupRoleException(msg.toString());
350            }
351    
352            /**
353             * Returns the last org group role in the ordered set where groupId = &#63;.
354             *
355             * @param groupId the group ID
356             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
357             * @return the last matching org group role, or <code>null</code> if a matching org group role could not be found
358             */
359            @Override
360            public OrgGroupRole fetchByGroupId_Last(long groupId,
361                    OrderByComparator<OrgGroupRole> orderByComparator) {
362                    int count = countByGroupId(groupId);
363    
364                    if (count == 0) {
365                            return null;
366                    }
367    
368                    List<OrgGroupRole> list = findByGroupId(groupId, count - 1, count,
369                                    orderByComparator);
370    
371                    if (!list.isEmpty()) {
372                            return list.get(0);
373                    }
374    
375                    return null;
376            }
377    
378            /**
379             * Returns the org group roles before and after the current org group role in the ordered set where groupId = &#63;.
380             *
381             * @param orgGroupRolePK the primary key of the current org group role
382             * @param groupId the group ID
383             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
384             * @return the previous, current, and next org group role
385             * @throws NoSuchOrgGroupRoleException if a org group role with the primary key could not be found
386             */
387            @Override
388            public OrgGroupRole[] findByGroupId_PrevAndNext(
389                    OrgGroupRolePK orgGroupRolePK, long groupId,
390                    OrderByComparator<OrgGroupRole> orderByComparator)
391                    throws NoSuchOrgGroupRoleException {
392                    OrgGroupRole orgGroupRole = findByPrimaryKey(orgGroupRolePK);
393    
394                    Session session = null;
395    
396                    try {
397                            session = openSession();
398    
399                            OrgGroupRole[] array = new OrgGroupRoleImpl[3];
400    
401                            array[0] = getByGroupId_PrevAndNext(session, orgGroupRole, groupId,
402                                            orderByComparator, true);
403    
404                            array[1] = orgGroupRole;
405    
406                            array[2] = getByGroupId_PrevAndNext(session, orgGroupRole, groupId,
407                                            orderByComparator, false);
408    
409                            return array;
410                    }
411                    catch (Exception e) {
412                            throw processException(e);
413                    }
414                    finally {
415                            closeSession(session);
416                    }
417            }
418    
419            protected OrgGroupRole getByGroupId_PrevAndNext(Session session,
420                    OrgGroupRole orgGroupRole, long groupId,
421                    OrderByComparator<OrgGroupRole> orderByComparator, boolean previous) {
422                    StringBundler query = null;
423    
424                    if (orderByComparator != null) {
425                            query = new StringBundler(6 +
426                                            (orderByComparator.getOrderByFields().length * 6));
427                    }
428                    else {
429                            query = new StringBundler(3);
430                    }
431    
432                    query.append(_SQL_SELECT_ORGGROUPROLE_WHERE);
433    
434                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
435    
436                    if (orderByComparator != null) {
437                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
438    
439                            if (orderByConditionFields.length > 0) {
440                                    query.append(WHERE_AND);
441                            }
442    
443                            for (int i = 0; i < orderByConditionFields.length; i++) {
444                                    query.append(_ORDER_BY_ENTITY_ALIAS);
445                                    query.append(orderByConditionFields[i]);
446    
447                                    if ((i + 1) < orderByConditionFields.length) {
448                                            if (orderByComparator.isAscending() ^ previous) {
449                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
450                                            }
451                                            else {
452                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
453                                            }
454                                    }
455                                    else {
456                                            if (orderByComparator.isAscending() ^ previous) {
457                                                    query.append(WHERE_GREATER_THAN);
458                                            }
459                                            else {
460                                                    query.append(WHERE_LESSER_THAN);
461                                            }
462                                    }
463                            }
464    
465                            query.append(ORDER_BY_CLAUSE);
466    
467                            String[] orderByFields = orderByComparator.getOrderByFields();
468    
469                            for (int i = 0; i < orderByFields.length; i++) {
470                                    query.append(_ORDER_BY_ENTITY_ALIAS);
471                                    query.append(orderByFields[i]);
472    
473                                    if ((i + 1) < orderByFields.length) {
474                                            if (orderByComparator.isAscending() ^ previous) {
475                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
476                                            }
477                                            else {
478                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
479                                            }
480                                    }
481                                    else {
482                                            if (orderByComparator.isAscending() ^ previous) {
483                                                    query.append(ORDER_BY_ASC);
484                                            }
485                                            else {
486                                                    query.append(ORDER_BY_DESC);
487                                            }
488                                    }
489                            }
490                    }
491                    else {
492                            query.append(OrgGroupRoleModelImpl.ORDER_BY_JPQL);
493                    }
494    
495                    String sql = query.toString();
496    
497                    Query q = session.createQuery(sql);
498    
499                    q.setFirstResult(0);
500                    q.setMaxResults(2);
501    
502                    QueryPos qPos = QueryPos.getInstance(q);
503    
504                    qPos.add(groupId);
505    
506                    if (orderByComparator != null) {
507                            Object[] values = orderByComparator.getOrderByConditionValues(orgGroupRole);
508    
509                            for (Object value : values) {
510                                    qPos.add(value);
511                            }
512                    }
513    
514                    List<OrgGroupRole> list = q.list();
515    
516                    if (list.size() == 2) {
517                            return list.get(1);
518                    }
519                    else {
520                            return null;
521                    }
522            }
523    
524            /**
525             * Removes all the org group roles where groupId = &#63; from the database.
526             *
527             * @param groupId the group ID
528             */
529            @Override
530            public void removeByGroupId(long groupId) {
531                    for (OrgGroupRole orgGroupRole : findByGroupId(groupId,
532                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
533                            remove(orgGroupRole);
534                    }
535            }
536    
537            /**
538             * Returns the number of org group roles where groupId = &#63;.
539             *
540             * @param groupId the group ID
541             * @return the number of matching org group roles
542             */
543            @Override
544            public int countByGroupId(long groupId) {
545                    FinderPath finderPath = FINDER_PATH_COUNT_BY_GROUPID;
546    
547                    Object[] finderArgs = new Object[] { groupId };
548    
549                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
550    
551                    if (count == null) {
552                            StringBundler query = new StringBundler(2);
553    
554                            query.append(_SQL_COUNT_ORGGROUPROLE_WHERE);
555    
556                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
557    
558                            String sql = query.toString();
559    
560                            Session session = null;
561    
562                            try {
563                                    session = openSession();
564    
565                                    Query q = session.createQuery(sql);
566    
567                                    QueryPos qPos = QueryPos.getInstance(q);
568    
569                                    qPos.add(groupId);
570    
571                                    count = (Long)q.uniqueResult();
572    
573                                    finderCache.putResult(finderPath, finderArgs, count);
574                            }
575                            catch (Exception e) {
576                                    finderCache.removeResult(finderPath, finderArgs);
577    
578                                    throw processException(e);
579                            }
580                            finally {
581                                    closeSession(session);
582                            }
583                    }
584    
585                    return count.intValue();
586            }
587    
588            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "orgGroupRole.id.groupId = ?";
589            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_ROLEID = new FinderPath(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
590                            OrgGroupRoleModelImpl.FINDER_CACHE_ENABLED, OrgGroupRoleImpl.class,
591                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByRoleId",
592                            new String[] {
593                                    Long.class.getName(),
594                                    
595                            Integer.class.getName(), Integer.class.getName(),
596                                    OrderByComparator.class.getName()
597                            });
598            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ROLEID =
599                    new FinderPath(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
600                            OrgGroupRoleModelImpl.FINDER_CACHE_ENABLED, OrgGroupRoleImpl.class,
601                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByRoleId",
602                            new String[] { Long.class.getName() },
603                            OrgGroupRoleModelImpl.ROLEID_COLUMN_BITMASK);
604            public static final FinderPath FINDER_PATH_COUNT_BY_ROLEID = new FinderPath(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
605                            OrgGroupRoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
606                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByRoleId",
607                            new String[] { Long.class.getName() });
608    
609            /**
610             * Returns all the org group roles where roleId = &#63;.
611             *
612             * @param roleId the role ID
613             * @return the matching org group roles
614             */
615            @Override
616            public List<OrgGroupRole> findByRoleId(long roleId) {
617                    return findByRoleId(roleId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
618            }
619    
620            /**
621             * Returns a range of all the org group roles where roleId = &#63;.
622             *
623             * <p>
624             * 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 OrgGroupRoleModelImpl}. 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.
625             * </p>
626             *
627             * @param roleId the role ID
628             * @param start the lower bound of the range of org group roles
629             * @param end the upper bound of the range of org group roles (not inclusive)
630             * @return the range of matching org group roles
631             */
632            @Override
633            public List<OrgGroupRole> findByRoleId(long roleId, int start, int end) {
634                    return findByRoleId(roleId, start, end, null);
635            }
636    
637            /**
638             * Returns an ordered range of all the org group roles where roleId = &#63;.
639             *
640             * <p>
641             * 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 OrgGroupRoleModelImpl}. 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.
642             * </p>
643             *
644             * @param roleId the role ID
645             * @param start the lower bound of the range of org group roles
646             * @param end the upper bound of the range of org group roles (not inclusive)
647             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
648             * @return the ordered range of matching org group roles
649             */
650            @Override
651            public List<OrgGroupRole> findByRoleId(long roleId, int start, int end,
652                    OrderByComparator<OrgGroupRole> orderByComparator) {
653                    return findByRoleId(roleId, start, end, orderByComparator, true);
654            }
655    
656            /**
657             * Returns an ordered range of all the org group roles where roleId = &#63;.
658             *
659             * <p>
660             * 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 OrgGroupRoleModelImpl}. 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.
661             * </p>
662             *
663             * @param roleId the role ID
664             * @param start the lower bound of the range of org group roles
665             * @param end the upper bound of the range of org group roles (not inclusive)
666             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
667             * @param retrieveFromCache whether to retrieve from the finder cache
668             * @return the ordered range of matching org group roles
669             */
670            @Override
671            public List<OrgGroupRole> findByRoleId(long roleId, int start, int end,
672                    OrderByComparator<OrgGroupRole> orderByComparator,
673                    boolean retrieveFromCache) {
674                    boolean pagination = true;
675                    FinderPath finderPath = null;
676                    Object[] finderArgs = null;
677    
678                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
679                                    (orderByComparator == null)) {
680                            pagination = false;
681                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ROLEID;
682                            finderArgs = new Object[] { roleId };
683                    }
684                    else {
685                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_ROLEID;
686                            finderArgs = new Object[] { roleId, start, end, orderByComparator };
687                    }
688    
689                    List<OrgGroupRole> list = null;
690    
691                    if (retrieveFromCache) {
692                            list = (List<OrgGroupRole>)finderCache.getResult(finderPath,
693                                            finderArgs, this);
694    
695                            if ((list != null) && !list.isEmpty()) {
696                                    for (OrgGroupRole orgGroupRole : list) {
697                                            if ((roleId != orgGroupRole.getRoleId())) {
698                                                    list = null;
699    
700                                                    break;
701                                            }
702                                    }
703                            }
704                    }
705    
706                    if (list == null) {
707                            StringBundler query = null;
708    
709                            if (orderByComparator != null) {
710                                    query = new StringBundler(3 +
711                                                    (orderByComparator.getOrderByFields().length * 3));
712                            }
713                            else {
714                                    query = new StringBundler(3);
715                            }
716    
717                            query.append(_SQL_SELECT_ORGGROUPROLE_WHERE);
718    
719                            query.append(_FINDER_COLUMN_ROLEID_ROLEID_2);
720    
721                            if (orderByComparator != null) {
722                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
723                                            orderByComparator);
724                            }
725                            else
726                             if (pagination) {
727                                    query.append(OrgGroupRoleModelImpl.ORDER_BY_JPQL);
728                            }
729    
730                            String sql = query.toString();
731    
732                            Session session = null;
733    
734                            try {
735                                    session = openSession();
736    
737                                    Query q = session.createQuery(sql);
738    
739                                    QueryPos qPos = QueryPos.getInstance(q);
740    
741                                    qPos.add(roleId);
742    
743                                    if (!pagination) {
744                                            list = (List<OrgGroupRole>)QueryUtil.list(q, getDialect(),
745                                                            start, end, false);
746    
747                                            Collections.sort(list);
748    
749                                            list = Collections.unmodifiableList(list);
750                                    }
751                                    else {
752                                            list = (List<OrgGroupRole>)QueryUtil.list(q, getDialect(),
753                                                            start, end);
754                                    }
755    
756                                    cacheResult(list);
757    
758                                    finderCache.putResult(finderPath, finderArgs, list);
759                            }
760                            catch (Exception e) {
761                                    finderCache.removeResult(finderPath, finderArgs);
762    
763                                    throw processException(e);
764                            }
765                            finally {
766                                    closeSession(session);
767                            }
768                    }
769    
770                    return list;
771            }
772    
773            /**
774             * Returns the first org group role in the ordered set where roleId = &#63;.
775             *
776             * @param roleId the role ID
777             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
778             * @return the first matching org group role
779             * @throws NoSuchOrgGroupRoleException if a matching org group role could not be found
780             */
781            @Override
782            public OrgGroupRole findByRoleId_First(long roleId,
783                    OrderByComparator<OrgGroupRole> orderByComparator)
784                    throws NoSuchOrgGroupRoleException {
785                    OrgGroupRole orgGroupRole = fetchByRoleId_First(roleId,
786                                    orderByComparator);
787    
788                    if (orgGroupRole != null) {
789                            return orgGroupRole;
790                    }
791    
792                    StringBundler msg = new StringBundler(4);
793    
794                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
795    
796                    msg.append("roleId=");
797                    msg.append(roleId);
798    
799                    msg.append(StringPool.CLOSE_CURLY_BRACE);
800    
801                    throw new NoSuchOrgGroupRoleException(msg.toString());
802            }
803    
804            /**
805             * Returns the first org group role in the ordered set where roleId = &#63;.
806             *
807             * @param roleId the role ID
808             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
809             * @return the first matching org group role, or <code>null</code> if a matching org group role could not be found
810             */
811            @Override
812            public OrgGroupRole fetchByRoleId_First(long roleId,
813                    OrderByComparator<OrgGroupRole> orderByComparator) {
814                    List<OrgGroupRole> list = findByRoleId(roleId, 0, 1, orderByComparator);
815    
816                    if (!list.isEmpty()) {
817                            return list.get(0);
818                    }
819    
820                    return null;
821            }
822    
823            /**
824             * Returns the last org group role in the ordered set where roleId = &#63;.
825             *
826             * @param roleId the role ID
827             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
828             * @return the last matching org group role
829             * @throws NoSuchOrgGroupRoleException if a matching org group role could not be found
830             */
831            @Override
832            public OrgGroupRole findByRoleId_Last(long roleId,
833                    OrderByComparator<OrgGroupRole> orderByComparator)
834                    throws NoSuchOrgGroupRoleException {
835                    OrgGroupRole orgGroupRole = fetchByRoleId_Last(roleId, orderByComparator);
836    
837                    if (orgGroupRole != null) {
838                            return orgGroupRole;
839                    }
840    
841                    StringBundler msg = new StringBundler(4);
842    
843                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
844    
845                    msg.append("roleId=");
846                    msg.append(roleId);
847    
848                    msg.append(StringPool.CLOSE_CURLY_BRACE);
849    
850                    throw new NoSuchOrgGroupRoleException(msg.toString());
851            }
852    
853            /**
854             * Returns the last org group role in the ordered set where roleId = &#63;.
855             *
856             * @param roleId the role ID
857             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
858             * @return the last matching org group role, or <code>null</code> if a matching org group role could not be found
859             */
860            @Override
861            public OrgGroupRole fetchByRoleId_Last(long roleId,
862                    OrderByComparator<OrgGroupRole> orderByComparator) {
863                    int count = countByRoleId(roleId);
864    
865                    if (count == 0) {
866                            return null;
867                    }
868    
869                    List<OrgGroupRole> list = findByRoleId(roleId, count - 1, count,
870                                    orderByComparator);
871    
872                    if (!list.isEmpty()) {
873                            return list.get(0);
874                    }
875    
876                    return null;
877            }
878    
879            /**
880             * Returns the org group roles before and after the current org group role in the ordered set where roleId = &#63;.
881             *
882             * @param orgGroupRolePK the primary key of the current org group role
883             * @param roleId the role ID
884             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
885             * @return the previous, current, and next org group role
886             * @throws NoSuchOrgGroupRoleException if a org group role with the primary key could not be found
887             */
888            @Override
889            public OrgGroupRole[] findByRoleId_PrevAndNext(
890                    OrgGroupRolePK orgGroupRolePK, long roleId,
891                    OrderByComparator<OrgGroupRole> orderByComparator)
892                    throws NoSuchOrgGroupRoleException {
893                    OrgGroupRole orgGroupRole = findByPrimaryKey(orgGroupRolePK);
894    
895                    Session session = null;
896    
897                    try {
898                            session = openSession();
899    
900                            OrgGroupRole[] array = new OrgGroupRoleImpl[3];
901    
902                            array[0] = getByRoleId_PrevAndNext(session, orgGroupRole, roleId,
903                                            orderByComparator, true);
904    
905                            array[1] = orgGroupRole;
906    
907                            array[2] = getByRoleId_PrevAndNext(session, orgGroupRole, roleId,
908                                            orderByComparator, false);
909    
910                            return array;
911                    }
912                    catch (Exception e) {
913                            throw processException(e);
914                    }
915                    finally {
916                            closeSession(session);
917                    }
918            }
919    
920            protected OrgGroupRole getByRoleId_PrevAndNext(Session session,
921                    OrgGroupRole orgGroupRole, long roleId,
922                    OrderByComparator<OrgGroupRole> orderByComparator, boolean previous) {
923                    StringBundler query = null;
924    
925                    if (orderByComparator != null) {
926                            query = new StringBundler(6 +
927                                            (orderByComparator.getOrderByFields().length * 6));
928                    }
929                    else {
930                            query = new StringBundler(3);
931                    }
932    
933                    query.append(_SQL_SELECT_ORGGROUPROLE_WHERE);
934    
935                    query.append(_FINDER_COLUMN_ROLEID_ROLEID_2);
936    
937                    if (orderByComparator != null) {
938                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
939    
940                            if (orderByConditionFields.length > 0) {
941                                    query.append(WHERE_AND);
942                            }
943    
944                            for (int i = 0; i < orderByConditionFields.length; i++) {
945                                    query.append(_ORDER_BY_ENTITY_ALIAS);
946                                    query.append(orderByConditionFields[i]);
947    
948                                    if ((i + 1) < orderByConditionFields.length) {
949                                            if (orderByComparator.isAscending() ^ previous) {
950                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
951                                            }
952                                            else {
953                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
954                                            }
955                                    }
956                                    else {
957                                            if (orderByComparator.isAscending() ^ previous) {
958                                                    query.append(WHERE_GREATER_THAN);
959                                            }
960                                            else {
961                                                    query.append(WHERE_LESSER_THAN);
962                                            }
963                                    }
964                            }
965    
966                            query.append(ORDER_BY_CLAUSE);
967    
968                            String[] orderByFields = orderByComparator.getOrderByFields();
969    
970                            for (int i = 0; i < orderByFields.length; i++) {
971                                    query.append(_ORDER_BY_ENTITY_ALIAS);
972                                    query.append(orderByFields[i]);
973    
974                                    if ((i + 1) < orderByFields.length) {
975                                            if (orderByComparator.isAscending() ^ previous) {
976                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
977                                            }
978                                            else {
979                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
980                                            }
981                                    }
982                                    else {
983                                            if (orderByComparator.isAscending() ^ previous) {
984                                                    query.append(ORDER_BY_ASC);
985                                            }
986                                            else {
987                                                    query.append(ORDER_BY_DESC);
988                                            }
989                                    }
990                            }
991                    }
992                    else {
993                            query.append(OrgGroupRoleModelImpl.ORDER_BY_JPQL);
994                    }
995    
996                    String sql = query.toString();
997    
998                    Query q = session.createQuery(sql);
999    
1000                    q.setFirstResult(0);
1001                    q.setMaxResults(2);
1002    
1003                    QueryPos qPos = QueryPos.getInstance(q);
1004    
1005                    qPos.add(roleId);
1006    
1007                    if (orderByComparator != null) {
1008                            Object[] values = orderByComparator.getOrderByConditionValues(orgGroupRole);
1009    
1010                            for (Object value : values) {
1011                                    qPos.add(value);
1012                            }
1013                    }
1014    
1015                    List<OrgGroupRole> list = q.list();
1016    
1017                    if (list.size() == 2) {
1018                            return list.get(1);
1019                    }
1020                    else {
1021                            return null;
1022                    }
1023            }
1024    
1025            /**
1026             * Removes all the org group roles where roleId = &#63; from the database.
1027             *
1028             * @param roleId the role ID
1029             */
1030            @Override
1031            public void removeByRoleId(long roleId) {
1032                    for (OrgGroupRole orgGroupRole : findByRoleId(roleId,
1033                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1034                            remove(orgGroupRole);
1035                    }
1036            }
1037    
1038            /**
1039             * Returns the number of org group roles where roleId = &#63;.
1040             *
1041             * @param roleId the role ID
1042             * @return the number of matching org group roles
1043             */
1044            @Override
1045            public int countByRoleId(long roleId) {
1046                    FinderPath finderPath = FINDER_PATH_COUNT_BY_ROLEID;
1047    
1048                    Object[] finderArgs = new Object[] { roleId };
1049    
1050                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
1051    
1052                    if (count == null) {
1053                            StringBundler query = new StringBundler(2);
1054    
1055                            query.append(_SQL_COUNT_ORGGROUPROLE_WHERE);
1056    
1057                            query.append(_FINDER_COLUMN_ROLEID_ROLEID_2);
1058    
1059                            String sql = query.toString();
1060    
1061                            Session session = null;
1062    
1063                            try {
1064                                    session = openSession();
1065    
1066                                    Query q = session.createQuery(sql);
1067    
1068                                    QueryPos qPos = QueryPos.getInstance(q);
1069    
1070                                    qPos.add(roleId);
1071    
1072                                    count = (Long)q.uniqueResult();
1073    
1074                                    finderCache.putResult(finderPath, finderArgs, count);
1075                            }
1076                            catch (Exception e) {
1077                                    finderCache.removeResult(finderPath, finderArgs);
1078    
1079                                    throw processException(e);
1080                            }
1081                            finally {
1082                                    closeSession(session);
1083                            }
1084                    }
1085    
1086                    return count.intValue();
1087            }
1088    
1089            private static final String _FINDER_COLUMN_ROLEID_ROLEID_2 = "orgGroupRole.id.roleId = ?";
1090    
1091            public OrgGroupRolePersistenceImpl() {
1092                    setModelClass(OrgGroupRole.class);
1093            }
1094    
1095            /**
1096             * Caches the org group role in the entity cache if it is enabled.
1097             *
1098             * @param orgGroupRole the org group role
1099             */
1100            @Override
1101            public void cacheResult(OrgGroupRole orgGroupRole) {
1102                    entityCache.putResult(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
1103                            OrgGroupRoleImpl.class, orgGroupRole.getPrimaryKey(), orgGroupRole);
1104    
1105                    orgGroupRole.resetOriginalValues();
1106            }
1107    
1108            /**
1109             * Caches the org group roles in the entity cache if it is enabled.
1110             *
1111             * @param orgGroupRoles the org group roles
1112             */
1113            @Override
1114            public void cacheResult(List<OrgGroupRole> orgGroupRoles) {
1115                    for (OrgGroupRole orgGroupRole : orgGroupRoles) {
1116                            if (entityCache.getResult(
1117                                                    OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
1118                                                    OrgGroupRoleImpl.class, orgGroupRole.getPrimaryKey()) == null) {
1119                                    cacheResult(orgGroupRole);
1120                            }
1121                            else {
1122                                    orgGroupRole.resetOriginalValues();
1123                            }
1124                    }
1125            }
1126    
1127            /**
1128             * Clears the cache for all org group roles.
1129             *
1130             * <p>
1131             * The {@link EntityCache} and {@link FinderCache} are both cleared by this method.
1132             * </p>
1133             */
1134            @Override
1135            public void clearCache() {
1136                    entityCache.clearCache(OrgGroupRoleImpl.class);
1137    
1138                    finderCache.clearCache(FINDER_CLASS_NAME_ENTITY);
1139                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1140                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1141            }
1142    
1143            /**
1144             * Clears the cache for the org group role.
1145             *
1146             * <p>
1147             * The {@link EntityCache} and {@link FinderCache} are both cleared by this method.
1148             * </p>
1149             */
1150            @Override
1151            public void clearCache(OrgGroupRole orgGroupRole) {
1152                    entityCache.removeResult(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
1153                            OrgGroupRoleImpl.class, orgGroupRole.getPrimaryKey());
1154    
1155                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1156                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1157            }
1158    
1159            @Override
1160            public void clearCache(List<OrgGroupRole> orgGroupRoles) {
1161                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1162                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1163    
1164                    for (OrgGroupRole orgGroupRole : orgGroupRoles) {
1165                            entityCache.removeResult(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
1166                                    OrgGroupRoleImpl.class, orgGroupRole.getPrimaryKey());
1167                    }
1168            }
1169    
1170            /**
1171             * Creates a new org group role with the primary key. Does not add the org group role to the database.
1172             *
1173             * @param orgGroupRolePK the primary key for the new org group role
1174             * @return the new org group role
1175             */
1176            @Override
1177            public OrgGroupRole create(OrgGroupRolePK orgGroupRolePK) {
1178                    OrgGroupRole orgGroupRole = new OrgGroupRoleImpl();
1179    
1180                    orgGroupRole.setNew(true);
1181                    orgGroupRole.setPrimaryKey(orgGroupRolePK);
1182    
1183                    orgGroupRole.setCompanyId(companyProvider.getCompanyId());
1184    
1185                    return orgGroupRole;
1186            }
1187    
1188            /**
1189             * Removes the org group role with the primary key from the database. Also notifies the appropriate model listeners.
1190             *
1191             * @param orgGroupRolePK the primary key of the org group role
1192             * @return the org group role that was removed
1193             * @throws NoSuchOrgGroupRoleException if a org group role with the primary key could not be found
1194             */
1195            @Override
1196            public OrgGroupRole remove(OrgGroupRolePK orgGroupRolePK)
1197                    throws NoSuchOrgGroupRoleException {
1198                    return remove((Serializable)orgGroupRolePK);
1199            }
1200    
1201            /**
1202             * Removes the org group role with the primary key from the database. Also notifies the appropriate model listeners.
1203             *
1204             * @param primaryKey the primary key of the org group role
1205             * @return the org group role that was removed
1206             * @throws NoSuchOrgGroupRoleException if a org group role with the primary key could not be found
1207             */
1208            @Override
1209            public OrgGroupRole remove(Serializable primaryKey)
1210                    throws NoSuchOrgGroupRoleException {
1211                    Session session = null;
1212    
1213                    try {
1214                            session = openSession();
1215    
1216                            OrgGroupRole orgGroupRole = (OrgGroupRole)session.get(OrgGroupRoleImpl.class,
1217                                            primaryKey);
1218    
1219                            if (orgGroupRole == null) {
1220                                    if (_log.isWarnEnabled()) {
1221                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1222                                    }
1223    
1224                                    throw new NoSuchOrgGroupRoleException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1225                                            primaryKey);
1226                            }
1227    
1228                            return remove(orgGroupRole);
1229                    }
1230                    catch (NoSuchOrgGroupRoleException nsee) {
1231                            throw nsee;
1232                    }
1233                    catch (Exception e) {
1234                            throw processException(e);
1235                    }
1236                    finally {
1237                            closeSession(session);
1238                    }
1239            }
1240    
1241            @Override
1242            protected OrgGroupRole removeImpl(OrgGroupRole orgGroupRole) {
1243                    orgGroupRole = toUnwrappedModel(orgGroupRole);
1244    
1245                    Session session = null;
1246    
1247                    try {
1248                            session = openSession();
1249    
1250                            if (!session.contains(orgGroupRole)) {
1251                                    orgGroupRole = (OrgGroupRole)session.get(OrgGroupRoleImpl.class,
1252                                                    orgGroupRole.getPrimaryKeyObj());
1253                            }
1254    
1255                            if (orgGroupRole != null) {
1256                                    session.delete(orgGroupRole);
1257                            }
1258                    }
1259                    catch (Exception e) {
1260                            throw processException(e);
1261                    }
1262                    finally {
1263                            closeSession(session);
1264                    }
1265    
1266                    if (orgGroupRole != null) {
1267                            clearCache(orgGroupRole);
1268                    }
1269    
1270                    return orgGroupRole;
1271            }
1272    
1273            @Override
1274            public OrgGroupRole updateImpl(OrgGroupRole orgGroupRole) {
1275                    orgGroupRole = toUnwrappedModel(orgGroupRole);
1276    
1277                    boolean isNew = orgGroupRole.isNew();
1278    
1279                    OrgGroupRoleModelImpl orgGroupRoleModelImpl = (OrgGroupRoleModelImpl)orgGroupRole;
1280    
1281                    Session session = null;
1282    
1283                    try {
1284                            session = openSession();
1285    
1286                            if (orgGroupRole.isNew()) {
1287                                    session.save(orgGroupRole);
1288    
1289                                    orgGroupRole.setNew(false);
1290                            }
1291                            else {
1292                                    orgGroupRole = (OrgGroupRole)session.merge(orgGroupRole);
1293                            }
1294                    }
1295                    catch (Exception e) {
1296                            throw processException(e);
1297                    }
1298                    finally {
1299                            closeSession(session);
1300                    }
1301    
1302                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1303    
1304                    if (isNew || !OrgGroupRoleModelImpl.COLUMN_BITMASK_ENABLED) {
1305                            finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1306                    }
1307    
1308                    else {
1309                            if ((orgGroupRoleModelImpl.getColumnBitmask() &
1310                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
1311                                    Object[] args = new Object[] {
1312                                                    orgGroupRoleModelImpl.getOriginalGroupId()
1313                                            };
1314    
1315                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
1316                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
1317                                            args);
1318    
1319                                    args = new Object[] { orgGroupRoleModelImpl.getGroupId() };
1320    
1321                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
1322                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
1323                                            args);
1324                            }
1325    
1326                            if ((orgGroupRoleModelImpl.getColumnBitmask() &
1327                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ROLEID.getColumnBitmask()) != 0) {
1328                                    Object[] args = new Object[] {
1329                                                    orgGroupRoleModelImpl.getOriginalRoleId()
1330                                            };
1331    
1332                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_ROLEID, args);
1333                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ROLEID,
1334                                            args);
1335    
1336                                    args = new Object[] { orgGroupRoleModelImpl.getRoleId() };
1337    
1338                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_ROLEID, args);
1339                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ROLEID,
1340                                            args);
1341                            }
1342                    }
1343    
1344                    entityCache.putResult(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
1345                            OrgGroupRoleImpl.class, orgGroupRole.getPrimaryKey(), orgGroupRole,
1346                            false);
1347    
1348                    orgGroupRole.resetOriginalValues();
1349    
1350                    return orgGroupRole;
1351            }
1352    
1353            protected OrgGroupRole toUnwrappedModel(OrgGroupRole orgGroupRole) {
1354                    if (orgGroupRole instanceof OrgGroupRoleImpl) {
1355                            return orgGroupRole;
1356                    }
1357    
1358                    OrgGroupRoleImpl orgGroupRoleImpl = new OrgGroupRoleImpl();
1359    
1360                    orgGroupRoleImpl.setNew(orgGroupRole.isNew());
1361                    orgGroupRoleImpl.setPrimaryKey(orgGroupRole.getPrimaryKey());
1362    
1363                    orgGroupRoleImpl.setMvccVersion(orgGroupRole.getMvccVersion());
1364                    orgGroupRoleImpl.setOrganizationId(orgGroupRole.getOrganizationId());
1365                    orgGroupRoleImpl.setGroupId(orgGroupRole.getGroupId());
1366                    orgGroupRoleImpl.setRoleId(orgGroupRole.getRoleId());
1367                    orgGroupRoleImpl.setCompanyId(orgGroupRole.getCompanyId());
1368    
1369                    return orgGroupRoleImpl;
1370            }
1371    
1372            /**
1373             * Returns the org group role with the primary key or throws a {@link com.liferay.portal.exception.NoSuchModelException} if it could not be found.
1374             *
1375             * @param primaryKey the primary key of the org group role
1376             * @return the org group role
1377             * @throws NoSuchOrgGroupRoleException if a org group role with the primary key could not be found
1378             */
1379            @Override
1380            public OrgGroupRole findByPrimaryKey(Serializable primaryKey)
1381                    throws NoSuchOrgGroupRoleException {
1382                    OrgGroupRole orgGroupRole = fetchByPrimaryKey(primaryKey);
1383    
1384                    if (orgGroupRole == null) {
1385                            if (_log.isWarnEnabled()) {
1386                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1387                            }
1388    
1389                            throw new NoSuchOrgGroupRoleException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1390                                    primaryKey);
1391                    }
1392    
1393                    return orgGroupRole;
1394            }
1395    
1396            /**
1397             * Returns the org group role with the primary key or throws a {@link NoSuchOrgGroupRoleException} if it could not be found.
1398             *
1399             * @param orgGroupRolePK the primary key of the org group role
1400             * @return the org group role
1401             * @throws NoSuchOrgGroupRoleException if a org group role with the primary key could not be found
1402             */
1403            @Override
1404            public OrgGroupRole findByPrimaryKey(OrgGroupRolePK orgGroupRolePK)
1405                    throws NoSuchOrgGroupRoleException {
1406                    return findByPrimaryKey((Serializable)orgGroupRolePK);
1407            }
1408    
1409            /**
1410             * Returns the org group role with the primary key or returns <code>null</code> if it could not be found.
1411             *
1412             * @param primaryKey the primary key of the org group role
1413             * @return the org group role, or <code>null</code> if a org group role with the primary key could not be found
1414             */
1415            @Override
1416            public OrgGroupRole fetchByPrimaryKey(Serializable primaryKey) {
1417                    OrgGroupRole orgGroupRole = (OrgGroupRole)entityCache.getResult(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
1418                                    OrgGroupRoleImpl.class, primaryKey);
1419    
1420                    if (orgGroupRole == _nullOrgGroupRole) {
1421                            return null;
1422                    }
1423    
1424                    if (orgGroupRole == null) {
1425                            Session session = null;
1426    
1427                            try {
1428                                    session = openSession();
1429    
1430                                    orgGroupRole = (OrgGroupRole)session.get(OrgGroupRoleImpl.class,
1431                                                    primaryKey);
1432    
1433                                    if (orgGroupRole != null) {
1434                                            cacheResult(orgGroupRole);
1435                                    }
1436                                    else {
1437                                            entityCache.putResult(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
1438                                                    OrgGroupRoleImpl.class, primaryKey, _nullOrgGroupRole);
1439                                    }
1440                            }
1441                            catch (Exception e) {
1442                                    entityCache.removeResult(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
1443                                            OrgGroupRoleImpl.class, primaryKey);
1444    
1445                                    throw processException(e);
1446                            }
1447                            finally {
1448                                    closeSession(session);
1449                            }
1450                    }
1451    
1452                    return orgGroupRole;
1453            }
1454    
1455            /**
1456             * Returns the org group role with the primary key or returns <code>null</code> if it could not be found.
1457             *
1458             * @param orgGroupRolePK the primary key of the org group role
1459             * @return the org group role, or <code>null</code> if a org group role with the primary key could not be found
1460             */
1461            @Override
1462            public OrgGroupRole fetchByPrimaryKey(OrgGroupRolePK orgGroupRolePK) {
1463                    return fetchByPrimaryKey((Serializable)orgGroupRolePK);
1464            }
1465    
1466            @Override
1467            public Map<Serializable, OrgGroupRole> fetchByPrimaryKeys(
1468                    Set<Serializable> primaryKeys) {
1469                    if (primaryKeys.isEmpty()) {
1470                            return Collections.emptyMap();
1471                    }
1472    
1473                    Map<Serializable, OrgGroupRole> map = new HashMap<Serializable, OrgGroupRole>();
1474    
1475                    for (Serializable primaryKey : primaryKeys) {
1476                            OrgGroupRole orgGroupRole = fetchByPrimaryKey(primaryKey);
1477    
1478                            if (orgGroupRole != null) {
1479                                    map.put(primaryKey, orgGroupRole);
1480                            }
1481                    }
1482    
1483                    return map;
1484            }
1485    
1486            /**
1487             * Returns all the org group roles.
1488             *
1489             * @return the org group roles
1490             */
1491            @Override
1492            public List<OrgGroupRole> findAll() {
1493                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1494            }
1495    
1496            /**
1497             * Returns a range of all the org group roles.
1498             *
1499             * <p>
1500             * 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 OrgGroupRoleModelImpl}. 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.
1501             * </p>
1502             *
1503             * @param start the lower bound of the range of org group roles
1504             * @param end the upper bound of the range of org group roles (not inclusive)
1505             * @return the range of org group roles
1506             */
1507            @Override
1508            public List<OrgGroupRole> findAll(int start, int end) {
1509                    return findAll(start, end, null);
1510            }
1511    
1512            /**
1513             * Returns an ordered range of all the org group roles.
1514             *
1515             * <p>
1516             * 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 OrgGroupRoleModelImpl}. 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.
1517             * </p>
1518             *
1519             * @param start the lower bound of the range of org group roles
1520             * @param end the upper bound of the range of org group roles (not inclusive)
1521             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1522             * @return the ordered range of org group roles
1523             */
1524            @Override
1525            public List<OrgGroupRole> findAll(int start, int end,
1526                    OrderByComparator<OrgGroupRole> orderByComparator) {
1527                    return findAll(start, end, orderByComparator, true);
1528            }
1529    
1530            /**
1531             * Returns an ordered range of all the org group roles.
1532             *
1533             * <p>
1534             * 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 OrgGroupRoleModelImpl}. 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.
1535             * </p>
1536             *
1537             * @param start the lower bound of the range of org group roles
1538             * @param end the upper bound of the range of org group roles (not inclusive)
1539             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1540             * @param retrieveFromCache whether to retrieve from the finder cache
1541             * @return the ordered range of org group roles
1542             */
1543            @Override
1544            public List<OrgGroupRole> findAll(int start, int end,
1545                    OrderByComparator<OrgGroupRole> orderByComparator,
1546                    boolean retrieveFromCache) {
1547                    boolean pagination = true;
1548                    FinderPath finderPath = null;
1549                    Object[] finderArgs = null;
1550    
1551                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1552                                    (orderByComparator == null)) {
1553                            pagination = false;
1554                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1555                            finderArgs = FINDER_ARGS_EMPTY;
1556                    }
1557                    else {
1558                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1559                            finderArgs = new Object[] { start, end, orderByComparator };
1560                    }
1561    
1562                    List<OrgGroupRole> list = null;
1563    
1564                    if (retrieveFromCache) {
1565                            list = (List<OrgGroupRole>)finderCache.getResult(finderPath,
1566                                            finderArgs, this);
1567                    }
1568    
1569                    if (list == null) {
1570                            StringBundler query = null;
1571                            String sql = null;
1572    
1573                            if (orderByComparator != null) {
1574                                    query = new StringBundler(2 +
1575                                                    (orderByComparator.getOrderByFields().length * 3));
1576    
1577                                    query.append(_SQL_SELECT_ORGGROUPROLE);
1578    
1579                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1580                                            orderByComparator);
1581    
1582                                    sql = query.toString();
1583                            }
1584                            else {
1585                                    sql = _SQL_SELECT_ORGGROUPROLE;
1586    
1587                                    if (pagination) {
1588                                            sql = sql.concat(OrgGroupRoleModelImpl.ORDER_BY_JPQL);
1589                                    }
1590                            }
1591    
1592                            Session session = null;
1593    
1594                            try {
1595                                    session = openSession();
1596    
1597                                    Query q = session.createQuery(sql);
1598    
1599                                    if (!pagination) {
1600                                            list = (List<OrgGroupRole>)QueryUtil.list(q, getDialect(),
1601                                                            start, end, false);
1602    
1603                                            Collections.sort(list);
1604    
1605                                            list = Collections.unmodifiableList(list);
1606                                    }
1607                                    else {
1608                                            list = (List<OrgGroupRole>)QueryUtil.list(q, getDialect(),
1609                                                            start, end);
1610                                    }
1611    
1612                                    cacheResult(list);
1613    
1614                                    finderCache.putResult(finderPath, finderArgs, list);
1615                            }
1616                            catch (Exception e) {
1617                                    finderCache.removeResult(finderPath, finderArgs);
1618    
1619                                    throw processException(e);
1620                            }
1621                            finally {
1622                                    closeSession(session);
1623                            }
1624                    }
1625    
1626                    return list;
1627            }
1628    
1629            /**
1630             * Removes all the org group roles from the database.
1631             *
1632             */
1633            @Override
1634            public void removeAll() {
1635                    for (OrgGroupRole orgGroupRole : findAll()) {
1636                            remove(orgGroupRole);
1637                    }
1638            }
1639    
1640            /**
1641             * Returns the number of org group roles.
1642             *
1643             * @return the number of org group roles
1644             */
1645            @Override
1646            public int countAll() {
1647                    Long count = (Long)finderCache.getResult(FINDER_PATH_COUNT_ALL,
1648                                    FINDER_ARGS_EMPTY, this);
1649    
1650                    if (count == null) {
1651                            Session session = null;
1652    
1653                            try {
1654                                    session = openSession();
1655    
1656                                    Query q = session.createQuery(_SQL_COUNT_ORGGROUPROLE);
1657    
1658                                    count = (Long)q.uniqueResult();
1659    
1660                                    finderCache.putResult(FINDER_PATH_COUNT_ALL, FINDER_ARGS_EMPTY,
1661                                            count);
1662                            }
1663                            catch (Exception e) {
1664                                    finderCache.removeResult(FINDER_PATH_COUNT_ALL,
1665                                            FINDER_ARGS_EMPTY);
1666    
1667                                    throw processException(e);
1668                            }
1669                            finally {
1670                                    closeSession(session);
1671                            }
1672                    }
1673    
1674                    return count.intValue();
1675            }
1676    
1677            @Override
1678            protected Map<String, Integer> getTableColumnsMap() {
1679                    return OrgGroupRoleModelImpl.TABLE_COLUMNS_MAP;
1680            }
1681    
1682            /**
1683             * Initializes the org group role persistence.
1684             */
1685            public void afterPropertiesSet() {
1686            }
1687    
1688            public void destroy() {
1689                    entityCache.removeCache(OrgGroupRoleImpl.class.getName());
1690                    finderCache.removeCache(FINDER_CLASS_NAME_ENTITY);
1691                    finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1692                    finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1693            }
1694    
1695            @BeanReference(type = CompanyProviderWrapper.class)
1696            protected CompanyProvider companyProvider;
1697            protected EntityCache entityCache = EntityCacheUtil.getEntityCache();
1698            protected FinderCache finderCache = FinderCacheUtil.getFinderCache();
1699            private static final String _SQL_SELECT_ORGGROUPROLE = "SELECT orgGroupRole FROM OrgGroupRole orgGroupRole";
1700            private static final String _SQL_SELECT_ORGGROUPROLE_WHERE = "SELECT orgGroupRole FROM OrgGroupRole orgGroupRole WHERE ";
1701            private static final String _SQL_COUNT_ORGGROUPROLE = "SELECT COUNT(orgGroupRole) FROM OrgGroupRole orgGroupRole";
1702            private static final String _SQL_COUNT_ORGGROUPROLE_WHERE = "SELECT COUNT(orgGroupRole) FROM OrgGroupRole orgGroupRole WHERE ";
1703            private static final String _ORDER_BY_ENTITY_ALIAS = "orgGroupRole.";
1704            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No OrgGroupRole exists with the primary key ";
1705            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No OrgGroupRole exists with the key {";
1706            private static final Log _log = LogFactoryUtil.getLog(OrgGroupRolePersistenceImpl.class);
1707            private static final OrgGroupRole _nullOrgGroupRole = new OrgGroupRoleImpl() {
1708                            @Override
1709                            public Object clone() {
1710                                    return this;
1711                            }
1712    
1713                            @Override
1714                            public CacheModel<OrgGroupRole> toCacheModel() {
1715                                    return _nullOrgGroupRoleCacheModel;
1716                            }
1717                    };
1718    
1719            private static final CacheModel<OrgGroupRole> _nullOrgGroupRoleCacheModel = new NullCacheModel();
1720    
1721            private static class NullCacheModel implements CacheModel<OrgGroupRole>,
1722                    MVCCModel {
1723                    @Override
1724                    public long getMvccVersion() {
1725                            return -1;
1726                    }
1727    
1728                    @Override
1729                    public void setMvccVersion(long mvccVersion) {
1730                    }
1731    
1732                    @Override
1733                    public OrgGroupRole toEntityModel() {
1734                            return _nullOrgGroupRole;
1735                    }
1736            }
1737    }