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