001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.service.persistence;
016    
017    import com.liferay.portal.NoSuchCompanyException;
018    import com.liferay.portal.NoSuchModelException;
019    import com.liferay.portal.kernel.annotation.BeanReference;
020    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
021    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
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.SystemException;
029    import com.liferay.portal.kernel.log.Log;
030    import com.liferay.portal.kernel.log.LogFactoryUtil;
031    import com.liferay.portal.kernel.util.GetterUtil;
032    import com.liferay.portal.kernel.util.InstanceFactory;
033    import com.liferay.portal.kernel.util.OrderByComparator;
034    import com.liferay.portal.kernel.util.StringBundler;
035    import com.liferay.portal.kernel.util.StringPool;
036    import com.liferay.portal.kernel.util.StringUtil;
037    import com.liferay.portal.kernel.util.Validator;
038    import com.liferay.portal.model.Company;
039    import com.liferay.portal.model.ModelListener;
040    import com.liferay.portal.model.impl.CompanyImpl;
041    import com.liferay.portal.model.impl.CompanyModelImpl;
042    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
043    
044    import java.io.Serializable;
045    
046    import java.util.ArrayList;
047    import java.util.Collections;
048    import java.util.List;
049    
050    /**
051     * @author    Brian Wing Shun Chan
052     * @see       CompanyPersistence
053     * @see       CompanyUtil
054     * @generated
055     */
056    public class CompanyPersistenceImpl extends BasePersistenceImpl<Company>
057            implements CompanyPersistence {
058            public static final String FINDER_CLASS_NAME_ENTITY = CompanyImpl.class.getName();
059            public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
060                    ".List";
061            public static final FinderPath FINDER_PATH_FETCH_BY_WEBID = new FinderPath(CompanyModelImpl.ENTITY_CACHE_ENABLED,
062                            CompanyModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
063                            "fetchByWebId", new String[] { String.class.getName() });
064            public static final FinderPath FINDER_PATH_COUNT_BY_WEBID = new FinderPath(CompanyModelImpl.ENTITY_CACHE_ENABLED,
065                            CompanyModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
066                            "countByWebId", new String[] { String.class.getName() });
067            public static final FinderPath FINDER_PATH_FETCH_BY_VIRTUALHOST = new FinderPath(CompanyModelImpl.ENTITY_CACHE_ENABLED,
068                            CompanyModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
069                            "fetchByVirtualHost", new String[] { String.class.getName() });
070            public static final FinderPath FINDER_PATH_COUNT_BY_VIRTUALHOST = new FinderPath(CompanyModelImpl.ENTITY_CACHE_ENABLED,
071                            CompanyModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
072                            "countByVirtualHost", new String[] { String.class.getName() });
073            public static final FinderPath FINDER_PATH_FETCH_BY_MX = new FinderPath(CompanyModelImpl.ENTITY_CACHE_ENABLED,
074                            CompanyModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
075                            "fetchByMx", new String[] { String.class.getName() });
076            public static final FinderPath FINDER_PATH_COUNT_BY_MX = new FinderPath(CompanyModelImpl.ENTITY_CACHE_ENABLED,
077                            CompanyModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
078                            "countByMx", new String[] { String.class.getName() });
079            public static final FinderPath FINDER_PATH_FETCH_BY_LOGOID = new FinderPath(CompanyModelImpl.ENTITY_CACHE_ENABLED,
080                            CompanyModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
081                            "fetchByLogoId", new String[] { Long.class.getName() });
082            public static final FinderPath FINDER_PATH_COUNT_BY_LOGOID = new FinderPath(CompanyModelImpl.ENTITY_CACHE_ENABLED,
083                            CompanyModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
084                            "countByLogoId", new String[] { Long.class.getName() });
085            public static final FinderPath FINDER_PATH_FIND_BY_SYSTEM = new FinderPath(CompanyModelImpl.ENTITY_CACHE_ENABLED,
086                            CompanyModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
087                            "findBySystem",
088                            new String[] {
089                                    Boolean.class.getName(),
090                                    
091                            "java.lang.Integer", "java.lang.Integer",
092                                    "com.liferay.portal.kernel.util.OrderByComparator"
093                            });
094            public static final FinderPath FINDER_PATH_COUNT_BY_SYSTEM = new FinderPath(CompanyModelImpl.ENTITY_CACHE_ENABLED,
095                            CompanyModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
096                            "countBySystem", new String[] { Boolean.class.getName() });
097            public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(CompanyModelImpl.ENTITY_CACHE_ENABLED,
098                            CompanyModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
099                            "findAll", new String[0]);
100            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(CompanyModelImpl.ENTITY_CACHE_ENABLED,
101                            CompanyModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
102                            "countAll", new String[0]);
103    
104            public void cacheResult(Company company) {
105                    EntityCacheUtil.putResult(CompanyModelImpl.ENTITY_CACHE_ENABLED,
106                            CompanyImpl.class, company.getPrimaryKey(), company);
107    
108                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_WEBID,
109                            new Object[] { company.getWebId() }, company);
110    
111                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_VIRTUALHOST,
112                            new Object[] { company.getVirtualHost() }, company);
113    
114                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_MX,
115                            new Object[] { company.getMx() }, company);
116    
117                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_LOGOID,
118                            new Object[] { new Long(company.getLogoId()) }, company);
119            }
120    
121            public void cacheResult(List<Company> companies) {
122                    for (Company company : companies) {
123                            if (EntityCacheUtil.getResult(
124                                                    CompanyModelImpl.ENTITY_CACHE_ENABLED,
125                                                    CompanyImpl.class, company.getPrimaryKey(), this) == null) {
126                                    cacheResult(company);
127                            }
128                    }
129            }
130    
131            public void clearCache() {
132                    CacheRegistryUtil.clear(CompanyImpl.class.getName());
133                    EntityCacheUtil.clearCache(CompanyImpl.class.getName());
134                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
135                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
136            }
137    
138            public void clearCache(Company company) {
139                    EntityCacheUtil.removeResult(CompanyModelImpl.ENTITY_CACHE_ENABLED,
140                            CompanyImpl.class, company.getPrimaryKey());
141    
142                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_WEBID,
143                            new Object[] { company.getWebId() });
144    
145                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_VIRTUALHOST,
146                            new Object[] { company.getVirtualHost() });
147    
148                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_MX,
149                            new Object[] { company.getMx() });
150    
151                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_LOGOID,
152                            new Object[] { new Long(company.getLogoId()) });
153            }
154    
155            public Company create(long companyId) {
156                    Company company = new CompanyImpl();
157    
158                    company.setNew(true);
159                    company.setPrimaryKey(companyId);
160    
161                    return company;
162            }
163    
164            public Company remove(Serializable primaryKey)
165                    throws NoSuchModelException, SystemException {
166                    return remove(((Long)primaryKey).longValue());
167            }
168    
169            public Company remove(long companyId)
170                    throws NoSuchCompanyException, SystemException {
171                    Session session = null;
172    
173                    try {
174                            session = openSession();
175    
176                            Company company = (Company)session.get(CompanyImpl.class,
177                                            new Long(companyId));
178    
179                            if (company == null) {
180                                    if (_log.isWarnEnabled()) {
181                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + companyId);
182                                    }
183    
184                                    throw new NoSuchCompanyException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
185                                            companyId);
186                            }
187    
188                            return remove(company);
189                    }
190                    catch (NoSuchCompanyException nsee) {
191                            throw nsee;
192                    }
193                    catch (Exception e) {
194                            throw processException(e);
195                    }
196                    finally {
197                            closeSession(session);
198                    }
199            }
200    
201            protected Company removeImpl(Company company) throws SystemException {
202                    company = toUnwrappedModel(company);
203    
204                    Session session = null;
205    
206                    try {
207                            session = openSession();
208    
209                            if (company.isCachedModel() || BatchSessionUtil.isEnabled()) {
210                                    Object staleObject = session.get(CompanyImpl.class,
211                                                    company.getPrimaryKeyObj());
212    
213                                    if (staleObject != null) {
214                                            session.evict(staleObject);
215                                    }
216                            }
217    
218                            session.delete(company);
219    
220                            session.flush();
221                    }
222                    catch (Exception e) {
223                            throw processException(e);
224                    }
225                    finally {
226                            closeSession(session);
227                    }
228    
229                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
230    
231                    CompanyModelImpl companyModelImpl = (CompanyModelImpl)company;
232    
233                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_WEBID,
234                            new Object[] { companyModelImpl.getOriginalWebId() });
235    
236                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_VIRTUALHOST,
237                            new Object[] { companyModelImpl.getOriginalVirtualHost() });
238    
239                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_MX,
240                            new Object[] { companyModelImpl.getOriginalMx() });
241    
242                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_LOGOID,
243                            new Object[] { new Long(companyModelImpl.getOriginalLogoId()) });
244    
245                    EntityCacheUtil.removeResult(CompanyModelImpl.ENTITY_CACHE_ENABLED,
246                            CompanyImpl.class, company.getPrimaryKey());
247    
248                    return company;
249            }
250    
251            public Company updateImpl(com.liferay.portal.model.Company company,
252                    boolean merge) throws SystemException {
253                    company = toUnwrappedModel(company);
254    
255                    boolean isNew = company.isNew();
256    
257                    CompanyModelImpl companyModelImpl = (CompanyModelImpl)company;
258    
259                    Session session = null;
260    
261                    try {
262                            session = openSession();
263    
264                            BatchSessionUtil.update(session, company, merge);
265    
266                            company.setNew(false);
267                    }
268                    catch (Exception e) {
269                            throw processException(e);
270                    }
271                    finally {
272                            closeSession(session);
273                    }
274    
275                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
276    
277                    EntityCacheUtil.putResult(CompanyModelImpl.ENTITY_CACHE_ENABLED,
278                            CompanyImpl.class, company.getPrimaryKey(), company);
279    
280                    if (!isNew &&
281                                    (!Validator.equals(company.getWebId(),
282                                            companyModelImpl.getOriginalWebId()))) {
283                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_WEBID,
284                                    new Object[] { companyModelImpl.getOriginalWebId() });
285                    }
286    
287                    if (isNew ||
288                                    (!Validator.equals(company.getWebId(),
289                                            companyModelImpl.getOriginalWebId()))) {
290                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_WEBID,
291                                    new Object[] { company.getWebId() }, company);
292                    }
293    
294                    if (!isNew &&
295                                    (!Validator.equals(company.getVirtualHost(),
296                                            companyModelImpl.getOriginalVirtualHost()))) {
297                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_VIRTUALHOST,
298                                    new Object[] { companyModelImpl.getOriginalVirtualHost() });
299                    }
300    
301                    if (isNew ||
302                                    (!Validator.equals(company.getVirtualHost(),
303                                            companyModelImpl.getOriginalVirtualHost()))) {
304                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_VIRTUALHOST,
305                                    new Object[] { company.getVirtualHost() }, company);
306                    }
307    
308                    if (!isNew &&
309                                    (!Validator.equals(company.getMx(),
310                                            companyModelImpl.getOriginalMx()))) {
311                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_MX,
312                                    new Object[] { companyModelImpl.getOriginalMx() });
313                    }
314    
315                    if (isNew ||
316                                    (!Validator.equals(company.getMx(),
317                                            companyModelImpl.getOriginalMx()))) {
318                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_MX,
319                                    new Object[] { company.getMx() }, company);
320                    }
321    
322                    if (!isNew &&
323                                    (company.getLogoId() != companyModelImpl.getOriginalLogoId())) {
324                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_LOGOID,
325                                    new Object[] { new Long(companyModelImpl.getOriginalLogoId()) });
326                    }
327    
328                    if (isNew ||
329                                    (company.getLogoId() != companyModelImpl.getOriginalLogoId())) {
330                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_LOGOID,
331                                    new Object[] { new Long(company.getLogoId()) }, company);
332                    }
333    
334                    return company;
335            }
336    
337            protected Company toUnwrappedModel(Company company) {
338                    if (company instanceof CompanyImpl) {
339                            return company;
340                    }
341    
342                    CompanyImpl companyImpl = new CompanyImpl();
343    
344                    companyImpl.setNew(company.isNew());
345                    companyImpl.setPrimaryKey(company.getPrimaryKey());
346    
347                    companyImpl.setCompanyId(company.getCompanyId());
348                    companyImpl.setAccountId(company.getAccountId());
349                    companyImpl.setWebId(company.getWebId());
350                    companyImpl.setKey(company.getKey());
351                    companyImpl.setVirtualHost(company.getVirtualHost());
352                    companyImpl.setMx(company.getMx());
353                    companyImpl.setHomeURL(company.getHomeURL());
354                    companyImpl.setLogoId(company.getLogoId());
355                    companyImpl.setSystem(company.isSystem());
356                    companyImpl.setMaxUsers(company.getMaxUsers());
357    
358                    return companyImpl;
359            }
360    
361            public Company findByPrimaryKey(Serializable primaryKey)
362                    throws NoSuchModelException, SystemException {
363                    return findByPrimaryKey(((Long)primaryKey).longValue());
364            }
365    
366            public Company findByPrimaryKey(long companyId)
367                    throws NoSuchCompanyException, SystemException {
368                    Company company = fetchByPrimaryKey(companyId);
369    
370                    if (company == null) {
371                            if (_log.isWarnEnabled()) {
372                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + companyId);
373                            }
374    
375                            throw new NoSuchCompanyException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
376                                    companyId);
377                    }
378    
379                    return company;
380            }
381    
382            public Company fetchByPrimaryKey(Serializable primaryKey)
383                    throws SystemException {
384                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
385            }
386    
387            public Company fetchByPrimaryKey(long companyId) throws SystemException {
388                    Company company = (Company)EntityCacheUtil.getResult(CompanyModelImpl.ENTITY_CACHE_ENABLED,
389                                    CompanyImpl.class, companyId, this);
390    
391                    if (company == null) {
392                            Session session = null;
393    
394                            try {
395                                    session = openSession();
396    
397                                    company = (Company)session.get(CompanyImpl.class,
398                                                    new Long(companyId));
399                            }
400                            catch (Exception e) {
401                                    throw processException(e);
402                            }
403                            finally {
404                                    if (company != null) {
405                                            cacheResult(company);
406                                    }
407    
408                                    closeSession(session);
409                            }
410                    }
411    
412                    return company;
413            }
414    
415            public Company findByWebId(String webId)
416                    throws NoSuchCompanyException, SystemException {
417                    Company company = fetchByWebId(webId);
418    
419                    if (company == null) {
420                            StringBundler msg = new StringBundler(4);
421    
422                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
423    
424                            msg.append("webId=");
425                            msg.append(webId);
426    
427                            msg.append(StringPool.CLOSE_CURLY_BRACE);
428    
429                            if (_log.isWarnEnabled()) {
430                                    _log.warn(msg.toString());
431                            }
432    
433                            throw new NoSuchCompanyException(msg.toString());
434                    }
435    
436                    return company;
437            }
438    
439            public Company fetchByWebId(String webId) throws SystemException {
440                    return fetchByWebId(webId, true);
441            }
442    
443            public Company fetchByWebId(String webId, boolean retrieveFromCache)
444                    throws SystemException {
445                    Object[] finderArgs = new Object[] { webId };
446    
447                    Object result = null;
448    
449                    if (retrieveFromCache) {
450                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_WEBID,
451                                            finderArgs, this);
452                    }
453    
454                    if (result == null) {
455                            Session session = null;
456    
457                            try {
458                                    session = openSession();
459    
460                                    StringBundler query = new StringBundler(2);
461    
462                                    query.append(_SQL_SELECT_COMPANY_WHERE);
463    
464                                    if (webId == null) {
465                                            query.append(_FINDER_COLUMN_WEBID_WEBID_1);
466                                    }
467                                    else {
468                                            if (webId.equals(StringPool.BLANK)) {
469                                                    query.append(_FINDER_COLUMN_WEBID_WEBID_3);
470                                            }
471                                            else {
472                                                    query.append(_FINDER_COLUMN_WEBID_WEBID_2);
473                                            }
474                                    }
475    
476                                    String sql = query.toString();
477    
478                                    Query q = session.createQuery(sql);
479    
480                                    QueryPos qPos = QueryPos.getInstance(q);
481    
482                                    if (webId != null) {
483                                            qPos.add(webId);
484                                    }
485    
486                                    List<Company> list = q.list();
487    
488                                    result = list;
489    
490                                    Company company = null;
491    
492                                    if (list.isEmpty()) {
493                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_WEBID,
494                                                    finderArgs, list);
495                                    }
496                                    else {
497                                            company = list.get(0);
498    
499                                            cacheResult(company);
500    
501                                            if ((company.getWebId() == null) ||
502                                                            !company.getWebId().equals(webId)) {
503                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_WEBID,
504                                                            finderArgs, company);
505                                            }
506                                    }
507    
508                                    return company;
509                            }
510                            catch (Exception e) {
511                                    throw processException(e);
512                            }
513                            finally {
514                                    if (result == null) {
515                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_WEBID,
516                                                    finderArgs, new ArrayList<Company>());
517                                    }
518    
519                                    closeSession(session);
520                            }
521                    }
522                    else {
523                            if (result instanceof List<?>) {
524                                    return null;
525                            }
526                            else {
527                                    return (Company)result;
528                            }
529                    }
530            }
531    
532            public Company findByVirtualHost(String virtualHost)
533                    throws NoSuchCompanyException, SystemException {
534                    Company company = fetchByVirtualHost(virtualHost);
535    
536                    if (company == null) {
537                            StringBundler msg = new StringBundler(4);
538    
539                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
540    
541                            msg.append("virtualHost=");
542                            msg.append(virtualHost);
543    
544                            msg.append(StringPool.CLOSE_CURLY_BRACE);
545    
546                            if (_log.isWarnEnabled()) {
547                                    _log.warn(msg.toString());
548                            }
549    
550                            throw new NoSuchCompanyException(msg.toString());
551                    }
552    
553                    return company;
554            }
555    
556            public Company fetchByVirtualHost(String virtualHost)
557                    throws SystemException {
558                    return fetchByVirtualHost(virtualHost, true);
559            }
560    
561            public Company fetchByVirtualHost(String virtualHost,
562                    boolean retrieveFromCache) throws SystemException {
563                    Object[] finderArgs = new Object[] { virtualHost };
564    
565                    Object result = null;
566    
567                    if (retrieveFromCache) {
568                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_VIRTUALHOST,
569                                            finderArgs, this);
570                    }
571    
572                    if (result == null) {
573                            Session session = null;
574    
575                            try {
576                                    session = openSession();
577    
578                                    StringBundler query = new StringBundler(2);
579    
580                                    query.append(_SQL_SELECT_COMPANY_WHERE);
581    
582                                    if (virtualHost == null) {
583                                            query.append(_FINDER_COLUMN_VIRTUALHOST_VIRTUALHOST_1);
584                                    }
585                                    else {
586                                            if (virtualHost.equals(StringPool.BLANK)) {
587                                                    query.append(_FINDER_COLUMN_VIRTUALHOST_VIRTUALHOST_3);
588                                            }
589                                            else {
590                                                    query.append(_FINDER_COLUMN_VIRTUALHOST_VIRTUALHOST_2);
591                                            }
592                                    }
593    
594                                    String sql = query.toString();
595    
596                                    Query q = session.createQuery(sql);
597    
598                                    QueryPos qPos = QueryPos.getInstance(q);
599    
600                                    if (virtualHost != null) {
601                                            qPos.add(virtualHost);
602                                    }
603    
604                                    List<Company> list = q.list();
605    
606                                    result = list;
607    
608                                    Company company = null;
609    
610                                    if (list.isEmpty()) {
611                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_VIRTUALHOST,
612                                                    finderArgs, list);
613                                    }
614                                    else {
615                                            company = list.get(0);
616    
617                                            cacheResult(company);
618    
619                                            if ((company.getVirtualHost() == null) ||
620                                                            !company.getVirtualHost().equals(virtualHost)) {
621                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_VIRTUALHOST,
622                                                            finderArgs, company);
623                                            }
624                                    }
625    
626                                    return company;
627                            }
628                            catch (Exception e) {
629                                    throw processException(e);
630                            }
631                            finally {
632                                    if (result == null) {
633                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_VIRTUALHOST,
634                                                    finderArgs, new ArrayList<Company>());
635                                    }
636    
637                                    closeSession(session);
638                            }
639                    }
640                    else {
641                            if (result instanceof List<?>) {
642                                    return null;
643                            }
644                            else {
645                                    return (Company)result;
646                            }
647                    }
648            }
649    
650            public Company findByMx(String mx)
651                    throws NoSuchCompanyException, SystemException {
652                    Company company = fetchByMx(mx);
653    
654                    if (company == null) {
655                            StringBundler msg = new StringBundler(4);
656    
657                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
658    
659                            msg.append("mx=");
660                            msg.append(mx);
661    
662                            msg.append(StringPool.CLOSE_CURLY_BRACE);
663    
664                            if (_log.isWarnEnabled()) {
665                                    _log.warn(msg.toString());
666                            }
667    
668                            throw new NoSuchCompanyException(msg.toString());
669                    }
670    
671                    return company;
672            }
673    
674            public Company fetchByMx(String mx) throws SystemException {
675                    return fetchByMx(mx, true);
676            }
677    
678            public Company fetchByMx(String mx, boolean retrieveFromCache)
679                    throws SystemException {
680                    Object[] finderArgs = new Object[] { mx };
681    
682                    Object result = null;
683    
684                    if (retrieveFromCache) {
685                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_MX,
686                                            finderArgs, this);
687                    }
688    
689                    if (result == null) {
690                            Session session = null;
691    
692                            try {
693                                    session = openSession();
694    
695                                    StringBundler query = new StringBundler(2);
696    
697                                    query.append(_SQL_SELECT_COMPANY_WHERE);
698    
699                                    if (mx == null) {
700                                            query.append(_FINDER_COLUMN_MX_MX_1);
701                                    }
702                                    else {
703                                            if (mx.equals(StringPool.BLANK)) {
704                                                    query.append(_FINDER_COLUMN_MX_MX_3);
705                                            }
706                                            else {
707                                                    query.append(_FINDER_COLUMN_MX_MX_2);
708                                            }
709                                    }
710    
711                                    String sql = query.toString();
712    
713                                    Query q = session.createQuery(sql);
714    
715                                    QueryPos qPos = QueryPos.getInstance(q);
716    
717                                    if (mx != null) {
718                                            qPos.add(mx);
719                                    }
720    
721                                    List<Company> list = q.list();
722    
723                                    result = list;
724    
725                                    Company company = null;
726    
727                                    if (list.isEmpty()) {
728                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_MX,
729                                                    finderArgs, list);
730                                    }
731                                    else {
732                                            company = list.get(0);
733    
734                                            cacheResult(company);
735    
736                                            if ((company.getMx() == null) ||
737                                                            !company.getMx().equals(mx)) {
738                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_MX,
739                                                            finderArgs, company);
740                                            }
741                                    }
742    
743                                    return company;
744                            }
745                            catch (Exception e) {
746                                    throw processException(e);
747                            }
748                            finally {
749                                    if (result == null) {
750                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_MX,
751                                                    finderArgs, new ArrayList<Company>());
752                                    }
753    
754                                    closeSession(session);
755                            }
756                    }
757                    else {
758                            if (result instanceof List<?>) {
759                                    return null;
760                            }
761                            else {
762                                    return (Company)result;
763                            }
764                    }
765            }
766    
767            public Company findByLogoId(long logoId)
768                    throws NoSuchCompanyException, SystemException {
769                    Company company = fetchByLogoId(logoId);
770    
771                    if (company == null) {
772                            StringBundler msg = new StringBundler(4);
773    
774                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
775    
776                            msg.append("logoId=");
777                            msg.append(logoId);
778    
779                            msg.append(StringPool.CLOSE_CURLY_BRACE);
780    
781                            if (_log.isWarnEnabled()) {
782                                    _log.warn(msg.toString());
783                            }
784    
785                            throw new NoSuchCompanyException(msg.toString());
786                    }
787    
788                    return company;
789            }
790    
791            public Company fetchByLogoId(long logoId) throws SystemException {
792                    return fetchByLogoId(logoId, true);
793            }
794    
795            public Company fetchByLogoId(long logoId, boolean retrieveFromCache)
796                    throws SystemException {
797                    Object[] finderArgs = new Object[] { logoId };
798    
799                    Object result = null;
800    
801                    if (retrieveFromCache) {
802                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_LOGOID,
803                                            finderArgs, this);
804                    }
805    
806                    if (result == null) {
807                            Session session = null;
808    
809                            try {
810                                    session = openSession();
811    
812                                    StringBundler query = new StringBundler(2);
813    
814                                    query.append(_SQL_SELECT_COMPANY_WHERE);
815    
816                                    query.append(_FINDER_COLUMN_LOGOID_LOGOID_2);
817    
818                                    String sql = query.toString();
819    
820                                    Query q = session.createQuery(sql);
821    
822                                    QueryPos qPos = QueryPos.getInstance(q);
823    
824                                    qPos.add(logoId);
825    
826                                    List<Company> list = q.list();
827    
828                                    result = list;
829    
830                                    Company company = null;
831    
832                                    if (list.isEmpty()) {
833                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_LOGOID,
834                                                    finderArgs, list);
835                                    }
836                                    else {
837                                            company = list.get(0);
838    
839                                            cacheResult(company);
840    
841                                            if ((company.getLogoId() != logoId)) {
842                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_LOGOID,
843                                                            finderArgs, company);
844                                            }
845                                    }
846    
847                                    return company;
848                            }
849                            catch (Exception e) {
850                                    throw processException(e);
851                            }
852                            finally {
853                                    if (result == null) {
854                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_LOGOID,
855                                                    finderArgs, new ArrayList<Company>());
856                                    }
857    
858                                    closeSession(session);
859                            }
860                    }
861                    else {
862                            if (result instanceof List<?>) {
863                                    return null;
864                            }
865                            else {
866                                    return (Company)result;
867                            }
868                    }
869            }
870    
871            public List<Company> findBySystem(boolean system) throws SystemException {
872                    return findBySystem(system, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
873            }
874    
875            public List<Company> findBySystem(boolean system, int start, int end)
876                    throws SystemException {
877                    return findBySystem(system, start, end, null);
878            }
879    
880            public List<Company> findBySystem(boolean system, int start, int end,
881                    OrderByComparator orderByComparator) throws SystemException {
882                    Object[] finderArgs = new Object[] {
883                                    system,
884                                    
885                                    String.valueOf(start), String.valueOf(end),
886                                    String.valueOf(orderByComparator)
887                            };
888    
889                    List<Company> list = (List<Company>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_SYSTEM,
890                                    finderArgs, this);
891    
892                    if (list == null) {
893                            Session session = null;
894    
895                            try {
896                                    session = openSession();
897    
898                                    StringBundler query = null;
899    
900                                    if (orderByComparator != null) {
901                                            query = new StringBundler(3 +
902                                                            (orderByComparator.getOrderByFields().length * 3));
903                                    }
904                                    else {
905                                            query = new StringBundler(2);
906                                    }
907    
908                                    query.append(_SQL_SELECT_COMPANY_WHERE);
909    
910                                    query.append(_FINDER_COLUMN_SYSTEM_SYSTEM_2);
911    
912                                    if (orderByComparator != null) {
913                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
914                                                    orderByComparator);
915                                    }
916    
917                                    String sql = query.toString();
918    
919                                    Query q = session.createQuery(sql);
920    
921                                    QueryPos qPos = QueryPos.getInstance(q);
922    
923                                    qPos.add(system);
924    
925                                    list = (List<Company>)QueryUtil.list(q, getDialect(), start, end);
926                            }
927                            catch (Exception e) {
928                                    throw processException(e);
929                            }
930                            finally {
931                                    if (list == null) {
932                                            list = new ArrayList<Company>();
933                                    }
934    
935                                    cacheResult(list);
936    
937                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_SYSTEM,
938                                            finderArgs, list);
939    
940                                    closeSession(session);
941                            }
942                    }
943    
944                    return list;
945            }
946    
947            public Company findBySystem_First(boolean system,
948                    OrderByComparator orderByComparator)
949                    throws NoSuchCompanyException, SystemException {
950                    List<Company> list = findBySystem(system, 0, 1, orderByComparator);
951    
952                    if (list.isEmpty()) {
953                            StringBundler msg = new StringBundler(4);
954    
955                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
956    
957                            msg.append("system=");
958                            msg.append(system);
959    
960                            msg.append(StringPool.CLOSE_CURLY_BRACE);
961    
962                            throw new NoSuchCompanyException(msg.toString());
963                    }
964                    else {
965                            return list.get(0);
966                    }
967            }
968    
969            public Company findBySystem_Last(boolean system,
970                    OrderByComparator orderByComparator)
971                    throws NoSuchCompanyException, SystemException {
972                    int count = countBySystem(system);
973    
974                    List<Company> list = findBySystem(system, count - 1, count,
975                                    orderByComparator);
976    
977                    if (list.isEmpty()) {
978                            StringBundler msg = new StringBundler(4);
979    
980                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
981    
982                            msg.append("system=");
983                            msg.append(system);
984    
985                            msg.append(StringPool.CLOSE_CURLY_BRACE);
986    
987                            throw new NoSuchCompanyException(msg.toString());
988                    }
989                    else {
990                            return list.get(0);
991                    }
992            }
993    
994            public Company[] findBySystem_PrevAndNext(long companyId, boolean system,
995                    OrderByComparator orderByComparator)
996                    throws NoSuchCompanyException, SystemException {
997                    Company company = findByPrimaryKey(companyId);
998    
999                    Session session = null;
1000    
1001                    try {
1002                            session = openSession();
1003    
1004                            Company[] array = new CompanyImpl[3];
1005    
1006                            array[0] = getBySystem_PrevAndNext(session, company, system,
1007                                            orderByComparator, true);
1008    
1009                            array[1] = company;
1010    
1011                            array[2] = getBySystem_PrevAndNext(session, company, system,
1012                                            orderByComparator, false);
1013    
1014                            return array;
1015                    }
1016                    catch (Exception e) {
1017                            throw processException(e);
1018                    }
1019                    finally {
1020                            closeSession(session);
1021                    }
1022            }
1023    
1024            protected Company getBySystem_PrevAndNext(Session session, Company company,
1025                    boolean system, OrderByComparator orderByComparator, boolean previous) {
1026                    StringBundler query = null;
1027    
1028                    if (orderByComparator != null) {
1029                            query = new StringBundler(6 +
1030                                            (orderByComparator.getOrderByFields().length * 6));
1031                    }
1032                    else {
1033                            query = new StringBundler(3);
1034                    }
1035    
1036                    query.append(_SQL_SELECT_COMPANY_WHERE);
1037    
1038                    query.append(_FINDER_COLUMN_SYSTEM_SYSTEM_2);
1039    
1040                    if (orderByComparator != null) {
1041                            String[] orderByFields = orderByComparator.getOrderByFields();
1042    
1043                            if (orderByFields.length > 0) {
1044                                    query.append(WHERE_AND);
1045                            }
1046    
1047                            for (int i = 0; i < orderByFields.length; i++) {
1048                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1049                                    query.append(orderByFields[i]);
1050    
1051                                    if ((i + 1) < orderByFields.length) {
1052                                            if (orderByComparator.isAscending() ^ previous) {
1053                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1054                                            }
1055                                            else {
1056                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1057                                            }
1058                                    }
1059                                    else {
1060                                            if (orderByComparator.isAscending() ^ previous) {
1061                                                    query.append(WHERE_GREATER_THAN);
1062                                            }
1063                                            else {
1064                                                    query.append(WHERE_LESSER_THAN);
1065                                            }
1066                                    }
1067                            }
1068    
1069                            query.append(ORDER_BY_CLAUSE);
1070    
1071                            for (int i = 0; i < orderByFields.length; i++) {
1072                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1073                                    query.append(orderByFields[i]);
1074    
1075                                    if ((i + 1) < orderByFields.length) {
1076                                            if (orderByComparator.isAscending() ^ previous) {
1077                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1078                                            }
1079                                            else {
1080                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1081                                            }
1082                                    }
1083                                    else {
1084                                            if (orderByComparator.isAscending() ^ previous) {
1085                                                    query.append(ORDER_BY_ASC);
1086                                            }
1087                                            else {
1088                                                    query.append(ORDER_BY_DESC);
1089                                            }
1090                                    }
1091                            }
1092                    }
1093    
1094                    String sql = query.toString();
1095    
1096                    Query q = session.createQuery(sql);
1097    
1098                    q.setFirstResult(0);
1099                    q.setMaxResults(2);
1100    
1101                    QueryPos qPos = QueryPos.getInstance(q);
1102    
1103                    qPos.add(system);
1104    
1105                    if (orderByComparator != null) {
1106                            Object[] values = orderByComparator.getOrderByValues(company);
1107    
1108                            for (Object value : values) {
1109                                    qPos.add(value);
1110                            }
1111                    }
1112    
1113                    List<Company> list = q.list();
1114    
1115                    if (list.size() == 2) {
1116                            return list.get(1);
1117                    }
1118                    else {
1119                            return null;
1120                    }
1121            }
1122    
1123            public List<Company> findAll() throws SystemException {
1124                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1125            }
1126    
1127            public List<Company> findAll(int start, int end) throws SystemException {
1128                    return findAll(start, end, null);
1129            }
1130    
1131            public List<Company> findAll(int start, int end,
1132                    OrderByComparator orderByComparator) throws SystemException {
1133                    Object[] finderArgs = new Object[] {
1134                                    String.valueOf(start), String.valueOf(end),
1135                                    String.valueOf(orderByComparator)
1136                            };
1137    
1138                    List<Company> list = (List<Company>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1139                                    finderArgs, this);
1140    
1141                    if (list == null) {
1142                            Session session = null;
1143    
1144                            try {
1145                                    session = openSession();
1146    
1147                                    StringBundler query = null;
1148                                    String sql = null;
1149    
1150                                    if (orderByComparator != null) {
1151                                            query = new StringBundler(2 +
1152                                                            (orderByComparator.getOrderByFields().length * 3));
1153    
1154                                            query.append(_SQL_SELECT_COMPANY);
1155    
1156                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1157                                                    orderByComparator);
1158    
1159                                            sql = query.toString();
1160                                    }
1161                                    else {
1162                                            sql = _SQL_SELECT_COMPANY;
1163                                    }
1164    
1165                                    Query q = session.createQuery(sql);
1166    
1167                                    if (orderByComparator == null) {
1168                                            list = (List<Company>)QueryUtil.list(q, getDialect(),
1169                                                            start, end, false);
1170    
1171                                            Collections.sort(list);
1172                                    }
1173                                    else {
1174                                            list = (List<Company>)QueryUtil.list(q, getDialect(),
1175                                                            start, end);
1176                                    }
1177                            }
1178                            catch (Exception e) {
1179                                    throw processException(e);
1180                            }
1181                            finally {
1182                                    if (list == null) {
1183                                            list = new ArrayList<Company>();
1184                                    }
1185    
1186                                    cacheResult(list);
1187    
1188                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1189    
1190                                    closeSession(session);
1191                            }
1192                    }
1193    
1194                    return list;
1195            }
1196    
1197            public void removeByWebId(String webId)
1198                    throws NoSuchCompanyException, SystemException {
1199                    Company company = findByWebId(webId);
1200    
1201                    remove(company);
1202            }
1203    
1204            public void removeByVirtualHost(String virtualHost)
1205                    throws NoSuchCompanyException, SystemException {
1206                    Company company = findByVirtualHost(virtualHost);
1207    
1208                    remove(company);
1209            }
1210    
1211            public void removeByMx(String mx)
1212                    throws NoSuchCompanyException, SystemException {
1213                    Company company = findByMx(mx);
1214    
1215                    remove(company);
1216            }
1217    
1218            public void removeByLogoId(long logoId)
1219                    throws NoSuchCompanyException, SystemException {
1220                    Company company = findByLogoId(logoId);
1221    
1222                    remove(company);
1223            }
1224    
1225            public void removeBySystem(boolean system) throws SystemException {
1226                    for (Company company : findBySystem(system)) {
1227                            remove(company);
1228                    }
1229            }
1230    
1231            public void removeAll() throws SystemException {
1232                    for (Company company : findAll()) {
1233                            remove(company);
1234                    }
1235            }
1236    
1237            public int countByWebId(String webId) throws SystemException {
1238                    Object[] finderArgs = new Object[] { webId };
1239    
1240                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_WEBID,
1241                                    finderArgs, this);
1242    
1243                    if (count == null) {
1244                            Session session = null;
1245    
1246                            try {
1247                                    session = openSession();
1248    
1249                                    StringBundler query = new StringBundler(2);
1250    
1251                                    query.append(_SQL_COUNT_COMPANY_WHERE);
1252    
1253                                    if (webId == null) {
1254                                            query.append(_FINDER_COLUMN_WEBID_WEBID_1);
1255                                    }
1256                                    else {
1257                                            if (webId.equals(StringPool.BLANK)) {
1258                                                    query.append(_FINDER_COLUMN_WEBID_WEBID_3);
1259                                            }
1260                                            else {
1261                                                    query.append(_FINDER_COLUMN_WEBID_WEBID_2);
1262                                            }
1263                                    }
1264    
1265                                    String sql = query.toString();
1266    
1267                                    Query q = session.createQuery(sql);
1268    
1269                                    QueryPos qPos = QueryPos.getInstance(q);
1270    
1271                                    if (webId != null) {
1272                                            qPos.add(webId);
1273                                    }
1274    
1275                                    count = (Long)q.uniqueResult();
1276                            }
1277                            catch (Exception e) {
1278                                    throw processException(e);
1279                            }
1280                            finally {
1281                                    if (count == null) {
1282                                            count = Long.valueOf(0);
1283                                    }
1284    
1285                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_WEBID,
1286                                            finderArgs, count);
1287    
1288                                    closeSession(session);
1289                            }
1290                    }
1291    
1292                    return count.intValue();
1293            }
1294    
1295            public int countByVirtualHost(String virtualHost) throws SystemException {
1296                    Object[] finderArgs = new Object[] { virtualHost };
1297    
1298                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_VIRTUALHOST,
1299                                    finderArgs, this);
1300    
1301                    if (count == null) {
1302                            Session session = null;
1303    
1304                            try {
1305                                    session = openSession();
1306    
1307                                    StringBundler query = new StringBundler(2);
1308    
1309                                    query.append(_SQL_COUNT_COMPANY_WHERE);
1310    
1311                                    if (virtualHost == null) {
1312                                            query.append(_FINDER_COLUMN_VIRTUALHOST_VIRTUALHOST_1);
1313                                    }
1314                                    else {
1315                                            if (virtualHost.equals(StringPool.BLANK)) {
1316                                                    query.append(_FINDER_COLUMN_VIRTUALHOST_VIRTUALHOST_3);
1317                                            }
1318                                            else {
1319                                                    query.append(_FINDER_COLUMN_VIRTUALHOST_VIRTUALHOST_2);
1320                                            }
1321                                    }
1322    
1323                                    String sql = query.toString();
1324    
1325                                    Query q = session.createQuery(sql);
1326    
1327                                    QueryPos qPos = QueryPos.getInstance(q);
1328    
1329                                    if (virtualHost != null) {
1330                                            qPos.add(virtualHost);
1331                                    }
1332    
1333                                    count = (Long)q.uniqueResult();
1334                            }
1335                            catch (Exception e) {
1336                                    throw processException(e);
1337                            }
1338                            finally {
1339                                    if (count == null) {
1340                                            count = Long.valueOf(0);
1341                                    }
1342    
1343                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_VIRTUALHOST,
1344                                            finderArgs, count);
1345    
1346                                    closeSession(session);
1347                            }
1348                    }
1349    
1350                    return count.intValue();
1351            }
1352    
1353            public int countByMx(String mx) throws SystemException {
1354                    Object[] finderArgs = new Object[] { mx };
1355    
1356                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_MX,
1357                                    finderArgs, this);
1358    
1359                    if (count == null) {
1360                            Session session = null;
1361    
1362                            try {
1363                                    session = openSession();
1364    
1365                                    StringBundler query = new StringBundler(2);
1366    
1367                                    query.append(_SQL_COUNT_COMPANY_WHERE);
1368    
1369                                    if (mx == null) {
1370                                            query.append(_FINDER_COLUMN_MX_MX_1);
1371                                    }
1372                                    else {
1373                                            if (mx.equals(StringPool.BLANK)) {
1374                                                    query.append(_FINDER_COLUMN_MX_MX_3);
1375                                            }
1376                                            else {
1377                                                    query.append(_FINDER_COLUMN_MX_MX_2);
1378                                            }
1379                                    }
1380    
1381                                    String sql = query.toString();
1382    
1383                                    Query q = session.createQuery(sql);
1384    
1385                                    QueryPos qPos = QueryPos.getInstance(q);
1386    
1387                                    if (mx != null) {
1388                                            qPos.add(mx);
1389                                    }
1390    
1391                                    count = (Long)q.uniqueResult();
1392                            }
1393                            catch (Exception e) {
1394                                    throw processException(e);
1395                            }
1396                            finally {
1397                                    if (count == null) {
1398                                            count = Long.valueOf(0);
1399                                    }
1400    
1401                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_MX, finderArgs,
1402                                            count);
1403    
1404                                    closeSession(session);
1405                            }
1406                    }
1407    
1408                    return count.intValue();
1409            }
1410    
1411            public int countByLogoId(long logoId) throws SystemException {
1412                    Object[] finderArgs = new Object[] { logoId };
1413    
1414                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_LOGOID,
1415                                    finderArgs, this);
1416    
1417                    if (count == null) {
1418                            Session session = null;
1419    
1420                            try {
1421                                    session = openSession();
1422    
1423                                    StringBundler query = new StringBundler(2);
1424    
1425                                    query.append(_SQL_COUNT_COMPANY_WHERE);
1426    
1427                                    query.append(_FINDER_COLUMN_LOGOID_LOGOID_2);
1428    
1429                                    String sql = query.toString();
1430    
1431                                    Query q = session.createQuery(sql);
1432    
1433                                    QueryPos qPos = QueryPos.getInstance(q);
1434    
1435                                    qPos.add(logoId);
1436    
1437                                    count = (Long)q.uniqueResult();
1438                            }
1439                            catch (Exception e) {
1440                                    throw processException(e);
1441                            }
1442                            finally {
1443                                    if (count == null) {
1444                                            count = Long.valueOf(0);
1445                                    }
1446    
1447                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_LOGOID,
1448                                            finderArgs, count);
1449    
1450                                    closeSession(session);
1451                            }
1452                    }
1453    
1454                    return count.intValue();
1455            }
1456    
1457            public int countBySystem(boolean system) throws SystemException {
1458                    Object[] finderArgs = new Object[] { system };
1459    
1460                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_SYSTEM,
1461                                    finderArgs, this);
1462    
1463                    if (count == null) {
1464                            Session session = null;
1465    
1466                            try {
1467                                    session = openSession();
1468    
1469                                    StringBundler query = new StringBundler(2);
1470    
1471                                    query.append(_SQL_COUNT_COMPANY_WHERE);
1472    
1473                                    query.append(_FINDER_COLUMN_SYSTEM_SYSTEM_2);
1474    
1475                                    String sql = query.toString();
1476    
1477                                    Query q = session.createQuery(sql);
1478    
1479                                    QueryPos qPos = QueryPos.getInstance(q);
1480    
1481                                    qPos.add(system);
1482    
1483                                    count = (Long)q.uniqueResult();
1484                            }
1485                            catch (Exception e) {
1486                                    throw processException(e);
1487                            }
1488                            finally {
1489                                    if (count == null) {
1490                                            count = Long.valueOf(0);
1491                                    }
1492    
1493                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_SYSTEM,
1494                                            finderArgs, count);
1495    
1496                                    closeSession(session);
1497                            }
1498                    }
1499    
1500                    return count.intValue();
1501            }
1502    
1503            public int countAll() throws SystemException {
1504                    Object[] finderArgs = new Object[0];
1505    
1506                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1507                                    finderArgs, this);
1508    
1509                    if (count == null) {
1510                            Session session = null;
1511    
1512                            try {
1513                                    session = openSession();
1514    
1515                                    Query q = session.createQuery(_SQL_COUNT_COMPANY);
1516    
1517                                    count = (Long)q.uniqueResult();
1518                            }
1519                            catch (Exception e) {
1520                                    throw processException(e);
1521                            }
1522                            finally {
1523                                    if (count == null) {
1524                                            count = Long.valueOf(0);
1525                                    }
1526    
1527                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1528                                            count);
1529    
1530                                    closeSession(session);
1531                            }
1532                    }
1533    
1534                    return count.intValue();
1535            }
1536    
1537            public void afterPropertiesSet() {
1538                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1539                                            com.liferay.portal.util.PropsUtil.get(
1540                                                    "value.object.listener.com.liferay.portal.model.Company")));
1541    
1542                    if (listenerClassNames.length > 0) {
1543                            try {
1544                                    List<ModelListener<Company>> listenersList = new ArrayList<ModelListener<Company>>();
1545    
1546                                    for (String listenerClassName : listenerClassNames) {
1547                                            listenersList.add((ModelListener<Company>)InstanceFactory.newInstance(
1548                                                            listenerClassName));
1549                                    }
1550    
1551                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1552                            }
1553                            catch (Exception e) {
1554                                    _log.error(e);
1555                            }
1556                    }
1557            }
1558    
1559            @BeanReference(type = AccountPersistence.class)
1560            protected AccountPersistence accountPersistence;
1561            @BeanReference(type = AddressPersistence.class)
1562            protected AddressPersistence addressPersistence;
1563            @BeanReference(type = BrowserTrackerPersistence.class)
1564            protected BrowserTrackerPersistence browserTrackerPersistence;
1565            @BeanReference(type = ClassNamePersistence.class)
1566            protected ClassNamePersistence classNamePersistence;
1567            @BeanReference(type = CompanyPersistence.class)
1568            protected CompanyPersistence companyPersistence;
1569            @BeanReference(type = ContactPersistence.class)
1570            protected ContactPersistence contactPersistence;
1571            @BeanReference(type = CountryPersistence.class)
1572            protected CountryPersistence countryPersistence;
1573            @BeanReference(type = EmailAddressPersistence.class)
1574            protected EmailAddressPersistence emailAddressPersistence;
1575            @BeanReference(type = GroupPersistence.class)
1576            protected GroupPersistence groupPersistence;
1577            @BeanReference(type = ImagePersistence.class)
1578            protected ImagePersistence imagePersistence;
1579            @BeanReference(type = LayoutPersistence.class)
1580            protected LayoutPersistence layoutPersistence;
1581            @BeanReference(type = LayoutPrototypePersistence.class)
1582            protected LayoutPrototypePersistence layoutPrototypePersistence;
1583            @BeanReference(type = LayoutSetPersistence.class)
1584            protected LayoutSetPersistence layoutSetPersistence;
1585            @BeanReference(type = LayoutSetPrototypePersistence.class)
1586            protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
1587            @BeanReference(type = ListTypePersistence.class)
1588            protected ListTypePersistence listTypePersistence;
1589            @BeanReference(type = LockPersistence.class)
1590            protected LockPersistence lockPersistence;
1591            @BeanReference(type = MembershipRequestPersistence.class)
1592            protected MembershipRequestPersistence membershipRequestPersistence;
1593            @BeanReference(type = OrganizationPersistence.class)
1594            protected OrganizationPersistence organizationPersistence;
1595            @BeanReference(type = OrgGroupPermissionPersistence.class)
1596            protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
1597            @BeanReference(type = OrgGroupRolePersistence.class)
1598            protected OrgGroupRolePersistence orgGroupRolePersistence;
1599            @BeanReference(type = OrgLaborPersistence.class)
1600            protected OrgLaborPersistence orgLaborPersistence;
1601            @BeanReference(type = PasswordPolicyPersistence.class)
1602            protected PasswordPolicyPersistence passwordPolicyPersistence;
1603            @BeanReference(type = PasswordPolicyRelPersistence.class)
1604            protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
1605            @BeanReference(type = PasswordTrackerPersistence.class)
1606            protected PasswordTrackerPersistence passwordTrackerPersistence;
1607            @BeanReference(type = PermissionPersistence.class)
1608            protected PermissionPersistence permissionPersistence;
1609            @BeanReference(type = PhonePersistence.class)
1610            protected PhonePersistence phonePersistence;
1611            @BeanReference(type = PluginSettingPersistence.class)
1612            protected PluginSettingPersistence pluginSettingPersistence;
1613            @BeanReference(type = PortletPersistence.class)
1614            protected PortletPersistence portletPersistence;
1615            @BeanReference(type = PortletItemPersistence.class)
1616            protected PortletItemPersistence portletItemPersistence;
1617            @BeanReference(type = PortletPreferencesPersistence.class)
1618            protected PortletPreferencesPersistence portletPreferencesPersistence;
1619            @BeanReference(type = RegionPersistence.class)
1620            protected RegionPersistence regionPersistence;
1621            @BeanReference(type = ReleasePersistence.class)
1622            protected ReleasePersistence releasePersistence;
1623            @BeanReference(type = ResourcePersistence.class)
1624            protected ResourcePersistence resourcePersistence;
1625            @BeanReference(type = ResourceActionPersistence.class)
1626            protected ResourceActionPersistence resourceActionPersistence;
1627            @BeanReference(type = ResourceCodePersistence.class)
1628            protected ResourceCodePersistence resourceCodePersistence;
1629            @BeanReference(type = ResourcePermissionPersistence.class)
1630            protected ResourcePermissionPersistence resourcePermissionPersistence;
1631            @BeanReference(type = RolePersistence.class)
1632            protected RolePersistence rolePersistence;
1633            @BeanReference(type = ServiceComponentPersistence.class)
1634            protected ServiceComponentPersistence serviceComponentPersistence;
1635            @BeanReference(type = ShardPersistence.class)
1636            protected ShardPersistence shardPersistence;
1637            @BeanReference(type = SubscriptionPersistence.class)
1638            protected SubscriptionPersistence subscriptionPersistence;
1639            @BeanReference(type = TicketPersistence.class)
1640            protected TicketPersistence ticketPersistence;
1641            @BeanReference(type = TeamPersistence.class)
1642            protected TeamPersistence teamPersistence;
1643            @BeanReference(type = UserPersistence.class)
1644            protected UserPersistence userPersistence;
1645            @BeanReference(type = UserGroupPersistence.class)
1646            protected UserGroupPersistence userGroupPersistence;
1647            @BeanReference(type = UserGroupGroupRolePersistence.class)
1648            protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
1649            @BeanReference(type = UserGroupRolePersistence.class)
1650            protected UserGroupRolePersistence userGroupRolePersistence;
1651            @BeanReference(type = UserIdMapperPersistence.class)
1652            protected UserIdMapperPersistence userIdMapperPersistence;
1653            @BeanReference(type = UserTrackerPersistence.class)
1654            protected UserTrackerPersistence userTrackerPersistence;
1655            @BeanReference(type = UserTrackerPathPersistence.class)
1656            protected UserTrackerPathPersistence userTrackerPathPersistence;
1657            @BeanReference(type = WebDAVPropsPersistence.class)
1658            protected WebDAVPropsPersistence webDAVPropsPersistence;
1659            @BeanReference(type = WebsitePersistence.class)
1660            protected WebsitePersistence websitePersistence;
1661            @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
1662            protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
1663            @BeanReference(type = WorkflowInstanceLinkPersistence.class)
1664            protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
1665            private static final String _SQL_SELECT_COMPANY = "SELECT company FROM Company company";
1666            private static final String _SQL_SELECT_COMPANY_WHERE = "SELECT company FROM Company company WHERE ";
1667            private static final String _SQL_COUNT_COMPANY = "SELECT COUNT(company) FROM Company company";
1668            private static final String _SQL_COUNT_COMPANY_WHERE = "SELECT COUNT(company) FROM Company company WHERE ";
1669            private static final String _FINDER_COLUMN_WEBID_WEBID_1 = "company.webId IS NULL";
1670            private static final String _FINDER_COLUMN_WEBID_WEBID_2 = "company.webId = ?";
1671            private static final String _FINDER_COLUMN_WEBID_WEBID_3 = "(company.webId IS NULL OR company.webId = ?)";
1672            private static final String _FINDER_COLUMN_VIRTUALHOST_VIRTUALHOST_1 = "company.virtualHost IS NULL";
1673            private static final String _FINDER_COLUMN_VIRTUALHOST_VIRTUALHOST_2 = "company.virtualHost = ?";
1674            private static final String _FINDER_COLUMN_VIRTUALHOST_VIRTUALHOST_3 = "(company.virtualHost IS NULL OR company.virtualHost = ?)";
1675            private static final String _FINDER_COLUMN_MX_MX_1 = "company.mx IS NULL";
1676            private static final String _FINDER_COLUMN_MX_MX_2 = "company.mx = ?";
1677            private static final String _FINDER_COLUMN_MX_MX_3 = "(company.mx IS NULL OR company.mx = ?)";
1678            private static final String _FINDER_COLUMN_LOGOID_LOGOID_2 = "company.logoId = ?";
1679            private static final String _FINDER_COLUMN_SYSTEM_SYSTEM_2 = "company.system = ?";
1680            private static final String _ORDER_BY_ENTITY_ALIAS = "company.";
1681            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Company exists with the primary key ";
1682            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Company exists with the key {";
1683            private static Log _log = LogFactoryUtil.getLog(CompanyPersistenceImpl.class);
1684    }