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 * 2));
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(4 +
1099                                            (orderByComparator.getOrderByConditionFields().length * 3) +
1100                                            (orderByComparator.getOrderByFields().length * 3));
1101                    }
1102                    else {
1103                            query = new StringBundler(3);
1104                    }
1105    
1106                    query.append(_SQL_SELECT_COMPANY_WHERE);
1107    
1108                    query.append(_FINDER_COLUMN_SYSTEM_SYSTEM_2);
1109    
1110                    if (orderByComparator != null) {
1111                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1112    
1113                            if (orderByConditionFields.length > 0) {
1114                                    query.append(WHERE_AND);
1115                            }
1116    
1117                            for (int i = 0; i < orderByConditionFields.length; i++) {
1118                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1119                                    query.append(orderByConditionFields[i]);
1120    
1121                                    if ((i + 1) < orderByConditionFields.length) {
1122                                            if (orderByComparator.isAscending() ^ previous) {
1123                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1124                                            }
1125                                            else {
1126                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1127                                            }
1128                                    }
1129                                    else {
1130                                            if (orderByComparator.isAscending() ^ previous) {
1131                                                    query.append(WHERE_GREATER_THAN);
1132                                            }
1133                                            else {
1134                                                    query.append(WHERE_LESSER_THAN);
1135                                            }
1136                                    }
1137                            }
1138    
1139                            query.append(ORDER_BY_CLAUSE);
1140    
1141                            String[] orderByFields = orderByComparator.getOrderByFields();
1142    
1143                            for (int i = 0; i < orderByFields.length; i++) {
1144                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1145                                    query.append(orderByFields[i]);
1146    
1147                                    if ((i + 1) < orderByFields.length) {
1148                                            if (orderByComparator.isAscending() ^ previous) {
1149                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1150                                            }
1151                                            else {
1152                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1153                                            }
1154                                    }
1155                                    else {
1156                                            if (orderByComparator.isAscending() ^ previous) {
1157                                                    query.append(ORDER_BY_ASC);
1158                                            }
1159                                            else {
1160                                                    query.append(ORDER_BY_DESC);
1161                                            }
1162                                    }
1163                            }
1164                    }
1165                    else {
1166                            query.append(CompanyModelImpl.ORDER_BY_JPQL);
1167                    }
1168    
1169                    String sql = query.toString();
1170    
1171                    Query q = session.createQuery(sql);
1172    
1173                    q.setFirstResult(0);
1174                    q.setMaxResults(2);
1175    
1176                    QueryPos qPos = QueryPos.getInstance(q);
1177    
1178                    qPos.add(system);
1179    
1180                    if (orderByComparator != null) {
1181                            Object[] values = orderByComparator.getOrderByConditionValues(company);
1182    
1183                            for (Object value : values) {
1184                                    qPos.add(value);
1185                            }
1186                    }
1187    
1188                    List<Company> list = q.list();
1189    
1190                    if (list.size() == 2) {
1191                            return list.get(1);
1192                    }
1193                    else {
1194                            return null;
1195                    }
1196            }
1197    
1198            /**
1199             * Removes all the companies where system = &#63; from the database.
1200             *
1201             * @param system the system
1202             */
1203            @Override
1204            public void removeBySystem(boolean system) {
1205                    for (Company company : findBySystem(system, QueryUtil.ALL_POS,
1206                                    QueryUtil.ALL_POS, null)) {
1207                            remove(company);
1208                    }
1209            }
1210    
1211            /**
1212             * Returns the number of companies where system = &#63;.
1213             *
1214             * @param system the system
1215             * @return the number of matching companies
1216             */
1217            @Override
1218            public int countBySystem(boolean system) {
1219                    FinderPath finderPath = FINDER_PATH_COUNT_BY_SYSTEM;
1220    
1221                    Object[] finderArgs = new Object[] { system };
1222    
1223                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
1224    
1225                    if (count == null) {
1226                            StringBundler query = new StringBundler(2);
1227    
1228                            query.append(_SQL_COUNT_COMPANY_WHERE);
1229    
1230                            query.append(_FINDER_COLUMN_SYSTEM_SYSTEM_2);
1231    
1232                            String sql = query.toString();
1233    
1234                            Session session = null;
1235    
1236                            try {
1237                                    session = openSession();
1238    
1239                                    Query q = session.createQuery(sql);
1240    
1241                                    QueryPos qPos = QueryPos.getInstance(q);
1242    
1243                                    qPos.add(system);
1244    
1245                                    count = (Long)q.uniqueResult();
1246    
1247                                    finderCache.putResult(finderPath, finderArgs, count);
1248                            }
1249                            catch (Exception e) {
1250                                    finderCache.removeResult(finderPath, finderArgs);
1251    
1252                                    throw processException(e);
1253                            }
1254                            finally {
1255                                    closeSession(session);
1256                            }
1257                    }
1258    
1259                    return count.intValue();
1260            }
1261    
1262            private static final String _FINDER_COLUMN_SYSTEM_SYSTEM_2 = "company.system = ?";
1263    
1264            public CompanyPersistenceImpl() {
1265                    setModelClass(Company.class);
1266            }
1267    
1268            /**
1269             * Caches the company in the entity cache if it is enabled.
1270             *
1271             * @param company the company
1272             */
1273            @Override
1274            public void cacheResult(Company company) {
1275                    entityCache.putResult(CompanyModelImpl.ENTITY_CACHE_ENABLED,
1276                            CompanyImpl.class, company.getPrimaryKey(), company);
1277    
1278                    finderCache.putResult(FINDER_PATH_FETCH_BY_WEBID,
1279                            new Object[] { company.getWebId() }, company);
1280    
1281                    finderCache.putResult(FINDER_PATH_FETCH_BY_MX,
1282                            new Object[] { company.getMx() }, company);
1283    
1284                    finderCache.putResult(FINDER_PATH_FETCH_BY_LOGOID,
1285                            new Object[] { company.getLogoId() }, company);
1286    
1287                    company.resetOriginalValues();
1288            }
1289    
1290            /**
1291             * Caches the companies in the entity cache if it is enabled.
1292             *
1293             * @param companies the companies
1294             */
1295            @Override
1296            public void cacheResult(List<Company> companies) {
1297                    for (Company company : companies) {
1298                            if (entityCache.getResult(CompanyModelImpl.ENTITY_CACHE_ENABLED,
1299                                                    CompanyImpl.class, company.getPrimaryKey()) == null) {
1300                                    cacheResult(company);
1301                            }
1302                            else {
1303                                    company.resetOriginalValues();
1304                            }
1305                    }
1306            }
1307    
1308            /**
1309             * Clears the cache for all companies.
1310             *
1311             * <p>
1312             * The {@link EntityCache} and {@link FinderCache} are both cleared by this method.
1313             * </p>
1314             */
1315            @Override
1316            public void clearCache() {
1317                    entityCache.clearCache(CompanyImpl.class);
1318    
1319                    finderCache.clearCache(FINDER_CLASS_NAME_ENTITY);
1320                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1321                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1322            }
1323    
1324            /**
1325             * Clears the cache for the company.
1326             *
1327             * <p>
1328             * The {@link EntityCache} and {@link FinderCache} are both cleared by this method.
1329             * </p>
1330             */
1331            @Override
1332            public void clearCache(Company company) {
1333                    entityCache.removeResult(CompanyModelImpl.ENTITY_CACHE_ENABLED,
1334                            CompanyImpl.class, company.getPrimaryKey());
1335    
1336                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1337                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1338    
1339                    clearUniqueFindersCache((CompanyModelImpl)company);
1340            }
1341    
1342            @Override
1343            public void clearCache(List<Company> companies) {
1344                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1345                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1346    
1347                    for (Company company : companies) {
1348                            entityCache.removeResult(CompanyModelImpl.ENTITY_CACHE_ENABLED,
1349                                    CompanyImpl.class, company.getPrimaryKey());
1350    
1351                            clearUniqueFindersCache((CompanyModelImpl)company);
1352                    }
1353            }
1354    
1355            protected void cacheUniqueFindersCache(CompanyModelImpl companyModelImpl,
1356                    boolean isNew) {
1357                    if (isNew) {
1358                            Object[] args = new Object[] { companyModelImpl.getWebId() };
1359    
1360                            finderCache.putResult(FINDER_PATH_COUNT_BY_WEBID, args,
1361                                    Long.valueOf(1));
1362                            finderCache.putResult(FINDER_PATH_FETCH_BY_WEBID, args,
1363                                    companyModelImpl);
1364    
1365                            args = new Object[] { companyModelImpl.getMx() };
1366    
1367                            finderCache.putResult(FINDER_PATH_COUNT_BY_MX, args, Long.valueOf(1));
1368                            finderCache.putResult(FINDER_PATH_FETCH_BY_MX, args,
1369                                    companyModelImpl);
1370    
1371                            args = new Object[] { companyModelImpl.getLogoId() };
1372    
1373                            finderCache.putResult(FINDER_PATH_COUNT_BY_LOGOID, args,
1374                                    Long.valueOf(1));
1375                            finderCache.putResult(FINDER_PATH_FETCH_BY_LOGOID, args,
1376                                    companyModelImpl);
1377                    }
1378                    else {
1379                            if ((companyModelImpl.getColumnBitmask() &
1380                                            FINDER_PATH_FETCH_BY_WEBID.getColumnBitmask()) != 0) {
1381                                    Object[] args = new Object[] { companyModelImpl.getWebId() };
1382    
1383                                    finderCache.putResult(FINDER_PATH_COUNT_BY_WEBID, args,
1384                                            Long.valueOf(1));
1385                                    finderCache.putResult(FINDER_PATH_FETCH_BY_WEBID, args,
1386                                            companyModelImpl);
1387                            }
1388    
1389                            if ((companyModelImpl.getColumnBitmask() &
1390                                            FINDER_PATH_FETCH_BY_MX.getColumnBitmask()) != 0) {
1391                                    Object[] args = new Object[] { companyModelImpl.getMx() };
1392    
1393                                    finderCache.putResult(FINDER_PATH_COUNT_BY_MX, args,
1394                                            Long.valueOf(1));
1395                                    finderCache.putResult(FINDER_PATH_FETCH_BY_MX, args,
1396                                            companyModelImpl);
1397                            }
1398    
1399                            if ((companyModelImpl.getColumnBitmask() &
1400                                            FINDER_PATH_FETCH_BY_LOGOID.getColumnBitmask()) != 0) {
1401                                    Object[] args = new Object[] { companyModelImpl.getLogoId() };
1402    
1403                                    finderCache.putResult(FINDER_PATH_COUNT_BY_LOGOID, args,
1404                                            Long.valueOf(1));
1405                                    finderCache.putResult(FINDER_PATH_FETCH_BY_LOGOID, args,
1406                                            companyModelImpl);
1407                            }
1408                    }
1409            }
1410    
1411            protected void clearUniqueFindersCache(CompanyModelImpl companyModelImpl) {
1412                    Object[] args = new Object[] { companyModelImpl.getWebId() };
1413    
1414                    finderCache.removeResult(FINDER_PATH_COUNT_BY_WEBID, args);
1415                    finderCache.removeResult(FINDER_PATH_FETCH_BY_WEBID, args);
1416    
1417                    if ((companyModelImpl.getColumnBitmask() &
1418                                    FINDER_PATH_FETCH_BY_WEBID.getColumnBitmask()) != 0) {
1419                            args = new Object[] { companyModelImpl.getOriginalWebId() };
1420    
1421                            finderCache.removeResult(FINDER_PATH_COUNT_BY_WEBID, args);
1422                            finderCache.removeResult(FINDER_PATH_FETCH_BY_WEBID, args);
1423                    }
1424    
1425                    args = new Object[] { companyModelImpl.getMx() };
1426    
1427                    finderCache.removeResult(FINDER_PATH_COUNT_BY_MX, args);
1428                    finderCache.removeResult(FINDER_PATH_FETCH_BY_MX, args);
1429    
1430                    if ((companyModelImpl.getColumnBitmask() &
1431                                    FINDER_PATH_FETCH_BY_MX.getColumnBitmask()) != 0) {
1432                            args = new Object[] { companyModelImpl.getOriginalMx() };
1433    
1434                            finderCache.removeResult(FINDER_PATH_COUNT_BY_MX, args);
1435                            finderCache.removeResult(FINDER_PATH_FETCH_BY_MX, args);
1436                    }
1437    
1438                    args = new Object[] { companyModelImpl.getLogoId() };
1439    
1440                    finderCache.removeResult(FINDER_PATH_COUNT_BY_LOGOID, args);
1441                    finderCache.removeResult(FINDER_PATH_FETCH_BY_LOGOID, args);
1442    
1443                    if ((companyModelImpl.getColumnBitmask() &
1444                                    FINDER_PATH_FETCH_BY_LOGOID.getColumnBitmask()) != 0) {
1445                            args = new Object[] { companyModelImpl.getOriginalLogoId() };
1446    
1447                            finderCache.removeResult(FINDER_PATH_COUNT_BY_LOGOID, args);
1448                            finderCache.removeResult(FINDER_PATH_FETCH_BY_LOGOID, args);
1449                    }
1450            }
1451    
1452            /**
1453             * Creates a new company with the primary key. Does not add the company to the database.
1454             *
1455             * @param companyId the primary key for the new company
1456             * @return the new company
1457             */
1458            @Override
1459            public Company create(long companyId) {
1460                    Company company = new CompanyImpl();
1461    
1462                    company.setNew(true);
1463                    company.setPrimaryKey(companyId);
1464    
1465                    return company;
1466            }
1467    
1468            /**
1469             * Removes the company with the primary key from the database. Also notifies the appropriate model listeners.
1470             *
1471             * @param companyId the primary key of the company
1472             * @return the company that was removed
1473             * @throws NoSuchCompanyException if a company with the primary key could not be found
1474             */
1475            @Override
1476            public Company remove(long companyId) throws NoSuchCompanyException {
1477                    return remove((Serializable)companyId);
1478            }
1479    
1480            /**
1481             * Removes the company with the primary key from the database. Also notifies the appropriate model listeners.
1482             *
1483             * @param primaryKey the primary key of the company
1484             * @return the company that was removed
1485             * @throws NoSuchCompanyException if a company with the primary key could not be found
1486             */
1487            @Override
1488            public Company remove(Serializable primaryKey)
1489                    throws NoSuchCompanyException {
1490                    Session session = null;
1491    
1492                    try {
1493                            session = openSession();
1494    
1495                            Company company = (Company)session.get(CompanyImpl.class, primaryKey);
1496    
1497                            if (company == null) {
1498                                    if (_log.isWarnEnabled()) {
1499                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1500                                    }
1501    
1502                                    throw new NoSuchCompanyException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1503                                            primaryKey);
1504                            }
1505    
1506                            return remove(company);
1507                    }
1508                    catch (NoSuchCompanyException nsee) {
1509                            throw nsee;
1510                    }
1511                    catch (Exception e) {
1512                            throw processException(e);
1513                    }
1514                    finally {
1515                            closeSession(session);
1516                    }
1517            }
1518    
1519            @Override
1520            protected Company removeImpl(Company company) {
1521                    company = toUnwrappedModel(company);
1522    
1523                    Session session = null;
1524    
1525                    try {
1526                            session = openSession();
1527    
1528                            if (!session.contains(company)) {
1529                                    company = (Company)session.get(CompanyImpl.class,
1530                                                    company.getPrimaryKeyObj());
1531                            }
1532    
1533                            if (company != null) {
1534                                    session.delete(company);
1535                            }
1536                    }
1537                    catch (Exception e) {
1538                            throw processException(e);
1539                    }
1540                    finally {
1541                            closeSession(session);
1542                    }
1543    
1544                    if (company != null) {
1545                            clearCache(company);
1546                    }
1547    
1548                    return company;
1549            }
1550    
1551            @Override
1552            public Company updateImpl(Company company) {
1553                    company = toUnwrappedModel(company);
1554    
1555                    boolean isNew = company.isNew();
1556    
1557                    CompanyModelImpl companyModelImpl = (CompanyModelImpl)company;
1558    
1559                    Session session = null;
1560    
1561                    try {
1562                            session = openSession();
1563    
1564                            if (company.isNew()) {
1565                                    session.save(company);
1566    
1567                                    company.setNew(false);
1568                            }
1569                            else {
1570                                    company = (Company)session.merge(company);
1571                            }
1572                    }
1573                    catch (Exception e) {
1574                            throw processException(e);
1575                    }
1576                    finally {
1577                            closeSession(session);
1578                    }
1579    
1580                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1581    
1582                    if (isNew || !CompanyModelImpl.COLUMN_BITMASK_ENABLED) {
1583                            finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1584                    }
1585    
1586                    else {
1587                            if ((companyModelImpl.getColumnBitmask() &
1588                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SYSTEM.getColumnBitmask()) != 0) {
1589                                    Object[] args = new Object[] {
1590                                                    companyModelImpl.getOriginalSystem()
1591                                            };
1592    
1593                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_SYSTEM, args);
1594                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SYSTEM,
1595                                            args);
1596    
1597                                    args = new Object[] { companyModelImpl.getSystem() };
1598    
1599                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_SYSTEM, args);
1600                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SYSTEM,
1601                                            args);
1602                            }
1603                    }
1604    
1605                    entityCache.putResult(CompanyModelImpl.ENTITY_CACHE_ENABLED,
1606                            CompanyImpl.class, company.getPrimaryKey(), company, false);
1607    
1608                    clearUniqueFindersCache(companyModelImpl);
1609                    cacheUniqueFindersCache(companyModelImpl, isNew);
1610    
1611                    company.resetOriginalValues();
1612    
1613                    return company;
1614            }
1615    
1616            protected Company toUnwrappedModel(Company company) {
1617                    if (company instanceof CompanyImpl) {
1618                            return company;
1619                    }
1620    
1621                    CompanyImpl companyImpl = new CompanyImpl();
1622    
1623                    companyImpl.setNew(company.isNew());
1624                    companyImpl.setPrimaryKey(company.getPrimaryKey());
1625    
1626                    companyImpl.setMvccVersion(company.getMvccVersion());
1627                    companyImpl.setCompanyId(company.getCompanyId());
1628                    companyImpl.setAccountId(company.getAccountId());
1629                    companyImpl.setWebId(company.getWebId());
1630                    companyImpl.setKey(company.getKey());
1631                    companyImpl.setMx(company.getMx());
1632                    companyImpl.setHomeURL(company.getHomeURL());
1633                    companyImpl.setLogoId(company.getLogoId());
1634                    companyImpl.setSystem(company.isSystem());
1635                    companyImpl.setMaxUsers(company.getMaxUsers());
1636                    companyImpl.setActive(company.isActive());
1637    
1638                    return companyImpl;
1639            }
1640    
1641            /**
1642             * Returns the company with the primary key or throws a {@link com.liferay.portal.exception.NoSuchModelException} if it could not be found.
1643             *
1644             * @param primaryKey the primary key of the company
1645             * @return the company
1646             * @throws NoSuchCompanyException if a company with the primary key could not be found
1647             */
1648            @Override
1649            public Company findByPrimaryKey(Serializable primaryKey)
1650                    throws NoSuchCompanyException {
1651                    Company company = fetchByPrimaryKey(primaryKey);
1652    
1653                    if (company == null) {
1654                            if (_log.isWarnEnabled()) {
1655                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1656                            }
1657    
1658                            throw new NoSuchCompanyException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1659                                    primaryKey);
1660                    }
1661    
1662                    return company;
1663            }
1664    
1665            /**
1666             * Returns the company with the primary key or throws a {@link NoSuchCompanyException} if it could not be found.
1667             *
1668             * @param companyId the primary key of the company
1669             * @return the company
1670             * @throws NoSuchCompanyException if a company with the primary key could not be found
1671             */
1672            @Override
1673            public Company findByPrimaryKey(long companyId)
1674                    throws NoSuchCompanyException {
1675                    return findByPrimaryKey((Serializable)companyId);
1676            }
1677    
1678            /**
1679             * Returns the company with the primary key or returns <code>null</code> if it could not be found.
1680             *
1681             * @param primaryKey the primary key of the company
1682             * @return the company, or <code>null</code> if a company with the primary key could not be found
1683             */
1684            @Override
1685            public Company fetchByPrimaryKey(Serializable primaryKey) {
1686                    Company company = (Company)entityCache.getResult(CompanyModelImpl.ENTITY_CACHE_ENABLED,
1687                                    CompanyImpl.class, primaryKey);
1688    
1689                    if (company == _nullCompany) {
1690                            return null;
1691                    }
1692    
1693                    if (company == null) {
1694                            Session session = null;
1695    
1696                            try {
1697                                    session = openSession();
1698    
1699                                    company = (Company)session.get(CompanyImpl.class, primaryKey);
1700    
1701                                    if (company != null) {
1702                                            cacheResult(company);
1703                                    }
1704                                    else {
1705                                            entityCache.putResult(CompanyModelImpl.ENTITY_CACHE_ENABLED,
1706                                                    CompanyImpl.class, primaryKey, _nullCompany);
1707                                    }
1708                            }
1709                            catch (Exception e) {
1710                                    entityCache.removeResult(CompanyModelImpl.ENTITY_CACHE_ENABLED,
1711                                            CompanyImpl.class, primaryKey);
1712    
1713                                    throw processException(e);
1714                            }
1715                            finally {
1716                                    closeSession(session);
1717                            }
1718                    }
1719    
1720                    return company;
1721            }
1722    
1723            /**
1724             * Returns the company with the primary key or returns <code>null</code> if it could not be found.
1725             *
1726             * @param companyId the primary key of the company
1727             * @return the company, or <code>null</code> if a company with the primary key could not be found
1728             */
1729            @Override
1730            public Company fetchByPrimaryKey(long companyId) {
1731                    return fetchByPrimaryKey((Serializable)companyId);
1732            }
1733    
1734            @Override
1735            public Map<Serializable, Company> fetchByPrimaryKeys(
1736                    Set<Serializable> primaryKeys) {
1737                    if (primaryKeys.isEmpty()) {
1738                            return Collections.emptyMap();
1739                    }
1740    
1741                    Map<Serializable, Company> map = new HashMap<Serializable, Company>();
1742    
1743                    if (primaryKeys.size() == 1) {
1744                            Iterator<Serializable> iterator = primaryKeys.iterator();
1745    
1746                            Serializable primaryKey = iterator.next();
1747    
1748                            Company company = fetchByPrimaryKey(primaryKey);
1749    
1750                            if (company != null) {
1751                                    map.put(primaryKey, company);
1752                            }
1753    
1754                            return map;
1755                    }
1756    
1757                    Set<Serializable> uncachedPrimaryKeys = null;
1758    
1759                    for (Serializable primaryKey : primaryKeys) {
1760                            Company company = (Company)entityCache.getResult(CompanyModelImpl.ENTITY_CACHE_ENABLED,
1761                                            CompanyImpl.class, primaryKey);
1762    
1763                            if (company == null) {
1764                                    if (uncachedPrimaryKeys == null) {
1765                                            uncachedPrimaryKeys = new HashSet<Serializable>();
1766                                    }
1767    
1768                                    uncachedPrimaryKeys.add(primaryKey);
1769                            }
1770                            else {
1771                                    map.put(primaryKey, company);
1772                            }
1773                    }
1774    
1775                    if (uncachedPrimaryKeys == null) {
1776                            return map;
1777                    }
1778    
1779                    StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
1780                                    1);
1781    
1782                    query.append(_SQL_SELECT_COMPANY_WHERE_PKS_IN);
1783    
1784                    for (Serializable primaryKey : uncachedPrimaryKeys) {
1785                            query.append(String.valueOf(primaryKey));
1786    
1787                            query.append(StringPool.COMMA);
1788                    }
1789    
1790                    query.setIndex(query.index() - 1);
1791    
1792                    query.append(StringPool.CLOSE_PARENTHESIS);
1793    
1794                    String sql = query.toString();
1795    
1796                    Session session = null;
1797    
1798                    try {
1799                            session = openSession();
1800    
1801                            Query q = session.createQuery(sql);
1802    
1803                            for (Company company : (List<Company>)q.list()) {
1804                                    map.put(company.getPrimaryKeyObj(), company);
1805    
1806                                    cacheResult(company);
1807    
1808                                    uncachedPrimaryKeys.remove(company.getPrimaryKeyObj());
1809                            }
1810    
1811                            for (Serializable primaryKey : uncachedPrimaryKeys) {
1812                                    entityCache.putResult(CompanyModelImpl.ENTITY_CACHE_ENABLED,
1813                                            CompanyImpl.class, primaryKey, _nullCompany);
1814                            }
1815                    }
1816                    catch (Exception e) {
1817                            throw processException(e);
1818                    }
1819                    finally {
1820                            closeSession(session);
1821                    }
1822    
1823                    return map;
1824            }
1825    
1826            /**
1827             * Returns all the companies.
1828             *
1829             * @return the companies
1830             */
1831            @Override
1832            public List<Company> findAll() {
1833                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1834            }
1835    
1836            /**
1837             * Returns a range of all the companies.
1838             *
1839             * <p>
1840             * 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.
1841             * </p>
1842             *
1843             * @param start the lower bound of the range of companies
1844             * @param end the upper bound of the range of companies (not inclusive)
1845             * @return the range of companies
1846             */
1847            @Override
1848            public List<Company> findAll(int start, int end) {
1849                    return findAll(start, end, null);
1850            }
1851    
1852            /**
1853             * Returns an ordered range of all the companies.
1854             *
1855             * <p>
1856             * 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.
1857             * </p>
1858             *
1859             * @param start the lower bound of the range of companies
1860             * @param end the upper bound of the range of companies (not inclusive)
1861             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1862             * @return the ordered range of companies
1863             */
1864            @Override
1865            public List<Company> findAll(int start, int end,
1866                    OrderByComparator<Company> orderByComparator) {
1867                    return findAll(start, end, orderByComparator, true);
1868            }
1869    
1870            /**
1871             * Returns an ordered range of all the companies.
1872             *
1873             * <p>
1874             * 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.
1875             * </p>
1876             *
1877             * @param start the lower bound of the range of companies
1878             * @param end the upper bound of the range of companies (not inclusive)
1879             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1880             * @param retrieveFromCache whether to retrieve from the finder cache
1881             * @return the ordered range of companies
1882             */
1883            @Override
1884            public List<Company> findAll(int start, int end,
1885                    OrderByComparator<Company> orderByComparator, boolean retrieveFromCache) {
1886                    boolean pagination = true;
1887                    FinderPath finderPath = null;
1888                    Object[] finderArgs = null;
1889    
1890                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1891                                    (orderByComparator == null)) {
1892                            pagination = false;
1893                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1894                            finderArgs = FINDER_ARGS_EMPTY;
1895                    }
1896                    else {
1897                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1898                            finderArgs = new Object[] { start, end, orderByComparator };
1899                    }
1900    
1901                    List<Company> list = null;
1902    
1903                    if (retrieveFromCache) {
1904                            list = (List<Company>)finderCache.getResult(finderPath, finderArgs,
1905                                            this);
1906                    }
1907    
1908                    if (list == null) {
1909                            StringBundler query = null;
1910                            String sql = null;
1911    
1912                            if (orderByComparator != null) {
1913                                    query = new StringBundler(2 +
1914                                                    (orderByComparator.getOrderByFields().length * 2));
1915    
1916                                    query.append(_SQL_SELECT_COMPANY);
1917    
1918                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1919                                            orderByComparator);
1920    
1921                                    sql = query.toString();
1922                            }
1923                            else {
1924                                    sql = _SQL_SELECT_COMPANY;
1925    
1926                                    if (pagination) {
1927                                            sql = sql.concat(CompanyModelImpl.ORDER_BY_JPQL);
1928                                    }
1929                            }
1930    
1931                            Session session = null;
1932    
1933                            try {
1934                                    session = openSession();
1935    
1936                                    Query q = session.createQuery(sql);
1937    
1938                                    if (!pagination) {
1939                                            list = (List<Company>)QueryUtil.list(q, getDialect(),
1940                                                            start, end, false);
1941    
1942                                            Collections.sort(list);
1943    
1944                                            list = Collections.unmodifiableList(list);
1945                                    }
1946                                    else {
1947                                            list = (List<Company>)QueryUtil.list(q, getDialect(),
1948                                                            start, end);
1949                                    }
1950    
1951                                    cacheResult(list);
1952    
1953                                    finderCache.putResult(finderPath, finderArgs, list);
1954                            }
1955                            catch (Exception e) {
1956                                    finderCache.removeResult(finderPath, finderArgs);
1957    
1958                                    throw processException(e);
1959                            }
1960                            finally {
1961                                    closeSession(session);
1962                            }
1963                    }
1964    
1965                    return list;
1966            }
1967    
1968            /**
1969             * Removes all the companies from the database.
1970             *
1971             */
1972            @Override
1973            public void removeAll() {
1974                    for (Company company : findAll()) {
1975                            remove(company);
1976                    }
1977            }
1978    
1979            /**
1980             * Returns the number of companies.
1981             *
1982             * @return the number of companies
1983             */
1984            @Override
1985            public int countAll() {
1986                    Long count = (Long)finderCache.getResult(FINDER_PATH_COUNT_ALL,
1987                                    FINDER_ARGS_EMPTY, this);
1988    
1989                    if (count == null) {
1990                            Session session = null;
1991    
1992                            try {
1993                                    session = openSession();
1994    
1995                                    Query q = session.createQuery(_SQL_COUNT_COMPANY);
1996    
1997                                    count = (Long)q.uniqueResult();
1998    
1999                                    finderCache.putResult(FINDER_PATH_COUNT_ALL, FINDER_ARGS_EMPTY,
2000                                            count);
2001                            }
2002                            catch (Exception e) {
2003                                    finderCache.removeResult(FINDER_PATH_COUNT_ALL,
2004                                            FINDER_ARGS_EMPTY);
2005    
2006                                    throw processException(e);
2007                            }
2008                            finally {
2009                                    closeSession(session);
2010                            }
2011                    }
2012    
2013                    return count.intValue();
2014            }
2015    
2016            @Override
2017            public Set<String> getBadColumnNames() {
2018                    return _badColumnNames;
2019            }
2020    
2021            @Override
2022            protected Map<String, Integer> getTableColumnsMap() {
2023                    return CompanyModelImpl.TABLE_COLUMNS_MAP;
2024            }
2025    
2026            /**
2027             * Initializes the company persistence.
2028             */
2029            public void afterPropertiesSet() {
2030            }
2031    
2032            public void destroy() {
2033                    entityCache.removeCache(CompanyImpl.class.getName());
2034                    finderCache.removeCache(FINDER_CLASS_NAME_ENTITY);
2035                    finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2036                    finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2037            }
2038    
2039            protected EntityCache entityCache = EntityCacheUtil.getEntityCache();
2040            protected FinderCache finderCache = FinderCacheUtil.getFinderCache();
2041            private static final String _SQL_SELECT_COMPANY = "SELECT company FROM Company company";
2042            private static final String _SQL_SELECT_COMPANY_WHERE_PKS_IN = "SELECT company FROM Company company WHERE companyId IN (";
2043            private static final String _SQL_SELECT_COMPANY_WHERE = "SELECT company FROM Company company WHERE ";
2044            private static final String _SQL_COUNT_COMPANY = "SELECT COUNT(company) FROM Company company";
2045            private static final String _SQL_COUNT_COMPANY_WHERE = "SELECT COUNT(company) FROM Company company WHERE ";
2046            private static final String _ORDER_BY_ENTITY_ALIAS = "company.";
2047            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Company exists with the primary key ";
2048            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Company exists with the key {";
2049            private static final Log _log = LogFactoryUtil.getLog(CompanyPersistenceImpl.class);
2050            private static final Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
2051                                    "key", "active"
2052                            });
2053            private static final Company _nullCompany = new CompanyImpl() {
2054                            @Override
2055                            public Object clone() {
2056                                    return this;
2057                            }
2058    
2059                            @Override
2060                            public CacheModel<Company> toCacheModel() {
2061                                    return _nullCompanyCacheModel;
2062                            }
2063                    };
2064    
2065            private static final CacheModel<Company> _nullCompanyCacheModel = new NullCacheModel();
2066    
2067            private static class NullCacheModel implements CacheModel<Company>,
2068                    MVCCModel {
2069                    @Override
2070                    public long getMvccVersion() {
2071                            return -1;
2072                    }
2073    
2074                    @Override
2075                    public void setMvccVersion(long mvccVersion) {
2076                    }
2077    
2078                    @Override
2079                    public Company toEntityModel() {
2080                            return _nullCompany;
2081                    }
2082            }
2083    }