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