001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.service.persistence.impl;
016    
017    import aQute.bnd.annotation.ProviderType;
018    
019    import com.liferay.portal.exception.NoSuchCompanyException;
020    import com.liferay.portal.kernel.dao.orm.EntityCache;
021    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderCache;
023    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
024    import com.liferay.portal.kernel.dao.orm.FinderPath;
025    import com.liferay.portal.kernel.dao.orm.Query;
026    import com.liferay.portal.kernel.dao.orm.QueryPos;
027    import com.liferay.portal.kernel.dao.orm.QueryUtil;
028    import com.liferay.portal.kernel.dao.orm.Session;
029    import com.liferay.portal.kernel.log.Log;
030    import com.liferay.portal.kernel.log.LogFactoryUtil;
031    import com.liferay.portal.kernel.util.OrderByComparator;
032    import com.liferay.portal.kernel.util.SetUtil;
033    import com.liferay.portal.kernel.util.StringBundler;
034    import com.liferay.portal.kernel.util.StringPool;
035    import com.liferay.portal.kernel.util.StringUtil;
036    import com.liferay.portal.kernel.util.Validator;
037    import com.liferay.portal.model.CacheModel;
038    import com.liferay.portal.model.Company;
039    import com.liferay.portal.model.MVCCModel;
040    import com.liferay.portal.model.impl.CompanyImpl;
041    import com.liferay.portal.model.impl.CompanyModelImpl;
042    import com.liferay.portal.service.persistence.CompanyPersistence;
043    
044    import java.io.Serializable;
045    
046    import java.util.Collections;
047    import java.util.HashMap;
048    import java.util.HashSet;
049    import java.util.Iterator;
050    import java.util.List;
051    import java.util.Map;
052    import java.util.Set;
053    
054    /**
055     * The persistence implementation for the company service.
056     *
057     * <p>
058     * Caching information and settings can be found in <code>portal.properties</code>
059     * </p>
060     *
061     * @author Brian Wing Shun Chan
062     * @see CompanyPersistence
063     * @see com.liferay.portal.service.persistence.CompanyUtil
064     * @generated
065     */
066    @ProviderType
067    public class CompanyPersistenceImpl extends BasePersistenceImpl<Company>
068            implements CompanyPersistence {
069            /*
070             * NOTE FOR DEVELOPERS:
071             *
072             * Never modify or reference this class directly. Always use {@link CompanyUtil} to access the company persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
073             */
074            public static final String FINDER_CLASS_NAME_ENTITY = CompanyImpl.class.getName();
075            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
076                    ".List1";
077            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
078                    ".List2";
079            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(CompanyModelImpl.ENTITY_CACHE_ENABLED,
080                            CompanyModelImpl.FINDER_CACHE_ENABLED, CompanyImpl.class,
081                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
082            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(CompanyModelImpl.ENTITY_CACHE_ENABLED,
083                            CompanyModelImpl.FINDER_CACHE_ENABLED, CompanyImpl.class,
084                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
085            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(CompanyModelImpl.ENTITY_CACHE_ENABLED,
086                            CompanyModelImpl.FINDER_CACHE_ENABLED, Long.class,
087                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
088            public static final FinderPath FINDER_PATH_FETCH_BY_WEBID = new FinderPath(CompanyModelImpl.ENTITY_CACHE_ENABLED,
089                            CompanyModelImpl.FINDER_CACHE_ENABLED, CompanyImpl.class,
090                            FINDER_CLASS_NAME_ENTITY, "fetchByWebId",
091                            new String[] { String.class.getName() },
092                            CompanyModelImpl.WEBID_COLUMN_BITMASK);
093            public static final FinderPath FINDER_PATH_COUNT_BY_WEBID = new FinderPath(CompanyModelImpl.ENTITY_CACHE_ENABLED,
094                            CompanyModelImpl.FINDER_CACHE_ENABLED, Long.class,
095                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByWebId",
096                            new String[] { String.class.getName() });
097    
098            /**
099             * Returns the company where webId = &#63; or throws a {@link NoSuchCompanyException} if it could not be found.
100             *
101             * @param webId the web ID
102             * @return the matching company
103             * @throws NoSuchCompanyException if a matching company could not be found
104             */
105            @Override
106            public Company findByWebId(String webId) throws NoSuchCompanyException {
107                    Company company = fetchByWebId(webId);
108    
109                    if (company == null) {
110                            StringBundler msg = new StringBundler(4);
111    
112                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
113    
114                            msg.append("webId=");
115                            msg.append(webId);
116    
117                            msg.append(StringPool.CLOSE_CURLY_BRACE);
118    
119                            if (_log.isWarnEnabled()) {
120                                    _log.warn(msg.toString());
121                            }
122    
123                            throw new NoSuchCompanyException(msg.toString());
124                    }
125    
126                    return company;
127            }
128    
129            /**
130             * Returns the company where webId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
131             *
132             * @param webId the web ID
133             * @return the matching company, or <code>null</code> if a matching company could not be found
134             */
135            @Override
136            public Company fetchByWebId(String webId) {
137                    return fetchByWebId(webId, true);
138            }
139    
140            /**
141             * Returns the company where webId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
142             *
143             * @param webId the web ID
144             * @param retrieveFromCache whether to retrieve from the finder cache
145             * @return the matching company, or <code>null</code> if a matching company could not be found
146             */
147            @Override
148            public Company fetchByWebId(String webId, boolean retrieveFromCache) {
149                    Object[] finderArgs = new Object[] { webId };
150    
151                    Object result = null;
152    
153                    if (retrieveFromCache) {
154                            result = finderCache.getResult(FINDER_PATH_FETCH_BY_WEBID,
155                                            finderArgs, this);
156                    }
157    
158                    if (result instanceof Company) {
159                            Company company = (Company)result;
160    
161                            if (!Validator.equals(webId, company.getWebId())) {
162                                    result = null;
163                            }
164                    }
165    
166                    if (result == null) {
167                            StringBundler query = new StringBundler(3);
168    
169                            query.append(_SQL_SELECT_COMPANY_WHERE);
170    
171                            boolean bindWebId = false;
172    
173                            if (webId == null) {
174                                    query.append(_FINDER_COLUMN_WEBID_WEBID_1);
175                            }
176                            else if (webId.equals(StringPool.BLANK)) {
177                                    query.append(_FINDER_COLUMN_WEBID_WEBID_3);
178                            }
179                            else {
180                                    bindWebId = true;
181    
182                                    query.append(_FINDER_COLUMN_WEBID_WEBID_2);
183                            }
184    
185                            String sql = query.toString();
186    
187                            Session session = null;
188    
189                            try {
190                                    session = openSession();
191    
192                                    Query q = session.createQuery(sql);
193    
194                                    QueryPos qPos = QueryPos.getInstance(q);
195    
196                                    if (bindWebId) {
197                                            qPos.add(webId);
198                                    }
199    
200                                    List<Company> list = q.list();
201    
202                                    if (list.isEmpty()) {
203                                            finderCache.putResult(FINDER_PATH_FETCH_BY_WEBID,
204                                                    finderArgs, list);
205                                    }
206                                    else {
207                                            Company company = list.get(0);
208    
209                                            result = company;
210    
211                                            cacheResult(company);
212    
213                                            if ((company.getWebId() == null) ||
214                                                            !company.getWebId().equals(webId)) {
215                                                    finderCache.putResult(FINDER_PATH_FETCH_BY_WEBID,
216                                                            finderArgs, company);
217                                            }
218                                    }
219                            }
220                            catch (Exception e) {
221                                    finderCache.removeResult(FINDER_PATH_FETCH_BY_WEBID, finderArgs);
222    
223                                    throw processException(e);
224                            }
225                            finally {
226                                    closeSession(session);
227                            }
228                    }
229    
230                    if (result instanceof List<?>) {
231                            return null;
232                    }
233                    else {
234                            return (Company)result;
235                    }
236            }
237    
238            /**
239             * Removes the company where webId = &#63; from the database.
240             *
241             * @param webId the web ID
242             * @return the company that was removed
243             */
244            @Override
245            public Company removeByWebId(String webId) throws NoSuchCompanyException {
246                    Company company = findByWebId(webId);
247    
248                    return remove(company);
249            }
250    
251            /**
252             * Returns the number of companies where webId = &#63;.
253             *
254             * @param webId the web ID
255             * @return the number of matching companies
256             */
257            @Override
258            public int countByWebId(String webId) {
259                    FinderPath finderPath = FINDER_PATH_COUNT_BY_WEBID;
260    
261                    Object[] finderArgs = new Object[] { webId };
262    
263                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
264    
265                    if (count == null) {
266                            StringBundler query = new StringBundler(2);
267    
268                            query.append(_SQL_COUNT_COMPANY_WHERE);
269    
270                            boolean bindWebId = false;
271    
272                            if (webId == null) {
273                                    query.append(_FINDER_COLUMN_WEBID_WEBID_1);
274                            }
275                            else if (webId.equals(StringPool.BLANK)) {
276                                    query.append(_FINDER_COLUMN_WEBID_WEBID_3);
277                            }
278                            else {
279                                    bindWebId = true;
280    
281                                    query.append(_FINDER_COLUMN_WEBID_WEBID_2);
282                            }
283    
284                            String sql = query.toString();
285    
286                            Session session = null;
287    
288                            try {
289                                    session = openSession();
290    
291                                    Query q = session.createQuery(sql);
292    
293                                    QueryPos qPos = QueryPos.getInstance(q);
294    
295                                    if (bindWebId) {
296                                            qPos.add(webId);
297                                    }
298    
299                                    count = (Long)q.uniqueResult();
300    
301                                    finderCache.putResult(finderPath, finderArgs, count);
302                            }
303                            catch (Exception e) {
304                                    finderCache.removeResult(finderPath, finderArgs);
305    
306                                    throw processException(e);
307                            }
308                            finally {
309                                    closeSession(session);
310                            }
311                    }
312    
313                    return count.intValue();
314            }
315    
316            private static final String _FINDER_COLUMN_WEBID_WEBID_1 = "company.webId IS NULL";
317            private static final String _FINDER_COLUMN_WEBID_WEBID_2 = "company.webId = ?";
318            private static final String _FINDER_COLUMN_WEBID_WEBID_3 = "(company.webId IS NULL OR company.webId = '')";
319            public static final FinderPath FINDER_PATH_FETCH_BY_MX = new FinderPath(CompanyModelImpl.ENTITY_CACHE_ENABLED,
320                            CompanyModelImpl.FINDER_CACHE_ENABLED, CompanyImpl.class,
321                            FINDER_CLASS_NAME_ENTITY, "fetchByMx",
322                            new String[] { String.class.getName() },
323                            CompanyModelImpl.MX_COLUMN_BITMASK);
324            public static final FinderPath FINDER_PATH_COUNT_BY_MX = new FinderPath(CompanyModelImpl.ENTITY_CACHE_ENABLED,
325                            CompanyModelImpl.FINDER_CACHE_ENABLED, Long.class,
326                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByMx",
327                            new String[] { String.class.getName() });
328    
329            /**
330             * Returns the company where mx = &#63; or throws a {@link NoSuchCompanyException} if it could not be found.
331             *
332             * @param mx the mx
333             * @return the matching company
334             * @throws NoSuchCompanyException if a matching company could not be found
335             */
336            @Override
337            public Company findByMx(String mx) throws NoSuchCompanyException {
338                    Company company = fetchByMx(mx);
339    
340                    if (company == null) {
341                            StringBundler msg = new StringBundler(4);
342    
343                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
344    
345                            msg.append("mx=");
346                            msg.append(mx);
347    
348                            msg.append(StringPool.CLOSE_CURLY_BRACE);
349    
350                            if (_log.isWarnEnabled()) {
351                                    _log.warn(msg.toString());
352                            }
353    
354                            throw new NoSuchCompanyException(msg.toString());
355                    }
356    
357                    return company;
358            }
359    
360            /**
361             * Returns the company where mx = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
362             *
363             * @param mx the mx
364             * @return the matching company, or <code>null</code> if a matching company could not be found
365             */
366            @Override
367            public Company fetchByMx(String mx) {
368                    return fetchByMx(mx, true);
369            }
370    
371            /**
372             * Returns the company where mx = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
373             *
374             * @param mx the mx
375             * @param retrieveFromCache whether to retrieve from the finder cache
376             * @return the matching company, or <code>null</code> if a matching company could not be found
377             */
378            @Override
379            public Company fetchByMx(String mx, boolean retrieveFromCache) {
380                    Object[] finderArgs = new Object[] { mx };
381    
382                    Object result = null;
383    
384                    if (retrieveFromCache) {
385                            result = finderCache.getResult(FINDER_PATH_FETCH_BY_MX, finderArgs,
386                                            this);
387                    }
388    
389                    if (result instanceof Company) {
390                            Company company = (Company)result;
391    
392                            if (!Validator.equals(mx, company.getMx())) {
393                                    result = null;
394                            }
395                    }
396    
397                    if (result == null) {
398                            StringBundler query = new StringBundler(3);
399    
400                            query.append(_SQL_SELECT_COMPANY_WHERE);
401    
402                            boolean bindMx = false;
403    
404                            if (mx == null) {
405                                    query.append(_FINDER_COLUMN_MX_MX_1);
406                            }
407                            else if (mx.equals(StringPool.BLANK)) {
408                                    query.append(_FINDER_COLUMN_MX_MX_3);
409                            }
410                            else {
411                                    bindMx = true;
412    
413                                    query.append(_FINDER_COLUMN_MX_MX_2);
414                            }
415    
416                            String sql = query.toString();
417    
418                            Session session = null;
419    
420                            try {
421                                    session = openSession();
422    
423                                    Query q = session.createQuery(sql);
424    
425                                    QueryPos qPos = QueryPos.getInstance(q);
426    
427                                    if (bindMx) {
428                                            qPos.add(mx);
429                                    }
430    
431                                    List<Company> list = q.list();
432    
433                                    if (list.isEmpty()) {
434                                            finderCache.putResult(FINDER_PATH_FETCH_BY_MX, finderArgs,
435                                                    list);
436                                    }
437                                    else {
438                                            if ((list.size() > 1) && _log.isWarnEnabled()) {
439                                                    _log.warn(
440                                                            "CompanyPersistenceImpl.fetchByMx(String, boolean) with parameters (" +
441                                                            StringUtil.merge(finderArgs) +
442                                                            ") yields a result set with more than 1 result. This violates the logical unique restriction. There is no order guarantee on which result is returned by this finder.");
443                                            }
444    
445                                            Company company = list.get(0);
446    
447                                            result = company;
448    
449                                            cacheResult(company);
450    
451                                            if ((company.getMx() == null) ||
452                                                            !company.getMx().equals(mx)) {
453                                                    finderCache.putResult(FINDER_PATH_FETCH_BY_MX,
454                                                            finderArgs, company);
455                                            }
456                                    }
457                            }
458                            catch (Exception e) {
459                                    finderCache.removeResult(FINDER_PATH_FETCH_BY_MX, finderArgs);
460    
461                                    throw processException(e);
462                            }
463                            finally {
464                                    closeSession(session);
465                            }
466                    }
467    
468                    if (result instanceof List<?>) {
469                            return null;
470                    }
471                    else {
472                            return (Company)result;
473                    }
474            }
475    
476            /**
477             * Removes the company where mx = &#63; from the database.
478             *
479             * @param mx the mx
480             * @return the company that was removed
481             */
482            @Override
483            public Company removeByMx(String mx) throws NoSuchCompanyException {
484                    Company company = findByMx(mx);
485    
486                    return remove(company);
487            }
488    
489            /**
490             * Returns the number of companies where mx = &#63;.
491             *
492             * @param mx the mx
493             * @return the number of matching companies
494             */
495            @Override
496            public int countByMx(String mx) {
497                    FinderPath finderPath = FINDER_PATH_COUNT_BY_MX;
498    
499                    Object[] finderArgs = new Object[] { mx };
500    
501                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
502    
503                    if (count == null) {
504                            StringBundler query = new StringBundler(2);
505    
506                            query.append(_SQL_COUNT_COMPANY_WHERE);
507    
508                            boolean bindMx = false;
509    
510                            if (mx == null) {
511                                    query.append(_FINDER_COLUMN_MX_MX_1);
512                            }
513                            else if (mx.equals(StringPool.BLANK)) {
514                                    query.append(_FINDER_COLUMN_MX_MX_3);
515                            }
516                            else {
517                                    bindMx = true;
518    
519                                    query.append(_FINDER_COLUMN_MX_MX_2);
520                            }
521    
522                            String sql = query.toString();
523    
524                            Session session = null;
525    
526                            try {
527                                    session = openSession();
528    
529                                    Query q = session.createQuery(sql);
530    
531                                    QueryPos qPos = QueryPos.getInstance(q);
532    
533                                    if (bindMx) {
534                                            qPos.add(mx);
535                                    }
536    
537                                    count = (Long)q.uniqueResult();
538    
539                                    finderCache.putResult(finderPath, finderArgs, count);
540                            }
541                            catch (Exception e) {
542                                    finderCache.removeResult(finderPath, finderArgs);
543    
544                                    throw processException(e);
545                            }
546                            finally {
547                                    closeSession(session);
548                            }
549                    }
550    
551                    return count.intValue();
552            }
553    
554            private static final String _FINDER_COLUMN_MX_MX_1 = "company.mx IS NULL";
555            private static final String _FINDER_COLUMN_MX_MX_2 = "company.mx = ?";
556            private static final String _FINDER_COLUMN_MX_MX_3 = "(company.mx IS NULL OR company.mx = '')";
557            public static final FinderPath FINDER_PATH_FETCH_BY_LOGOID = new FinderPath(CompanyModelImpl.ENTITY_CACHE_ENABLED,
558                            CompanyModelImpl.FINDER_CACHE_ENABLED, CompanyImpl.class,
559                            FINDER_CLASS_NAME_ENTITY, "fetchByLogoId",
560                            new String[] { Long.class.getName() },
561                            CompanyModelImpl.LOGOID_COLUMN_BITMASK);
562            public static final FinderPath FINDER_PATH_COUNT_BY_LOGOID = new FinderPath(CompanyModelImpl.ENTITY_CACHE_ENABLED,
563                            CompanyModelImpl.FINDER_CACHE_ENABLED, Long.class,
564                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByLogoId",
565                            new String[] { Long.class.getName() });
566    
567            /**
568             * Returns the company where logoId = &#63; or throws a {@link NoSuchCompanyException} if it could not be found.
569             *
570             * @param logoId the logo ID
571             * @return the matching company
572             * @throws NoSuchCompanyException if a matching company could not be found
573             */
574            @Override
575            public Company findByLogoId(long logoId) throws NoSuchCompanyException {
576                    Company company = fetchByLogoId(logoId);
577    
578                    if (company == null) {
579                            StringBundler msg = new StringBundler(4);
580    
581                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
582    
583                            msg.append("logoId=");
584                            msg.append(logoId);
585    
586                            msg.append(StringPool.CLOSE_CURLY_BRACE);
587    
588                            if (_log.isWarnEnabled()) {
589                                    _log.warn(msg.toString());
590                            }
591    
592                            throw new NoSuchCompanyException(msg.toString());
593                    }
594    
595                    return company;
596            }
597    
598            /**
599             * Returns the company where logoId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
600             *
601             * @param logoId the logo ID
602             * @return the matching company, or <code>null</code> if a matching company could not be found
603             */
604            @Override
605            public Company fetchByLogoId(long logoId) {
606                    return fetchByLogoId(logoId, true);
607            }
608    
609            /**
610             * Returns the company where logoId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
611             *
612             * @param logoId the logo ID
613             * @param retrieveFromCache whether to retrieve from the finder cache
614             * @return the matching company, or <code>null</code> if a matching company could not be found
615             */
616            @Override
617            public Company fetchByLogoId(long logoId, boolean retrieveFromCache) {
618                    Object[] finderArgs = new Object[] { logoId };
619    
620                    Object result = null;
621    
622                    if (retrieveFromCache) {
623                            result = finderCache.getResult(FINDER_PATH_FETCH_BY_LOGOID,
624                                            finderArgs, this);
625                    }
626    
627                    if (result instanceof Company) {
628                            Company company = (Company)result;
629    
630                            if ((logoId != company.getLogoId())) {
631                                    result = null;
632                            }
633                    }
634    
635                    if (result == null) {
636                            StringBundler query = new StringBundler(3);
637    
638                            query.append(_SQL_SELECT_COMPANY_WHERE);
639    
640                            query.append(_FINDER_COLUMN_LOGOID_LOGOID_2);
641    
642                            String sql = query.toString();
643    
644                            Session session = null;
645    
646                            try {
647                                    session = openSession();
648    
649                                    Query q = session.createQuery(sql);
650    
651                                    QueryPos qPos = QueryPos.getInstance(q);
652    
653                                    qPos.add(logoId);
654    
655                                    List<Company> list = q.list();
656    
657                                    if (list.isEmpty()) {
658                                            finderCache.putResult(FINDER_PATH_FETCH_BY_LOGOID,
659                                                    finderArgs, list);
660                                    }
661                                    else {
662                                            if ((list.size() > 1) && _log.isWarnEnabled()) {
663                                                    _log.warn(
664                                                            "CompanyPersistenceImpl.fetchByLogoId(long, boolean) with parameters (" +
665                                                            StringUtil.merge(finderArgs) +
666                                                            ") yields a result set with more than 1 result. This violates the logical unique restriction. There is no order guarantee on which result is returned by this finder.");
667                                            }
668    
669                                            Company company = list.get(0);
670    
671                                            result = company;
672    
673                                            cacheResult(company);
674    
675                                            if ((company.getLogoId() != logoId)) {
676                                                    finderCache.putResult(FINDER_PATH_FETCH_BY_LOGOID,
677                                                            finderArgs, company);
678                                            }
679                                    }
680                            }
681                            catch (Exception e) {
682                                    finderCache.removeResult(FINDER_PATH_FETCH_BY_LOGOID, finderArgs);
683    
684                                    throw processException(e);
685                            }
686                            finally {
687                                    closeSession(session);
688                            }
689                    }
690    
691                    if (result instanceof List<?>) {
692                            return null;
693                    }
694                    else {
695                            return (Company)result;
696                    }
697            }
698    
699            /**
700             * Removes the company where logoId = &#63; from the database.
701             *
702             * @param logoId the logo ID
703             * @return the company that was removed
704             */
705            @Override
706            public Company removeByLogoId(long logoId) throws NoSuchCompanyException {
707                    Company company = findByLogoId(logoId);
708    
709                    return remove(company);
710            }
711    
712            /**
713             * Returns the number of companies where logoId = &#63;.
714             *
715             * @param logoId the logo ID
716             * @return the number of matching companies
717             */
718            @Override
719            public int countByLogoId(long logoId) {
720                    FinderPath finderPath = FINDER_PATH_COUNT_BY_LOGOID;
721    
722                    Object[] finderArgs = new Object[] { logoId };
723    
724                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
725    
726                    if (count == null) {
727                            StringBundler query = new StringBundler(2);
728    
729                            query.append(_SQL_COUNT_COMPANY_WHERE);
730    
731                            query.append(_FINDER_COLUMN_LOGOID_LOGOID_2);
732    
733                            String sql = query.toString();
734    
735                            Session session = null;
736    
737                            try {
738                                    session = openSession();
739    
740                                    Query q = session.createQuery(sql);
741    
742                                    QueryPos qPos = QueryPos.getInstance(q);
743    
744                                    qPos.add(logoId);
745    
746                                    count = (Long)q.uniqueResult();
747    
748                                    finderCache.putResult(finderPath, finderArgs, count);
749                            }
750                            catch (Exception e) {
751                                    finderCache.removeResult(finderPath, finderArgs);
752    
753                                    throw processException(e);
754                            }
755                            finally {
756                                    closeSession(session);
757                            }
758                    }
759    
760                    return count.intValue();
761            }
762    
763            private static final String _FINDER_COLUMN_LOGOID_LOGOID_2 = "company.logoId = ?";
764            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_SYSTEM = new FinderPath(CompanyModelImpl.ENTITY_CACHE_ENABLED,
765                            CompanyModelImpl.FINDER_CACHE_ENABLED, CompanyImpl.class,
766                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findBySystem",
767                            new String[] {
768                                    Boolean.class.getName(),
769                                    
770                            Integer.class.getName(), Integer.class.getName(),
771                                    OrderByComparator.class.getName()
772                            });
773            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SYSTEM =
774                    new FinderPath(CompanyModelImpl.ENTITY_CACHE_ENABLED,
775                            CompanyModelImpl.FINDER_CACHE_ENABLED, CompanyImpl.class,
776                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findBySystem",
777                            new String[] { Boolean.class.getName() },
778                            CompanyModelImpl.SYSTEM_COLUMN_BITMASK);
779            public static final FinderPath FINDER_PATH_COUNT_BY_SYSTEM = new FinderPath(CompanyModelImpl.ENTITY_CACHE_ENABLED,
780                            CompanyModelImpl.FINDER_CACHE_ENABLED, Long.class,
781                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countBySystem",
782                            new String[] { Boolean.class.getName() });
783    
784            /**
785             * Returns all the companies where system = &#63;.
786             *
787             * @param system the system
788             * @return the matching companies
789             */
790            @Override
791            public List<Company> findBySystem(boolean system) {
792                    return findBySystem(system, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
793            }
794    
795            /**
796             * Returns a range of all the companies where system = &#63;.
797             *
798             * <p>
799             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link CompanyModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
800             * </p>
801             *
802             * @param system the system
803             * @param start the lower bound of the range of companies
804             * @param end the upper bound of the range of companies (not inclusive)
805             * @return the range of matching companies
806             */
807            @Override
808            public List<Company> findBySystem(boolean system, int start, int end) {
809                    return findBySystem(system, start, end, null);
810            }
811    
812            /**
813             * Returns an ordered range of all the companies where system = &#63;.
814             *
815             * <p>
816             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link CompanyModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
817             * </p>
818             *
819             * @param system the system
820             * @param start the lower bound of the range of companies
821             * @param end the upper bound of the range of companies (not inclusive)
822             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
823             * @return the ordered range of matching companies
824             */
825            @Override
826            public List<Company> findBySystem(boolean system, int start, int end,
827                    OrderByComparator<Company> orderByComparator) {
828                    return findBySystem(system, start, end, orderByComparator, true);
829            }
830    
831            /**
832             * Returns an ordered range of all the companies where system = &#63;.
833             *
834             * <p>
835             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link CompanyModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
836             * </p>
837             *
838             * @param system the system
839             * @param start the lower bound of the range of companies
840             * @param end the upper bound of the range of companies (not inclusive)
841             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
842             * @param retrieveFromCache whether to retrieve from the finder cache
843             * @return the ordered range of matching companies
844             */
845            @Override
846            public List<Company> findBySystem(boolean system, int start, int end,
847                    OrderByComparator<Company> orderByComparator, boolean retrieveFromCache) {
848                    boolean pagination = true;
849                    FinderPath finderPath = null;
850                    Object[] finderArgs = null;
851    
852                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
853                                    (orderByComparator == null)) {
854                            pagination = false;
855                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SYSTEM;
856                            finderArgs = new Object[] { system };
857                    }
858                    else {
859                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_SYSTEM;
860                            finderArgs = new Object[] { system, start, end, orderByComparator };
861                    }
862    
863                    List<Company> list = null;
864    
865                    if (retrieveFromCache) {
866                            list = (List<Company>)finderCache.getResult(finderPath, finderArgs,
867                                            this);
868    
869                            if ((list != null) && !list.isEmpty()) {
870                                    for (Company company : list) {
871                                            if ((system != company.getSystem())) {
872                                                    list = null;
873    
874                                                    break;
875                                            }
876                                    }
877                            }
878                    }
879    
880                    if (list == null) {
881                            StringBundler query = null;
882    
883                            if (orderByComparator != null) {
884                                    query = new StringBundler(3 +
885                                                    (orderByComparator.getOrderByFields().length * 3));
886                            }
887                            else {
888                                    query = new StringBundler(3);
889                            }
890    
891                            query.append(_SQL_SELECT_COMPANY_WHERE);
892    
893                            query.append(_FINDER_COLUMN_SYSTEM_SYSTEM_2);
894    
895                            if (orderByComparator != null) {
896                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
897                                            orderByComparator);
898                            }
899                            else
900                             if (pagination) {
901                                    query.append(CompanyModelImpl.ORDER_BY_JPQL);
902                            }
903    
904                            String sql = query.toString();
905    
906                            Session session = null;
907    
908                            try {
909                                    session = openSession();
910    
911                                    Query q = session.createQuery(sql);
912    
913                                    QueryPos qPos = QueryPos.getInstance(q);
914    
915                                    qPos.add(system);
916    
917                                    if (!pagination) {
918                                            list = (List<Company>)QueryUtil.list(q, getDialect(),
919                                                            start, end, false);
920    
921                                            Collections.sort(list);
922    
923                                            list = Collections.unmodifiableList(list);
924                                    }
925                                    else {
926                                            list = (List<Company>)QueryUtil.list(q, getDialect(),
927                                                            start, end);
928                                    }
929    
930                                    cacheResult(list);
931    
932                                    finderCache.putResult(finderPath, finderArgs, list);
933                            }
934                            catch (Exception e) {
935                                    finderCache.removeResult(finderPath, finderArgs);
936    
937                                    throw processException(e);
938                            }
939                            finally {
940                                    closeSession(session);
941                            }
942                    }
943    
944                    return list;
945            }
946    
947            /**
948             * Returns the first company in the ordered set where system = &#63;.
949             *
950             * @param system the system
951             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
952             * @return the first matching company
953             * @throws NoSuchCompanyException if a matching company could not be found
954             */
955            @Override
956            public Company findBySystem_First(boolean system,
957                    OrderByComparator<Company> orderByComparator)
958                    throws NoSuchCompanyException {
959                    Company company = fetchBySystem_First(system, orderByComparator);
960    
961                    if (company != null) {
962                            return company;
963                    }
964    
965                    StringBundler msg = new StringBundler(4);
966    
967                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
968    
969                    msg.append("system=");
970                    msg.append(system);
971    
972                    msg.append(StringPool.CLOSE_CURLY_BRACE);
973    
974                    throw new NoSuchCompanyException(msg.toString());
975            }
976    
977            /**
978             * Returns the first company in the ordered set where system = &#63;.
979             *
980             * @param system the system
981             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
982             * @return the first matching company, or <code>null</code> if a matching company could not be found
983             */
984            @Override
985            public Company fetchBySystem_First(boolean system,
986                    OrderByComparator<Company> orderByComparator) {
987                    List<Company> list = findBySystem(system, 0, 1, orderByComparator);
988    
989                    if (!list.isEmpty()) {
990                            return list.get(0);
991                    }
992    
993                    return null;
994            }
995    
996            /**
997             * Returns the last company in the ordered set where system = &#63;.
998             *
999             * @param system the system
1000             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1001             * @return the last matching company
1002             * @throws NoSuchCompanyException if a matching company could not be found
1003             */
1004            @Override
1005            public Company findBySystem_Last(boolean system,
1006                    OrderByComparator<Company> orderByComparator)
1007                    throws NoSuchCompanyException {
1008                    Company company = fetchBySystem_Last(system, orderByComparator);
1009    
1010                    if (company != null) {
1011                            return company;
1012                    }
1013    
1014                    StringBundler msg = new StringBundler(4);
1015    
1016                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1017    
1018                    msg.append("system=");
1019                    msg.append(system);
1020    
1021                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1022    
1023                    throw new NoSuchCompanyException(msg.toString());
1024            }
1025    
1026            /**
1027             * Returns the last company in the ordered set where system = &#63;.
1028             *
1029             * @param system the system
1030             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1031             * @return the last matching company, or <code>null</code> if a matching company could not be found
1032             */
1033            @Override
1034            public Company fetchBySystem_Last(boolean system,
1035                    OrderByComparator<Company> orderByComparator) {
1036                    int count = countBySystem(system);
1037    
1038                    if (count == 0) {
1039                            return null;
1040                    }
1041    
1042                    List<Company> list = findBySystem(system, count - 1, count,
1043                                    orderByComparator);
1044    
1045                    if (!list.isEmpty()) {
1046                            return list.get(0);
1047                    }
1048    
1049                    return null;
1050            }
1051    
1052            /**
1053             * Returns the companies before and after the current company in the ordered set where system = &#63;.
1054             *
1055             * @param companyId the primary key of the current company
1056             * @param system the system
1057             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1058             * @return the previous, current, and next company
1059             * @throws NoSuchCompanyException if a company with the primary key could not be found
1060             */
1061            @Override
1062            public Company[] findBySystem_PrevAndNext(long companyId, boolean system,
1063                    OrderByComparator<Company> orderByComparator)
1064                    throws NoSuchCompanyException {
1065                    Company company = findByPrimaryKey(companyId);
1066    
1067                    Session session = null;
1068    
1069                    try {
1070                            session = openSession();
1071    
1072                            Company[] array = new CompanyImpl[3];
1073    
1074                            array[0] = getBySystem_PrevAndNext(session, company, system,
1075                                            orderByComparator, true);
1076    
1077                            array[1] = company;
1078    
1079                            array[2] = getBySystem_PrevAndNext(session, company, system,
1080                                            orderByComparator, false);
1081    
1082                            return array;
1083                    }
1084                    catch (Exception e) {
1085                            throw processException(e);
1086                    }
1087                    finally {
1088                            closeSession(session);
1089                    }
1090            }
1091    
1092            protected Company getBySystem_PrevAndNext(Session session, Company company,
1093                    boolean system, OrderByComparator<Company> orderByComparator,
1094                    boolean previous) {
1095                    StringBundler query = null;
1096    
1097                    if (orderByComparator != null) {
1098                            query = new StringBundler(6 +
1099                                            (orderByComparator.getOrderByFields().length * 6));
1100                    }
1101                    else {
1102                            query = new StringBundler(3);
1103                    }
1104    
1105                    query.append(_SQL_SELECT_COMPANY_WHERE);
1106    
1107                    query.append(_FINDER_COLUMN_SYSTEM_SYSTEM_2);
1108    
1109                    if (orderByComparator != null) {
1110                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1111    
1112                            if (orderByConditionFields.length > 0) {
1113                                    query.append(WHERE_AND);
1114                            }
1115    
1116                            for (int i = 0; i < orderByConditionFields.length; i++) {
1117                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1118                                    query.append(orderByConditionFields[i]);
1119    
1120                                    if ((i + 1) < orderByConditionFields.length) {
1121                                            if (orderByComparator.isAscending() ^ previous) {
1122                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1123                                            }
1124                                            else {
1125                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1126                                            }
1127                                    }
1128                                    else {
1129                                            if (orderByComparator.isAscending() ^ previous) {
1130                                                    query.append(WHERE_GREATER_THAN);
1131                                            }
1132                                            else {
1133                                                    query.append(WHERE_LESSER_THAN);
1134                                            }
1135                                    }
1136                            }
1137    
1138                            query.append(ORDER_BY_CLAUSE);
1139    
1140                            String[] orderByFields = orderByComparator.getOrderByFields();
1141    
1142                            for (int i = 0; i < orderByFields.length; i++) {
1143                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1144                                    query.append(orderByFields[i]);
1145    
1146                                    if ((i + 1) < orderByFields.length) {
1147                                            if (orderByComparator.isAscending() ^ previous) {
1148                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1149                                            }
1150                                            else {
1151                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1152                                            }
1153                                    }
1154                                    else {
1155                                            if (orderByComparator.isAscending() ^ previous) {
1156                                                    query.append(ORDER_BY_ASC);
1157                                            }
1158                                            else {
1159                                                    query.append(ORDER_BY_DESC);
1160                                            }
1161                                    }
1162                            }
1163                    }
1164                    else {
1165                            query.append(CompanyModelImpl.ORDER_BY_JPQL);
1166                    }
1167    
1168                    String sql = query.toString();
1169    
1170                    Query q = session.createQuery(sql);
1171    
1172                    q.setFirstResult(0);
1173                    q.setMaxResults(2);
1174    
1175                    QueryPos qPos = QueryPos.getInstance(q);
1176    
1177                    qPos.add(system);
1178    
1179                    if (orderByComparator != null) {
1180                            Object[] values = orderByComparator.getOrderByConditionValues(company);
1181    
1182                            for (Object value : values) {
1183                                    qPos.add(value);
1184                            }
1185                    }
1186    
1187                    List<Company> list = q.list();
1188    
1189                    if (list.size() == 2) {
1190                            return list.get(1);
1191                    }
1192                    else {
1193                            return null;
1194                    }
1195            }
1196    
1197            /**
1198             * Removes all the companies where system = &#63; from the database.
1199             *
1200             * @param system the system
1201             */
1202            @Override
1203            public void removeBySystem(boolean system) {
1204                    for (Company company : findBySystem(system, QueryUtil.ALL_POS,
1205                                    QueryUtil.ALL_POS, null)) {
1206                            remove(company);
1207                    }
1208            }
1209    
1210            /**
1211             * Returns the number of companies where system = &#63;.
1212             *
1213             * @param system the system
1214             * @return the number of matching companies
1215             */
1216            @Override
1217            public int countBySystem(boolean system) {
1218                    FinderPath finderPath = FINDER_PATH_COUNT_BY_SYSTEM;
1219    
1220                    Object[] finderArgs = new Object[] { system };
1221    
1222                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
1223    
1224                    if (count == null) {
1225                            StringBundler query = new StringBundler(2);
1226    
1227                            query.append(_SQL_COUNT_COMPANY_WHERE);
1228    
1229                            query.append(_FINDER_COLUMN_SYSTEM_SYSTEM_2);
1230    
1231                            String sql = query.toString();
1232    
1233                            Session session = null;
1234    
1235                            try {
1236                                    session = openSession();
1237    
1238                                    Query q = session.createQuery(sql);
1239    
1240                                    QueryPos qPos = QueryPos.getInstance(q);
1241    
1242                                    qPos.add(system);
1243    
1244                                    count = (Long)q.uniqueResult();
1245    
1246                                    finderCache.putResult(finderPath, finderArgs, count);
1247                            }
1248                            catch (Exception e) {
1249                                    finderCache.removeResult(finderPath, finderArgs);
1250    
1251                                    throw processException(e);
1252                            }
1253                            finally {
1254                                    closeSession(session);
1255                            }
1256                    }
1257    
1258                    return count.intValue();
1259            }
1260    
1261            private static final String _FINDER_COLUMN_SYSTEM_SYSTEM_2 = "company.system = ?";
1262    
1263            public CompanyPersistenceImpl() {
1264                    setModelClass(Company.class);
1265            }
1266    
1267            /**
1268             * Caches the company in the entity cache if it is enabled.
1269             *
1270             * @param company the company
1271             */
1272            @Override
1273            public void cacheResult(Company company) {
1274                    entityCache.putResult(CompanyModelImpl.ENTITY_CACHE_ENABLED,
1275                            CompanyImpl.class, company.getPrimaryKey(), company);
1276    
1277                    finderCache.putResult(FINDER_PATH_FETCH_BY_WEBID,
1278                            new Object[] { company.getWebId() }, company);
1279    
1280                    finderCache.putResult(FINDER_PATH_FETCH_BY_MX,
1281                            new Object[] { company.getMx() }, company);
1282    
1283                    finderCache.putResult(FINDER_PATH_FETCH_BY_LOGOID,
1284                            new Object[] { company.getLogoId() }, company);
1285    
1286                    company.resetOriginalValues();
1287            }
1288    
1289            /**
1290             * Caches the companies in the entity cache if it is enabled.
1291             *
1292             * @param companies the companies
1293             */
1294            @Override
1295            public void cacheResult(List<Company> companies) {
1296                    for (Company company : companies) {
1297                            if (entityCache.getResult(CompanyModelImpl.ENTITY_CACHE_ENABLED,
1298                                                    CompanyImpl.class, company.getPrimaryKey()) == null) {
1299                                    cacheResult(company);
1300                            }
1301                            else {
1302                                    company.resetOriginalValues();
1303                            }
1304                    }
1305            }
1306    
1307            /**
1308             * Clears the cache for all companies.
1309             *
1310             * <p>
1311             * The {@link EntityCache} and {@link FinderCache} are both cleared by this method.
1312             * </p>
1313             */
1314            @Override
1315            public void clearCache() {
1316                    entityCache.clearCache(CompanyImpl.class);
1317    
1318                    finderCache.clearCache(FINDER_CLASS_NAME_ENTITY);
1319                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1320                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1321            }
1322    
1323            /**
1324             * Clears the cache for the company.
1325             *
1326             * <p>
1327             * The {@link EntityCache} and {@link FinderCache} are both cleared by this method.
1328             * </p>
1329             */
1330            @Override
1331            public void clearCache(Company company) {
1332                    entityCache.removeResult(CompanyModelImpl.ENTITY_CACHE_ENABLED,
1333                            CompanyImpl.class, company.getPrimaryKey());
1334    
1335                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1336                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1337    
1338                    clearUniqueFindersCache((CompanyModelImpl)company);
1339            }
1340    
1341            @Override
1342            public void clearCache(List<Company> companies) {
1343                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1344                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1345    
1346                    for (Company company : companies) {
1347                            entityCache.removeResult(CompanyModelImpl.ENTITY_CACHE_ENABLED,
1348                                    CompanyImpl.class, company.getPrimaryKey());
1349    
1350                            clearUniqueFindersCache((CompanyModelImpl)company);
1351                    }
1352            }
1353    
1354            protected void cacheUniqueFindersCache(CompanyModelImpl companyModelImpl,
1355                    boolean isNew) {
1356                    if (isNew) {
1357                            Object[] args = new Object[] { companyModelImpl.getWebId() };
1358    
1359                            finderCache.putResult(FINDER_PATH_COUNT_BY_WEBID, args,
1360                                    Long.valueOf(1));
1361                            finderCache.putResult(FINDER_PATH_FETCH_BY_WEBID, args,
1362                                    companyModelImpl);
1363    
1364                            args = new Object[] { companyModelImpl.getMx() };
1365    
1366                            finderCache.putResult(FINDER_PATH_COUNT_BY_MX, args, Long.valueOf(1));
1367                            finderCache.putResult(FINDER_PATH_FETCH_BY_MX, args,
1368                                    companyModelImpl);
1369    
1370                            args = new Object[] { companyModelImpl.getLogoId() };
1371    
1372                            finderCache.putResult(FINDER_PATH_COUNT_BY_LOGOID, args,
1373                                    Long.valueOf(1));
1374                            finderCache.putResult(FINDER_PATH_FETCH_BY_LOGOID, args,
1375                                    companyModelImpl);
1376                    }
1377                    else {
1378                            if ((companyModelImpl.getColumnBitmask() &
1379                                            FINDER_PATH_FETCH_BY_WEBID.getColumnBitmask()) != 0) {
1380                                    Object[] args = new Object[] { companyModelImpl.getWebId() };
1381    
1382                                    finderCache.putResult(FINDER_PATH_COUNT_BY_WEBID, args,
1383                                            Long.valueOf(1));
1384                                    finderCache.putResult(FINDER_PATH_FETCH_BY_WEBID, args,
1385                                            companyModelImpl);
1386                            }
1387    
1388                            if ((companyModelImpl.getColumnBitmask() &
1389                                            FINDER_PATH_FETCH_BY_MX.getColumnBitmask()) != 0) {
1390                                    Object[] args = new Object[] { companyModelImpl.getMx() };
1391    
1392                                    finderCache.putResult(FINDER_PATH_COUNT_BY_MX, args,
1393                                            Long.valueOf(1));
1394                                    finderCache.putResult(FINDER_PATH_FETCH_BY_MX, args,
1395                                            companyModelImpl);
1396                            }
1397    
1398                            if ((companyModelImpl.getColumnBitmask() &
1399                                            FINDER_PATH_FETCH_BY_LOGOID.getColumnBitmask()) != 0) {
1400                                    Object[] args = new Object[] { companyModelImpl.getLogoId() };
1401    
1402                                    finderCache.putResult(FINDER_PATH_COUNT_BY_LOGOID, args,
1403                                            Long.valueOf(1));
1404                                    finderCache.putResult(FINDER_PATH_FETCH_BY_LOGOID, args,
1405                                            companyModelImpl);
1406                            }
1407                    }
1408            }
1409    
1410            protected void clearUniqueFindersCache(CompanyModelImpl companyModelImpl) {
1411                    Object[] args = new Object[] { companyModelImpl.getWebId() };
1412    
1413                    finderCache.removeResult(FINDER_PATH_COUNT_BY_WEBID, args);
1414                    finderCache.removeResult(FINDER_PATH_FETCH_BY_WEBID, args);
1415    
1416                    if ((companyModelImpl.getColumnBitmask() &
1417                                    FINDER_PATH_FETCH_BY_WEBID.getColumnBitmask()) != 0) {
1418                            args = new Object[] { companyModelImpl.getOriginalWebId() };
1419    
1420                            finderCache.removeResult(FINDER_PATH_COUNT_BY_WEBID, args);
1421                            finderCache.removeResult(FINDER_PATH_FETCH_BY_WEBID, args);
1422                    }
1423    
1424                    args = new Object[] { companyModelImpl.getMx() };
1425    
1426                    finderCache.removeResult(FINDER_PATH_COUNT_BY_MX, args);
1427                    finderCache.removeResult(FINDER_PATH_FETCH_BY_MX, args);
1428    
1429                    if ((companyModelImpl.getColumnBitmask() &
1430                                    FINDER_PATH_FETCH_BY_MX.getColumnBitmask()) != 0) {
1431                            args = new Object[] { companyModelImpl.getOriginalMx() };
1432    
1433                            finderCache.removeResult(FINDER_PATH_COUNT_BY_MX, args);
1434                            finderCache.removeResult(FINDER_PATH_FETCH_BY_MX, args);
1435                    }
1436    
1437                    args = new Object[] { companyModelImpl.getLogoId() };
1438    
1439                    finderCache.removeResult(FINDER_PATH_COUNT_BY_LOGOID, args);
1440                    finderCache.removeResult(FINDER_PATH_FETCH_BY_LOGOID, args);
1441    
1442                    if ((companyModelImpl.getColumnBitmask() &
1443                                    FINDER_PATH_FETCH_BY_LOGOID.getColumnBitmask()) != 0) {
1444                            args = new Object[] { companyModelImpl.getOriginalLogoId() };
1445    
1446                            finderCache.removeResult(FINDER_PATH_COUNT_BY_LOGOID, args);
1447                            finderCache.removeResult(FINDER_PATH_FETCH_BY_LOGOID, args);
1448                    }
1449            }
1450    
1451            /**
1452             * Creates a new company with the primary key. Does not add the company to the database.
1453             *
1454             * @param companyId the primary key for the new company
1455             * @return the new company
1456             */
1457            @Override
1458            public Company create(long companyId) {
1459                    Company company = new CompanyImpl();
1460    
1461                    company.setNew(true);
1462                    company.setPrimaryKey(companyId);
1463    
1464                    return company;
1465            }
1466    
1467            /**
1468             * Removes the company with the primary key from the database. Also notifies the appropriate model listeners.
1469             *
1470             * @param companyId the primary key of the company
1471             * @return the company that was removed
1472             * @throws NoSuchCompanyException if a company with the primary key could not be found
1473             */
1474            @Override
1475            public Company remove(long companyId) throws NoSuchCompanyException {
1476                    return remove((Serializable)companyId);
1477            }
1478    
1479            /**
1480             * Removes the company with the primary key from the database. Also notifies the appropriate model listeners.
1481             *
1482             * @param primaryKey the primary key of the company
1483             * @return the company that was removed
1484             * @throws NoSuchCompanyException if a company with the primary key could not be found
1485             */
1486            @Override
1487            public Company remove(Serializable primaryKey)
1488                    throws NoSuchCompanyException {
1489                    Session session = null;
1490    
1491                    try {
1492                            session = openSession();
1493    
1494                            Company company = (Company)session.get(CompanyImpl.class, primaryKey);
1495    
1496                            if (company == null) {
1497                                    if (_log.isWarnEnabled()) {
1498                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1499                                    }
1500    
1501                                    throw new NoSuchCompanyException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1502                                            primaryKey);
1503                            }
1504    
1505                            return remove(company);
1506                    }
1507                    catch (NoSuchCompanyException nsee) {
1508                            throw nsee;
1509                    }
1510                    catch (Exception e) {
1511                            throw processException(e);
1512                    }
1513                    finally {
1514                            closeSession(session);
1515                    }
1516            }
1517    
1518            @Override
1519            protected Company removeImpl(Company company) {
1520                    company = toUnwrappedModel(company);
1521    
1522                    Session session = null;
1523    
1524                    try {
1525                            session = openSession();
1526    
1527                            if (!session.contains(company)) {
1528                                    company = (Company)session.get(CompanyImpl.class,
1529                                                    company.getPrimaryKeyObj());
1530                            }
1531    
1532                            if (company != null) {
1533                                    session.delete(company);
1534                            }
1535                    }
1536                    catch (Exception e) {
1537                            throw processException(e);
1538                    }
1539                    finally {
1540                            closeSession(session);
1541                    }
1542    
1543                    if (company != null) {
1544                            clearCache(company);
1545                    }
1546    
1547                    return company;
1548            }
1549    
1550            @Override
1551            public Company updateImpl(Company company) {
1552                    company = toUnwrappedModel(company);
1553    
1554                    boolean isNew = company.isNew();
1555    
1556                    CompanyModelImpl companyModelImpl = (CompanyModelImpl)company;
1557    
1558                    Session session = null;
1559    
1560                    try {
1561                            session = openSession();
1562    
1563                            if (company.isNew()) {
1564                                    session.save(company);
1565    
1566                                    company.setNew(false);
1567                            }
1568                            else {
1569                                    company = (Company)session.merge(company);
1570                            }
1571                    }
1572                    catch (Exception e) {
1573                            throw processException(e);
1574                    }
1575                    finally {
1576                            closeSession(session);
1577                    }
1578    
1579                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1580    
1581                    if (isNew || !CompanyModelImpl.COLUMN_BITMASK_ENABLED) {
1582                            finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1583                    }
1584    
1585                    else {
1586                            if ((companyModelImpl.getColumnBitmask() &
1587                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SYSTEM.getColumnBitmask()) != 0) {
1588                                    Object[] args = new Object[] {
1589                                                    companyModelImpl.getOriginalSystem()
1590                                            };
1591    
1592                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_SYSTEM, args);
1593                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SYSTEM,
1594                                            args);
1595    
1596                                    args = new Object[] { companyModelImpl.getSystem() };
1597    
1598                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_SYSTEM, args);
1599                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SYSTEM,
1600                                            args);
1601                            }
1602                    }
1603    
1604                    entityCache.putResult(CompanyModelImpl.ENTITY_CACHE_ENABLED,
1605                            CompanyImpl.class, company.getPrimaryKey(), company, false);
1606    
1607                    clearUniqueFindersCache(companyModelImpl);
1608                    cacheUniqueFindersCache(companyModelImpl, isNew);
1609    
1610                    company.resetOriginalValues();
1611    
1612                    return company;
1613            }
1614    
1615            protected Company toUnwrappedModel(Company company) {
1616                    if (company instanceof CompanyImpl) {
1617                            return company;
1618                    }
1619    
1620                    CompanyImpl companyImpl = new CompanyImpl();
1621    
1622                    companyImpl.setNew(company.isNew());
1623                    companyImpl.setPrimaryKey(company.getPrimaryKey());
1624    
1625                    companyImpl.setMvccVersion(company.getMvccVersion());
1626                    companyImpl.setCompanyId(company.getCompanyId());
1627                    companyImpl.setAccountId(company.getAccountId());
1628                    companyImpl.setWebId(company.getWebId());
1629                    companyImpl.setKey(company.getKey());
1630                    companyImpl.setMx(company.getMx());
1631                    companyImpl.setHomeURL(company.getHomeURL());
1632                    companyImpl.setLogoId(company.getLogoId());
1633                    companyImpl.setSystem(company.isSystem());
1634                    companyImpl.setMaxUsers(company.getMaxUsers());
1635                    companyImpl.setActive(company.isActive());
1636    
1637                    return companyImpl;
1638            }
1639    
1640            /**
1641             * Returns the company with the primary key or throws a {@link com.liferay.portal.exception.NoSuchModelException} if it could not be found.
1642             *
1643             * @param primaryKey the primary key of the company
1644             * @return the company
1645             * @throws NoSuchCompanyException if a company with the primary key could not be found
1646             */
1647            @Override
1648            public Company findByPrimaryKey(Serializable primaryKey)
1649                    throws NoSuchCompanyException {
1650                    Company company = fetchByPrimaryKey(primaryKey);
1651    
1652                    if (company == null) {
1653                            if (_log.isWarnEnabled()) {
1654                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1655                            }
1656    
1657                            throw new NoSuchCompanyException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1658                                    primaryKey);
1659                    }
1660    
1661                    return company;
1662            }
1663    
1664            /**
1665             * Returns the company with the primary key or throws a {@link NoSuchCompanyException} if it could not be found.
1666             *
1667             * @param companyId the primary key of the company
1668             * @return the company
1669             * @throws NoSuchCompanyException if a company with the primary key could not be found
1670             */
1671            @Override
1672            public Company findByPrimaryKey(long companyId)
1673                    throws NoSuchCompanyException {
1674                    return findByPrimaryKey((Serializable)companyId);
1675            }
1676    
1677            /**
1678             * Returns the company with the primary key or returns <code>null</code> if it could not be found.
1679             *
1680             * @param primaryKey the primary key of the company
1681             * @return the company, or <code>null</code> if a company with the primary key could not be found
1682             */
1683            @Override
1684            public Company fetchByPrimaryKey(Serializable primaryKey) {
1685                    Company company = (Company)entityCache.getResult(CompanyModelImpl.ENTITY_CACHE_ENABLED,
1686                                    CompanyImpl.class, primaryKey);
1687    
1688                    if (company == _nullCompany) {
1689                            return null;
1690                    }
1691    
1692                    if (company == null) {
1693                            Session session = null;
1694    
1695                            try {
1696                                    session = openSession();
1697    
1698                                    company = (Company)session.get(CompanyImpl.class, primaryKey);
1699    
1700                                    if (company != null) {
1701                                            cacheResult(company);
1702                                    }
1703                                    else {
1704                                            entityCache.putResult(CompanyModelImpl.ENTITY_CACHE_ENABLED,
1705                                                    CompanyImpl.class, primaryKey, _nullCompany);
1706                                    }
1707                            }
1708                            catch (Exception e) {
1709                                    entityCache.removeResult(CompanyModelImpl.ENTITY_CACHE_ENABLED,
1710                                            CompanyImpl.class, primaryKey);
1711    
1712                                    throw processException(e);
1713                            }
1714                            finally {
1715                                    closeSession(session);
1716                            }
1717                    }
1718    
1719                    return company;
1720            }
1721    
1722            /**
1723             * Returns the company with the primary key or returns <code>null</code> if it could not be found.
1724             *
1725             * @param companyId the primary key of the company
1726             * @return the company, or <code>null</code> if a company with the primary key could not be found
1727             */
1728            @Override
1729            public Company fetchByPrimaryKey(long companyId) {
1730                    return fetchByPrimaryKey((Serializable)companyId);
1731            }
1732    
1733            @Override
1734            public Map<Serializable, Company> fetchByPrimaryKeys(
1735                    Set<Serializable> primaryKeys) {
1736                    if (primaryKeys.isEmpty()) {
1737                            return Collections.emptyMap();
1738                    }
1739    
1740                    Map<Serializable, Company> map = new HashMap<Serializable, Company>();
1741    
1742                    if (primaryKeys.size() == 1) {
1743                            Iterator<Serializable> iterator = primaryKeys.iterator();
1744    
1745                            Serializable primaryKey = iterator.next();
1746    
1747                            Company company = fetchByPrimaryKey(primaryKey);
1748    
1749                            if (company != null) {
1750                                    map.put(primaryKey, company);
1751                            }
1752    
1753                            return map;
1754                    }
1755    
1756                    Set<Serializable> uncachedPrimaryKeys = null;
1757    
1758                    for (Serializable primaryKey : primaryKeys) {
1759                            Company company = (Company)entityCache.getResult(CompanyModelImpl.ENTITY_CACHE_ENABLED,
1760                                            CompanyImpl.class, primaryKey);
1761    
1762                            if (company == null) {
1763                                    if (uncachedPrimaryKeys == null) {
1764                                            uncachedPrimaryKeys = new HashSet<Serializable>();
1765                                    }
1766    
1767                                    uncachedPrimaryKeys.add(primaryKey);
1768                            }
1769                            else {
1770                                    map.put(primaryKey, company);
1771                            }
1772                    }
1773    
1774                    if (uncachedPrimaryKeys == null) {
1775                            return map;
1776                    }
1777    
1778                    StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
1779                                    1);
1780    
1781                    query.append(_SQL_SELECT_COMPANY_WHERE_PKS_IN);
1782    
1783                    for (Serializable primaryKey : uncachedPrimaryKeys) {
1784                            query.append(String.valueOf(primaryKey));
1785    
1786                            query.append(StringPool.COMMA);
1787                    }
1788    
1789                    query.setIndex(query.index() - 1);
1790    
1791                    query.append(StringPool.CLOSE_PARENTHESIS);
1792    
1793                    String sql = query.toString();
1794    
1795                    Session session = null;
1796    
1797                    try {
1798                            session = openSession();
1799    
1800                            Query q = session.createQuery(sql);
1801    
1802                            for (Company company : (List<Company>)q.list()) {
1803                                    map.put(company.getPrimaryKeyObj(), company);
1804    
1805                                    cacheResult(company);
1806    
1807                                    uncachedPrimaryKeys.remove(company.getPrimaryKeyObj());
1808                            }
1809    
1810                            for (Serializable primaryKey : uncachedPrimaryKeys) {
1811                                    entityCache.putResult(CompanyModelImpl.ENTITY_CACHE_ENABLED,
1812                                            CompanyImpl.class, primaryKey, _nullCompany);
1813                            }
1814                    }
1815                    catch (Exception e) {
1816                            throw processException(e);
1817                    }
1818                    finally {
1819                            closeSession(session);
1820                    }
1821    
1822                    return map;
1823            }
1824    
1825            /**
1826             * Returns all the companies.
1827             *
1828             * @return the companies
1829             */
1830            @Override
1831            public List<Company> findAll() {
1832                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1833            }
1834    
1835            /**
1836             * Returns a range of all the companies.
1837             *
1838             * <p>
1839             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link CompanyModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1840             * </p>
1841             *
1842             * @param start the lower bound of the range of companies
1843             * @param end the upper bound of the range of companies (not inclusive)
1844             * @return the range of companies
1845             */
1846            @Override
1847            public List<Company> findAll(int start, int end) {
1848                    return findAll(start, end, null);
1849            }
1850    
1851            /**
1852             * Returns an ordered range of all the companies.
1853             *
1854             * <p>
1855             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link CompanyModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1856             * </p>
1857             *
1858             * @param start the lower bound of the range of companies
1859             * @param end the upper bound of the range of companies (not inclusive)
1860             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1861             * @return the ordered range of companies
1862             */
1863            @Override
1864            public List<Company> findAll(int start, int end,
1865                    OrderByComparator<Company> orderByComparator) {
1866                    return findAll(start, end, orderByComparator, true);
1867            }
1868    
1869            /**
1870             * Returns an ordered range of all the companies.
1871             *
1872             * <p>
1873             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link CompanyModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1874             * </p>
1875             *
1876             * @param start the lower bound of the range of companies
1877             * @param end the upper bound of the range of companies (not inclusive)
1878             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1879             * @param retrieveFromCache whether to retrieve from the finder cache
1880             * @return the ordered range of companies
1881             */
1882            @Override
1883            public List<Company> findAll(int start, int end,
1884                    OrderByComparator<Company> orderByComparator, boolean retrieveFromCache) {
1885                    boolean pagination = true;
1886                    FinderPath finderPath = null;
1887                    Object[] finderArgs = null;
1888    
1889                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1890                                    (orderByComparator == null)) {
1891                            pagination = false;
1892                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1893                            finderArgs = FINDER_ARGS_EMPTY;
1894                    }
1895                    else {
1896                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1897                            finderArgs = new Object[] { start, end, orderByComparator };
1898                    }
1899    
1900                    List<Company> list = null;
1901    
1902                    if (retrieveFromCache) {
1903                            list = (List<Company>)finderCache.getResult(finderPath, finderArgs,
1904                                            this);
1905                    }
1906    
1907                    if (list == null) {
1908                            StringBundler query = null;
1909                            String sql = null;
1910    
1911                            if (orderByComparator != null) {
1912                                    query = new StringBundler(2 +
1913                                                    (orderByComparator.getOrderByFields().length * 3));
1914    
1915                                    query.append(_SQL_SELECT_COMPANY);
1916    
1917                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1918                                            orderByComparator);
1919    
1920                                    sql = query.toString();
1921                            }
1922                            else {
1923                                    sql = _SQL_SELECT_COMPANY;
1924    
1925                                    if (pagination) {
1926                                            sql = sql.concat(CompanyModelImpl.ORDER_BY_JPQL);
1927                                    }
1928                            }
1929    
1930                            Session session = null;
1931    
1932                            try {
1933                                    session = openSession();
1934    
1935                                    Query q = session.createQuery(sql);
1936    
1937                                    if (!pagination) {
1938                                            list = (List<Company>)QueryUtil.list(q, getDialect(),
1939                                                            start, end, false);
1940    
1941                                            Collections.sort(list);
1942    
1943                                            list = Collections.unmodifiableList(list);
1944                                    }
1945                                    else {
1946                                            list = (List<Company>)QueryUtil.list(q, getDialect(),
1947                                                            start, end);
1948                                    }
1949    
1950                                    cacheResult(list);
1951    
1952                                    finderCache.putResult(finderPath, finderArgs, list);
1953                            }
1954                            catch (Exception e) {
1955                                    finderCache.removeResult(finderPath, finderArgs);
1956    
1957                                    throw processException(e);
1958                            }
1959                            finally {
1960                                    closeSession(session);
1961                            }
1962                    }
1963    
1964                    return list;
1965            }
1966    
1967            /**
1968             * Removes all the companies from the database.
1969             *
1970             */
1971            @Override
1972            public void removeAll() {
1973                    for (Company company : findAll()) {
1974                            remove(company);
1975                    }
1976            }
1977    
1978            /**
1979             * Returns the number of companies.
1980             *
1981             * @return the number of companies
1982             */
1983            @Override
1984            public int countAll() {
1985                    Long count = (Long)finderCache.getResult(FINDER_PATH_COUNT_ALL,
1986                                    FINDER_ARGS_EMPTY, this);
1987    
1988                    if (count == null) {
1989                            Session session = null;
1990    
1991                            try {
1992                                    session = openSession();
1993    
1994                                    Query q = session.createQuery(_SQL_COUNT_COMPANY);
1995    
1996                                    count = (Long)q.uniqueResult();
1997    
1998                                    finderCache.putResult(FINDER_PATH_COUNT_ALL, FINDER_ARGS_EMPTY,
1999                                            count);
2000                            }
2001                            catch (Exception e) {
2002                                    finderCache.removeResult(FINDER_PATH_COUNT_ALL,
2003                                            FINDER_ARGS_EMPTY);
2004    
2005                                    throw processException(e);
2006                            }
2007                            finally {
2008                                    closeSession(session);
2009                            }
2010                    }
2011    
2012                    return count.intValue();
2013            }
2014    
2015            @Override
2016            public Set<String> getBadColumnNames() {
2017                    return _badColumnNames;
2018            }
2019    
2020            @Override
2021            protected Map<String, Integer> getTableColumnsMap() {
2022                    return CompanyModelImpl.TABLE_COLUMNS_MAP;
2023            }
2024    
2025            /**
2026             * Initializes the company persistence.
2027             */
2028            public void afterPropertiesSet() {
2029            }
2030    
2031            public void destroy() {
2032                    entityCache.removeCache(CompanyImpl.class.getName());
2033                    finderCache.removeCache(FINDER_CLASS_NAME_ENTITY);
2034                    finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2035                    finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2036            }
2037    
2038            protected EntityCache entityCache = EntityCacheUtil.getEntityCache();
2039            protected FinderCache finderCache = FinderCacheUtil.getFinderCache();
2040            private static final String _SQL_SELECT_COMPANY = "SELECT company FROM Company company";
2041            private static final String _SQL_SELECT_COMPANY_WHERE_PKS_IN = "SELECT company FROM Company company WHERE companyId IN (";
2042            private static final String _SQL_SELECT_COMPANY_WHERE = "SELECT company FROM Company company WHERE ";
2043            private static final String _SQL_COUNT_COMPANY = "SELECT COUNT(company) FROM Company company";
2044            private static final String _SQL_COUNT_COMPANY_WHERE = "SELECT COUNT(company) FROM Company company WHERE ";
2045            private static final String _ORDER_BY_ENTITY_ALIAS = "company.";
2046            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Company exists with the primary key ";
2047            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Company exists with the key {";
2048            private static final Log _log = LogFactoryUtil.getLog(CompanyPersistenceImpl.class);
2049            private static final Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
2050                                    "key", "active"
2051                            });
2052            private static final Company _nullCompany = new CompanyImpl() {
2053                            @Override
2054                            public Object clone() {
2055                                    return this;
2056                            }
2057    
2058                            @Override
2059                            public CacheModel<Company> toCacheModel() {
2060                                    return _nullCompanyCacheModel;
2061                            }
2062                    };
2063    
2064            private static final CacheModel<Company> _nullCompanyCacheModel = new NullCacheModel();
2065    
2066            private static class NullCacheModel implements CacheModel<Company>,
2067                    MVCCModel {
2068                    @Override
2069                    public long getMvccVersion() {
2070                            return -1;
2071                    }
2072    
2073                    @Override
2074                    public void setMvccVersion(long mvccVersion) {
2075                    }
2076    
2077                    @Override
2078                    public Company toEntityModel() {
2079                            return _nullCompany;
2080                    }
2081            }
2082    }