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.NoSuchRegionException;
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.ModelListener;
0033: import com.liferay.portal.model.Region;
0034: import com.liferay.portal.model.impl.RegionImpl;
0035: import com.liferay.portal.model.impl.RegionModelImpl;
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="RegionPersistenceImpl.java.html"><b><i>View Source</i></b></a>
0054: *
0055: * @author Brian Wing Shun Chan
0056: *
0057: */
0058: public class RegionPersistenceImpl extends BasePersistence implements
0059: RegionPersistence {
0060: public Region create(long regionId) {
0061: Region region = new RegionImpl();
0062:
0063: region.setNew(true);
0064: region.setPrimaryKey(regionId);
0065:
0066: return region;
0067: }
0068:
0069: public Region remove(long regionId) throws NoSuchRegionException,
0070: SystemException {
0071: Session session = null;
0072:
0073: try {
0074: session = openSession();
0075:
0076: Region region = (Region) session.get(RegionImpl.class,
0077: new Long(regionId));
0078:
0079: if (region == null) {
0080: if (_log.isWarnEnabled()) {
0081: _log.warn("No Region exists with the primary key "
0082: + regionId);
0083: }
0084:
0085: throw new NoSuchRegionException(
0086: "No Region exists with the primary key "
0087: + regionId);
0088: }
0089:
0090: return remove(region);
0091: } catch (NoSuchRegionException nsee) {
0092: throw nsee;
0093: } catch (Exception e) {
0094: throw HibernateUtil.processException(e);
0095: } finally {
0096: closeSession(session);
0097: }
0098: }
0099:
0100: public Region remove(Region region) throws SystemException {
0101: ModelListener listener = _getListener();
0102:
0103: if (listener != null) {
0104: listener.onBeforeRemove(region);
0105: }
0106:
0107: region = removeImpl(region);
0108:
0109: if (listener != null) {
0110: listener.onAfterRemove(region);
0111: }
0112:
0113: return region;
0114: }
0115:
0116: protected Region removeImpl(Region region) throws SystemException {
0117: Session session = null;
0118:
0119: try {
0120: session = openSession();
0121:
0122: session.delete(region);
0123:
0124: session.flush();
0125:
0126: return region;
0127: } catch (Exception e) {
0128: throw HibernateUtil.processException(e);
0129: } finally {
0130: closeSession(session);
0131:
0132: FinderCache.clearCache(Region.class.getName());
0133: }
0134: }
0135:
0136: public Region update(Region region) throws SystemException {
0137: return update(region, false);
0138: }
0139:
0140: public Region update(Region region, boolean merge)
0141: throws SystemException {
0142: ModelListener listener = _getListener();
0143:
0144: boolean isNew = region.isNew();
0145:
0146: if (listener != null) {
0147: if (isNew) {
0148: listener.onBeforeCreate(region);
0149: } else {
0150: listener.onBeforeUpdate(region);
0151: }
0152: }
0153:
0154: region = updateImpl(region, merge);
0155:
0156: if (listener != null) {
0157: if (isNew) {
0158: listener.onAfterCreate(region);
0159: } else {
0160: listener.onAfterUpdate(region);
0161: }
0162: }
0163:
0164: return region;
0165: }
0166:
0167: public Region updateImpl(com.liferay.portal.model.Region region,
0168: boolean merge) throws SystemException {
0169: Session session = null;
0170:
0171: try {
0172: session = openSession();
0173:
0174: if (merge) {
0175: session.merge(region);
0176: } else {
0177: if (region.isNew()) {
0178: session.save(region);
0179: }
0180: }
0181:
0182: session.flush();
0183:
0184: region.setNew(false);
0185:
0186: return region;
0187: } catch (Exception e) {
0188: throw HibernateUtil.processException(e);
0189: } finally {
0190: closeSession(session);
0191:
0192: FinderCache.clearCache(Region.class.getName());
0193: }
0194: }
0195:
0196: public Region findByPrimaryKey(long regionId)
0197: throws NoSuchRegionException, SystemException {
0198: Region region = fetchByPrimaryKey(regionId);
0199:
0200: if (region == null) {
0201: if (_log.isWarnEnabled()) {
0202: _log.warn("No Region exists with the primary key "
0203: + regionId);
0204: }
0205:
0206: throw new NoSuchRegionException(
0207: "No Region exists with the primary key " + regionId);
0208: }
0209:
0210: return region;
0211: }
0212:
0213: public Region fetchByPrimaryKey(long regionId)
0214: throws SystemException {
0215: Session session = null;
0216:
0217: try {
0218: session = openSession();
0219:
0220: return (Region) session.get(RegionImpl.class, new Long(
0221: regionId));
0222: } catch (Exception e) {
0223: throw HibernateUtil.processException(e);
0224: } finally {
0225: closeSession(session);
0226: }
0227: }
0228:
0229: public List findByCountryId(long countryId) throws SystemException {
0230: boolean finderClassNameCacheEnabled = RegionModelImpl.CACHE_ENABLED;
0231: String finderClassName = Region.class.getName();
0232: String finderMethodName = "findByCountryId";
0233: String[] finderParams = new String[] { Long.class.getName() };
0234: Object[] finderArgs = new Object[] { new Long(countryId) };
0235:
0236: Object result = null;
0237:
0238: if (finderClassNameCacheEnabled) {
0239: result = FinderCache.getResult(finderClassName,
0240: finderMethodName, finderParams, finderArgs,
0241: getSessionFactory());
0242: }
0243:
0244: if (result == null) {
0245: Session session = null;
0246:
0247: try {
0248: session = openSession();
0249:
0250: StringMaker query = new StringMaker();
0251:
0252: query
0253: .append("FROM com.liferay.portal.model.Region WHERE ");
0254:
0255: query.append("countryId = ?");
0256:
0257: query.append(" ");
0258:
0259: query.append("ORDER BY ");
0260:
0261: query.append("name ASC");
0262:
0263: Query q = session.createQuery(query.toString());
0264:
0265: int queryPos = 0;
0266:
0267: q.setLong(queryPos++, countryId);
0268:
0269: List list = q.list();
0270:
0271: FinderCache.putResult(finderClassNameCacheEnabled,
0272: finderClassName, finderMethodName,
0273: finderParams, finderArgs, list);
0274:
0275: return list;
0276: } catch (Exception e) {
0277: throw HibernateUtil.processException(e);
0278: } finally {
0279: closeSession(session);
0280: }
0281: } else {
0282: return (List) result;
0283: }
0284: }
0285:
0286: public List findByCountryId(long countryId, int begin, int end)
0287: throws SystemException {
0288: return findByCountryId(countryId, begin, end, null);
0289: }
0290:
0291: public List findByCountryId(long countryId, int begin, int end,
0292: OrderByComparator obc) throws SystemException {
0293: boolean finderClassNameCacheEnabled = RegionModelImpl.CACHE_ENABLED;
0294: String finderClassName = Region.class.getName();
0295: String finderMethodName = "findByCountryId";
0296: String[] finderParams = new String[] { Long.class.getName(),
0297:
0298: "java.lang.Integer", "java.lang.Integer",
0299: "com.liferay.portal.kernel.util.OrderByComparator" };
0300: Object[] finderArgs = new Object[] { new Long(countryId),
0301:
0302: String.valueOf(begin), String.valueOf(end), String.valueOf(obc) };
0303:
0304: Object result = null;
0305:
0306: if (finderClassNameCacheEnabled) {
0307: result = FinderCache.getResult(finderClassName,
0308: finderMethodName, finderParams, finderArgs,
0309: getSessionFactory());
0310: }
0311:
0312: if (result == null) {
0313: Session session = null;
0314:
0315: try {
0316: session = openSession();
0317:
0318: StringMaker query = new StringMaker();
0319:
0320: query
0321: .append("FROM com.liferay.portal.model.Region WHERE ");
0322:
0323: query.append("countryId = ?");
0324:
0325: query.append(" ");
0326:
0327: if (obc != null) {
0328: query.append("ORDER BY ");
0329: query.append(obc.getOrderBy());
0330: }
0331:
0332: else {
0333: query.append("ORDER BY ");
0334:
0335: query.append("name ASC");
0336: }
0337:
0338: Query q = session.createQuery(query.toString());
0339:
0340: int queryPos = 0;
0341:
0342: q.setLong(queryPos++, countryId);
0343:
0344: List list = QueryUtil.list(q, getDialect(), begin, end);
0345:
0346: FinderCache.putResult(finderClassNameCacheEnabled,
0347: finderClassName, finderMethodName,
0348: finderParams, finderArgs, list);
0349:
0350: return list;
0351: } catch (Exception e) {
0352: throw HibernateUtil.processException(e);
0353: } finally {
0354: closeSession(session);
0355: }
0356: } else {
0357: return (List) result;
0358: }
0359: }
0360:
0361: public Region findByCountryId_First(long countryId,
0362: OrderByComparator obc) throws NoSuchRegionException,
0363: SystemException {
0364: List list = findByCountryId(countryId, 0, 1, obc);
0365:
0366: if (list.size() == 0) {
0367: StringMaker msg = new StringMaker();
0368:
0369: msg.append("No Region exists with the key {");
0370:
0371: msg.append("countryId=" + countryId);
0372:
0373: msg.append(StringPool.CLOSE_CURLY_BRACE);
0374:
0375: throw new NoSuchRegionException(msg.toString());
0376: } else {
0377: return (Region) list.get(0);
0378: }
0379: }
0380:
0381: public Region findByCountryId_Last(long countryId,
0382: OrderByComparator obc) throws NoSuchRegionException,
0383: SystemException {
0384: int count = countByCountryId(countryId);
0385:
0386: List list = findByCountryId(countryId, count - 1, count, obc);
0387:
0388: if (list.size() == 0) {
0389: StringMaker msg = new StringMaker();
0390:
0391: msg.append("No Region exists with the key {");
0392:
0393: msg.append("countryId=" + countryId);
0394:
0395: msg.append(StringPool.CLOSE_CURLY_BRACE);
0396:
0397: throw new NoSuchRegionException(msg.toString());
0398: } else {
0399: return (Region) list.get(0);
0400: }
0401: }
0402:
0403: public Region[] findByCountryId_PrevAndNext(long regionId,
0404: long countryId, OrderByComparator obc)
0405: throws NoSuchRegionException, SystemException {
0406: Region region = findByPrimaryKey(regionId);
0407:
0408: int count = countByCountryId(countryId);
0409:
0410: Session session = null;
0411:
0412: try {
0413: session = openSession();
0414:
0415: StringMaker query = new StringMaker();
0416:
0417: query.append("FROM com.liferay.portal.model.Region WHERE ");
0418:
0419: query.append("countryId = ?");
0420:
0421: query.append(" ");
0422:
0423: if (obc != null) {
0424: query.append("ORDER BY ");
0425: query.append(obc.getOrderBy());
0426: }
0427:
0428: else {
0429: query.append("ORDER BY ");
0430:
0431: query.append("name ASC");
0432: }
0433:
0434: Query q = session.createQuery(query.toString());
0435:
0436: int queryPos = 0;
0437:
0438: q.setLong(queryPos++, countryId);
0439:
0440: Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
0441: region);
0442:
0443: Region[] array = new RegionImpl[3];
0444:
0445: array[0] = (Region) objArray[0];
0446: array[1] = (Region) objArray[1];
0447: array[2] = (Region) objArray[2];
0448:
0449: return array;
0450: } catch (Exception e) {
0451: throw HibernateUtil.processException(e);
0452: } finally {
0453: closeSession(session);
0454: }
0455: }
0456:
0457: public List findByActive(boolean active) throws SystemException {
0458: boolean finderClassNameCacheEnabled = RegionModelImpl.CACHE_ENABLED;
0459: String finderClassName = Region.class.getName();
0460: String finderMethodName = "findByActive";
0461: String[] finderParams = new String[] { Boolean.class.getName() };
0462: Object[] finderArgs = new Object[] { Boolean.valueOf(active) };
0463:
0464: Object result = null;
0465:
0466: if (finderClassNameCacheEnabled) {
0467: result = FinderCache.getResult(finderClassName,
0468: finderMethodName, finderParams, finderArgs,
0469: getSessionFactory());
0470: }
0471:
0472: if (result == null) {
0473: Session session = null;
0474:
0475: try {
0476: session = openSession();
0477:
0478: StringMaker query = new StringMaker();
0479:
0480: query
0481: .append("FROM com.liferay.portal.model.Region WHERE ");
0482:
0483: query.append("active_ = ?");
0484:
0485: query.append(" ");
0486:
0487: query.append("ORDER BY ");
0488:
0489: query.append("name ASC");
0490:
0491: Query q = session.createQuery(query.toString());
0492:
0493: int queryPos = 0;
0494:
0495: q.setBoolean(queryPos++, active);
0496:
0497: List list = q.list();
0498:
0499: FinderCache.putResult(finderClassNameCacheEnabled,
0500: finderClassName, finderMethodName,
0501: finderParams, finderArgs, list);
0502:
0503: return list;
0504: } catch (Exception e) {
0505: throw HibernateUtil.processException(e);
0506: } finally {
0507: closeSession(session);
0508: }
0509: } else {
0510: return (List) result;
0511: }
0512: }
0513:
0514: public List findByActive(boolean active, int begin, int end)
0515: throws SystemException {
0516: return findByActive(active, begin, end, null);
0517: }
0518:
0519: public List findByActive(boolean active, int begin, int end,
0520: OrderByComparator obc) throws SystemException {
0521: boolean finderClassNameCacheEnabled = RegionModelImpl.CACHE_ENABLED;
0522: String finderClassName = Region.class.getName();
0523: String finderMethodName = "findByActive";
0524: String[] finderParams = new String[] { Boolean.class.getName(),
0525:
0526: "java.lang.Integer", "java.lang.Integer",
0527: "com.liferay.portal.kernel.util.OrderByComparator" };
0528: Object[] finderArgs = new Object[] { Boolean.valueOf(active),
0529:
0530: String.valueOf(begin), String.valueOf(end), String.valueOf(obc) };
0531:
0532: Object result = null;
0533:
0534: if (finderClassNameCacheEnabled) {
0535: result = FinderCache.getResult(finderClassName,
0536: finderMethodName, finderParams, finderArgs,
0537: getSessionFactory());
0538: }
0539:
0540: if (result == null) {
0541: Session session = null;
0542:
0543: try {
0544: session = openSession();
0545:
0546: StringMaker query = new StringMaker();
0547:
0548: query
0549: .append("FROM com.liferay.portal.model.Region WHERE ");
0550:
0551: query.append("active_ = ?");
0552:
0553: query.append(" ");
0554:
0555: if (obc != null) {
0556: query.append("ORDER BY ");
0557: query.append(obc.getOrderBy());
0558: }
0559:
0560: else {
0561: query.append("ORDER BY ");
0562:
0563: query.append("name ASC");
0564: }
0565:
0566: Query q = session.createQuery(query.toString());
0567:
0568: int queryPos = 0;
0569:
0570: q.setBoolean(queryPos++, active);
0571:
0572: List list = QueryUtil.list(q, getDialect(), begin, end);
0573:
0574: FinderCache.putResult(finderClassNameCacheEnabled,
0575: finderClassName, finderMethodName,
0576: finderParams, finderArgs, list);
0577:
0578: return list;
0579: } catch (Exception e) {
0580: throw HibernateUtil.processException(e);
0581: } finally {
0582: closeSession(session);
0583: }
0584: } else {
0585: return (List) result;
0586: }
0587: }
0588:
0589: public Region findByActive_First(boolean active,
0590: OrderByComparator obc) throws NoSuchRegionException,
0591: SystemException {
0592: List list = findByActive(active, 0, 1, obc);
0593:
0594: if (list.size() == 0) {
0595: StringMaker msg = new StringMaker();
0596:
0597: msg.append("No Region exists with the key {");
0598:
0599: msg.append("active=" + active);
0600:
0601: msg.append(StringPool.CLOSE_CURLY_BRACE);
0602:
0603: throw new NoSuchRegionException(msg.toString());
0604: } else {
0605: return (Region) list.get(0);
0606: }
0607: }
0608:
0609: public Region findByActive_Last(boolean active,
0610: OrderByComparator obc) throws NoSuchRegionException,
0611: SystemException {
0612: int count = countByActive(active);
0613:
0614: List list = findByActive(active, count - 1, count, obc);
0615:
0616: if (list.size() == 0) {
0617: StringMaker msg = new StringMaker();
0618:
0619: msg.append("No Region exists with the key {");
0620:
0621: msg.append("active=" + active);
0622:
0623: msg.append(StringPool.CLOSE_CURLY_BRACE);
0624:
0625: throw new NoSuchRegionException(msg.toString());
0626: } else {
0627: return (Region) list.get(0);
0628: }
0629: }
0630:
0631: public Region[] findByActive_PrevAndNext(long regionId,
0632: boolean active, OrderByComparator obc)
0633: throws NoSuchRegionException, SystemException {
0634: Region region = findByPrimaryKey(regionId);
0635:
0636: int count = countByActive(active);
0637:
0638: Session session = null;
0639:
0640: try {
0641: session = openSession();
0642:
0643: StringMaker query = new StringMaker();
0644:
0645: query.append("FROM com.liferay.portal.model.Region WHERE ");
0646:
0647: query.append("active_ = ?");
0648:
0649: query.append(" ");
0650:
0651: if (obc != null) {
0652: query.append("ORDER BY ");
0653: query.append(obc.getOrderBy());
0654: }
0655:
0656: else {
0657: query.append("ORDER BY ");
0658:
0659: query.append("name ASC");
0660: }
0661:
0662: Query q = session.createQuery(query.toString());
0663:
0664: int queryPos = 0;
0665:
0666: q.setBoolean(queryPos++, active);
0667:
0668: Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
0669: region);
0670:
0671: Region[] array = new RegionImpl[3];
0672:
0673: array[0] = (Region) objArray[0];
0674: array[1] = (Region) objArray[1];
0675: array[2] = (Region) objArray[2];
0676:
0677: return array;
0678: } catch (Exception e) {
0679: throw HibernateUtil.processException(e);
0680: } finally {
0681: closeSession(session);
0682: }
0683: }
0684:
0685: public List findByC_A(long countryId, boolean active)
0686: throws SystemException {
0687: boolean finderClassNameCacheEnabled = RegionModelImpl.CACHE_ENABLED;
0688: String finderClassName = Region.class.getName();
0689: String finderMethodName = "findByC_A";
0690: String[] finderParams = new String[] { Long.class.getName(),
0691: Boolean.class.getName() };
0692: Object[] finderArgs = new Object[] { new Long(countryId),
0693: Boolean.valueOf(active) };
0694:
0695: Object result = null;
0696:
0697: if (finderClassNameCacheEnabled) {
0698: result = FinderCache.getResult(finderClassName,
0699: finderMethodName, finderParams, finderArgs,
0700: getSessionFactory());
0701: }
0702:
0703: if (result == null) {
0704: Session session = null;
0705:
0706: try {
0707: session = openSession();
0708:
0709: StringMaker query = new StringMaker();
0710:
0711: query
0712: .append("FROM com.liferay.portal.model.Region WHERE ");
0713:
0714: query.append("countryId = ?");
0715:
0716: query.append(" AND ");
0717:
0718: query.append("active_ = ?");
0719:
0720: query.append(" ");
0721:
0722: query.append("ORDER BY ");
0723:
0724: query.append("name ASC");
0725:
0726: Query q = session.createQuery(query.toString());
0727:
0728: int queryPos = 0;
0729:
0730: q.setLong(queryPos++, countryId);
0731:
0732: q.setBoolean(queryPos++, active);
0733:
0734: List list = q.list();
0735:
0736: FinderCache.putResult(finderClassNameCacheEnabled,
0737: finderClassName, finderMethodName,
0738: finderParams, finderArgs, list);
0739:
0740: return list;
0741: } catch (Exception e) {
0742: throw HibernateUtil.processException(e);
0743: } finally {
0744: closeSession(session);
0745: }
0746: } else {
0747: return (List) result;
0748: }
0749: }
0750:
0751: public List findByC_A(long countryId, boolean active, int begin,
0752: int end) throws SystemException {
0753: return findByC_A(countryId, active, begin, end, null);
0754: }
0755:
0756: public List findByC_A(long countryId, boolean active, int begin,
0757: int end, OrderByComparator obc) throws SystemException {
0758: boolean finderClassNameCacheEnabled = RegionModelImpl.CACHE_ENABLED;
0759: String finderClassName = Region.class.getName();
0760: String finderMethodName = "findByC_A";
0761: String[] finderParams = new String[] { Long.class.getName(),
0762: Boolean.class.getName(),
0763:
0764: "java.lang.Integer", "java.lang.Integer",
0765: "com.liferay.portal.kernel.util.OrderByComparator" };
0766: Object[] finderArgs = new Object[] { new Long(countryId),
0767: Boolean.valueOf(active),
0768:
0769: String.valueOf(begin), String.valueOf(end),
0770: String.valueOf(obc) };
0771:
0772: Object result = null;
0773:
0774: if (finderClassNameCacheEnabled) {
0775: result = FinderCache.getResult(finderClassName,
0776: finderMethodName, finderParams, finderArgs,
0777: getSessionFactory());
0778: }
0779:
0780: if (result == null) {
0781: Session session = null;
0782:
0783: try {
0784: session = openSession();
0785:
0786: StringMaker query = new StringMaker();
0787:
0788: query
0789: .append("FROM com.liferay.portal.model.Region WHERE ");
0790:
0791: query.append("countryId = ?");
0792:
0793: query.append(" AND ");
0794:
0795: query.append("active_ = ?");
0796:
0797: query.append(" ");
0798:
0799: if (obc != null) {
0800: query.append("ORDER BY ");
0801: query.append(obc.getOrderBy());
0802: }
0803:
0804: else {
0805: query.append("ORDER BY ");
0806:
0807: query.append("name ASC");
0808: }
0809:
0810: Query q = session.createQuery(query.toString());
0811:
0812: int queryPos = 0;
0813:
0814: q.setLong(queryPos++, countryId);
0815:
0816: q.setBoolean(queryPos++, active);
0817:
0818: List list = QueryUtil.list(q, getDialect(), begin, end);
0819:
0820: FinderCache.putResult(finderClassNameCacheEnabled,
0821: finderClassName, finderMethodName,
0822: finderParams, finderArgs, list);
0823:
0824: return list;
0825: } catch (Exception e) {
0826: throw HibernateUtil.processException(e);
0827: } finally {
0828: closeSession(session);
0829: }
0830: } else {
0831: return (List) result;
0832: }
0833: }
0834:
0835: public Region findByC_A_First(long countryId, boolean active,
0836: OrderByComparator obc) throws NoSuchRegionException,
0837: SystemException {
0838: List list = findByC_A(countryId, active, 0, 1, obc);
0839:
0840: if (list.size() == 0) {
0841: StringMaker msg = new StringMaker();
0842:
0843: msg.append("No Region exists with the key {");
0844:
0845: msg.append("countryId=" + countryId);
0846:
0847: msg.append(", ");
0848: msg.append("active=" + active);
0849:
0850: msg.append(StringPool.CLOSE_CURLY_BRACE);
0851:
0852: throw new NoSuchRegionException(msg.toString());
0853: } else {
0854: return (Region) list.get(0);
0855: }
0856: }
0857:
0858: public Region findByC_A_Last(long countryId, boolean active,
0859: OrderByComparator obc) throws NoSuchRegionException,
0860: SystemException {
0861: int count = countByC_A(countryId, active);
0862:
0863: List list = findByC_A(countryId, active, count - 1, count, obc);
0864:
0865: if (list.size() == 0) {
0866: StringMaker msg = new StringMaker();
0867:
0868: msg.append("No Region exists with the key {");
0869:
0870: msg.append("countryId=" + countryId);
0871:
0872: msg.append(", ");
0873: msg.append("active=" + active);
0874:
0875: msg.append(StringPool.CLOSE_CURLY_BRACE);
0876:
0877: throw new NoSuchRegionException(msg.toString());
0878: } else {
0879: return (Region) list.get(0);
0880: }
0881: }
0882:
0883: public Region[] findByC_A_PrevAndNext(long regionId,
0884: long countryId, boolean active, OrderByComparator obc)
0885: throws NoSuchRegionException, SystemException {
0886: Region region = findByPrimaryKey(regionId);
0887:
0888: int count = countByC_A(countryId, active);
0889:
0890: Session session = null;
0891:
0892: try {
0893: session = openSession();
0894:
0895: StringMaker query = new StringMaker();
0896:
0897: query.append("FROM com.liferay.portal.model.Region WHERE ");
0898:
0899: query.append("countryId = ?");
0900:
0901: query.append(" AND ");
0902:
0903: query.append("active_ = ?");
0904:
0905: query.append(" ");
0906:
0907: if (obc != null) {
0908: query.append("ORDER BY ");
0909: query.append(obc.getOrderBy());
0910: }
0911:
0912: else {
0913: query.append("ORDER BY ");
0914:
0915: query.append("name ASC");
0916: }
0917:
0918: Query q = session.createQuery(query.toString());
0919:
0920: int queryPos = 0;
0921:
0922: q.setLong(queryPos++, countryId);
0923:
0924: q.setBoolean(queryPos++, active);
0925:
0926: Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
0927: region);
0928:
0929: Region[] array = new RegionImpl[3];
0930:
0931: array[0] = (Region) objArray[0];
0932: array[1] = (Region) objArray[1];
0933: array[2] = (Region) objArray[2];
0934:
0935: return array;
0936: } catch (Exception e) {
0937: throw HibernateUtil.processException(e);
0938: } finally {
0939: closeSession(session);
0940: }
0941: }
0942:
0943: public List findWithDynamicQuery(
0944: DynamicQueryInitializer queryInitializer)
0945: throws SystemException {
0946: Session session = null;
0947:
0948: try {
0949: session = openSession();
0950:
0951: DynamicQuery query = queryInitializer.initialize(session);
0952:
0953: return query.list();
0954: } catch (Exception e) {
0955: throw HibernateUtil.processException(e);
0956: } finally {
0957: closeSession(session);
0958: }
0959: }
0960:
0961: public List findWithDynamicQuery(
0962: DynamicQueryInitializer queryInitializer, int begin, int end)
0963: throws SystemException {
0964: Session session = null;
0965:
0966: try {
0967: session = openSession();
0968:
0969: DynamicQuery query = queryInitializer.initialize(session);
0970:
0971: query.setLimit(begin, end);
0972:
0973: return query.list();
0974: } catch (Exception e) {
0975: throw HibernateUtil.processException(e);
0976: } finally {
0977: closeSession(session);
0978: }
0979: }
0980:
0981: public List findAll() throws SystemException {
0982: return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
0983: }
0984:
0985: public List findAll(int begin, int end) throws SystemException {
0986: return findAll(begin, end, null);
0987: }
0988:
0989: public List findAll(int begin, int end, OrderByComparator obc)
0990: throws SystemException {
0991: boolean finderClassNameCacheEnabled = RegionModelImpl.CACHE_ENABLED;
0992: String finderClassName = Region.class.getName();
0993: String finderMethodName = "findAll";
0994: String[] finderParams = new String[] { "java.lang.Integer",
0995: "java.lang.Integer",
0996: "com.liferay.portal.kernel.util.OrderByComparator" };
0997: Object[] finderArgs = new Object[] { String.valueOf(begin),
0998: String.valueOf(end), String.valueOf(obc) };
0999:
1000: Object result = null;
1001:
1002: if (finderClassNameCacheEnabled) {
1003: result = FinderCache.getResult(finderClassName,
1004: finderMethodName, finderParams, finderArgs,
1005: getSessionFactory());
1006: }
1007:
1008: if (result == null) {
1009: Session session = null;
1010:
1011: try {
1012: session = openSession();
1013:
1014: StringMaker query = new StringMaker();
1015:
1016: query.append("FROM com.liferay.portal.model.Region ");
1017:
1018: if (obc != null) {
1019: query.append("ORDER BY ");
1020: query.append(obc.getOrderBy());
1021: }
1022:
1023: else {
1024: query.append("ORDER BY ");
1025:
1026: query.append("name ASC");
1027: }
1028:
1029: Query q = session.createQuery(query.toString());
1030:
1031: List list = QueryUtil.list(q, getDialect(), begin, end);
1032:
1033: if (obc == null) {
1034: Collections.sort(list);
1035: }
1036:
1037: FinderCache.putResult(finderClassNameCacheEnabled,
1038: finderClassName, finderMethodName,
1039: finderParams, finderArgs, list);
1040:
1041: return list;
1042: } catch (Exception e) {
1043: throw HibernateUtil.processException(e);
1044: } finally {
1045: closeSession(session);
1046: }
1047: } else {
1048: return (List) result;
1049: }
1050: }
1051:
1052: public void removeByCountryId(long countryId)
1053: throws SystemException {
1054: Iterator itr = findByCountryId(countryId).iterator();
1055:
1056: while (itr.hasNext()) {
1057: Region region = (Region) itr.next();
1058:
1059: remove(region);
1060: }
1061: }
1062:
1063: public void removeByActive(boolean active) throws SystemException {
1064: Iterator itr = findByActive(active).iterator();
1065:
1066: while (itr.hasNext()) {
1067: Region region = (Region) itr.next();
1068:
1069: remove(region);
1070: }
1071: }
1072:
1073: public void removeByC_A(long countryId, boolean active)
1074: throws SystemException {
1075: Iterator itr = findByC_A(countryId, active).iterator();
1076:
1077: while (itr.hasNext()) {
1078: Region region = (Region) itr.next();
1079:
1080: remove(region);
1081: }
1082: }
1083:
1084: public void removeAll() throws SystemException {
1085: Iterator itr = findAll().iterator();
1086:
1087: while (itr.hasNext()) {
1088: remove((Region) itr.next());
1089: }
1090: }
1091:
1092: public int countByCountryId(long countryId) throws SystemException {
1093: boolean finderClassNameCacheEnabled = RegionModelImpl.CACHE_ENABLED;
1094: String finderClassName = Region.class.getName();
1095: String finderMethodName = "countByCountryId";
1096: String[] finderParams = new String[] { Long.class.getName() };
1097: Object[] finderArgs = new Object[] { new Long(countryId) };
1098:
1099: Object result = null;
1100:
1101: if (finderClassNameCacheEnabled) {
1102: result = FinderCache.getResult(finderClassName,
1103: finderMethodName, finderParams, finderArgs,
1104: getSessionFactory());
1105: }
1106:
1107: if (result == null) {
1108: Session session = null;
1109:
1110: try {
1111: session = openSession();
1112:
1113: StringMaker query = new StringMaker();
1114:
1115: query.append("SELECT COUNT(*) ");
1116: query
1117: .append("FROM com.liferay.portal.model.Region WHERE ");
1118:
1119: query.append("countryId = ?");
1120:
1121: query.append(" ");
1122:
1123: Query q = session.createQuery(query.toString());
1124:
1125: int queryPos = 0;
1126:
1127: q.setLong(queryPos++, countryId);
1128:
1129: Long count = null;
1130:
1131: Iterator itr = q.list().iterator();
1132:
1133: if (itr.hasNext()) {
1134: count = (Long) itr.next();
1135: }
1136:
1137: if (count == null) {
1138: count = new Long(0);
1139: }
1140:
1141: FinderCache.putResult(finderClassNameCacheEnabled,
1142: finderClassName, finderMethodName,
1143: finderParams, finderArgs, count);
1144:
1145: return count.intValue();
1146: } catch (Exception e) {
1147: throw HibernateUtil.processException(e);
1148: } finally {
1149: closeSession(session);
1150: }
1151: } else {
1152: return ((Long) result).intValue();
1153: }
1154: }
1155:
1156: public int countByActive(boolean active) throws SystemException {
1157: boolean finderClassNameCacheEnabled = RegionModelImpl.CACHE_ENABLED;
1158: String finderClassName = Region.class.getName();
1159: String finderMethodName = "countByActive";
1160: String[] finderParams = new String[] { Boolean.class.getName() };
1161: Object[] finderArgs = new Object[] { Boolean.valueOf(active) };
1162:
1163: Object result = null;
1164:
1165: if (finderClassNameCacheEnabled) {
1166: result = FinderCache.getResult(finderClassName,
1167: finderMethodName, finderParams, finderArgs,
1168: getSessionFactory());
1169: }
1170:
1171: if (result == null) {
1172: Session session = null;
1173:
1174: try {
1175: session = openSession();
1176:
1177: StringMaker query = new StringMaker();
1178:
1179: query.append("SELECT COUNT(*) ");
1180: query
1181: .append("FROM com.liferay.portal.model.Region WHERE ");
1182:
1183: query.append("active_ = ?");
1184:
1185: query.append(" ");
1186:
1187: Query q = session.createQuery(query.toString());
1188:
1189: int queryPos = 0;
1190:
1191: q.setBoolean(queryPos++, active);
1192:
1193: Long count = null;
1194:
1195: Iterator itr = q.list().iterator();
1196:
1197: if (itr.hasNext()) {
1198: count = (Long) itr.next();
1199: }
1200:
1201: if (count == null) {
1202: count = new Long(0);
1203: }
1204:
1205: FinderCache.putResult(finderClassNameCacheEnabled,
1206: finderClassName, finderMethodName,
1207: finderParams, finderArgs, count);
1208:
1209: return count.intValue();
1210: } catch (Exception e) {
1211: throw HibernateUtil.processException(e);
1212: } finally {
1213: closeSession(session);
1214: }
1215: } else {
1216: return ((Long) result).intValue();
1217: }
1218: }
1219:
1220: public int countByC_A(long countryId, boolean active)
1221: throws SystemException {
1222: boolean finderClassNameCacheEnabled = RegionModelImpl.CACHE_ENABLED;
1223: String finderClassName = Region.class.getName();
1224: String finderMethodName = "countByC_A";
1225: String[] finderParams = new String[] { Long.class.getName(),
1226: Boolean.class.getName() };
1227: Object[] finderArgs = new Object[] { new Long(countryId),
1228: Boolean.valueOf(active) };
1229:
1230: Object result = null;
1231:
1232: if (finderClassNameCacheEnabled) {
1233: result = FinderCache.getResult(finderClassName,
1234: finderMethodName, finderParams, finderArgs,
1235: getSessionFactory());
1236: }
1237:
1238: if (result == null) {
1239: Session session = null;
1240:
1241: try {
1242: session = openSession();
1243:
1244: StringMaker query = new StringMaker();
1245:
1246: query.append("SELECT COUNT(*) ");
1247: query
1248: .append("FROM com.liferay.portal.model.Region WHERE ");
1249:
1250: query.append("countryId = ?");
1251:
1252: query.append(" AND ");
1253:
1254: query.append("active_ = ?");
1255:
1256: query.append(" ");
1257:
1258: Query q = session.createQuery(query.toString());
1259:
1260: int queryPos = 0;
1261:
1262: q.setLong(queryPos++, countryId);
1263:
1264: q.setBoolean(queryPos++, active);
1265:
1266: Long count = null;
1267:
1268: Iterator itr = q.list().iterator();
1269:
1270: if (itr.hasNext()) {
1271: count = (Long) itr.next();
1272: }
1273:
1274: if (count == null) {
1275: count = new Long(0);
1276: }
1277:
1278: FinderCache.putResult(finderClassNameCacheEnabled,
1279: finderClassName, finderMethodName,
1280: finderParams, finderArgs, count);
1281:
1282: return count.intValue();
1283: } catch (Exception e) {
1284: throw HibernateUtil.processException(e);
1285: } finally {
1286: closeSession(session);
1287: }
1288: } else {
1289: return ((Long) result).intValue();
1290: }
1291: }
1292:
1293: public int countAll() throws SystemException {
1294: boolean finderClassNameCacheEnabled = RegionModelImpl.CACHE_ENABLED;
1295: String finderClassName = Region.class.getName();
1296: String finderMethodName = "countAll";
1297: String[] finderParams = new String[] {};
1298: Object[] finderArgs = new Object[] {};
1299:
1300: Object result = null;
1301:
1302: if (finderClassNameCacheEnabled) {
1303: result = FinderCache.getResult(finderClassName,
1304: finderMethodName, finderParams, finderArgs,
1305: getSessionFactory());
1306: }
1307:
1308: if (result == null) {
1309: Session session = null;
1310:
1311: try {
1312: session = openSession();
1313:
1314: Query q = session
1315: .createQuery("SELECT COUNT(*) FROM com.liferay.portal.model.Region");
1316:
1317: Long count = null;
1318:
1319: Iterator itr = q.list().iterator();
1320:
1321: if (itr.hasNext()) {
1322: count = (Long) itr.next();
1323: }
1324:
1325: if (count == null) {
1326: count = new Long(0);
1327: }
1328:
1329: FinderCache.putResult(finderClassNameCacheEnabled,
1330: finderClassName, finderMethodName,
1331: finderParams, finderArgs, count);
1332:
1333: return count.intValue();
1334: } catch (Exception e) {
1335: throw HibernateUtil.processException(e);
1336: } finally {
1337: closeSession(session);
1338: }
1339: } else {
1340: return ((Long) result).intValue();
1341: }
1342: }
1343:
1344: protected void initDao() {
1345: }
1346:
1347: private static ModelListener _getListener() {
1348: if (Validator.isNotNull(_LISTENER)) {
1349: try {
1350: return (ModelListener) Class.forName(_LISTENER)
1351: .newInstance();
1352: } catch (Exception e) {
1353: _log.error(e);
1354: }
1355: }
1356:
1357: return null;
1358: }
1359:
1360: private static final String _LISTENER = GetterUtil
1361: .getString(PropsUtil
1362: .get("value.object.listener.com.liferay.portal.model.Region"));
1363: private static Log _log = LogFactory
1364: .getLog(RegionPersistenceImpl.class);
1365: }
|