0001: /**
0002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
0003: *
0004: * Permission is hereby granted, free of charge, to any person obtaining a copy
0005: * of this software and associated documentation files (the "Software"), to deal
0006: * in the Software without restriction, including without limitation the rights
0007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
0008: * copies of the Software, and to permit persons to whom the Software is
0009: * furnished to do so, subject to the following conditions:
0010: *
0011: * The above copyright notice and this permission notice shall be included in
0012: * all copies or substantial portions of the Software.
0013: *
0014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
0017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
0018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
0019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
0020: * SOFTWARE.
0021: */package com.liferay.portal.service.persistence;
0022:
0023: import com.liferay.portal.NoSuchCompanyException;
0024: import com.liferay.portal.SystemException;
0025: import com.liferay.portal.kernel.dao.DynamicQuery;
0026: import com.liferay.portal.kernel.dao.DynamicQueryInitializer;
0027: import com.liferay.portal.kernel.util.GetterUtil;
0028: import com.liferay.portal.kernel.util.OrderByComparator;
0029: import com.liferay.portal.kernel.util.StringMaker;
0030: import com.liferay.portal.kernel.util.StringPool;
0031: import com.liferay.portal.kernel.util.Validator;
0032: import com.liferay.portal.model.Company;
0033: import com.liferay.portal.model.ModelListener;
0034: import com.liferay.portal.model.impl.CompanyImpl;
0035: import com.liferay.portal.model.impl.CompanyModelImpl;
0036: import com.liferay.portal.spring.hibernate.FinderCache;
0037: import com.liferay.portal.spring.hibernate.HibernateUtil;
0038: import com.liferay.portal.util.PropsUtil;
0039:
0040: import com.liferay.util.dao.hibernate.QueryUtil;
0041:
0042: import org.apache.commons.logging.Log;
0043: import org.apache.commons.logging.LogFactory;
0044:
0045: import org.hibernate.Query;
0046: import org.hibernate.Session;
0047:
0048: import java.util.Collections;
0049: import java.util.Iterator;
0050: import java.util.List;
0051:
0052: /**
0053: * <a href="CompanyPersistenceImpl.java.html"><b><i>View Source</i></b></a>
0054: *
0055: * @author Brian Wing Shun Chan
0056: *
0057: */
0058: public class CompanyPersistenceImpl extends BasePersistence implements
0059: CompanyPersistence {
0060: public Company create(long companyId) {
0061: Company company = new CompanyImpl();
0062:
0063: company.setNew(true);
0064: company.setPrimaryKey(companyId);
0065:
0066: return company;
0067: }
0068:
0069: public Company remove(long companyId)
0070: throws NoSuchCompanyException, SystemException {
0071: Session session = null;
0072:
0073: try {
0074: session = openSession();
0075:
0076: Company company = (Company) session.get(CompanyImpl.class,
0077: new Long(companyId));
0078:
0079: if (company == null) {
0080: if (_log.isWarnEnabled()) {
0081: _log.warn("No Company exists with the primary key "
0082: + companyId);
0083: }
0084:
0085: throw new NoSuchCompanyException(
0086: "No Company exists with the primary key "
0087: + companyId);
0088: }
0089:
0090: return remove(company);
0091: } catch (NoSuchCompanyException nsee) {
0092: throw nsee;
0093: } catch (Exception e) {
0094: throw HibernateUtil.processException(e);
0095: } finally {
0096: closeSession(session);
0097: }
0098: }
0099:
0100: public Company remove(Company company) throws SystemException {
0101: ModelListener listener = _getListener();
0102:
0103: if (listener != null) {
0104: listener.onBeforeRemove(company);
0105: }
0106:
0107: company = removeImpl(company);
0108:
0109: if (listener != null) {
0110: listener.onAfterRemove(company);
0111: }
0112:
0113: return company;
0114: }
0115:
0116: protected Company removeImpl(Company company)
0117: throws SystemException {
0118: Session session = null;
0119:
0120: try {
0121: session = openSession();
0122:
0123: session.delete(company);
0124:
0125: session.flush();
0126:
0127: return company;
0128: } catch (Exception e) {
0129: throw HibernateUtil.processException(e);
0130: } finally {
0131: closeSession(session);
0132:
0133: FinderCache.clearCache(Company.class.getName());
0134: }
0135: }
0136:
0137: public Company update(Company company) throws SystemException {
0138: return update(company, false);
0139: }
0140:
0141: public Company update(Company company, boolean merge)
0142: throws SystemException {
0143: ModelListener listener = _getListener();
0144:
0145: boolean isNew = company.isNew();
0146:
0147: if (listener != null) {
0148: if (isNew) {
0149: listener.onBeforeCreate(company);
0150: } else {
0151: listener.onBeforeUpdate(company);
0152: }
0153: }
0154:
0155: company = updateImpl(company, merge);
0156:
0157: if (listener != null) {
0158: if (isNew) {
0159: listener.onAfterCreate(company);
0160: } else {
0161: listener.onAfterUpdate(company);
0162: }
0163: }
0164:
0165: return company;
0166: }
0167:
0168: public Company updateImpl(com.liferay.portal.model.Company company,
0169: boolean merge) throws SystemException {
0170: Session session = null;
0171:
0172: try {
0173: session = openSession();
0174:
0175: if (merge) {
0176: session.merge(company);
0177: } else {
0178: if (company.isNew()) {
0179: session.save(company);
0180: }
0181: }
0182:
0183: session.flush();
0184:
0185: company.setNew(false);
0186:
0187: return company;
0188: } catch (Exception e) {
0189: throw HibernateUtil.processException(e);
0190: } finally {
0191: closeSession(session);
0192:
0193: FinderCache.clearCache(Company.class.getName());
0194: }
0195: }
0196:
0197: public Company findByPrimaryKey(long companyId)
0198: throws NoSuchCompanyException, SystemException {
0199: Company company = fetchByPrimaryKey(companyId);
0200:
0201: if (company == null) {
0202: if (_log.isWarnEnabled()) {
0203: _log.warn("No Company exists with the primary key "
0204: + companyId);
0205: }
0206:
0207: throw new NoSuchCompanyException(
0208: "No Company exists with the primary key "
0209: + companyId);
0210: }
0211:
0212: return company;
0213: }
0214:
0215: public Company fetchByPrimaryKey(long companyId)
0216: throws SystemException {
0217: Session session = null;
0218:
0219: try {
0220: session = openSession();
0221:
0222: return (Company) session.get(CompanyImpl.class, new Long(
0223: companyId));
0224: } catch (Exception e) {
0225: throw HibernateUtil.processException(e);
0226: } finally {
0227: closeSession(session);
0228: }
0229: }
0230:
0231: public Company findByWebId(String webId)
0232: throws NoSuchCompanyException, SystemException {
0233: Company company = fetchByWebId(webId);
0234:
0235: if (company == null) {
0236: StringMaker msg = new StringMaker();
0237:
0238: msg.append("No Company exists with the key {");
0239:
0240: msg.append("webId=" + webId);
0241:
0242: msg.append(StringPool.CLOSE_CURLY_BRACE);
0243:
0244: if (_log.isWarnEnabled()) {
0245: _log.warn(msg.toString());
0246: }
0247:
0248: throw new NoSuchCompanyException(msg.toString());
0249: }
0250:
0251: return company;
0252: }
0253:
0254: public Company fetchByWebId(String webId) throws SystemException {
0255: boolean finderClassNameCacheEnabled = CompanyModelImpl.CACHE_ENABLED;
0256: String finderClassName = Company.class.getName();
0257: String finderMethodName = "fetchByWebId";
0258: String[] finderParams = new String[] { String.class.getName() };
0259: Object[] finderArgs = new Object[] { webId };
0260:
0261: Object result = null;
0262:
0263: if (finderClassNameCacheEnabled) {
0264: result = FinderCache.getResult(finderClassName,
0265: finderMethodName, finderParams, finderArgs,
0266: getSessionFactory());
0267: }
0268:
0269: if (result == null) {
0270: Session session = null;
0271:
0272: try {
0273: session = openSession();
0274:
0275: StringMaker query = new StringMaker();
0276:
0277: query
0278: .append("FROM com.liferay.portal.model.Company WHERE ");
0279:
0280: if (webId == null) {
0281: query.append("webId IS NULL");
0282: } else {
0283: query.append("webId = ?");
0284: }
0285:
0286: query.append(" ");
0287:
0288: Query q = session.createQuery(query.toString());
0289:
0290: int queryPos = 0;
0291:
0292: if (webId != null) {
0293: q.setString(queryPos++, webId);
0294: }
0295:
0296: List list = q.list();
0297:
0298: FinderCache.putResult(finderClassNameCacheEnabled,
0299: finderClassName, finderMethodName,
0300: finderParams, finderArgs, list);
0301:
0302: if (list.size() == 0) {
0303: return null;
0304: } else {
0305: return (Company) list.get(0);
0306: }
0307: } catch (Exception e) {
0308: throw HibernateUtil.processException(e);
0309: } finally {
0310: closeSession(session);
0311: }
0312: } else {
0313: List list = (List) result;
0314:
0315: if (list.size() == 0) {
0316: return null;
0317: } else {
0318: return (Company) list.get(0);
0319: }
0320: }
0321: }
0322:
0323: public Company findByVirtualHost(String virtualHost)
0324: throws NoSuchCompanyException, SystemException {
0325: Company company = fetchByVirtualHost(virtualHost);
0326:
0327: if (company == null) {
0328: StringMaker msg = new StringMaker();
0329:
0330: msg.append("No Company exists with the key {");
0331:
0332: msg.append("virtualHost=" + virtualHost);
0333:
0334: msg.append(StringPool.CLOSE_CURLY_BRACE);
0335:
0336: if (_log.isWarnEnabled()) {
0337: _log.warn(msg.toString());
0338: }
0339:
0340: throw new NoSuchCompanyException(msg.toString());
0341: }
0342:
0343: return company;
0344: }
0345:
0346: public Company fetchByVirtualHost(String virtualHost)
0347: throws SystemException {
0348: boolean finderClassNameCacheEnabled = CompanyModelImpl.CACHE_ENABLED;
0349: String finderClassName = Company.class.getName();
0350: String finderMethodName = "fetchByVirtualHost";
0351: String[] finderParams = new String[] { String.class.getName() };
0352: Object[] finderArgs = new Object[] { virtualHost };
0353:
0354: Object result = null;
0355:
0356: if (finderClassNameCacheEnabled) {
0357: result = FinderCache.getResult(finderClassName,
0358: finderMethodName, finderParams, finderArgs,
0359: getSessionFactory());
0360: }
0361:
0362: if (result == null) {
0363: Session session = null;
0364:
0365: try {
0366: session = openSession();
0367:
0368: StringMaker query = new StringMaker();
0369:
0370: query
0371: .append("FROM com.liferay.portal.model.Company WHERE ");
0372:
0373: if (virtualHost == null) {
0374: query.append("virtualHost IS NULL");
0375: } else {
0376: query.append("virtualHost = ?");
0377: }
0378:
0379: query.append(" ");
0380:
0381: Query q = session.createQuery(query.toString());
0382:
0383: int queryPos = 0;
0384:
0385: if (virtualHost != null) {
0386: q.setString(queryPos++, virtualHost);
0387: }
0388:
0389: List list = q.list();
0390:
0391: FinderCache.putResult(finderClassNameCacheEnabled,
0392: finderClassName, finderMethodName,
0393: finderParams, finderArgs, list);
0394:
0395: if (list.size() == 0) {
0396: return null;
0397: } else {
0398: return (Company) list.get(0);
0399: }
0400: } catch (Exception e) {
0401: throw HibernateUtil.processException(e);
0402: } finally {
0403: closeSession(session);
0404: }
0405: } else {
0406: List list = (List) result;
0407:
0408: if (list.size() == 0) {
0409: return null;
0410: } else {
0411: return (Company) list.get(0);
0412: }
0413: }
0414: }
0415:
0416: public Company findByMx(String mx) throws NoSuchCompanyException,
0417: SystemException {
0418: Company company = fetchByMx(mx);
0419:
0420: if (company == null) {
0421: StringMaker msg = new StringMaker();
0422:
0423: msg.append("No Company exists with the key {");
0424:
0425: msg.append("mx=" + mx);
0426:
0427: msg.append(StringPool.CLOSE_CURLY_BRACE);
0428:
0429: if (_log.isWarnEnabled()) {
0430: _log.warn(msg.toString());
0431: }
0432:
0433: throw new NoSuchCompanyException(msg.toString());
0434: }
0435:
0436: return company;
0437: }
0438:
0439: public Company fetchByMx(String mx) throws SystemException {
0440: boolean finderClassNameCacheEnabled = CompanyModelImpl.CACHE_ENABLED;
0441: String finderClassName = Company.class.getName();
0442: String finderMethodName = "fetchByMx";
0443: String[] finderParams = new String[] { String.class.getName() };
0444: Object[] finderArgs = new Object[] { mx };
0445:
0446: Object result = null;
0447:
0448: if (finderClassNameCacheEnabled) {
0449: result = FinderCache.getResult(finderClassName,
0450: finderMethodName, finderParams, finderArgs,
0451: getSessionFactory());
0452: }
0453:
0454: if (result == null) {
0455: Session session = null;
0456:
0457: try {
0458: session = openSession();
0459:
0460: StringMaker query = new StringMaker();
0461:
0462: query
0463: .append("FROM com.liferay.portal.model.Company WHERE ");
0464:
0465: if (mx == null) {
0466: query.append("mx IS NULL");
0467: } else {
0468: query.append("mx = ?");
0469: }
0470:
0471: query.append(" ");
0472:
0473: Query q = session.createQuery(query.toString());
0474:
0475: int queryPos = 0;
0476:
0477: if (mx != null) {
0478: q.setString(queryPos++, mx);
0479: }
0480:
0481: List list = q.list();
0482:
0483: FinderCache.putResult(finderClassNameCacheEnabled,
0484: finderClassName, finderMethodName,
0485: finderParams, finderArgs, list);
0486:
0487: if (list.size() == 0) {
0488: return null;
0489: } else {
0490: return (Company) list.get(0);
0491: }
0492: } catch (Exception e) {
0493: throw HibernateUtil.processException(e);
0494: } finally {
0495: closeSession(session);
0496: }
0497: } else {
0498: List list = (List) result;
0499:
0500: if (list.size() == 0) {
0501: return null;
0502: } else {
0503: return (Company) list.get(0);
0504: }
0505: }
0506: }
0507:
0508: public Company findByLogoId(long logoId)
0509: throws NoSuchCompanyException, SystemException {
0510: Company company = fetchByLogoId(logoId);
0511:
0512: if (company == null) {
0513: StringMaker msg = new StringMaker();
0514:
0515: msg.append("No Company exists with the key {");
0516:
0517: msg.append("logoId=" + logoId);
0518:
0519: msg.append(StringPool.CLOSE_CURLY_BRACE);
0520:
0521: if (_log.isWarnEnabled()) {
0522: _log.warn(msg.toString());
0523: }
0524:
0525: throw new NoSuchCompanyException(msg.toString());
0526: }
0527:
0528: return company;
0529: }
0530:
0531: public Company fetchByLogoId(long logoId) throws SystemException {
0532: boolean finderClassNameCacheEnabled = CompanyModelImpl.CACHE_ENABLED;
0533: String finderClassName = Company.class.getName();
0534: String finderMethodName = "fetchByLogoId";
0535: String[] finderParams = new String[] { Long.class.getName() };
0536: Object[] finderArgs = new Object[] { new Long(logoId) };
0537:
0538: Object result = null;
0539:
0540: if (finderClassNameCacheEnabled) {
0541: result = FinderCache.getResult(finderClassName,
0542: finderMethodName, finderParams, finderArgs,
0543: getSessionFactory());
0544: }
0545:
0546: if (result == null) {
0547: Session session = null;
0548:
0549: try {
0550: session = openSession();
0551:
0552: StringMaker query = new StringMaker();
0553:
0554: query
0555: .append("FROM com.liferay.portal.model.Company WHERE ");
0556:
0557: query.append("logoId = ?");
0558:
0559: query.append(" ");
0560:
0561: Query q = session.createQuery(query.toString());
0562:
0563: int queryPos = 0;
0564:
0565: q.setLong(queryPos++, logoId);
0566:
0567: List list = q.list();
0568:
0569: FinderCache.putResult(finderClassNameCacheEnabled,
0570: finderClassName, finderMethodName,
0571: finderParams, finderArgs, list);
0572:
0573: if (list.size() == 0) {
0574: return null;
0575: } else {
0576: return (Company) list.get(0);
0577: }
0578: } catch (Exception e) {
0579: throw HibernateUtil.processException(e);
0580: } finally {
0581: closeSession(session);
0582: }
0583: } else {
0584: List list = (List) result;
0585:
0586: if (list.size() == 0) {
0587: return null;
0588: } else {
0589: return (Company) list.get(0);
0590: }
0591: }
0592: }
0593:
0594: public List findWithDynamicQuery(
0595: DynamicQueryInitializer queryInitializer)
0596: throws SystemException {
0597: Session session = null;
0598:
0599: try {
0600: session = openSession();
0601:
0602: DynamicQuery query = queryInitializer.initialize(session);
0603:
0604: return query.list();
0605: } catch (Exception e) {
0606: throw HibernateUtil.processException(e);
0607: } finally {
0608: closeSession(session);
0609: }
0610: }
0611:
0612: public List findWithDynamicQuery(
0613: DynamicQueryInitializer queryInitializer, int begin, int end)
0614: throws SystemException {
0615: Session session = null;
0616:
0617: try {
0618: session = openSession();
0619:
0620: DynamicQuery query = queryInitializer.initialize(session);
0621:
0622: query.setLimit(begin, end);
0623:
0624: return query.list();
0625: } catch (Exception e) {
0626: throw HibernateUtil.processException(e);
0627: } finally {
0628: closeSession(session);
0629: }
0630: }
0631:
0632: public List findAll() throws SystemException {
0633: return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
0634: }
0635:
0636: public List findAll(int begin, int end) throws SystemException {
0637: return findAll(begin, end, null);
0638: }
0639:
0640: public List findAll(int begin, int end, OrderByComparator obc)
0641: throws SystemException {
0642: boolean finderClassNameCacheEnabled = CompanyModelImpl.CACHE_ENABLED;
0643: String finderClassName = Company.class.getName();
0644: String finderMethodName = "findAll";
0645: String[] finderParams = new String[] { "java.lang.Integer",
0646: "java.lang.Integer",
0647: "com.liferay.portal.kernel.util.OrderByComparator" };
0648: Object[] finderArgs = new Object[] { String.valueOf(begin),
0649: String.valueOf(end), String.valueOf(obc) };
0650:
0651: Object result = null;
0652:
0653: if (finderClassNameCacheEnabled) {
0654: result = FinderCache.getResult(finderClassName,
0655: finderMethodName, finderParams, finderArgs,
0656: getSessionFactory());
0657: }
0658:
0659: if (result == null) {
0660: Session session = null;
0661:
0662: try {
0663: session = openSession();
0664:
0665: StringMaker query = new StringMaker();
0666:
0667: query.append("FROM com.liferay.portal.model.Company ");
0668:
0669: if (obc != null) {
0670: query.append("ORDER BY ");
0671: query.append(obc.getOrderBy());
0672: }
0673:
0674: Query q = session.createQuery(query.toString());
0675:
0676: List list = QueryUtil.list(q, getDialect(), begin, end);
0677:
0678: if (obc == null) {
0679: Collections.sort(list);
0680: }
0681:
0682: FinderCache.putResult(finderClassNameCacheEnabled,
0683: finderClassName, finderMethodName,
0684: finderParams, finderArgs, list);
0685:
0686: return list;
0687: } catch (Exception e) {
0688: throw HibernateUtil.processException(e);
0689: } finally {
0690: closeSession(session);
0691: }
0692: } else {
0693: return (List) result;
0694: }
0695: }
0696:
0697: public void removeByWebId(String webId)
0698: throws NoSuchCompanyException, SystemException {
0699: Company company = findByWebId(webId);
0700:
0701: remove(company);
0702: }
0703:
0704: public void removeByVirtualHost(String virtualHost)
0705: throws NoSuchCompanyException, SystemException {
0706: Company company = findByVirtualHost(virtualHost);
0707:
0708: remove(company);
0709: }
0710:
0711: public void removeByMx(String mx) throws NoSuchCompanyException,
0712: SystemException {
0713: Company company = findByMx(mx);
0714:
0715: remove(company);
0716: }
0717:
0718: public void removeByLogoId(long logoId)
0719: throws NoSuchCompanyException, SystemException {
0720: Company company = findByLogoId(logoId);
0721:
0722: remove(company);
0723: }
0724:
0725: public void removeAll() throws SystemException {
0726: Iterator itr = findAll().iterator();
0727:
0728: while (itr.hasNext()) {
0729: remove((Company) itr.next());
0730: }
0731: }
0732:
0733: public int countByWebId(String webId) throws SystemException {
0734: boolean finderClassNameCacheEnabled = CompanyModelImpl.CACHE_ENABLED;
0735: String finderClassName = Company.class.getName();
0736: String finderMethodName = "countByWebId";
0737: String[] finderParams = new String[] { String.class.getName() };
0738: Object[] finderArgs = new Object[] { webId };
0739:
0740: Object result = null;
0741:
0742: if (finderClassNameCacheEnabled) {
0743: result = FinderCache.getResult(finderClassName,
0744: finderMethodName, finderParams, finderArgs,
0745: getSessionFactory());
0746: }
0747:
0748: if (result == null) {
0749: Session session = null;
0750:
0751: try {
0752: session = openSession();
0753:
0754: StringMaker query = new StringMaker();
0755:
0756: query.append("SELECT COUNT(*) ");
0757: query
0758: .append("FROM com.liferay.portal.model.Company WHERE ");
0759:
0760: if (webId == null) {
0761: query.append("webId IS NULL");
0762: } else {
0763: query.append("webId = ?");
0764: }
0765:
0766: query.append(" ");
0767:
0768: Query q = session.createQuery(query.toString());
0769:
0770: int queryPos = 0;
0771:
0772: if (webId != null) {
0773: q.setString(queryPos++, webId);
0774: }
0775:
0776: Long count = null;
0777:
0778: Iterator itr = q.list().iterator();
0779:
0780: if (itr.hasNext()) {
0781: count = (Long) itr.next();
0782: }
0783:
0784: if (count == null) {
0785: count = new Long(0);
0786: }
0787:
0788: FinderCache.putResult(finderClassNameCacheEnabled,
0789: finderClassName, finderMethodName,
0790: finderParams, finderArgs, count);
0791:
0792: return count.intValue();
0793: } catch (Exception e) {
0794: throw HibernateUtil.processException(e);
0795: } finally {
0796: closeSession(session);
0797: }
0798: } else {
0799: return ((Long) result).intValue();
0800: }
0801: }
0802:
0803: public int countByVirtualHost(String virtualHost)
0804: throws SystemException {
0805: boolean finderClassNameCacheEnabled = CompanyModelImpl.CACHE_ENABLED;
0806: String finderClassName = Company.class.getName();
0807: String finderMethodName = "countByVirtualHost";
0808: String[] finderParams = new String[] { String.class.getName() };
0809: Object[] finderArgs = new Object[] { virtualHost };
0810:
0811: Object result = null;
0812:
0813: if (finderClassNameCacheEnabled) {
0814: result = FinderCache.getResult(finderClassName,
0815: finderMethodName, finderParams, finderArgs,
0816: getSessionFactory());
0817: }
0818:
0819: if (result == null) {
0820: Session session = null;
0821:
0822: try {
0823: session = openSession();
0824:
0825: StringMaker query = new StringMaker();
0826:
0827: query.append("SELECT COUNT(*) ");
0828: query
0829: .append("FROM com.liferay.portal.model.Company WHERE ");
0830:
0831: if (virtualHost == null) {
0832: query.append("virtualHost IS NULL");
0833: } else {
0834: query.append("virtualHost = ?");
0835: }
0836:
0837: query.append(" ");
0838:
0839: Query q = session.createQuery(query.toString());
0840:
0841: int queryPos = 0;
0842:
0843: if (virtualHost != null) {
0844: q.setString(queryPos++, virtualHost);
0845: }
0846:
0847: Long count = null;
0848:
0849: Iterator itr = q.list().iterator();
0850:
0851: if (itr.hasNext()) {
0852: count = (Long) itr.next();
0853: }
0854:
0855: if (count == null) {
0856: count = new Long(0);
0857: }
0858:
0859: FinderCache.putResult(finderClassNameCacheEnabled,
0860: finderClassName, finderMethodName,
0861: finderParams, finderArgs, count);
0862:
0863: return count.intValue();
0864: } catch (Exception e) {
0865: throw HibernateUtil.processException(e);
0866: } finally {
0867: closeSession(session);
0868: }
0869: } else {
0870: return ((Long) result).intValue();
0871: }
0872: }
0873:
0874: public int countByMx(String mx) throws SystemException {
0875: boolean finderClassNameCacheEnabled = CompanyModelImpl.CACHE_ENABLED;
0876: String finderClassName = Company.class.getName();
0877: String finderMethodName = "countByMx";
0878: String[] finderParams = new String[] { String.class.getName() };
0879: Object[] finderArgs = new Object[] { mx };
0880:
0881: Object result = null;
0882:
0883: if (finderClassNameCacheEnabled) {
0884: result = FinderCache.getResult(finderClassName,
0885: finderMethodName, finderParams, finderArgs,
0886: getSessionFactory());
0887: }
0888:
0889: if (result == null) {
0890: Session session = null;
0891:
0892: try {
0893: session = openSession();
0894:
0895: StringMaker query = new StringMaker();
0896:
0897: query.append("SELECT COUNT(*) ");
0898: query
0899: .append("FROM com.liferay.portal.model.Company WHERE ");
0900:
0901: if (mx == null) {
0902: query.append("mx IS NULL");
0903: } else {
0904: query.append("mx = ?");
0905: }
0906:
0907: query.append(" ");
0908:
0909: Query q = session.createQuery(query.toString());
0910:
0911: int queryPos = 0;
0912:
0913: if (mx != null) {
0914: q.setString(queryPos++, mx);
0915: }
0916:
0917: Long count = null;
0918:
0919: Iterator itr = q.list().iterator();
0920:
0921: if (itr.hasNext()) {
0922: count = (Long) itr.next();
0923: }
0924:
0925: if (count == null) {
0926: count = new Long(0);
0927: }
0928:
0929: FinderCache.putResult(finderClassNameCacheEnabled,
0930: finderClassName, finderMethodName,
0931: finderParams, finderArgs, count);
0932:
0933: return count.intValue();
0934: } catch (Exception e) {
0935: throw HibernateUtil.processException(e);
0936: } finally {
0937: closeSession(session);
0938: }
0939: } else {
0940: return ((Long) result).intValue();
0941: }
0942: }
0943:
0944: public int countByLogoId(long logoId) throws SystemException {
0945: boolean finderClassNameCacheEnabled = CompanyModelImpl.CACHE_ENABLED;
0946: String finderClassName = Company.class.getName();
0947: String finderMethodName = "countByLogoId";
0948: String[] finderParams = new String[] { Long.class.getName() };
0949: Object[] finderArgs = new Object[] { new Long(logoId) };
0950:
0951: Object result = null;
0952:
0953: if (finderClassNameCacheEnabled) {
0954: result = FinderCache.getResult(finderClassName,
0955: finderMethodName, finderParams, finderArgs,
0956: getSessionFactory());
0957: }
0958:
0959: if (result == null) {
0960: Session session = null;
0961:
0962: try {
0963: session = openSession();
0964:
0965: StringMaker query = new StringMaker();
0966:
0967: query.append("SELECT COUNT(*) ");
0968: query
0969: .append("FROM com.liferay.portal.model.Company WHERE ");
0970:
0971: query.append("logoId = ?");
0972:
0973: query.append(" ");
0974:
0975: Query q = session.createQuery(query.toString());
0976:
0977: int queryPos = 0;
0978:
0979: q.setLong(queryPos++, logoId);
0980:
0981: Long count = null;
0982:
0983: Iterator itr = q.list().iterator();
0984:
0985: if (itr.hasNext()) {
0986: count = (Long) itr.next();
0987: }
0988:
0989: if (count == null) {
0990: count = new Long(0);
0991: }
0992:
0993: FinderCache.putResult(finderClassNameCacheEnabled,
0994: finderClassName, finderMethodName,
0995: finderParams, finderArgs, count);
0996:
0997: return count.intValue();
0998: } catch (Exception e) {
0999: throw HibernateUtil.processException(e);
1000: } finally {
1001: closeSession(session);
1002: }
1003: } else {
1004: return ((Long) result).intValue();
1005: }
1006: }
1007:
1008: public int countAll() throws SystemException {
1009: boolean finderClassNameCacheEnabled = CompanyModelImpl.CACHE_ENABLED;
1010: String finderClassName = Company.class.getName();
1011: String finderMethodName = "countAll";
1012: String[] finderParams = new String[] {};
1013: Object[] finderArgs = new Object[] {};
1014:
1015: Object result = null;
1016:
1017: if (finderClassNameCacheEnabled) {
1018: result = FinderCache.getResult(finderClassName,
1019: finderMethodName, finderParams, finderArgs,
1020: getSessionFactory());
1021: }
1022:
1023: if (result == null) {
1024: Session session = null;
1025:
1026: try {
1027: session = openSession();
1028:
1029: Query q = session
1030: .createQuery("SELECT COUNT(*) FROM com.liferay.portal.model.Company");
1031:
1032: Long count = null;
1033:
1034: Iterator itr = q.list().iterator();
1035:
1036: if (itr.hasNext()) {
1037: count = (Long) itr.next();
1038: }
1039:
1040: if (count == null) {
1041: count = new Long(0);
1042: }
1043:
1044: FinderCache.putResult(finderClassNameCacheEnabled,
1045: finderClassName, finderMethodName,
1046: finderParams, finderArgs, count);
1047:
1048: return count.intValue();
1049: } catch (Exception e) {
1050: throw HibernateUtil.processException(e);
1051: } finally {
1052: closeSession(session);
1053: }
1054: } else {
1055: return ((Long) result).intValue();
1056: }
1057: }
1058:
1059: protected void initDao() {
1060: }
1061:
1062: private static ModelListener _getListener() {
1063: if (Validator.isNotNull(_LISTENER)) {
1064: try {
1065: return (ModelListener) Class.forName(_LISTENER)
1066: .newInstance();
1067: } catch (Exception e) {
1068: _log.error(e);
1069: }
1070: }
1071:
1072: return null;
1073: }
1074:
1075: private static final String _LISTENER = GetterUtil
1076: .getString(PropsUtil
1077: .get("value.object.listener.com.liferay.portal.model.Company"));
1078: private static Log _log = LogFactory
1079: .getLog(CompanyPersistenceImpl.class);
1080: }
|