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.NoSuchModelException;
018    import com.liferay.portal.NoSuchOrganizationException;
019    import com.liferay.portal.kernel.bean.BeanReference;
020    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
021    import com.liferay.portal.kernel.dao.jdbc.MappingSqlQuery;
022    import com.liferay.portal.kernel.dao.jdbc.MappingSqlQueryFactoryUtil;
023    import com.liferay.portal.kernel.dao.jdbc.RowMapper;
024    import com.liferay.portal.kernel.dao.jdbc.SqlUpdate;
025    import com.liferay.portal.kernel.dao.jdbc.SqlUpdateFactoryUtil;
026    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
027    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
028    import com.liferay.portal.kernel.dao.orm.FinderPath;
029    import com.liferay.portal.kernel.dao.orm.Query;
030    import com.liferay.portal.kernel.dao.orm.QueryPos;
031    import com.liferay.portal.kernel.dao.orm.QueryUtil;
032    import com.liferay.portal.kernel.dao.orm.SQLQuery;
033    import com.liferay.portal.kernel.dao.orm.Session;
034    import com.liferay.portal.kernel.exception.SystemException;
035    import com.liferay.portal.kernel.log.Log;
036    import com.liferay.portal.kernel.log.LogFactoryUtil;
037    import com.liferay.portal.kernel.util.GetterUtil;
038    import com.liferay.portal.kernel.util.InstanceFactory;
039    import com.liferay.portal.kernel.util.OrderByComparator;
040    import com.liferay.portal.kernel.util.SetUtil;
041    import com.liferay.portal.kernel.util.StringBundler;
042    import com.liferay.portal.kernel.util.StringPool;
043    import com.liferay.portal.kernel.util.StringUtil;
044    import com.liferay.portal.kernel.util.Validator;
045    import com.liferay.portal.model.CacheModel;
046    import com.liferay.portal.model.ModelListener;
047    import com.liferay.portal.model.Organization;
048    import com.liferay.portal.model.impl.OrganizationImpl;
049    import com.liferay.portal.model.impl.OrganizationModelImpl;
050    import com.liferay.portal.security.permission.InlineSQLHelperUtil;
051    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
052    
053    import com.liferay.portlet.asset.service.persistence.AssetEntryPersistence;
054    import com.liferay.portlet.expando.service.persistence.ExpandoValuePersistence;
055    
056    import java.io.Serializable;
057    
058    import java.util.ArrayList;
059    import java.util.Collections;
060    import java.util.List;
061    import java.util.Set;
062    
063    /**
064     * The persistence implementation for the organization service.
065     *
066     * <p>
067     * Caching information and settings can be found in <code>portal.properties</code>
068     * </p>
069     *
070     * @author Brian Wing Shun Chan
071     * @see OrganizationPersistence
072     * @see OrganizationUtil
073     * @generated
074     */
075    public class OrganizationPersistenceImpl extends BasePersistenceImpl<Organization>
076            implements OrganizationPersistence {
077            /*
078             * NOTE FOR DEVELOPERS:
079             *
080             * 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.
081             */
082            public static final String FINDER_CLASS_NAME_ENTITY = OrganizationImpl.class.getName();
083            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
084                    ".List1";
085            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
086                    ".List2";
087            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
088                    new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
089                            OrganizationModelImpl.FINDER_CACHE_ENABLED, OrganizationImpl.class,
090                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByCompanyId",
091                            new String[] {
092                                    Long.class.getName(),
093                                    
094                            "java.lang.Integer", "java.lang.Integer",
095                                    "com.liferay.portal.kernel.util.OrderByComparator"
096                            });
097            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
098                    new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
099                            OrganizationModelImpl.FINDER_CACHE_ENABLED, OrganizationImpl.class,
100                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCompanyId",
101                            new String[] { Long.class.getName() },
102                            OrganizationModelImpl.COMPANYID_COLUMN_BITMASK);
103            public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
104                            OrganizationModelImpl.FINDER_CACHE_ENABLED, Long.class,
105                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
106                            new String[] { Long.class.getName() });
107            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_LOCATIONS =
108                    new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
109                            OrganizationModelImpl.FINDER_CACHE_ENABLED, OrganizationImpl.class,
110                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByLocations",
111                            new String[] {
112                                    Long.class.getName(),
113                                    
114                            "java.lang.Integer", "java.lang.Integer",
115                                    "com.liferay.portal.kernel.util.OrderByComparator"
116                            });
117            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LOCATIONS =
118                    new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
119                            OrganizationModelImpl.FINDER_CACHE_ENABLED, OrganizationImpl.class,
120                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByLocations",
121                            new String[] { Long.class.getName() },
122                            OrganizationModelImpl.COMPANYID_COLUMN_BITMASK);
123            public static final FinderPath FINDER_PATH_COUNT_BY_LOCATIONS = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
124                            OrganizationModelImpl.FINDER_CACHE_ENABLED, Long.class,
125                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByLocations",
126                            new String[] { Long.class.getName() });
127            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_P = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
128                            OrganizationModelImpl.FINDER_CACHE_ENABLED, OrganizationImpl.class,
129                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_P",
130                            new String[] {
131                                    Long.class.getName(), Long.class.getName(),
132                                    
133                            "java.lang.Integer", "java.lang.Integer",
134                                    "com.liferay.portal.kernel.util.OrderByComparator"
135                            });
136            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
137                            OrganizationModelImpl.FINDER_CACHE_ENABLED, OrganizationImpl.class,
138                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_P",
139                            new String[] { Long.class.getName(), Long.class.getName() },
140                            OrganizationModelImpl.COMPANYID_COLUMN_BITMASK |
141                            OrganizationModelImpl.PARENTORGANIZATIONID_COLUMN_BITMASK);
142            public static final FinderPath FINDER_PATH_COUNT_BY_C_P = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
143                            OrganizationModelImpl.FINDER_CACHE_ENABLED, Long.class,
144                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_P",
145                            new String[] { Long.class.getName(), Long.class.getName() });
146            public static final FinderPath FINDER_PATH_FETCH_BY_C_N = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
147                            OrganizationModelImpl.FINDER_CACHE_ENABLED, OrganizationImpl.class,
148                            FINDER_CLASS_NAME_ENTITY, "fetchByC_N",
149                            new String[] { Long.class.getName(), String.class.getName() },
150                            OrganizationModelImpl.COMPANYID_COLUMN_BITMASK |
151                            OrganizationModelImpl.NAME_COLUMN_BITMASK);
152            public static final FinderPath FINDER_PATH_COUNT_BY_C_N = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
153                            OrganizationModelImpl.FINDER_CACHE_ENABLED, Long.class,
154                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_N",
155                            new String[] { Long.class.getName(), String.class.getName() });
156            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
157                            OrganizationModelImpl.FINDER_CACHE_ENABLED, OrganizationImpl.class,
158                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
159            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
160                            OrganizationModelImpl.FINDER_CACHE_ENABLED, OrganizationImpl.class,
161                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
162            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
163                            OrganizationModelImpl.FINDER_CACHE_ENABLED, Long.class,
164                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
165    
166            /**
167             * Caches the organization in the entity cache if it is enabled.
168             *
169             * @param organization the organization
170             */
171            public void cacheResult(Organization organization) {
172                    EntityCacheUtil.putResult(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
173                            OrganizationImpl.class, organization.getPrimaryKey(), organization);
174    
175                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
176                            new Object[] {
177                                    Long.valueOf(organization.getCompanyId()),
178                                    
179                            organization.getName()
180                            }, organization);
181    
182                    organization.resetOriginalValues();
183            }
184    
185            /**
186             * Caches the organizations in the entity cache if it is enabled.
187             *
188             * @param organizations the organizations
189             */
190            public void cacheResult(List<Organization> organizations) {
191                    for (Organization organization : organizations) {
192                            if (EntityCacheUtil.getResult(
193                                                    OrganizationModelImpl.ENTITY_CACHE_ENABLED,
194                                                    OrganizationImpl.class, organization.getPrimaryKey()) == null) {
195                                    cacheResult(organization);
196                            }
197                            else {
198                                    organization.resetOriginalValues();
199                            }
200                    }
201            }
202    
203            /**
204             * Clears the cache for all organizations.
205             *
206             * <p>
207             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
208             * </p>
209             */
210            @Override
211            public void clearCache() {
212                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
213                            CacheRegistryUtil.clear(OrganizationImpl.class.getName());
214                    }
215    
216                    EntityCacheUtil.clearCache(OrganizationImpl.class.getName());
217    
218                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
219                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
220                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
221            }
222    
223            /**
224             * Clears the cache for the organization.
225             *
226             * <p>
227             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
228             * </p>
229             */
230            @Override
231            public void clearCache(Organization organization) {
232                    EntityCacheUtil.removeResult(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
233                            OrganizationImpl.class, organization.getPrimaryKey());
234    
235                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
236                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
237    
238                    clearUniqueFindersCache(organization);
239            }
240    
241            @Override
242            public void clearCache(List<Organization> organizations) {
243                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
244                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
245    
246                    for (Organization organization : organizations) {
247                            EntityCacheUtil.removeResult(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
248                                    OrganizationImpl.class, organization.getPrimaryKey());
249    
250                            clearUniqueFindersCache(organization);
251                    }
252            }
253    
254            protected void cacheUniqueFindersCache(Organization organization) {
255                    if (organization.isNew()) {
256                            Object[] args = new Object[] {
257                                            Long.valueOf(organization.getCompanyId()),
258                                            
259                                            organization.getName()
260                                    };
261    
262                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_N, args,
263                                    Long.valueOf(1));
264                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N, args,
265                                    organization);
266                    }
267                    else {
268                            OrganizationModelImpl organizationModelImpl = (OrganizationModelImpl)organization;
269    
270                            if ((organizationModelImpl.getColumnBitmask() &
271                                            FINDER_PATH_FETCH_BY_C_N.getColumnBitmask()) != 0) {
272                                    Object[] args = new Object[] {
273                                                    Long.valueOf(organization.getCompanyId()),
274                                                    
275                                                    organization.getName()
276                                            };
277    
278                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_N, args,
279                                            Long.valueOf(1));
280                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N, args,
281                                            organization);
282                            }
283                    }
284            }
285    
286            protected void clearUniqueFindersCache(Organization organization) {
287                    OrganizationModelImpl organizationModelImpl = (OrganizationModelImpl)organization;
288    
289                    Object[] args = new Object[] {
290                                    Long.valueOf(organization.getCompanyId()),
291                                    
292                                    organization.getName()
293                            };
294    
295                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_N, args);
296                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N, args);
297    
298                    if ((organizationModelImpl.getColumnBitmask() &
299                                    FINDER_PATH_FETCH_BY_C_N.getColumnBitmask()) != 0) {
300                            args = new Object[] {
301                                            Long.valueOf(organizationModelImpl.getOriginalCompanyId()),
302                                            
303                                            organizationModelImpl.getOriginalName()
304                                    };
305    
306                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_N, args);
307                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N, args);
308                    }
309            }
310    
311            /**
312             * Creates a new organization with the primary key. Does not add the organization to the database.
313             *
314             * @param organizationId the primary key for the new organization
315             * @return the new organization
316             */
317            public Organization create(long organizationId) {
318                    Organization organization = new OrganizationImpl();
319    
320                    organization.setNew(true);
321                    organization.setPrimaryKey(organizationId);
322    
323                    return organization;
324            }
325    
326            /**
327             * Removes the organization with the primary key from the database. Also notifies the appropriate model listeners.
328             *
329             * @param organizationId the primary key of the organization
330             * @return the organization that was removed
331             * @throws com.liferay.portal.NoSuchOrganizationException if a organization with the primary key could not be found
332             * @throws SystemException if a system exception occurred
333             */
334            public Organization remove(long organizationId)
335                    throws NoSuchOrganizationException, SystemException {
336                    return remove(Long.valueOf(organizationId));
337            }
338    
339            /**
340             * Removes the organization with the primary key from the database. Also notifies the appropriate model listeners.
341             *
342             * @param primaryKey the primary key of the organization
343             * @return the organization that was removed
344             * @throws com.liferay.portal.NoSuchOrganizationException if a organization with the primary key could not be found
345             * @throws SystemException if a system exception occurred
346             */
347            @Override
348            public Organization remove(Serializable primaryKey)
349                    throws NoSuchOrganizationException, SystemException {
350                    Session session = null;
351    
352                    try {
353                            session = openSession();
354    
355                            Organization organization = (Organization)session.get(OrganizationImpl.class,
356                                            primaryKey);
357    
358                            if (organization == null) {
359                                    if (_log.isWarnEnabled()) {
360                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
361                                    }
362    
363                                    throw new NoSuchOrganizationException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
364                                            primaryKey);
365                            }
366    
367                            return remove(organization);
368                    }
369                    catch (NoSuchOrganizationException nsee) {
370                            throw nsee;
371                    }
372                    catch (Exception e) {
373                            throw processException(e);
374                    }
375                    finally {
376                            closeSession(session);
377                    }
378            }
379    
380            @Override
381            protected Organization removeImpl(Organization organization)
382                    throws SystemException {
383                    organization = toUnwrappedModel(organization);
384    
385                    try {
386                            clearGroups.clear(organization.getPrimaryKey());
387                    }
388                    catch (Exception e) {
389                            throw processException(e);
390                    }
391                    finally {
392                            FinderCacheUtil.clearCache(OrganizationModelImpl.MAPPING_TABLE_GROUPS_ORGS_NAME);
393                    }
394    
395                    try {
396                            clearUsers.clear(organization.getPrimaryKey());
397                    }
398                    catch (Exception e) {
399                            throw processException(e);
400                    }
401                    finally {
402                            FinderCacheUtil.clearCache(OrganizationModelImpl.MAPPING_TABLE_USERS_ORGS_NAME);
403                    }
404    
405                    Session session = null;
406    
407                    try {
408                            session = openSession();
409    
410                            BatchSessionUtil.delete(session, organization);
411                    }
412                    catch (Exception e) {
413                            throw processException(e);
414                    }
415                    finally {
416                            closeSession(session);
417                    }
418    
419                    clearCache(organization);
420    
421                    return organization;
422            }
423    
424            @Override
425            public Organization updateImpl(
426                    com.liferay.portal.model.Organization organization, boolean merge)
427                    throws SystemException {
428                    organization = toUnwrappedModel(organization);
429    
430                    boolean isNew = organization.isNew();
431    
432                    OrganizationModelImpl organizationModelImpl = (OrganizationModelImpl)organization;
433    
434                    Session session = null;
435    
436                    try {
437                            session = openSession();
438    
439                            BatchSessionUtil.update(session, organization, merge);
440    
441                            organization.setNew(false);
442                    }
443                    catch (Exception e) {
444                            throw processException(e);
445                    }
446                    finally {
447                            closeSession(session);
448                    }
449    
450                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
451    
452                    if (isNew || !OrganizationModelImpl.COLUMN_BITMASK_ENABLED) {
453                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
454                    }
455    
456                    else {
457                            if ((organizationModelImpl.getColumnBitmask() &
458                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
459                                    Object[] args = new Object[] {
460                                                    Long.valueOf(organizationModelImpl.getOriginalCompanyId())
461                                            };
462    
463                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
464                                            args);
465                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
466                                            args);
467    
468                                    args = new Object[] {
469                                                    Long.valueOf(organizationModelImpl.getCompanyId())
470                                            };
471    
472                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
473                                            args);
474                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
475                                            args);
476                            }
477    
478                            if ((organizationModelImpl.getColumnBitmask() &
479                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LOCATIONS.getColumnBitmask()) != 0) {
480                                    Object[] args = new Object[] {
481                                                    Long.valueOf(organizationModelImpl.getOriginalCompanyId())
482                                            };
483    
484                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_LOCATIONS,
485                                            args);
486                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LOCATIONS,
487                                            args);
488    
489                                    args = new Object[] {
490                                                    Long.valueOf(organizationModelImpl.getCompanyId())
491                                            };
492    
493                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_LOCATIONS,
494                                            args);
495                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LOCATIONS,
496                                            args);
497                            }
498    
499                            if ((organizationModelImpl.getColumnBitmask() &
500                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P.getColumnBitmask()) != 0) {
501                                    Object[] args = new Object[] {
502                                                    Long.valueOf(organizationModelImpl.getOriginalCompanyId()),
503                                                    Long.valueOf(organizationModelImpl.getOriginalParentOrganizationId())
504                                            };
505    
506                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_P, args);
507                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P,
508                                            args);
509    
510                                    args = new Object[] {
511                                                    Long.valueOf(organizationModelImpl.getCompanyId()),
512                                                    Long.valueOf(organizationModelImpl.getParentOrganizationId())
513                                            };
514    
515                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_P, args);
516                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P,
517                                            args);
518                            }
519                    }
520    
521                    EntityCacheUtil.putResult(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
522                            OrganizationImpl.class, organization.getPrimaryKey(), organization);
523    
524                    clearUniqueFindersCache(organization);
525                    cacheUniqueFindersCache(organization);
526    
527                    return organization;
528            }
529    
530            protected Organization toUnwrappedModel(Organization organization) {
531                    if (organization instanceof OrganizationImpl) {
532                            return organization;
533                    }
534    
535                    OrganizationImpl organizationImpl = new OrganizationImpl();
536    
537                    organizationImpl.setNew(organization.isNew());
538                    organizationImpl.setPrimaryKey(organization.getPrimaryKey());
539    
540                    organizationImpl.setOrganizationId(organization.getOrganizationId());
541                    organizationImpl.setCompanyId(organization.getCompanyId());
542                    organizationImpl.setParentOrganizationId(organization.getParentOrganizationId());
543                    organizationImpl.setTreePath(organization.getTreePath());
544                    organizationImpl.setName(organization.getName());
545                    organizationImpl.setType(organization.getType());
546                    organizationImpl.setRecursable(organization.isRecursable());
547                    organizationImpl.setRegionId(organization.getRegionId());
548                    organizationImpl.setCountryId(organization.getCountryId());
549                    organizationImpl.setStatusId(organization.getStatusId());
550                    organizationImpl.setComments(organization.getComments());
551    
552                    return organizationImpl;
553            }
554    
555            /**
556             * Returns the organization with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
557             *
558             * @param primaryKey the primary key of the organization
559             * @return the organization
560             * @throws com.liferay.portal.NoSuchModelException if a organization with the primary key could not be found
561             * @throws SystemException if a system exception occurred
562             */
563            @Override
564            public Organization findByPrimaryKey(Serializable primaryKey)
565                    throws NoSuchModelException, SystemException {
566                    return findByPrimaryKey(((Long)primaryKey).longValue());
567            }
568    
569            /**
570             * Returns the organization with the primary key or throws a {@link com.liferay.portal.NoSuchOrganizationException} if it could not be found.
571             *
572             * @param organizationId the primary key of the organization
573             * @return the organization
574             * @throws com.liferay.portal.NoSuchOrganizationException if a organization with the primary key could not be found
575             * @throws SystemException if a system exception occurred
576             */
577            public Organization findByPrimaryKey(long organizationId)
578                    throws NoSuchOrganizationException, SystemException {
579                    Organization organization = fetchByPrimaryKey(organizationId);
580    
581                    if (organization == null) {
582                            if (_log.isWarnEnabled()) {
583                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + organizationId);
584                            }
585    
586                            throw new NoSuchOrganizationException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
587                                    organizationId);
588                    }
589    
590                    return organization;
591            }
592    
593            /**
594             * Returns the organization with the primary key or returns <code>null</code> if it could not be found.
595             *
596             * @param primaryKey the primary key of the organization
597             * @return the organization, or <code>null</code> if a organization with the primary key could not be found
598             * @throws SystemException if a system exception occurred
599             */
600            @Override
601            public Organization fetchByPrimaryKey(Serializable primaryKey)
602                    throws SystemException {
603                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
604            }
605    
606            /**
607             * Returns the organization with the primary key or returns <code>null</code> if it could not be found.
608             *
609             * @param organizationId the primary key of the organization
610             * @return the organization, or <code>null</code> if a organization with the primary key could not be found
611             * @throws SystemException if a system exception occurred
612             */
613            public Organization fetchByPrimaryKey(long organizationId)
614                    throws SystemException {
615                    Organization organization = (Organization)EntityCacheUtil.getResult(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
616                                    OrganizationImpl.class, organizationId);
617    
618                    if (organization == _nullOrganization) {
619                            return null;
620                    }
621    
622                    if (organization == null) {
623                            Session session = null;
624    
625                            boolean hasException = false;
626    
627                            try {
628                                    session = openSession();
629    
630                                    organization = (Organization)session.get(OrganizationImpl.class,
631                                                    Long.valueOf(organizationId));
632                            }
633                            catch (Exception e) {
634                                    hasException = true;
635    
636                                    throw processException(e);
637                            }
638                            finally {
639                                    if (organization != null) {
640                                            cacheResult(organization);
641                                    }
642                                    else if (!hasException) {
643                                            EntityCacheUtil.putResult(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
644                                                    OrganizationImpl.class, organizationId,
645                                                    _nullOrganization);
646                                    }
647    
648                                    closeSession(session);
649                            }
650                    }
651    
652                    return organization;
653            }
654    
655            /**
656             * Returns all the organizations where companyId = &#63;.
657             *
658             * @param companyId the company ID
659             * @return the matching organizations
660             * @throws SystemException if a system exception occurred
661             */
662            public List<Organization> findByCompanyId(long companyId)
663                    throws SystemException {
664                    return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
665                            null);
666            }
667    
668            /**
669             * Returns a range of all the organizations where companyId = &#63;.
670             *
671             * <p>
672             * 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.
673             * </p>
674             *
675             * @param companyId the company ID
676             * @param start the lower bound of the range of organizations
677             * @param end the upper bound of the range of organizations (not inclusive)
678             * @return the range of matching organizations
679             * @throws SystemException if a system exception occurred
680             */
681            public List<Organization> findByCompanyId(long companyId, int start, int end)
682                    throws SystemException {
683                    return findByCompanyId(companyId, start, end, null);
684            }
685    
686            /**
687             * Returns an ordered range of all the organizations where companyId = &#63;.
688             *
689             * <p>
690             * 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.
691             * </p>
692             *
693             * @param companyId the company ID
694             * @param start the lower bound of the range of organizations
695             * @param end the upper bound of the range of organizations (not inclusive)
696             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
697             * @return the ordered range of matching organizations
698             * @throws SystemException if a system exception occurred
699             */
700            public List<Organization> findByCompanyId(long companyId, int start,
701                    int end, OrderByComparator orderByComparator) throws SystemException {
702                    FinderPath finderPath = null;
703                    Object[] finderArgs = null;
704    
705                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
706                                    (orderByComparator == null)) {
707                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
708                            finderArgs = new Object[] { companyId };
709                    }
710                    else {
711                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
712                            finderArgs = new Object[] { companyId, start, end, orderByComparator };
713                    }
714    
715                    List<Organization> list = (List<Organization>)FinderCacheUtil.getResult(finderPath,
716                                    finderArgs, this);
717    
718                    if ((list != null) && !list.isEmpty()) {
719                            for (Organization organization : list) {
720                                    if ((companyId != organization.getCompanyId())) {
721                                            list = null;
722    
723                                            break;
724                                    }
725                            }
726                    }
727    
728                    if (list == null) {
729                            StringBundler query = null;
730    
731                            if (orderByComparator != null) {
732                                    query = new StringBundler(3 +
733                                                    (orderByComparator.getOrderByFields().length * 3));
734                            }
735                            else {
736                                    query = new StringBundler(3);
737                            }
738    
739                            query.append(_SQL_SELECT_ORGANIZATION_WHERE);
740    
741                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
742    
743                            if (orderByComparator != null) {
744                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
745                                            orderByComparator);
746                            }
747    
748                            else {
749                                    query.append(OrganizationModelImpl.ORDER_BY_JPQL);
750                            }
751    
752                            String sql = query.toString();
753    
754                            Session session = null;
755    
756                            try {
757                                    session = openSession();
758    
759                                    Query q = session.createQuery(sql);
760    
761                                    QueryPos qPos = QueryPos.getInstance(q);
762    
763                                    qPos.add(companyId);
764    
765                                    list = (List<Organization>)QueryUtil.list(q, getDialect(),
766                                                    start, end);
767                            }
768                            catch (Exception e) {
769                                    throw processException(e);
770                            }
771                            finally {
772                                    if (list == null) {
773                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
774                                    }
775                                    else {
776                                            cacheResult(list);
777    
778                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
779                                    }
780    
781                                    closeSession(session);
782                            }
783                    }
784    
785                    return list;
786            }
787    
788            /**
789             * Returns the first organization in the ordered set where companyId = &#63;.
790             *
791             * @param companyId the company ID
792             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
793             * @return the first matching organization
794             * @throws com.liferay.portal.NoSuchOrganizationException if a matching organization could not be found
795             * @throws SystemException if a system exception occurred
796             */
797            public Organization findByCompanyId_First(long companyId,
798                    OrderByComparator orderByComparator)
799                    throws NoSuchOrganizationException, SystemException {
800                    Organization organization = fetchByCompanyId_First(companyId,
801                                    orderByComparator);
802    
803                    if (organization != null) {
804                            return organization;
805                    }
806    
807                    StringBundler msg = new StringBundler(4);
808    
809                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
810    
811                    msg.append("companyId=");
812                    msg.append(companyId);
813    
814                    msg.append(StringPool.CLOSE_CURLY_BRACE);
815    
816                    throw new NoSuchOrganizationException(msg.toString());
817            }
818    
819            /**
820             * Returns the first organization in the ordered set where companyId = &#63;.
821             *
822             * @param companyId the company ID
823             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
824             * @return the first matching organization, or <code>null</code> if a matching organization could not be found
825             * @throws SystemException if a system exception occurred
826             */
827            public Organization fetchByCompanyId_First(long companyId,
828                    OrderByComparator orderByComparator) throws SystemException {
829                    List<Organization> list = findByCompanyId(companyId, 0, 1,
830                                    orderByComparator);
831    
832                    if (!list.isEmpty()) {
833                            return list.get(0);
834                    }
835    
836                    return null;
837            }
838    
839            /**
840             * Returns the last organization in the ordered set where companyId = &#63;.
841             *
842             * @param companyId the company ID
843             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
844             * @return the last matching organization
845             * @throws com.liferay.portal.NoSuchOrganizationException if a matching organization could not be found
846             * @throws SystemException if a system exception occurred
847             */
848            public Organization findByCompanyId_Last(long companyId,
849                    OrderByComparator orderByComparator)
850                    throws NoSuchOrganizationException, SystemException {
851                    Organization organization = fetchByCompanyId_Last(companyId,
852                                    orderByComparator);
853    
854                    if (organization != null) {
855                            return organization;
856                    }
857    
858                    StringBundler msg = new StringBundler(4);
859    
860                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
861    
862                    msg.append("companyId=");
863                    msg.append(companyId);
864    
865                    msg.append(StringPool.CLOSE_CURLY_BRACE);
866    
867                    throw new NoSuchOrganizationException(msg.toString());
868            }
869    
870            /**
871             * Returns the last organization in the ordered set where companyId = &#63;.
872             *
873             * @param companyId the company ID
874             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
875             * @return the last matching organization, or <code>null</code> if a matching organization could not be found
876             * @throws SystemException if a system exception occurred
877             */
878            public Organization fetchByCompanyId_Last(long companyId,
879                    OrderByComparator orderByComparator) throws SystemException {
880                    int count = countByCompanyId(companyId);
881    
882                    List<Organization> list = findByCompanyId(companyId, count - 1, count,
883                                    orderByComparator);
884    
885                    if (!list.isEmpty()) {
886                            return list.get(0);
887                    }
888    
889                    return null;
890            }
891    
892            /**
893             * Returns the organizations before and after the current organization in the ordered set where companyId = &#63;.
894             *
895             * @param organizationId the primary key of the current organization
896             * @param companyId the company ID
897             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
898             * @return the previous, current, and next organization
899             * @throws com.liferay.portal.NoSuchOrganizationException if a organization with the primary key could not be found
900             * @throws SystemException if a system exception occurred
901             */
902            public Organization[] findByCompanyId_PrevAndNext(long organizationId,
903                    long companyId, OrderByComparator orderByComparator)
904                    throws NoSuchOrganizationException, SystemException {
905                    Organization organization = findByPrimaryKey(organizationId);
906    
907                    Session session = null;
908    
909                    try {
910                            session = openSession();
911    
912                            Organization[] array = new OrganizationImpl[3];
913    
914                            array[0] = getByCompanyId_PrevAndNext(session, organization,
915                                            companyId, orderByComparator, true);
916    
917                            array[1] = organization;
918    
919                            array[2] = getByCompanyId_PrevAndNext(session, organization,
920                                            companyId, orderByComparator, false);
921    
922                            return array;
923                    }
924                    catch (Exception e) {
925                            throw processException(e);
926                    }
927                    finally {
928                            closeSession(session);
929                    }
930            }
931    
932            protected Organization getByCompanyId_PrevAndNext(Session session,
933                    Organization organization, long companyId,
934                    OrderByComparator orderByComparator, boolean previous) {
935                    StringBundler query = null;
936    
937                    if (orderByComparator != null) {
938                            query = new StringBundler(6 +
939                                            (orderByComparator.getOrderByFields().length * 6));
940                    }
941                    else {
942                            query = new StringBundler(3);
943                    }
944    
945                    query.append(_SQL_SELECT_ORGANIZATION_WHERE);
946    
947                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
948    
949                    if (orderByComparator != null) {
950                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
951    
952                            if (orderByConditionFields.length > 0) {
953                                    query.append(WHERE_AND);
954                            }
955    
956                            for (int i = 0; i < orderByConditionFields.length; i++) {
957                                    query.append(_ORDER_BY_ENTITY_ALIAS);
958                                    query.append(orderByConditionFields[i]);
959    
960                                    if ((i + 1) < orderByConditionFields.length) {
961                                            if (orderByComparator.isAscending() ^ previous) {
962                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
963                                            }
964                                            else {
965                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
966                                            }
967                                    }
968                                    else {
969                                            if (orderByComparator.isAscending() ^ previous) {
970                                                    query.append(WHERE_GREATER_THAN);
971                                            }
972                                            else {
973                                                    query.append(WHERE_LESSER_THAN);
974                                            }
975                                    }
976                            }
977    
978                            query.append(ORDER_BY_CLAUSE);
979    
980                            String[] orderByFields = orderByComparator.getOrderByFields();
981    
982                            for (int i = 0; i < orderByFields.length; i++) {
983                                    query.append(_ORDER_BY_ENTITY_ALIAS);
984                                    query.append(orderByFields[i]);
985    
986                                    if ((i + 1) < orderByFields.length) {
987                                            if (orderByComparator.isAscending() ^ previous) {
988                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
989                                            }
990                                            else {
991                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
992                                            }
993                                    }
994                                    else {
995                                            if (orderByComparator.isAscending() ^ previous) {
996                                                    query.append(ORDER_BY_ASC);
997                                            }
998                                            else {
999                                                    query.append(ORDER_BY_DESC);
1000                                            }
1001                                    }
1002                            }
1003                    }
1004    
1005                    else {
1006                            query.append(OrganizationModelImpl.ORDER_BY_JPQL);
1007                    }
1008    
1009                    String sql = query.toString();
1010    
1011                    Query q = session.createQuery(sql);
1012    
1013                    q.setFirstResult(0);
1014                    q.setMaxResults(2);
1015    
1016                    QueryPos qPos = QueryPos.getInstance(q);
1017    
1018                    qPos.add(companyId);
1019    
1020                    if (orderByComparator != null) {
1021                            Object[] values = orderByComparator.getOrderByConditionValues(organization);
1022    
1023                            for (Object value : values) {
1024                                    qPos.add(value);
1025                            }
1026                    }
1027    
1028                    List<Organization> list = q.list();
1029    
1030                    if (list.size() == 2) {
1031                            return list.get(1);
1032                    }
1033                    else {
1034                            return null;
1035                    }
1036            }
1037    
1038            /**
1039             * Returns all the organizations that the user has permission to view where companyId = &#63;.
1040             *
1041             * @param companyId the company ID
1042             * @return the matching organizations that the user has permission to view
1043             * @throws SystemException if a system exception occurred
1044             */
1045            public List<Organization> filterFindByCompanyId(long companyId)
1046                    throws SystemException {
1047                    return filterFindByCompanyId(companyId, QueryUtil.ALL_POS,
1048                            QueryUtil.ALL_POS, null);
1049            }
1050    
1051            /**
1052             * Returns a range of all the organizations that the user has permission to view where companyId = &#63;.
1053             *
1054             * <p>
1055             * 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.
1056             * </p>
1057             *
1058             * @param companyId the company ID
1059             * @param start the lower bound of the range of organizations
1060             * @param end the upper bound of the range of organizations (not inclusive)
1061             * @return the range of matching organizations that the user has permission to view
1062             * @throws SystemException if a system exception occurred
1063             */
1064            public List<Organization> filterFindByCompanyId(long companyId, int start,
1065                    int end) throws SystemException {
1066                    return filterFindByCompanyId(companyId, start, end, null);
1067            }
1068    
1069            /**
1070             * Returns an ordered range of all the organizations that the user has permissions to view where companyId = &#63;.
1071             *
1072             * <p>
1073             * 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.
1074             * </p>
1075             *
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 that the user has permission to view
1081             * @throws SystemException if a system exception occurred
1082             */
1083            public List<Organization> filterFindByCompanyId(long companyId, int start,
1084                    int end, OrderByComparator orderByComparator) throws SystemException {
1085                    if (!InlineSQLHelperUtil.isEnabled()) {
1086                            return findByCompanyId(companyId, start, end, orderByComparator);
1087                    }
1088    
1089                    StringBundler query = null;
1090    
1091                    if (orderByComparator != null) {
1092                            query = new StringBundler(3 +
1093                                            (orderByComparator.getOrderByFields().length * 3));
1094                    }
1095                    else {
1096                            query = new StringBundler(3);
1097                    }
1098    
1099                    if (getDB().isSupportsInlineDistinct()) {
1100                            query.append(_FILTER_SQL_SELECT_ORGANIZATION_WHERE);
1101                    }
1102                    else {
1103                            query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_1);
1104                    }
1105    
1106                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1107    
1108                    if (!getDB().isSupportsInlineDistinct()) {
1109                            query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_2);
1110                    }
1111    
1112                    if (orderByComparator != null) {
1113                            if (getDB().isSupportsInlineDistinct()) {
1114                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1115                                            orderByComparator);
1116                            }
1117                            else {
1118                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
1119                                            orderByComparator);
1120                            }
1121                    }
1122    
1123                    else {
1124                            if (getDB().isSupportsInlineDistinct()) {
1125                                    query.append(OrganizationModelImpl.ORDER_BY_JPQL);
1126                            }
1127                            else {
1128                                    query.append(OrganizationModelImpl.ORDER_BY_SQL);
1129                            }
1130                    }
1131    
1132                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1133                                    Organization.class.getName(),
1134                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
1135    
1136                    Session session = null;
1137    
1138                    try {
1139                            session = openSession();
1140    
1141                            SQLQuery q = session.createSQLQuery(sql);
1142    
1143                            if (getDB().isSupportsInlineDistinct()) {
1144                                    q.addEntity(_FILTER_ENTITY_ALIAS, OrganizationImpl.class);
1145                            }
1146                            else {
1147                                    q.addEntity(_FILTER_ENTITY_TABLE, OrganizationImpl.class);
1148                            }
1149    
1150                            QueryPos qPos = QueryPos.getInstance(q);
1151    
1152                            qPos.add(companyId);
1153    
1154                            return (List<Organization>)QueryUtil.list(q, getDialect(), start,
1155                                    end);
1156                    }
1157                    catch (Exception e) {
1158                            throw processException(e);
1159                    }
1160                    finally {
1161                            closeSession(session);
1162                    }
1163            }
1164    
1165            /**
1166             * 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;.
1167             *
1168             * @param organizationId the primary key of the current organization
1169             * @param companyId the company ID
1170             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1171             * @return the previous, current, and next organization
1172             * @throws com.liferay.portal.NoSuchOrganizationException if a organization with the primary key could not be found
1173             * @throws SystemException if a system exception occurred
1174             */
1175            public Organization[] filterFindByCompanyId_PrevAndNext(
1176                    long organizationId, long companyId, OrderByComparator orderByComparator)
1177                    throws NoSuchOrganizationException, SystemException {
1178                    if (!InlineSQLHelperUtil.isEnabled()) {
1179                            return findByCompanyId_PrevAndNext(organizationId, companyId,
1180                                    orderByComparator);
1181                    }
1182    
1183                    Organization organization = findByPrimaryKey(organizationId);
1184    
1185                    Session session = null;
1186    
1187                    try {
1188                            session = openSession();
1189    
1190                            Organization[] array = new OrganizationImpl[3];
1191    
1192                            array[0] = filterGetByCompanyId_PrevAndNext(session, organization,
1193                                            companyId, orderByComparator, true);
1194    
1195                            array[1] = organization;
1196    
1197                            array[2] = filterGetByCompanyId_PrevAndNext(session, organization,
1198                                            companyId, orderByComparator, false);
1199    
1200                            return array;
1201                    }
1202                    catch (Exception e) {
1203                            throw processException(e);
1204                    }
1205                    finally {
1206                            closeSession(session);
1207                    }
1208            }
1209    
1210            protected Organization filterGetByCompanyId_PrevAndNext(Session session,
1211                    Organization organization, long companyId,
1212                    OrderByComparator orderByComparator, boolean previous) {
1213                    StringBundler query = null;
1214    
1215                    if (orderByComparator != null) {
1216                            query = new StringBundler(6 +
1217                                            (orderByComparator.getOrderByFields().length * 6));
1218                    }
1219                    else {
1220                            query = new StringBundler(3);
1221                    }
1222    
1223                    if (getDB().isSupportsInlineDistinct()) {
1224                            query.append(_FILTER_SQL_SELECT_ORGANIZATION_WHERE);
1225                    }
1226                    else {
1227                            query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_1);
1228                    }
1229    
1230                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1231    
1232                    if (!getDB().isSupportsInlineDistinct()) {
1233                            query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_2);
1234                    }
1235    
1236                    if (orderByComparator != null) {
1237                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1238    
1239                            if (orderByConditionFields.length > 0) {
1240                                    query.append(WHERE_AND);
1241                            }
1242    
1243                            for (int i = 0; i < orderByConditionFields.length; i++) {
1244                                    if (getDB().isSupportsInlineDistinct()) {
1245                                            query.append(_ORDER_BY_ENTITY_ALIAS);
1246                                    }
1247                                    else {
1248                                            query.append(_ORDER_BY_ENTITY_TABLE);
1249                                    }
1250    
1251                                    query.append(orderByConditionFields[i]);
1252    
1253                                    if ((i + 1) < orderByConditionFields.length) {
1254                                            if (orderByComparator.isAscending() ^ previous) {
1255                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1256                                            }
1257                                            else {
1258                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1259                                            }
1260                                    }
1261                                    else {
1262                                            if (orderByComparator.isAscending() ^ previous) {
1263                                                    query.append(WHERE_GREATER_THAN);
1264                                            }
1265                                            else {
1266                                                    query.append(WHERE_LESSER_THAN);
1267                                            }
1268                                    }
1269                            }
1270    
1271                            query.append(ORDER_BY_CLAUSE);
1272    
1273                            String[] orderByFields = orderByComparator.getOrderByFields();
1274    
1275                            for (int i = 0; i < orderByFields.length; i++) {
1276                                    if (getDB().isSupportsInlineDistinct()) {
1277                                            query.append(_ORDER_BY_ENTITY_ALIAS);
1278                                    }
1279                                    else {
1280                                            query.append(_ORDER_BY_ENTITY_TABLE);
1281                                    }
1282    
1283                                    query.append(orderByFields[i]);
1284    
1285                                    if ((i + 1) < orderByFields.length) {
1286                                            if (orderByComparator.isAscending() ^ previous) {
1287                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1288                                            }
1289                                            else {
1290                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1291                                            }
1292                                    }
1293                                    else {
1294                                            if (orderByComparator.isAscending() ^ previous) {
1295                                                    query.append(ORDER_BY_ASC);
1296                                            }
1297                                            else {
1298                                                    query.append(ORDER_BY_DESC);
1299                                            }
1300                                    }
1301                            }
1302                    }
1303    
1304                    else {
1305                            if (getDB().isSupportsInlineDistinct()) {
1306                                    query.append(OrganizationModelImpl.ORDER_BY_JPQL);
1307                            }
1308                            else {
1309                                    query.append(OrganizationModelImpl.ORDER_BY_SQL);
1310                            }
1311                    }
1312    
1313                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1314                                    Organization.class.getName(),
1315                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
1316    
1317                    SQLQuery q = session.createSQLQuery(sql);
1318    
1319                    q.setFirstResult(0);
1320                    q.setMaxResults(2);
1321    
1322                    if (getDB().isSupportsInlineDistinct()) {
1323                            q.addEntity(_FILTER_ENTITY_ALIAS, OrganizationImpl.class);
1324                    }
1325                    else {
1326                            q.addEntity(_FILTER_ENTITY_TABLE, OrganizationImpl.class);
1327                    }
1328    
1329                    QueryPos qPos = QueryPos.getInstance(q);
1330    
1331                    qPos.add(companyId);
1332    
1333                    if (orderByComparator != null) {
1334                            Object[] values = orderByComparator.getOrderByConditionValues(organization);
1335    
1336                            for (Object value : values) {
1337                                    qPos.add(value);
1338                            }
1339                    }
1340    
1341                    List<Organization> list = q.list();
1342    
1343                    if (list.size() == 2) {
1344                            return list.get(1);
1345                    }
1346                    else {
1347                            return null;
1348                    }
1349            }
1350    
1351            /**
1352             * Returns all the organizations where companyId = &#63;.
1353             *
1354             * @param companyId the company ID
1355             * @return the matching organizations
1356             * @throws SystemException if a system exception occurred
1357             */
1358            public List<Organization> findByLocations(long companyId)
1359                    throws SystemException {
1360                    return findByLocations(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1361                            null);
1362            }
1363    
1364            /**
1365             * Returns a range of all the organizations where companyId = &#63;.
1366             *
1367             * <p>
1368             * 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.
1369             * </p>
1370             *
1371             * @param companyId the company ID
1372             * @param start the lower bound of the range of organizations
1373             * @param end the upper bound of the range of organizations (not inclusive)
1374             * @return the range of matching organizations
1375             * @throws SystemException if a system exception occurred
1376             */
1377            public List<Organization> findByLocations(long companyId, int start, int end)
1378                    throws SystemException {
1379                    return findByLocations(companyId, start, end, null);
1380            }
1381    
1382            /**
1383             * Returns an ordered range of all the organizations where companyId = &#63;.
1384             *
1385             * <p>
1386             * 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.
1387             * </p>
1388             *
1389             * @param companyId the company ID
1390             * @param start the lower bound of the range of organizations
1391             * @param end the upper bound of the range of organizations (not inclusive)
1392             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1393             * @return the ordered range of matching organizations
1394             * @throws SystemException if a system exception occurred
1395             */
1396            public List<Organization> findByLocations(long companyId, int start,
1397                    int end, OrderByComparator orderByComparator) throws SystemException {
1398                    FinderPath finderPath = null;
1399                    Object[] finderArgs = null;
1400    
1401                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1402                                    (orderByComparator == null)) {
1403                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LOCATIONS;
1404                            finderArgs = new Object[] { companyId };
1405                    }
1406                    else {
1407                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_LOCATIONS;
1408                            finderArgs = new Object[] { companyId, start, end, orderByComparator };
1409                    }
1410    
1411                    List<Organization> list = (List<Organization>)FinderCacheUtil.getResult(finderPath,
1412                                    finderArgs, this);
1413    
1414                    if ((list != null) && !list.isEmpty()) {
1415                            for (Organization organization : list) {
1416                                    if ((companyId != organization.getCompanyId())) {
1417                                            list = null;
1418    
1419                                            break;
1420                                    }
1421                            }
1422                    }
1423    
1424                    if (list == null) {
1425                            StringBundler query = null;
1426    
1427                            if (orderByComparator != null) {
1428                                    query = new StringBundler(3 +
1429                                                    (orderByComparator.getOrderByFields().length * 3));
1430                            }
1431                            else {
1432                                    query = new StringBundler(3);
1433                            }
1434    
1435                            query.append(_SQL_SELECT_ORGANIZATION_WHERE);
1436    
1437                            query.append(_FINDER_COLUMN_LOCATIONS_COMPANYID_2);
1438    
1439                            if (orderByComparator != null) {
1440                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1441                                            orderByComparator);
1442                            }
1443    
1444                            else {
1445                                    query.append(OrganizationModelImpl.ORDER_BY_JPQL);
1446                            }
1447    
1448                            String sql = query.toString();
1449    
1450                            Session session = null;
1451    
1452                            try {
1453                                    session = openSession();
1454    
1455                                    Query q = session.createQuery(sql);
1456    
1457                                    QueryPos qPos = QueryPos.getInstance(q);
1458    
1459                                    qPos.add(companyId);
1460    
1461                                    list = (List<Organization>)QueryUtil.list(q, getDialect(),
1462                                                    start, end);
1463                            }
1464                            catch (Exception e) {
1465                                    throw processException(e);
1466                            }
1467                            finally {
1468                                    if (list == null) {
1469                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1470                                    }
1471                                    else {
1472                                            cacheResult(list);
1473    
1474                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1475                                    }
1476    
1477                                    closeSession(session);
1478                            }
1479                    }
1480    
1481                    return list;
1482            }
1483    
1484            /**
1485             * Returns the first organization in the ordered set where companyId = &#63;.
1486             *
1487             * @param companyId the company ID
1488             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1489             * @return the first matching organization
1490             * @throws com.liferay.portal.NoSuchOrganizationException if a matching organization could not be found
1491             * @throws SystemException if a system exception occurred
1492             */
1493            public Organization findByLocations_First(long companyId,
1494                    OrderByComparator orderByComparator)
1495                    throws NoSuchOrganizationException, SystemException {
1496                    Organization organization = fetchByLocations_First(companyId,
1497                                    orderByComparator);
1498    
1499                    if (organization != null) {
1500                            return organization;
1501                    }
1502    
1503                    StringBundler msg = new StringBundler(4);
1504    
1505                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1506    
1507                    msg.append("companyId=");
1508                    msg.append(companyId);
1509    
1510                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1511    
1512                    throw new NoSuchOrganizationException(msg.toString());
1513            }
1514    
1515            /**
1516             * Returns the first organization in the ordered set where companyId = &#63;.
1517             *
1518             * @param companyId the company ID
1519             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1520             * @return the first matching organization, or <code>null</code> if a matching organization could not be found
1521             * @throws SystemException if a system exception occurred
1522             */
1523            public Organization fetchByLocations_First(long companyId,
1524                    OrderByComparator orderByComparator) throws SystemException {
1525                    List<Organization> list = findByLocations(companyId, 0, 1,
1526                                    orderByComparator);
1527    
1528                    if (!list.isEmpty()) {
1529                            return list.get(0);
1530                    }
1531    
1532                    return null;
1533            }
1534    
1535            /**
1536             * Returns the last organization in the ordered set where companyId = &#63;.
1537             *
1538             * @param companyId the company ID
1539             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1540             * @return the last matching organization
1541             * @throws com.liferay.portal.NoSuchOrganizationException if a matching organization could not be found
1542             * @throws SystemException if a system exception occurred
1543             */
1544            public Organization findByLocations_Last(long companyId,
1545                    OrderByComparator orderByComparator)
1546                    throws NoSuchOrganizationException, SystemException {
1547                    Organization organization = fetchByLocations_Last(companyId,
1548                                    orderByComparator);
1549    
1550                    if (organization != null) {
1551                            return organization;
1552                    }
1553    
1554                    StringBundler msg = new StringBundler(4);
1555    
1556                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1557    
1558                    msg.append("companyId=");
1559                    msg.append(companyId);
1560    
1561                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1562    
1563                    throw new NoSuchOrganizationException(msg.toString());
1564            }
1565    
1566            /**
1567             * Returns the last organization in the ordered set where companyId = &#63;.
1568             *
1569             * @param companyId the company ID
1570             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1571             * @return the last matching organization, or <code>null</code> if a matching organization could not be found
1572             * @throws SystemException if a system exception occurred
1573             */
1574            public Organization fetchByLocations_Last(long companyId,
1575                    OrderByComparator orderByComparator) throws SystemException {
1576                    int count = countByLocations(companyId);
1577    
1578                    List<Organization> list = findByLocations(companyId, count - 1, count,
1579                                    orderByComparator);
1580    
1581                    if (!list.isEmpty()) {
1582                            return list.get(0);
1583                    }
1584    
1585                    return null;
1586            }
1587    
1588            /**
1589             * Returns the organizations before and after the current organization in the ordered set where companyId = &#63;.
1590             *
1591             * @param organizationId the primary key of the current organization
1592             * @param companyId the company ID
1593             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1594             * @return the previous, current, and next organization
1595             * @throws com.liferay.portal.NoSuchOrganizationException if a organization with the primary key could not be found
1596             * @throws SystemException if a system exception occurred
1597             */
1598            public Organization[] findByLocations_PrevAndNext(long organizationId,
1599                    long companyId, OrderByComparator orderByComparator)
1600                    throws NoSuchOrganizationException, SystemException {
1601                    Organization organization = findByPrimaryKey(organizationId);
1602    
1603                    Session session = null;
1604    
1605                    try {
1606                            session = openSession();
1607    
1608                            Organization[] array = new OrganizationImpl[3];
1609    
1610                            array[0] = getByLocations_PrevAndNext(session, organization,
1611                                            companyId, orderByComparator, true);
1612    
1613                            array[1] = organization;
1614    
1615                            array[2] = getByLocations_PrevAndNext(session, organization,
1616                                            companyId, orderByComparator, false);
1617    
1618                            return array;
1619                    }
1620                    catch (Exception e) {
1621                            throw processException(e);
1622                    }
1623                    finally {
1624                            closeSession(session);
1625                    }
1626            }
1627    
1628            protected Organization getByLocations_PrevAndNext(Session session,
1629                    Organization organization, long companyId,
1630                    OrderByComparator orderByComparator, boolean previous) {
1631                    StringBundler query = null;
1632    
1633                    if (orderByComparator != null) {
1634                            query = new StringBundler(6 +
1635                                            (orderByComparator.getOrderByFields().length * 6));
1636                    }
1637                    else {
1638                            query = new StringBundler(3);
1639                    }
1640    
1641                    query.append(_SQL_SELECT_ORGANIZATION_WHERE);
1642    
1643                    query.append(_FINDER_COLUMN_LOCATIONS_COMPANYID_2);
1644    
1645                    if (orderByComparator != null) {
1646                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1647    
1648                            if (orderByConditionFields.length > 0) {
1649                                    query.append(WHERE_AND);
1650                            }
1651    
1652                            for (int i = 0; i < orderByConditionFields.length; i++) {
1653                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1654                                    query.append(orderByConditionFields[i]);
1655    
1656                                    if ((i + 1) < orderByConditionFields.length) {
1657                                            if (orderByComparator.isAscending() ^ previous) {
1658                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1659                                            }
1660                                            else {
1661                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1662                                            }
1663                                    }
1664                                    else {
1665                                            if (orderByComparator.isAscending() ^ previous) {
1666                                                    query.append(WHERE_GREATER_THAN);
1667                                            }
1668                                            else {
1669                                                    query.append(WHERE_LESSER_THAN);
1670                                            }
1671                                    }
1672                            }
1673    
1674                            query.append(ORDER_BY_CLAUSE);
1675    
1676                            String[] orderByFields = orderByComparator.getOrderByFields();
1677    
1678                            for (int i = 0; i < orderByFields.length; i++) {
1679                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1680                                    query.append(orderByFields[i]);
1681    
1682                                    if ((i + 1) < orderByFields.length) {
1683                                            if (orderByComparator.isAscending() ^ previous) {
1684                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1685                                            }
1686                                            else {
1687                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1688                                            }
1689                                    }
1690                                    else {
1691                                            if (orderByComparator.isAscending() ^ previous) {
1692                                                    query.append(ORDER_BY_ASC);
1693                                            }
1694                                            else {
1695                                                    query.append(ORDER_BY_DESC);
1696                                            }
1697                                    }
1698                            }
1699                    }
1700    
1701                    else {
1702                            query.append(OrganizationModelImpl.ORDER_BY_JPQL);
1703                    }
1704    
1705                    String sql = query.toString();
1706    
1707                    Query q = session.createQuery(sql);
1708    
1709                    q.setFirstResult(0);
1710                    q.setMaxResults(2);
1711    
1712                    QueryPos qPos = QueryPos.getInstance(q);
1713    
1714                    qPos.add(companyId);
1715    
1716                    if (orderByComparator != null) {
1717                            Object[] values = orderByComparator.getOrderByConditionValues(organization);
1718    
1719                            for (Object value : values) {
1720                                    qPos.add(value);
1721                            }
1722                    }
1723    
1724                    List<Organization> list = q.list();
1725    
1726                    if (list.size() == 2) {
1727                            return list.get(1);
1728                    }
1729                    else {
1730                            return null;
1731                    }
1732            }
1733    
1734            /**
1735             * Returns all the organizations that the user has permission to view where companyId = &#63;.
1736             *
1737             * @param companyId the company ID
1738             * @return the matching organizations that the user has permission to view
1739             * @throws SystemException if a system exception occurred
1740             */
1741            public List<Organization> filterFindByLocations(long companyId)
1742                    throws SystemException {
1743                    return filterFindByLocations(companyId, QueryUtil.ALL_POS,
1744                            QueryUtil.ALL_POS, null);
1745            }
1746    
1747            /**
1748             * Returns a range of all the organizations that the user has permission to view where companyId = &#63;.
1749             *
1750             * <p>
1751             * 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.
1752             * </p>
1753             *
1754             * @param companyId the company ID
1755             * @param start the lower bound of the range of organizations
1756             * @param end the upper bound of the range of organizations (not inclusive)
1757             * @return the range of matching organizations that the user has permission to view
1758             * @throws SystemException if a system exception occurred
1759             */
1760            public List<Organization> filterFindByLocations(long companyId, int start,
1761                    int end) throws SystemException {
1762                    return filterFindByLocations(companyId, start, end, null);
1763            }
1764    
1765            /**
1766             * Returns an ordered range of all the organizations that the user has permissions to view where companyId = &#63;.
1767             *
1768             * <p>
1769             * 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.
1770             * </p>
1771             *
1772             * @param companyId the company ID
1773             * @param start the lower bound of the range of organizations
1774             * @param end the upper bound of the range of organizations (not inclusive)
1775             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1776             * @return the ordered range of matching organizations that the user has permission to view
1777             * @throws SystemException if a system exception occurred
1778             */
1779            public List<Organization> filterFindByLocations(long companyId, int start,
1780                    int end, OrderByComparator orderByComparator) throws SystemException {
1781                    if (!InlineSQLHelperUtil.isEnabled()) {
1782                            return findByLocations(companyId, start, end, orderByComparator);
1783                    }
1784    
1785                    StringBundler query = null;
1786    
1787                    if (orderByComparator != null) {
1788                            query = new StringBundler(3 +
1789                                            (orderByComparator.getOrderByFields().length * 3));
1790                    }
1791                    else {
1792                            query = new StringBundler(3);
1793                    }
1794    
1795                    if (getDB().isSupportsInlineDistinct()) {
1796                            query.append(_FILTER_SQL_SELECT_ORGANIZATION_WHERE);
1797                    }
1798                    else {
1799                            query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_1);
1800                    }
1801    
1802                    query.append(_FINDER_COLUMN_LOCATIONS_COMPANYID_2);
1803    
1804                    if (!getDB().isSupportsInlineDistinct()) {
1805                            query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_2);
1806                    }
1807    
1808                    if (orderByComparator != null) {
1809                            if (getDB().isSupportsInlineDistinct()) {
1810                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1811                                            orderByComparator);
1812                            }
1813                            else {
1814                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
1815                                            orderByComparator);
1816                            }
1817                    }
1818    
1819                    else {
1820                            if (getDB().isSupportsInlineDistinct()) {
1821                                    query.append(OrganizationModelImpl.ORDER_BY_JPQL);
1822                            }
1823                            else {
1824                                    query.append(OrganizationModelImpl.ORDER_BY_SQL);
1825                            }
1826                    }
1827    
1828                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1829                                    Organization.class.getName(),
1830                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
1831    
1832                    Session session = null;
1833    
1834                    try {
1835                            session = openSession();
1836    
1837                            SQLQuery q = session.createSQLQuery(sql);
1838    
1839                            if (getDB().isSupportsInlineDistinct()) {
1840                                    q.addEntity(_FILTER_ENTITY_ALIAS, OrganizationImpl.class);
1841                            }
1842                            else {
1843                                    q.addEntity(_FILTER_ENTITY_TABLE, OrganizationImpl.class);
1844                            }
1845    
1846                            QueryPos qPos = QueryPos.getInstance(q);
1847    
1848                            qPos.add(companyId);
1849    
1850                            return (List<Organization>)QueryUtil.list(q, getDialect(), start,
1851                                    end);
1852                    }
1853                    catch (Exception e) {
1854                            throw processException(e);
1855                    }
1856                    finally {
1857                            closeSession(session);
1858                    }
1859            }
1860    
1861            /**
1862             * 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;.
1863             *
1864             * @param organizationId the primary key of the current organization
1865             * @param companyId the company ID
1866             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1867             * @return the previous, current, and next organization
1868             * @throws com.liferay.portal.NoSuchOrganizationException if a organization with the primary key could not be found
1869             * @throws SystemException if a system exception occurred
1870             */
1871            public Organization[] filterFindByLocations_PrevAndNext(
1872                    long organizationId, long companyId, OrderByComparator orderByComparator)
1873                    throws NoSuchOrganizationException, SystemException {
1874                    if (!InlineSQLHelperUtil.isEnabled()) {
1875                            return findByLocations_PrevAndNext(organizationId, companyId,
1876                                    orderByComparator);
1877                    }
1878    
1879                    Organization organization = findByPrimaryKey(organizationId);
1880    
1881                    Session session = null;
1882    
1883                    try {
1884                            session = openSession();
1885    
1886                            Organization[] array = new OrganizationImpl[3];
1887    
1888                            array[0] = filterGetByLocations_PrevAndNext(session, organization,
1889                                            companyId, orderByComparator, true);
1890    
1891                            array[1] = organization;
1892    
1893                            array[2] = filterGetByLocations_PrevAndNext(session, organization,
1894                                            companyId, orderByComparator, false);
1895    
1896                            return array;
1897                    }
1898                    catch (Exception e) {
1899                            throw processException(e);
1900                    }
1901                    finally {
1902                            closeSession(session);
1903                    }
1904            }
1905    
1906            protected Organization filterGetByLocations_PrevAndNext(Session session,
1907                    Organization organization, long companyId,
1908                    OrderByComparator orderByComparator, boolean previous) {
1909                    StringBundler query = null;
1910    
1911                    if (orderByComparator != null) {
1912                            query = new StringBundler(6 +
1913                                            (orderByComparator.getOrderByFields().length * 6));
1914                    }
1915                    else {
1916                            query = new StringBundler(3);
1917                    }
1918    
1919                    if (getDB().isSupportsInlineDistinct()) {
1920                            query.append(_FILTER_SQL_SELECT_ORGANIZATION_WHERE);
1921                    }
1922                    else {
1923                            query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_1);
1924                    }
1925    
1926                    query.append(_FINDER_COLUMN_LOCATIONS_COMPANYID_2);
1927    
1928                    if (!getDB().isSupportsInlineDistinct()) {
1929                            query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_2);
1930                    }
1931    
1932                    if (orderByComparator != null) {
1933                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1934    
1935                            if (orderByConditionFields.length > 0) {
1936                                    query.append(WHERE_AND);
1937                            }
1938    
1939                            for (int i = 0; i < orderByConditionFields.length; i++) {
1940                                    if (getDB().isSupportsInlineDistinct()) {
1941                                            query.append(_ORDER_BY_ENTITY_ALIAS);
1942                                    }
1943                                    else {
1944                                            query.append(_ORDER_BY_ENTITY_TABLE);
1945                                    }
1946    
1947                                    query.append(orderByConditionFields[i]);
1948    
1949                                    if ((i + 1) < orderByConditionFields.length) {
1950                                            if (orderByComparator.isAscending() ^ previous) {
1951                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1952                                            }
1953                                            else {
1954                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1955                                            }
1956                                    }
1957                                    else {
1958                                            if (orderByComparator.isAscending() ^ previous) {
1959                                                    query.append(WHERE_GREATER_THAN);
1960                                            }
1961                                            else {
1962                                                    query.append(WHERE_LESSER_THAN);
1963                                            }
1964                                    }
1965                            }
1966    
1967                            query.append(ORDER_BY_CLAUSE);
1968    
1969                            String[] orderByFields = orderByComparator.getOrderByFields();
1970    
1971                            for (int i = 0; i < orderByFields.length; i++) {
1972                                    if (getDB().isSupportsInlineDistinct()) {
1973                                            query.append(_ORDER_BY_ENTITY_ALIAS);
1974                                    }
1975                                    else {
1976                                            query.append(_ORDER_BY_ENTITY_TABLE);
1977                                    }
1978    
1979                                    query.append(orderByFields[i]);
1980    
1981                                    if ((i + 1) < orderByFields.length) {
1982                                            if (orderByComparator.isAscending() ^ previous) {
1983                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1984                                            }
1985                                            else {
1986                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1987                                            }
1988                                    }
1989                                    else {
1990                                            if (orderByComparator.isAscending() ^ previous) {
1991                                                    query.append(ORDER_BY_ASC);
1992                                            }
1993                                            else {
1994                                                    query.append(ORDER_BY_DESC);
1995                                            }
1996                                    }
1997                            }
1998                    }
1999    
2000                    else {
2001                            if (getDB().isSupportsInlineDistinct()) {
2002                                    query.append(OrganizationModelImpl.ORDER_BY_JPQL);
2003                            }
2004                            else {
2005                                    query.append(OrganizationModelImpl.ORDER_BY_SQL);
2006                            }
2007                    }
2008    
2009                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2010                                    Organization.class.getName(),
2011                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
2012    
2013                    SQLQuery q = session.createSQLQuery(sql);
2014    
2015                    q.setFirstResult(0);
2016                    q.setMaxResults(2);
2017    
2018                    if (getDB().isSupportsInlineDistinct()) {
2019                            q.addEntity(_FILTER_ENTITY_ALIAS, OrganizationImpl.class);
2020                    }
2021                    else {
2022                            q.addEntity(_FILTER_ENTITY_TABLE, OrganizationImpl.class);
2023                    }
2024    
2025                    QueryPos qPos = QueryPos.getInstance(q);
2026    
2027                    qPos.add(companyId);
2028    
2029                    if (orderByComparator != null) {
2030                            Object[] values = orderByComparator.getOrderByConditionValues(organization);
2031    
2032                            for (Object value : values) {
2033                                    qPos.add(value);
2034                            }
2035                    }
2036    
2037                    List<Organization> list = q.list();
2038    
2039                    if (list.size() == 2) {
2040                            return list.get(1);
2041                    }
2042                    else {
2043                            return null;
2044                    }
2045            }
2046    
2047            /**
2048             * Returns all the organizations where companyId = &#63; and parentOrganizationId = &#63;.
2049             *
2050             * @param companyId the company ID
2051             * @param parentOrganizationId the parent organization ID
2052             * @return the matching organizations
2053             * @throws SystemException if a system exception occurred
2054             */
2055            public List<Organization> findByC_P(long companyId,
2056                    long parentOrganizationId) throws SystemException {
2057                    return findByC_P(companyId, parentOrganizationId, QueryUtil.ALL_POS,
2058                            QueryUtil.ALL_POS, null);
2059            }
2060    
2061            /**
2062             * Returns a range of all the organizations where companyId = &#63; and parentOrganizationId = &#63;.
2063             *
2064             * <p>
2065             * 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.
2066             * </p>
2067             *
2068             * @param companyId the company ID
2069             * @param parentOrganizationId the parent organization ID
2070             * @param start the lower bound of the range of organizations
2071             * @param end the upper bound of the range of organizations (not inclusive)
2072             * @return the range of matching organizations
2073             * @throws SystemException if a system exception occurred
2074             */
2075            public List<Organization> findByC_P(long companyId,
2076                    long parentOrganizationId, int start, int end)
2077                    throws SystemException {
2078                    return findByC_P(companyId, parentOrganizationId, start, end, null);
2079            }
2080    
2081            /**
2082             * Returns an ordered range of all the organizations where companyId = &#63; and parentOrganizationId = &#63;.
2083             *
2084             * <p>
2085             * 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.
2086             * </p>
2087             *
2088             * @param companyId the company ID
2089             * @param parentOrganizationId the parent organization ID
2090             * @param start the lower bound of the range of organizations
2091             * @param end the upper bound of the range of organizations (not inclusive)
2092             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2093             * @return the ordered range of matching organizations
2094             * @throws SystemException if a system exception occurred
2095             */
2096            public List<Organization> findByC_P(long companyId,
2097                    long parentOrganizationId, int start, int end,
2098                    OrderByComparator orderByComparator) throws SystemException {
2099                    FinderPath finderPath = null;
2100                    Object[] finderArgs = null;
2101    
2102                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2103                                    (orderByComparator == null)) {
2104                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P;
2105                            finderArgs = new Object[] { companyId, parentOrganizationId };
2106                    }
2107                    else {
2108                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_P;
2109                            finderArgs = new Object[] {
2110                                            companyId, parentOrganizationId,
2111                                            
2112                                            start, end, orderByComparator
2113                                    };
2114                    }
2115    
2116                    List<Organization> list = (List<Organization>)FinderCacheUtil.getResult(finderPath,
2117                                    finderArgs, this);
2118    
2119                    if ((list != null) && !list.isEmpty()) {
2120                            for (Organization organization : list) {
2121                                    if ((companyId != organization.getCompanyId()) ||
2122                                                    (parentOrganizationId != organization.getParentOrganizationId())) {
2123                                            list = null;
2124    
2125                                            break;
2126                                    }
2127                            }
2128                    }
2129    
2130                    if (list == null) {
2131                            StringBundler query = null;
2132    
2133                            if (orderByComparator != null) {
2134                                    query = new StringBundler(4 +
2135                                                    (orderByComparator.getOrderByFields().length * 3));
2136                            }
2137                            else {
2138                                    query = new StringBundler(4);
2139                            }
2140    
2141                            query.append(_SQL_SELECT_ORGANIZATION_WHERE);
2142    
2143                            query.append(_FINDER_COLUMN_C_P_COMPANYID_2);
2144    
2145                            query.append(_FINDER_COLUMN_C_P_PARENTORGANIZATIONID_2);
2146    
2147                            if (orderByComparator != null) {
2148                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2149                                            orderByComparator);
2150                            }
2151    
2152                            else {
2153                                    query.append(OrganizationModelImpl.ORDER_BY_JPQL);
2154                            }
2155    
2156                            String sql = query.toString();
2157    
2158                            Session session = null;
2159    
2160                            try {
2161                                    session = openSession();
2162    
2163                                    Query q = session.createQuery(sql);
2164    
2165                                    QueryPos qPos = QueryPos.getInstance(q);
2166    
2167                                    qPos.add(companyId);
2168    
2169                                    qPos.add(parentOrganizationId);
2170    
2171                                    list = (List<Organization>)QueryUtil.list(q, getDialect(),
2172                                                    start, end);
2173                            }
2174                            catch (Exception e) {
2175                                    throw processException(e);
2176                            }
2177                            finally {
2178                                    if (list == null) {
2179                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
2180                                    }
2181                                    else {
2182                                            cacheResult(list);
2183    
2184                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
2185                                    }
2186    
2187                                    closeSession(session);
2188                            }
2189                    }
2190    
2191                    return list;
2192            }
2193    
2194            /**
2195             * Returns the first organization in the ordered set where companyId = &#63; and parentOrganizationId = &#63;.
2196             *
2197             * @param companyId the company ID
2198             * @param parentOrganizationId the parent organization ID
2199             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2200             * @return the first matching organization
2201             * @throws com.liferay.portal.NoSuchOrganizationException if a matching organization could not be found
2202             * @throws SystemException if a system exception occurred
2203             */
2204            public Organization findByC_P_First(long companyId,
2205                    long parentOrganizationId, OrderByComparator orderByComparator)
2206                    throws NoSuchOrganizationException, SystemException {
2207                    Organization organization = fetchByC_P_First(companyId,
2208                                    parentOrganizationId, orderByComparator);
2209    
2210                    if (organization != null) {
2211                            return organization;
2212                    }
2213    
2214                    StringBundler msg = new StringBundler(6);
2215    
2216                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2217    
2218                    msg.append("companyId=");
2219                    msg.append(companyId);
2220    
2221                    msg.append(", parentOrganizationId=");
2222                    msg.append(parentOrganizationId);
2223    
2224                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2225    
2226                    throw new NoSuchOrganizationException(msg.toString());
2227            }
2228    
2229            /**
2230             * Returns the first organization in the ordered set where companyId = &#63; and parentOrganizationId = &#63;.
2231             *
2232             * @param companyId the company ID
2233             * @param parentOrganizationId the parent organization ID
2234             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2235             * @return the first matching organization, or <code>null</code> if a matching organization could not be found
2236             * @throws SystemException if a system exception occurred
2237             */
2238            public Organization fetchByC_P_First(long companyId,
2239                    long parentOrganizationId, OrderByComparator orderByComparator)
2240                    throws SystemException {
2241                    List<Organization> list = findByC_P(companyId, parentOrganizationId, 0,
2242                                    1, orderByComparator);
2243    
2244                    if (!list.isEmpty()) {
2245                            return list.get(0);
2246                    }
2247    
2248                    return null;
2249            }
2250    
2251            /**
2252             * Returns the last organization in the ordered set where companyId = &#63; and parentOrganizationId = &#63;.
2253             *
2254             * @param companyId the company ID
2255             * @param parentOrganizationId the parent organization ID
2256             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2257             * @return the last matching organization
2258             * @throws com.liferay.portal.NoSuchOrganizationException if a matching organization could not be found
2259             * @throws SystemException if a system exception occurred
2260             */
2261            public Organization findByC_P_Last(long companyId,
2262                    long parentOrganizationId, OrderByComparator orderByComparator)
2263                    throws NoSuchOrganizationException, SystemException {
2264                    Organization organization = fetchByC_P_Last(companyId,
2265                                    parentOrganizationId, orderByComparator);
2266    
2267                    if (organization != null) {
2268                            return organization;
2269                    }
2270    
2271                    StringBundler msg = new StringBundler(6);
2272    
2273                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2274    
2275                    msg.append("companyId=");
2276                    msg.append(companyId);
2277    
2278                    msg.append(", parentOrganizationId=");
2279                    msg.append(parentOrganizationId);
2280    
2281                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2282    
2283                    throw new NoSuchOrganizationException(msg.toString());
2284            }
2285    
2286            /**
2287             * Returns the last organization in the ordered set where companyId = &#63; and parentOrganizationId = &#63;.
2288             *
2289             * @param companyId the company ID
2290             * @param parentOrganizationId the parent organization ID
2291             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2292             * @return the last matching organization, or <code>null</code> if a matching organization could not be found
2293             * @throws SystemException if a system exception occurred
2294             */
2295            public Organization fetchByC_P_Last(long companyId,
2296                    long parentOrganizationId, OrderByComparator orderByComparator)
2297                    throws SystemException {
2298                    int count = countByC_P(companyId, parentOrganizationId);
2299    
2300                    List<Organization> list = findByC_P(companyId, parentOrganizationId,
2301                                    count - 1, count, orderByComparator);
2302    
2303                    if (!list.isEmpty()) {
2304                            return list.get(0);
2305                    }
2306    
2307                    return null;
2308            }
2309    
2310            /**
2311             * Returns the organizations before and after the current organization in the ordered set where companyId = &#63; and parentOrganizationId = &#63;.
2312             *
2313             * @param organizationId the primary key of the current organization
2314             * @param companyId the company ID
2315             * @param parentOrganizationId the parent organization ID
2316             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2317             * @return the previous, current, and next organization
2318             * @throws com.liferay.portal.NoSuchOrganizationException if a organization with the primary key could not be found
2319             * @throws SystemException if a system exception occurred
2320             */
2321            public Organization[] findByC_P_PrevAndNext(long organizationId,
2322                    long companyId, long parentOrganizationId,
2323                    OrderByComparator orderByComparator)
2324                    throws NoSuchOrganizationException, SystemException {
2325                    Organization organization = findByPrimaryKey(organizationId);
2326    
2327                    Session session = null;
2328    
2329                    try {
2330                            session = openSession();
2331    
2332                            Organization[] array = new OrganizationImpl[3];
2333    
2334                            array[0] = getByC_P_PrevAndNext(session, organization, companyId,
2335                                            parentOrganizationId, orderByComparator, true);
2336    
2337                            array[1] = organization;
2338    
2339                            array[2] = getByC_P_PrevAndNext(session, organization, companyId,
2340                                            parentOrganizationId, orderByComparator, false);
2341    
2342                            return array;
2343                    }
2344                    catch (Exception e) {
2345                            throw processException(e);
2346                    }
2347                    finally {
2348                            closeSession(session);
2349                    }
2350            }
2351    
2352            protected Organization getByC_P_PrevAndNext(Session session,
2353                    Organization organization, long companyId, long parentOrganizationId,
2354                    OrderByComparator orderByComparator, boolean previous) {
2355                    StringBundler query = null;
2356    
2357                    if (orderByComparator != null) {
2358                            query = new StringBundler(6 +
2359                                            (orderByComparator.getOrderByFields().length * 6));
2360                    }
2361                    else {
2362                            query = new StringBundler(3);
2363                    }
2364    
2365                    query.append(_SQL_SELECT_ORGANIZATION_WHERE);
2366    
2367                    query.append(_FINDER_COLUMN_C_P_COMPANYID_2);
2368    
2369                    query.append(_FINDER_COLUMN_C_P_PARENTORGANIZATIONID_2);
2370    
2371                    if (orderByComparator != null) {
2372                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2373    
2374                            if (orderByConditionFields.length > 0) {
2375                                    query.append(WHERE_AND);
2376                            }
2377    
2378                            for (int i = 0; i < orderByConditionFields.length; i++) {
2379                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2380                                    query.append(orderByConditionFields[i]);
2381    
2382                                    if ((i + 1) < orderByConditionFields.length) {
2383                                            if (orderByComparator.isAscending() ^ previous) {
2384                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2385                                            }
2386                                            else {
2387                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2388                                            }
2389                                    }
2390                                    else {
2391                                            if (orderByComparator.isAscending() ^ previous) {
2392                                                    query.append(WHERE_GREATER_THAN);
2393                                            }
2394                                            else {
2395                                                    query.append(WHERE_LESSER_THAN);
2396                                            }
2397                                    }
2398                            }
2399    
2400                            query.append(ORDER_BY_CLAUSE);
2401    
2402                            String[] orderByFields = orderByComparator.getOrderByFields();
2403    
2404                            for (int i = 0; i < orderByFields.length; i++) {
2405                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2406                                    query.append(orderByFields[i]);
2407    
2408                                    if ((i + 1) < orderByFields.length) {
2409                                            if (orderByComparator.isAscending() ^ previous) {
2410                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2411                                            }
2412                                            else {
2413                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2414                                            }
2415                                    }
2416                                    else {
2417                                            if (orderByComparator.isAscending() ^ previous) {
2418                                                    query.append(ORDER_BY_ASC);
2419                                            }
2420                                            else {
2421                                                    query.append(ORDER_BY_DESC);
2422                                            }
2423                                    }
2424                            }
2425                    }
2426    
2427                    else {
2428                            query.append(OrganizationModelImpl.ORDER_BY_JPQL);
2429                    }
2430    
2431                    String sql = query.toString();
2432    
2433                    Query q = session.createQuery(sql);
2434    
2435                    q.setFirstResult(0);
2436                    q.setMaxResults(2);
2437    
2438                    QueryPos qPos = QueryPos.getInstance(q);
2439    
2440                    qPos.add(companyId);
2441    
2442                    qPos.add(parentOrganizationId);
2443    
2444                    if (orderByComparator != null) {
2445                            Object[] values = orderByComparator.getOrderByConditionValues(organization);
2446    
2447                            for (Object value : values) {
2448                                    qPos.add(value);
2449                            }
2450                    }
2451    
2452                    List<Organization> list = q.list();
2453    
2454                    if (list.size() == 2) {
2455                            return list.get(1);
2456                    }
2457                    else {
2458                            return null;
2459                    }
2460            }
2461    
2462            /**
2463             * Returns all the organizations that the user has permission to view where companyId = &#63; and parentOrganizationId = &#63;.
2464             *
2465             * @param companyId the company ID
2466             * @param parentOrganizationId the parent organization ID
2467             * @return the matching organizations that the user has permission to view
2468             * @throws SystemException if a system exception occurred
2469             */
2470            public List<Organization> filterFindByC_P(long companyId,
2471                    long parentOrganizationId) throws SystemException {
2472                    return filterFindByC_P(companyId, parentOrganizationId,
2473                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2474            }
2475    
2476            /**
2477             * Returns a range of all the organizations that the user has permission to view where companyId = &#63; and parentOrganizationId = &#63;.
2478             *
2479             * <p>
2480             * 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.
2481             * </p>
2482             *
2483             * @param companyId the company ID
2484             * @param parentOrganizationId the parent organization ID
2485             * @param start the lower bound of the range of organizations
2486             * @param end the upper bound of the range of organizations (not inclusive)
2487             * @return the range of matching organizations that the user has permission to view
2488             * @throws SystemException if a system exception occurred
2489             */
2490            public List<Organization> filterFindByC_P(long companyId,
2491                    long parentOrganizationId, int start, int end)
2492                    throws SystemException {
2493                    return filterFindByC_P(companyId, parentOrganizationId, start, end, null);
2494            }
2495    
2496            /**
2497             * Returns an ordered range of all the organizations that the user has permissions to view where companyId = &#63; and parentOrganizationId = &#63;.
2498             *
2499             * <p>
2500             * 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.
2501             * </p>
2502             *
2503             * @param companyId the company ID
2504             * @param parentOrganizationId the parent organization ID
2505             * @param start the lower bound of the range of organizations
2506             * @param end the upper bound of the range of organizations (not inclusive)
2507             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2508             * @return the ordered range of matching organizations that the user has permission to view
2509             * @throws SystemException if a system exception occurred
2510             */
2511            public List<Organization> filterFindByC_P(long companyId,
2512                    long parentOrganizationId, int start, int end,
2513                    OrderByComparator orderByComparator) throws SystemException {
2514                    if (!InlineSQLHelperUtil.isEnabled()) {
2515                            return findByC_P(companyId, parentOrganizationId, start, end,
2516                                    orderByComparator);
2517                    }
2518    
2519                    StringBundler query = null;
2520    
2521                    if (orderByComparator != null) {
2522                            query = new StringBundler(4 +
2523                                            (orderByComparator.getOrderByFields().length * 3));
2524                    }
2525                    else {
2526                            query = new StringBundler(4);
2527                    }
2528    
2529                    if (getDB().isSupportsInlineDistinct()) {
2530                            query.append(_FILTER_SQL_SELECT_ORGANIZATION_WHERE);
2531                    }
2532                    else {
2533                            query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_1);
2534                    }
2535    
2536                    query.append(_FINDER_COLUMN_C_P_COMPANYID_2);
2537    
2538                    query.append(_FINDER_COLUMN_C_P_PARENTORGANIZATIONID_2);
2539    
2540                    if (!getDB().isSupportsInlineDistinct()) {
2541                            query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_2);
2542                    }
2543    
2544                    if (orderByComparator != null) {
2545                            if (getDB().isSupportsInlineDistinct()) {
2546                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2547                                            orderByComparator);
2548                            }
2549                            else {
2550                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
2551                                            orderByComparator);
2552                            }
2553                    }
2554    
2555                    else {
2556                            if (getDB().isSupportsInlineDistinct()) {
2557                                    query.append(OrganizationModelImpl.ORDER_BY_JPQL);
2558                            }
2559                            else {
2560                                    query.append(OrganizationModelImpl.ORDER_BY_SQL);
2561                            }
2562                    }
2563    
2564                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2565                                    Organization.class.getName(),
2566                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
2567    
2568                    Session session = null;
2569    
2570                    try {
2571                            session = openSession();
2572    
2573                            SQLQuery q = session.createSQLQuery(sql);
2574    
2575                            if (getDB().isSupportsInlineDistinct()) {
2576                                    q.addEntity(_FILTER_ENTITY_ALIAS, OrganizationImpl.class);
2577                            }
2578                            else {
2579                                    q.addEntity(_FILTER_ENTITY_TABLE, OrganizationImpl.class);
2580                            }
2581    
2582                            QueryPos qPos = QueryPos.getInstance(q);
2583    
2584                            qPos.add(companyId);
2585    
2586                            qPos.add(parentOrganizationId);
2587    
2588                            return (List<Organization>)QueryUtil.list(q, getDialect(), start,
2589                                    end);
2590                    }
2591                    catch (Exception e) {
2592                            throw processException(e);
2593                    }
2594                    finally {
2595                            closeSession(session);
2596                    }
2597            }
2598    
2599            /**
2600             * 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;.
2601             *
2602             * @param organizationId the primary key of the current organization
2603             * @param companyId the company ID
2604             * @param parentOrganizationId the parent organization ID
2605             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2606             * @return the previous, current, and next organization
2607             * @throws com.liferay.portal.NoSuchOrganizationException if a organization with the primary key could not be found
2608             * @throws SystemException if a system exception occurred
2609             */
2610            public Organization[] filterFindByC_P_PrevAndNext(long organizationId,
2611                    long companyId, long parentOrganizationId,
2612                    OrderByComparator orderByComparator)
2613                    throws NoSuchOrganizationException, SystemException {
2614                    if (!InlineSQLHelperUtil.isEnabled()) {
2615                            return findByC_P_PrevAndNext(organizationId, companyId,
2616                                    parentOrganizationId, orderByComparator);
2617                    }
2618    
2619                    Organization organization = findByPrimaryKey(organizationId);
2620    
2621                    Session session = null;
2622    
2623                    try {
2624                            session = openSession();
2625    
2626                            Organization[] array = new OrganizationImpl[3];
2627    
2628                            array[0] = filterGetByC_P_PrevAndNext(session, organization,
2629                                            companyId, parentOrganizationId, orderByComparator, true);
2630    
2631                            array[1] = organization;
2632    
2633                            array[2] = filterGetByC_P_PrevAndNext(session, organization,
2634                                            companyId, parentOrganizationId, orderByComparator, false);
2635    
2636                            return array;
2637                    }
2638                    catch (Exception e) {
2639                            throw processException(e);
2640                    }
2641                    finally {
2642                            closeSession(session);
2643                    }
2644            }
2645    
2646            protected Organization filterGetByC_P_PrevAndNext(Session session,
2647                    Organization organization, long companyId, long parentOrganizationId,
2648                    OrderByComparator orderByComparator, boolean previous) {
2649                    StringBundler query = null;
2650    
2651                    if (orderByComparator != null) {
2652                            query = new StringBundler(6 +
2653                                            (orderByComparator.getOrderByFields().length * 6));
2654                    }
2655                    else {
2656                            query = new StringBundler(3);
2657                    }
2658    
2659                    if (getDB().isSupportsInlineDistinct()) {
2660                            query.append(_FILTER_SQL_SELECT_ORGANIZATION_WHERE);
2661                    }
2662                    else {
2663                            query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_1);
2664                    }
2665    
2666                    query.append(_FINDER_COLUMN_C_P_COMPANYID_2);
2667    
2668                    query.append(_FINDER_COLUMN_C_P_PARENTORGANIZATIONID_2);
2669    
2670                    if (!getDB().isSupportsInlineDistinct()) {
2671                            query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_2);
2672                    }
2673    
2674                    if (orderByComparator != null) {
2675                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2676    
2677                            if (orderByConditionFields.length > 0) {
2678                                    query.append(WHERE_AND);
2679                            }
2680    
2681                            for (int i = 0; i < orderByConditionFields.length; i++) {
2682                                    if (getDB().isSupportsInlineDistinct()) {
2683                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2684                                    }
2685                                    else {
2686                                            query.append(_ORDER_BY_ENTITY_TABLE);
2687                                    }
2688    
2689                                    query.append(orderByConditionFields[i]);
2690    
2691                                    if ((i + 1) < orderByConditionFields.length) {
2692                                            if (orderByComparator.isAscending() ^ previous) {
2693                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2694                                            }
2695                                            else {
2696                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2697                                            }
2698                                    }
2699                                    else {
2700                                            if (orderByComparator.isAscending() ^ previous) {
2701                                                    query.append(WHERE_GREATER_THAN);
2702                                            }
2703                                            else {
2704                                                    query.append(WHERE_LESSER_THAN);
2705                                            }
2706                                    }
2707                            }
2708    
2709                            query.append(ORDER_BY_CLAUSE);
2710    
2711                            String[] orderByFields = orderByComparator.getOrderByFields();
2712    
2713                            for (int i = 0; i < orderByFields.length; i++) {
2714                                    if (getDB().isSupportsInlineDistinct()) {
2715                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2716                                    }
2717                                    else {
2718                                            query.append(_ORDER_BY_ENTITY_TABLE);
2719                                    }
2720    
2721                                    query.append(orderByFields[i]);
2722    
2723                                    if ((i + 1) < orderByFields.length) {
2724                                            if (orderByComparator.isAscending() ^ previous) {
2725                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2726                                            }
2727                                            else {
2728                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2729                                            }
2730                                    }
2731                                    else {
2732                                            if (orderByComparator.isAscending() ^ previous) {
2733                                                    query.append(ORDER_BY_ASC);
2734                                            }
2735                                            else {
2736                                                    query.append(ORDER_BY_DESC);
2737                                            }
2738                                    }
2739                            }
2740                    }
2741    
2742                    else {
2743                            if (getDB().isSupportsInlineDistinct()) {
2744                                    query.append(OrganizationModelImpl.ORDER_BY_JPQL);
2745                            }
2746                            else {
2747                                    query.append(OrganizationModelImpl.ORDER_BY_SQL);
2748                            }
2749                    }
2750    
2751                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2752                                    Organization.class.getName(),
2753                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
2754    
2755                    SQLQuery q = session.createSQLQuery(sql);
2756    
2757                    q.setFirstResult(0);
2758                    q.setMaxResults(2);
2759    
2760                    if (getDB().isSupportsInlineDistinct()) {
2761                            q.addEntity(_FILTER_ENTITY_ALIAS, OrganizationImpl.class);
2762                    }
2763                    else {
2764                            q.addEntity(_FILTER_ENTITY_TABLE, OrganizationImpl.class);
2765                    }
2766    
2767                    QueryPos qPos = QueryPos.getInstance(q);
2768    
2769                    qPos.add(companyId);
2770    
2771                    qPos.add(parentOrganizationId);
2772    
2773                    if (orderByComparator != null) {
2774                            Object[] values = orderByComparator.getOrderByConditionValues(organization);
2775    
2776                            for (Object value : values) {
2777                                    qPos.add(value);
2778                            }
2779                    }
2780    
2781                    List<Organization> list = q.list();
2782    
2783                    if (list.size() == 2) {
2784                            return list.get(1);
2785                    }
2786                    else {
2787                            return null;
2788                    }
2789            }
2790    
2791            /**
2792             * Returns the organization where companyId = &#63; and name = &#63; or throws a {@link com.liferay.portal.NoSuchOrganizationException} if it could not be found.
2793             *
2794             * @param companyId the company ID
2795             * @param name the name
2796             * @return the matching organization
2797             * @throws com.liferay.portal.NoSuchOrganizationException if a matching organization could not be found
2798             * @throws SystemException if a system exception occurred
2799             */
2800            public Organization findByC_N(long companyId, String name)
2801                    throws NoSuchOrganizationException, SystemException {
2802                    Organization organization = fetchByC_N(companyId, name);
2803    
2804                    if (organization == null) {
2805                            StringBundler msg = new StringBundler(6);
2806    
2807                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2808    
2809                            msg.append("companyId=");
2810                            msg.append(companyId);
2811    
2812                            msg.append(", name=");
2813                            msg.append(name);
2814    
2815                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2816    
2817                            if (_log.isWarnEnabled()) {
2818                                    _log.warn(msg.toString());
2819                            }
2820    
2821                            throw new NoSuchOrganizationException(msg.toString());
2822                    }
2823    
2824                    return organization;
2825            }
2826    
2827            /**
2828             * Returns the organization where companyId = &#63; and name = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
2829             *
2830             * @param companyId the company ID
2831             * @param name the name
2832             * @return the matching organization, or <code>null</code> if a matching organization could not be found
2833             * @throws SystemException if a system exception occurred
2834             */
2835            public Organization fetchByC_N(long companyId, String name)
2836                    throws SystemException {
2837                    return fetchByC_N(companyId, name, true);
2838            }
2839    
2840            /**
2841             * 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.
2842             *
2843             * @param companyId the company ID
2844             * @param name the name
2845             * @param retrieveFromCache whether to use the finder cache
2846             * @return the matching organization, or <code>null</code> if a matching organization could not be found
2847             * @throws SystemException if a system exception occurred
2848             */
2849            public Organization fetchByC_N(long companyId, String name,
2850                    boolean retrieveFromCache) throws SystemException {
2851                    Object[] finderArgs = new Object[] { companyId, name };
2852    
2853                    Object result = null;
2854    
2855                    if (retrieveFromCache) {
2856                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_N,
2857                                            finderArgs, this);
2858                    }
2859    
2860                    if (result instanceof Organization) {
2861                            Organization organization = (Organization)result;
2862    
2863                            if ((companyId != organization.getCompanyId()) ||
2864                                            !Validator.equals(name, organization.getName())) {
2865                                    result = null;
2866                            }
2867                    }
2868    
2869                    if (result == null) {
2870                            StringBundler query = new StringBundler(4);
2871    
2872                            query.append(_SQL_SELECT_ORGANIZATION_WHERE);
2873    
2874                            query.append(_FINDER_COLUMN_C_N_COMPANYID_2);
2875    
2876                            if (name == null) {
2877                                    query.append(_FINDER_COLUMN_C_N_NAME_1);
2878                            }
2879                            else {
2880                                    if (name.equals(StringPool.BLANK)) {
2881                                            query.append(_FINDER_COLUMN_C_N_NAME_3);
2882                                    }
2883                                    else {
2884                                            query.append(_FINDER_COLUMN_C_N_NAME_2);
2885                                    }
2886                            }
2887    
2888                            query.append(OrganizationModelImpl.ORDER_BY_JPQL);
2889    
2890                            String sql = query.toString();
2891    
2892                            Session session = null;
2893    
2894                            try {
2895                                    session = openSession();
2896    
2897                                    Query q = session.createQuery(sql);
2898    
2899                                    QueryPos qPos = QueryPos.getInstance(q);
2900    
2901                                    qPos.add(companyId);
2902    
2903                                    if (name != null) {
2904                                            qPos.add(name);
2905                                    }
2906    
2907                                    List<Organization> list = q.list();
2908    
2909                                    result = list;
2910    
2911                                    Organization organization = null;
2912    
2913                                    if (list.isEmpty()) {
2914                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
2915                                                    finderArgs, list);
2916                                    }
2917                                    else {
2918                                            organization = list.get(0);
2919    
2920                                            cacheResult(organization);
2921    
2922                                            if ((organization.getCompanyId() != companyId) ||
2923                                                            (organization.getName() == null) ||
2924                                                            !organization.getName().equals(name)) {
2925                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
2926                                                            finderArgs, organization);
2927                                            }
2928                                    }
2929    
2930                                    return organization;
2931                            }
2932                            catch (Exception e) {
2933                                    throw processException(e);
2934                            }
2935                            finally {
2936                                    if (result == null) {
2937                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N,
2938                                                    finderArgs);
2939                                    }
2940    
2941                                    closeSession(session);
2942                            }
2943                    }
2944                    else {
2945                            if (result instanceof List<?>) {
2946                                    return null;
2947                            }
2948                            else {
2949                                    return (Organization)result;
2950                            }
2951                    }
2952            }
2953    
2954            /**
2955             * Returns all the organizations.
2956             *
2957             * @return the organizations
2958             * @throws SystemException if a system exception occurred
2959             */
2960            public List<Organization> findAll() throws SystemException {
2961                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2962            }
2963    
2964            /**
2965             * Returns a range of all the organizations.
2966             *
2967             * <p>
2968             * 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.
2969             * </p>
2970             *
2971             * @param start the lower bound of the range of organizations
2972             * @param end the upper bound of the range of organizations (not inclusive)
2973             * @return the range of organizations
2974             * @throws SystemException if a system exception occurred
2975             */
2976            public List<Organization> findAll(int start, int end)
2977                    throws SystemException {
2978                    return findAll(start, end, null);
2979            }
2980    
2981            /**
2982             * Returns an ordered range of all the organizations.
2983             *
2984             * <p>
2985             * 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.
2986             * </p>
2987             *
2988             * @param start the lower bound of the range of organizations
2989             * @param end the upper bound of the range of organizations (not inclusive)
2990             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2991             * @return the ordered range of organizations
2992             * @throws SystemException if a system exception occurred
2993             */
2994            public List<Organization> findAll(int start, int end,
2995                    OrderByComparator orderByComparator) throws SystemException {
2996                    FinderPath finderPath = null;
2997                    Object[] finderArgs = new Object[] { start, end, orderByComparator };
2998    
2999                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3000                                    (orderByComparator == null)) {
3001                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
3002                            finderArgs = FINDER_ARGS_EMPTY;
3003                    }
3004                    else {
3005                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
3006                            finderArgs = new Object[] { start, end, orderByComparator };
3007                    }
3008    
3009                    List<Organization> list = (List<Organization>)FinderCacheUtil.getResult(finderPath,
3010                                    finderArgs, this);
3011    
3012                    if (list == null) {
3013                            StringBundler query = null;
3014                            String sql = null;
3015    
3016                            if (orderByComparator != null) {
3017                                    query = new StringBundler(2 +
3018                                                    (orderByComparator.getOrderByFields().length * 3));
3019    
3020                                    query.append(_SQL_SELECT_ORGANIZATION);
3021    
3022                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3023                                            orderByComparator);
3024    
3025                                    sql = query.toString();
3026                            }
3027                            else {
3028                                    sql = _SQL_SELECT_ORGANIZATION.concat(OrganizationModelImpl.ORDER_BY_JPQL);
3029                            }
3030    
3031                            Session session = null;
3032    
3033                            try {
3034                                    session = openSession();
3035    
3036                                    Query q = session.createQuery(sql);
3037    
3038                                    if (orderByComparator == null) {
3039                                            list = (List<Organization>)QueryUtil.list(q, getDialect(),
3040                                                            start, end, false);
3041    
3042                                            Collections.sort(list);
3043                                    }
3044                                    else {
3045                                            list = (List<Organization>)QueryUtil.list(q, getDialect(),
3046                                                            start, end);
3047                                    }
3048                            }
3049                            catch (Exception e) {
3050                                    throw processException(e);
3051                            }
3052                            finally {
3053                                    if (list == null) {
3054                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
3055                                    }
3056                                    else {
3057                                            cacheResult(list);
3058    
3059                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
3060                                    }
3061    
3062                                    closeSession(session);
3063                            }
3064                    }
3065    
3066                    return list;
3067            }
3068    
3069            /**
3070             * Removes all the organizations where companyId = &#63; from the database.
3071             *
3072             * @param companyId the company ID
3073             * @throws SystemException if a system exception occurred
3074             */
3075            public void removeByCompanyId(long companyId) throws SystemException {
3076                    for (Organization organization : findByCompanyId(companyId)) {
3077                            remove(organization);
3078                    }
3079            }
3080    
3081            /**
3082             * Removes all the organizations where companyId = &#63; from the database.
3083             *
3084             * @param companyId the company ID
3085             * @throws SystemException if a system exception occurred
3086             */
3087            public void removeByLocations(long companyId) throws SystemException {
3088                    for (Organization organization : findByLocations(companyId)) {
3089                            remove(organization);
3090                    }
3091            }
3092    
3093            /**
3094             * Removes all the organizations where companyId = &#63; and parentOrganizationId = &#63; from the database.
3095             *
3096             * @param companyId the company ID
3097             * @param parentOrganizationId the parent organization ID
3098             * @throws SystemException if a system exception occurred
3099             */
3100            public void removeByC_P(long companyId, long parentOrganizationId)
3101                    throws SystemException {
3102                    for (Organization organization : findByC_P(companyId,
3103                                    parentOrganizationId)) {
3104                            remove(organization);
3105                    }
3106            }
3107    
3108            /**
3109             * Removes the organization where companyId = &#63; and name = &#63; from the database.
3110             *
3111             * @param companyId the company ID
3112             * @param name the name
3113             * @return the organization that was removed
3114             * @throws SystemException if a system exception occurred
3115             */
3116            public Organization removeByC_N(long companyId, String name)
3117                    throws NoSuchOrganizationException, SystemException {
3118                    Organization organization = findByC_N(companyId, name);
3119    
3120                    return remove(organization);
3121            }
3122    
3123            /**
3124             * Removes all the organizations from the database.
3125             *
3126             * @throws SystemException if a system exception occurred
3127             */
3128            public void removeAll() throws SystemException {
3129                    for (Organization organization : findAll()) {
3130                            remove(organization);
3131                    }
3132            }
3133    
3134            /**
3135             * Returns the number of organizations where companyId = &#63;.
3136             *
3137             * @param companyId the company ID
3138             * @return the number of matching organizations
3139             * @throws SystemException if a system exception occurred
3140             */
3141            public int countByCompanyId(long companyId) throws SystemException {
3142                    Object[] finderArgs = new Object[] { companyId };
3143    
3144                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
3145                                    finderArgs, this);
3146    
3147                    if (count == null) {
3148                            StringBundler query = new StringBundler(2);
3149    
3150                            query.append(_SQL_COUNT_ORGANIZATION_WHERE);
3151    
3152                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
3153    
3154                            String sql = query.toString();
3155    
3156                            Session session = null;
3157    
3158                            try {
3159                                    session = openSession();
3160    
3161                                    Query q = session.createQuery(sql);
3162    
3163                                    QueryPos qPos = QueryPos.getInstance(q);
3164    
3165                                    qPos.add(companyId);
3166    
3167                                    count = (Long)q.uniqueResult();
3168                            }
3169                            catch (Exception e) {
3170                                    throw processException(e);
3171                            }
3172                            finally {
3173                                    if (count == null) {
3174                                            count = Long.valueOf(0);
3175                                    }
3176    
3177                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
3178                                            finderArgs, count);
3179    
3180                                    closeSession(session);
3181                            }
3182                    }
3183    
3184                    return count.intValue();
3185            }
3186    
3187            /**
3188             * Returns the number of organizations that the user has permission to view where companyId = &#63;.
3189             *
3190             * @param companyId the company ID
3191             * @return the number of matching organizations that the user has permission to view
3192             * @throws SystemException if a system exception occurred
3193             */
3194            public int filterCountByCompanyId(long companyId) throws SystemException {
3195                    if (!InlineSQLHelperUtil.isEnabled()) {
3196                            return countByCompanyId(companyId);
3197                    }
3198    
3199                    StringBundler query = new StringBundler(2);
3200    
3201                    query.append(_FILTER_SQL_COUNT_ORGANIZATION_WHERE);
3202    
3203                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
3204    
3205                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3206                                    Organization.class.getName(),
3207                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
3208    
3209                    Session session = null;
3210    
3211                    try {
3212                            session = openSession();
3213    
3214                            SQLQuery q = session.createSQLQuery(sql);
3215    
3216                            q.addScalar(COUNT_COLUMN_NAME,
3217                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
3218    
3219                            QueryPos qPos = QueryPos.getInstance(q);
3220    
3221                            qPos.add(companyId);
3222    
3223                            Long count = (Long)q.uniqueResult();
3224    
3225                            return count.intValue();
3226                    }
3227                    catch (Exception e) {
3228                            throw processException(e);
3229                    }
3230                    finally {
3231                            closeSession(session);
3232                    }
3233            }
3234    
3235            /**
3236             * Returns the number of organizations where companyId = &#63;.
3237             *
3238             * @param companyId the company ID
3239             * @return the number of matching organizations
3240             * @throws SystemException if a system exception occurred
3241             */
3242            public int countByLocations(long companyId) throws SystemException {
3243                    Object[] finderArgs = new Object[] { companyId };
3244    
3245                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_LOCATIONS,
3246                                    finderArgs, this);
3247    
3248                    if (count == null) {
3249                            StringBundler query = new StringBundler(2);
3250    
3251                            query.append(_SQL_COUNT_ORGANIZATION_WHERE);
3252    
3253                            query.append(_FINDER_COLUMN_LOCATIONS_COMPANYID_2);
3254    
3255                            String sql = query.toString();
3256    
3257                            Session session = null;
3258    
3259                            try {
3260                                    session = openSession();
3261    
3262                                    Query q = session.createQuery(sql);
3263    
3264                                    QueryPos qPos = QueryPos.getInstance(q);
3265    
3266                                    qPos.add(companyId);
3267    
3268                                    count = (Long)q.uniqueResult();
3269                            }
3270                            catch (Exception e) {
3271                                    throw processException(e);
3272                            }
3273                            finally {
3274                                    if (count == null) {
3275                                            count = Long.valueOf(0);
3276                                    }
3277    
3278                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_LOCATIONS,
3279                                            finderArgs, count);
3280    
3281                                    closeSession(session);
3282                            }
3283                    }
3284    
3285                    return count.intValue();
3286            }
3287    
3288            /**
3289             * Returns the number of organizations that the user has permission to view where companyId = &#63;.
3290             *
3291             * @param companyId the company ID
3292             * @return the number of matching organizations that the user has permission to view
3293             * @throws SystemException if a system exception occurred
3294             */
3295            public int filterCountByLocations(long companyId) throws SystemException {
3296                    if (!InlineSQLHelperUtil.isEnabled()) {
3297                            return countByLocations(companyId);
3298                    }
3299    
3300                    StringBundler query = new StringBundler(2);
3301    
3302                    query.append(_FILTER_SQL_COUNT_ORGANIZATION_WHERE);
3303    
3304                    query.append(_FINDER_COLUMN_LOCATIONS_COMPANYID_2);
3305    
3306                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3307                                    Organization.class.getName(),
3308                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
3309    
3310                    Session session = null;
3311    
3312                    try {
3313                            session = openSession();
3314    
3315                            SQLQuery q = session.createSQLQuery(sql);
3316    
3317                            q.addScalar(COUNT_COLUMN_NAME,
3318                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
3319    
3320                            QueryPos qPos = QueryPos.getInstance(q);
3321    
3322                            qPos.add(companyId);
3323    
3324                            Long count = (Long)q.uniqueResult();
3325    
3326                            return count.intValue();
3327                    }
3328                    catch (Exception e) {
3329                            throw processException(e);
3330                    }
3331                    finally {
3332                            closeSession(session);
3333                    }
3334            }
3335    
3336            /**
3337             * Returns the number of organizations where companyId = &#63; and parentOrganizationId = &#63;.
3338             *
3339             * @param companyId the company ID
3340             * @param parentOrganizationId the parent organization ID
3341             * @return the number of matching organizations
3342             * @throws SystemException if a system exception occurred
3343             */
3344            public int countByC_P(long companyId, long parentOrganizationId)
3345                    throws SystemException {
3346                    Object[] finderArgs = new Object[] { companyId, parentOrganizationId };
3347    
3348                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_P,
3349                                    finderArgs, this);
3350    
3351                    if (count == null) {
3352                            StringBundler query = new StringBundler(3);
3353    
3354                            query.append(_SQL_COUNT_ORGANIZATION_WHERE);
3355    
3356                            query.append(_FINDER_COLUMN_C_P_COMPANYID_2);
3357    
3358                            query.append(_FINDER_COLUMN_C_P_PARENTORGANIZATIONID_2);
3359    
3360                            String sql = query.toString();
3361    
3362                            Session session = null;
3363    
3364                            try {
3365                                    session = openSession();
3366    
3367                                    Query q = session.createQuery(sql);
3368    
3369                                    QueryPos qPos = QueryPos.getInstance(q);
3370    
3371                                    qPos.add(companyId);
3372    
3373                                    qPos.add(parentOrganizationId);
3374    
3375                                    count = (Long)q.uniqueResult();
3376                            }
3377                            catch (Exception e) {
3378                                    throw processException(e);
3379                            }
3380                            finally {
3381                                    if (count == null) {
3382                                            count = Long.valueOf(0);
3383                                    }
3384    
3385                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_P, finderArgs,
3386                                            count);
3387    
3388                                    closeSession(session);
3389                            }
3390                    }
3391    
3392                    return count.intValue();
3393            }
3394    
3395            /**
3396             * Returns the number of organizations that the user has permission to view where companyId = &#63; and parentOrganizationId = &#63;.
3397             *
3398             * @param companyId the company ID
3399             * @param parentOrganizationId the parent organization ID
3400             * @return the number of matching organizations that the user has permission to view
3401             * @throws SystemException if a system exception occurred
3402             */
3403            public int filterCountByC_P(long companyId, long parentOrganizationId)
3404                    throws SystemException {
3405                    if (!InlineSQLHelperUtil.isEnabled()) {
3406                            return countByC_P(companyId, parentOrganizationId);
3407                    }
3408    
3409                    StringBundler query = new StringBundler(3);
3410    
3411                    query.append(_FILTER_SQL_COUNT_ORGANIZATION_WHERE);
3412    
3413                    query.append(_FINDER_COLUMN_C_P_COMPANYID_2);
3414    
3415                    query.append(_FINDER_COLUMN_C_P_PARENTORGANIZATIONID_2);
3416    
3417                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3418                                    Organization.class.getName(),
3419                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
3420    
3421                    Session session = null;
3422    
3423                    try {
3424                            session = openSession();
3425    
3426                            SQLQuery q = session.createSQLQuery(sql);
3427    
3428                            q.addScalar(COUNT_COLUMN_NAME,
3429                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
3430    
3431                            QueryPos qPos = QueryPos.getInstance(q);
3432    
3433                            qPos.add(companyId);
3434    
3435                            qPos.add(parentOrganizationId);
3436    
3437                            Long count = (Long)q.uniqueResult();
3438    
3439                            return count.intValue();
3440                    }
3441                    catch (Exception e) {
3442                            throw processException(e);
3443                    }
3444                    finally {
3445                            closeSession(session);
3446                    }
3447            }
3448    
3449            /**
3450             * Returns the number of organizations where companyId = &#63; and name = &#63;.
3451             *
3452             * @param companyId the company ID
3453             * @param name the name
3454             * @return the number of matching organizations
3455             * @throws SystemException if a system exception occurred
3456             */
3457            public int countByC_N(long companyId, String name)
3458                    throws SystemException {
3459                    Object[] finderArgs = new Object[] { companyId, name };
3460    
3461                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_N,
3462                                    finderArgs, this);
3463    
3464                    if (count == null) {
3465                            StringBundler query = new StringBundler(3);
3466    
3467                            query.append(_SQL_COUNT_ORGANIZATION_WHERE);
3468    
3469                            query.append(_FINDER_COLUMN_C_N_COMPANYID_2);
3470    
3471                            if (name == null) {
3472                                    query.append(_FINDER_COLUMN_C_N_NAME_1);
3473                            }
3474                            else {
3475                                    if (name.equals(StringPool.BLANK)) {
3476                                            query.append(_FINDER_COLUMN_C_N_NAME_3);
3477                                    }
3478                                    else {
3479                                            query.append(_FINDER_COLUMN_C_N_NAME_2);
3480                                    }
3481                            }
3482    
3483                            String sql = query.toString();
3484    
3485                            Session session = null;
3486    
3487                            try {
3488                                    session = openSession();
3489    
3490                                    Query q = session.createQuery(sql);
3491    
3492                                    QueryPos qPos = QueryPos.getInstance(q);
3493    
3494                                    qPos.add(companyId);
3495    
3496                                    if (name != null) {
3497                                            qPos.add(name);
3498                                    }
3499    
3500                                    count = (Long)q.uniqueResult();
3501                            }
3502                            catch (Exception e) {
3503                                    throw processException(e);
3504                            }
3505                            finally {
3506                                    if (count == null) {
3507                                            count = Long.valueOf(0);
3508                                    }
3509    
3510                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_N, finderArgs,
3511                                            count);
3512    
3513                                    closeSession(session);
3514                            }
3515                    }
3516    
3517                    return count.intValue();
3518            }
3519    
3520            /**
3521             * Returns the number of organizations.
3522             *
3523             * @return the number of organizations
3524             * @throws SystemException if a system exception occurred
3525             */
3526            public int countAll() throws SystemException {
3527                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
3528                                    FINDER_ARGS_EMPTY, this);
3529    
3530                    if (count == null) {
3531                            Session session = null;
3532    
3533                            try {
3534                                    session = openSession();
3535    
3536                                    Query q = session.createQuery(_SQL_COUNT_ORGANIZATION);
3537    
3538                                    count = (Long)q.uniqueResult();
3539                            }
3540                            catch (Exception e) {
3541                                    throw processException(e);
3542                            }
3543                            finally {
3544                                    if (count == null) {
3545                                            count = Long.valueOf(0);
3546                                    }
3547    
3548                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
3549                                            FINDER_ARGS_EMPTY, count);
3550    
3551                                    closeSession(session);
3552                            }
3553                    }
3554    
3555                    return count.intValue();
3556            }
3557    
3558            /**
3559             * Returns all the groups associated with the organization.
3560             *
3561             * @param pk the primary key of the organization
3562             * @return the groups associated with the organization
3563             * @throws SystemException if a system exception occurred
3564             */
3565            public List<com.liferay.portal.model.Group> getGroups(long pk)
3566                    throws SystemException {
3567                    return getGroups(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
3568            }
3569    
3570            /**
3571             * Returns a range of all the groups associated with the organization.
3572             *
3573             * <p>
3574             * 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.
3575             * </p>
3576             *
3577             * @param pk the primary key of the organization
3578             * @param start the lower bound of the range of organizations
3579             * @param end the upper bound of the range of organizations (not inclusive)
3580             * @return the range of groups associated with the organization
3581             * @throws SystemException if a system exception occurred
3582             */
3583            public List<com.liferay.portal.model.Group> getGroups(long pk, int start,
3584                    int end) throws SystemException {
3585                    return getGroups(pk, start, end, null);
3586            }
3587    
3588            public static final FinderPath FINDER_PATH_GET_GROUPS = new FinderPath(com.liferay.portal.model.impl.GroupModelImpl.ENTITY_CACHE_ENABLED,
3589                            OrganizationModelImpl.FINDER_CACHE_ENABLED_GROUPS_ORGS,
3590                            com.liferay.portal.model.impl.GroupImpl.class,
3591                            OrganizationModelImpl.MAPPING_TABLE_GROUPS_ORGS_NAME, "getGroups",
3592                            new String[] {
3593                                    Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
3594                                    "com.liferay.portal.kernel.util.OrderByComparator"
3595                            });
3596    
3597            static {
3598                    FINDER_PATH_GET_GROUPS.setCacheKeyGeneratorCacheName(null);
3599            }
3600    
3601            /**
3602             * Returns an ordered range of all the groups associated with the organization.
3603             *
3604             * <p>
3605             * 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.
3606             * </p>
3607             *
3608             * @param pk the primary key of the organization
3609             * @param start the lower bound of the range of organizations
3610             * @param end the upper bound of the range of organizations (not inclusive)
3611             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3612             * @return the ordered range of groups associated with the organization
3613             * @throws SystemException if a system exception occurred
3614             */
3615            public List<com.liferay.portal.model.Group> getGroups(long pk, int start,
3616                    int end, OrderByComparator orderByComparator) throws SystemException {
3617                    Object[] finderArgs = new Object[] { pk, start, end, orderByComparator };
3618    
3619                    List<com.liferay.portal.model.Group> list = (List<com.liferay.portal.model.Group>)FinderCacheUtil.getResult(FINDER_PATH_GET_GROUPS,
3620                                    finderArgs, this);
3621    
3622                    if (list == null) {
3623                            Session session = null;
3624    
3625                            try {
3626                                    session = openSession();
3627    
3628                                    String sql = null;
3629    
3630                                    if (orderByComparator != null) {
3631                                            sql = _SQL_GETGROUPS.concat(ORDER_BY_CLAUSE)
3632                                                                                    .concat(orderByComparator.getOrderBy());
3633                                    }
3634                                    else {
3635                                            sql = _SQL_GETGROUPS.concat(com.liferay.portal.model.impl.GroupModelImpl.ORDER_BY_SQL);
3636                                    }
3637    
3638                                    SQLQuery q = session.createSQLQuery(sql);
3639    
3640                                    q.addEntity("Group_",
3641                                            com.liferay.portal.model.impl.GroupImpl.class);
3642    
3643                                    QueryPos qPos = QueryPos.getInstance(q);
3644    
3645                                    qPos.add(pk);
3646    
3647                                    list = (List<com.liferay.portal.model.Group>)QueryUtil.list(q,
3648                                                    getDialect(), start, end);
3649                            }
3650                            catch (Exception e) {
3651                                    throw processException(e);
3652                            }
3653                            finally {
3654                                    if (list == null) {
3655                                            FinderCacheUtil.removeResult(FINDER_PATH_GET_GROUPS,
3656                                                    finderArgs);
3657                                    }
3658                                    else {
3659                                            groupPersistence.cacheResult(list);
3660    
3661                                            FinderCacheUtil.putResult(FINDER_PATH_GET_GROUPS,
3662                                                    finderArgs, list);
3663                                    }
3664    
3665                                    closeSession(session);
3666                            }
3667                    }
3668    
3669                    return list;
3670            }
3671    
3672            public static final FinderPath FINDER_PATH_GET_GROUPS_SIZE = new FinderPath(com.liferay.portal.model.impl.GroupModelImpl.ENTITY_CACHE_ENABLED,
3673                            OrganizationModelImpl.FINDER_CACHE_ENABLED_GROUPS_ORGS, Long.class,
3674                            OrganizationModelImpl.MAPPING_TABLE_GROUPS_ORGS_NAME,
3675                            "getGroupsSize", new String[] { Long.class.getName() });
3676    
3677            static {
3678                    FINDER_PATH_GET_GROUPS_SIZE.setCacheKeyGeneratorCacheName(null);
3679            }
3680    
3681            /**
3682             * Returns the number of groups associated with the organization.
3683             *
3684             * @param pk the primary key of the organization
3685             * @return the number of groups associated with the organization
3686             * @throws SystemException if a system exception occurred
3687             */
3688            public int getGroupsSize(long pk) throws SystemException {
3689                    Object[] finderArgs = new Object[] { pk };
3690    
3691                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_GROUPS_SIZE,
3692                                    finderArgs, this);
3693    
3694                    if (count == null) {
3695                            Session session = null;
3696    
3697                            try {
3698                                    session = openSession();
3699    
3700                                    SQLQuery q = session.createSQLQuery(_SQL_GETGROUPSSIZE);
3701    
3702                                    q.addScalar(COUNT_COLUMN_NAME,
3703                                            com.liferay.portal.kernel.dao.orm.Type.LONG);
3704    
3705                                    QueryPos qPos = QueryPos.getInstance(q);
3706    
3707                                    qPos.add(pk);
3708    
3709                                    count = (Long)q.uniqueResult();
3710                            }
3711                            catch (Exception e) {
3712                                    throw processException(e);
3713                            }
3714                            finally {
3715                                    if (count == null) {
3716                                            count = Long.valueOf(0);
3717                                    }
3718    
3719                                    FinderCacheUtil.putResult(FINDER_PATH_GET_GROUPS_SIZE,
3720                                            finderArgs, count);
3721    
3722                                    closeSession(session);
3723                            }
3724                    }
3725    
3726                    return count.intValue();
3727            }
3728    
3729            public static final FinderPath FINDER_PATH_CONTAINS_GROUP = new FinderPath(com.liferay.portal.model.impl.GroupModelImpl.ENTITY_CACHE_ENABLED,
3730                            OrganizationModelImpl.FINDER_CACHE_ENABLED_GROUPS_ORGS,
3731                            Boolean.class,
3732                            OrganizationModelImpl.MAPPING_TABLE_GROUPS_ORGS_NAME,
3733                            "containsGroup",
3734                            new String[] { Long.class.getName(), Long.class.getName() });
3735    
3736            /**
3737             * Returns <code>true</code> if the group is associated with the organization.
3738             *
3739             * @param pk the primary key of the organization
3740             * @param groupPK the primary key of the group
3741             * @return <code>true</code> if the group is associated with the organization; <code>false</code> otherwise
3742             * @throws SystemException if a system exception occurred
3743             */
3744            public boolean containsGroup(long pk, long groupPK)
3745                    throws SystemException {
3746                    Object[] finderArgs = new Object[] { pk, groupPK };
3747    
3748                    Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_GROUP,
3749                                    finderArgs, this);
3750    
3751                    if (value == null) {
3752                            try {
3753                                    value = Boolean.valueOf(containsGroup.contains(pk, groupPK));
3754                            }
3755                            catch (Exception e) {
3756                                    throw processException(e);
3757                            }
3758                            finally {
3759                                    if (value == null) {
3760                                            value = Boolean.FALSE;
3761                                    }
3762    
3763                                    FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_GROUP,
3764                                            finderArgs, value);
3765                            }
3766                    }
3767    
3768                    return value.booleanValue();
3769            }
3770    
3771            /**
3772             * Returns <code>true</code> if the organization has any groups associated with it.
3773             *
3774             * @param pk the primary key of the organization to check for associations with groups
3775             * @return <code>true</code> if the organization has any groups associated with it; <code>false</code> otherwise
3776             * @throws SystemException if a system exception occurred
3777             */
3778            public boolean containsGroups(long pk) throws SystemException {
3779                    if (getGroupsSize(pk) > 0) {
3780                            return true;
3781                    }
3782                    else {
3783                            return false;
3784                    }
3785            }
3786    
3787            /**
3788             * Adds an association between the organization and the group. Also notifies the appropriate model listeners and clears the mapping table finder cache.
3789             *
3790             * @param pk the primary key of the organization
3791             * @param groupPK the primary key of the group
3792             * @throws SystemException if a system exception occurred
3793             */
3794            public void addGroup(long pk, long groupPK) throws SystemException {
3795                    try {
3796                            addGroup.add(pk, groupPK);
3797                    }
3798                    catch (Exception e) {
3799                            throw processException(e);
3800                    }
3801                    finally {
3802                            FinderCacheUtil.clearCache(OrganizationModelImpl.MAPPING_TABLE_GROUPS_ORGS_NAME);
3803                    }
3804            }
3805    
3806            /**
3807             * Adds an association between the organization and the group. Also notifies the appropriate model listeners and clears the mapping table finder cache.
3808             *
3809             * @param pk the primary key of the organization
3810             * @param group the group
3811             * @throws SystemException if a system exception occurred
3812             */
3813            public void addGroup(long pk, com.liferay.portal.model.Group group)
3814                    throws SystemException {
3815                    try {
3816                            addGroup.add(pk, group.getPrimaryKey());
3817                    }
3818                    catch (Exception e) {
3819                            throw processException(e);
3820                    }
3821                    finally {
3822                            FinderCacheUtil.clearCache(OrganizationModelImpl.MAPPING_TABLE_GROUPS_ORGS_NAME);
3823                    }
3824            }
3825    
3826            /**
3827             * Adds an association between the organization and the groups. Also notifies the appropriate model listeners and clears the mapping table finder cache.
3828             *
3829             * @param pk the primary key of the organization
3830             * @param groupPKs the primary keys of the groups
3831             * @throws SystemException if a system exception occurred
3832             */
3833            public void addGroups(long pk, long[] groupPKs) throws SystemException {
3834                    try {
3835                            for (long groupPK : groupPKs) {
3836                                    addGroup.add(pk, groupPK);
3837                            }
3838                    }
3839                    catch (Exception e) {
3840                            throw processException(e);
3841                    }
3842                    finally {
3843                            FinderCacheUtil.clearCache(OrganizationModelImpl.MAPPING_TABLE_GROUPS_ORGS_NAME);
3844                    }
3845            }
3846    
3847            /**
3848             * Adds an association between the organization and the groups. Also notifies the appropriate model listeners and clears the mapping table finder cache.
3849             *
3850             * @param pk the primary key of the organization
3851             * @param groups the groups
3852             * @throws SystemException if a system exception occurred
3853             */
3854            public void addGroups(long pk, List<com.liferay.portal.model.Group> groups)
3855                    throws SystemException {
3856                    try {
3857                            for (com.liferay.portal.model.Group group : groups) {
3858                                    addGroup.add(pk, group.getPrimaryKey());
3859                            }
3860                    }
3861                    catch (Exception e) {
3862                            throw processException(e);
3863                    }
3864                    finally {
3865                            FinderCacheUtil.clearCache(OrganizationModelImpl.MAPPING_TABLE_GROUPS_ORGS_NAME);
3866                    }
3867            }
3868    
3869            /**
3870             * Clears all associations between the organization and its groups. Also notifies the appropriate model listeners and clears the mapping table finder cache.
3871             *
3872             * @param pk the primary key of the organization to clear the associated groups from
3873             * @throws SystemException if a system exception occurred
3874             */
3875            public void clearGroups(long pk) throws SystemException {
3876                    try {
3877                            clearGroups.clear(pk);
3878                    }
3879                    catch (Exception e) {
3880                            throw processException(e);
3881                    }
3882                    finally {
3883                            FinderCacheUtil.clearCache(OrganizationModelImpl.MAPPING_TABLE_GROUPS_ORGS_NAME);
3884                    }
3885            }
3886    
3887            /**
3888             * Removes the association between the organization and the group. Also notifies the appropriate model listeners and clears the mapping table finder cache.
3889             *
3890             * @param pk the primary key of the organization
3891             * @param groupPK the primary key of the group
3892             * @throws SystemException if a system exception occurred
3893             */
3894            public void removeGroup(long pk, long groupPK) throws SystemException {
3895                    try {
3896                            removeGroup.remove(pk, groupPK);
3897                    }
3898                    catch (Exception e) {
3899                            throw processException(e);
3900                    }
3901                    finally {
3902                            FinderCacheUtil.clearCache(OrganizationModelImpl.MAPPING_TABLE_GROUPS_ORGS_NAME);
3903                    }
3904            }
3905    
3906            /**
3907             * Removes the association between the organization and the group. Also notifies the appropriate model listeners and clears the mapping table finder cache.
3908             *
3909             * @param pk the primary key of the organization
3910             * @param group the group
3911             * @throws SystemException if a system exception occurred
3912             */
3913            public void removeGroup(long pk, com.liferay.portal.model.Group group)
3914                    throws SystemException {
3915                    try {
3916                            removeGroup.remove(pk, group.getPrimaryKey());
3917                    }
3918                    catch (Exception e) {
3919                            throw processException(e);
3920                    }
3921                    finally {
3922                            FinderCacheUtil.clearCache(OrganizationModelImpl.MAPPING_TABLE_GROUPS_ORGS_NAME);
3923                    }
3924            }
3925    
3926            /**
3927             * Removes the association between the organization and the groups. Also notifies the appropriate model listeners and clears the mapping table finder cache.
3928             *
3929             * @param pk the primary key of the organization
3930             * @param groupPKs the primary keys of the groups
3931             * @throws SystemException if a system exception occurred
3932             */
3933            public void removeGroups(long pk, long[] groupPKs)
3934                    throws SystemException {
3935                    try {
3936                            for (long groupPK : groupPKs) {
3937                                    removeGroup.remove(pk, groupPK);
3938                            }
3939                    }
3940                    catch (Exception e) {
3941                            throw processException(e);
3942                    }
3943                    finally {
3944                            FinderCacheUtil.clearCache(OrganizationModelImpl.MAPPING_TABLE_GROUPS_ORGS_NAME);
3945                    }
3946            }
3947    
3948            /**
3949             * Removes the association between the organization and the groups. Also notifies the appropriate model listeners and clears the mapping table finder cache.
3950             *
3951             * @param pk the primary key of the organization
3952             * @param groups the groups
3953             * @throws SystemException if a system exception occurred
3954             */
3955            public void removeGroups(long pk,
3956                    List<com.liferay.portal.model.Group> groups) throws SystemException {
3957                    try {
3958                            for (com.liferay.portal.model.Group group : groups) {
3959                                    removeGroup.remove(pk, group.getPrimaryKey());
3960                            }
3961                    }
3962                    catch (Exception e) {
3963                            throw processException(e);
3964                    }
3965                    finally {
3966                            FinderCacheUtil.clearCache(OrganizationModelImpl.MAPPING_TABLE_GROUPS_ORGS_NAME);
3967                    }
3968            }
3969    
3970            /**
3971             * 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.
3972             *
3973             * @param pk the primary key of the organization
3974             * @param groupPKs the primary keys of the groups to be associated with the organization
3975             * @throws SystemException if a system exception occurred
3976             */
3977            public void setGroups(long pk, long[] groupPKs) throws SystemException {
3978                    try {
3979                            Set<Long> groupPKSet = SetUtil.fromArray(groupPKs);
3980    
3981                            List<com.liferay.portal.model.Group> groups = getGroups(pk);
3982    
3983                            for (com.liferay.portal.model.Group group : groups) {
3984                                    if (!groupPKSet.remove(group.getPrimaryKey())) {
3985                                            removeGroup.remove(pk, group.getPrimaryKey());
3986                                    }
3987                            }
3988    
3989                            for (Long groupPK : groupPKSet) {
3990                                    addGroup.add(pk, groupPK);
3991                            }
3992                    }
3993                    catch (Exception e) {
3994                            throw processException(e);
3995                    }
3996                    finally {
3997                            FinderCacheUtil.clearCache(OrganizationModelImpl.MAPPING_TABLE_GROUPS_ORGS_NAME);
3998                    }
3999            }
4000    
4001            /**
4002             * 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.
4003             *
4004             * @param pk the primary key of the organization
4005             * @param groups the groups to be associated with the organization
4006             * @throws SystemException if a system exception occurred
4007             */
4008            public void setGroups(long pk, List<com.liferay.portal.model.Group> groups)
4009                    throws SystemException {
4010                    try {
4011                            long[] groupPKs = new long[groups.size()];
4012    
4013                            for (int i = 0; i < groups.size(); i++) {
4014                                    com.liferay.portal.model.Group group = groups.get(i);
4015    
4016                                    groupPKs[i] = group.getPrimaryKey();
4017                            }
4018    
4019                            setGroups(pk, groupPKs);
4020                    }
4021                    catch (Exception e) {
4022                            throw processException(e);
4023                    }
4024                    finally {
4025                            FinderCacheUtil.clearCache(OrganizationModelImpl.MAPPING_TABLE_GROUPS_ORGS_NAME);
4026                    }
4027            }
4028    
4029            /**
4030             * Returns all the users associated with the organization.
4031             *
4032             * @param pk the primary key of the organization
4033             * @return the users associated with the organization
4034             * @throws SystemException if a system exception occurred
4035             */
4036            public List<com.liferay.portal.model.User> getUsers(long pk)
4037                    throws SystemException {
4038                    return getUsers(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
4039            }
4040    
4041            /**
4042             * Returns a range of all the users associated with the organization.
4043             *
4044             * <p>
4045             * 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.
4046             * </p>
4047             *
4048             * @param pk the primary key of the organization
4049             * @param start the lower bound of the range of organizations
4050             * @param end the upper bound of the range of organizations (not inclusive)
4051             * @return the range of users associated with the organization
4052             * @throws SystemException if a system exception occurred
4053             */
4054            public List<com.liferay.portal.model.User> getUsers(long pk, int start,
4055                    int end) throws SystemException {
4056                    return getUsers(pk, start, end, null);
4057            }
4058    
4059            public static final FinderPath FINDER_PATH_GET_USERS = new FinderPath(com.liferay.portal.model.impl.UserModelImpl.ENTITY_CACHE_ENABLED,
4060                            OrganizationModelImpl.FINDER_CACHE_ENABLED_USERS_ORGS,
4061                            com.liferay.portal.model.impl.UserImpl.class,
4062                            OrganizationModelImpl.MAPPING_TABLE_USERS_ORGS_NAME, "getUsers",
4063                            new String[] {
4064                                    Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
4065                                    "com.liferay.portal.kernel.util.OrderByComparator"
4066                            });
4067    
4068            static {
4069                    FINDER_PATH_GET_USERS.setCacheKeyGeneratorCacheName(null);
4070            }
4071    
4072            /**
4073             * Returns an ordered range of all the users associated with the organization.
4074             *
4075             * <p>
4076             * 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.
4077             * </p>
4078             *
4079             * @param pk the primary key of the organization
4080             * @param start the lower bound of the range of organizations
4081             * @param end the upper bound of the range of organizations (not inclusive)
4082             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4083             * @return the ordered range of users associated with the organization
4084             * @throws SystemException if a system exception occurred
4085             */
4086            public List<com.liferay.portal.model.User> getUsers(long pk, int start,
4087                    int end, OrderByComparator orderByComparator) throws SystemException {
4088                    Object[] finderArgs = new Object[] { pk, start, end, orderByComparator };
4089    
4090                    List<com.liferay.portal.model.User> list = (List<com.liferay.portal.model.User>)FinderCacheUtil.getResult(FINDER_PATH_GET_USERS,
4091                                    finderArgs, this);
4092    
4093                    if (list == null) {
4094                            Session session = null;
4095    
4096                            try {
4097                                    session = openSession();
4098    
4099                                    String sql = null;
4100    
4101                                    if (orderByComparator != null) {
4102                                            sql = _SQL_GETUSERS.concat(ORDER_BY_CLAUSE)
4103                                                                               .concat(orderByComparator.getOrderBy());
4104                                    }
4105                                    else {
4106                                            sql = _SQL_GETUSERS;
4107                                    }
4108    
4109                                    SQLQuery q = session.createSQLQuery(sql);
4110    
4111                                    q.addEntity("User_",
4112                                            com.liferay.portal.model.impl.UserImpl.class);
4113    
4114                                    QueryPos qPos = QueryPos.getInstance(q);
4115    
4116                                    qPos.add(pk);
4117    
4118                                    list = (List<com.liferay.portal.model.User>)QueryUtil.list(q,
4119                                                    getDialect(), start, end);
4120                            }
4121                            catch (Exception e) {
4122                                    throw processException(e);
4123                            }
4124                            finally {
4125                                    if (list == null) {
4126                                            FinderCacheUtil.removeResult(FINDER_PATH_GET_USERS,
4127                                                    finderArgs);
4128                                    }
4129                                    else {
4130                                            userPersistence.cacheResult(list);
4131    
4132                                            FinderCacheUtil.putResult(FINDER_PATH_GET_USERS,
4133                                                    finderArgs, list);
4134                                    }
4135    
4136                                    closeSession(session);
4137                            }
4138                    }
4139    
4140                    return list;
4141            }
4142    
4143            public static final FinderPath FINDER_PATH_GET_USERS_SIZE = new FinderPath(com.liferay.portal.model.impl.UserModelImpl.ENTITY_CACHE_ENABLED,
4144                            OrganizationModelImpl.FINDER_CACHE_ENABLED_USERS_ORGS, Long.class,
4145                            OrganizationModelImpl.MAPPING_TABLE_USERS_ORGS_NAME,
4146                            "getUsersSize", new String[] { Long.class.getName() });
4147    
4148            static {
4149                    FINDER_PATH_GET_USERS_SIZE.setCacheKeyGeneratorCacheName(null);
4150            }
4151    
4152            /**
4153             * Returns the number of users associated with the organization.
4154             *
4155             * @param pk the primary key of the organization
4156             * @return the number of users associated with the organization
4157             * @throws SystemException if a system exception occurred
4158             */
4159            public int getUsersSize(long pk) throws SystemException {
4160                    Object[] finderArgs = new Object[] { pk };
4161    
4162                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_USERS_SIZE,
4163                                    finderArgs, this);
4164    
4165                    if (count == null) {
4166                            Session session = null;
4167    
4168                            try {
4169                                    session = openSession();
4170    
4171                                    SQLQuery q = session.createSQLQuery(_SQL_GETUSERSSIZE);
4172    
4173                                    q.addScalar(COUNT_COLUMN_NAME,
4174                                            com.liferay.portal.kernel.dao.orm.Type.LONG);
4175    
4176                                    QueryPos qPos = QueryPos.getInstance(q);
4177    
4178                                    qPos.add(pk);
4179    
4180                                    count = (Long)q.uniqueResult();
4181                            }
4182                            catch (Exception e) {
4183                                    throw processException(e);
4184                            }
4185                            finally {
4186                                    if (count == null) {
4187                                            count = Long.valueOf(0);
4188                                    }
4189    
4190                                    FinderCacheUtil.putResult(FINDER_PATH_GET_USERS_SIZE,
4191                                            finderArgs, count);
4192    
4193                                    closeSession(session);
4194                            }
4195                    }
4196    
4197                    return count.intValue();
4198            }
4199    
4200            public static final FinderPath FINDER_PATH_CONTAINS_USER = new FinderPath(com.liferay.portal.model.impl.UserModelImpl.ENTITY_CACHE_ENABLED,
4201                            OrganizationModelImpl.FINDER_CACHE_ENABLED_USERS_ORGS,
4202                            Boolean.class, OrganizationModelImpl.MAPPING_TABLE_USERS_ORGS_NAME,
4203                            "containsUser",
4204                            new String[] { Long.class.getName(), Long.class.getName() });
4205    
4206            /**
4207             * Returns <code>true</code> if the user is associated with the organization.
4208             *
4209             * @param pk the primary key of the organization
4210             * @param userPK the primary key of the user
4211             * @return <code>true</code> if the user is associated with the organization; <code>false</code> otherwise
4212             * @throws SystemException if a system exception occurred
4213             */
4214            public boolean containsUser(long pk, long userPK) throws SystemException {
4215                    Object[] finderArgs = new Object[] { pk, userPK };
4216    
4217                    Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_USER,
4218                                    finderArgs, this);
4219    
4220                    if (value == null) {
4221                            try {
4222                                    value = Boolean.valueOf(containsUser.contains(pk, userPK));
4223                            }
4224                            catch (Exception e) {
4225                                    throw processException(e);
4226                            }
4227                            finally {
4228                                    if (value == null) {
4229                                            value = Boolean.FALSE;
4230                                    }
4231    
4232                                    FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_USER,
4233                                            finderArgs, value);
4234                            }
4235                    }
4236    
4237                    return value.booleanValue();
4238            }
4239    
4240            /**
4241             * Returns <code>true</code> if the organization has any users associated with it.
4242             *
4243             * @param pk the primary key of the organization to check for associations with users
4244             * @return <code>true</code> if the organization has any users associated with it; <code>false</code> otherwise
4245             * @throws SystemException if a system exception occurred
4246             */
4247            public boolean containsUsers(long pk) throws SystemException {
4248                    if (getUsersSize(pk) > 0) {
4249                            return true;
4250                    }
4251                    else {
4252                            return false;
4253                    }
4254            }
4255    
4256            /**
4257             * Adds an association between the organization and the user. Also notifies the appropriate model listeners and clears the mapping table finder cache.
4258             *
4259             * @param pk the primary key of the organization
4260             * @param userPK the primary key of the user
4261             * @throws SystemException if a system exception occurred
4262             */
4263            public void addUser(long pk, long userPK) throws SystemException {
4264                    try {
4265                            addUser.add(pk, userPK);
4266                    }
4267                    catch (Exception e) {
4268                            throw processException(e);
4269                    }
4270                    finally {
4271                            FinderCacheUtil.clearCache(OrganizationModelImpl.MAPPING_TABLE_USERS_ORGS_NAME);
4272                    }
4273            }
4274    
4275            /**
4276             * Adds an association between the organization and the user. Also notifies the appropriate model listeners and clears the mapping table finder cache.
4277             *
4278             * @param pk the primary key of the organization
4279             * @param user the user
4280             * @throws SystemException if a system exception occurred
4281             */
4282            public void addUser(long pk, com.liferay.portal.model.User user)
4283                    throws SystemException {
4284                    try {
4285                            addUser.add(pk, user.getPrimaryKey());
4286                    }
4287                    catch (Exception e) {
4288                            throw processException(e);
4289                    }
4290                    finally {
4291                            FinderCacheUtil.clearCache(OrganizationModelImpl.MAPPING_TABLE_USERS_ORGS_NAME);
4292                    }
4293            }
4294    
4295            /**
4296             * Adds an association between the organization and the users. Also notifies the appropriate model listeners and clears the mapping table finder cache.
4297             *
4298             * @param pk the primary key of the organization
4299             * @param userPKs the primary keys of the users
4300             * @throws SystemException if a system exception occurred
4301             */
4302            public void addUsers(long pk, long[] userPKs) throws SystemException {
4303                    try {
4304                            for (long userPK : userPKs) {
4305                                    addUser.add(pk, userPK);
4306                            }
4307                    }
4308                    catch (Exception e) {
4309                            throw processException(e);
4310                    }
4311                    finally {
4312                            FinderCacheUtil.clearCache(OrganizationModelImpl.MAPPING_TABLE_USERS_ORGS_NAME);
4313                    }
4314            }
4315    
4316            /**
4317             * Adds an association between the organization and the users. Also notifies the appropriate model listeners and clears the mapping table finder cache.
4318             *
4319             * @param pk the primary key of the organization
4320             * @param users the users
4321             * @throws SystemException if a system exception occurred
4322             */
4323            public void addUsers(long pk, List<com.liferay.portal.model.User> users)
4324                    throws SystemException {
4325                    try {
4326                            for (com.liferay.portal.model.User user : users) {
4327                                    addUser.add(pk, user.getPrimaryKey());
4328                            }
4329                    }
4330                    catch (Exception e) {
4331                            throw processException(e);
4332                    }
4333                    finally {
4334                            FinderCacheUtil.clearCache(OrganizationModelImpl.MAPPING_TABLE_USERS_ORGS_NAME);
4335                    }
4336            }
4337    
4338            /**
4339             * Clears all associations between the organization and its users. Also notifies the appropriate model listeners and clears the mapping table finder cache.
4340             *
4341             * @param pk the primary key of the organization to clear the associated users from
4342             * @throws SystemException if a system exception occurred
4343             */
4344            public void clearUsers(long pk) throws SystemException {
4345                    try {
4346                            clearUsers.clear(pk);
4347                    }
4348                    catch (Exception e) {
4349                            throw processException(e);
4350                    }
4351                    finally {
4352                            FinderCacheUtil.clearCache(OrganizationModelImpl.MAPPING_TABLE_USERS_ORGS_NAME);
4353                    }
4354            }
4355    
4356            /**
4357             * Removes the association between the organization and the user. Also notifies the appropriate model listeners and clears the mapping table finder cache.
4358             *
4359             * @param pk the primary key of the organization
4360             * @param userPK the primary key of the user
4361             * @throws SystemException if a system exception occurred
4362             */
4363            public void removeUser(long pk, long userPK) throws SystemException {
4364                    try {
4365                            removeUser.remove(pk, userPK);
4366                    }
4367                    catch (Exception e) {
4368                            throw processException(e);
4369                    }
4370                    finally {
4371                            FinderCacheUtil.clearCache(OrganizationModelImpl.MAPPING_TABLE_USERS_ORGS_NAME);
4372                    }
4373            }
4374    
4375            /**
4376             * Removes the association between the organization and the user. Also notifies the appropriate model listeners and clears the mapping table finder cache.
4377             *
4378             * @param pk the primary key of the organization
4379             * @param user the user
4380             * @throws SystemException if a system exception occurred
4381             */
4382            public void removeUser(long pk, com.liferay.portal.model.User user)
4383                    throws SystemException {
4384                    try {
4385                            removeUser.remove(pk, user.getPrimaryKey());
4386                    }
4387                    catch (Exception e) {
4388                            throw processException(e);
4389                    }
4390                    finally {
4391                            FinderCacheUtil.clearCache(OrganizationModelImpl.MAPPING_TABLE_USERS_ORGS_NAME);
4392                    }
4393            }
4394    
4395            /**
4396             * Removes the association between the organization and the users. Also notifies the appropriate model listeners and clears the mapping table finder cache.
4397             *
4398             * @param pk the primary key of the organization
4399             * @param userPKs the primary keys of the users
4400             * @throws SystemException if a system exception occurred
4401             */
4402            public void removeUsers(long pk, long[] userPKs) throws SystemException {
4403                    try {
4404                            for (long userPK : userPKs) {
4405                                    removeUser.remove(pk, userPK);
4406                            }
4407                    }
4408                    catch (Exception e) {
4409                            throw processException(e);
4410                    }
4411                    finally {
4412                            FinderCacheUtil.clearCache(OrganizationModelImpl.MAPPING_TABLE_USERS_ORGS_NAME);
4413                    }
4414            }
4415    
4416            /**
4417             * Removes the association between the organization and the users. Also notifies the appropriate model listeners and clears the mapping table finder cache.
4418             *
4419             * @param pk the primary key of the organization
4420             * @param users the users
4421             * @throws SystemException if a system exception occurred
4422             */
4423            public void removeUsers(long pk, List<com.liferay.portal.model.User> users)
4424                    throws SystemException {
4425                    try {
4426                            for (com.liferay.portal.model.User user : users) {
4427                                    removeUser.remove(pk, user.getPrimaryKey());
4428                            }
4429                    }
4430                    catch (Exception e) {
4431                            throw processException(e);
4432                    }
4433                    finally {
4434                            FinderCacheUtil.clearCache(OrganizationModelImpl.MAPPING_TABLE_USERS_ORGS_NAME);
4435                    }
4436            }
4437    
4438            /**
4439             * 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.
4440             *
4441             * @param pk the primary key of the organization
4442             * @param userPKs the primary keys of the users to be associated with the organization
4443             * @throws SystemException if a system exception occurred
4444             */
4445            public void setUsers(long pk, long[] userPKs) throws SystemException {
4446                    try {
4447                            Set<Long> userPKSet = SetUtil.fromArray(userPKs);
4448    
4449                            List<com.liferay.portal.model.User> users = getUsers(pk);
4450    
4451                            for (com.liferay.portal.model.User user : users) {
4452                                    if (!userPKSet.remove(user.getPrimaryKey())) {
4453                                            removeUser.remove(pk, user.getPrimaryKey());
4454                                    }
4455                            }
4456    
4457                            for (Long userPK : userPKSet) {
4458                                    addUser.add(pk, userPK);
4459                            }
4460                    }
4461                    catch (Exception e) {
4462                            throw processException(e);
4463                    }
4464                    finally {
4465                            FinderCacheUtil.clearCache(OrganizationModelImpl.MAPPING_TABLE_USERS_ORGS_NAME);
4466                    }
4467            }
4468    
4469            /**
4470             * 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.
4471             *
4472             * @param pk the primary key of the organization
4473             * @param users the users to be associated with the organization
4474             * @throws SystemException if a system exception occurred
4475             */
4476            public void setUsers(long pk, List<com.liferay.portal.model.User> users)
4477                    throws SystemException {
4478                    try {
4479                            long[] userPKs = new long[users.size()];
4480    
4481                            for (int i = 0; i < users.size(); i++) {
4482                                    com.liferay.portal.model.User user = users.get(i);
4483    
4484                                    userPKs[i] = user.getPrimaryKey();
4485                            }
4486    
4487                            setUsers(pk, userPKs);
4488                    }
4489                    catch (Exception e) {
4490                            throw processException(e);
4491                    }
4492                    finally {
4493                            FinderCacheUtil.clearCache(OrganizationModelImpl.MAPPING_TABLE_USERS_ORGS_NAME);
4494                    }
4495            }
4496    
4497            /**
4498             * Initializes the organization persistence.
4499             */
4500            public void afterPropertiesSet() {
4501                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
4502                                            com.liferay.portal.util.PropsUtil.get(
4503                                                    "value.object.listener.com.liferay.portal.model.Organization")));
4504    
4505                    if (listenerClassNames.length > 0) {
4506                            try {
4507                                    List<ModelListener<Organization>> listenersList = new ArrayList<ModelListener<Organization>>();
4508    
4509                                    for (String listenerClassName : listenerClassNames) {
4510                                            Class<?> clazz = getClass();
4511    
4512                                            listenersList.add((ModelListener<Organization>)InstanceFactory.newInstance(
4513                                                            clazz.getClassLoader(), listenerClassName));
4514                                    }
4515    
4516                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
4517                            }
4518                            catch (Exception e) {
4519                                    _log.error(e);
4520                            }
4521                    }
4522    
4523                    containsGroup = new ContainsGroup();
4524    
4525                    addGroup = new AddGroup();
4526                    clearGroups = new ClearGroups();
4527                    removeGroup = new RemoveGroup();
4528    
4529                    containsUser = new ContainsUser();
4530    
4531                    addUser = new AddUser();
4532                    clearUsers = new ClearUsers();
4533                    removeUser = new RemoveUser();
4534            }
4535    
4536            public void destroy() {
4537                    EntityCacheUtil.removeCache(OrganizationImpl.class.getName());
4538                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
4539                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
4540            }
4541    
4542            @BeanReference(type = AccountPersistence.class)
4543            protected AccountPersistence accountPersistence;
4544            @BeanReference(type = AddressPersistence.class)
4545            protected AddressPersistence addressPersistence;
4546            @BeanReference(type = BrowserTrackerPersistence.class)
4547            protected BrowserTrackerPersistence browserTrackerPersistence;
4548            @BeanReference(type = ClassNamePersistence.class)
4549            protected ClassNamePersistence classNamePersistence;
4550            @BeanReference(type = ClusterGroupPersistence.class)
4551            protected ClusterGroupPersistence clusterGroupPersistence;
4552            @BeanReference(type = CompanyPersistence.class)
4553            protected CompanyPersistence companyPersistence;
4554            @BeanReference(type = ContactPersistence.class)
4555            protected ContactPersistence contactPersistence;
4556            @BeanReference(type = CountryPersistence.class)
4557            protected CountryPersistence countryPersistence;
4558            @BeanReference(type = EmailAddressPersistence.class)
4559            protected EmailAddressPersistence emailAddressPersistence;
4560            @BeanReference(type = GroupPersistence.class)
4561            protected GroupPersistence groupPersistence;
4562            @BeanReference(type = ImagePersistence.class)
4563            protected ImagePersistence imagePersistence;
4564            @BeanReference(type = LayoutPersistence.class)
4565            protected LayoutPersistence layoutPersistence;
4566            @BeanReference(type = LayoutBranchPersistence.class)
4567            protected LayoutBranchPersistence layoutBranchPersistence;
4568            @BeanReference(type = LayoutPrototypePersistence.class)
4569            protected LayoutPrototypePersistence layoutPrototypePersistence;
4570            @BeanReference(type = LayoutRevisionPersistence.class)
4571            protected LayoutRevisionPersistence layoutRevisionPersistence;
4572            @BeanReference(type = LayoutSetPersistence.class)
4573            protected LayoutSetPersistence layoutSetPersistence;
4574            @BeanReference(type = LayoutSetBranchPersistence.class)
4575            protected LayoutSetBranchPersistence layoutSetBranchPersistence;
4576            @BeanReference(type = LayoutSetPrototypePersistence.class)
4577            protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
4578            @BeanReference(type = ListTypePersistence.class)
4579            protected ListTypePersistence listTypePersistence;
4580            @BeanReference(type = LockPersistence.class)
4581            protected LockPersistence lockPersistence;
4582            @BeanReference(type = MembershipRequestPersistence.class)
4583            protected MembershipRequestPersistence membershipRequestPersistence;
4584            @BeanReference(type = OrganizationPersistence.class)
4585            protected OrganizationPersistence organizationPersistence;
4586            @BeanReference(type = OrgGroupPermissionPersistence.class)
4587            protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
4588            @BeanReference(type = OrgGroupRolePersistence.class)
4589            protected OrgGroupRolePersistence orgGroupRolePersistence;
4590            @BeanReference(type = OrgLaborPersistence.class)
4591            protected OrgLaborPersistence orgLaborPersistence;
4592            @BeanReference(type = PasswordPolicyPersistence.class)
4593            protected PasswordPolicyPersistence passwordPolicyPersistence;
4594            @BeanReference(type = PasswordPolicyRelPersistence.class)
4595            protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
4596            @BeanReference(type = PasswordTrackerPersistence.class)
4597            protected PasswordTrackerPersistence passwordTrackerPersistence;
4598            @BeanReference(type = PermissionPersistence.class)
4599            protected PermissionPersistence permissionPersistence;
4600            @BeanReference(type = PhonePersistence.class)
4601            protected PhonePersistence phonePersistence;
4602            @BeanReference(type = PluginSettingPersistence.class)
4603            protected PluginSettingPersistence pluginSettingPersistence;
4604            @BeanReference(type = PortalPreferencesPersistence.class)
4605            protected PortalPreferencesPersistence portalPreferencesPersistence;
4606            @BeanReference(type = PortletPersistence.class)
4607            protected PortletPersistence portletPersistence;
4608            @BeanReference(type = PortletItemPersistence.class)
4609            protected PortletItemPersistence portletItemPersistence;
4610            @BeanReference(type = PortletPreferencesPersistence.class)
4611            protected PortletPreferencesPersistence portletPreferencesPersistence;
4612            @BeanReference(type = RegionPersistence.class)
4613            protected RegionPersistence regionPersistence;
4614            @BeanReference(type = ReleasePersistence.class)
4615            protected ReleasePersistence releasePersistence;
4616            @BeanReference(type = RepositoryPersistence.class)
4617            protected RepositoryPersistence repositoryPersistence;
4618            @BeanReference(type = RepositoryEntryPersistence.class)
4619            protected RepositoryEntryPersistence repositoryEntryPersistence;
4620            @BeanReference(type = ResourcePersistence.class)
4621            protected ResourcePersistence resourcePersistence;
4622            @BeanReference(type = ResourceActionPersistence.class)
4623            protected ResourceActionPersistence resourceActionPersistence;
4624            @BeanReference(type = ResourceBlockPersistence.class)
4625            protected ResourceBlockPersistence resourceBlockPersistence;
4626            @BeanReference(type = ResourceBlockPermissionPersistence.class)
4627            protected ResourceBlockPermissionPersistence resourceBlockPermissionPersistence;
4628            @BeanReference(type = ResourceCodePersistence.class)
4629            protected ResourceCodePersistence resourceCodePersistence;
4630            @BeanReference(type = ResourcePermissionPersistence.class)
4631            protected ResourcePermissionPersistence resourcePermissionPersistence;
4632            @BeanReference(type = ResourceTypePermissionPersistence.class)
4633            protected ResourceTypePermissionPersistence resourceTypePermissionPersistence;
4634            @BeanReference(type = RolePersistence.class)
4635            protected RolePersistence rolePersistence;
4636            @BeanReference(type = ServiceComponentPersistence.class)
4637            protected ServiceComponentPersistence serviceComponentPersistence;
4638            @BeanReference(type = ShardPersistence.class)
4639            protected ShardPersistence shardPersistence;
4640            @BeanReference(type = SubscriptionPersistence.class)
4641            protected SubscriptionPersistence subscriptionPersistence;
4642            @BeanReference(type = TeamPersistence.class)
4643            protected TeamPersistence teamPersistence;
4644            @BeanReference(type = TicketPersistence.class)
4645            protected TicketPersistence ticketPersistence;
4646            @BeanReference(type = UserPersistence.class)
4647            protected UserPersistence userPersistence;
4648            @BeanReference(type = UserGroupPersistence.class)
4649            protected UserGroupPersistence userGroupPersistence;
4650            @BeanReference(type = UserGroupGroupRolePersistence.class)
4651            protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
4652            @BeanReference(type = UserGroupRolePersistence.class)
4653            protected UserGroupRolePersistence userGroupRolePersistence;
4654            @BeanReference(type = UserIdMapperPersistence.class)
4655            protected UserIdMapperPersistence userIdMapperPersistence;
4656            @BeanReference(type = UserNotificationEventPersistence.class)
4657            protected UserNotificationEventPersistence userNotificationEventPersistence;
4658            @BeanReference(type = UserTrackerPersistence.class)
4659            protected UserTrackerPersistence userTrackerPersistence;
4660            @BeanReference(type = UserTrackerPathPersistence.class)
4661            protected UserTrackerPathPersistence userTrackerPathPersistence;
4662            @BeanReference(type = VirtualHostPersistence.class)
4663            protected VirtualHostPersistence virtualHostPersistence;
4664            @BeanReference(type = WebDAVPropsPersistence.class)
4665            protected WebDAVPropsPersistence webDAVPropsPersistence;
4666            @BeanReference(type = WebsitePersistence.class)
4667            protected WebsitePersistence websitePersistence;
4668            @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
4669            protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
4670            @BeanReference(type = WorkflowInstanceLinkPersistence.class)
4671            protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
4672            @BeanReference(type = AssetEntryPersistence.class)
4673            protected AssetEntryPersistence assetEntryPersistence;
4674            @BeanReference(type = ExpandoValuePersistence.class)
4675            protected ExpandoValuePersistence expandoValuePersistence;
4676            protected ContainsGroup containsGroup;
4677            protected AddGroup addGroup;
4678            protected ClearGroups clearGroups;
4679            protected RemoveGroup removeGroup;
4680            protected ContainsUser containsUser;
4681            protected AddUser addUser;
4682            protected ClearUsers clearUsers;
4683            protected RemoveUser removeUser;
4684    
4685            protected class ContainsGroup {
4686                    protected ContainsGroup() {
4687                            _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
4688                                            _SQL_CONTAINSGROUP,
4689                                            new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT },
4690                                            RowMapper.COUNT);
4691                    }
4692    
4693                    protected boolean contains(long organizationId, long groupId) {
4694                            List<Integer> results = _mappingSqlQuery.execute(new Object[] {
4695                                                    new Long(organizationId), new Long(groupId)
4696                                            });
4697    
4698                            if (results.size() > 0) {
4699                                    Integer count = results.get(0);
4700    
4701                                    if (count.intValue() > 0) {
4702                                            return true;
4703                                    }
4704                            }
4705    
4706                            return false;
4707                    }
4708    
4709                    private MappingSqlQuery<Integer> _mappingSqlQuery;
4710            }
4711    
4712            protected class AddGroup {
4713                    protected AddGroup() {
4714                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
4715                                            "INSERT INTO Groups_Orgs (organizationId, groupId) VALUES (?, ?)",
4716                                            new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
4717                    }
4718    
4719                    protected void add(long organizationId, long groupId)
4720                            throws SystemException {
4721                            if (!containsGroup.contains(organizationId, groupId)) {
4722                                    ModelListener<com.liferay.portal.model.Group>[] groupListeners = groupPersistence.getListeners();
4723    
4724                                    for (ModelListener<Organization> listener : listeners) {
4725                                            listener.onBeforeAddAssociation(organizationId,
4726                                                    com.liferay.portal.model.Group.class.getName(), groupId);
4727                                    }
4728    
4729                                    for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
4730                                            listener.onBeforeAddAssociation(groupId,
4731                                                    Organization.class.getName(), organizationId);
4732                                    }
4733    
4734                                    _sqlUpdate.update(new Object[] {
4735                                                    new Long(organizationId), new Long(groupId)
4736                                            });
4737    
4738                                    for (ModelListener<Organization> listener : listeners) {
4739                                            listener.onAfterAddAssociation(organizationId,
4740                                                    com.liferay.portal.model.Group.class.getName(), groupId);
4741                                    }
4742    
4743                                    for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
4744                                            listener.onAfterAddAssociation(groupId,
4745                                                    Organization.class.getName(), organizationId);
4746                                    }
4747                            }
4748                    }
4749    
4750                    private SqlUpdate _sqlUpdate;
4751            }
4752    
4753            protected class ClearGroups {
4754                    protected ClearGroups() {
4755                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
4756                                            "DELETE FROM Groups_Orgs WHERE organizationId = ?",
4757                                            new int[] { java.sql.Types.BIGINT });
4758                    }
4759    
4760                    protected void clear(long organizationId) throws SystemException {
4761                            ModelListener<com.liferay.portal.model.Group>[] groupListeners = groupPersistence.getListeners();
4762    
4763                            List<com.liferay.portal.model.Group> groups = null;
4764    
4765                            if ((listeners.length > 0) || (groupListeners.length > 0)) {
4766                                    groups = getGroups(organizationId);
4767    
4768                                    for (com.liferay.portal.model.Group group : groups) {
4769                                            for (ModelListener<Organization> listener : listeners) {
4770                                                    listener.onBeforeRemoveAssociation(organizationId,
4771                                                            com.liferay.portal.model.Group.class.getName(),
4772                                                            group.getPrimaryKey());
4773                                            }
4774    
4775                                            for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
4776                                                    listener.onBeforeRemoveAssociation(group.getPrimaryKey(),
4777                                                            Organization.class.getName(), organizationId);
4778                                            }
4779                                    }
4780                            }
4781    
4782                            _sqlUpdate.update(new Object[] { new Long(organizationId) });
4783    
4784                            if ((listeners.length > 0) || (groupListeners.length > 0)) {
4785                                    for (com.liferay.portal.model.Group group : groups) {
4786                                            for (ModelListener<Organization> listener : listeners) {
4787                                                    listener.onAfterRemoveAssociation(organizationId,
4788                                                            com.liferay.portal.model.Group.class.getName(),
4789                                                            group.getPrimaryKey());
4790                                            }
4791    
4792                                            for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
4793                                                    listener.onAfterRemoveAssociation(group.getPrimaryKey(),
4794                                                            Organization.class.getName(), organizationId);
4795                                            }
4796                                    }
4797                            }
4798                    }
4799    
4800                    private SqlUpdate _sqlUpdate;
4801            }
4802    
4803            protected class RemoveGroup {
4804                    protected RemoveGroup() {
4805                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
4806                                            "DELETE FROM Groups_Orgs WHERE organizationId = ? AND groupId = ?",
4807                                            new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
4808                    }
4809    
4810                    protected void remove(long organizationId, long groupId)
4811                            throws SystemException {
4812                            if (containsGroup.contains(organizationId, groupId)) {
4813                                    ModelListener<com.liferay.portal.model.Group>[] groupListeners = groupPersistence.getListeners();
4814    
4815                                    for (ModelListener<Organization> listener : listeners) {
4816                                            listener.onBeforeRemoveAssociation(organizationId,
4817                                                    com.liferay.portal.model.Group.class.getName(), groupId);
4818                                    }
4819    
4820                                    for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
4821                                            listener.onBeforeRemoveAssociation(groupId,
4822                                                    Organization.class.getName(), organizationId);
4823                                    }
4824    
4825                                    _sqlUpdate.update(new Object[] {
4826                                                    new Long(organizationId), new Long(groupId)
4827                                            });
4828    
4829                                    for (ModelListener<Organization> listener : listeners) {
4830                                            listener.onAfterRemoveAssociation(organizationId,
4831                                                    com.liferay.portal.model.Group.class.getName(), groupId);
4832                                    }
4833    
4834                                    for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
4835                                            listener.onAfterRemoveAssociation(groupId,
4836                                                    Organization.class.getName(), organizationId);
4837                                    }
4838                            }
4839                    }
4840    
4841                    private SqlUpdate _sqlUpdate;
4842            }
4843    
4844            protected class ContainsUser {
4845                    protected ContainsUser() {
4846                            _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
4847                                            _SQL_CONTAINSUSER,
4848                                            new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT },
4849                                            RowMapper.COUNT);
4850                    }
4851    
4852                    protected boolean contains(long organizationId, long userId) {
4853                            List<Integer> results = _mappingSqlQuery.execute(new Object[] {
4854                                                    new Long(organizationId), new Long(userId)
4855                                            });
4856    
4857                            if (results.size() > 0) {
4858                                    Integer count = results.get(0);
4859    
4860                                    if (count.intValue() > 0) {
4861                                            return true;
4862                                    }
4863                            }
4864    
4865                            return false;
4866                    }
4867    
4868                    private MappingSqlQuery<Integer> _mappingSqlQuery;
4869            }
4870    
4871            protected class AddUser {
4872                    protected AddUser() {
4873                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
4874                                            "INSERT INTO Users_Orgs (organizationId, userId) VALUES (?, ?)",
4875                                            new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
4876                    }
4877    
4878                    protected void add(long organizationId, long userId)
4879                            throws SystemException {
4880                            if (!containsUser.contains(organizationId, userId)) {
4881                                    ModelListener<com.liferay.portal.model.User>[] userListeners = userPersistence.getListeners();
4882    
4883                                    for (ModelListener<Organization> listener : listeners) {
4884                                            listener.onBeforeAddAssociation(organizationId,
4885                                                    com.liferay.portal.model.User.class.getName(), userId);
4886                                    }
4887    
4888                                    for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
4889                                            listener.onBeforeAddAssociation(userId,
4890                                                    Organization.class.getName(), organizationId);
4891                                    }
4892    
4893                                    _sqlUpdate.update(new Object[] {
4894                                                    new Long(organizationId), new Long(userId)
4895                                            });
4896    
4897                                    for (ModelListener<Organization> listener : listeners) {
4898                                            listener.onAfterAddAssociation(organizationId,
4899                                                    com.liferay.portal.model.User.class.getName(), userId);
4900                                    }
4901    
4902                                    for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
4903                                            listener.onAfterAddAssociation(userId,
4904                                                    Organization.class.getName(), organizationId);
4905                                    }
4906                            }
4907                    }
4908    
4909                    private SqlUpdate _sqlUpdate;
4910            }
4911    
4912            protected class ClearUsers {
4913                    protected ClearUsers() {
4914                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
4915                                            "DELETE FROM Users_Orgs WHERE organizationId = ?",
4916                                            new int[] { java.sql.Types.BIGINT });
4917                    }
4918    
4919                    protected void clear(long organizationId) throws SystemException {
4920                            ModelListener<com.liferay.portal.model.User>[] userListeners = userPersistence.getListeners();
4921    
4922                            List<com.liferay.portal.model.User> users = null;
4923    
4924                            if ((listeners.length > 0) || (userListeners.length > 0)) {
4925                                    users = getUsers(organizationId);
4926    
4927                                    for (com.liferay.portal.model.User user : users) {
4928                                            for (ModelListener<Organization> listener : listeners) {
4929                                                    listener.onBeforeRemoveAssociation(organizationId,
4930                                                            com.liferay.portal.model.User.class.getName(),
4931                                                            user.getPrimaryKey());
4932                                            }
4933    
4934                                            for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
4935                                                    listener.onBeforeRemoveAssociation(user.getPrimaryKey(),
4936                                                            Organization.class.getName(), organizationId);
4937                                            }
4938                                    }
4939                            }
4940    
4941                            _sqlUpdate.update(new Object[] { new Long(organizationId) });
4942    
4943                            if ((listeners.length > 0) || (userListeners.length > 0)) {
4944                                    for (com.liferay.portal.model.User user : users) {
4945                                            for (ModelListener<Organization> listener : listeners) {
4946                                                    listener.onAfterRemoveAssociation(organizationId,
4947                                                            com.liferay.portal.model.User.class.getName(),
4948                                                            user.getPrimaryKey());
4949                                            }
4950    
4951                                            for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
4952                                                    listener.onAfterRemoveAssociation(user.getPrimaryKey(),
4953                                                            Organization.class.getName(), organizationId);
4954                                            }
4955                                    }
4956                            }
4957                    }
4958    
4959                    private SqlUpdate _sqlUpdate;
4960            }
4961    
4962            protected class RemoveUser {
4963                    protected RemoveUser() {
4964                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
4965                                            "DELETE FROM Users_Orgs WHERE organizationId = ? AND userId = ?",
4966                                            new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
4967                    }
4968    
4969                    protected void remove(long organizationId, long userId)
4970                            throws SystemException {
4971                            if (containsUser.contains(organizationId, userId)) {
4972                                    ModelListener<com.liferay.portal.model.User>[] userListeners = userPersistence.getListeners();
4973    
4974                                    for (ModelListener<Organization> listener : listeners) {
4975                                            listener.onBeforeRemoveAssociation(organizationId,
4976                                                    com.liferay.portal.model.User.class.getName(), userId);
4977                                    }
4978    
4979                                    for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
4980                                            listener.onBeforeRemoveAssociation(userId,
4981                                                    Organization.class.getName(), organizationId);
4982                                    }
4983    
4984                                    _sqlUpdate.update(new Object[] {
4985                                                    new Long(organizationId), new Long(userId)
4986                                            });
4987    
4988                                    for (ModelListener<Organization> listener : listeners) {
4989                                            listener.onAfterRemoveAssociation(organizationId,
4990                                                    com.liferay.portal.model.User.class.getName(), userId);
4991                                    }
4992    
4993                                    for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
4994                                            listener.onAfterRemoveAssociation(userId,
4995                                                    Organization.class.getName(), organizationId);
4996                                    }
4997                            }
4998                    }
4999    
5000                    private SqlUpdate _sqlUpdate;
5001            }
5002    
5003            private static final String _SQL_SELECT_ORGANIZATION = "SELECT organization FROM Organization organization";
5004            private static final String _SQL_SELECT_ORGANIZATION_WHERE = "SELECT organization FROM Organization organization WHERE ";
5005            private static final String _SQL_COUNT_ORGANIZATION = "SELECT COUNT(organization) FROM Organization organization";
5006            private static final String _SQL_COUNT_ORGANIZATION_WHERE = "SELECT COUNT(organization) FROM Organization organization WHERE ";
5007            private static final String _SQL_GETGROUPS = "SELECT {Group_.*} FROM Group_ INNER JOIN Groups_Orgs ON (Groups_Orgs.groupId = Group_.groupId) WHERE (Groups_Orgs.organizationId = ?)";
5008            private static final String _SQL_GETGROUPSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM Groups_Orgs WHERE organizationId = ?";
5009            private static final String _SQL_CONTAINSGROUP = "SELECT COUNT(*) AS COUNT_VALUE FROM Groups_Orgs WHERE organizationId = ? AND groupId = ?";
5010            private static final String _SQL_GETUSERS = "SELECT {User_.*} FROM User_ INNER JOIN Users_Orgs ON (Users_Orgs.userId = User_.userId) WHERE (Users_Orgs.organizationId = ?)";
5011            private static final String _SQL_GETUSERSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM Users_Orgs WHERE organizationId = ?";
5012            private static final String _SQL_CONTAINSUSER = "SELECT COUNT(*) AS COUNT_VALUE FROM Users_Orgs WHERE organizationId = ? AND userId = ?";
5013            private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "organization.companyId = ?";
5014            private static final String _FINDER_COLUMN_LOCATIONS_COMPANYID_2 = "organization.companyId = ? AND organization.parentOrganizationId != 0";
5015            private static final String _FINDER_COLUMN_C_P_COMPANYID_2 = "organization.companyId = ? AND ";
5016            private static final String _FINDER_COLUMN_C_P_PARENTORGANIZATIONID_2 = "organization.parentOrganizationId = ?";
5017            private static final String _FINDER_COLUMN_C_N_COMPANYID_2 = "organization.companyId = ? AND ";
5018            private static final String _FINDER_COLUMN_C_N_NAME_1 = "organization.name IS NULL";
5019            private static final String _FINDER_COLUMN_C_N_NAME_2 = "organization.name = ?";
5020            private static final String _FINDER_COLUMN_C_N_NAME_3 = "(organization.name IS NULL OR organization.name = ?)";
5021            private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "organization.organizationId";
5022            private static final String _FILTER_SQL_SELECT_ORGANIZATION_WHERE = "SELECT DISTINCT {organization.*} FROM Organization_ organization WHERE ";
5023            private static final String _FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_1 =
5024                    "SELECT {Organization_.*} FROM (SELECT DISTINCT organization.organizationId FROM Organization_ organization WHERE ";
5025            private static final String _FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_2 =
5026                    ") TEMP_TABLE INNER JOIN Organization_ ON TEMP_TABLE.organizationId = Organization_.organizationId";
5027            private static final String _FILTER_SQL_COUNT_ORGANIZATION_WHERE = "SELECT COUNT(DISTINCT organization.organizationId) AS COUNT_VALUE FROM Organization_ organization WHERE ";
5028            private static final String _FILTER_ENTITY_ALIAS = "organization";
5029            private static final String _FILTER_ENTITY_TABLE = "Organization_";
5030            private static final String _ORDER_BY_ENTITY_ALIAS = "organization.";
5031            private static final String _ORDER_BY_ENTITY_TABLE = "Organization_.";
5032            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Organization exists with the primary key ";
5033            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Organization exists with the key {";
5034            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
5035            private static Log _log = LogFactoryUtil.getLog(OrganizationPersistenceImpl.class);
5036            private static Organization _nullOrganization = new OrganizationImpl() {
5037                            @Override
5038                            public Object clone() {
5039                                    return this;
5040                            }
5041    
5042                            @Override
5043                            public CacheModel<Organization> toCacheModel() {
5044                                    return _nullOrganizationCacheModel;
5045                            }
5046                    };
5047    
5048            private static CacheModel<Organization> _nullOrganizationCacheModel = new CacheModel<Organization>() {
5049                            public Organization toEntityModel() {
5050                                    return _nullOrganization;
5051                            }
5052                    };
5053    }