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