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