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