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.NoSuchOrganizationException;
020    import com.liferay.portal.kernel.bean.BeanReference;
021    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
022    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
023    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
024    import com.liferay.portal.kernel.dao.orm.FinderPath;
025    import com.liferay.portal.kernel.dao.orm.Query;
026    import com.liferay.portal.kernel.dao.orm.QueryPos;
027    import com.liferay.portal.kernel.dao.orm.QueryUtil;
028    import com.liferay.portal.kernel.dao.orm.SQLQuery;
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.CharPool;
033    import com.liferay.portal.kernel.util.OrderByComparator;
034    import com.liferay.portal.kernel.util.SetUtil;
035    import com.liferay.portal.kernel.util.StringBundler;
036    import com.liferay.portal.kernel.util.StringPool;
037    import com.liferay.portal.kernel.util.StringUtil;
038    import com.liferay.portal.kernel.util.Validator;
039    import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
040    import com.liferay.portal.model.CacheModel;
041    import com.liferay.portal.model.MVCCModel;
042    import com.liferay.portal.model.Organization;
043    import com.liferay.portal.model.impl.OrganizationImpl;
044    import com.liferay.portal.model.impl.OrganizationModelImpl;
045    import com.liferay.portal.security.permission.InlineSQLHelperUtil;
046    import com.liferay.portal.service.persistence.GroupPersistence;
047    import com.liferay.portal.service.persistence.OrganizationPersistence;
048    import com.liferay.portal.service.persistence.UserPersistence;
049    
050    import java.io.Serializable;
051    
052    import java.util.Collections;
053    import java.util.HashMap;
054    import java.util.HashSet;
055    import java.util.Iterator;
056    import java.util.List;
057    import java.util.Map;
058    import java.util.Set;
059    
060    /**
061     * The persistence implementation for the organization service.
062     *
063     * <p>
064     * Caching information and settings can be found in <code>portal.properties</code>
065     * </p>
066     *
067     * @author Brian Wing Shun Chan
068     * @see OrganizationPersistence
069     * @see OrganizationUtil
070     * @generated
071     */
072    @ProviderType
073    public class OrganizationPersistenceImpl extends BasePersistenceImpl<Organization>
074            implements OrganizationPersistence {
075            /*
076             * NOTE FOR DEVELOPERS:
077             *
078             * Never modify or reference this class directly. Always use {@link OrganizationUtil} to access the organization persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
079             */
080            public static final String FINDER_CLASS_NAME_ENTITY = OrganizationImpl.class.getName();
081            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
082                    ".List1";
083            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
084                    ".List2";
085            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
086                            OrganizationModelImpl.FINDER_CACHE_ENABLED, OrganizationImpl.class,
087                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
088            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
089                            OrganizationModelImpl.FINDER_CACHE_ENABLED, OrganizationImpl.class,
090                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
091            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
092                            OrganizationModelImpl.FINDER_CACHE_ENABLED, Long.class,
093                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
094            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
095                            OrganizationModelImpl.FINDER_CACHE_ENABLED, OrganizationImpl.class,
096                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
097                            new String[] {
098                                    String.class.getName(),
099                                    
100                            Integer.class.getName(), Integer.class.getName(),
101                                    OrderByComparator.class.getName()
102                            });
103            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
104                            OrganizationModelImpl.FINDER_CACHE_ENABLED, OrganizationImpl.class,
105                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
106                            new String[] { String.class.getName() },
107                            OrganizationModelImpl.UUID_COLUMN_BITMASK |
108                            OrganizationModelImpl.NAME_COLUMN_BITMASK);
109            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
110                            OrganizationModelImpl.FINDER_CACHE_ENABLED, Long.class,
111                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
112                            new String[] { String.class.getName() });
113    
114            /**
115             * Returns all the organizations where uuid = &#63;.
116             *
117             * @param uuid the uuid
118             * @return the matching organizations
119             */
120            @Override
121            public List<Organization> findByUuid(String uuid) {
122                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
123            }
124    
125            /**
126             * Returns a range of all the organizations where uuid = &#63;.
127             *
128             * <p>
129             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.OrganizationModelImpl}. 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.
130             * </p>
131             *
132             * @param uuid the uuid
133             * @param start the lower bound of the range of organizations
134             * @param end the upper bound of the range of organizations (not inclusive)
135             * @return the range of matching organizations
136             */
137            @Override
138            public List<Organization> findByUuid(String uuid, int start, int end) {
139                    return findByUuid(uuid, start, end, null);
140            }
141    
142            /**
143             * Returns an ordered range of all the organizations where uuid = &#63;.
144             *
145             * <p>
146             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.OrganizationModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
147             * </p>
148             *
149             * @param uuid the uuid
150             * @param start the lower bound of the range of organizations
151             * @param end the upper bound of the range of organizations (not inclusive)
152             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
153             * @return the ordered range of matching organizations
154             */
155            @Override
156            public List<Organization> findByUuid(String uuid, int start, int end,
157                    OrderByComparator<Organization> orderByComparator) {
158                    boolean pagination = true;
159                    FinderPath finderPath = null;
160                    Object[] finderArgs = null;
161    
162                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
163                                    (orderByComparator == null)) {
164                            pagination = false;
165                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
166                            finderArgs = new Object[] { uuid };
167                    }
168                    else {
169                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
170                            finderArgs = new Object[] { uuid, start, end, orderByComparator };
171                    }
172    
173                    List<Organization> list = (List<Organization>)FinderCacheUtil.getResult(finderPath,
174                                    finderArgs, this);
175    
176                    if ((list != null) && !list.isEmpty()) {
177                            for (Organization organization : list) {
178                                    if (!Validator.equals(uuid, organization.getUuid())) {
179                                            list = null;
180    
181                                            break;
182                                    }
183                            }
184                    }
185    
186                    if (list == null) {
187                            StringBundler query = null;
188    
189                            if (orderByComparator != null) {
190                                    query = new StringBundler(3 +
191                                                    (orderByComparator.getOrderByFields().length * 3));
192                            }
193                            else {
194                                    query = new StringBundler(3);
195                            }
196    
197                            query.append(_SQL_SELECT_ORGANIZATION_WHERE);
198    
199                            boolean bindUuid = false;
200    
201                            if (uuid == null) {
202                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
203                            }
204                            else if (uuid.equals(StringPool.BLANK)) {
205                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
206                            }
207                            else {
208                                    bindUuid = true;
209    
210                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
211                            }
212    
213                            if (orderByComparator != null) {
214                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
215                                            orderByComparator);
216                            }
217                            else
218                             if (pagination) {
219                                    query.append(OrganizationModelImpl.ORDER_BY_JPQL);
220                            }
221    
222                            String sql = query.toString();
223    
224                            Session session = null;
225    
226                            try {
227                                    session = openSession();
228    
229                                    Query q = session.createQuery(sql);
230    
231                                    QueryPos qPos = QueryPos.getInstance(q);
232    
233                                    if (bindUuid) {
234                                            qPos.add(uuid);
235                                    }
236    
237                                    if (!pagination) {
238                                            list = (List<Organization>)QueryUtil.list(q, getDialect(),
239                                                            start, end, false);
240    
241                                            Collections.sort(list);
242    
243                                            list = Collections.unmodifiableList(list);
244                                    }
245                                    else {
246                                            list = (List<Organization>)QueryUtil.list(q, getDialect(),
247                                                            start, end);
248                                    }
249    
250                                    cacheResult(list);
251    
252                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
253                            }
254                            catch (Exception e) {
255                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
256    
257                                    throw processException(e);
258                            }
259                            finally {
260                                    closeSession(session);
261                            }
262                    }
263    
264                    return list;
265            }
266    
267            /**
268             * Returns the first organization in the ordered set where uuid = &#63;.
269             *
270             * @param uuid the uuid
271             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
272             * @return the first matching organization
273             * @throws com.liferay.portal.NoSuchOrganizationException if a matching organization could not be found
274             */
275            @Override
276            public Organization findByUuid_First(String uuid,
277                    OrderByComparator<Organization> orderByComparator)
278                    throws NoSuchOrganizationException {
279                    Organization organization = fetchByUuid_First(uuid, orderByComparator);
280    
281                    if (organization != null) {
282                            return organization;
283                    }
284    
285                    StringBundler msg = new StringBundler(4);
286    
287                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
288    
289                    msg.append("uuid=");
290                    msg.append(uuid);
291    
292                    msg.append(StringPool.CLOSE_CURLY_BRACE);
293    
294                    throw new NoSuchOrganizationException(msg.toString());
295            }
296    
297            /**
298             * Returns the first organization in the ordered set where uuid = &#63;.
299             *
300             * @param uuid the uuid
301             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
302             * @return the first matching organization, or <code>null</code> if a matching organization could not be found
303             */
304            @Override
305            public Organization fetchByUuid_First(String uuid,
306                    OrderByComparator<Organization> orderByComparator) {
307                    List<Organization> list = findByUuid(uuid, 0, 1, orderByComparator);
308    
309                    if (!list.isEmpty()) {
310                            return list.get(0);
311                    }
312    
313                    return null;
314            }
315    
316            /**
317             * Returns the last organization in the ordered set where uuid = &#63;.
318             *
319             * @param uuid the uuid
320             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
321             * @return the last matching organization
322             * @throws com.liferay.portal.NoSuchOrganizationException if a matching organization could not be found
323             */
324            @Override
325            public Organization findByUuid_Last(String uuid,
326                    OrderByComparator<Organization> orderByComparator)
327                    throws NoSuchOrganizationException {
328                    Organization organization = fetchByUuid_Last(uuid, orderByComparator);
329    
330                    if (organization != null) {
331                            return organization;
332                    }
333    
334                    StringBundler msg = new StringBundler(4);
335    
336                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
337    
338                    msg.append("uuid=");
339                    msg.append(uuid);
340    
341                    msg.append(StringPool.CLOSE_CURLY_BRACE);
342    
343                    throw new NoSuchOrganizationException(msg.toString());
344            }
345    
346            /**
347             * Returns the last organization in the ordered set where uuid = &#63;.
348             *
349             * @param uuid the uuid
350             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
351             * @return the last matching organization, or <code>null</code> if a matching organization could not be found
352             */
353            @Override
354            public Organization fetchByUuid_Last(String uuid,
355                    OrderByComparator<Organization> orderByComparator) {
356                    int count = countByUuid(uuid);
357    
358                    if (count == 0) {
359                            return null;
360                    }
361    
362                    List<Organization> list = findByUuid(uuid, count - 1, count,
363                                    orderByComparator);
364    
365                    if (!list.isEmpty()) {
366                            return list.get(0);
367                    }
368    
369                    return null;
370            }
371    
372            /**
373             * Returns the organizations before and after the current organization in the ordered set where uuid = &#63;.
374             *
375             * @param organizationId the primary key of the current organization
376             * @param uuid the uuid
377             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
378             * @return the previous, current, and next organization
379             * @throws com.liferay.portal.NoSuchOrganizationException if a organization with the primary key could not be found
380             */
381            @Override
382            public Organization[] findByUuid_PrevAndNext(long organizationId,
383                    String uuid, OrderByComparator<Organization> orderByComparator)
384                    throws NoSuchOrganizationException {
385                    Organization organization = findByPrimaryKey(organizationId);
386    
387                    Session session = null;
388    
389                    try {
390                            session = openSession();
391    
392                            Organization[] array = new OrganizationImpl[3];
393    
394                            array[0] = getByUuid_PrevAndNext(session, organization, uuid,
395                                            orderByComparator, true);
396    
397                            array[1] = organization;
398    
399                            array[2] = getByUuid_PrevAndNext(session, organization, uuid,
400                                            orderByComparator, false);
401    
402                            return array;
403                    }
404                    catch (Exception e) {
405                            throw processException(e);
406                    }
407                    finally {
408                            closeSession(session);
409                    }
410            }
411    
412            protected Organization getByUuid_PrevAndNext(Session session,
413                    Organization organization, String uuid,
414                    OrderByComparator<Organization> orderByComparator, boolean previous) {
415                    StringBundler query = null;
416    
417                    if (orderByComparator != null) {
418                            query = new StringBundler(6 +
419                                            (orderByComparator.getOrderByFields().length * 6));
420                    }
421                    else {
422                            query = new StringBundler(3);
423                    }
424    
425                    query.append(_SQL_SELECT_ORGANIZATION_WHERE);
426    
427                    boolean bindUuid = false;
428    
429                    if (uuid == null) {
430                            query.append(_FINDER_COLUMN_UUID_UUID_1);
431                    }
432                    else if (uuid.equals(StringPool.BLANK)) {
433                            query.append(_FINDER_COLUMN_UUID_UUID_3);
434                    }
435                    else {
436                            bindUuid = true;
437    
438                            query.append(_FINDER_COLUMN_UUID_UUID_2);
439                    }
440    
441                    if (orderByComparator != null) {
442                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
443    
444                            if (orderByConditionFields.length > 0) {
445                                    query.append(WHERE_AND);
446                            }
447    
448                            for (int i = 0; i < orderByConditionFields.length; i++) {
449                                    query.append(_ORDER_BY_ENTITY_ALIAS);
450                                    query.append(orderByConditionFields[i]);
451    
452                                    if ((i + 1) < orderByConditionFields.length) {
453                                            if (orderByComparator.isAscending() ^ previous) {
454                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
455                                            }
456                                            else {
457                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
458                                            }
459                                    }
460                                    else {
461                                            if (orderByComparator.isAscending() ^ previous) {
462                                                    query.append(WHERE_GREATER_THAN);
463                                            }
464                                            else {
465                                                    query.append(WHERE_LESSER_THAN);
466                                            }
467                                    }
468                            }
469    
470                            query.append(ORDER_BY_CLAUSE);
471    
472                            String[] orderByFields = orderByComparator.getOrderByFields();
473    
474                            for (int i = 0; i < orderByFields.length; i++) {
475                                    query.append(_ORDER_BY_ENTITY_ALIAS);
476                                    query.append(orderByFields[i]);
477    
478                                    if ((i + 1) < orderByFields.length) {
479                                            if (orderByComparator.isAscending() ^ previous) {
480                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
481                                            }
482                                            else {
483                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
484                                            }
485                                    }
486                                    else {
487                                            if (orderByComparator.isAscending() ^ previous) {
488                                                    query.append(ORDER_BY_ASC);
489                                            }
490                                            else {
491                                                    query.append(ORDER_BY_DESC);
492                                            }
493                                    }
494                            }
495                    }
496                    else {
497                            query.append(OrganizationModelImpl.ORDER_BY_JPQL);
498                    }
499    
500                    String sql = query.toString();
501    
502                    Query q = session.createQuery(sql);
503    
504                    q.setFirstResult(0);
505                    q.setMaxResults(2);
506    
507                    QueryPos qPos = QueryPos.getInstance(q);
508    
509                    if (bindUuid) {
510                            qPos.add(uuid);
511                    }
512    
513                    if (orderByComparator != null) {
514                            Object[] values = orderByComparator.getOrderByConditionValues(organization);
515    
516                            for (Object value : values) {
517                                    qPos.add(value);
518                            }
519                    }
520    
521                    List<Organization> list = q.list();
522    
523                    if (list.size() == 2) {
524                            return list.get(1);
525                    }
526                    else {
527                            return null;
528                    }
529            }
530    
531            /**
532             * Returns all the organizations that the user has permission to view where uuid = &#63;.
533             *
534             * @param uuid the uuid
535             * @return the matching organizations that the user has permission to view
536             */
537            @Override
538            public List<Organization> filterFindByUuid(String uuid) {
539                    return filterFindByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
540            }
541    
542            /**
543             * Returns a range of all the organizations that the user has permission to view where uuid = &#63;.
544             *
545             * <p>
546             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.OrganizationModelImpl}. 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.
547             * </p>
548             *
549             * @param uuid the uuid
550             * @param start the lower bound of the range of organizations
551             * @param end the upper bound of the range of organizations (not inclusive)
552             * @return the range of matching organizations that the user has permission to view
553             */
554            @Override
555            public List<Organization> filterFindByUuid(String uuid, int start, int end) {
556                    return filterFindByUuid(uuid, start, end, null);
557            }
558    
559            /**
560             * Returns an ordered range of all the organizations that the user has permissions to view where uuid = &#63;.
561             *
562             * <p>
563             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.OrganizationModelImpl}. 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.
564             * </p>
565             *
566             * @param uuid the uuid
567             * @param start the lower bound of the range of organizations
568             * @param end the upper bound of the range of organizations (not inclusive)
569             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
570             * @return the ordered range of matching organizations that the user has permission to view
571             */
572            @Override
573            public List<Organization> filterFindByUuid(String uuid, int start, int end,
574                    OrderByComparator<Organization> orderByComparator) {
575                    if (!InlineSQLHelperUtil.isEnabled()) {
576                            return findByUuid(uuid, start, end, orderByComparator);
577                    }
578    
579                    StringBundler query = null;
580    
581                    if (orderByComparator != null) {
582                            query = new StringBundler(3 +
583                                            (orderByComparator.getOrderByFields().length * 3));
584                    }
585                    else {
586                            query = new StringBundler(3);
587                    }
588    
589                    if (getDB().isSupportsInlineDistinct()) {
590                            query.append(_FILTER_SQL_SELECT_ORGANIZATION_WHERE);
591                    }
592                    else {
593                            query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_1);
594                    }
595    
596                    boolean bindUuid = false;
597    
598                    if (uuid == null) {
599                            query.append(_FINDER_COLUMN_UUID_UUID_1_SQL);
600                    }
601                    else if (uuid.equals(StringPool.BLANK)) {
602                            query.append(_FINDER_COLUMN_UUID_UUID_3_SQL);
603                    }
604                    else {
605                            bindUuid = true;
606    
607                            query.append(_FINDER_COLUMN_UUID_UUID_2_SQL);
608                    }
609    
610                    if (!getDB().isSupportsInlineDistinct()) {
611                            query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_2);
612                    }
613    
614                    if (orderByComparator != null) {
615                            if (getDB().isSupportsInlineDistinct()) {
616                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
617                                            orderByComparator, true);
618                            }
619                            else {
620                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
621                                            orderByComparator, true);
622                            }
623                    }
624                    else {
625                            if (getDB().isSupportsInlineDistinct()) {
626                                    query.append(OrganizationModelImpl.ORDER_BY_JPQL);
627                            }
628                            else {
629                                    query.append(OrganizationModelImpl.ORDER_BY_SQL);
630                            }
631                    }
632    
633                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
634                                    Organization.class.getName(),
635                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
636    
637                    Session session = null;
638    
639                    try {
640                            session = openSession();
641    
642                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
643    
644                            if (getDB().isSupportsInlineDistinct()) {
645                                    q.addEntity(_FILTER_ENTITY_ALIAS, OrganizationImpl.class);
646                            }
647                            else {
648                                    q.addEntity(_FILTER_ENTITY_TABLE, OrganizationImpl.class);
649                            }
650    
651                            QueryPos qPos = QueryPos.getInstance(q);
652    
653                            if (bindUuid) {
654                                    qPos.add(uuid);
655                            }
656    
657                            return (List<Organization>)QueryUtil.list(q, getDialect(), start,
658                                    end);
659                    }
660                    catch (Exception e) {
661                            throw processException(e);
662                    }
663                    finally {
664                            closeSession(session);
665                    }
666            }
667    
668            /**
669             * Returns the organizations before and after the current organization in the ordered set of organizations that the user has permission to view where uuid = &#63;.
670             *
671             * @param organizationId the primary key of the current organization
672             * @param uuid the uuid
673             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
674             * @return the previous, current, and next organization
675             * @throws com.liferay.portal.NoSuchOrganizationException if a organization with the primary key could not be found
676             */
677            @Override
678            public Organization[] filterFindByUuid_PrevAndNext(long organizationId,
679                    String uuid, OrderByComparator<Organization> orderByComparator)
680                    throws NoSuchOrganizationException {
681                    if (!InlineSQLHelperUtil.isEnabled()) {
682                            return findByUuid_PrevAndNext(organizationId, uuid,
683                                    orderByComparator);
684                    }
685    
686                    Organization organization = findByPrimaryKey(organizationId);
687    
688                    Session session = null;
689    
690                    try {
691                            session = openSession();
692    
693                            Organization[] array = new OrganizationImpl[3];
694    
695                            array[0] = filterGetByUuid_PrevAndNext(session, organization, uuid,
696                                            orderByComparator, true);
697    
698                            array[1] = organization;
699    
700                            array[2] = filterGetByUuid_PrevAndNext(session, organization, uuid,
701                                            orderByComparator, false);
702    
703                            return array;
704                    }
705                    catch (Exception e) {
706                            throw processException(e);
707                    }
708                    finally {
709                            closeSession(session);
710                    }
711            }
712    
713            protected Organization filterGetByUuid_PrevAndNext(Session session,
714                    Organization organization, String uuid,
715                    OrderByComparator<Organization> orderByComparator, boolean previous) {
716                    StringBundler query = null;
717    
718                    if (orderByComparator != null) {
719                            query = new StringBundler(6 +
720                                            (orderByComparator.getOrderByFields().length * 6));
721                    }
722                    else {
723                            query = new StringBundler(3);
724                    }
725    
726                    if (getDB().isSupportsInlineDistinct()) {
727                            query.append(_FILTER_SQL_SELECT_ORGANIZATION_WHERE);
728                    }
729                    else {
730                            query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_1);
731                    }
732    
733                    boolean bindUuid = false;
734    
735                    if (uuid == null) {
736                            query.append(_FINDER_COLUMN_UUID_UUID_1_SQL);
737                    }
738                    else if (uuid.equals(StringPool.BLANK)) {
739                            query.append(_FINDER_COLUMN_UUID_UUID_3_SQL);
740                    }
741                    else {
742                            bindUuid = true;
743    
744                            query.append(_FINDER_COLUMN_UUID_UUID_2_SQL);
745                    }
746    
747                    if (!getDB().isSupportsInlineDistinct()) {
748                            query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_2);
749                    }
750    
751                    if (orderByComparator != null) {
752                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
753    
754                            if (orderByConditionFields.length > 0) {
755                                    query.append(WHERE_AND);
756                            }
757    
758                            for (int i = 0; i < orderByConditionFields.length; i++) {
759                                    if (getDB().isSupportsInlineDistinct()) {
760                                            query.append(_ORDER_BY_ENTITY_ALIAS);
761                                    }
762                                    else {
763                                            query.append(_ORDER_BY_ENTITY_TABLE);
764                                    }
765    
766                                    query.append(orderByConditionFields[i]);
767    
768                                    if ((i + 1) < orderByConditionFields.length) {
769                                            if (orderByComparator.isAscending() ^ previous) {
770                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
771                                            }
772                                            else {
773                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
774                                            }
775                                    }
776                                    else {
777                                            if (orderByComparator.isAscending() ^ previous) {
778                                                    query.append(WHERE_GREATER_THAN);
779                                            }
780                                            else {
781                                                    query.append(WHERE_LESSER_THAN);
782                                            }
783                                    }
784                            }
785    
786                            query.append(ORDER_BY_CLAUSE);
787    
788                            String[] orderByFields = orderByComparator.getOrderByFields();
789    
790                            for (int i = 0; i < orderByFields.length; i++) {
791                                    if (getDB().isSupportsInlineDistinct()) {
792                                            query.append(_ORDER_BY_ENTITY_ALIAS);
793                                    }
794                                    else {
795                                            query.append(_ORDER_BY_ENTITY_TABLE);
796                                    }
797    
798                                    query.append(orderByFields[i]);
799    
800                                    if ((i + 1) < orderByFields.length) {
801                                            if (orderByComparator.isAscending() ^ previous) {
802                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
803                                            }
804                                            else {
805                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
806                                            }
807                                    }
808                                    else {
809                                            if (orderByComparator.isAscending() ^ previous) {
810                                                    query.append(ORDER_BY_ASC);
811                                            }
812                                            else {
813                                                    query.append(ORDER_BY_DESC);
814                                            }
815                                    }
816                            }
817                    }
818                    else {
819                            if (getDB().isSupportsInlineDistinct()) {
820                                    query.append(OrganizationModelImpl.ORDER_BY_JPQL);
821                            }
822                            else {
823                                    query.append(OrganizationModelImpl.ORDER_BY_SQL);
824                            }
825                    }
826    
827                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
828                                    Organization.class.getName(),
829                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
830    
831                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
832    
833                    q.setFirstResult(0);
834                    q.setMaxResults(2);
835    
836                    if (getDB().isSupportsInlineDistinct()) {
837                            q.addEntity(_FILTER_ENTITY_ALIAS, OrganizationImpl.class);
838                    }
839                    else {
840                            q.addEntity(_FILTER_ENTITY_TABLE, OrganizationImpl.class);
841                    }
842    
843                    QueryPos qPos = QueryPos.getInstance(q);
844    
845                    if (bindUuid) {
846                            qPos.add(uuid);
847                    }
848    
849                    if (orderByComparator != null) {
850                            Object[] values = orderByComparator.getOrderByConditionValues(organization);
851    
852                            for (Object value : values) {
853                                    qPos.add(value);
854                            }
855                    }
856    
857                    List<Organization> list = q.list();
858    
859                    if (list.size() == 2) {
860                            return list.get(1);
861                    }
862                    else {
863                            return null;
864                    }
865            }
866    
867            /**
868             * Removes all the organizations where uuid = &#63; from the database.
869             *
870             * @param uuid the uuid
871             */
872            @Override
873            public void removeByUuid(String uuid) {
874                    for (Organization organization : findByUuid(uuid, QueryUtil.ALL_POS,
875                                    QueryUtil.ALL_POS, null)) {
876                            remove(organization);
877                    }
878            }
879    
880            /**
881             * Returns the number of organizations where uuid = &#63;.
882             *
883             * @param uuid the uuid
884             * @return the number of matching organizations
885             */
886            @Override
887            public int countByUuid(String uuid) {
888                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
889    
890                    Object[] finderArgs = new Object[] { uuid };
891    
892                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
893                                    this);
894    
895                    if (count == null) {
896                            StringBundler query = new StringBundler(2);
897    
898                            query.append(_SQL_COUNT_ORGANIZATION_WHERE);
899    
900                            boolean bindUuid = false;
901    
902                            if (uuid == null) {
903                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
904                            }
905                            else if (uuid.equals(StringPool.BLANK)) {
906                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
907                            }
908                            else {
909                                    bindUuid = true;
910    
911                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
912                            }
913    
914                            String sql = query.toString();
915    
916                            Session session = null;
917    
918                            try {
919                                    session = openSession();
920    
921                                    Query q = session.createQuery(sql);
922    
923                                    QueryPos qPos = QueryPos.getInstance(q);
924    
925                                    if (bindUuid) {
926                                            qPos.add(uuid);
927                                    }
928    
929                                    count = (Long)q.uniqueResult();
930    
931                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
932                            }
933                            catch (Exception e) {
934                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
935    
936                                    throw processException(e);
937                            }
938                            finally {
939                                    closeSession(session);
940                            }
941                    }
942    
943                    return count.intValue();
944            }
945    
946            /**
947             * Returns the number of organizations that the user has permission to view where uuid = &#63;.
948             *
949             * @param uuid the uuid
950             * @return the number of matching organizations that the user has permission to view
951             */
952            @Override
953            public int filterCountByUuid(String uuid) {
954                    if (!InlineSQLHelperUtil.isEnabled()) {
955                            return countByUuid(uuid);
956                    }
957    
958                    StringBundler query = new StringBundler(2);
959    
960                    query.append(_FILTER_SQL_COUNT_ORGANIZATION_WHERE);
961    
962                    boolean bindUuid = false;
963    
964                    if (uuid == null) {
965                            query.append(_FINDER_COLUMN_UUID_UUID_1_SQL);
966                    }
967                    else if (uuid.equals(StringPool.BLANK)) {
968                            query.append(_FINDER_COLUMN_UUID_UUID_3_SQL);
969                    }
970                    else {
971                            bindUuid = true;
972    
973                            query.append(_FINDER_COLUMN_UUID_UUID_2_SQL);
974                    }
975    
976                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
977                                    Organization.class.getName(),
978                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
979    
980                    Session session = null;
981    
982                    try {
983                            session = openSession();
984    
985                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
986    
987                            q.addScalar(COUNT_COLUMN_NAME,
988                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
989    
990                            QueryPos qPos = QueryPos.getInstance(q);
991    
992                            if (bindUuid) {
993                                    qPos.add(uuid);
994                            }
995    
996                            Long count = (Long)q.uniqueResult();
997    
998                            return count.intValue();
999                    }
1000                    catch (Exception e) {
1001                            throw processException(e);
1002                    }
1003                    finally {
1004                            closeSession(session);
1005                    }
1006            }
1007    
1008            private static final String _FINDER_COLUMN_UUID_UUID_1 = "organization.uuid IS NULL";
1009            private static final String _FINDER_COLUMN_UUID_UUID_2 = "organization.uuid = ?";
1010            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(organization.uuid IS NULL OR organization.uuid = '')";
1011            private static final String _FINDER_COLUMN_UUID_UUID_1_SQL = "organization.uuid_ IS NULL";
1012            private static final String _FINDER_COLUMN_UUID_UUID_2_SQL = "organization.uuid_ = ?";
1013            private static final String _FINDER_COLUMN_UUID_UUID_3_SQL = "(organization.uuid_ IS NULL OR organization.uuid_ = '')";
1014            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
1015                            OrganizationModelImpl.FINDER_CACHE_ENABLED, OrganizationImpl.class,
1016                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid_C",
1017                            new String[] {
1018                                    String.class.getName(), Long.class.getName(),
1019                                    
1020                            Integer.class.getName(), Integer.class.getName(),
1021                                    OrderByComparator.class.getName()
1022                            });
1023            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
1024                    new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
1025                            OrganizationModelImpl.FINDER_CACHE_ENABLED, OrganizationImpl.class,
1026                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid_C",
1027                            new String[] { String.class.getName(), Long.class.getName() },
1028                            OrganizationModelImpl.UUID_COLUMN_BITMASK |
1029                            OrganizationModelImpl.COMPANYID_COLUMN_BITMASK |
1030                            OrganizationModelImpl.NAME_COLUMN_BITMASK);
1031            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
1032                            OrganizationModelImpl.FINDER_CACHE_ENABLED, Long.class,
1033                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
1034                            new String[] { String.class.getName(), Long.class.getName() });
1035    
1036            /**
1037             * Returns all the organizations where uuid = &#63; and companyId = &#63;.
1038             *
1039             * @param uuid the uuid
1040             * @param companyId the company ID
1041             * @return the matching organizations
1042             */
1043            @Override
1044            public List<Organization> findByUuid_C(String uuid, long companyId) {
1045                    return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
1046                            QueryUtil.ALL_POS, null);
1047            }
1048    
1049            /**
1050             * Returns a range of all the organizations where uuid = &#63; and companyId = &#63;.
1051             *
1052             * <p>
1053             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.OrganizationModelImpl}. 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.
1054             * </p>
1055             *
1056             * @param uuid the uuid
1057             * @param companyId the company ID
1058             * @param start the lower bound of the range of organizations
1059             * @param end the upper bound of the range of organizations (not inclusive)
1060             * @return the range of matching organizations
1061             */
1062            @Override
1063            public List<Organization> findByUuid_C(String uuid, long companyId,
1064                    int start, int end) {
1065                    return findByUuid_C(uuid, companyId, start, end, null);
1066            }
1067    
1068            /**
1069             * Returns an ordered range of all the organizations where uuid = &#63; and companyId = &#63;.
1070             *
1071             * <p>
1072             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.OrganizationModelImpl}. 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.
1073             * </p>
1074             *
1075             * @param uuid the uuid
1076             * @param companyId the company ID
1077             * @param start the lower bound of the range of organizations
1078             * @param end the upper bound of the range of organizations (not inclusive)
1079             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1080             * @return the ordered range of matching organizations
1081             */
1082            @Override
1083            public List<Organization> findByUuid_C(String uuid, long companyId,
1084                    int start, int end, OrderByComparator<Organization> orderByComparator) {
1085                    boolean pagination = true;
1086                    FinderPath finderPath = null;
1087                    Object[] finderArgs = null;
1088    
1089                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1090                                    (orderByComparator == null)) {
1091                            pagination = false;
1092                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
1093                            finderArgs = new Object[] { uuid, companyId };
1094                    }
1095                    else {
1096                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
1097                            finderArgs = new Object[] {
1098                                            uuid, companyId,
1099                                            
1100                                            start, end, orderByComparator
1101                                    };
1102                    }
1103    
1104                    List<Organization> list = (List<Organization>)FinderCacheUtil.getResult(finderPath,
1105                                    finderArgs, this);
1106    
1107                    if ((list != null) && !list.isEmpty()) {
1108                            for (Organization organization : list) {
1109                                    if (!Validator.equals(uuid, organization.getUuid()) ||
1110                                                    (companyId != organization.getCompanyId())) {
1111                                            list = null;
1112    
1113                                            break;
1114                                    }
1115                            }
1116                    }
1117    
1118                    if (list == null) {
1119                            StringBundler query = null;
1120    
1121                            if (orderByComparator != null) {
1122                                    query = new StringBundler(4 +
1123                                                    (orderByComparator.getOrderByFields().length * 3));
1124                            }
1125                            else {
1126                                    query = new StringBundler(4);
1127                            }
1128    
1129                            query.append(_SQL_SELECT_ORGANIZATION_WHERE);
1130    
1131                            boolean bindUuid = false;
1132    
1133                            if (uuid == null) {
1134                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1135                            }
1136                            else if (uuid.equals(StringPool.BLANK)) {
1137                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1138                            }
1139                            else {
1140                                    bindUuid = true;
1141    
1142                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1143                            }
1144    
1145                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1146    
1147                            if (orderByComparator != null) {
1148                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1149                                            orderByComparator);
1150                            }
1151                            else
1152                             if (pagination) {
1153                                    query.append(OrganizationModelImpl.ORDER_BY_JPQL);
1154                            }
1155    
1156                            String sql = query.toString();
1157    
1158                            Session session = null;
1159    
1160                            try {
1161                                    session = openSession();
1162    
1163                                    Query q = session.createQuery(sql);
1164    
1165                                    QueryPos qPos = QueryPos.getInstance(q);
1166    
1167                                    if (bindUuid) {
1168                                            qPos.add(uuid);
1169                                    }
1170    
1171                                    qPos.add(companyId);
1172    
1173                                    if (!pagination) {
1174                                            list = (List<Organization>)QueryUtil.list(q, getDialect(),
1175                                                            start, end, false);
1176    
1177                                            Collections.sort(list);
1178    
1179                                            list = Collections.unmodifiableList(list);
1180                                    }
1181                                    else {
1182                                            list = (List<Organization>)QueryUtil.list(q, getDialect(),
1183                                                            start, end);
1184                                    }
1185    
1186                                    cacheResult(list);
1187    
1188                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1189                            }
1190                            catch (Exception e) {
1191                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1192    
1193                                    throw processException(e);
1194                            }
1195                            finally {
1196                                    closeSession(session);
1197                            }
1198                    }
1199    
1200                    return list;
1201            }
1202    
1203            /**
1204             * Returns the first organization in the ordered set where uuid = &#63; and companyId = &#63;.
1205             *
1206             * @param uuid the uuid
1207             * @param companyId the company ID
1208             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1209             * @return the first matching organization
1210             * @throws com.liferay.portal.NoSuchOrganizationException if a matching organization could not be found
1211             */
1212            @Override
1213            public Organization findByUuid_C_First(String uuid, long companyId,
1214                    OrderByComparator<Organization> orderByComparator)
1215                    throws NoSuchOrganizationException {
1216                    Organization organization = fetchByUuid_C_First(uuid, companyId,
1217                                    orderByComparator);
1218    
1219                    if (organization != null) {
1220                            return organization;
1221                    }
1222    
1223                    StringBundler msg = new StringBundler(6);
1224    
1225                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1226    
1227                    msg.append("uuid=");
1228                    msg.append(uuid);
1229    
1230                    msg.append(", companyId=");
1231                    msg.append(companyId);
1232    
1233                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1234    
1235                    throw new NoSuchOrganizationException(msg.toString());
1236            }
1237    
1238            /**
1239             * Returns the first organization in the ordered set where uuid = &#63; and companyId = &#63;.
1240             *
1241             * @param uuid the uuid
1242             * @param companyId the company ID
1243             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1244             * @return the first matching organization, or <code>null</code> if a matching organization could not be found
1245             */
1246            @Override
1247            public Organization fetchByUuid_C_First(String uuid, long companyId,
1248                    OrderByComparator<Organization> orderByComparator) {
1249                    List<Organization> list = findByUuid_C(uuid, companyId, 0, 1,
1250                                    orderByComparator);
1251    
1252                    if (!list.isEmpty()) {
1253                            return list.get(0);
1254                    }
1255    
1256                    return null;
1257            }
1258    
1259            /**
1260             * Returns the last organization in the ordered set where uuid = &#63; and companyId = &#63;.
1261             *
1262             * @param uuid the uuid
1263             * @param companyId the company ID
1264             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1265             * @return the last matching organization
1266             * @throws com.liferay.portal.NoSuchOrganizationException if a matching organization could not be found
1267             */
1268            @Override
1269            public Organization findByUuid_C_Last(String uuid, long companyId,
1270                    OrderByComparator<Organization> orderByComparator)
1271                    throws NoSuchOrganizationException {
1272                    Organization organization = fetchByUuid_C_Last(uuid, companyId,
1273                                    orderByComparator);
1274    
1275                    if (organization != null) {
1276                            return organization;
1277                    }
1278    
1279                    StringBundler msg = new StringBundler(6);
1280    
1281                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1282    
1283                    msg.append("uuid=");
1284                    msg.append(uuid);
1285    
1286                    msg.append(", companyId=");
1287                    msg.append(companyId);
1288    
1289                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1290    
1291                    throw new NoSuchOrganizationException(msg.toString());
1292            }
1293    
1294            /**
1295             * Returns the last organization in the ordered set where uuid = &#63; and companyId = &#63;.
1296             *
1297             * @param uuid the uuid
1298             * @param companyId the company ID
1299             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1300             * @return the last matching organization, or <code>null</code> if a matching organization could not be found
1301             */
1302            @Override
1303            public Organization fetchByUuid_C_Last(String uuid, long companyId,
1304                    OrderByComparator<Organization> orderByComparator) {
1305                    int count = countByUuid_C(uuid, companyId);
1306    
1307                    if (count == 0) {
1308                            return null;
1309                    }
1310    
1311                    List<Organization> list = findByUuid_C(uuid, companyId, count - 1,
1312                                    count, orderByComparator);
1313    
1314                    if (!list.isEmpty()) {
1315                            return list.get(0);
1316                    }
1317    
1318                    return null;
1319            }
1320    
1321            /**
1322             * Returns the organizations before and after the current organization in the ordered set where uuid = &#63; and companyId = &#63;.
1323             *
1324             * @param organizationId the primary key of the current organization
1325             * @param uuid the uuid
1326             * @param companyId the company ID
1327             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1328             * @return the previous, current, and next organization
1329             * @throws com.liferay.portal.NoSuchOrganizationException if a organization with the primary key could not be found
1330             */
1331            @Override
1332            public Organization[] findByUuid_C_PrevAndNext(long organizationId,
1333                    String uuid, long companyId,
1334                    OrderByComparator<Organization> orderByComparator)
1335                    throws NoSuchOrganizationException {
1336                    Organization organization = findByPrimaryKey(organizationId);
1337    
1338                    Session session = null;
1339    
1340                    try {
1341                            session = openSession();
1342    
1343                            Organization[] array = new OrganizationImpl[3];
1344    
1345                            array[0] = getByUuid_C_PrevAndNext(session, organization, uuid,
1346                                            companyId, orderByComparator, true);
1347    
1348                            array[1] = organization;
1349    
1350                            array[2] = getByUuid_C_PrevAndNext(session, organization, uuid,
1351                                            companyId, orderByComparator, false);
1352    
1353                            return array;
1354                    }
1355                    catch (Exception e) {
1356                            throw processException(e);
1357                    }
1358                    finally {
1359                            closeSession(session);
1360                    }
1361            }
1362    
1363            protected Organization getByUuid_C_PrevAndNext(Session session,
1364                    Organization organization, String uuid, long companyId,
1365                    OrderByComparator<Organization> orderByComparator, boolean previous) {
1366                    StringBundler query = null;
1367    
1368                    if (orderByComparator != null) {
1369                            query = new StringBundler(6 +
1370                                            (orderByComparator.getOrderByFields().length * 6));
1371                    }
1372                    else {
1373                            query = new StringBundler(3);
1374                    }
1375    
1376                    query.append(_SQL_SELECT_ORGANIZATION_WHERE);
1377    
1378                    boolean bindUuid = false;
1379    
1380                    if (uuid == null) {
1381                            query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1382                    }
1383                    else if (uuid.equals(StringPool.BLANK)) {
1384                            query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1385                    }
1386                    else {
1387                            bindUuid = true;
1388    
1389                            query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1390                    }
1391    
1392                    query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1393    
1394                    if (orderByComparator != null) {
1395                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1396    
1397                            if (orderByConditionFields.length > 0) {
1398                                    query.append(WHERE_AND);
1399                            }
1400    
1401                            for (int i = 0; i < orderByConditionFields.length; i++) {
1402                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1403                                    query.append(orderByConditionFields[i]);
1404    
1405                                    if ((i + 1) < orderByConditionFields.length) {
1406                                            if (orderByComparator.isAscending() ^ previous) {
1407                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1408                                            }
1409                                            else {
1410                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1411                                            }
1412                                    }
1413                                    else {
1414                                            if (orderByComparator.isAscending() ^ previous) {
1415                                                    query.append(WHERE_GREATER_THAN);
1416                                            }
1417                                            else {
1418                                                    query.append(WHERE_LESSER_THAN);
1419                                            }
1420                                    }
1421                            }
1422    
1423                            query.append(ORDER_BY_CLAUSE);
1424    
1425                            String[] orderByFields = orderByComparator.getOrderByFields();
1426    
1427                            for (int i = 0; i < orderByFields.length; i++) {
1428                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1429                                    query.append(orderByFields[i]);
1430    
1431                                    if ((i + 1) < orderByFields.length) {
1432                                            if (orderByComparator.isAscending() ^ previous) {
1433                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1434                                            }
1435                                            else {
1436                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1437                                            }
1438                                    }
1439                                    else {
1440                                            if (orderByComparator.isAscending() ^ previous) {
1441                                                    query.append(ORDER_BY_ASC);
1442                                            }
1443                                            else {
1444                                                    query.append(ORDER_BY_DESC);
1445                                            }
1446                                    }
1447                            }
1448                    }
1449                    else {
1450                            query.append(OrganizationModelImpl.ORDER_BY_JPQL);
1451                    }
1452    
1453                    String sql = query.toString();
1454    
1455                    Query q = session.createQuery(sql);
1456    
1457                    q.setFirstResult(0);
1458                    q.setMaxResults(2);
1459    
1460                    QueryPos qPos = QueryPos.getInstance(q);
1461    
1462                    if (bindUuid) {
1463                            qPos.add(uuid);
1464                    }
1465    
1466                    qPos.add(companyId);
1467    
1468                    if (orderByComparator != null) {
1469                            Object[] values = orderByComparator.getOrderByConditionValues(organization);
1470    
1471                            for (Object value : values) {
1472                                    qPos.add(value);
1473                            }
1474                    }
1475    
1476                    List<Organization> list = q.list();
1477    
1478                    if (list.size() == 2) {
1479                            return list.get(1);
1480                    }
1481                    else {
1482                            return null;
1483                    }
1484            }
1485    
1486            /**
1487             * Returns all the organizations that the user has permission to view where uuid = &#63; and companyId = &#63;.
1488             *
1489             * @param uuid the uuid
1490             * @param companyId the company ID
1491             * @return the matching organizations that the user has permission to view
1492             */
1493            @Override
1494            public List<Organization> filterFindByUuid_C(String uuid, long companyId) {
1495                    return filterFindByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
1496                            QueryUtil.ALL_POS, null);
1497            }
1498    
1499            /**
1500             * Returns a range of all the organizations that the user has permission to view where uuid = &#63; and companyId = &#63;.
1501             *
1502             * <p>
1503             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.OrganizationModelImpl}. 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.
1504             * </p>
1505             *
1506             * @param uuid the uuid
1507             * @param companyId the company ID
1508             * @param start the lower bound of the range of organizations
1509             * @param end the upper bound of the range of organizations (not inclusive)
1510             * @return the range of matching organizations that the user has permission to view
1511             */
1512            @Override
1513            public List<Organization> filterFindByUuid_C(String uuid, long companyId,
1514                    int start, int end) {
1515                    return filterFindByUuid_C(uuid, companyId, start, end, null);
1516            }
1517    
1518            /**
1519             * Returns an ordered range of all the organizations that the user has permissions to view where uuid = &#63; and companyId = &#63;.
1520             *
1521             * <p>
1522             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.OrganizationModelImpl}. 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.
1523             * </p>
1524             *
1525             * @param uuid the uuid
1526             * @param companyId the company ID
1527             * @param start the lower bound of the range of organizations
1528             * @param end the upper bound of the range of organizations (not inclusive)
1529             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1530             * @return the ordered range of matching organizations that the user has permission to view
1531             */
1532            @Override
1533            public List<Organization> filterFindByUuid_C(String uuid, long companyId,
1534                    int start, int end, OrderByComparator<Organization> orderByComparator) {
1535                    if (!InlineSQLHelperUtil.isEnabled()) {
1536                            return findByUuid_C(uuid, companyId, start, end, orderByComparator);
1537                    }
1538    
1539                    StringBundler query = null;
1540    
1541                    if (orderByComparator != null) {
1542                            query = new StringBundler(4 +
1543                                            (orderByComparator.getOrderByFields().length * 3));
1544                    }
1545                    else {
1546                            query = new StringBundler(4);
1547                    }
1548    
1549                    if (getDB().isSupportsInlineDistinct()) {
1550                            query.append(_FILTER_SQL_SELECT_ORGANIZATION_WHERE);
1551                    }
1552                    else {
1553                            query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_1);
1554                    }
1555    
1556                    boolean bindUuid = false;
1557    
1558                    if (uuid == null) {
1559                            query.append(_FINDER_COLUMN_UUID_C_UUID_1_SQL);
1560                    }
1561                    else if (uuid.equals(StringPool.BLANK)) {
1562                            query.append(_FINDER_COLUMN_UUID_C_UUID_3_SQL);
1563                    }
1564                    else {
1565                            bindUuid = true;
1566    
1567                            query.append(_FINDER_COLUMN_UUID_C_UUID_2_SQL);
1568                    }
1569    
1570                    query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1571    
1572                    if (!getDB().isSupportsInlineDistinct()) {
1573                            query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_2);
1574                    }
1575    
1576                    if (orderByComparator != null) {
1577                            if (getDB().isSupportsInlineDistinct()) {
1578                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1579                                            orderByComparator, true);
1580                            }
1581                            else {
1582                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
1583                                            orderByComparator, true);
1584                            }
1585                    }
1586                    else {
1587                            if (getDB().isSupportsInlineDistinct()) {
1588                                    query.append(OrganizationModelImpl.ORDER_BY_JPQL);
1589                            }
1590                            else {
1591                                    query.append(OrganizationModelImpl.ORDER_BY_SQL);
1592                            }
1593                    }
1594    
1595                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1596                                    Organization.class.getName(),
1597                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
1598    
1599                    Session session = null;
1600    
1601                    try {
1602                            session = openSession();
1603    
1604                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
1605    
1606                            if (getDB().isSupportsInlineDistinct()) {
1607                                    q.addEntity(_FILTER_ENTITY_ALIAS, OrganizationImpl.class);
1608                            }
1609                            else {
1610                                    q.addEntity(_FILTER_ENTITY_TABLE, OrganizationImpl.class);
1611                            }
1612    
1613                            QueryPos qPos = QueryPos.getInstance(q);
1614    
1615                            if (bindUuid) {
1616                                    qPos.add(uuid);
1617                            }
1618    
1619                            qPos.add(companyId);
1620    
1621                            return (List<Organization>)QueryUtil.list(q, getDialect(), start,
1622                                    end);
1623                    }
1624                    catch (Exception e) {
1625                            throw processException(e);
1626                    }
1627                    finally {
1628                            closeSession(session);
1629                    }
1630            }
1631    
1632            /**
1633             * Returns the organizations before and after the current organization in the ordered set of organizations that the user has permission to view where uuid = &#63; and companyId = &#63;.
1634             *
1635             * @param organizationId the primary key of the current organization
1636             * @param uuid the uuid
1637             * @param companyId the company ID
1638             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1639             * @return the previous, current, and next organization
1640             * @throws com.liferay.portal.NoSuchOrganizationException if a organization with the primary key could not be found
1641             */
1642            @Override
1643            public Organization[] filterFindByUuid_C_PrevAndNext(long organizationId,
1644                    String uuid, long companyId,
1645                    OrderByComparator<Organization> orderByComparator)
1646                    throws NoSuchOrganizationException {
1647                    if (!InlineSQLHelperUtil.isEnabled()) {
1648                            return findByUuid_C_PrevAndNext(organizationId, uuid, companyId,
1649                                    orderByComparator);
1650                    }
1651    
1652                    Organization organization = findByPrimaryKey(organizationId);
1653    
1654                    Session session = null;
1655    
1656                    try {
1657                            session = openSession();
1658    
1659                            Organization[] array = new OrganizationImpl[3];
1660    
1661                            array[0] = filterGetByUuid_C_PrevAndNext(session, organization,
1662                                            uuid, companyId, orderByComparator, true);
1663    
1664                            array[1] = organization;
1665    
1666                            array[2] = filterGetByUuid_C_PrevAndNext(session, organization,
1667                                            uuid, companyId, orderByComparator, false);
1668    
1669                            return array;
1670                    }
1671                    catch (Exception e) {
1672                            throw processException(e);
1673                    }
1674                    finally {
1675                            closeSession(session);
1676                    }
1677            }
1678    
1679            protected Organization filterGetByUuid_C_PrevAndNext(Session session,
1680                    Organization organization, String uuid, long companyId,
1681                    OrderByComparator<Organization> orderByComparator, boolean previous) {
1682                    StringBundler query = null;
1683    
1684                    if (orderByComparator != null) {
1685                            query = new StringBundler(6 +
1686                                            (orderByComparator.getOrderByFields().length * 6));
1687                    }
1688                    else {
1689                            query = new StringBundler(3);
1690                    }
1691    
1692                    if (getDB().isSupportsInlineDistinct()) {
1693                            query.append(_FILTER_SQL_SELECT_ORGANIZATION_WHERE);
1694                    }
1695                    else {
1696                            query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_1);
1697                    }
1698    
1699                    boolean bindUuid = false;
1700    
1701                    if (uuid == null) {
1702                            query.append(_FINDER_COLUMN_UUID_C_UUID_1_SQL);
1703                    }
1704                    else if (uuid.equals(StringPool.BLANK)) {
1705                            query.append(_FINDER_COLUMN_UUID_C_UUID_3_SQL);
1706                    }
1707                    else {
1708                            bindUuid = true;
1709    
1710                            query.append(_FINDER_COLUMN_UUID_C_UUID_2_SQL);
1711                    }
1712    
1713                    query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1714    
1715                    if (!getDB().isSupportsInlineDistinct()) {
1716                            query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_2);
1717                    }
1718    
1719                    if (orderByComparator != null) {
1720                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1721    
1722                            if (orderByConditionFields.length > 0) {
1723                                    query.append(WHERE_AND);
1724                            }
1725    
1726                            for (int i = 0; i < orderByConditionFields.length; i++) {
1727                                    if (getDB().isSupportsInlineDistinct()) {
1728                                            query.append(_ORDER_BY_ENTITY_ALIAS);
1729                                    }
1730                                    else {
1731                                            query.append(_ORDER_BY_ENTITY_TABLE);
1732                                    }
1733    
1734                                    query.append(orderByConditionFields[i]);
1735    
1736                                    if ((i + 1) < orderByConditionFields.length) {
1737                                            if (orderByComparator.isAscending() ^ previous) {
1738                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1739                                            }
1740                                            else {
1741                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1742                                            }
1743                                    }
1744                                    else {
1745                                            if (orderByComparator.isAscending() ^ previous) {
1746                                                    query.append(WHERE_GREATER_THAN);
1747                                            }
1748                                            else {
1749                                                    query.append(WHERE_LESSER_THAN);
1750                                            }
1751                                    }
1752                            }
1753    
1754                            query.append(ORDER_BY_CLAUSE);
1755    
1756                            String[] orderByFields = orderByComparator.getOrderByFields();
1757    
1758                            for (int i = 0; i < orderByFields.length; i++) {
1759                                    if (getDB().isSupportsInlineDistinct()) {
1760                                            query.append(_ORDER_BY_ENTITY_ALIAS);
1761                                    }
1762                                    else {
1763                                            query.append(_ORDER_BY_ENTITY_TABLE);
1764                                    }
1765    
1766                                    query.append(orderByFields[i]);
1767    
1768                                    if ((i + 1) < orderByFields.length) {
1769                                            if (orderByComparator.isAscending() ^ previous) {
1770                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1771                                            }
1772                                            else {
1773                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1774                                            }
1775                                    }
1776                                    else {
1777                                            if (orderByComparator.isAscending() ^ previous) {
1778                                                    query.append(ORDER_BY_ASC);
1779                                            }
1780                                            else {
1781                                                    query.append(ORDER_BY_DESC);
1782                                            }
1783                                    }
1784                            }
1785                    }
1786                    else {
1787                            if (getDB().isSupportsInlineDistinct()) {
1788                                    query.append(OrganizationModelImpl.ORDER_BY_JPQL);
1789                            }
1790                            else {
1791                                    query.append(OrganizationModelImpl.ORDER_BY_SQL);
1792                            }
1793                    }
1794    
1795                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1796                                    Organization.class.getName(),
1797                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
1798    
1799                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
1800    
1801                    q.setFirstResult(0);
1802                    q.setMaxResults(2);
1803    
1804                    if (getDB().isSupportsInlineDistinct()) {
1805                            q.addEntity(_FILTER_ENTITY_ALIAS, OrganizationImpl.class);
1806                    }
1807                    else {
1808                            q.addEntity(_FILTER_ENTITY_TABLE, OrganizationImpl.class);
1809                    }
1810    
1811                    QueryPos qPos = QueryPos.getInstance(q);
1812    
1813                    if (bindUuid) {
1814                            qPos.add(uuid);
1815                    }
1816    
1817                    qPos.add(companyId);
1818    
1819                    if (orderByComparator != null) {
1820                            Object[] values = orderByComparator.getOrderByConditionValues(organization);
1821    
1822                            for (Object value : values) {
1823                                    qPos.add(value);
1824                            }
1825                    }
1826    
1827                    List<Organization> list = q.list();
1828    
1829                    if (list.size() == 2) {
1830                            return list.get(1);
1831                    }
1832                    else {
1833                            return null;
1834                    }
1835            }
1836    
1837            /**
1838             * Removes all the organizations where uuid = &#63; and companyId = &#63; from the database.
1839             *
1840             * @param uuid the uuid
1841             * @param companyId the company ID
1842             */
1843            @Override
1844            public void removeByUuid_C(String uuid, long companyId) {
1845                    for (Organization organization : findByUuid_C(uuid, companyId,
1846                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1847                            remove(organization);
1848                    }
1849            }
1850    
1851            /**
1852             * Returns the number of organizations where uuid = &#63; and companyId = &#63;.
1853             *
1854             * @param uuid the uuid
1855             * @param companyId the company ID
1856             * @return the number of matching organizations
1857             */
1858            @Override
1859            public int countByUuid_C(String uuid, long companyId) {
1860                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1861    
1862                    Object[] finderArgs = new Object[] { uuid, companyId };
1863    
1864                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1865                                    this);
1866    
1867                    if (count == null) {
1868                            StringBundler query = new StringBundler(3);
1869    
1870                            query.append(_SQL_COUNT_ORGANIZATION_WHERE);
1871    
1872                            boolean bindUuid = false;
1873    
1874                            if (uuid == null) {
1875                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1876                            }
1877                            else if (uuid.equals(StringPool.BLANK)) {
1878                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1879                            }
1880                            else {
1881                                    bindUuid = true;
1882    
1883                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1884                            }
1885    
1886                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1887    
1888                            String sql = query.toString();
1889    
1890                            Session session = null;
1891    
1892                            try {
1893                                    session = openSession();
1894    
1895                                    Query q = session.createQuery(sql);
1896    
1897                                    QueryPos qPos = QueryPos.getInstance(q);
1898    
1899                                    if (bindUuid) {
1900                                            qPos.add(uuid);
1901                                    }
1902    
1903                                    qPos.add(companyId);
1904    
1905                                    count = (Long)q.uniqueResult();
1906    
1907                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1908                            }
1909                            catch (Exception e) {
1910                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1911    
1912                                    throw processException(e);
1913                            }
1914                            finally {
1915                                    closeSession(session);
1916                            }
1917                    }
1918    
1919                    return count.intValue();
1920            }
1921    
1922            /**
1923             * Returns the number of organizations that the user has permission to view where uuid = &#63; and companyId = &#63;.
1924             *
1925             * @param uuid the uuid
1926             * @param companyId the company ID
1927             * @return the number of matching organizations that the user has permission to view
1928             */
1929            @Override
1930            public int filterCountByUuid_C(String uuid, long companyId) {
1931                    if (!InlineSQLHelperUtil.isEnabled()) {
1932                            return countByUuid_C(uuid, companyId);
1933                    }
1934    
1935                    StringBundler query = new StringBundler(3);
1936    
1937                    query.append(_FILTER_SQL_COUNT_ORGANIZATION_WHERE);
1938    
1939                    boolean bindUuid = false;
1940    
1941                    if (uuid == null) {
1942                            query.append(_FINDER_COLUMN_UUID_C_UUID_1_SQL);
1943                    }
1944                    else if (uuid.equals(StringPool.BLANK)) {
1945                            query.append(_FINDER_COLUMN_UUID_C_UUID_3_SQL);
1946                    }
1947                    else {
1948                            bindUuid = true;
1949    
1950                            query.append(_FINDER_COLUMN_UUID_C_UUID_2_SQL);
1951                    }
1952    
1953                    query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1954    
1955                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1956                                    Organization.class.getName(),
1957                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
1958    
1959                    Session session = null;
1960    
1961                    try {
1962                            session = openSession();
1963    
1964                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
1965    
1966                            q.addScalar(COUNT_COLUMN_NAME,
1967                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
1968    
1969                            QueryPos qPos = QueryPos.getInstance(q);
1970    
1971                            if (bindUuid) {
1972                                    qPos.add(uuid);
1973                            }
1974    
1975                            qPos.add(companyId);
1976    
1977                            Long count = (Long)q.uniqueResult();
1978    
1979                            return count.intValue();
1980                    }
1981                    catch (Exception e) {
1982                            throw processException(e);
1983                    }
1984                    finally {
1985                            closeSession(session);
1986                    }
1987            }
1988    
1989            private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "organization.uuid IS NULL AND ";
1990            private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "organization.uuid = ? AND ";
1991            private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(organization.uuid IS NULL OR organization.uuid = '') AND ";
1992            private static final String _FINDER_COLUMN_UUID_C_UUID_1_SQL = "organization.uuid_ IS NULL AND ";
1993            private static final String _FINDER_COLUMN_UUID_C_UUID_2_SQL = "organization.uuid_ = ? AND ";
1994            private static final String _FINDER_COLUMN_UUID_C_UUID_3_SQL = "(organization.uuid_ IS NULL OR organization.uuid_ = '') AND ";
1995            private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "organization.companyId = ?";
1996            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
1997                    new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
1998                            OrganizationModelImpl.FINDER_CACHE_ENABLED, OrganizationImpl.class,
1999                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByCompanyId",
2000                            new String[] {
2001                                    Long.class.getName(),
2002                                    
2003                            Integer.class.getName(), Integer.class.getName(),
2004                                    OrderByComparator.class.getName()
2005                            });
2006            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
2007                    new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
2008                            OrganizationModelImpl.FINDER_CACHE_ENABLED, OrganizationImpl.class,
2009                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCompanyId",
2010                            new String[] { Long.class.getName() },
2011                            OrganizationModelImpl.COMPANYID_COLUMN_BITMASK |
2012                            OrganizationModelImpl.NAME_COLUMN_BITMASK);
2013            public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
2014                            OrganizationModelImpl.FINDER_CACHE_ENABLED, Long.class,
2015                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
2016                            new String[] { Long.class.getName() });
2017    
2018            /**
2019             * Returns all the organizations where companyId = &#63;.
2020             *
2021             * @param companyId the company ID
2022             * @return the matching organizations
2023             */
2024            @Override
2025            public List<Organization> findByCompanyId(long companyId) {
2026                    return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
2027                            null);
2028            }
2029    
2030            /**
2031             * Returns a range of all the organizations where companyId = &#63;.
2032             *
2033             * <p>
2034             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.OrganizationModelImpl}. 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.
2035             * </p>
2036             *
2037             * @param companyId the company ID
2038             * @param start the lower bound of the range of organizations
2039             * @param end the upper bound of the range of organizations (not inclusive)
2040             * @return the range of matching organizations
2041             */
2042            @Override
2043            public List<Organization> findByCompanyId(long companyId, int start, int end) {
2044                    return findByCompanyId(companyId, start, end, null);
2045            }
2046    
2047            /**
2048             * Returns an ordered range of all the organizations where companyId = &#63;.
2049             *
2050             * <p>
2051             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.OrganizationModelImpl}. 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.
2052             * </p>
2053             *
2054             * @param companyId the company ID
2055             * @param start the lower bound of the range of organizations
2056             * @param end the upper bound of the range of organizations (not inclusive)
2057             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2058             * @return the ordered range of matching organizations
2059             */
2060            @Override
2061            public List<Organization> findByCompanyId(long companyId, int start,
2062                    int end, OrderByComparator<Organization> orderByComparator) {
2063                    boolean pagination = true;
2064                    FinderPath finderPath = null;
2065                    Object[] finderArgs = null;
2066    
2067                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2068                                    (orderByComparator == null)) {
2069                            pagination = false;
2070                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
2071                            finderArgs = new Object[] { companyId };
2072                    }
2073                    else {
2074                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
2075                            finderArgs = new Object[] { companyId, start, end, orderByComparator };
2076                    }
2077    
2078                    List<Organization> list = (List<Organization>)FinderCacheUtil.getResult(finderPath,
2079                                    finderArgs, this);
2080    
2081                    if ((list != null) && !list.isEmpty()) {
2082                            for (Organization organization : list) {
2083                                    if ((companyId != organization.getCompanyId())) {
2084                                            list = null;
2085    
2086                                            break;
2087                                    }
2088                            }
2089                    }
2090    
2091                    if (list == null) {
2092                            StringBundler query = null;
2093    
2094                            if (orderByComparator != null) {
2095                                    query = new StringBundler(3 +
2096                                                    (orderByComparator.getOrderByFields().length * 3));
2097                            }
2098                            else {
2099                                    query = new StringBundler(3);
2100                            }
2101    
2102                            query.append(_SQL_SELECT_ORGANIZATION_WHERE);
2103    
2104                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2105    
2106                            if (orderByComparator != null) {
2107                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2108                                            orderByComparator);
2109                            }
2110                            else
2111                             if (pagination) {
2112                                    query.append(OrganizationModelImpl.ORDER_BY_JPQL);
2113                            }
2114    
2115                            String sql = query.toString();
2116    
2117                            Session session = null;
2118    
2119                            try {
2120                                    session = openSession();
2121    
2122                                    Query q = session.createQuery(sql);
2123    
2124                                    QueryPos qPos = QueryPos.getInstance(q);
2125    
2126                                    qPos.add(companyId);
2127    
2128                                    if (!pagination) {
2129                                            list = (List<Organization>)QueryUtil.list(q, getDialect(),
2130                                                            start, end, false);
2131    
2132                                            Collections.sort(list);
2133    
2134                                            list = Collections.unmodifiableList(list);
2135                                    }
2136                                    else {
2137                                            list = (List<Organization>)QueryUtil.list(q, getDialect(),
2138                                                            start, end);
2139                                    }
2140    
2141                                    cacheResult(list);
2142    
2143                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
2144                            }
2145                            catch (Exception e) {
2146                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2147    
2148                                    throw processException(e);
2149                            }
2150                            finally {
2151                                    closeSession(session);
2152                            }
2153                    }
2154    
2155                    return list;
2156            }
2157    
2158            /**
2159             * Returns the first organization in the ordered set where companyId = &#63;.
2160             *
2161             * @param companyId the company ID
2162             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2163             * @return the first matching organization
2164             * @throws com.liferay.portal.NoSuchOrganizationException if a matching organization could not be found
2165             */
2166            @Override
2167            public Organization findByCompanyId_First(long companyId,
2168                    OrderByComparator<Organization> orderByComparator)
2169                    throws NoSuchOrganizationException {
2170                    Organization organization = fetchByCompanyId_First(companyId,
2171                                    orderByComparator);
2172    
2173                    if (organization != null) {
2174                            return organization;
2175                    }
2176    
2177                    StringBundler msg = new StringBundler(4);
2178    
2179                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2180    
2181                    msg.append("companyId=");
2182                    msg.append(companyId);
2183    
2184                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2185    
2186                    throw new NoSuchOrganizationException(msg.toString());
2187            }
2188    
2189            /**
2190             * Returns the first organization in the ordered set where companyId = &#63;.
2191             *
2192             * @param companyId the company ID
2193             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2194             * @return the first matching organization, or <code>null</code> if a matching organization could not be found
2195             */
2196            @Override
2197            public Organization fetchByCompanyId_First(long companyId,
2198                    OrderByComparator<Organization> orderByComparator) {
2199                    List<Organization> list = findByCompanyId(companyId, 0, 1,
2200                                    orderByComparator);
2201    
2202                    if (!list.isEmpty()) {
2203                            return list.get(0);
2204                    }
2205    
2206                    return null;
2207            }
2208    
2209            /**
2210             * Returns the last organization in the ordered set where companyId = &#63;.
2211             *
2212             * @param companyId the company ID
2213             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2214             * @return the last matching organization
2215             * @throws com.liferay.portal.NoSuchOrganizationException if a matching organization could not be found
2216             */
2217            @Override
2218            public Organization findByCompanyId_Last(long companyId,
2219                    OrderByComparator<Organization> orderByComparator)
2220                    throws NoSuchOrganizationException {
2221                    Organization organization = fetchByCompanyId_Last(companyId,
2222                                    orderByComparator);
2223    
2224                    if (organization != null) {
2225                            return organization;
2226                    }
2227    
2228                    StringBundler msg = new StringBundler(4);
2229    
2230                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2231    
2232                    msg.append("companyId=");
2233                    msg.append(companyId);
2234    
2235                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2236    
2237                    throw new NoSuchOrganizationException(msg.toString());
2238            }
2239    
2240            /**
2241             * Returns the last organization in the ordered set where companyId = &#63;.
2242             *
2243             * @param companyId the company ID
2244             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2245             * @return the last matching organization, or <code>null</code> if a matching organization could not be found
2246             */
2247            @Override
2248            public Organization fetchByCompanyId_Last(long companyId,
2249                    OrderByComparator<Organization> orderByComparator) {
2250                    int count = countByCompanyId(companyId);
2251    
2252                    if (count == 0) {
2253                            return null;
2254                    }
2255    
2256                    List<Organization> list = findByCompanyId(companyId, count - 1, count,
2257                                    orderByComparator);
2258    
2259                    if (!list.isEmpty()) {
2260                            return list.get(0);
2261                    }
2262    
2263                    return null;
2264            }
2265    
2266            /**
2267             * Returns the organizations before and after the current organization in the ordered set where companyId = &#63;.
2268             *
2269             * @param organizationId the primary key of the current organization
2270             * @param companyId the company ID
2271             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2272             * @return the previous, current, and next organization
2273             * @throws com.liferay.portal.NoSuchOrganizationException if a organization with the primary key could not be found
2274             */
2275            @Override
2276            public Organization[] findByCompanyId_PrevAndNext(long organizationId,
2277                    long companyId, OrderByComparator<Organization> orderByComparator)
2278                    throws NoSuchOrganizationException {
2279                    Organization organization = findByPrimaryKey(organizationId);
2280    
2281                    Session session = null;
2282    
2283                    try {
2284                            session = openSession();
2285    
2286                            Organization[] array = new OrganizationImpl[3];
2287    
2288                            array[0] = getByCompanyId_PrevAndNext(session, organization,
2289                                            companyId, orderByComparator, true);
2290    
2291                            array[1] = organization;
2292    
2293                            array[2] = getByCompanyId_PrevAndNext(session, organization,
2294                                            companyId, orderByComparator, false);
2295    
2296                            return array;
2297                    }
2298                    catch (Exception e) {
2299                            throw processException(e);
2300                    }
2301                    finally {
2302                            closeSession(session);
2303                    }
2304            }
2305    
2306            protected Organization getByCompanyId_PrevAndNext(Session session,
2307                    Organization organization, long companyId,
2308                    OrderByComparator<Organization> orderByComparator, boolean previous) {
2309                    StringBundler query = null;
2310    
2311                    if (orderByComparator != null) {
2312                            query = new StringBundler(6 +
2313                                            (orderByComparator.getOrderByFields().length * 6));
2314                    }
2315                    else {
2316                            query = new StringBundler(3);
2317                    }
2318    
2319                    query.append(_SQL_SELECT_ORGANIZATION_WHERE);
2320    
2321                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2322    
2323                    if (orderByComparator != null) {
2324                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2325    
2326                            if (orderByConditionFields.length > 0) {
2327                                    query.append(WHERE_AND);
2328                            }
2329    
2330                            for (int i = 0; i < orderByConditionFields.length; i++) {
2331                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2332                                    query.append(orderByConditionFields[i]);
2333    
2334                                    if ((i + 1) < orderByConditionFields.length) {
2335                                            if (orderByComparator.isAscending() ^ previous) {
2336                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2337                                            }
2338                                            else {
2339                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2340                                            }
2341                                    }
2342                                    else {
2343                                            if (orderByComparator.isAscending() ^ previous) {
2344                                                    query.append(WHERE_GREATER_THAN);
2345                                            }
2346                                            else {
2347                                                    query.append(WHERE_LESSER_THAN);
2348                                            }
2349                                    }
2350                            }
2351    
2352                            query.append(ORDER_BY_CLAUSE);
2353    
2354                            String[] orderByFields = orderByComparator.getOrderByFields();
2355    
2356                            for (int i = 0; i < orderByFields.length; i++) {
2357                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2358                                    query.append(orderByFields[i]);
2359    
2360                                    if ((i + 1) < orderByFields.length) {
2361                                            if (orderByComparator.isAscending() ^ previous) {
2362                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2363                                            }
2364                                            else {
2365                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2366                                            }
2367                                    }
2368                                    else {
2369                                            if (orderByComparator.isAscending() ^ previous) {
2370                                                    query.append(ORDER_BY_ASC);
2371                                            }
2372                                            else {
2373                                                    query.append(ORDER_BY_DESC);
2374                                            }
2375                                    }
2376                            }
2377                    }
2378                    else {
2379                            query.append(OrganizationModelImpl.ORDER_BY_JPQL);
2380                    }
2381    
2382                    String sql = query.toString();
2383    
2384                    Query q = session.createQuery(sql);
2385    
2386                    q.setFirstResult(0);
2387                    q.setMaxResults(2);
2388    
2389                    QueryPos qPos = QueryPos.getInstance(q);
2390    
2391                    qPos.add(companyId);
2392    
2393                    if (orderByComparator != null) {
2394                            Object[] values = orderByComparator.getOrderByConditionValues(organization);
2395    
2396                            for (Object value : values) {
2397                                    qPos.add(value);
2398                            }
2399                    }
2400    
2401                    List<Organization> list = q.list();
2402    
2403                    if (list.size() == 2) {
2404                            return list.get(1);
2405                    }
2406                    else {
2407                            return null;
2408                    }
2409            }
2410    
2411            /**
2412             * Returns all the organizations that the user has permission to view where companyId = &#63;.
2413             *
2414             * @param companyId the company ID
2415             * @return the matching organizations that the user has permission to view
2416             */
2417            @Override
2418            public List<Organization> filterFindByCompanyId(long companyId) {
2419                    return filterFindByCompanyId(companyId, QueryUtil.ALL_POS,
2420                            QueryUtil.ALL_POS, null);
2421            }
2422    
2423            /**
2424             * Returns a range of all the organizations that the user has permission to view where companyId = &#63;.
2425             *
2426             * <p>
2427             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.OrganizationModelImpl}. 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.
2428             * </p>
2429             *
2430             * @param companyId the company ID
2431             * @param start the lower bound of the range of organizations
2432             * @param end the upper bound of the range of organizations (not inclusive)
2433             * @return the range of matching organizations that the user has permission to view
2434             */
2435            @Override
2436            public List<Organization> filterFindByCompanyId(long companyId, int start,
2437                    int end) {
2438                    return filterFindByCompanyId(companyId, start, end, null);
2439            }
2440    
2441            /**
2442             * Returns an ordered range of all the organizations that the user has permissions to view where companyId = &#63;.
2443             *
2444             * <p>
2445             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.OrganizationModelImpl}. 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.
2446             * </p>
2447             *
2448             * @param companyId the company ID
2449             * @param start the lower bound of the range of organizations
2450             * @param end the upper bound of the range of organizations (not inclusive)
2451             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2452             * @return the ordered range of matching organizations that the user has permission to view
2453             */
2454            @Override
2455            public List<Organization> filterFindByCompanyId(long companyId, int start,
2456                    int end, OrderByComparator<Organization> orderByComparator) {
2457                    if (!InlineSQLHelperUtil.isEnabled()) {
2458                            return findByCompanyId(companyId, start, end, orderByComparator);
2459                    }
2460    
2461                    StringBundler query = null;
2462    
2463                    if (orderByComparator != null) {
2464                            query = new StringBundler(3 +
2465                                            (orderByComparator.getOrderByFields().length * 3));
2466                    }
2467                    else {
2468                            query = new StringBundler(3);
2469                    }
2470    
2471                    if (getDB().isSupportsInlineDistinct()) {
2472                            query.append(_FILTER_SQL_SELECT_ORGANIZATION_WHERE);
2473                    }
2474                    else {
2475                            query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_1);
2476                    }
2477    
2478                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2479    
2480                    if (!getDB().isSupportsInlineDistinct()) {
2481                            query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_2);
2482                    }
2483    
2484                    if (orderByComparator != null) {
2485                            if (getDB().isSupportsInlineDistinct()) {
2486                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2487                                            orderByComparator, true);
2488                            }
2489                            else {
2490                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
2491                                            orderByComparator, true);
2492                            }
2493                    }
2494                    else {
2495                            if (getDB().isSupportsInlineDistinct()) {
2496                                    query.append(OrganizationModelImpl.ORDER_BY_JPQL);
2497                            }
2498                            else {
2499                                    query.append(OrganizationModelImpl.ORDER_BY_SQL);
2500                            }
2501                    }
2502    
2503                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2504                                    Organization.class.getName(),
2505                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
2506    
2507                    Session session = null;
2508    
2509                    try {
2510                            session = openSession();
2511    
2512                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
2513    
2514                            if (getDB().isSupportsInlineDistinct()) {
2515                                    q.addEntity(_FILTER_ENTITY_ALIAS, OrganizationImpl.class);
2516                            }
2517                            else {
2518                                    q.addEntity(_FILTER_ENTITY_TABLE, OrganizationImpl.class);
2519                            }
2520    
2521                            QueryPos qPos = QueryPos.getInstance(q);
2522    
2523                            qPos.add(companyId);
2524    
2525                            return (List<Organization>)QueryUtil.list(q, getDialect(), start,
2526                                    end);
2527                    }
2528                    catch (Exception e) {
2529                            throw processException(e);
2530                    }
2531                    finally {
2532                            closeSession(session);
2533                    }
2534            }
2535    
2536            /**
2537             * Returns the organizations before and after the current organization in the ordered set of organizations that the user has permission to view where companyId = &#63;.
2538             *
2539             * @param organizationId the primary key of the current organization
2540             * @param companyId the company ID
2541             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2542             * @return the previous, current, and next organization
2543             * @throws com.liferay.portal.NoSuchOrganizationException if a organization with the primary key could not be found
2544             */
2545            @Override
2546            public Organization[] filterFindByCompanyId_PrevAndNext(
2547                    long organizationId, long companyId,
2548                    OrderByComparator<Organization> orderByComparator)
2549                    throws NoSuchOrganizationException {
2550                    if (!InlineSQLHelperUtil.isEnabled()) {
2551                            return findByCompanyId_PrevAndNext(organizationId, companyId,
2552                                    orderByComparator);
2553                    }
2554    
2555                    Organization organization = findByPrimaryKey(organizationId);
2556    
2557                    Session session = null;
2558    
2559                    try {
2560                            session = openSession();
2561    
2562                            Organization[] array = new OrganizationImpl[3];
2563    
2564                            array[0] = filterGetByCompanyId_PrevAndNext(session, organization,
2565                                            companyId, orderByComparator, true);
2566    
2567                            array[1] = organization;
2568    
2569                            array[2] = filterGetByCompanyId_PrevAndNext(session, organization,
2570                                            companyId, orderByComparator, false);
2571    
2572                            return array;
2573                    }
2574                    catch (Exception e) {
2575                            throw processException(e);
2576                    }
2577                    finally {
2578                            closeSession(session);
2579                    }
2580            }
2581    
2582            protected Organization filterGetByCompanyId_PrevAndNext(Session session,
2583                    Organization organization, long companyId,
2584                    OrderByComparator<Organization> orderByComparator, boolean previous) {
2585                    StringBundler query = null;
2586    
2587                    if (orderByComparator != null) {
2588                            query = new StringBundler(6 +
2589                                            (orderByComparator.getOrderByFields().length * 6));
2590                    }
2591                    else {
2592                            query = new StringBundler(3);
2593                    }
2594    
2595                    if (getDB().isSupportsInlineDistinct()) {
2596                            query.append(_FILTER_SQL_SELECT_ORGANIZATION_WHERE);
2597                    }
2598                    else {
2599                            query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_1);
2600                    }
2601    
2602                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2603    
2604                    if (!getDB().isSupportsInlineDistinct()) {
2605                            query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_2);
2606                    }
2607    
2608                    if (orderByComparator != null) {
2609                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2610    
2611                            if (orderByConditionFields.length > 0) {
2612                                    query.append(WHERE_AND);
2613                            }
2614    
2615                            for (int i = 0; i < orderByConditionFields.length; i++) {
2616                                    if (getDB().isSupportsInlineDistinct()) {
2617                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2618                                    }
2619                                    else {
2620                                            query.append(_ORDER_BY_ENTITY_TABLE);
2621                                    }
2622    
2623                                    query.append(orderByConditionFields[i]);
2624    
2625                                    if ((i + 1) < orderByConditionFields.length) {
2626                                            if (orderByComparator.isAscending() ^ previous) {
2627                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2628                                            }
2629                                            else {
2630                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2631                                            }
2632                                    }
2633                                    else {
2634                                            if (orderByComparator.isAscending() ^ previous) {
2635                                                    query.append(WHERE_GREATER_THAN);
2636                                            }
2637                                            else {
2638                                                    query.append(WHERE_LESSER_THAN);
2639                                            }
2640                                    }
2641                            }
2642    
2643                            query.append(ORDER_BY_CLAUSE);
2644    
2645                            String[] orderByFields = orderByComparator.getOrderByFields();
2646    
2647                            for (int i = 0; i < orderByFields.length; i++) {
2648                                    if (getDB().isSupportsInlineDistinct()) {
2649                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2650                                    }
2651                                    else {
2652                                            query.append(_ORDER_BY_ENTITY_TABLE);
2653                                    }
2654    
2655                                    query.append(orderByFields[i]);
2656    
2657                                    if ((i + 1) < orderByFields.length) {
2658                                            if (orderByComparator.isAscending() ^ previous) {
2659                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2660                                            }
2661                                            else {
2662                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2663                                            }
2664                                    }
2665                                    else {
2666                                            if (orderByComparator.isAscending() ^ previous) {
2667                                                    query.append(ORDER_BY_ASC);
2668                                            }
2669                                            else {
2670                                                    query.append(ORDER_BY_DESC);
2671                                            }
2672                                    }
2673                            }
2674                    }
2675                    else {
2676                            if (getDB().isSupportsInlineDistinct()) {
2677                                    query.append(OrganizationModelImpl.ORDER_BY_JPQL);
2678                            }
2679                            else {
2680                                    query.append(OrganizationModelImpl.ORDER_BY_SQL);
2681                            }
2682                    }
2683    
2684                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2685                                    Organization.class.getName(),
2686                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
2687    
2688                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
2689    
2690                    q.setFirstResult(0);
2691                    q.setMaxResults(2);
2692    
2693                    if (getDB().isSupportsInlineDistinct()) {
2694                            q.addEntity(_FILTER_ENTITY_ALIAS, OrganizationImpl.class);
2695                    }
2696                    else {
2697                            q.addEntity(_FILTER_ENTITY_TABLE, OrganizationImpl.class);
2698                    }
2699    
2700                    QueryPos qPos = QueryPos.getInstance(q);
2701    
2702                    qPos.add(companyId);
2703    
2704                    if (orderByComparator != null) {
2705                            Object[] values = orderByComparator.getOrderByConditionValues(organization);
2706    
2707                            for (Object value : values) {
2708                                    qPos.add(value);
2709                            }
2710                    }
2711    
2712                    List<Organization> list = q.list();
2713    
2714                    if (list.size() == 2) {
2715                            return list.get(1);
2716                    }
2717                    else {
2718                            return null;
2719                    }
2720            }
2721    
2722            /**
2723             * Removes all the organizations where companyId = &#63; from the database.
2724             *
2725             * @param companyId the company ID
2726             */
2727            @Override
2728            public void removeByCompanyId(long companyId) {
2729                    for (Organization organization : findByCompanyId(companyId,
2730                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2731                            remove(organization);
2732                    }
2733            }
2734    
2735            /**
2736             * Returns the number of organizations where companyId = &#63;.
2737             *
2738             * @param companyId the company ID
2739             * @return the number of matching organizations
2740             */
2741            @Override
2742            public int countByCompanyId(long companyId) {
2743                    FinderPath finderPath = FINDER_PATH_COUNT_BY_COMPANYID;
2744    
2745                    Object[] finderArgs = new Object[] { companyId };
2746    
2747                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2748                                    this);
2749    
2750                    if (count == null) {
2751                            StringBundler query = new StringBundler(2);
2752    
2753                            query.append(_SQL_COUNT_ORGANIZATION_WHERE);
2754    
2755                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2756    
2757                            String sql = query.toString();
2758    
2759                            Session session = null;
2760    
2761                            try {
2762                                    session = openSession();
2763    
2764                                    Query q = session.createQuery(sql);
2765    
2766                                    QueryPos qPos = QueryPos.getInstance(q);
2767    
2768                                    qPos.add(companyId);
2769    
2770                                    count = (Long)q.uniqueResult();
2771    
2772                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
2773                            }
2774                            catch (Exception e) {
2775                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2776    
2777                                    throw processException(e);
2778                            }
2779                            finally {
2780                                    closeSession(session);
2781                            }
2782                    }
2783    
2784                    return count.intValue();
2785            }
2786    
2787            /**
2788             * Returns the number of organizations that the user has permission to view where companyId = &#63;.
2789             *
2790             * @param companyId the company ID
2791             * @return the number of matching organizations that the user has permission to view
2792             */
2793            @Override
2794            public int filterCountByCompanyId(long companyId) {
2795                    if (!InlineSQLHelperUtil.isEnabled()) {
2796                            return countByCompanyId(companyId);
2797                    }
2798    
2799                    StringBundler query = new StringBundler(2);
2800    
2801                    query.append(_FILTER_SQL_COUNT_ORGANIZATION_WHERE);
2802    
2803                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2804    
2805                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2806                                    Organization.class.getName(),
2807                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
2808    
2809                    Session session = null;
2810    
2811                    try {
2812                            session = openSession();
2813    
2814                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
2815    
2816                            q.addScalar(COUNT_COLUMN_NAME,
2817                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
2818    
2819                            QueryPos qPos = QueryPos.getInstance(q);
2820    
2821                            qPos.add(companyId);
2822    
2823                            Long count = (Long)q.uniqueResult();
2824    
2825                            return count.intValue();
2826                    }
2827                    catch (Exception e) {
2828                            throw processException(e);
2829                    }
2830                    finally {
2831                            closeSession(session);
2832                    }
2833            }
2834    
2835            private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "organization.companyId = ?";
2836            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_LOCATIONS =
2837                    new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
2838                            OrganizationModelImpl.FINDER_CACHE_ENABLED, OrganizationImpl.class,
2839                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByLocations",
2840                            new String[] {
2841                                    Long.class.getName(),
2842                                    
2843                            Integer.class.getName(), Integer.class.getName(),
2844                                    OrderByComparator.class.getName()
2845                            });
2846            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LOCATIONS =
2847                    new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
2848                            OrganizationModelImpl.FINDER_CACHE_ENABLED, OrganizationImpl.class,
2849                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByLocations",
2850                            new String[] { Long.class.getName() },
2851                            OrganizationModelImpl.COMPANYID_COLUMN_BITMASK |
2852                            OrganizationModelImpl.NAME_COLUMN_BITMASK);
2853            public static final FinderPath FINDER_PATH_COUNT_BY_LOCATIONS = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
2854                            OrganizationModelImpl.FINDER_CACHE_ENABLED, Long.class,
2855                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByLocations",
2856                            new String[] { Long.class.getName() });
2857    
2858            /**
2859             * Returns all the organizations where companyId = &#63;.
2860             *
2861             * @param companyId the company ID
2862             * @return the matching organizations
2863             */
2864            @Override
2865            public List<Organization> findByLocations(long companyId) {
2866                    return findByLocations(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
2867                            null);
2868            }
2869    
2870            /**
2871             * Returns a range of all the organizations where companyId = &#63;.
2872             *
2873             * <p>
2874             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.OrganizationModelImpl}. 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.
2875             * </p>
2876             *
2877             * @param companyId the company ID
2878             * @param start the lower bound of the range of organizations
2879             * @param end the upper bound of the range of organizations (not inclusive)
2880             * @return the range of matching organizations
2881             */
2882            @Override
2883            public List<Organization> findByLocations(long companyId, int start, int end) {
2884                    return findByLocations(companyId, start, end, null);
2885            }
2886    
2887            /**
2888             * Returns an ordered range of all the organizations where companyId = &#63;.
2889             *
2890             * <p>
2891             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.OrganizationModelImpl}. 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.
2892             * </p>
2893             *
2894             * @param companyId the company ID
2895             * @param start the lower bound of the range of organizations
2896             * @param end the upper bound of the range of organizations (not inclusive)
2897             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2898             * @return the ordered range of matching organizations
2899             */
2900            @Override
2901            public List<Organization> findByLocations(long companyId, int start,
2902                    int end, OrderByComparator<Organization> orderByComparator) {
2903                    boolean pagination = true;
2904                    FinderPath finderPath = null;
2905                    Object[] finderArgs = null;
2906    
2907                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2908                                    (orderByComparator == null)) {
2909                            pagination = false;
2910                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LOCATIONS;
2911                            finderArgs = new Object[] { companyId };
2912                    }
2913                    else {
2914                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_LOCATIONS;
2915                            finderArgs = new Object[] { companyId, start, end, orderByComparator };
2916                    }
2917    
2918                    List<Organization> list = (List<Organization>)FinderCacheUtil.getResult(finderPath,
2919                                    finderArgs, this);
2920    
2921                    if ((list != null) && !list.isEmpty()) {
2922                            for (Organization organization : list) {
2923                                    if ((companyId != organization.getCompanyId())) {
2924                                            list = null;
2925    
2926                                            break;
2927                                    }
2928                            }
2929                    }
2930    
2931                    if (list == null) {
2932                            StringBundler query = null;
2933    
2934                            if (orderByComparator != null) {
2935                                    query = new StringBundler(3 +
2936                                                    (orderByComparator.getOrderByFields().length * 3));
2937                            }
2938                            else {
2939                                    query = new StringBundler(3);
2940                            }
2941    
2942                            query.append(_SQL_SELECT_ORGANIZATION_WHERE);
2943    
2944                            query.append(_FINDER_COLUMN_LOCATIONS_COMPANYID_2);
2945    
2946                            if (orderByComparator != null) {
2947                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2948                                            orderByComparator);
2949                            }
2950                            else
2951                             if (pagination) {
2952                                    query.append(OrganizationModelImpl.ORDER_BY_JPQL);
2953                            }
2954    
2955                            String sql = query.toString();
2956    
2957                            Session session = null;
2958    
2959                            try {
2960                                    session = openSession();
2961    
2962                                    Query q = session.createQuery(sql);
2963    
2964                                    QueryPos qPos = QueryPos.getInstance(q);
2965    
2966                                    qPos.add(companyId);
2967    
2968                                    if (!pagination) {
2969                                            list = (List<Organization>)QueryUtil.list(q, getDialect(),
2970                                                            start, end, false);
2971    
2972                                            Collections.sort(list);
2973    
2974                                            list = Collections.unmodifiableList(list);
2975                                    }
2976                                    else {
2977                                            list = (List<Organization>)QueryUtil.list(q, getDialect(),
2978                                                            start, end);
2979                                    }
2980    
2981                                    cacheResult(list);
2982    
2983                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
2984                            }
2985                            catch (Exception e) {
2986                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2987    
2988                                    throw processException(e);
2989                            }
2990                            finally {
2991                                    closeSession(session);
2992                            }
2993                    }
2994    
2995                    return list;
2996            }
2997    
2998            /**
2999             * Returns the first organization in the ordered set where companyId = &#63;.
3000             *
3001             * @param companyId the company ID
3002             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3003             * @return the first matching organization
3004             * @throws com.liferay.portal.NoSuchOrganizationException if a matching organization could not be found
3005             */
3006            @Override
3007            public Organization findByLocations_First(long companyId,
3008                    OrderByComparator<Organization> orderByComparator)
3009                    throws NoSuchOrganizationException {
3010                    Organization organization = fetchByLocations_First(companyId,
3011                                    orderByComparator);
3012    
3013                    if (organization != null) {
3014                            return organization;
3015                    }
3016    
3017                    StringBundler msg = new StringBundler(4);
3018    
3019                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3020    
3021                    msg.append("companyId=");
3022                    msg.append(companyId);
3023    
3024                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3025    
3026                    throw new NoSuchOrganizationException(msg.toString());
3027            }
3028    
3029            /**
3030             * Returns the first organization in the ordered set where companyId = &#63;.
3031             *
3032             * @param companyId the company ID
3033             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3034             * @return the first matching organization, or <code>null</code> if a matching organization could not be found
3035             */
3036            @Override
3037            public Organization fetchByLocations_First(long companyId,
3038                    OrderByComparator<Organization> orderByComparator) {
3039                    List<Organization> list = findByLocations(companyId, 0, 1,
3040                                    orderByComparator);
3041    
3042                    if (!list.isEmpty()) {
3043                            return list.get(0);
3044                    }
3045    
3046                    return null;
3047            }
3048    
3049            /**
3050             * Returns the last organization in the ordered set where companyId = &#63;.
3051             *
3052             * @param companyId the company ID
3053             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3054             * @return the last matching organization
3055             * @throws com.liferay.portal.NoSuchOrganizationException if a matching organization could not be found
3056             */
3057            @Override
3058            public Organization findByLocations_Last(long companyId,
3059                    OrderByComparator<Organization> orderByComparator)
3060                    throws NoSuchOrganizationException {
3061                    Organization organization = fetchByLocations_Last(companyId,
3062                                    orderByComparator);
3063    
3064                    if (organization != null) {
3065                            return organization;
3066                    }
3067    
3068                    StringBundler msg = new StringBundler(4);
3069    
3070                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3071    
3072                    msg.append("companyId=");
3073                    msg.append(companyId);
3074    
3075                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3076    
3077                    throw new NoSuchOrganizationException(msg.toString());
3078            }
3079    
3080            /**
3081             * Returns the last organization in the ordered set where companyId = &#63;.
3082             *
3083             * @param companyId the company ID
3084             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3085             * @return the last matching organization, or <code>null</code> if a matching organization could not be found
3086             */
3087            @Override
3088            public Organization fetchByLocations_Last(long companyId,
3089                    OrderByComparator<Organization> orderByComparator) {
3090                    int count = countByLocations(companyId);
3091    
3092                    if (count == 0) {
3093                            return null;
3094                    }
3095    
3096                    List<Organization> list = findByLocations(companyId, count - 1, count,
3097                                    orderByComparator);
3098    
3099                    if (!list.isEmpty()) {
3100                            return list.get(0);
3101                    }
3102    
3103                    return null;
3104            }
3105    
3106            /**
3107             * Returns the organizations before and after the current organization in the ordered set where companyId = &#63;.
3108             *
3109             * @param organizationId the primary key of the current organization
3110             * @param companyId the company ID
3111             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3112             * @return the previous, current, and next organization
3113             * @throws com.liferay.portal.NoSuchOrganizationException if a organization with the primary key could not be found
3114             */
3115            @Override
3116            public Organization[] findByLocations_PrevAndNext(long organizationId,
3117                    long companyId, OrderByComparator<Organization> orderByComparator)
3118                    throws NoSuchOrganizationException {
3119                    Organization organization = findByPrimaryKey(organizationId);
3120    
3121                    Session session = null;
3122    
3123                    try {
3124                            session = openSession();
3125    
3126                            Organization[] array = new OrganizationImpl[3];
3127    
3128                            array[0] = getByLocations_PrevAndNext(session, organization,
3129                                            companyId, orderByComparator, true);
3130    
3131                            array[1] = organization;
3132    
3133                            array[2] = getByLocations_PrevAndNext(session, organization,
3134                                            companyId, orderByComparator, false);
3135    
3136                            return array;
3137                    }
3138                    catch (Exception e) {
3139                            throw processException(e);
3140                    }
3141                    finally {
3142                            closeSession(session);
3143                    }
3144            }
3145    
3146            protected Organization getByLocations_PrevAndNext(Session session,
3147                    Organization organization, long companyId,
3148                    OrderByComparator<Organization> orderByComparator, boolean previous) {
3149                    StringBundler query = null;
3150    
3151                    if (orderByComparator != null) {
3152                            query = new StringBundler(6 +
3153                                            (orderByComparator.getOrderByFields().length * 6));
3154                    }
3155                    else {
3156                            query = new StringBundler(3);
3157                    }
3158    
3159                    query.append(_SQL_SELECT_ORGANIZATION_WHERE);
3160    
3161                    query.append(_FINDER_COLUMN_LOCATIONS_COMPANYID_2);
3162    
3163                    if (orderByComparator != null) {
3164                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3165    
3166                            if (orderByConditionFields.length > 0) {
3167                                    query.append(WHERE_AND);
3168                            }
3169    
3170                            for (int i = 0; i < orderByConditionFields.length; i++) {
3171                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3172                                    query.append(orderByConditionFields[i]);
3173    
3174                                    if ((i + 1) < orderByConditionFields.length) {
3175                                            if (orderByComparator.isAscending() ^ previous) {
3176                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3177                                            }
3178                                            else {
3179                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3180                                            }
3181                                    }
3182                                    else {
3183                                            if (orderByComparator.isAscending() ^ previous) {
3184                                                    query.append(WHERE_GREATER_THAN);
3185                                            }
3186                                            else {
3187                                                    query.append(WHERE_LESSER_THAN);
3188                                            }
3189                                    }
3190                            }
3191    
3192                            query.append(ORDER_BY_CLAUSE);
3193    
3194                            String[] orderByFields = orderByComparator.getOrderByFields();
3195    
3196                            for (int i = 0; i < orderByFields.length; i++) {
3197                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3198                                    query.append(orderByFields[i]);
3199    
3200                                    if ((i + 1) < orderByFields.length) {
3201                                            if (orderByComparator.isAscending() ^ previous) {
3202                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3203                                            }
3204                                            else {
3205                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3206                                            }
3207                                    }
3208                                    else {
3209                                            if (orderByComparator.isAscending() ^ previous) {
3210                                                    query.append(ORDER_BY_ASC);
3211                                            }
3212                                            else {
3213                                                    query.append(ORDER_BY_DESC);
3214                                            }
3215                                    }
3216                            }
3217                    }
3218                    else {
3219                            query.append(OrganizationModelImpl.ORDER_BY_JPQL);
3220                    }
3221    
3222                    String sql = query.toString();
3223    
3224                    Query q = session.createQuery(sql);
3225    
3226                    q.setFirstResult(0);
3227                    q.setMaxResults(2);
3228    
3229                    QueryPos qPos = QueryPos.getInstance(q);
3230    
3231                    qPos.add(companyId);
3232    
3233                    if (orderByComparator != null) {
3234                            Object[] values = orderByComparator.getOrderByConditionValues(organization);
3235    
3236                            for (Object value : values) {
3237                                    qPos.add(value);
3238                            }
3239                    }
3240    
3241                    List<Organization> list = q.list();
3242    
3243                    if (list.size() == 2) {
3244                            return list.get(1);
3245                    }
3246                    else {
3247                            return null;
3248                    }
3249            }
3250    
3251            /**
3252             * Returns all the organizations that the user has permission to view where companyId = &#63;.
3253             *
3254             * @param companyId the company ID
3255             * @return the matching organizations that the user has permission to view
3256             */
3257            @Override
3258            public List<Organization> filterFindByLocations(long companyId) {
3259                    return filterFindByLocations(companyId, QueryUtil.ALL_POS,
3260                            QueryUtil.ALL_POS, null);
3261            }
3262    
3263            /**
3264             * Returns a range of all the organizations that the user has permission to view where companyId = &#63;.
3265             *
3266             * <p>
3267             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.OrganizationModelImpl}. 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.
3268             * </p>
3269             *
3270             * @param companyId the company ID
3271             * @param start the lower bound of the range of organizations
3272             * @param end the upper bound of the range of organizations (not inclusive)
3273             * @return the range of matching organizations that the user has permission to view
3274             */
3275            @Override
3276            public List<Organization> filterFindByLocations(long companyId, int start,
3277                    int end) {
3278                    return filterFindByLocations(companyId, start, end, null);
3279            }
3280    
3281            /**
3282             * Returns an ordered range of all the organizations that the user has permissions to view where companyId = &#63;.
3283             *
3284             * <p>
3285             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.OrganizationModelImpl}. 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.
3286             * </p>
3287             *
3288             * @param companyId the company ID
3289             * @param start the lower bound of the range of organizations
3290             * @param end the upper bound of the range of organizations (not inclusive)
3291             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3292             * @return the ordered range of matching organizations that the user has permission to view
3293             */
3294            @Override
3295            public List<Organization> filterFindByLocations(long companyId, int start,
3296                    int end, OrderByComparator<Organization> orderByComparator) {
3297                    if (!InlineSQLHelperUtil.isEnabled()) {
3298                            return findByLocations(companyId, start, end, orderByComparator);
3299                    }
3300    
3301                    StringBundler query = null;
3302    
3303                    if (orderByComparator != null) {
3304                            query = new StringBundler(3 +
3305                                            (orderByComparator.getOrderByFields().length * 3));
3306                    }
3307                    else {
3308                            query = new StringBundler(3);
3309                    }
3310    
3311                    if (getDB().isSupportsInlineDistinct()) {
3312                            query.append(_FILTER_SQL_SELECT_ORGANIZATION_WHERE);
3313                    }
3314                    else {
3315                            query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_1);
3316                    }
3317    
3318                    query.append(_FINDER_COLUMN_LOCATIONS_COMPANYID_2);
3319    
3320                    if (!getDB().isSupportsInlineDistinct()) {
3321                            query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_2);
3322                    }
3323    
3324                    if (orderByComparator != null) {
3325                            if (getDB().isSupportsInlineDistinct()) {
3326                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3327                                            orderByComparator, true);
3328                            }
3329                            else {
3330                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
3331                                            orderByComparator, true);
3332                            }
3333                    }
3334                    else {
3335                            if (getDB().isSupportsInlineDistinct()) {
3336                                    query.append(OrganizationModelImpl.ORDER_BY_JPQL);
3337                            }
3338                            else {
3339                                    query.append(OrganizationModelImpl.ORDER_BY_SQL);
3340                            }
3341                    }
3342    
3343                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3344                                    Organization.class.getName(),
3345                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
3346    
3347                    Session session = null;
3348    
3349                    try {
3350                            session = openSession();
3351    
3352                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
3353    
3354                            if (getDB().isSupportsInlineDistinct()) {
3355                                    q.addEntity(_FILTER_ENTITY_ALIAS, OrganizationImpl.class);
3356                            }
3357                            else {
3358                                    q.addEntity(_FILTER_ENTITY_TABLE, OrganizationImpl.class);
3359                            }
3360    
3361                            QueryPos qPos = QueryPos.getInstance(q);
3362    
3363                            qPos.add(companyId);
3364    
3365                            return (List<Organization>)QueryUtil.list(q, getDialect(), start,
3366                                    end);
3367                    }
3368                    catch (Exception e) {
3369                            throw processException(e);
3370                    }
3371                    finally {
3372                            closeSession(session);
3373                    }
3374            }
3375    
3376            /**
3377             * Returns the organizations before and after the current organization in the ordered set of organizations that the user has permission to view where companyId = &#63;.
3378             *
3379             * @param organizationId the primary key of the current organization
3380             * @param companyId the company ID
3381             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3382             * @return the previous, current, and next organization
3383             * @throws com.liferay.portal.NoSuchOrganizationException if a organization with the primary key could not be found
3384             */
3385            @Override
3386            public Organization[] filterFindByLocations_PrevAndNext(
3387                    long organizationId, long companyId,
3388                    OrderByComparator<Organization> orderByComparator)
3389                    throws NoSuchOrganizationException {
3390                    if (!InlineSQLHelperUtil.isEnabled()) {
3391                            return findByLocations_PrevAndNext(organizationId, companyId,
3392                                    orderByComparator);
3393                    }
3394    
3395                    Organization organization = findByPrimaryKey(organizationId);
3396    
3397                    Session session = null;
3398    
3399                    try {
3400                            session = openSession();
3401    
3402                            Organization[] array = new OrganizationImpl[3];
3403    
3404                            array[0] = filterGetByLocations_PrevAndNext(session, organization,
3405                                            companyId, orderByComparator, true);
3406    
3407                            array[1] = organization;
3408    
3409                            array[2] = filterGetByLocations_PrevAndNext(session, organization,
3410                                            companyId, orderByComparator, false);
3411    
3412                            return array;
3413                    }
3414                    catch (Exception e) {
3415                            throw processException(e);
3416                    }
3417                    finally {
3418                            closeSession(session);
3419                    }
3420            }
3421    
3422            protected Organization filterGetByLocations_PrevAndNext(Session session,
3423                    Organization organization, long companyId,
3424                    OrderByComparator<Organization> orderByComparator, boolean previous) {
3425                    StringBundler query = null;
3426    
3427                    if (orderByComparator != null) {
3428                            query = new StringBundler(6 +
3429                                            (orderByComparator.getOrderByFields().length * 6));
3430                    }
3431                    else {
3432                            query = new StringBundler(3);
3433                    }
3434    
3435                    if (getDB().isSupportsInlineDistinct()) {
3436                            query.append(_FILTER_SQL_SELECT_ORGANIZATION_WHERE);
3437                    }
3438                    else {
3439                            query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_1);
3440                    }
3441    
3442                    query.append(_FINDER_COLUMN_LOCATIONS_COMPANYID_2);
3443    
3444                    if (!getDB().isSupportsInlineDistinct()) {
3445                            query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_2);
3446                    }
3447    
3448                    if (orderByComparator != null) {
3449                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3450    
3451                            if (orderByConditionFields.length > 0) {
3452                                    query.append(WHERE_AND);
3453                            }
3454    
3455                            for (int i = 0; i < orderByConditionFields.length; i++) {
3456                                    if (getDB().isSupportsInlineDistinct()) {
3457                                            query.append(_ORDER_BY_ENTITY_ALIAS);
3458                                    }
3459                                    else {
3460                                            query.append(_ORDER_BY_ENTITY_TABLE);
3461                                    }
3462    
3463                                    query.append(orderByConditionFields[i]);
3464    
3465                                    if ((i + 1) < orderByConditionFields.length) {
3466                                            if (orderByComparator.isAscending() ^ previous) {
3467                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3468                                            }
3469                                            else {
3470                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3471                                            }
3472                                    }
3473                                    else {
3474                                            if (orderByComparator.isAscending() ^ previous) {
3475                                                    query.append(WHERE_GREATER_THAN);
3476                                            }
3477                                            else {
3478                                                    query.append(WHERE_LESSER_THAN);
3479                                            }
3480                                    }
3481                            }
3482    
3483                            query.append(ORDER_BY_CLAUSE);
3484    
3485                            String[] orderByFields = orderByComparator.getOrderByFields();
3486    
3487                            for (int i = 0; i < orderByFields.length; i++) {
3488                                    if (getDB().isSupportsInlineDistinct()) {
3489                                            query.append(_ORDER_BY_ENTITY_ALIAS);
3490                                    }
3491                                    else {
3492                                            query.append(_ORDER_BY_ENTITY_TABLE);
3493                                    }
3494    
3495                                    query.append(orderByFields[i]);
3496    
3497                                    if ((i + 1) < orderByFields.length) {
3498                                            if (orderByComparator.isAscending() ^ previous) {
3499                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3500                                            }
3501                                            else {
3502                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3503                                            }
3504                                    }
3505                                    else {
3506                                            if (orderByComparator.isAscending() ^ previous) {
3507                                                    query.append(ORDER_BY_ASC);
3508                                            }
3509                                            else {
3510                                                    query.append(ORDER_BY_DESC);
3511                                            }
3512                                    }
3513                            }
3514                    }
3515                    else {
3516                            if (getDB().isSupportsInlineDistinct()) {
3517                                    query.append(OrganizationModelImpl.ORDER_BY_JPQL);
3518                            }
3519                            else {
3520                                    query.append(OrganizationModelImpl.ORDER_BY_SQL);
3521                            }
3522                    }
3523    
3524                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3525                                    Organization.class.getName(),
3526                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
3527    
3528                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
3529    
3530                    q.setFirstResult(0);
3531                    q.setMaxResults(2);
3532    
3533                    if (getDB().isSupportsInlineDistinct()) {
3534                            q.addEntity(_FILTER_ENTITY_ALIAS, OrganizationImpl.class);
3535                    }
3536                    else {
3537                            q.addEntity(_FILTER_ENTITY_TABLE, OrganizationImpl.class);
3538                    }
3539    
3540                    QueryPos qPos = QueryPos.getInstance(q);
3541    
3542                    qPos.add(companyId);
3543    
3544                    if (orderByComparator != null) {
3545                            Object[] values = orderByComparator.getOrderByConditionValues(organization);
3546    
3547                            for (Object value : values) {
3548                                    qPos.add(value);
3549                            }
3550                    }
3551    
3552                    List<Organization> list = q.list();
3553    
3554                    if (list.size() == 2) {
3555                            return list.get(1);
3556                    }
3557                    else {
3558                            return null;
3559                    }
3560            }
3561    
3562            /**
3563             * Removes all the organizations where companyId = &#63; from the database.
3564             *
3565             * @param companyId the company ID
3566             */
3567            @Override
3568            public void removeByLocations(long companyId) {
3569                    for (Organization organization : findByLocations(companyId,
3570                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
3571                            remove(organization);
3572                    }
3573            }
3574    
3575            /**
3576             * Returns the number of organizations where companyId = &#63;.
3577             *
3578             * @param companyId the company ID
3579             * @return the number of matching organizations
3580             */
3581            @Override
3582            public int countByLocations(long companyId) {
3583                    FinderPath finderPath = FINDER_PATH_COUNT_BY_LOCATIONS;
3584    
3585                    Object[] finderArgs = new Object[] { companyId };
3586    
3587                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
3588                                    this);
3589    
3590                    if (count == null) {
3591                            StringBundler query = new StringBundler(2);
3592    
3593                            query.append(_SQL_COUNT_ORGANIZATION_WHERE);
3594    
3595                            query.append(_FINDER_COLUMN_LOCATIONS_COMPANYID_2);
3596    
3597                            String sql = query.toString();
3598    
3599                            Session session = null;
3600    
3601                            try {
3602                                    session = openSession();
3603    
3604                                    Query q = session.createQuery(sql);
3605    
3606                                    QueryPos qPos = QueryPos.getInstance(q);
3607    
3608                                    qPos.add(companyId);
3609    
3610                                    count = (Long)q.uniqueResult();
3611    
3612                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
3613                            }
3614                            catch (Exception e) {
3615                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3616    
3617                                    throw processException(e);
3618                            }
3619                            finally {
3620                                    closeSession(session);
3621                            }
3622                    }
3623    
3624                    return count.intValue();
3625            }
3626    
3627            /**
3628             * Returns the number of organizations that the user has permission to view where companyId = &#63;.
3629             *
3630             * @param companyId the company ID
3631             * @return the number of matching organizations that the user has permission to view
3632             */
3633            @Override
3634            public int filterCountByLocations(long companyId) {
3635                    if (!InlineSQLHelperUtil.isEnabled()) {
3636                            return countByLocations(companyId);
3637                    }
3638    
3639                    StringBundler query = new StringBundler(2);
3640    
3641                    query.append(_FILTER_SQL_COUNT_ORGANIZATION_WHERE);
3642    
3643                    query.append(_FINDER_COLUMN_LOCATIONS_COMPANYID_2);
3644    
3645                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3646                                    Organization.class.getName(),
3647                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
3648    
3649                    Session session = null;
3650    
3651                    try {
3652                            session = openSession();
3653    
3654                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
3655    
3656                            q.addScalar(COUNT_COLUMN_NAME,
3657                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
3658    
3659                            QueryPos qPos = QueryPos.getInstance(q);
3660    
3661                            qPos.add(companyId);
3662    
3663                            Long count = (Long)q.uniqueResult();
3664    
3665                            return count.intValue();
3666                    }
3667                    catch (Exception e) {
3668                            throw processException(e);
3669                    }
3670                    finally {
3671                            closeSession(session);
3672                    }
3673            }
3674    
3675            private static final String _FINDER_COLUMN_LOCATIONS_COMPANYID_2 = "organization.companyId = ? AND organization.parentOrganizationId != 0";
3676            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_P = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
3677                            OrganizationModelImpl.FINDER_CACHE_ENABLED, OrganizationImpl.class,
3678                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_P",
3679                            new String[] {
3680                                    Long.class.getName(), Long.class.getName(),
3681                                    
3682                            Integer.class.getName(), Integer.class.getName(),
3683                                    OrderByComparator.class.getName()
3684                            });
3685            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
3686                            OrganizationModelImpl.FINDER_CACHE_ENABLED, OrganizationImpl.class,
3687                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_P",
3688                            new String[] { Long.class.getName(), Long.class.getName() },
3689                            OrganizationModelImpl.COMPANYID_COLUMN_BITMASK |
3690                            OrganizationModelImpl.PARENTORGANIZATIONID_COLUMN_BITMASK |
3691                            OrganizationModelImpl.NAME_COLUMN_BITMASK);
3692            public static final FinderPath FINDER_PATH_COUNT_BY_C_P = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
3693                            OrganizationModelImpl.FINDER_CACHE_ENABLED, Long.class,
3694                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_P",
3695                            new String[] { Long.class.getName(), Long.class.getName() });
3696    
3697            /**
3698             * Returns all the organizations where companyId = &#63; and parentOrganizationId = &#63;.
3699             *
3700             * @param companyId the company ID
3701             * @param parentOrganizationId the parent organization ID
3702             * @return the matching organizations
3703             */
3704            @Override
3705            public List<Organization> findByC_P(long companyId,
3706                    long parentOrganizationId) {
3707                    return findByC_P(companyId, parentOrganizationId, QueryUtil.ALL_POS,
3708                            QueryUtil.ALL_POS, null);
3709            }
3710    
3711            /**
3712             * Returns a range of all the organizations where companyId = &#63; and parentOrganizationId = &#63;.
3713             *
3714             * <p>
3715             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.OrganizationModelImpl}. 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.
3716             * </p>
3717             *
3718             * @param companyId the company ID
3719             * @param parentOrganizationId the parent organization ID
3720             * @param start the lower bound of the range of organizations
3721             * @param end the upper bound of the range of organizations (not inclusive)
3722             * @return the range of matching organizations
3723             */
3724            @Override
3725            public List<Organization> findByC_P(long companyId,
3726                    long parentOrganizationId, int start, int end) {
3727                    return findByC_P(companyId, parentOrganizationId, start, end, null);
3728            }
3729    
3730            /**
3731             * Returns an ordered range of all the organizations where companyId = &#63; and parentOrganizationId = &#63;.
3732             *
3733             * <p>
3734             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.OrganizationModelImpl}. 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.
3735             * </p>
3736             *
3737             * @param companyId the company ID
3738             * @param parentOrganizationId the parent organization ID
3739             * @param start the lower bound of the range of organizations
3740             * @param end the upper bound of the range of organizations (not inclusive)
3741             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3742             * @return the ordered range of matching organizations
3743             */
3744            @Override
3745            public List<Organization> findByC_P(long companyId,
3746                    long parentOrganizationId, int start, int end,
3747                    OrderByComparator<Organization> orderByComparator) {
3748                    boolean pagination = true;
3749                    FinderPath finderPath = null;
3750                    Object[] finderArgs = null;
3751    
3752                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3753                                    (orderByComparator == null)) {
3754                            pagination = false;
3755                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P;
3756                            finderArgs = new Object[] { companyId, parentOrganizationId };
3757                    }
3758                    else {
3759                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_P;
3760                            finderArgs = new Object[] {
3761                                            companyId, parentOrganizationId,
3762                                            
3763                                            start, end, orderByComparator
3764                                    };
3765                    }
3766    
3767                    List<Organization> list = (List<Organization>)FinderCacheUtil.getResult(finderPath,
3768                                    finderArgs, this);
3769    
3770                    if ((list != null) && !list.isEmpty()) {
3771                            for (Organization organization : list) {
3772                                    if ((companyId != organization.getCompanyId()) ||
3773                                                    (parentOrganizationId != organization.getParentOrganizationId())) {
3774                                            list = null;
3775    
3776                                            break;
3777                                    }
3778                            }
3779                    }
3780    
3781                    if (list == null) {
3782                            StringBundler query = null;
3783    
3784                            if (orderByComparator != null) {
3785                                    query = new StringBundler(4 +
3786                                                    (orderByComparator.getOrderByFields().length * 3));
3787                            }
3788                            else {
3789                                    query = new StringBundler(4);
3790                            }
3791    
3792                            query.append(_SQL_SELECT_ORGANIZATION_WHERE);
3793    
3794                            query.append(_FINDER_COLUMN_C_P_COMPANYID_2);
3795    
3796                            query.append(_FINDER_COLUMN_C_P_PARENTORGANIZATIONID_2);
3797    
3798                            if (orderByComparator != null) {
3799                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3800                                            orderByComparator);
3801                            }
3802                            else
3803                             if (pagination) {
3804                                    query.append(OrganizationModelImpl.ORDER_BY_JPQL);
3805                            }
3806    
3807                            String sql = query.toString();
3808    
3809                            Session session = null;
3810    
3811                            try {
3812                                    session = openSession();
3813    
3814                                    Query q = session.createQuery(sql);
3815    
3816                                    QueryPos qPos = QueryPos.getInstance(q);
3817    
3818                                    qPos.add(companyId);
3819    
3820                                    qPos.add(parentOrganizationId);
3821    
3822                                    if (!pagination) {
3823                                            list = (List<Organization>)QueryUtil.list(q, getDialect(),
3824                                                            start, end, false);
3825    
3826                                            Collections.sort(list);
3827    
3828                                            list = Collections.unmodifiableList(list);
3829                                    }
3830                                    else {
3831                                            list = (List<Organization>)QueryUtil.list(q, getDialect(),
3832                                                            start, end);
3833                                    }
3834    
3835                                    cacheResult(list);
3836    
3837                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
3838                            }
3839                            catch (Exception e) {
3840                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3841    
3842                                    throw processException(e);
3843                            }
3844                            finally {
3845                                    closeSession(session);
3846                            }
3847                    }
3848    
3849                    return list;
3850            }
3851    
3852            /**
3853             * Returns the first organization in the ordered set where companyId = &#63; and parentOrganizationId = &#63;.
3854             *
3855             * @param companyId the company ID
3856             * @param parentOrganizationId the parent organization ID
3857             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3858             * @return the first matching organization
3859             * @throws com.liferay.portal.NoSuchOrganizationException if a matching organization could not be found
3860             */
3861            @Override
3862            public Organization findByC_P_First(long companyId,
3863                    long parentOrganizationId,
3864                    OrderByComparator<Organization> orderByComparator)
3865                    throws NoSuchOrganizationException {
3866                    Organization organization = fetchByC_P_First(companyId,
3867                                    parentOrganizationId, orderByComparator);
3868    
3869                    if (organization != null) {
3870                            return organization;
3871                    }
3872    
3873                    StringBundler msg = new StringBundler(6);
3874    
3875                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3876    
3877                    msg.append("companyId=");
3878                    msg.append(companyId);
3879    
3880                    msg.append(", parentOrganizationId=");
3881                    msg.append(parentOrganizationId);
3882    
3883                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3884    
3885                    throw new NoSuchOrganizationException(msg.toString());
3886            }
3887    
3888            /**
3889             * Returns the first organization in the ordered set where companyId = &#63; and parentOrganizationId = &#63;.
3890             *
3891             * @param companyId the company ID
3892             * @param parentOrganizationId the parent organization ID
3893             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3894             * @return the first matching organization, or <code>null</code> if a matching organization could not be found
3895             */
3896            @Override
3897            public Organization fetchByC_P_First(long companyId,
3898                    long parentOrganizationId,
3899                    OrderByComparator<Organization> orderByComparator) {
3900                    List<Organization> list = findByC_P(companyId, parentOrganizationId, 0,
3901                                    1, orderByComparator);
3902    
3903                    if (!list.isEmpty()) {
3904                            return list.get(0);
3905                    }
3906    
3907                    return null;
3908            }
3909    
3910            /**
3911             * Returns the last organization in the ordered set where companyId = &#63; and parentOrganizationId = &#63;.
3912             *
3913             * @param companyId the company ID
3914             * @param parentOrganizationId the parent organization ID
3915             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3916             * @return the last matching organization
3917             * @throws com.liferay.portal.NoSuchOrganizationException if a matching organization could not be found
3918             */
3919            @Override
3920            public Organization findByC_P_Last(long companyId,
3921                    long parentOrganizationId,
3922                    OrderByComparator<Organization> orderByComparator)
3923                    throws NoSuchOrganizationException {
3924                    Organization organization = fetchByC_P_Last(companyId,
3925                                    parentOrganizationId, orderByComparator);
3926    
3927                    if (organization != null) {
3928                            return organization;
3929                    }
3930    
3931                    StringBundler msg = new StringBundler(6);
3932    
3933                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3934    
3935                    msg.append("companyId=");
3936                    msg.append(companyId);
3937    
3938                    msg.append(", parentOrganizationId=");
3939                    msg.append(parentOrganizationId);
3940    
3941                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3942    
3943                    throw new NoSuchOrganizationException(msg.toString());
3944            }
3945    
3946            /**
3947             * Returns the last organization in the ordered set where companyId = &#63; and parentOrganizationId = &#63;.
3948             *
3949             * @param companyId the company ID
3950             * @param parentOrganizationId the parent organization ID
3951             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3952             * @return the last matching organization, or <code>null</code> if a matching organization could not be found
3953             */
3954            @Override
3955            public Organization fetchByC_P_Last(long companyId,
3956                    long parentOrganizationId,
3957                    OrderByComparator<Organization> orderByComparator) {
3958                    int count = countByC_P(companyId, parentOrganizationId);
3959    
3960                    if (count == 0) {
3961                            return null;
3962                    }
3963    
3964                    List<Organization> list = findByC_P(companyId, parentOrganizationId,
3965                                    count - 1, count, orderByComparator);
3966    
3967                    if (!list.isEmpty()) {
3968                            return list.get(0);
3969                    }
3970    
3971                    return null;
3972            }
3973    
3974            /**
3975             * Returns the organizations before and after the current organization in the ordered set where companyId = &#63; and parentOrganizationId = &#63;.
3976             *
3977             * @param organizationId the primary key of the current organization
3978             * @param companyId the company ID
3979             * @param parentOrganizationId the parent organization ID
3980             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3981             * @return the previous, current, and next organization
3982             * @throws com.liferay.portal.NoSuchOrganizationException if a organization with the primary key could not be found
3983             */
3984            @Override
3985            public Organization[] findByC_P_PrevAndNext(long organizationId,
3986                    long companyId, long parentOrganizationId,
3987                    OrderByComparator<Organization> orderByComparator)
3988                    throws NoSuchOrganizationException {
3989                    Organization organization = findByPrimaryKey(organizationId);
3990    
3991                    Session session = null;
3992    
3993                    try {
3994                            session = openSession();
3995    
3996                            Organization[] array = new OrganizationImpl[3];
3997    
3998                            array[0] = getByC_P_PrevAndNext(session, organization, companyId,
3999                                            parentOrganizationId, orderByComparator, true);
4000    
4001                            array[1] = organization;
4002    
4003                            array[2] = getByC_P_PrevAndNext(session, organization, companyId,
4004                                            parentOrganizationId, orderByComparator, false);
4005    
4006                            return array;
4007                    }
4008                    catch (Exception e) {
4009                            throw processException(e);
4010                    }
4011                    finally {
4012                            closeSession(session);
4013                    }
4014            }
4015    
4016            protected Organization getByC_P_PrevAndNext(Session session,
4017                    Organization organization, long companyId, long parentOrganizationId,
4018                    OrderByComparator<Organization> orderByComparator, boolean previous) {
4019                    StringBundler query = null;
4020    
4021                    if (orderByComparator != null) {
4022                            query = new StringBundler(6 +
4023                                            (orderByComparator.getOrderByFields().length * 6));
4024                    }
4025                    else {
4026                            query = new StringBundler(3);
4027                    }
4028    
4029                    query.append(_SQL_SELECT_ORGANIZATION_WHERE);
4030    
4031                    query.append(_FINDER_COLUMN_C_P_COMPANYID_2);
4032    
4033                    query.append(_FINDER_COLUMN_C_P_PARENTORGANIZATIONID_2);
4034    
4035                    if (orderByComparator != null) {
4036                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4037    
4038                            if (orderByConditionFields.length > 0) {
4039                                    query.append(WHERE_AND);
4040                            }
4041    
4042                            for (int i = 0; i < orderByConditionFields.length; i++) {
4043                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4044                                    query.append(orderByConditionFields[i]);
4045    
4046                                    if ((i + 1) < orderByConditionFields.length) {
4047                                            if (orderByComparator.isAscending() ^ previous) {
4048                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4049                                            }
4050                                            else {
4051                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4052                                            }
4053                                    }
4054                                    else {
4055                                            if (orderByComparator.isAscending() ^ previous) {
4056                                                    query.append(WHERE_GREATER_THAN);
4057                                            }
4058                                            else {
4059                                                    query.append(WHERE_LESSER_THAN);
4060                                            }
4061                                    }
4062                            }
4063    
4064                            query.append(ORDER_BY_CLAUSE);
4065    
4066                            String[] orderByFields = orderByComparator.getOrderByFields();
4067    
4068                            for (int i = 0; i < orderByFields.length; i++) {
4069                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4070                                    query.append(orderByFields[i]);
4071    
4072                                    if ((i + 1) < orderByFields.length) {
4073                                            if (orderByComparator.isAscending() ^ previous) {
4074                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4075                                            }
4076                                            else {
4077                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4078                                            }
4079                                    }
4080                                    else {
4081                                            if (orderByComparator.isAscending() ^ previous) {
4082                                                    query.append(ORDER_BY_ASC);
4083                                            }
4084                                            else {
4085                                                    query.append(ORDER_BY_DESC);
4086                                            }
4087                                    }
4088                            }
4089                    }
4090                    else {
4091                            query.append(OrganizationModelImpl.ORDER_BY_JPQL);
4092                    }
4093    
4094                    String sql = query.toString();
4095    
4096                    Query q = session.createQuery(sql);
4097    
4098                    q.setFirstResult(0);
4099                    q.setMaxResults(2);
4100    
4101                    QueryPos qPos = QueryPos.getInstance(q);
4102    
4103                    qPos.add(companyId);
4104    
4105                    qPos.add(parentOrganizationId);
4106    
4107                    if (orderByComparator != null) {
4108                            Object[] values = orderByComparator.getOrderByConditionValues(organization);
4109    
4110                            for (Object value : values) {
4111                                    qPos.add(value);
4112                            }
4113                    }
4114    
4115                    List<Organization> list = q.list();
4116    
4117                    if (list.size() == 2) {
4118                            return list.get(1);
4119                    }
4120                    else {
4121                            return null;
4122                    }
4123            }
4124    
4125            /**
4126             * Returns all the organizations that the user has permission to view where companyId = &#63; and parentOrganizationId = &#63;.
4127             *
4128             * @param companyId the company ID
4129             * @param parentOrganizationId the parent organization ID
4130             * @return the matching organizations that the user has permission to view
4131             */
4132            @Override
4133            public List<Organization> filterFindByC_P(long companyId,
4134                    long parentOrganizationId) {
4135                    return filterFindByC_P(companyId, parentOrganizationId,
4136                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
4137            }
4138    
4139            /**
4140             * Returns a range of all the organizations that the user has permission to view where companyId = &#63; and parentOrganizationId = &#63;.
4141             *
4142             * <p>
4143             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.OrganizationModelImpl}. 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.
4144             * </p>
4145             *
4146             * @param companyId the company ID
4147             * @param parentOrganizationId the parent organization ID
4148             * @param start the lower bound of the range of organizations
4149             * @param end the upper bound of the range of organizations (not inclusive)
4150             * @return the range of matching organizations that the user has permission to view
4151             */
4152            @Override
4153            public List<Organization> filterFindByC_P(long companyId,
4154                    long parentOrganizationId, int start, int end) {
4155                    return filterFindByC_P(companyId, parentOrganizationId, start, end, null);
4156            }
4157    
4158            /**
4159             * Returns an ordered range of all the organizations that the user has permissions to view where companyId = &#63; and parentOrganizationId = &#63;.
4160             *
4161             * <p>
4162             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.OrganizationModelImpl}. 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.
4163             * </p>
4164             *
4165             * @param companyId the company ID
4166             * @param parentOrganizationId the parent organization ID
4167             * @param start the lower bound of the range of organizations
4168             * @param end the upper bound of the range of organizations (not inclusive)
4169             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4170             * @return the ordered range of matching organizations that the user has permission to view
4171             */
4172            @Override
4173            public List<Organization> filterFindByC_P(long companyId,
4174                    long parentOrganizationId, int start, int end,
4175                    OrderByComparator<Organization> orderByComparator) {
4176                    if (!InlineSQLHelperUtil.isEnabled()) {
4177                            return findByC_P(companyId, parentOrganizationId, start, end,
4178                                    orderByComparator);
4179                    }
4180    
4181                    StringBundler query = null;
4182    
4183                    if (orderByComparator != null) {
4184                            query = new StringBundler(4 +
4185                                            (orderByComparator.getOrderByFields().length * 3));
4186                    }
4187                    else {
4188                            query = new StringBundler(4);
4189                    }
4190    
4191                    if (getDB().isSupportsInlineDistinct()) {
4192                            query.append(_FILTER_SQL_SELECT_ORGANIZATION_WHERE);
4193                    }
4194                    else {
4195                            query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_1);
4196                    }
4197    
4198                    query.append(_FINDER_COLUMN_C_P_COMPANYID_2);
4199    
4200                    query.append(_FINDER_COLUMN_C_P_PARENTORGANIZATIONID_2);
4201    
4202                    if (!getDB().isSupportsInlineDistinct()) {
4203                            query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_2);
4204                    }
4205    
4206                    if (orderByComparator != null) {
4207                            if (getDB().isSupportsInlineDistinct()) {
4208                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4209                                            orderByComparator, true);
4210                            }
4211                            else {
4212                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
4213                                            orderByComparator, true);
4214                            }
4215                    }
4216                    else {
4217                            if (getDB().isSupportsInlineDistinct()) {
4218                                    query.append(OrganizationModelImpl.ORDER_BY_JPQL);
4219                            }
4220                            else {
4221                                    query.append(OrganizationModelImpl.ORDER_BY_SQL);
4222                            }
4223                    }
4224    
4225                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4226                                    Organization.class.getName(),
4227                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
4228    
4229                    Session session = null;
4230    
4231                    try {
4232                            session = openSession();
4233    
4234                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
4235    
4236                            if (getDB().isSupportsInlineDistinct()) {
4237                                    q.addEntity(_FILTER_ENTITY_ALIAS, OrganizationImpl.class);
4238                            }
4239                            else {
4240                                    q.addEntity(_FILTER_ENTITY_TABLE, OrganizationImpl.class);
4241                            }
4242    
4243                            QueryPos qPos = QueryPos.getInstance(q);
4244    
4245                            qPos.add(companyId);
4246    
4247                            qPos.add(parentOrganizationId);
4248    
4249                            return (List<Organization>)QueryUtil.list(q, getDialect(), start,
4250                                    end);
4251                    }
4252                    catch (Exception e) {
4253                            throw processException(e);
4254                    }
4255                    finally {
4256                            closeSession(session);
4257                    }
4258            }
4259    
4260            /**
4261             * Returns the organizations before and after the current organization in the ordered set of organizations that the user has permission to view where companyId = &#63; and parentOrganizationId = &#63;.
4262             *
4263             * @param organizationId the primary key of the current organization
4264             * @param companyId the company ID
4265             * @param parentOrganizationId the parent organization ID
4266             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4267             * @return the previous, current, and next organization
4268             * @throws com.liferay.portal.NoSuchOrganizationException if a organization with the primary key could not be found
4269             */
4270            @Override
4271            public Organization[] filterFindByC_P_PrevAndNext(long organizationId,
4272                    long companyId, long parentOrganizationId,
4273                    OrderByComparator<Organization> orderByComparator)
4274                    throws NoSuchOrganizationException {
4275                    if (!InlineSQLHelperUtil.isEnabled()) {
4276                            return findByC_P_PrevAndNext(organizationId, companyId,
4277                                    parentOrganizationId, orderByComparator);
4278                    }
4279    
4280                    Organization organization = findByPrimaryKey(organizationId);
4281    
4282                    Session session = null;
4283    
4284                    try {
4285                            session = openSession();
4286    
4287                            Organization[] array = new OrganizationImpl[3];
4288    
4289                            array[0] = filterGetByC_P_PrevAndNext(session, organization,
4290                                            companyId, parentOrganizationId, orderByComparator, true);
4291    
4292                            array[1] = organization;
4293    
4294                            array[2] = filterGetByC_P_PrevAndNext(session, organization,
4295                                            companyId, parentOrganizationId, orderByComparator, false);
4296    
4297                            return array;
4298                    }
4299                    catch (Exception e) {
4300                            throw processException(e);
4301                    }
4302                    finally {
4303                            closeSession(session);
4304                    }
4305            }
4306    
4307            protected Organization filterGetByC_P_PrevAndNext(Session session,
4308                    Organization organization, long companyId, long parentOrganizationId,
4309                    OrderByComparator<Organization> orderByComparator, boolean previous) {
4310                    StringBundler query = null;
4311    
4312                    if (orderByComparator != null) {
4313                            query = new StringBundler(6 +
4314                                            (orderByComparator.getOrderByFields().length * 6));
4315                    }
4316                    else {
4317                            query = new StringBundler(3);
4318                    }
4319    
4320                    if (getDB().isSupportsInlineDistinct()) {
4321                            query.append(_FILTER_SQL_SELECT_ORGANIZATION_WHERE);
4322                    }
4323                    else {
4324                            query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_1);
4325                    }
4326    
4327                    query.append(_FINDER_COLUMN_C_P_COMPANYID_2);
4328    
4329                    query.append(_FINDER_COLUMN_C_P_PARENTORGANIZATIONID_2);
4330    
4331                    if (!getDB().isSupportsInlineDistinct()) {
4332                            query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_2);
4333                    }
4334    
4335                    if (orderByComparator != null) {
4336                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4337    
4338                            if (orderByConditionFields.length > 0) {
4339                                    query.append(WHERE_AND);
4340                            }
4341    
4342                            for (int i = 0; i < orderByConditionFields.length; i++) {
4343                                    if (getDB().isSupportsInlineDistinct()) {
4344                                            query.append(_ORDER_BY_ENTITY_ALIAS);
4345                                    }
4346                                    else {
4347                                            query.append(_ORDER_BY_ENTITY_TABLE);
4348                                    }
4349    
4350                                    query.append(orderByConditionFields[i]);
4351    
4352                                    if ((i + 1) < orderByConditionFields.length) {
4353                                            if (orderByComparator.isAscending() ^ previous) {
4354                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4355                                            }
4356                                            else {
4357                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4358                                            }
4359                                    }
4360                                    else {
4361                                            if (orderByComparator.isAscending() ^ previous) {
4362                                                    query.append(WHERE_GREATER_THAN);
4363                                            }
4364                                            else {
4365                                                    query.append(WHERE_LESSER_THAN);
4366                                            }
4367                                    }
4368                            }
4369    
4370                            query.append(ORDER_BY_CLAUSE);
4371    
4372                            String[] orderByFields = orderByComparator.getOrderByFields();
4373    
4374                            for (int i = 0; i < orderByFields.length; i++) {
4375                                    if (getDB().isSupportsInlineDistinct()) {
4376                                            query.append(_ORDER_BY_ENTITY_ALIAS);
4377                                    }
4378                                    else {
4379                                            query.append(_ORDER_BY_ENTITY_TABLE);
4380                                    }
4381    
4382                                    query.append(orderByFields[i]);
4383    
4384                                    if ((i + 1) < orderByFields.length) {
4385                                            if (orderByComparator.isAscending() ^ previous) {
4386                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4387                                            }
4388                                            else {
4389                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4390                                            }
4391                                    }
4392                                    else {
4393                                            if (orderByComparator.isAscending() ^ previous) {
4394                                                    query.append(ORDER_BY_ASC);
4395                                            }
4396                                            else {
4397                                                    query.append(ORDER_BY_DESC);
4398                                            }
4399                                    }
4400                            }
4401                    }
4402                    else {
4403                            if (getDB().isSupportsInlineDistinct()) {
4404                                    query.append(OrganizationModelImpl.ORDER_BY_JPQL);
4405                            }
4406                            else {
4407                                    query.append(OrganizationModelImpl.ORDER_BY_SQL);
4408                            }
4409                    }
4410    
4411                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4412                                    Organization.class.getName(),
4413                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
4414    
4415                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
4416    
4417                    q.setFirstResult(0);
4418                    q.setMaxResults(2);
4419    
4420                    if (getDB().isSupportsInlineDistinct()) {
4421                            q.addEntity(_FILTER_ENTITY_ALIAS, OrganizationImpl.class);
4422                    }
4423                    else {
4424                            q.addEntity(_FILTER_ENTITY_TABLE, OrganizationImpl.class);
4425                    }
4426    
4427                    QueryPos qPos = QueryPos.getInstance(q);
4428    
4429                    qPos.add(companyId);
4430    
4431                    qPos.add(parentOrganizationId);
4432    
4433                    if (orderByComparator != null) {
4434                            Object[] values = orderByComparator.getOrderByConditionValues(organization);
4435    
4436                            for (Object value : values) {
4437                                    qPos.add(value);
4438                            }
4439                    }
4440    
4441                    List<Organization> list = q.list();
4442    
4443                    if (list.size() == 2) {
4444                            return list.get(1);
4445                    }
4446                    else {
4447                            return null;
4448                    }
4449            }
4450    
4451            /**
4452             * Removes all the organizations where companyId = &#63; and parentOrganizationId = &#63; from the database.
4453             *
4454             * @param companyId the company ID
4455             * @param parentOrganizationId the parent organization ID
4456             */
4457            @Override
4458            public void removeByC_P(long companyId, long parentOrganizationId) {
4459                    for (Organization organization : findByC_P(companyId,
4460                                    parentOrganizationId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
4461                            remove(organization);
4462                    }
4463            }
4464    
4465            /**
4466             * Returns the number of organizations where companyId = &#63; and parentOrganizationId = &#63;.
4467             *
4468             * @param companyId the company ID
4469             * @param parentOrganizationId the parent organization ID
4470             * @return the number of matching organizations
4471             */
4472            @Override
4473            public int countByC_P(long companyId, long parentOrganizationId) {
4474                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_P;
4475    
4476                    Object[] finderArgs = new Object[] { companyId, parentOrganizationId };
4477    
4478                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
4479                                    this);
4480    
4481                    if (count == null) {
4482                            StringBundler query = new StringBundler(3);
4483    
4484                            query.append(_SQL_COUNT_ORGANIZATION_WHERE);
4485    
4486                            query.append(_FINDER_COLUMN_C_P_COMPANYID_2);
4487    
4488                            query.append(_FINDER_COLUMN_C_P_PARENTORGANIZATIONID_2);
4489    
4490                            String sql = query.toString();
4491    
4492                            Session session = null;
4493    
4494                            try {
4495                                    session = openSession();
4496    
4497                                    Query q = session.createQuery(sql);
4498    
4499                                    QueryPos qPos = QueryPos.getInstance(q);
4500    
4501                                    qPos.add(companyId);
4502    
4503                                    qPos.add(parentOrganizationId);
4504    
4505                                    count = (Long)q.uniqueResult();
4506    
4507                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
4508                            }
4509                            catch (Exception e) {
4510                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4511    
4512                                    throw processException(e);
4513                            }
4514                            finally {
4515                                    closeSession(session);
4516                            }
4517                    }
4518    
4519                    return count.intValue();
4520            }
4521    
4522            /**
4523             * Returns the number of organizations that the user has permission to view where companyId = &#63; and parentOrganizationId = &#63;.
4524             *
4525             * @param companyId the company ID
4526             * @param parentOrganizationId the parent organization ID
4527             * @return the number of matching organizations that the user has permission to view
4528             */
4529            @Override
4530            public int filterCountByC_P(long companyId, long parentOrganizationId) {
4531                    if (!InlineSQLHelperUtil.isEnabled()) {
4532                            return countByC_P(companyId, parentOrganizationId);
4533                    }
4534    
4535                    StringBundler query = new StringBundler(3);
4536    
4537                    query.append(_FILTER_SQL_COUNT_ORGANIZATION_WHERE);
4538    
4539                    query.append(_FINDER_COLUMN_C_P_COMPANYID_2);
4540    
4541                    query.append(_FINDER_COLUMN_C_P_PARENTORGANIZATIONID_2);
4542    
4543                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4544                                    Organization.class.getName(),
4545                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
4546    
4547                    Session session = null;
4548    
4549                    try {
4550                            session = openSession();
4551    
4552                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
4553    
4554                            q.addScalar(COUNT_COLUMN_NAME,
4555                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
4556    
4557                            QueryPos qPos = QueryPos.getInstance(q);
4558    
4559                            qPos.add(companyId);
4560    
4561                            qPos.add(parentOrganizationId);
4562    
4563                            Long count = (Long)q.uniqueResult();
4564    
4565                            return count.intValue();
4566                    }
4567                    catch (Exception e) {
4568                            throw processException(e);
4569                    }
4570                    finally {
4571                            closeSession(session);
4572                    }
4573            }
4574    
4575            private static final String _FINDER_COLUMN_C_P_COMPANYID_2 = "organization.companyId = ? AND ";
4576            private static final String _FINDER_COLUMN_C_P_PARENTORGANIZATIONID_2 = "organization.parentOrganizationId = ?";
4577            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_T = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
4578                            OrganizationModelImpl.FINDER_CACHE_ENABLED, OrganizationImpl.class,
4579                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_T",
4580                            new String[] {
4581                                    Long.class.getName(), String.class.getName(),
4582                                    
4583                            Integer.class.getName(), Integer.class.getName(),
4584                                    OrderByComparator.class.getName()
4585                            });
4586            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_T = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
4587                            OrganizationModelImpl.FINDER_CACHE_ENABLED, Long.class,
4588                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByC_T",
4589                            new String[] { Long.class.getName(), String.class.getName() });
4590    
4591            /**
4592             * Returns all the organizations where companyId = &#63; and treePath LIKE &#63;.
4593             *
4594             * @param companyId the company ID
4595             * @param treePath the tree path
4596             * @return the matching organizations
4597             */
4598            @Override
4599            public List<Organization> findByC_T(long companyId, String treePath) {
4600                    return findByC_T(companyId, treePath, QueryUtil.ALL_POS,
4601                            QueryUtil.ALL_POS, null);
4602            }
4603    
4604            /**
4605             * Returns a range of all the organizations where companyId = &#63; and treePath LIKE &#63;.
4606             *
4607             * <p>
4608             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.OrganizationModelImpl}. 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.
4609             * </p>
4610             *
4611             * @param companyId the company ID
4612             * @param treePath the tree path
4613             * @param start the lower bound of the range of organizations
4614             * @param end the upper bound of the range of organizations (not inclusive)
4615             * @return the range of matching organizations
4616             */
4617            @Override
4618            public List<Organization> findByC_T(long companyId, String treePath,
4619                    int start, int end) {
4620                    return findByC_T(companyId, treePath, start, end, null);
4621            }
4622    
4623            /**
4624             * Returns an ordered range of all the organizations where companyId = &#63; and treePath LIKE &#63;.
4625             *
4626             * <p>
4627             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.OrganizationModelImpl}. 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.
4628             * </p>
4629             *
4630             * @param companyId the company ID
4631             * @param treePath the tree path
4632             * @param start the lower bound of the range of organizations
4633             * @param end the upper bound of the range of organizations (not inclusive)
4634             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4635             * @return the ordered range of matching organizations
4636             */
4637            @Override
4638            public List<Organization> findByC_T(long companyId, String treePath,
4639                    int start, int end, OrderByComparator<Organization> orderByComparator) {
4640                    boolean pagination = true;
4641                    FinderPath finderPath = null;
4642                    Object[] finderArgs = null;
4643    
4644                    finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_T;
4645                    finderArgs = new Object[] {
4646                                    companyId, treePath,
4647                                    
4648                                    start, end, orderByComparator
4649                            };
4650    
4651                    List<Organization> list = (List<Organization>)FinderCacheUtil.getResult(finderPath,
4652                                    finderArgs, this);
4653    
4654                    if ((list != null) && !list.isEmpty()) {
4655                            for (Organization organization : list) {
4656                                    if ((companyId != organization.getCompanyId()) ||
4657                                                    !StringUtil.wildcardMatches(
4658                                                            organization.getTreePath(), treePath,
4659                                                            CharPool.UNDERLINE, CharPool.PERCENT,
4660                                                            CharPool.BACK_SLASH, true)) {
4661                                            list = null;
4662    
4663                                            break;
4664                                    }
4665                            }
4666                    }
4667    
4668                    if (list == null) {
4669                            StringBundler query = null;
4670    
4671                            if (orderByComparator != null) {
4672                                    query = new StringBundler(4 +
4673                                                    (orderByComparator.getOrderByFields().length * 3));
4674                            }
4675                            else {
4676                                    query = new StringBundler(4);
4677                            }
4678    
4679                            query.append(_SQL_SELECT_ORGANIZATION_WHERE);
4680    
4681                            query.append(_FINDER_COLUMN_C_T_COMPANYID_2);
4682    
4683                            boolean bindTreePath = false;
4684    
4685                            if (treePath == null) {
4686                                    query.append(_FINDER_COLUMN_C_T_TREEPATH_1);
4687                            }
4688                            else if (treePath.equals(StringPool.BLANK)) {
4689                                    query.append(_FINDER_COLUMN_C_T_TREEPATH_3);
4690                            }
4691                            else {
4692                                    bindTreePath = true;
4693    
4694                                    query.append(_FINDER_COLUMN_C_T_TREEPATH_2);
4695                            }
4696    
4697                            if (orderByComparator != null) {
4698                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4699                                            orderByComparator);
4700                            }
4701                            else
4702                             if (pagination) {
4703                                    query.append(OrganizationModelImpl.ORDER_BY_JPQL);
4704                            }
4705    
4706                            String sql = query.toString();
4707    
4708                            Session session = null;
4709    
4710                            try {
4711                                    session = openSession();
4712    
4713                                    Query q = session.createQuery(sql);
4714    
4715                                    QueryPos qPos = QueryPos.getInstance(q);
4716    
4717                                    qPos.add(companyId);
4718    
4719                                    if (bindTreePath) {
4720                                            qPos.add(treePath);
4721                                    }
4722    
4723                                    if (!pagination) {
4724                                            list = (List<Organization>)QueryUtil.list(q, getDialect(),
4725                                                            start, end, false);
4726    
4727                                            Collections.sort(list);
4728    
4729                                            list = Collections.unmodifiableList(list);
4730                                    }
4731                                    else {
4732                                            list = (List<Organization>)QueryUtil.list(q, getDialect(),
4733                                                            start, end);
4734                                    }
4735    
4736                                    cacheResult(list);
4737    
4738                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
4739                            }
4740                            catch (Exception e) {
4741                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4742    
4743                                    throw processException(e);
4744                            }
4745                            finally {
4746                                    closeSession(session);
4747                            }
4748                    }
4749    
4750                    return list;
4751            }
4752    
4753            /**
4754             * Returns the first organization in the ordered set where companyId = &#63; and treePath LIKE &#63;.
4755             *
4756             * @param companyId the company ID
4757             * @param treePath the tree path
4758             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4759             * @return the first matching organization
4760             * @throws com.liferay.portal.NoSuchOrganizationException if a matching organization could not be found
4761             */
4762            @Override
4763            public Organization findByC_T_First(long companyId, String treePath,
4764                    OrderByComparator<Organization> orderByComparator)
4765                    throws NoSuchOrganizationException {
4766                    Organization organization = fetchByC_T_First(companyId, treePath,
4767                                    orderByComparator);
4768    
4769                    if (organization != null) {
4770                            return organization;
4771                    }
4772    
4773                    StringBundler msg = new StringBundler(6);
4774    
4775                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4776    
4777                    msg.append("companyId=");
4778                    msg.append(companyId);
4779    
4780                    msg.append(", treePath=");
4781                    msg.append(treePath);
4782    
4783                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4784    
4785                    throw new NoSuchOrganizationException(msg.toString());
4786            }
4787    
4788            /**
4789             * Returns the first organization in the ordered set where companyId = &#63; and treePath LIKE &#63;.
4790             *
4791             * @param companyId the company ID
4792             * @param treePath the tree path
4793             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4794             * @return the first matching organization, or <code>null</code> if a matching organization could not be found
4795             */
4796            @Override
4797            public Organization fetchByC_T_First(long companyId, String treePath,
4798                    OrderByComparator<Organization> orderByComparator) {
4799                    List<Organization> list = findByC_T(companyId, treePath, 0, 1,
4800                                    orderByComparator);
4801    
4802                    if (!list.isEmpty()) {
4803                            return list.get(0);
4804                    }
4805    
4806                    return null;
4807            }
4808    
4809            /**
4810             * Returns the last organization in the ordered set where companyId = &#63; and treePath LIKE &#63;.
4811             *
4812             * @param companyId the company ID
4813             * @param treePath the tree path
4814             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4815             * @return the last matching organization
4816             * @throws com.liferay.portal.NoSuchOrganizationException if a matching organization could not be found
4817             */
4818            @Override
4819            public Organization findByC_T_Last(long companyId, String treePath,
4820                    OrderByComparator<Organization> orderByComparator)
4821                    throws NoSuchOrganizationException {
4822                    Organization organization = fetchByC_T_Last(companyId, treePath,
4823                                    orderByComparator);
4824    
4825                    if (organization != null) {
4826                            return organization;
4827                    }
4828    
4829                    StringBundler msg = new StringBundler(6);
4830    
4831                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4832    
4833                    msg.append("companyId=");
4834                    msg.append(companyId);
4835    
4836                    msg.append(", treePath=");
4837                    msg.append(treePath);
4838    
4839                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4840    
4841                    throw new NoSuchOrganizationException(msg.toString());
4842            }
4843    
4844            /**
4845             * Returns the last organization in the ordered set where companyId = &#63; and treePath LIKE &#63;.
4846             *
4847             * @param companyId the company ID
4848             * @param treePath the tree path
4849             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4850             * @return the last matching organization, or <code>null</code> if a matching organization could not be found
4851             */
4852            @Override
4853            public Organization fetchByC_T_Last(long companyId, String treePath,
4854                    OrderByComparator<Organization> orderByComparator) {
4855                    int count = countByC_T(companyId, treePath);
4856    
4857                    if (count == 0) {
4858                            return null;
4859                    }
4860    
4861                    List<Organization> list = findByC_T(companyId, treePath, count - 1,
4862                                    count, orderByComparator);
4863    
4864                    if (!list.isEmpty()) {
4865                            return list.get(0);
4866                    }
4867    
4868                    return null;
4869            }
4870    
4871            /**
4872             * Returns the organizations before and after the current organization in the ordered set where companyId = &#63; and treePath LIKE &#63;.
4873             *
4874             * @param organizationId the primary key of the current organization
4875             * @param companyId the company ID
4876             * @param treePath the tree path
4877             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4878             * @return the previous, current, and next organization
4879             * @throws com.liferay.portal.NoSuchOrganizationException if a organization with the primary key could not be found
4880             */
4881            @Override
4882            public Organization[] findByC_T_PrevAndNext(long organizationId,
4883                    long companyId, String treePath,
4884                    OrderByComparator<Organization> orderByComparator)
4885                    throws NoSuchOrganizationException {
4886                    Organization organization = findByPrimaryKey(organizationId);
4887    
4888                    Session session = null;
4889    
4890                    try {
4891                            session = openSession();
4892    
4893                            Organization[] array = new OrganizationImpl[3];
4894    
4895                            array[0] = getByC_T_PrevAndNext(session, organization, companyId,
4896                                            treePath, orderByComparator, true);
4897    
4898                            array[1] = organization;
4899    
4900                            array[2] = getByC_T_PrevAndNext(session, organization, companyId,
4901                                            treePath, orderByComparator, false);
4902    
4903                            return array;
4904                    }
4905                    catch (Exception e) {
4906                            throw processException(e);
4907                    }
4908                    finally {
4909                            closeSession(session);
4910                    }
4911            }
4912    
4913            protected Organization getByC_T_PrevAndNext(Session session,
4914                    Organization organization, long companyId, String treePath,
4915                    OrderByComparator<Organization> orderByComparator, boolean previous) {
4916                    StringBundler query = null;
4917    
4918                    if (orderByComparator != null) {
4919                            query = new StringBundler(6 +
4920                                            (orderByComparator.getOrderByFields().length * 6));
4921                    }
4922                    else {
4923                            query = new StringBundler(3);
4924                    }
4925    
4926                    query.append(_SQL_SELECT_ORGANIZATION_WHERE);
4927    
4928                    query.append(_FINDER_COLUMN_C_T_COMPANYID_2);
4929    
4930                    boolean bindTreePath = false;
4931    
4932                    if (treePath == null) {
4933                            query.append(_FINDER_COLUMN_C_T_TREEPATH_1);
4934                    }
4935                    else if (treePath.equals(StringPool.BLANK)) {
4936                            query.append(_FINDER_COLUMN_C_T_TREEPATH_3);
4937                    }
4938                    else {
4939                            bindTreePath = true;
4940    
4941                            query.append(_FINDER_COLUMN_C_T_TREEPATH_2);
4942                    }
4943    
4944                    if (orderByComparator != null) {
4945                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4946    
4947                            if (orderByConditionFields.length > 0) {
4948                                    query.append(WHERE_AND);
4949                            }
4950    
4951                            for (int i = 0; i < orderByConditionFields.length; i++) {
4952                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4953                                    query.append(orderByConditionFields[i]);
4954    
4955                                    if ((i + 1) < orderByConditionFields.length) {
4956                                            if (orderByComparator.isAscending() ^ previous) {
4957                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4958                                            }
4959                                            else {
4960                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4961                                            }
4962                                    }
4963                                    else {
4964                                            if (orderByComparator.isAscending() ^ previous) {
4965                                                    query.append(WHERE_GREATER_THAN);
4966                                            }
4967                                            else {
4968                                                    query.append(WHERE_LESSER_THAN);
4969                                            }
4970                                    }
4971                            }
4972    
4973                            query.append(ORDER_BY_CLAUSE);
4974    
4975                            String[] orderByFields = orderByComparator.getOrderByFields();
4976    
4977                            for (int i = 0; i < orderByFields.length; i++) {
4978                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4979                                    query.append(orderByFields[i]);
4980    
4981                                    if ((i + 1) < orderByFields.length) {
4982                                            if (orderByComparator.isAscending() ^ previous) {
4983                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4984                                            }
4985                                            else {
4986                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4987                                            }
4988                                    }
4989                                    else {
4990                                            if (orderByComparator.isAscending() ^ previous) {
4991                                                    query.append(ORDER_BY_ASC);
4992                                            }
4993                                            else {
4994                                                    query.append(ORDER_BY_DESC);
4995                                            }
4996                                    }
4997                            }
4998                    }
4999                    else {
5000                            query.append(OrganizationModelImpl.ORDER_BY_JPQL);
5001                    }
5002    
5003                    String sql = query.toString();
5004    
5005                    Query q = session.createQuery(sql);
5006    
5007                    q.setFirstResult(0);
5008                    q.setMaxResults(2);
5009    
5010                    QueryPos qPos = QueryPos.getInstance(q);
5011    
5012                    qPos.add(companyId);
5013    
5014                    if (bindTreePath) {
5015                            qPos.add(treePath);
5016                    }
5017    
5018                    if (orderByComparator != null) {
5019                            Object[] values = orderByComparator.getOrderByConditionValues(organization);
5020    
5021                            for (Object value : values) {
5022                                    qPos.add(value);
5023                            }
5024                    }
5025    
5026                    List<Organization> list = q.list();
5027    
5028                    if (list.size() == 2) {
5029                            return list.get(1);
5030                    }
5031                    else {
5032                            return null;
5033                    }
5034            }
5035    
5036            /**
5037             * Returns all the organizations that the user has permission to view where companyId = &#63; and treePath LIKE &#63;.
5038             *
5039             * @param companyId the company ID
5040             * @param treePath the tree path
5041             * @return the matching organizations that the user has permission to view
5042             */
5043            @Override
5044            public List<Organization> filterFindByC_T(long companyId, String treePath) {
5045                    return filterFindByC_T(companyId, treePath, QueryUtil.ALL_POS,
5046                            QueryUtil.ALL_POS, null);
5047            }
5048    
5049            /**
5050             * Returns a range of all the organizations that the user has permission to view where companyId = &#63; and treePath LIKE &#63;.
5051             *
5052             * <p>
5053             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.OrganizationModelImpl}. 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.
5054             * </p>
5055             *
5056             * @param companyId the company ID
5057             * @param treePath the tree path
5058             * @param start the lower bound of the range of organizations
5059             * @param end the upper bound of the range of organizations (not inclusive)
5060             * @return the range of matching organizations that the user has permission to view
5061             */
5062            @Override
5063            public List<Organization> filterFindByC_T(long companyId, String treePath,
5064                    int start, int end) {
5065                    return filterFindByC_T(companyId, treePath, start, end, null);
5066            }
5067    
5068            /**
5069             * Returns an ordered range of all the organizations that the user has permissions to view where companyId = &#63; and treePath LIKE &#63;.
5070             *
5071             * <p>
5072             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.OrganizationModelImpl}. 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.
5073             * </p>
5074             *
5075             * @param companyId the company ID
5076             * @param treePath the tree path
5077             * @param start the lower bound of the range of organizations
5078             * @param end the upper bound of the range of organizations (not inclusive)
5079             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5080             * @return the ordered range of matching organizations that the user has permission to view
5081             */
5082            @Override
5083            public List<Organization> filterFindByC_T(long companyId, String treePath,
5084                    int start, int end, OrderByComparator<Organization> orderByComparator) {
5085                    if (!InlineSQLHelperUtil.isEnabled()) {
5086                            return findByC_T(companyId, treePath, start, end, orderByComparator);
5087                    }
5088    
5089                    StringBundler query = null;
5090    
5091                    if (orderByComparator != null) {
5092                            query = new StringBundler(4 +
5093                                            (orderByComparator.getOrderByFields().length * 3));
5094                    }
5095                    else {
5096                            query = new StringBundler(4);
5097                    }
5098    
5099                    if (getDB().isSupportsInlineDistinct()) {
5100                            query.append(_FILTER_SQL_SELECT_ORGANIZATION_WHERE);
5101                    }
5102                    else {
5103                            query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_1);
5104                    }
5105    
5106                    query.append(_FINDER_COLUMN_C_T_COMPANYID_2);
5107    
5108                    boolean bindTreePath = false;
5109    
5110                    if (treePath == null) {
5111                            query.append(_FINDER_COLUMN_C_T_TREEPATH_1);
5112                    }
5113                    else if (treePath.equals(StringPool.BLANK)) {
5114                            query.append(_FINDER_COLUMN_C_T_TREEPATH_3);
5115                    }
5116                    else {
5117                            bindTreePath = true;
5118    
5119                            query.append(_FINDER_COLUMN_C_T_TREEPATH_2);
5120                    }
5121    
5122                    if (!getDB().isSupportsInlineDistinct()) {
5123                            query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_2);
5124                    }
5125    
5126                    if (orderByComparator != null) {
5127                            if (getDB().isSupportsInlineDistinct()) {
5128                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5129                                            orderByComparator, true);
5130                            }
5131                            else {
5132                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
5133                                            orderByComparator, true);
5134                            }
5135                    }
5136                    else {
5137                            if (getDB().isSupportsInlineDistinct()) {
5138                                    query.append(OrganizationModelImpl.ORDER_BY_JPQL);
5139                            }
5140                            else {
5141                                    query.append(OrganizationModelImpl.ORDER_BY_SQL);
5142                            }
5143                    }
5144    
5145                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5146                                    Organization.class.getName(),
5147                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
5148    
5149                    Session session = null;
5150    
5151                    try {
5152                            session = openSession();
5153    
5154                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
5155    
5156                            if (getDB().isSupportsInlineDistinct()) {
5157                                    q.addEntity(_FILTER_ENTITY_ALIAS, OrganizationImpl.class);
5158                            }
5159                            else {
5160                                    q.addEntity(_FILTER_ENTITY_TABLE, OrganizationImpl.class);
5161                            }
5162    
5163                            QueryPos qPos = QueryPos.getInstance(q);
5164    
5165                            qPos.add(companyId);
5166    
5167                            if (bindTreePath) {
5168                                    qPos.add(treePath);
5169                            }
5170    
5171                            return (List<Organization>)QueryUtil.list(q, getDialect(), start,
5172                                    end);
5173                    }
5174                    catch (Exception e) {
5175                            throw processException(e);
5176                    }
5177                    finally {
5178                            closeSession(session);
5179                    }
5180            }
5181    
5182            /**
5183             * Returns the organizations before and after the current organization in the ordered set of organizations that the user has permission to view where companyId = &#63; and treePath LIKE &#63;.
5184             *
5185             * @param organizationId the primary key of the current organization
5186             * @param companyId the company ID
5187             * @param treePath the tree path
5188             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5189             * @return the previous, current, and next organization
5190             * @throws com.liferay.portal.NoSuchOrganizationException if a organization with the primary key could not be found
5191             */
5192            @Override
5193            public Organization[] filterFindByC_T_PrevAndNext(long organizationId,
5194                    long companyId, String treePath,
5195                    OrderByComparator<Organization> orderByComparator)
5196                    throws NoSuchOrganizationException {
5197                    if (!InlineSQLHelperUtil.isEnabled()) {
5198                            return findByC_T_PrevAndNext(organizationId, companyId, treePath,
5199                                    orderByComparator);
5200                    }
5201    
5202                    Organization organization = findByPrimaryKey(organizationId);
5203    
5204                    Session session = null;
5205    
5206                    try {
5207                            session = openSession();
5208    
5209                            Organization[] array = new OrganizationImpl[3];
5210    
5211                            array[0] = filterGetByC_T_PrevAndNext(session, organization,
5212                                            companyId, treePath, orderByComparator, true);
5213    
5214                            array[1] = organization;
5215    
5216                            array[2] = filterGetByC_T_PrevAndNext(session, organization,
5217                                            companyId, treePath, orderByComparator, false);
5218    
5219                            return array;
5220                    }
5221                    catch (Exception e) {
5222                            throw processException(e);
5223                    }
5224                    finally {
5225                            closeSession(session);
5226                    }
5227            }
5228    
5229            protected Organization filterGetByC_T_PrevAndNext(Session session,
5230                    Organization organization, long companyId, String treePath,
5231                    OrderByComparator<Organization> orderByComparator, boolean previous) {
5232                    StringBundler query = null;
5233    
5234                    if (orderByComparator != null) {
5235                            query = new StringBundler(6 +
5236                                            (orderByComparator.getOrderByFields().length * 6));
5237                    }
5238                    else {
5239                            query = new StringBundler(3);
5240                    }
5241    
5242                    if (getDB().isSupportsInlineDistinct()) {
5243                            query.append(_FILTER_SQL_SELECT_ORGANIZATION_WHERE);
5244                    }
5245                    else {
5246                            query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_1);
5247                    }
5248    
5249                    query.append(_FINDER_COLUMN_C_T_COMPANYID_2);
5250    
5251                    boolean bindTreePath = false;
5252    
5253                    if (treePath == null) {
5254                            query.append(_FINDER_COLUMN_C_T_TREEPATH_1);
5255                    }
5256                    else if (treePath.equals(StringPool.BLANK)) {
5257                            query.append(_FINDER_COLUMN_C_T_TREEPATH_3);
5258                    }
5259                    else {
5260                            bindTreePath = true;
5261    
5262                            query.append(_FINDER_COLUMN_C_T_TREEPATH_2);
5263                    }
5264    
5265                    if (!getDB().isSupportsInlineDistinct()) {
5266                            query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_2);
5267                    }
5268    
5269                    if (orderByComparator != null) {
5270                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5271    
5272                            if (orderByConditionFields.length > 0) {
5273                                    query.append(WHERE_AND);
5274                            }
5275    
5276                            for (int i = 0; i < orderByConditionFields.length; i++) {
5277                                    if (getDB().isSupportsInlineDistinct()) {
5278                                            query.append(_ORDER_BY_ENTITY_ALIAS);
5279                                    }
5280                                    else {
5281                                            query.append(_ORDER_BY_ENTITY_TABLE);
5282                                    }
5283    
5284                                    query.append(orderByConditionFields[i]);
5285    
5286                                    if ((i + 1) < orderByConditionFields.length) {
5287                                            if (orderByComparator.isAscending() ^ previous) {
5288                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5289                                            }
5290                                            else {
5291                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5292                                            }
5293                                    }
5294                                    else {
5295                                            if (orderByComparator.isAscending() ^ previous) {
5296                                                    query.append(WHERE_GREATER_THAN);
5297                                            }
5298                                            else {
5299                                                    query.append(WHERE_LESSER_THAN);
5300                                            }
5301                                    }
5302                            }
5303    
5304                            query.append(ORDER_BY_CLAUSE);
5305    
5306                            String[] orderByFields = orderByComparator.getOrderByFields();
5307    
5308                            for (int i = 0; i < orderByFields.length; i++) {
5309                                    if (getDB().isSupportsInlineDistinct()) {
5310                                            query.append(_ORDER_BY_ENTITY_ALIAS);
5311                                    }
5312                                    else {
5313                                            query.append(_ORDER_BY_ENTITY_TABLE);
5314                                    }
5315    
5316                                    query.append(orderByFields[i]);
5317    
5318                                    if ((i + 1) < orderByFields.length) {
5319                                            if (orderByComparator.isAscending() ^ previous) {
5320                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5321                                            }
5322                                            else {
5323                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5324                                            }
5325                                    }
5326                                    else {
5327                                            if (orderByComparator.isAscending() ^ previous) {
5328                                                    query.append(ORDER_BY_ASC);
5329                                            }
5330                                            else {
5331                                                    query.append(ORDER_BY_DESC);
5332                                            }
5333                                    }
5334                            }
5335                    }
5336                    else {
5337                            if (getDB().isSupportsInlineDistinct()) {
5338                                    query.append(OrganizationModelImpl.ORDER_BY_JPQL);
5339                            }
5340                            else {
5341                                    query.append(OrganizationModelImpl.ORDER_BY_SQL);
5342                            }
5343                    }
5344    
5345                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5346                                    Organization.class.getName(),
5347                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
5348    
5349                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
5350    
5351                    q.setFirstResult(0);
5352                    q.setMaxResults(2);
5353    
5354                    if (getDB().isSupportsInlineDistinct()) {
5355                            q.addEntity(_FILTER_ENTITY_ALIAS, OrganizationImpl.class);
5356                    }
5357                    else {
5358                            q.addEntity(_FILTER_ENTITY_TABLE, OrganizationImpl.class);
5359                    }
5360    
5361                    QueryPos qPos = QueryPos.getInstance(q);
5362    
5363                    qPos.add(companyId);
5364    
5365                    if (bindTreePath) {
5366                            qPos.add(treePath);
5367                    }
5368    
5369                    if (orderByComparator != null) {
5370                            Object[] values = orderByComparator.getOrderByConditionValues(organization);
5371    
5372                            for (Object value : values) {
5373                                    qPos.add(value);
5374                            }
5375                    }
5376    
5377                    List<Organization> list = q.list();
5378    
5379                    if (list.size() == 2) {
5380                            return list.get(1);
5381                    }
5382                    else {
5383                            return null;
5384                    }
5385            }
5386    
5387            /**
5388             * Removes all the organizations where companyId = &#63; and treePath LIKE &#63; from the database.
5389             *
5390             * @param companyId the company ID
5391             * @param treePath the tree path
5392             */
5393            @Override
5394            public void removeByC_T(long companyId, String treePath) {
5395                    for (Organization organization : findByC_T(companyId, treePath,
5396                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
5397                            remove(organization);
5398                    }
5399            }
5400    
5401            /**
5402             * Returns the number of organizations where companyId = &#63; and treePath LIKE &#63;.
5403             *
5404             * @param companyId the company ID
5405             * @param treePath the tree path
5406             * @return the number of matching organizations
5407             */
5408            @Override
5409            public int countByC_T(long companyId, String treePath) {
5410                    FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_T;
5411    
5412                    Object[] finderArgs = new Object[] { companyId, treePath };
5413    
5414                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
5415                                    this);
5416    
5417                    if (count == null) {
5418                            StringBundler query = new StringBundler(3);
5419    
5420                            query.append(_SQL_COUNT_ORGANIZATION_WHERE);
5421    
5422                            query.append(_FINDER_COLUMN_C_T_COMPANYID_2);
5423    
5424                            boolean bindTreePath = false;
5425    
5426                            if (treePath == null) {
5427                                    query.append(_FINDER_COLUMN_C_T_TREEPATH_1);
5428                            }
5429                            else if (treePath.equals(StringPool.BLANK)) {
5430                                    query.append(_FINDER_COLUMN_C_T_TREEPATH_3);
5431                            }
5432                            else {
5433                                    bindTreePath = true;
5434    
5435                                    query.append(_FINDER_COLUMN_C_T_TREEPATH_2);
5436                            }
5437    
5438                            String sql = query.toString();
5439    
5440                            Session session = null;
5441    
5442                            try {
5443                                    session = openSession();
5444    
5445                                    Query q = session.createQuery(sql);
5446    
5447                                    QueryPos qPos = QueryPos.getInstance(q);
5448    
5449                                    qPos.add(companyId);
5450    
5451                                    if (bindTreePath) {
5452                                            qPos.add(treePath);
5453                                    }
5454    
5455                                    count = (Long)q.uniqueResult();
5456    
5457                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
5458                            }
5459                            catch (Exception e) {
5460                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
5461    
5462                                    throw processException(e);
5463                            }
5464                            finally {
5465                                    closeSession(session);
5466                            }
5467                    }
5468    
5469                    return count.intValue();
5470            }
5471    
5472            /**
5473             * Returns the number of organizations that the user has permission to view where companyId = &#63; and treePath LIKE &#63;.
5474             *
5475             * @param companyId the company ID
5476             * @param treePath the tree path
5477             * @return the number of matching organizations that the user has permission to view
5478             */
5479            @Override
5480            public int filterCountByC_T(long companyId, String treePath) {
5481                    if (!InlineSQLHelperUtil.isEnabled()) {
5482                            return countByC_T(companyId, treePath);
5483                    }
5484    
5485                    StringBundler query = new StringBundler(3);
5486    
5487                    query.append(_FILTER_SQL_COUNT_ORGANIZATION_WHERE);
5488    
5489                    query.append(_FINDER_COLUMN_C_T_COMPANYID_2);
5490    
5491                    boolean bindTreePath = false;
5492    
5493                    if (treePath == null) {
5494                            query.append(_FINDER_COLUMN_C_T_TREEPATH_1);
5495                    }
5496                    else if (treePath.equals(StringPool.BLANK)) {
5497                            query.append(_FINDER_COLUMN_C_T_TREEPATH_3);
5498                    }
5499                    else {
5500                            bindTreePath = true;
5501    
5502                            query.append(_FINDER_COLUMN_C_T_TREEPATH_2);
5503                    }
5504    
5505                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5506                                    Organization.class.getName(),
5507                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
5508    
5509                    Session session = null;
5510    
5511                    try {
5512                            session = openSession();
5513    
5514                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
5515    
5516                            q.addScalar(COUNT_COLUMN_NAME,
5517                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
5518    
5519                            QueryPos qPos = QueryPos.getInstance(q);
5520    
5521                            qPos.add(companyId);
5522    
5523                            if (bindTreePath) {
5524                                    qPos.add(treePath);
5525                            }
5526    
5527                            Long count = (Long)q.uniqueResult();
5528    
5529                            return count.intValue();
5530                    }
5531                    catch (Exception e) {
5532                            throw processException(e);
5533                    }
5534                    finally {
5535                            closeSession(session);
5536                    }
5537            }
5538    
5539            private static final String _FINDER_COLUMN_C_T_COMPANYID_2 = "organization.companyId = ? AND ";
5540            private static final String _FINDER_COLUMN_C_T_TREEPATH_1 = "organization.treePath LIKE NULL";
5541            private static final String _FINDER_COLUMN_C_T_TREEPATH_2 = "organization.treePath LIKE ?";
5542            private static final String _FINDER_COLUMN_C_T_TREEPATH_3 = "(organization.treePath IS NULL OR organization.treePath LIKE '')";
5543            public static final FinderPath FINDER_PATH_FETCH_BY_C_N = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
5544                            OrganizationModelImpl.FINDER_CACHE_ENABLED, OrganizationImpl.class,
5545                            FINDER_CLASS_NAME_ENTITY, "fetchByC_N",
5546                            new String[] { Long.class.getName(), String.class.getName() },
5547                            OrganizationModelImpl.COMPANYID_COLUMN_BITMASK |
5548                            OrganizationModelImpl.NAME_COLUMN_BITMASK);
5549            public static final FinderPath FINDER_PATH_COUNT_BY_C_N = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
5550                            OrganizationModelImpl.FINDER_CACHE_ENABLED, Long.class,
5551                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_N",
5552                            new String[] { Long.class.getName(), String.class.getName() });
5553    
5554            /**
5555             * Returns the organization where companyId = &#63; and name = &#63; or throws a {@link com.liferay.portal.NoSuchOrganizationException} if it could not be found.
5556             *
5557             * @param companyId the company ID
5558             * @param name the name
5559             * @return the matching organization
5560             * @throws com.liferay.portal.NoSuchOrganizationException if a matching organization could not be found
5561             */
5562            @Override
5563            public Organization findByC_N(long companyId, String name)
5564                    throws NoSuchOrganizationException {
5565                    Organization organization = fetchByC_N(companyId, name);
5566    
5567                    if (organization == null) {
5568                            StringBundler msg = new StringBundler(6);
5569    
5570                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5571    
5572                            msg.append("companyId=");
5573                            msg.append(companyId);
5574    
5575                            msg.append(", name=");
5576                            msg.append(name);
5577    
5578                            msg.append(StringPool.CLOSE_CURLY_BRACE);
5579    
5580                            if (_log.isWarnEnabled()) {
5581                                    _log.warn(msg.toString());
5582                            }
5583    
5584                            throw new NoSuchOrganizationException(msg.toString());
5585                    }
5586    
5587                    return organization;
5588            }
5589    
5590            /**
5591             * Returns the organization where companyId = &#63; and name = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
5592             *
5593             * @param companyId the company ID
5594             * @param name the name
5595             * @return the matching organization, or <code>null</code> if a matching organization could not be found
5596             */
5597            @Override
5598            public Organization fetchByC_N(long companyId, String name) {
5599                    return fetchByC_N(companyId, name, true);
5600            }
5601    
5602            /**
5603             * Returns the organization where companyId = &#63; and name = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
5604             *
5605             * @param companyId the company ID
5606             * @param name the name
5607             * @param retrieveFromCache whether to use the finder cache
5608             * @return the matching organization, or <code>null</code> if a matching organization could not be found
5609             */
5610            @Override
5611            public Organization fetchByC_N(long companyId, String name,
5612                    boolean retrieveFromCache) {
5613                    Object[] finderArgs = new Object[] { companyId, name };
5614    
5615                    Object result = null;
5616    
5617                    if (retrieveFromCache) {
5618                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_N,
5619                                            finderArgs, this);
5620                    }
5621    
5622                    if (result instanceof Organization) {
5623                            Organization organization = (Organization)result;
5624    
5625                            if ((companyId != organization.getCompanyId()) ||
5626                                            !Validator.equals(name, organization.getName())) {
5627                                    result = null;
5628                            }
5629                    }
5630    
5631                    if (result == null) {
5632                            StringBundler query = new StringBundler(4);
5633    
5634                            query.append(_SQL_SELECT_ORGANIZATION_WHERE);
5635    
5636                            query.append(_FINDER_COLUMN_C_N_COMPANYID_2);
5637    
5638                            boolean bindName = false;
5639    
5640                            if (name == null) {
5641                                    query.append(_FINDER_COLUMN_C_N_NAME_1);
5642                            }
5643                            else if (name.equals(StringPool.BLANK)) {
5644                                    query.append(_FINDER_COLUMN_C_N_NAME_3);
5645                            }
5646                            else {
5647                                    bindName = true;
5648    
5649                                    query.append(_FINDER_COLUMN_C_N_NAME_2);
5650                            }
5651    
5652                            String sql = query.toString();
5653    
5654                            Session session = null;
5655    
5656                            try {
5657                                    session = openSession();
5658    
5659                                    Query q = session.createQuery(sql);
5660    
5661                                    QueryPos qPos = QueryPos.getInstance(q);
5662    
5663                                    qPos.add(companyId);
5664    
5665                                    if (bindName) {
5666                                            qPos.add(name);
5667                                    }
5668    
5669                                    List<Organization> list = q.list();
5670    
5671                                    if (list.isEmpty()) {
5672                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
5673                                                    finderArgs, list);
5674                                    }
5675                                    else {
5676                                            Organization organization = list.get(0);
5677    
5678                                            result = organization;
5679    
5680                                            cacheResult(organization);
5681    
5682                                            if ((organization.getCompanyId() != companyId) ||
5683                                                            (organization.getName() == null) ||
5684                                                            !organization.getName().equals(name)) {
5685                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
5686                                                            finderArgs, organization);
5687                                            }
5688                                    }
5689                            }
5690                            catch (Exception e) {
5691                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N,
5692                                            finderArgs);
5693    
5694                                    throw processException(e);
5695                            }
5696                            finally {
5697                                    closeSession(session);
5698                            }
5699                    }
5700    
5701                    if (result instanceof List<?>) {
5702                            return null;
5703                    }
5704                    else {
5705                            return (Organization)result;
5706                    }
5707            }
5708    
5709            /**
5710             * Removes the organization where companyId = &#63; and name = &#63; from the database.
5711             *
5712             * @param companyId the company ID
5713             * @param name the name
5714             * @return the organization that was removed
5715             */
5716            @Override
5717            public Organization removeByC_N(long companyId, String name)
5718                    throws NoSuchOrganizationException {
5719                    Organization organization = findByC_N(companyId, name);
5720    
5721                    return remove(organization);
5722            }
5723    
5724            /**
5725             * Returns the number of organizations where companyId = &#63; and name = &#63;.
5726             *
5727             * @param companyId the company ID
5728             * @param name the name
5729             * @return the number of matching organizations
5730             */
5731            @Override
5732            public int countByC_N(long companyId, String name) {
5733                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_N;
5734    
5735                    Object[] finderArgs = new Object[] { companyId, name };
5736    
5737                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
5738                                    this);
5739    
5740                    if (count == null) {
5741                            StringBundler query = new StringBundler(3);
5742    
5743                            query.append(_SQL_COUNT_ORGANIZATION_WHERE);
5744    
5745                            query.append(_FINDER_COLUMN_C_N_COMPANYID_2);
5746    
5747                            boolean bindName = false;
5748    
5749                            if (name == null) {
5750                                    query.append(_FINDER_COLUMN_C_N_NAME_1);
5751                            }
5752                            else if (name.equals(StringPool.BLANK)) {
5753                                    query.append(_FINDER_COLUMN_C_N_NAME_3);
5754                            }
5755                            else {
5756                                    bindName = true;
5757    
5758                                    query.append(_FINDER_COLUMN_C_N_NAME_2);
5759                            }
5760    
5761                            String sql = query.toString();
5762    
5763                            Session session = null;
5764    
5765                            try {
5766                                    session = openSession();
5767    
5768                                    Query q = session.createQuery(sql);
5769    
5770                                    QueryPos qPos = QueryPos.getInstance(q);
5771    
5772                                    qPos.add(companyId);
5773    
5774                                    if (bindName) {
5775                                            qPos.add(name);
5776                                    }
5777    
5778                                    count = (Long)q.uniqueResult();
5779    
5780                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
5781                            }
5782                            catch (Exception e) {
5783                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
5784    
5785                                    throw processException(e);
5786                            }
5787                            finally {
5788                                    closeSession(session);
5789                            }
5790                    }
5791    
5792                    return count.intValue();
5793            }
5794    
5795            private static final String _FINDER_COLUMN_C_N_COMPANYID_2 = "organization.companyId = ? AND ";
5796            private static final String _FINDER_COLUMN_C_N_NAME_1 = "organization.name IS NULL";
5797            private static final String _FINDER_COLUMN_C_N_NAME_2 = "organization.name = ?";
5798            private static final String _FINDER_COLUMN_C_N_NAME_3 = "(organization.name IS NULL OR organization.name = '')";
5799            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_O_C_P = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
5800                            OrganizationModelImpl.FINDER_CACHE_ENABLED, OrganizationImpl.class,
5801                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByO_C_P",
5802                            new String[] {
5803                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
5804                                    
5805                            Integer.class.getName(), Integer.class.getName(),
5806                                    OrderByComparator.class.getName()
5807                            });
5808            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_O_C_P = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
5809                            OrganizationModelImpl.FINDER_CACHE_ENABLED, Long.class,
5810                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByO_C_P",
5811                            new String[] {
5812                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
5813                            });
5814    
5815            /**
5816             * Returns all the organizations where organizationId &gt; &#63; and companyId = &#63; and parentOrganizationId = &#63;.
5817             *
5818             * @param organizationId the organization ID
5819             * @param companyId the company ID
5820             * @param parentOrganizationId the parent organization ID
5821             * @return the matching organizations
5822             */
5823            @Override
5824            public List<Organization> findByO_C_P(long organizationId, long companyId,
5825                    long parentOrganizationId) {
5826                    return findByO_C_P(organizationId, companyId, parentOrganizationId,
5827                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
5828            }
5829    
5830            /**
5831             * Returns a range of all the organizations where organizationId &gt; &#63; and companyId = &#63; and parentOrganizationId = &#63;.
5832             *
5833             * <p>
5834             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.OrganizationModelImpl}. 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.
5835             * </p>
5836             *
5837             * @param organizationId the organization ID
5838             * @param companyId the company ID
5839             * @param parentOrganizationId the parent organization ID
5840             * @param start the lower bound of the range of organizations
5841             * @param end the upper bound of the range of organizations (not inclusive)
5842             * @return the range of matching organizations
5843             */
5844            @Override
5845            public List<Organization> findByO_C_P(long organizationId, long companyId,
5846                    long parentOrganizationId, int start, int end) {
5847                    return findByO_C_P(organizationId, companyId, parentOrganizationId,
5848                            start, end, null);
5849            }
5850    
5851            /**
5852             * Returns an ordered range of all the organizations where organizationId &gt; &#63; and companyId = &#63; and parentOrganizationId = &#63;.
5853             *
5854             * <p>
5855             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.OrganizationModelImpl}. 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.
5856             * </p>
5857             *
5858             * @param organizationId the organization ID
5859             * @param companyId the company ID
5860             * @param parentOrganizationId the parent organization ID
5861             * @param start the lower bound of the range of organizations
5862             * @param end the upper bound of the range of organizations (not inclusive)
5863             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5864             * @return the ordered range of matching organizations
5865             */
5866            @Override
5867            public List<Organization> findByO_C_P(long organizationId, long companyId,
5868                    long parentOrganizationId, int start, int end,
5869                    OrderByComparator<Organization> orderByComparator) {
5870                    boolean pagination = true;
5871                    FinderPath finderPath = null;
5872                    Object[] finderArgs = null;
5873    
5874                    finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_O_C_P;
5875                    finderArgs = new Object[] {
5876                                    organizationId, companyId, parentOrganizationId,
5877                                    
5878                                    start, end, orderByComparator
5879                            };
5880    
5881                    List<Organization> list = (List<Organization>)FinderCacheUtil.getResult(finderPath,
5882                                    finderArgs, this);
5883    
5884                    if ((list != null) && !list.isEmpty()) {
5885                            for (Organization organization : list) {
5886                                    if ((organizationId >= organization.getOrganizationId()) ||
5887                                                    (companyId != organization.getCompanyId()) ||
5888                                                    (parentOrganizationId != organization.getParentOrganizationId())) {
5889                                            list = null;
5890    
5891                                            break;
5892                                    }
5893                            }
5894                    }
5895    
5896                    if (list == null) {
5897                            StringBundler query = null;
5898    
5899                            if (orderByComparator != null) {
5900                                    query = new StringBundler(5 +
5901                                                    (orderByComparator.getOrderByFields().length * 3));
5902                            }
5903                            else {
5904                                    query = new StringBundler(5);
5905                            }
5906    
5907                            query.append(_SQL_SELECT_ORGANIZATION_WHERE);
5908    
5909                            query.append(_FINDER_COLUMN_O_C_P_ORGANIZATIONID_2);
5910    
5911                            query.append(_FINDER_COLUMN_O_C_P_COMPANYID_2);
5912    
5913                            query.append(_FINDER_COLUMN_O_C_P_PARENTORGANIZATIONID_2);
5914    
5915                            if (orderByComparator != null) {
5916                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5917                                            orderByComparator);
5918                            }
5919                            else
5920                             if (pagination) {
5921                                    query.append(OrganizationModelImpl.ORDER_BY_JPQL);
5922                            }
5923    
5924                            String sql = query.toString();
5925    
5926                            Session session = null;
5927    
5928                            try {
5929                                    session = openSession();
5930    
5931                                    Query q = session.createQuery(sql);
5932    
5933                                    QueryPos qPos = QueryPos.getInstance(q);
5934    
5935                                    qPos.add(organizationId);
5936    
5937                                    qPos.add(companyId);
5938    
5939                                    qPos.add(parentOrganizationId);
5940    
5941                                    if (!pagination) {
5942                                            list = (List<Organization>)QueryUtil.list(q, getDialect(),
5943                                                            start, end, false);
5944    
5945                                            Collections.sort(list);
5946    
5947                                            list = Collections.unmodifiableList(list);
5948                                    }
5949                                    else {
5950                                            list = (List<Organization>)QueryUtil.list(q, getDialect(),
5951                                                            start, end);
5952                                    }
5953    
5954                                    cacheResult(list);
5955    
5956                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
5957                            }
5958                            catch (Exception e) {
5959                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
5960    
5961                                    throw processException(e);
5962                            }
5963                            finally {
5964                                    closeSession(session);
5965                            }
5966                    }
5967    
5968                    return list;
5969            }
5970    
5971            /**
5972             * Returns the first organization in the ordered set where organizationId &gt; &#63; and companyId = &#63; and parentOrganizationId = &#63;.
5973             *
5974             * @param organizationId the organization ID
5975             * @param companyId the company ID
5976             * @param parentOrganizationId the parent organization ID
5977             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5978             * @return the first matching organization
5979             * @throws com.liferay.portal.NoSuchOrganizationException if a matching organization could not be found
5980             */
5981            @Override
5982            public Organization findByO_C_P_First(long organizationId, long companyId,
5983                    long parentOrganizationId,
5984                    OrderByComparator<Organization> orderByComparator)
5985                    throws NoSuchOrganizationException {
5986                    Organization organization = fetchByO_C_P_First(organizationId,
5987                                    companyId, parentOrganizationId, orderByComparator);
5988    
5989                    if (organization != null) {
5990                            return organization;
5991                    }
5992    
5993                    StringBundler msg = new StringBundler(8);
5994    
5995                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5996    
5997                    msg.append("organizationId=");
5998                    msg.append(organizationId);
5999    
6000                    msg.append(", companyId=");
6001                    msg.append(companyId);
6002    
6003                    msg.append(", parentOrganizationId=");
6004                    msg.append(parentOrganizationId);
6005    
6006                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6007    
6008                    throw new NoSuchOrganizationException(msg.toString());
6009            }
6010    
6011            /**
6012             * Returns the first organization in the ordered set where organizationId &gt; &#63; and companyId = &#63; and parentOrganizationId = &#63;.
6013             *
6014             * @param organizationId the organization ID
6015             * @param companyId the company ID
6016             * @param parentOrganizationId the parent organization ID
6017             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6018             * @return the first matching organization, or <code>null</code> if a matching organization could not be found
6019             */
6020            @Override
6021            public Organization fetchByO_C_P_First(long organizationId, long companyId,
6022                    long parentOrganizationId,
6023                    OrderByComparator<Organization> orderByComparator) {
6024                    List<Organization> list = findByO_C_P(organizationId, companyId,
6025                                    parentOrganizationId, 0, 1, orderByComparator);
6026    
6027                    if (!list.isEmpty()) {
6028                            return list.get(0);
6029                    }
6030    
6031                    return null;
6032            }
6033    
6034            /**
6035             * Returns the last organization in the ordered set where organizationId &gt; &#63; and companyId = &#63; and parentOrganizationId = &#63;.
6036             *
6037             * @param organizationId the organization ID
6038             * @param companyId the company ID
6039             * @param parentOrganizationId the parent organization ID
6040             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6041             * @return the last matching organization
6042             * @throws com.liferay.portal.NoSuchOrganizationException if a matching organization could not be found
6043             */
6044            @Override
6045            public Organization findByO_C_P_Last(long organizationId, long companyId,
6046                    long parentOrganizationId,
6047                    OrderByComparator<Organization> orderByComparator)
6048                    throws NoSuchOrganizationException {
6049                    Organization organization = fetchByO_C_P_Last(organizationId,
6050                                    companyId, parentOrganizationId, orderByComparator);
6051    
6052                    if (organization != null) {
6053                            return organization;
6054                    }
6055    
6056                    StringBundler msg = new StringBundler(8);
6057    
6058                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6059    
6060                    msg.append("organizationId=");
6061                    msg.append(organizationId);
6062    
6063                    msg.append(", companyId=");
6064                    msg.append(companyId);
6065    
6066                    msg.append(", parentOrganizationId=");
6067                    msg.append(parentOrganizationId);
6068    
6069                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6070    
6071                    throw new NoSuchOrganizationException(msg.toString());
6072            }
6073    
6074            /**
6075             * Returns the last organization in the ordered set where organizationId &gt; &#63; and companyId = &#63; and parentOrganizationId = &#63;.
6076             *
6077             * @param organizationId the organization ID
6078             * @param companyId the company ID
6079             * @param parentOrganizationId the parent organization ID
6080             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6081             * @return the last matching organization, or <code>null</code> if a matching organization could not be found
6082             */
6083            @Override
6084            public Organization fetchByO_C_P_Last(long organizationId, long companyId,
6085                    long parentOrganizationId,
6086                    OrderByComparator<Organization> orderByComparator) {
6087                    int count = countByO_C_P(organizationId, companyId, parentOrganizationId);
6088    
6089                    if (count == 0) {
6090                            return null;
6091                    }
6092    
6093                    List<Organization> list = findByO_C_P(organizationId, companyId,
6094                                    parentOrganizationId, count - 1, count, orderByComparator);
6095    
6096                    if (!list.isEmpty()) {
6097                            return list.get(0);
6098                    }
6099    
6100                    return null;
6101            }
6102    
6103            /**
6104             * Returns all the organizations that the user has permission to view where organizationId &gt; &#63; and companyId = &#63; and parentOrganizationId = &#63;.
6105             *
6106             * @param organizationId the organization ID
6107             * @param companyId the company ID
6108             * @param parentOrganizationId the parent organization ID
6109             * @return the matching organizations that the user has permission to view
6110             */
6111            @Override
6112            public List<Organization> filterFindByO_C_P(long organizationId,
6113                    long companyId, long parentOrganizationId) {
6114                    return filterFindByO_C_P(organizationId, companyId,
6115                            parentOrganizationId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
6116            }
6117    
6118            /**
6119             * Returns a range of all the organizations that the user has permission to view where organizationId &gt; &#63; and companyId = &#63; and parentOrganizationId = &#63;.
6120             *
6121             * <p>
6122             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.OrganizationModelImpl}. 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.
6123             * </p>
6124             *
6125             * @param organizationId the organization ID
6126             * @param companyId the company ID
6127             * @param parentOrganizationId the parent organization ID
6128             * @param start the lower bound of the range of organizations
6129             * @param end the upper bound of the range of organizations (not inclusive)
6130             * @return the range of matching organizations that the user has permission to view
6131             */
6132            @Override
6133            public List<Organization> filterFindByO_C_P(long organizationId,
6134                    long companyId, long parentOrganizationId, int start, int end) {
6135                    return filterFindByO_C_P(organizationId, companyId,
6136                            parentOrganizationId, start, end, null);
6137            }
6138    
6139            /**
6140             * Returns an ordered range of all the organizations that the user has permissions to view where organizationId &gt; &#63; and companyId = &#63; and parentOrganizationId = &#63;.
6141             *
6142             * <p>
6143             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.OrganizationModelImpl}. 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.
6144             * </p>
6145             *
6146             * @param organizationId the organization ID
6147             * @param companyId the company ID
6148             * @param parentOrganizationId the parent organization ID
6149             * @param start the lower bound of the range of organizations
6150             * @param end the upper bound of the range of organizations (not inclusive)
6151             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6152             * @return the ordered range of matching organizations that the user has permission to view
6153             */
6154            @Override
6155            public List<Organization> filterFindByO_C_P(long organizationId,
6156                    long companyId, long parentOrganizationId, int start, int end,
6157                    OrderByComparator<Organization> orderByComparator) {
6158                    if (!InlineSQLHelperUtil.isEnabled()) {
6159                            return findByO_C_P(organizationId, companyId, parentOrganizationId,
6160                                    start, end, orderByComparator);
6161                    }
6162    
6163                    StringBundler query = null;
6164    
6165                    if (orderByComparator != null) {
6166                            query = new StringBundler(5 +
6167                                            (orderByComparator.getOrderByFields().length * 3));
6168                    }
6169                    else {
6170                            query = new StringBundler(5);
6171                    }
6172    
6173                    if (getDB().isSupportsInlineDistinct()) {
6174                            query.append(_FILTER_SQL_SELECT_ORGANIZATION_WHERE);
6175                    }
6176                    else {
6177                            query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_1);
6178                    }
6179    
6180                    query.append(_FINDER_COLUMN_O_C_P_ORGANIZATIONID_2);
6181    
6182                    query.append(_FINDER_COLUMN_O_C_P_COMPANYID_2);
6183    
6184                    query.append(_FINDER_COLUMN_O_C_P_PARENTORGANIZATIONID_2);
6185    
6186                    if (!getDB().isSupportsInlineDistinct()) {
6187                            query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_2);
6188                    }
6189    
6190                    if (orderByComparator != null) {
6191                            if (getDB().isSupportsInlineDistinct()) {
6192                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6193                                            orderByComparator, true);
6194                            }
6195                            else {
6196                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
6197                                            orderByComparator, true);
6198                            }
6199                    }
6200                    else {
6201                            if (getDB().isSupportsInlineDistinct()) {
6202                                    query.append(OrganizationModelImpl.ORDER_BY_JPQL);
6203                            }
6204                            else {
6205                                    query.append(OrganizationModelImpl.ORDER_BY_SQL);
6206                            }
6207                    }
6208    
6209                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6210                                    Organization.class.getName(),
6211                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
6212    
6213                    Session session = null;
6214    
6215                    try {
6216                            session = openSession();
6217    
6218                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
6219    
6220                            if (getDB().isSupportsInlineDistinct()) {
6221                                    q.addEntity(_FILTER_ENTITY_ALIAS, OrganizationImpl.class);
6222                            }
6223                            else {
6224                                    q.addEntity(_FILTER_ENTITY_TABLE, OrganizationImpl.class);
6225                            }
6226    
6227                            QueryPos qPos = QueryPos.getInstance(q);
6228    
6229                            qPos.add(organizationId);
6230    
6231                            qPos.add(companyId);
6232    
6233                            qPos.add(parentOrganizationId);
6234    
6235                            return (List<Organization>)QueryUtil.list(q, getDialect(), start,
6236                                    end);
6237                    }
6238                    catch (Exception e) {
6239                            throw processException(e);
6240                    }
6241                    finally {
6242                            closeSession(session);
6243                    }
6244            }
6245    
6246            /**
6247             * Removes all the organizations where organizationId &gt; &#63; and companyId = &#63; and parentOrganizationId = &#63; from the database.
6248             *
6249             * @param organizationId the organization ID
6250             * @param companyId the company ID
6251             * @param parentOrganizationId the parent organization ID
6252             */
6253            @Override
6254            public void removeByO_C_P(long organizationId, long companyId,
6255                    long parentOrganizationId) {
6256                    for (Organization organization : findByO_C_P(organizationId, companyId,
6257                                    parentOrganizationId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
6258                            remove(organization);
6259                    }
6260            }
6261    
6262            /**
6263             * Returns the number of organizations where organizationId &gt; &#63; and companyId = &#63; and parentOrganizationId = &#63;.
6264             *
6265             * @param organizationId the organization ID
6266             * @param companyId the company ID
6267             * @param parentOrganizationId the parent organization ID
6268             * @return the number of matching organizations
6269             */
6270            @Override
6271            public int countByO_C_P(long organizationId, long companyId,
6272                    long parentOrganizationId) {
6273                    FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_COUNT_BY_O_C_P;
6274    
6275                    Object[] finderArgs = new Object[] {
6276                                    organizationId, companyId, parentOrganizationId
6277                            };
6278    
6279                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
6280                                    this);
6281    
6282                    if (count == null) {
6283                            StringBundler query = new StringBundler(4);
6284    
6285                            query.append(_SQL_COUNT_ORGANIZATION_WHERE);
6286    
6287                            query.append(_FINDER_COLUMN_O_C_P_ORGANIZATIONID_2);
6288    
6289                            query.append(_FINDER_COLUMN_O_C_P_COMPANYID_2);
6290    
6291                            query.append(_FINDER_COLUMN_O_C_P_PARENTORGANIZATIONID_2);
6292    
6293                            String sql = query.toString();
6294    
6295                            Session session = null;
6296    
6297                            try {
6298                                    session = openSession();
6299    
6300                                    Query q = session.createQuery(sql);
6301    
6302                                    QueryPos qPos = QueryPos.getInstance(q);
6303    
6304                                    qPos.add(organizationId);
6305    
6306                                    qPos.add(companyId);
6307    
6308                                    qPos.add(parentOrganizationId);
6309    
6310                                    count = (Long)q.uniqueResult();
6311    
6312                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
6313                            }
6314                            catch (Exception e) {
6315                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
6316    
6317                                    throw processException(e);
6318                            }
6319                            finally {
6320                                    closeSession(session);
6321                            }
6322                    }
6323    
6324                    return count.intValue();
6325            }
6326    
6327            /**
6328             * Returns the number of organizations that the user has permission to view where organizationId &gt; &#63; and companyId = &#63; and parentOrganizationId = &#63;.
6329             *
6330             * @param organizationId the organization ID
6331             * @param companyId the company ID
6332             * @param parentOrganizationId the parent organization ID
6333             * @return the number of matching organizations that the user has permission to view
6334             */
6335            @Override
6336            public int filterCountByO_C_P(long organizationId, long companyId,
6337                    long parentOrganizationId) {
6338                    if (!InlineSQLHelperUtil.isEnabled()) {
6339                            return countByO_C_P(organizationId, companyId, parentOrganizationId);
6340                    }
6341    
6342                    StringBundler query = new StringBundler(4);
6343    
6344                    query.append(_FILTER_SQL_COUNT_ORGANIZATION_WHERE);
6345    
6346                    query.append(_FINDER_COLUMN_O_C_P_ORGANIZATIONID_2);
6347    
6348                    query.append(_FINDER_COLUMN_O_C_P_COMPANYID_2);
6349    
6350                    query.append(_FINDER_COLUMN_O_C_P_PARENTORGANIZATIONID_2);
6351    
6352                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6353                                    Organization.class.getName(),
6354                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
6355    
6356                    Session session = null;
6357    
6358                    try {
6359                            session = openSession();
6360    
6361                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
6362    
6363                            q.addScalar(COUNT_COLUMN_NAME,
6364                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
6365    
6366                            QueryPos qPos = QueryPos.getInstance(q);
6367    
6368                            qPos.add(organizationId);
6369    
6370                            qPos.add(companyId);
6371    
6372                            qPos.add(parentOrganizationId);
6373    
6374                            Long count = (Long)q.uniqueResult();
6375    
6376                            return count.intValue();
6377                    }
6378                    catch (Exception e) {
6379                            throw processException(e);
6380                    }
6381                    finally {
6382                            closeSession(session);
6383                    }
6384            }
6385    
6386            private static final String _FINDER_COLUMN_O_C_P_ORGANIZATIONID_2 = "organization.organizationId > ? AND ";
6387            private static final String _FINDER_COLUMN_O_C_P_COMPANYID_2 = "organization.companyId = ? AND ";
6388            private static final String _FINDER_COLUMN_O_C_P_PARENTORGANIZATIONID_2 = "organization.parentOrganizationId = ?";
6389    
6390            public OrganizationPersistenceImpl() {
6391                    setModelClass(Organization.class);
6392            }
6393    
6394            /**
6395             * Caches the organization in the entity cache if it is enabled.
6396             *
6397             * @param organization the organization
6398             */
6399            @Override
6400            public void cacheResult(Organization organization) {
6401                    EntityCacheUtil.putResult(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
6402                            OrganizationImpl.class, organization.getPrimaryKey(), organization);
6403    
6404                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
6405                            new Object[] { organization.getCompanyId(), organization.getName() },
6406                            organization);
6407    
6408                    organization.resetOriginalValues();
6409            }
6410    
6411            /**
6412             * Caches the organizations in the entity cache if it is enabled.
6413             *
6414             * @param organizations the organizations
6415             */
6416            @Override
6417            public void cacheResult(List<Organization> organizations) {
6418                    for (Organization organization : organizations) {
6419                            if (EntityCacheUtil.getResult(
6420                                                    OrganizationModelImpl.ENTITY_CACHE_ENABLED,
6421                                                    OrganizationImpl.class, organization.getPrimaryKey()) == null) {
6422                                    cacheResult(organization);
6423                            }
6424                            else {
6425                                    organization.resetOriginalValues();
6426                            }
6427                    }
6428            }
6429    
6430            /**
6431             * Clears the cache for all organizations.
6432             *
6433             * <p>
6434             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
6435             * </p>
6436             */
6437            @Override
6438            public void clearCache() {
6439                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
6440                            CacheRegistryUtil.clear(OrganizationImpl.class.getName());
6441                    }
6442    
6443                    EntityCacheUtil.clearCache(OrganizationImpl.class);
6444    
6445                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
6446                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
6447                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
6448            }
6449    
6450            /**
6451             * Clears the cache for the organization.
6452             *
6453             * <p>
6454             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
6455             * </p>
6456             */
6457            @Override
6458            public void clearCache(Organization organization) {
6459                    EntityCacheUtil.removeResult(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
6460                            OrganizationImpl.class, organization.getPrimaryKey());
6461    
6462                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
6463                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
6464    
6465                    clearUniqueFindersCache(organization);
6466            }
6467    
6468            @Override
6469            public void clearCache(List<Organization> organizations) {
6470                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
6471                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
6472    
6473                    for (Organization organization : organizations) {
6474                            EntityCacheUtil.removeResult(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
6475                                    OrganizationImpl.class, organization.getPrimaryKey());
6476    
6477                            clearUniqueFindersCache(organization);
6478                    }
6479            }
6480    
6481            protected void cacheUniqueFindersCache(Organization organization) {
6482                    if (organization.isNew()) {
6483                            Object[] args = new Object[] {
6484                                            organization.getCompanyId(), organization.getName()
6485                                    };
6486    
6487                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_N, args,
6488                                    Long.valueOf(1));
6489                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N, args,
6490                                    organization);
6491                    }
6492                    else {
6493                            OrganizationModelImpl organizationModelImpl = (OrganizationModelImpl)organization;
6494    
6495                            if ((organizationModelImpl.getColumnBitmask() &
6496                                            FINDER_PATH_FETCH_BY_C_N.getColumnBitmask()) != 0) {
6497                                    Object[] args = new Object[] {
6498                                                    organization.getCompanyId(), organization.getName()
6499                                            };
6500    
6501                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_N, args,
6502                                            Long.valueOf(1));
6503                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N, args,
6504                                            organization);
6505                            }
6506                    }
6507            }
6508    
6509            protected void clearUniqueFindersCache(Organization organization) {
6510                    OrganizationModelImpl organizationModelImpl = (OrganizationModelImpl)organization;
6511    
6512                    Object[] args = new Object[] {
6513                                    organization.getCompanyId(), organization.getName()
6514                            };
6515    
6516                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_N, args);
6517                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N, args);
6518    
6519                    if ((organizationModelImpl.getColumnBitmask() &
6520                                    FINDER_PATH_FETCH_BY_C_N.getColumnBitmask()) != 0) {
6521                            args = new Object[] {
6522                                            organizationModelImpl.getOriginalCompanyId(),
6523                                            organizationModelImpl.getOriginalName()
6524                                    };
6525    
6526                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_N, args);
6527                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N, args);
6528                    }
6529            }
6530    
6531            /**
6532             * Creates a new organization with the primary key. Does not add the organization to the database.
6533             *
6534             * @param organizationId the primary key for the new organization
6535             * @return the new organization
6536             */
6537            @Override
6538            public Organization create(long organizationId) {
6539                    Organization organization = new OrganizationImpl();
6540    
6541                    organization.setNew(true);
6542                    organization.setPrimaryKey(organizationId);
6543    
6544                    String uuid = PortalUUIDUtil.generate();
6545    
6546                    organization.setUuid(uuid);
6547    
6548                    return organization;
6549            }
6550    
6551            /**
6552             * Removes the organization with the primary key from the database. Also notifies the appropriate model listeners.
6553             *
6554             * @param organizationId the primary key of the organization
6555             * @return the organization that was removed
6556             * @throws com.liferay.portal.NoSuchOrganizationException if a organization with the primary key could not be found
6557             */
6558            @Override
6559            public Organization remove(long organizationId)
6560                    throws NoSuchOrganizationException {
6561                    return remove((Serializable)organizationId);
6562            }
6563    
6564            /**
6565             * Removes the organization with the primary key from the database. Also notifies the appropriate model listeners.
6566             *
6567             * @param primaryKey the primary key of the organization
6568             * @return the organization that was removed
6569             * @throws com.liferay.portal.NoSuchOrganizationException if a organization with the primary key could not be found
6570             */
6571            @Override
6572            public Organization remove(Serializable primaryKey)
6573                    throws NoSuchOrganizationException {
6574                    Session session = null;
6575    
6576                    try {
6577                            session = openSession();
6578    
6579                            Organization organization = (Organization)session.get(OrganizationImpl.class,
6580                                            primaryKey);
6581    
6582                            if (organization == null) {
6583                                    if (_log.isWarnEnabled()) {
6584                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
6585                                    }
6586    
6587                                    throw new NoSuchOrganizationException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
6588                                            primaryKey);
6589                            }
6590    
6591                            return remove(organization);
6592                    }
6593                    catch (NoSuchOrganizationException nsee) {
6594                            throw nsee;
6595                    }
6596                    catch (Exception e) {
6597                            throw processException(e);
6598                    }
6599                    finally {
6600                            closeSession(session);
6601                    }
6602            }
6603    
6604            @Override
6605            protected Organization removeImpl(Organization organization) {
6606                    organization = toUnwrappedModel(organization);
6607    
6608                    organizationToGroupTableMapper.deleteLeftPrimaryKeyTableMappings(organization.getPrimaryKey());
6609    
6610                    organizationToUserTableMapper.deleteLeftPrimaryKeyTableMappings(organization.getPrimaryKey());
6611    
6612                    Session session = null;
6613    
6614                    try {
6615                            session = openSession();
6616    
6617                            if (!session.contains(organization)) {
6618                                    organization = (Organization)session.get(OrganizationImpl.class,
6619                                                    organization.getPrimaryKeyObj());
6620                            }
6621    
6622                            if (organization != null) {
6623                                    session.delete(organization);
6624                            }
6625                    }
6626                    catch (Exception e) {
6627                            throw processException(e);
6628                    }
6629                    finally {
6630                            closeSession(session);
6631                    }
6632    
6633                    if (organization != null) {
6634                            clearCache(organization);
6635                    }
6636    
6637                    return organization;
6638            }
6639    
6640            @Override
6641            public Organization updateImpl(
6642                    com.liferay.portal.model.Organization organization) {
6643                    organization = toUnwrappedModel(organization);
6644    
6645                    boolean isNew = organization.isNew();
6646    
6647                    OrganizationModelImpl organizationModelImpl = (OrganizationModelImpl)organization;
6648    
6649                    if (Validator.isNull(organization.getUuid())) {
6650                            String uuid = PortalUUIDUtil.generate();
6651    
6652                            organization.setUuid(uuid);
6653                    }
6654    
6655                    Session session = null;
6656    
6657                    try {
6658                            session = openSession();
6659    
6660                            if (organization.isNew()) {
6661                                    session.save(organization);
6662    
6663                                    organization.setNew(false);
6664                            }
6665                            else {
6666                                    session.merge(organization);
6667                            }
6668                    }
6669                    catch (Exception e) {
6670                            throw processException(e);
6671                    }
6672                    finally {
6673                            closeSession(session);
6674                    }
6675    
6676                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
6677    
6678                    if (isNew || !OrganizationModelImpl.COLUMN_BITMASK_ENABLED) {
6679                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
6680                    }
6681    
6682                    else {
6683                            if ((organizationModelImpl.getColumnBitmask() &
6684                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
6685                                    Object[] args = new Object[] {
6686                                                    organizationModelImpl.getOriginalUuid()
6687                                            };
6688    
6689                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
6690                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
6691                                            args);
6692    
6693                                    args = new Object[] { organizationModelImpl.getUuid() };
6694    
6695                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
6696                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
6697                                            args);
6698                            }
6699    
6700                            if ((organizationModelImpl.getColumnBitmask() &
6701                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
6702                                    Object[] args = new Object[] {
6703                                                    organizationModelImpl.getOriginalUuid(),
6704                                                    organizationModelImpl.getOriginalCompanyId()
6705                                            };
6706    
6707                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
6708                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
6709                                            args);
6710    
6711                                    args = new Object[] {
6712                                                    organizationModelImpl.getUuid(),
6713                                                    organizationModelImpl.getCompanyId()
6714                                            };
6715    
6716                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
6717                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
6718                                            args);
6719                            }
6720    
6721                            if ((organizationModelImpl.getColumnBitmask() &
6722                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
6723                                    Object[] args = new Object[] {
6724                                                    organizationModelImpl.getOriginalCompanyId()
6725                                            };
6726    
6727                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
6728                                            args);
6729                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
6730                                            args);
6731    
6732                                    args = new Object[] { organizationModelImpl.getCompanyId() };
6733    
6734                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
6735                                            args);
6736                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
6737                                            args);
6738                            }
6739    
6740                            if ((organizationModelImpl.getColumnBitmask() &
6741                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LOCATIONS.getColumnBitmask()) != 0) {
6742                                    Object[] args = new Object[] {
6743                                                    organizationModelImpl.getOriginalCompanyId()
6744                                            };
6745    
6746                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_LOCATIONS,
6747                                            args);
6748                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LOCATIONS,
6749                                            args);
6750    
6751                                    args = new Object[] { organizationModelImpl.getCompanyId() };
6752    
6753                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_LOCATIONS,
6754                                            args);
6755                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LOCATIONS,
6756                                            args);
6757                            }
6758    
6759                            if ((organizationModelImpl.getColumnBitmask() &
6760                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P.getColumnBitmask()) != 0) {
6761                                    Object[] args = new Object[] {
6762                                                    organizationModelImpl.getOriginalCompanyId(),
6763                                                    organizationModelImpl.getOriginalParentOrganizationId()
6764                                            };
6765    
6766                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_P, args);
6767                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P,
6768                                            args);
6769    
6770                                    args = new Object[] {
6771                                                    organizationModelImpl.getCompanyId(),
6772                                                    organizationModelImpl.getParentOrganizationId()
6773                                            };
6774    
6775                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_P, args);
6776                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P,
6777                                            args);
6778                            }
6779                    }
6780    
6781                    EntityCacheUtil.putResult(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
6782                            OrganizationImpl.class, organization.getPrimaryKey(), organization,
6783                            false);
6784    
6785                    clearUniqueFindersCache(organization);
6786                    cacheUniqueFindersCache(organization);
6787    
6788                    organization.resetOriginalValues();
6789    
6790                    return organization;
6791            }
6792    
6793            protected Organization toUnwrappedModel(Organization organization) {
6794                    if (organization instanceof OrganizationImpl) {
6795                            return organization;
6796                    }
6797    
6798                    OrganizationImpl organizationImpl = new OrganizationImpl();
6799    
6800                    organizationImpl.setNew(organization.isNew());
6801                    organizationImpl.setPrimaryKey(organization.getPrimaryKey());
6802    
6803                    organizationImpl.setMvccVersion(organization.getMvccVersion());
6804                    organizationImpl.setUuid(organization.getUuid());
6805                    organizationImpl.setOrganizationId(organization.getOrganizationId());
6806                    organizationImpl.setCompanyId(organization.getCompanyId());
6807                    organizationImpl.setUserId(organization.getUserId());
6808                    organizationImpl.setUserName(organization.getUserName());
6809                    organizationImpl.setCreateDate(organization.getCreateDate());
6810                    organizationImpl.setModifiedDate(organization.getModifiedDate());
6811                    organizationImpl.setParentOrganizationId(organization.getParentOrganizationId());
6812                    organizationImpl.setTreePath(organization.getTreePath());
6813                    organizationImpl.setName(organization.getName());
6814                    organizationImpl.setType(organization.getType());
6815                    organizationImpl.setRecursable(organization.isRecursable());
6816                    organizationImpl.setRegionId(organization.getRegionId());
6817                    organizationImpl.setCountryId(organization.getCountryId());
6818                    organizationImpl.setStatusId(organization.getStatusId());
6819                    organizationImpl.setComments(organization.getComments());
6820                    organizationImpl.setLogoId(organization.getLogoId());
6821    
6822                    return organizationImpl;
6823            }
6824    
6825            /**
6826             * Returns the organization with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
6827             *
6828             * @param primaryKey the primary key of the organization
6829             * @return the organization
6830             * @throws com.liferay.portal.NoSuchOrganizationException if a organization with the primary key could not be found
6831             */
6832            @Override
6833            public Organization findByPrimaryKey(Serializable primaryKey)
6834                    throws NoSuchOrganizationException {
6835                    Organization organization = fetchByPrimaryKey(primaryKey);
6836    
6837                    if (organization == null) {
6838                            if (_log.isWarnEnabled()) {
6839                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
6840                            }
6841    
6842                            throw new NoSuchOrganizationException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
6843                                    primaryKey);
6844                    }
6845    
6846                    return organization;
6847            }
6848    
6849            /**
6850             * Returns the organization with the primary key or throws a {@link com.liferay.portal.NoSuchOrganizationException} if it could not be found.
6851             *
6852             * @param organizationId the primary key of the organization
6853             * @return the organization
6854             * @throws com.liferay.portal.NoSuchOrganizationException if a organization with the primary key could not be found
6855             */
6856            @Override
6857            public Organization findByPrimaryKey(long organizationId)
6858                    throws NoSuchOrganizationException {
6859                    return findByPrimaryKey((Serializable)organizationId);
6860            }
6861    
6862            /**
6863             * Returns the organization with the primary key or returns <code>null</code> if it could not be found.
6864             *
6865             * @param primaryKey the primary key of the organization
6866             * @return the organization, or <code>null</code> if a organization with the primary key could not be found
6867             */
6868            @Override
6869            public Organization fetchByPrimaryKey(Serializable primaryKey) {
6870                    Organization organization = (Organization)EntityCacheUtil.getResult(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
6871                                    OrganizationImpl.class, primaryKey);
6872    
6873                    if (organization == _nullOrganization) {
6874                            return null;
6875                    }
6876    
6877                    if (organization == null) {
6878                            Session session = null;
6879    
6880                            try {
6881                                    session = openSession();
6882    
6883                                    organization = (Organization)session.get(OrganizationImpl.class,
6884                                                    primaryKey);
6885    
6886                                    if (organization != null) {
6887                                            cacheResult(organization);
6888                                    }
6889                                    else {
6890                                            EntityCacheUtil.putResult(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
6891                                                    OrganizationImpl.class, primaryKey, _nullOrganization);
6892                                    }
6893                            }
6894                            catch (Exception e) {
6895                                    EntityCacheUtil.removeResult(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
6896                                            OrganizationImpl.class, primaryKey);
6897    
6898                                    throw processException(e);
6899                            }
6900                            finally {
6901                                    closeSession(session);
6902                            }
6903                    }
6904    
6905                    return organization;
6906            }
6907    
6908            /**
6909             * Returns the organization with the primary key or returns <code>null</code> if it could not be found.
6910             *
6911             * @param organizationId the primary key of the organization
6912             * @return the organization, or <code>null</code> if a organization with the primary key could not be found
6913             */
6914            @Override
6915            public Organization fetchByPrimaryKey(long organizationId) {
6916                    return fetchByPrimaryKey((Serializable)organizationId);
6917            }
6918    
6919            @Override
6920            public Map<Serializable, Organization> fetchByPrimaryKeys(
6921                    Set<Serializable> primaryKeys) {
6922                    if (primaryKeys.isEmpty()) {
6923                            return Collections.emptyMap();
6924                    }
6925    
6926                    Map<Serializable, Organization> map = new HashMap<Serializable, Organization>();
6927    
6928                    if (primaryKeys.size() == 1) {
6929                            Iterator<Serializable> iterator = primaryKeys.iterator();
6930    
6931                            Serializable primaryKey = iterator.next();
6932    
6933                            Organization organization = fetchByPrimaryKey(primaryKey);
6934    
6935                            if (organization != null) {
6936                                    map.put(primaryKey, organization);
6937                            }
6938    
6939                            return map;
6940                    }
6941    
6942                    Set<Serializable> uncachedPrimaryKeys = null;
6943    
6944                    for (Serializable primaryKey : primaryKeys) {
6945                            Organization organization = (Organization)EntityCacheUtil.getResult(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
6946                                            OrganizationImpl.class, primaryKey);
6947    
6948                            if (organization == null) {
6949                                    if (uncachedPrimaryKeys == null) {
6950                                            uncachedPrimaryKeys = new HashSet<Serializable>();
6951                                    }
6952    
6953                                    uncachedPrimaryKeys.add(primaryKey);
6954                            }
6955                            else {
6956                                    map.put(primaryKey, organization);
6957                            }
6958                    }
6959    
6960                    if (uncachedPrimaryKeys == null) {
6961                            return map;
6962                    }
6963    
6964                    StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
6965                                    1);
6966    
6967                    query.append(_SQL_SELECT_ORGANIZATION_WHERE_PKS_IN);
6968    
6969                    for (Serializable primaryKey : uncachedPrimaryKeys) {
6970                            query.append(String.valueOf(primaryKey));
6971    
6972                            query.append(StringPool.COMMA);
6973                    }
6974    
6975                    query.setIndex(query.index() - 1);
6976    
6977                    query.append(StringPool.CLOSE_PARENTHESIS);
6978    
6979                    String sql = query.toString();
6980    
6981                    Session session = null;
6982    
6983                    try {
6984                            session = openSession();
6985    
6986                            Query q = session.createQuery(sql);
6987    
6988                            for (Organization organization : (List<Organization>)q.list()) {
6989                                    map.put(organization.getPrimaryKeyObj(), organization);
6990    
6991                                    cacheResult(organization);
6992    
6993                                    uncachedPrimaryKeys.remove(organization.getPrimaryKeyObj());
6994                            }
6995    
6996                            for (Serializable primaryKey : uncachedPrimaryKeys) {
6997                                    EntityCacheUtil.putResult(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
6998                                            OrganizationImpl.class, primaryKey, _nullOrganization);
6999                            }
7000                    }
7001                    catch (Exception e) {
7002                            throw processException(e);
7003                    }
7004                    finally {
7005                            closeSession(session);
7006                    }
7007    
7008                    return map;
7009            }
7010    
7011            /**
7012             * Returns all the organizations.
7013             *
7014             * @return the organizations
7015             */
7016            @Override
7017            public List<Organization> findAll() {
7018                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
7019            }
7020    
7021            /**
7022             * Returns a range of all the organizations.
7023             *
7024             * <p>
7025             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.OrganizationModelImpl}. 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.
7026             * </p>
7027             *
7028             * @param start the lower bound of the range of organizations
7029             * @param end the upper bound of the range of organizations (not inclusive)
7030             * @return the range of organizations
7031             */
7032            @Override
7033            public List<Organization> findAll(int start, int end) {
7034                    return findAll(start, end, null);
7035            }
7036    
7037            /**
7038             * Returns an ordered range of all the organizations.
7039             *
7040             * <p>
7041             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.OrganizationModelImpl}. 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.
7042             * </p>
7043             *
7044             * @param start the lower bound of the range of organizations
7045             * @param end the upper bound of the range of organizations (not inclusive)
7046             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7047             * @return the ordered range of organizations
7048             */
7049            @Override
7050            public List<Organization> findAll(int start, int end,
7051                    OrderByComparator<Organization> orderByComparator) {
7052                    boolean pagination = true;
7053                    FinderPath finderPath = null;
7054                    Object[] finderArgs = null;
7055    
7056                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
7057                                    (orderByComparator == null)) {
7058                            pagination = false;
7059                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
7060                            finderArgs = FINDER_ARGS_EMPTY;
7061                    }
7062                    else {
7063                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
7064                            finderArgs = new Object[] { start, end, orderByComparator };
7065                    }
7066    
7067                    List<Organization> list = (List<Organization>)FinderCacheUtil.getResult(finderPath,
7068                                    finderArgs, this);
7069    
7070                    if (list == null) {
7071                            StringBundler query = null;
7072                            String sql = null;
7073    
7074                            if (orderByComparator != null) {
7075                                    query = new StringBundler(2 +
7076                                                    (orderByComparator.getOrderByFields().length * 3));
7077    
7078                                    query.append(_SQL_SELECT_ORGANIZATION);
7079    
7080                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7081                                            orderByComparator);
7082    
7083                                    sql = query.toString();
7084                            }
7085                            else {
7086                                    sql = _SQL_SELECT_ORGANIZATION;
7087    
7088                                    if (pagination) {
7089                                            sql = sql.concat(OrganizationModelImpl.ORDER_BY_JPQL);
7090                                    }
7091                            }
7092    
7093                            Session session = null;
7094    
7095                            try {
7096                                    session = openSession();
7097    
7098                                    Query q = session.createQuery(sql);
7099    
7100                                    if (!pagination) {
7101                                            list = (List<Organization>)QueryUtil.list(q, getDialect(),
7102                                                            start, end, false);
7103    
7104                                            Collections.sort(list);
7105    
7106                                            list = Collections.unmodifiableList(list);
7107                                    }
7108                                    else {
7109                                            list = (List<Organization>)QueryUtil.list(q, getDialect(),
7110                                                            start, end);
7111                                    }
7112    
7113                                    cacheResult(list);
7114    
7115                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
7116                            }
7117                            catch (Exception e) {
7118                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
7119    
7120                                    throw processException(e);
7121                            }
7122                            finally {
7123                                    closeSession(session);
7124                            }
7125                    }
7126    
7127                    return list;
7128            }
7129    
7130            /**
7131             * Removes all the organizations from the database.
7132             *
7133             */
7134            @Override
7135            public void removeAll() {
7136                    for (Organization organization : findAll()) {
7137                            remove(organization);
7138                    }
7139            }
7140    
7141            /**
7142             * Returns the number of organizations.
7143             *
7144             * @return the number of organizations
7145             */
7146            @Override
7147            public int countAll() {
7148                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
7149                                    FINDER_ARGS_EMPTY, this);
7150    
7151                    if (count == null) {
7152                            Session session = null;
7153    
7154                            try {
7155                                    session = openSession();
7156    
7157                                    Query q = session.createQuery(_SQL_COUNT_ORGANIZATION);
7158    
7159                                    count = (Long)q.uniqueResult();
7160    
7161                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
7162                                            FINDER_ARGS_EMPTY, count);
7163                            }
7164                            catch (Exception e) {
7165                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
7166                                            FINDER_ARGS_EMPTY);
7167    
7168                                    throw processException(e);
7169                            }
7170                            finally {
7171                                    closeSession(session);
7172                            }
7173                    }
7174    
7175                    return count.intValue();
7176            }
7177    
7178            /**
7179             * Returns the primaryKeys of groups associated with the organization.
7180             *
7181             * @param pk the primary key of the organization
7182             * @return long[] of the primaryKeys of groups associated with the organization
7183             */
7184            @Override
7185            public long[] getGroupPrimaryKeys(long pk) {
7186                    long[] pks = organizationToGroupTableMapper.getRightPrimaryKeys(pk);
7187    
7188                    return pks.clone();
7189            }
7190    
7191            /**
7192             * Returns all the groups associated with the organization.
7193             *
7194             * @param pk the primary key of the organization
7195             * @return the groups associated with the organization
7196             */
7197            @Override
7198            public List<com.liferay.portal.model.Group> getGroups(long pk) {
7199                    return getGroups(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
7200            }
7201    
7202            /**
7203             * Returns a range of all the groups associated with the organization.
7204             *
7205             * <p>
7206             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.OrganizationModelImpl}. 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.
7207             * </p>
7208             *
7209             * @param pk the primary key of the organization
7210             * @param start the lower bound of the range of organizations
7211             * @param end the upper bound of the range of organizations (not inclusive)
7212             * @return the range of groups associated with the organization
7213             */
7214            @Override
7215            public List<com.liferay.portal.model.Group> getGroups(long pk, int start,
7216                    int end) {
7217                    return getGroups(pk, start, end, null);
7218            }
7219    
7220            /**
7221             * Returns an ordered range of all the groups associated with the organization.
7222             *
7223             * <p>
7224             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.OrganizationModelImpl}. 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.
7225             * </p>
7226             *
7227             * @param pk the primary key of the organization
7228             * @param start the lower bound of the range of organizations
7229             * @param end the upper bound of the range of organizations (not inclusive)
7230             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7231             * @return the ordered range of groups associated with the organization
7232             */
7233            @Override
7234            public List<com.liferay.portal.model.Group> getGroups(long pk, int start,
7235                    int end,
7236                    OrderByComparator<com.liferay.portal.model.Group> orderByComparator) {
7237                    return organizationToGroupTableMapper.getRightBaseModels(pk, start,
7238                            end, orderByComparator);
7239            }
7240    
7241            /**
7242             * Returns the number of groups associated with the organization.
7243             *
7244             * @param pk the primary key of the organization
7245             * @return the number of groups associated with the organization
7246             */
7247            @Override
7248            public int getGroupsSize(long pk) {
7249                    long[] pks = organizationToGroupTableMapper.getRightPrimaryKeys(pk);
7250    
7251                    return pks.length;
7252            }
7253    
7254            /**
7255             * Returns <code>true</code> if the group is associated with the organization.
7256             *
7257             * @param pk the primary key of the organization
7258             * @param groupPK the primary key of the group
7259             * @return <code>true</code> if the group is associated with the organization; <code>false</code> otherwise
7260             */
7261            @Override
7262            public boolean containsGroup(long pk, long groupPK) {
7263                    return organizationToGroupTableMapper.containsTableMapping(pk, groupPK);
7264            }
7265    
7266            /**
7267             * Returns <code>true</code> if the organization has any groups associated with it.
7268             *
7269             * @param pk the primary key of the organization to check for associations with groups
7270             * @return <code>true</code> if the organization has any groups associated with it; <code>false</code> otherwise
7271             */
7272            @Override
7273            public boolean containsGroups(long pk) {
7274                    if (getGroupsSize(pk) > 0) {
7275                            return true;
7276                    }
7277                    else {
7278                            return false;
7279                    }
7280            }
7281    
7282            /**
7283             * Adds an association between the organization and the group. Also notifies the appropriate model listeners and clears the mapping table finder cache.
7284             *
7285             * @param pk the primary key of the organization
7286             * @param groupPK the primary key of the group
7287             */
7288            @Override
7289            public void addGroup(long pk, long groupPK) {
7290                    organizationToGroupTableMapper.addTableMapping(pk, groupPK);
7291            }
7292    
7293            /**
7294             * Adds an association between the organization and the group. Also notifies the appropriate model listeners and clears the mapping table finder cache.
7295             *
7296             * @param pk the primary key of the organization
7297             * @param group the group
7298             */
7299            @Override
7300            public void addGroup(long pk, com.liferay.portal.model.Group group) {
7301                    organizationToGroupTableMapper.addTableMapping(pk, group.getPrimaryKey());
7302            }
7303    
7304            /**
7305             * Adds an association between the organization and the groups. Also notifies the appropriate model listeners and clears the mapping table finder cache.
7306             *
7307             * @param pk the primary key of the organization
7308             * @param groupPKs the primary keys of the groups
7309             */
7310            @Override
7311            public void addGroups(long pk, long[] groupPKs) {
7312                    for (long groupPK : groupPKs) {
7313                            organizationToGroupTableMapper.addTableMapping(pk, groupPK);
7314                    }
7315            }
7316    
7317            /**
7318             * Adds an association between the organization and the groups. Also notifies the appropriate model listeners and clears the mapping table finder cache.
7319             *
7320             * @param pk the primary key of the organization
7321             * @param groups the groups
7322             */
7323            @Override
7324            public void addGroups(long pk, List<com.liferay.portal.model.Group> groups) {
7325                    for (com.liferay.portal.model.Group group : groups) {
7326                            organizationToGroupTableMapper.addTableMapping(pk,
7327                                    group.getPrimaryKey());
7328                    }
7329            }
7330    
7331            /**
7332             * Clears all associations between the organization and its groups. Also notifies the appropriate model listeners and clears the mapping table finder cache.
7333             *
7334             * @param pk the primary key of the organization to clear the associated groups from
7335             */
7336            @Override
7337            public void clearGroups(long pk) {
7338                    organizationToGroupTableMapper.deleteLeftPrimaryKeyTableMappings(pk);
7339            }
7340    
7341            /**
7342             * Removes the association between the organization and the group. Also notifies the appropriate model listeners and clears the mapping table finder cache.
7343             *
7344             * @param pk the primary key of the organization
7345             * @param groupPK the primary key of the group
7346             */
7347            @Override
7348            public void removeGroup(long pk, long groupPK) {
7349                    organizationToGroupTableMapper.deleteTableMapping(pk, groupPK);
7350            }
7351    
7352            /**
7353             * Removes the association between the organization and the group. Also notifies the appropriate model listeners and clears the mapping table finder cache.
7354             *
7355             * @param pk the primary key of the organization
7356             * @param group the group
7357             */
7358            @Override
7359            public void removeGroup(long pk, com.liferay.portal.model.Group group) {
7360                    organizationToGroupTableMapper.deleteTableMapping(pk,
7361                            group.getPrimaryKey());
7362            }
7363    
7364            /**
7365             * Removes the association between the organization and the groups. Also notifies the appropriate model listeners and clears the mapping table finder cache.
7366             *
7367             * @param pk the primary key of the organization
7368             * @param groupPKs the primary keys of the groups
7369             */
7370            @Override
7371            public void removeGroups(long pk, long[] groupPKs) {
7372                    for (long groupPK : groupPKs) {
7373                            organizationToGroupTableMapper.deleteTableMapping(pk, groupPK);
7374                    }
7375            }
7376    
7377            /**
7378             * Removes the association between the organization and the groups. Also notifies the appropriate model listeners and clears the mapping table finder cache.
7379             *
7380             * @param pk the primary key of the organization
7381             * @param groups the groups
7382             */
7383            @Override
7384            public void removeGroups(long pk,
7385                    List<com.liferay.portal.model.Group> groups) {
7386                    for (com.liferay.portal.model.Group group : groups) {
7387                            organizationToGroupTableMapper.deleteTableMapping(pk,
7388                                    group.getPrimaryKey());
7389                    }
7390            }
7391    
7392            /**
7393             * Sets the groups associated with the organization, removing and adding associations as necessary. Also notifies the appropriate model listeners and clears the mapping table finder cache.
7394             *
7395             * @param pk the primary key of the organization
7396             * @param groupPKs the primary keys of the groups to be associated with the organization
7397             */
7398            @Override
7399            public void setGroups(long pk, long[] groupPKs) {
7400                    Set<Long> newGroupPKsSet = SetUtil.fromArray(groupPKs);
7401                    Set<Long> oldGroupPKsSet = SetUtil.fromArray(organizationToGroupTableMapper.getRightPrimaryKeys(
7402                                            pk));
7403    
7404                    Set<Long> removeGroupPKsSet = new HashSet<Long>(oldGroupPKsSet);
7405    
7406                    removeGroupPKsSet.removeAll(newGroupPKsSet);
7407    
7408                    for (long removeGroupPK : removeGroupPKsSet) {
7409                            organizationToGroupTableMapper.deleteTableMapping(pk, removeGroupPK);
7410                    }
7411    
7412                    newGroupPKsSet.removeAll(oldGroupPKsSet);
7413    
7414                    for (long newGroupPK : newGroupPKsSet) {
7415                            organizationToGroupTableMapper.addTableMapping(pk, newGroupPK);
7416                    }
7417            }
7418    
7419            /**
7420             * Sets the groups associated with the organization, removing and adding associations as necessary. Also notifies the appropriate model listeners and clears the mapping table finder cache.
7421             *
7422             * @param pk the primary key of the organization
7423             * @param groups the groups to be associated with the organization
7424             */
7425            @Override
7426            public void setGroups(long pk, List<com.liferay.portal.model.Group> groups) {
7427                    try {
7428                            long[] groupPKs = new long[groups.size()];
7429    
7430                            for (int i = 0; i < groups.size(); i++) {
7431                                    com.liferay.portal.model.Group group = groups.get(i);
7432    
7433                                    groupPKs[i] = group.getPrimaryKey();
7434                            }
7435    
7436                            setGroups(pk, groupPKs);
7437                    }
7438                    catch (Exception e) {
7439                            throw processException(e);
7440                    }
7441            }
7442    
7443            /**
7444             * Returns the primaryKeys of users associated with the organization.
7445             *
7446             * @param pk the primary key of the organization
7447             * @return long[] of the primaryKeys of users associated with the organization
7448             */
7449            @Override
7450            public long[] getUserPrimaryKeys(long pk) {
7451                    long[] pks = organizationToUserTableMapper.getRightPrimaryKeys(pk);
7452    
7453                    return pks.clone();
7454            }
7455    
7456            /**
7457             * Returns all the users associated with the organization.
7458             *
7459             * @param pk the primary key of the organization
7460             * @return the users associated with the organization
7461             */
7462            @Override
7463            public List<com.liferay.portal.model.User> getUsers(long pk) {
7464                    return getUsers(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
7465            }
7466    
7467            /**
7468             * Returns a range of all the users associated with the organization.
7469             *
7470             * <p>
7471             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.OrganizationModelImpl}. 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.
7472             * </p>
7473             *
7474             * @param pk the primary key of the organization
7475             * @param start the lower bound of the range of organizations
7476             * @param end the upper bound of the range of organizations (not inclusive)
7477             * @return the range of users associated with the organization
7478             */
7479            @Override
7480            public List<com.liferay.portal.model.User> getUsers(long pk, int start,
7481                    int end) {
7482                    return getUsers(pk, start, end, null);
7483            }
7484    
7485            /**
7486             * Returns an ordered range of all the users associated with the organization.
7487             *
7488             * <p>
7489             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.OrganizationModelImpl}. 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.
7490             * </p>
7491             *
7492             * @param pk the primary key of the organization
7493             * @param start the lower bound of the range of organizations
7494             * @param end the upper bound of the range of organizations (not inclusive)
7495             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7496             * @return the ordered range of users associated with the organization
7497             */
7498            @Override
7499            public List<com.liferay.portal.model.User> getUsers(long pk, int start,
7500                    int end,
7501                    OrderByComparator<com.liferay.portal.model.User> orderByComparator) {
7502                    return organizationToUserTableMapper.getRightBaseModels(pk, start, end,
7503                            orderByComparator);
7504            }
7505    
7506            /**
7507             * Returns the number of users associated with the organization.
7508             *
7509             * @param pk the primary key of the organization
7510             * @return the number of users associated with the organization
7511             */
7512            @Override
7513            public int getUsersSize(long pk) {
7514                    long[] pks = organizationToUserTableMapper.getRightPrimaryKeys(pk);
7515    
7516                    return pks.length;
7517            }
7518    
7519            /**
7520             * Returns <code>true</code> if the user is associated with the organization.
7521             *
7522             * @param pk the primary key of the organization
7523             * @param userPK the primary key of the user
7524             * @return <code>true</code> if the user is associated with the organization; <code>false</code> otherwise
7525             */
7526            @Override
7527            public boolean containsUser(long pk, long userPK) {
7528                    return organizationToUserTableMapper.containsTableMapping(pk, userPK);
7529            }
7530    
7531            /**
7532             * Returns <code>true</code> if the organization has any users associated with it.
7533             *
7534             * @param pk the primary key of the organization to check for associations with users
7535             * @return <code>true</code> if the organization has any users associated with it; <code>false</code> otherwise
7536             */
7537            @Override
7538            public boolean containsUsers(long pk) {
7539                    if (getUsersSize(pk) > 0) {
7540                            return true;
7541                    }
7542                    else {
7543                            return false;
7544                    }
7545            }
7546    
7547            /**
7548             * Adds an association between the organization and the user. Also notifies the appropriate model listeners and clears the mapping table finder cache.
7549             *
7550             * @param pk the primary key of the organization
7551             * @param userPK the primary key of the user
7552             */
7553            @Override
7554            public void addUser(long pk, long userPK) {
7555                    organizationToUserTableMapper.addTableMapping(pk, userPK);
7556            }
7557    
7558            /**
7559             * Adds an association between the organization and the user. Also notifies the appropriate model listeners and clears the mapping table finder cache.
7560             *
7561             * @param pk the primary key of the organization
7562             * @param user the user
7563             */
7564            @Override
7565            public void addUser(long pk, com.liferay.portal.model.User user) {
7566                    organizationToUserTableMapper.addTableMapping(pk, user.getPrimaryKey());
7567            }
7568    
7569            /**
7570             * Adds an association between the organization and the users. Also notifies the appropriate model listeners and clears the mapping table finder cache.
7571             *
7572             * @param pk the primary key of the organization
7573             * @param userPKs the primary keys of the users
7574             */
7575            @Override
7576            public void addUsers(long pk, long[] userPKs) {
7577                    for (long userPK : userPKs) {
7578                            organizationToUserTableMapper.addTableMapping(pk, userPK);
7579                    }
7580            }
7581    
7582            /**
7583             * Adds an association between the organization and the users. Also notifies the appropriate model listeners and clears the mapping table finder cache.
7584             *
7585             * @param pk the primary key of the organization
7586             * @param users the users
7587             */
7588            @Override
7589            public void addUsers(long pk, List<com.liferay.portal.model.User> users) {
7590                    for (com.liferay.portal.model.User user : users) {
7591                            organizationToUserTableMapper.addTableMapping(pk,
7592                                    user.getPrimaryKey());
7593                    }
7594            }
7595    
7596            /**
7597             * Clears all associations between the organization and its users. Also notifies the appropriate model listeners and clears the mapping table finder cache.
7598             *
7599             * @param pk the primary key of the organization to clear the associated users from
7600             */
7601            @Override
7602            public void clearUsers(long pk) {
7603                    organizationToUserTableMapper.deleteLeftPrimaryKeyTableMappings(pk);
7604            }
7605    
7606            /**
7607             * Removes the association between the organization and the user. Also notifies the appropriate model listeners and clears the mapping table finder cache.
7608             *
7609             * @param pk the primary key of the organization
7610             * @param userPK the primary key of the user
7611             */
7612            @Override
7613            public void removeUser(long pk, long userPK) {
7614                    organizationToUserTableMapper.deleteTableMapping(pk, userPK);
7615            }
7616    
7617            /**
7618             * Removes the association between the organization and the user. Also notifies the appropriate model listeners and clears the mapping table finder cache.
7619             *
7620             * @param pk the primary key of the organization
7621             * @param user the user
7622             */
7623            @Override
7624            public void removeUser(long pk, com.liferay.portal.model.User user) {
7625                    organizationToUserTableMapper.deleteTableMapping(pk,
7626                            user.getPrimaryKey());
7627            }
7628    
7629            /**
7630             * Removes the association between the organization and the users. Also notifies the appropriate model listeners and clears the mapping table finder cache.
7631             *
7632             * @param pk the primary key of the organization
7633             * @param userPKs the primary keys of the users
7634             */
7635            @Override
7636            public void removeUsers(long pk, long[] userPKs) {
7637                    for (long userPK : userPKs) {
7638                            organizationToUserTableMapper.deleteTableMapping(pk, userPK);
7639                    }
7640            }
7641    
7642            /**
7643             * Removes the association between the organization and the users. Also notifies the appropriate model listeners and clears the mapping table finder cache.
7644             *
7645             * @param pk the primary key of the organization
7646             * @param users the users
7647             */
7648            @Override
7649            public void removeUsers(long pk, List<com.liferay.portal.model.User> users) {
7650                    for (com.liferay.portal.model.User user : users) {
7651                            organizationToUserTableMapper.deleteTableMapping(pk,
7652                                    user.getPrimaryKey());
7653                    }
7654            }
7655    
7656            /**
7657             * Sets the users associated with the organization, removing and adding associations as necessary. Also notifies the appropriate model listeners and clears the mapping table finder cache.
7658             *
7659             * @param pk the primary key of the organization
7660             * @param userPKs the primary keys of the users to be associated with the organization
7661             */
7662            @Override
7663            public void setUsers(long pk, long[] userPKs) {
7664                    Set<Long> newUserPKsSet = SetUtil.fromArray(userPKs);
7665                    Set<Long> oldUserPKsSet = SetUtil.fromArray(organizationToUserTableMapper.getRightPrimaryKeys(
7666                                            pk));
7667    
7668                    Set<Long> removeUserPKsSet = new HashSet<Long>(oldUserPKsSet);
7669    
7670                    removeUserPKsSet.removeAll(newUserPKsSet);
7671    
7672                    for (long removeUserPK : removeUserPKsSet) {
7673                            organizationToUserTableMapper.deleteTableMapping(pk, removeUserPK);
7674                    }
7675    
7676                    newUserPKsSet.removeAll(oldUserPKsSet);
7677    
7678                    for (long newUserPK : newUserPKsSet) {
7679                            organizationToUserTableMapper.addTableMapping(pk, newUserPK);
7680                    }
7681            }
7682    
7683            /**
7684             * Sets the users associated with the organization, removing and adding associations as necessary. Also notifies the appropriate model listeners and clears the mapping table finder cache.
7685             *
7686             * @param pk the primary key of the organization
7687             * @param users the users to be associated with the organization
7688             */
7689            @Override
7690            public void setUsers(long pk, List<com.liferay.portal.model.User> users) {
7691                    try {
7692                            long[] userPKs = new long[users.size()];
7693    
7694                            for (int i = 0; i < users.size(); i++) {
7695                                    com.liferay.portal.model.User user = users.get(i);
7696    
7697                                    userPKs[i] = user.getPrimaryKey();
7698                            }
7699    
7700                            setUsers(pk, userPKs);
7701                    }
7702                    catch (Exception e) {
7703                            throw processException(e);
7704                    }
7705            }
7706    
7707            @Override
7708            protected Set<String> getBadColumnNames() {
7709                    return _badColumnNames;
7710            }
7711    
7712            /**
7713             * Initializes the organization persistence.
7714             */
7715            public void afterPropertiesSet() {
7716                    organizationToGroupTableMapper = TableMapperFactory.getTableMapper("Groups_Orgs",
7717                                    "organizationId", "groupId", this, groupPersistence);
7718    
7719                    organizationToUserTableMapper = TableMapperFactory.getTableMapper("Users_Orgs",
7720                                    "organizationId", "userId", this, userPersistence);
7721            }
7722    
7723            public void destroy() {
7724                    EntityCacheUtil.removeCache(OrganizationImpl.class.getName());
7725                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
7726                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
7727                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
7728    
7729                    TableMapperFactory.removeTableMapper("Groups_Orgs");
7730                    TableMapperFactory.removeTableMapper("Users_Orgs");
7731            }
7732    
7733            @BeanReference(type = GroupPersistence.class)
7734            protected GroupPersistence groupPersistence;
7735            protected TableMapper<Organization, com.liferay.portal.model.Group> organizationToGroupTableMapper;
7736            @BeanReference(type = UserPersistence.class)
7737            protected UserPersistence userPersistence;
7738            protected TableMapper<Organization, com.liferay.portal.model.User> organizationToUserTableMapper;
7739            private static final String _SQL_SELECT_ORGANIZATION = "SELECT organization FROM Organization organization";
7740            private static final String _SQL_SELECT_ORGANIZATION_WHERE_PKS_IN = "SELECT organization FROM Organization organization WHERE organizationId IN (";
7741            private static final String _SQL_SELECT_ORGANIZATION_WHERE = "SELECT organization FROM Organization organization WHERE ";
7742            private static final String _SQL_COUNT_ORGANIZATION = "SELECT COUNT(organization) FROM Organization organization";
7743            private static final String _SQL_COUNT_ORGANIZATION_WHERE = "SELECT COUNT(organization) FROM Organization organization WHERE ";
7744            private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "organization.organizationId";
7745            private static final String _FILTER_SQL_SELECT_ORGANIZATION_WHERE = "SELECT DISTINCT {organization.*} FROM Organization_ organization WHERE ";
7746            private static final String _FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_1 =
7747                    "SELECT {Organization_.*} FROM (SELECT DISTINCT organization.organizationId FROM Organization_ organization WHERE ";
7748            private static final String _FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_2 =
7749                    ") TEMP_TABLE INNER JOIN Organization_ ON TEMP_TABLE.organizationId = Organization_.organizationId";
7750            private static final String _FILTER_SQL_COUNT_ORGANIZATION_WHERE = "SELECT COUNT(DISTINCT organization.organizationId) AS COUNT_VALUE FROM Organization_ organization WHERE ";
7751            private static final String _FILTER_ENTITY_ALIAS = "organization";
7752            private static final String _FILTER_ENTITY_TABLE = "Organization_";
7753            private static final String _ORDER_BY_ENTITY_ALIAS = "organization.";
7754            private static final String _ORDER_BY_ENTITY_TABLE = "Organization_.";
7755            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Organization exists with the primary key ";
7756            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Organization exists with the key {";
7757            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
7758            private static final Log _log = LogFactoryUtil.getLog(OrganizationPersistenceImpl.class);
7759            private static final Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
7760                                    "uuid", "type"
7761                            });
7762            private static final Organization _nullOrganization = new OrganizationImpl() {
7763                            @Override
7764                            public Object clone() {
7765                                    return this;
7766                            }
7767    
7768                            @Override
7769                            public CacheModel<Organization> toCacheModel() {
7770                                    return _nullOrganizationCacheModel;
7771                            }
7772                    };
7773    
7774            private static final CacheModel<Organization> _nullOrganizationCacheModel = new NullCacheModel();
7775    
7776            private static class NullCacheModel implements CacheModel<Organization>,
7777                    MVCCModel {
7778                    @Override
7779                    public long getMvccVersion() {
7780                            return -1;
7781                    }
7782    
7783                    @Override
7784                    public void setMvccVersion(long mvccVersion) {
7785                    }
7786    
7787                    @Override
7788                    public Organization toEntityModel() {
7789                            return _nullOrganization;
7790                    }
7791            }
7792    }