/**
* Copyright (c) 2000-present Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/
package com.liferay.portal.service.persistence.impl;
import aQute.bnd.annotation.ProviderType;
import com.liferay.portal.kernel.dao.orm.EntityCache;
import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
import com.liferay.portal.kernel.dao.orm.FinderCache;
import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
import com.liferay.portal.kernel.dao.orm.FinderPath;
import com.liferay.portal.kernel.dao.orm.Query;
import com.liferay.portal.kernel.dao.orm.QueryPos;
import com.liferay.portal.kernel.dao.orm.QueryUtil;
import com.liferay.portal.kernel.dao.orm.Session;
import com.liferay.portal.kernel.exception.NoSuchRegionException;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.model.Region;
import com.liferay.portal.kernel.service.persistence.RegionPersistence;
import com.liferay.portal.kernel.service.persistence.impl.BasePersistenceImpl;
import com.liferay.portal.kernel.util.OrderByComparator;
import com.liferay.portal.kernel.util.ReflectionUtil;
import com.liferay.portal.kernel.util.SetUtil;
import com.liferay.portal.kernel.util.StringBundler;
import com.liferay.portal.kernel.util.StringPool;
import com.liferay.portal.model.impl.RegionImpl;
import com.liferay.portal.model.impl.RegionModelImpl;
import java.io.Serializable;
import java.lang.reflect.Field;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
/**
* The persistence implementation for the region service.
*
* <p>
* Caching information and settings can be found in <code>portal.properties</code>
* </p>
*
* @author Brian Wing Shun Chan
* @see RegionPersistence
* @see com.liferay.portal.kernel.service.persistence.RegionUtil
* @generated
*/
@ProviderType
public class RegionPersistenceImpl extends BasePersistenceImpl<Region>
implements RegionPersistence {
/*
* NOTE FOR DEVELOPERS:
*
* Never modify or reference this class directly. Always use {@link RegionUtil} to access the region persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
*/
public static final String FINDER_CLASS_NAME_ENTITY = RegionImpl.class.getName();
public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
".List1";
public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
".List2";
public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(RegionModelImpl.ENTITY_CACHE_ENABLED,
RegionModelImpl.FINDER_CACHE_ENABLED, RegionImpl.class,
FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(RegionModelImpl.ENTITY_CACHE_ENABLED,
RegionModelImpl.FINDER_CACHE_ENABLED, RegionImpl.class,
FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(RegionModelImpl.ENTITY_CACHE_ENABLED,
RegionModelImpl.FINDER_CACHE_ENABLED, Long.class,
FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COUNTRYID =
new FinderPath(RegionModelImpl.ENTITY_CACHE_ENABLED,
RegionModelImpl.FINDER_CACHE_ENABLED, RegionImpl.class,
FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByCountryId",
new String[] {
Long.class.getName(),
Integer.class.getName(), Integer.class.getName(),
OrderByComparator.class.getName()
});
public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COUNTRYID =
new FinderPath(RegionModelImpl.ENTITY_CACHE_ENABLED,
RegionModelImpl.FINDER_CACHE_ENABLED, RegionImpl.class,
FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCountryId",
new String[] { Long.class.getName() },
RegionModelImpl.COUNTRYID_COLUMN_BITMASK |
RegionModelImpl.NAME_COLUMN_BITMASK);
public static final FinderPath FINDER_PATH_COUNT_BY_COUNTRYID = new FinderPath(RegionModelImpl.ENTITY_CACHE_ENABLED,
RegionModelImpl.FINDER_CACHE_ENABLED, Long.class,
FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCountryId",
new String[] { Long.class.getName() });
/**
* Returns all the regions where countryId = ?.
*
* @param countryId the country ID
* @return the matching regions
*/
@Override
public List<Region> findByCountryId(long countryId) {
return findByCountryId(countryId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
null);
}
/**
* Returns a range of all the regions where countryId = ?.
*
* <p>
* Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link RegionModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
* </p>
*
* @param countryId the country ID
* @param start the lower bound of the range of regions
* @param end the upper bound of the range of regions (not inclusive)
* @return the range of matching regions
*/
@Override
public List<Region> findByCountryId(long countryId, int start, int end) {
return findByCountryId(countryId, start, end, null);
}
/**
* Returns an ordered range of all the regions where countryId = ?.
*
* <p>
* Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link RegionModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
* </p>
*
* @param countryId the country ID
* @param start the lower bound of the range of regions
* @param end the upper bound of the range of regions (not inclusive)
* @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
* @return the ordered range of matching regions
*/
@Override
public List<Region> findByCountryId(long countryId, int start, int end,
OrderByComparator<Region> orderByComparator) {
return findByCountryId(countryId, start, end, orderByComparator, true);
}
/**
* Returns an ordered range of all the regions where countryId = ?.
*
* <p>
* Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link RegionModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
* </p>
*
* @param countryId the country ID
* @param start the lower bound of the range of regions
* @param end the upper bound of the range of regions (not inclusive)
* @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
* @param retrieveFromCache whether to retrieve from the finder cache
* @return the ordered range of matching regions
*/
@Override
public List<Region> findByCountryId(long countryId, int start, int end,
OrderByComparator<Region> orderByComparator, boolean retrieveFromCache) {
boolean pagination = true;
FinderPath finderPath = null;
Object[] finderArgs = null;
if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
(orderByComparator == null)) {
pagination = false;
finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COUNTRYID;
finderArgs = new Object[] { countryId };
}
else {
finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COUNTRYID;
finderArgs = new Object[] { countryId, start, end, orderByComparator };
}
List<Region> list = null;
if (retrieveFromCache) {
list = (List<Region>)finderCache.getResult(finderPath, finderArgs,
this);
if ((list != null) && !list.isEmpty()) {
for (Region region : list) {
if ((countryId != region.getCountryId())) {
list = null;
break;
}
}
}
}
if (list == null) {
StringBundler query = null;
if (orderByComparator != null) {
query = new StringBundler(3 +
(orderByComparator.getOrderByFields().length * 2));
}
else {
query = new StringBundler(3);
}
query.append(_SQL_SELECT_REGION_WHERE);
query.append(_FINDER_COLUMN_COUNTRYID_COUNTRYID_2);
if (orderByComparator != null) {
appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
orderByComparator);
}
else
if (pagination) {
query.append(RegionModelImpl.ORDER_BY_JPQL);
}
String sql = query.toString();
Session session = null;
try {
session = openSession();
Query q = session.createQuery(sql);
QueryPos qPos = QueryPos.getInstance(q);
qPos.add(countryId);
if (!pagination) {
list = (List<Region>)QueryUtil.list(q, getDialect(), start,
end, false);
Collections.sort(list);
list = Collections.unmodifiableList(list);
}
else {
list = (List<Region>)QueryUtil.list(q, getDialect(), start,
end);
}
cacheResult(list);
finderCache.putResult(finderPath, finderArgs, list);
}
catch (Exception e) {
finderCache.removeResult(finderPath, finderArgs);
throw processException(e);
}
finally {
closeSession(session);
}
}
return list;
}
/**
* Returns the first region in the ordered set where countryId = ?.
*
* @param countryId the country ID
* @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
* @return the first matching region
* @throws NoSuchRegionException if a matching region could not be found
*/
@Override
public Region findByCountryId_First(long countryId,
OrderByComparator<Region> orderByComparator)
throws NoSuchRegionException {
Region region = fetchByCountryId_First(countryId, orderByComparator);
if (region != null) {
return region;
}
StringBundler msg = new StringBundler(4);
msg.append(_NO_SUCH_ENTITY_WITH_KEY);
msg.append("countryId=");
msg.append(countryId);
msg.append(StringPool.CLOSE_CURLY_BRACE);
throw new NoSuchRegionException(msg.toString());
}
/**
* Returns the first region in the ordered set where countryId = ?.
*
* @param countryId the country ID
* @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
* @return the first matching region, or <code>null</code> if a matching region could not be found
*/
@Override
public Region fetchByCountryId_First(long countryId,
OrderByComparator<Region> orderByComparator) {
List<Region> list = findByCountryId(countryId, 0, 1, orderByComparator);
if (!list.isEmpty()) {
return list.get(0);
}
return null;
}
/**
* Returns the last region in the ordered set where countryId = ?.
*
* @param countryId the country ID
* @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
* @return the last matching region
* @throws NoSuchRegionException if a matching region could not be found
*/
@Override
public Region findByCountryId_Last(long countryId,
OrderByComparator<Region> orderByComparator)
throws NoSuchRegionException {
Region region = fetchByCountryId_Last(countryId, orderByComparator);
if (region != null) {
return region;
}
StringBundler msg = new StringBundler(4);
msg.append(_NO_SUCH_ENTITY_WITH_KEY);
msg.append("countryId=");
msg.append(countryId);
msg.append(StringPool.CLOSE_CURLY_BRACE);
throw new NoSuchRegionException(msg.toString());
}
/**
* Returns the last region in the ordered set where countryId = ?.
*
* @param countryId the country ID
* @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
* @return the last matching region, or <code>null</code> if a matching region could not be found
*/
@Override
public Region fetchByCountryId_Last(long countryId,
OrderByComparator<Region> orderByComparator) {
int count = countByCountryId(countryId);
if (count == 0) {
return null;
}
List<Region> list = findByCountryId(countryId, count - 1, count,
orderByComparator);
if (!list.isEmpty()) {
return list.get(0);
}
return null;
}
/**
* Returns the regions before and after the current region in the ordered set where countryId = ?.
*
* @param regionId the primary key of the current region
* @param countryId the country ID
* @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
* @return the previous, current, and next region
* @throws NoSuchRegionException if a region with the primary key could not be found
*/
@Override
public Region[] findByCountryId_PrevAndNext(long regionId, long countryId,
OrderByComparator<Region> orderByComparator)
throws NoSuchRegionException {
Region region = findByPrimaryKey(regionId);
Session session = null;
try {
session = openSession();
Region[] array = new RegionImpl[3];
array[0] = getByCountryId_PrevAndNext(session, region, countryId,
orderByComparator, true);
array[1] = region;
array[2] = getByCountryId_PrevAndNext(session, region, countryId,
orderByComparator, false);
return array;
}
catch (Exception e) {
throw processException(e);
}
finally {
closeSession(session);
}
}
protected Region getByCountryId_PrevAndNext(Session session, Region region,
long countryId, OrderByComparator<Region> orderByComparator,
boolean previous) {
StringBundler query = null;
if (orderByComparator != null) {
query = new StringBundler(4 +
(orderByComparator.getOrderByConditionFields().length * 3) +
(orderByComparator.getOrderByFields().length * 3));
}
else {
query = new StringBundler(3);
}
query.append(_SQL_SELECT_REGION_WHERE);
query.append(_FINDER_COLUMN_COUNTRYID_COUNTRYID_2);
if (orderByComparator != null) {
String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
if (orderByConditionFields.length > 0) {
query.append(WHERE_AND);
}
for (int i = 0; i < orderByConditionFields.length; i++) {
query.append(_ORDER_BY_ENTITY_ALIAS);
query.append(orderByConditionFields[i]);
if ((i + 1) < orderByConditionFields.length) {
if (orderByComparator.isAscending() ^ previous) {
query.append(WHERE_GREATER_THAN_HAS_NEXT);
}
else {
query.append(WHERE_LESSER_THAN_HAS_NEXT);
}
}
else {
if (orderByComparator.isAscending() ^ previous) {
query.append(WHERE_GREATER_THAN);
}
else {
query.append(WHERE_LESSER_THAN);
}
}
}
query.append(ORDER_BY_CLAUSE);
String[] orderByFields = orderByComparator.getOrderByFields();
for (int i = 0; i < orderByFields.length; i++) {
query.append(_ORDER_BY_ENTITY_ALIAS);
query.append(orderByFields[i]);
if ((i + 1) < orderByFields.length) {
if (orderByComparator.isAscending() ^ previous) {
query.append(ORDER_BY_ASC_HAS_NEXT);
}
else {
query.append(ORDER_BY_DESC_HAS_NEXT);
}
}
else {
if (orderByComparator.isAscending() ^ previous) {
query.append(ORDER_BY_ASC);
}
else {
query.append(ORDER_BY_DESC);
}
}
}
}
else {
query.append(RegionModelImpl.ORDER_BY_JPQL);
}
String sql = query.toString();
Query q = session.createQuery(sql);
q.setFirstResult(0);
q.setMaxResults(2);
QueryPos qPos = QueryPos.getInstance(q);
qPos.add(countryId);
if (orderByComparator != null) {
Object[] values = orderByComparator.getOrderByConditionValues(region);
for (Object value : values) {
qPos.add(value);
}
}
List<Region> list = q.list();
if (list.size() == 2) {
return list.get(1);
}
else {
return null;
}
}
/**
* Removes all the regions where countryId = ? from the database.
*
* @param countryId the country ID
*/
@Override
public void removeByCountryId(long countryId) {
for (Region region : findByCountryId(countryId, QueryUtil.ALL_POS,
QueryUtil.ALL_POS, null)) {
remove(region);
}
}
/**
* Returns the number of regions where countryId = ?.
*
* @param countryId the country ID
* @return the number of matching regions
*/
@Override
public int countByCountryId(long countryId) {
FinderPath finderPath = FINDER_PATH_COUNT_BY_COUNTRYID;
Object[] finderArgs = new Object[] { countryId };
Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
if (count == null) {
StringBundler query = new StringBundler(2);
query.append(_SQL_COUNT_REGION_WHERE);
query.append(_FINDER_COLUMN_COUNTRYID_COUNTRYID_2);
String sql = query.toString();
Session session = null;
try {
session = openSession();
Query q = session.createQuery(sql);
QueryPos qPos = QueryPos.getInstance(q);
qPos.add(countryId);
count = (Long)q.uniqueResult();
finderCache.putResult(finderPath, finderArgs, count);
}
catch (Exception e) {
finderCache.removeResult(finderPath, finderArgs);
throw processException(e);
}
finally {
closeSession(session);
}
}
return count.intValue();
}
private static final String _FINDER_COLUMN_COUNTRYID_COUNTRYID_2 = "region.countryId = ?";
public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_ACTIVE = new FinderPath(RegionModelImpl.ENTITY_CACHE_ENABLED,
RegionModelImpl.FINDER_CACHE_ENABLED, RegionImpl.class,
FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByActive",
new String[] {
Boolean.class.getName(),
Integer.class.getName(), Integer.class.getName(),
OrderByComparator.class.getName()
});
public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ACTIVE =
new FinderPath(RegionModelImpl.ENTITY_CACHE_ENABLED,
RegionModelImpl.FINDER_CACHE_ENABLED, RegionImpl.class,
FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByActive",
new String[] { Boolean.class.getName() },
RegionModelImpl.ACTIVE_COLUMN_BITMASK |
RegionModelImpl.NAME_COLUMN_BITMASK);
public static final FinderPath FINDER_PATH_COUNT_BY_ACTIVE = new FinderPath(RegionModelImpl.ENTITY_CACHE_ENABLED,
RegionModelImpl.FINDER_CACHE_ENABLED, Long.class,
FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByActive",
new String[] { Boolean.class.getName() });
/**
* Returns all the regions where active = ?.
*
* @param active the active
* @return the matching regions
*/
@Override
public List<Region> findByActive(boolean active) {
return findByActive(active, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
}
/**
* Returns a range of all the regions where active = ?.
*
* <p>
* Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link RegionModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
* </p>
*
* @param active the active
* @param start the lower bound of the range of regions
* @param end the upper bound of the range of regions (not inclusive)
* @return the range of matching regions
*/
@Override
public List<Region> findByActive(boolean active, int start, int end) {
return findByActive(active, start, end, null);
}
/**
* Returns an ordered range of all the regions where active = ?.
*
* <p>
* Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link RegionModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
* </p>
*
* @param active the active
* @param start the lower bound of the range of regions
* @param end the upper bound of the range of regions (not inclusive)
* @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
* @return the ordered range of matching regions
*/
@Override
public List<Region> findByActive(boolean active, int start, int end,
OrderByComparator<Region> orderByComparator) {
return findByActive(active, start, end, orderByComparator, true);
}
/**
* Returns an ordered range of all the regions where active = ?.
*
* <p>
* Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link RegionModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
* </p>
*
* @param active the active
* @param start the lower bound of the range of regions
* @param end the upper bound of the range of regions (not inclusive)
* @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
* @param retrieveFromCache whether to retrieve from the finder cache
* @return the ordered range of matching regions
*/
@Override
public List<Region> findByActive(boolean active, int start, int end,
OrderByComparator<Region> orderByComparator, boolean retrieveFromCache) {
boolean pagination = true;
FinderPath finderPath = null;
Object[] finderArgs = null;
if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
(orderByComparator == null)) {
pagination = false;
finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ACTIVE;
finderArgs = new Object[] { active };
}
else {
finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_ACTIVE;
finderArgs = new Object[] { active, start, end, orderByComparator };
}
List<Region> list = null;
if (retrieveFromCache) {
list = (List<Region>)finderCache.getResult(finderPath, finderArgs,
this);
if ((list != null) && !list.isEmpty()) {
for (Region region : list) {
if ((active != region.getActive())) {
list = null;
break;
}
}
}
}
if (list == null) {
StringBundler query = null;
if (orderByComparator != null) {
query = new StringBundler(3 +
(orderByComparator.getOrderByFields().length * 2));
}
else {
query = new StringBundler(3);
}
query.append(_SQL_SELECT_REGION_WHERE);
query.append(_FINDER_COLUMN_ACTIVE_ACTIVE_2);
if (orderByComparator != null) {
appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
orderByComparator);
}
else
if (pagination) {
query.append(RegionModelImpl.ORDER_BY_JPQL);
}
String sql = query.toString();
Session session = null;
try {
session = openSession();
Query q = session.createQuery(sql);
QueryPos qPos = QueryPos.getInstance(q);
qPos.add(active);
if (!pagination) {
list = (List<Region>)QueryUtil.list(q, getDialect(), start,
end, false);
Collections.sort(list);
list = Collections.unmodifiableList(list);
}
else {
list = (List<Region>)QueryUtil.list(q, getDialect(), start,
end);
}
cacheResult(list);
finderCache.putResult(finderPath, finderArgs, list);
}
catch (Exception e) {
finderCache.removeResult(finderPath, finderArgs);
throw processException(e);
}
finally {
closeSession(session);
}
}
return list;
}
/**
* Returns the first region in the ordered set where active = ?.
*
* @param active the active
* @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
* @return the first matching region
* @throws NoSuchRegionException if a matching region could not be found
*/
@Override
public Region findByActive_First(boolean active,
OrderByComparator<Region> orderByComparator)
throws NoSuchRegionException {
Region region = fetchByActive_First(active, orderByComparator);
if (region != null) {
return region;
}
StringBundler msg = new StringBundler(4);
msg.append(_NO_SUCH_ENTITY_WITH_KEY);
msg.append("active=");
msg.append(active);
msg.append(StringPool.CLOSE_CURLY_BRACE);
throw new NoSuchRegionException(msg.toString());
}
/**
* Returns the first region in the ordered set where active = ?.
*
* @param active the active
* @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
* @return the first matching region, or <code>null</code> if a matching region could not be found
*/
@Override
public Region fetchByActive_First(boolean active,
OrderByComparator<Region> orderByComparator) {
List<Region> list = findByActive(active, 0, 1, orderByComparator);
if (!list.isEmpty()) {
return list.get(0);
}
return null;
}
/**
* Returns the last region in the ordered set where active = ?.
*
* @param active the active
* @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
* @return the last matching region
* @throws NoSuchRegionException if a matching region could not be found
*/
@Override
public Region findByActive_Last(boolean active,
OrderByComparator<Region> orderByComparator)
throws NoSuchRegionException {
Region region = fetchByActive_Last(active, orderByComparator);
if (region != null) {
return region;
}
StringBundler msg = new StringBundler(4);
msg.append(_NO_SUCH_ENTITY_WITH_KEY);
msg.append("active=");
msg.append(active);
msg.append(StringPool.CLOSE_CURLY_BRACE);
throw new NoSuchRegionException(msg.toString());
}
/**
* Returns the last region in the ordered set where active = ?.
*
* @param active the active
* @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
* @return the last matching region, or <code>null</code> if a matching region could not be found
*/
@Override
public Region fetchByActive_Last(boolean active,
OrderByComparator<Region> orderByComparator) {
int count = countByActive(active);
if (count == 0) {
return null;
}
List<Region> list = findByActive(active, count - 1, count,
orderByComparator);
if (!list.isEmpty()) {
return list.get(0);
}
return null;
}
/**
* Returns the regions before and after the current region in the ordered set where active = ?.
*
* @param regionId the primary key of the current region
* @param active the active
* @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
* @return the previous, current, and next region
* @throws NoSuchRegionException if a region with the primary key could not be found
*/
@Override
public Region[] findByActive_PrevAndNext(long regionId, boolean active,
OrderByComparator<Region> orderByComparator)
throws NoSuchRegionException {
Region region = findByPrimaryKey(regionId);
Session session = null;
try {
session = openSession();
Region[] array = new RegionImpl[3];
array[0] = getByActive_PrevAndNext(session, region, active,
orderByComparator, true);
array[1] = region;
array[2] = getByActive_PrevAndNext(session, region, active,
orderByComparator, false);
return array;
}
catch (Exception e) {
throw processException(e);
}
finally {
closeSession(session);
}
}
protected Region getByActive_PrevAndNext(Session session, Region region,
boolean active, OrderByComparator<Region> orderByComparator,
boolean previous) {
StringBundler query = null;
if (orderByComparator != null) {
query = new StringBundler(4 +
(orderByComparator.getOrderByConditionFields().length * 3) +
(orderByComparator.getOrderByFields().length * 3));
}
else {
query = new StringBundler(3);
}
query.append(_SQL_SELECT_REGION_WHERE);
query.append(_FINDER_COLUMN_ACTIVE_ACTIVE_2);
if (orderByComparator != null) {
String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
if (orderByConditionFields.length > 0) {
query.append(WHERE_AND);
}
for (int i = 0; i < orderByConditionFields.length; i++) {
query.append(_ORDER_BY_ENTITY_ALIAS);
query.append(orderByConditionFields[i]);
if ((i + 1) < orderByConditionFields.length) {
if (orderByComparator.isAscending() ^ previous) {
query.append(WHERE_GREATER_THAN_HAS_NEXT);
}
else {
query.append(WHERE_LESSER_THAN_HAS_NEXT);
}
}
else {
if (orderByComparator.isAscending() ^ previous) {
query.append(WHERE_GREATER_THAN);
}
else {
query.append(WHERE_LESSER_THAN);
}
}
}
query.append(ORDER_BY_CLAUSE);
String[] orderByFields = orderByComparator.getOrderByFields();
for (int i = 0; i < orderByFields.length; i++) {
query.append(_ORDER_BY_ENTITY_ALIAS);
query.append(orderByFields[i]);
if ((i + 1) < orderByFields.length) {
if (orderByComparator.isAscending() ^ previous) {
query.append(ORDER_BY_ASC_HAS_NEXT);
}
else {
query.append(ORDER_BY_DESC_HAS_NEXT);
}
}
else {
if (orderByComparator.isAscending() ^ previous) {
query.append(ORDER_BY_ASC);
}
else {
query.append(ORDER_BY_DESC);
}
}
}
}
else {
query.append(RegionModelImpl.ORDER_BY_JPQL);
}
String sql = query.toString();
Query q = session.createQuery(sql);
q.setFirstResult(0);
q.setMaxResults(2);
QueryPos qPos = QueryPos.getInstance(q);
qPos.add(active);
if (orderByComparator != null) {
Object[] values = orderByComparator.getOrderByConditionValues(region);
for (Object value : values) {
qPos.add(value);
}
}
List<Region> list = q.list();
if (list.size() == 2) {
return list.get(1);
}
else {
return null;
}
}
/**
* Removes all the regions where active = ? from the database.
*
* @param active the active
*/
@Override
public void removeByActive(boolean active) {
for (Region region : findByActive(active, QueryUtil.ALL_POS,
QueryUtil.ALL_POS, null)) {
remove(region);
}
}
/**
* Returns the number of regions where active = ?.
*
* @param active the active
* @return the number of matching regions
*/
@Override
public int countByActive(boolean active) {
FinderPath finderPath = FINDER_PATH_COUNT_BY_ACTIVE;
Object[] finderArgs = new Object[] { active };
Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
if (count == null) {
StringBundler query = new StringBundler(2);
query.append(_SQL_COUNT_REGION_WHERE);
query.append(_FINDER_COLUMN_ACTIVE_ACTIVE_2);
String sql = query.toString();
Session session = null;
try {
session = openSession();
Query q = session.createQuery(sql);
QueryPos qPos = QueryPos.getInstance(q);
qPos.add(active);
count = (Long)q.uniqueResult();
finderCache.putResult(finderPath, finderArgs, count);
}
catch (Exception e) {
finderCache.removeResult(finderPath, finderArgs);
throw processException(e);
}
finally {
closeSession(session);
}
}
return count.intValue();
}
private static final String _FINDER_COLUMN_ACTIVE_ACTIVE_2 = "region.active = ?";
public static final FinderPath FINDER_PATH_FETCH_BY_C_R = new FinderPath(RegionModelImpl.ENTITY_CACHE_ENABLED,
RegionModelImpl.FINDER_CACHE_ENABLED, RegionImpl.class,
FINDER_CLASS_NAME_ENTITY, "fetchByC_R",
new String[] { Long.class.getName(), String.class.getName() },
RegionModelImpl.COUNTRYID_COLUMN_BITMASK |
RegionModelImpl.REGIONCODE_COLUMN_BITMASK);
public static final FinderPath FINDER_PATH_COUNT_BY_C_R = new FinderPath(RegionModelImpl.ENTITY_CACHE_ENABLED,
RegionModelImpl.FINDER_CACHE_ENABLED, Long.class,
FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_R",
new String[] { Long.class.getName(), String.class.getName() });
/**
* Returns the region where countryId = ? and regionCode = ? or throws a {@link NoSuchRegionException} if it could not be found.
*
* @param countryId the country ID
* @param regionCode the region code
* @return the matching region
* @throws NoSuchRegionException if a matching region could not be found
*/
@Override
public Region findByC_R(long countryId, String regionCode)
throws NoSuchRegionException {
Region region = fetchByC_R(countryId, regionCode);
if (region == null) {
StringBundler msg = new StringBundler(6);
msg.append(_NO_SUCH_ENTITY_WITH_KEY);
msg.append("countryId=");
msg.append(countryId);
msg.append(", regionCode=");
msg.append(regionCode);
msg.append(StringPool.CLOSE_CURLY_BRACE);
if (_log.isDebugEnabled()) {
_log.debug(msg.toString());
}
throw new NoSuchRegionException(msg.toString());
}
return region;
}
/**
* Returns the region where countryId = ? and regionCode = ? or returns <code>null</code> if it could not be found. Uses the finder cache.
*
* @param countryId the country ID
* @param regionCode the region code
* @return the matching region, or <code>null</code> if a matching region could not be found
*/
@Override
public Region fetchByC_R(long countryId, String regionCode) {
return fetchByC_R(countryId, regionCode, true);
}
/**
* Returns the region where countryId = ? and regionCode = ? or returns <code>null</code> if it could not be found, optionally using the finder cache.
*
* @param countryId the country ID
* @param regionCode the region code
* @param retrieveFromCache whether to retrieve from the finder cache
* @return the matching region, or <code>null</code> if a matching region could not be found
*/
@Override
public Region fetchByC_R(long countryId, String regionCode,
boolean retrieveFromCache) {
Object[] finderArgs = new Object[] { countryId, regionCode };
Object result = null;
if (retrieveFromCache) {
result = finderCache.getResult(FINDER_PATH_FETCH_BY_C_R,
finderArgs, this);
}
if (result instanceof Region) {
Region region = (Region)result;
if ((countryId != region.getCountryId()) ||
!Objects.equals(regionCode, region.getRegionCode())) {
result = null;
}
}
if (result == null) {
StringBundler query = new StringBundler(4);
query.append(_SQL_SELECT_REGION_WHERE);
query.append(_FINDER_COLUMN_C_R_COUNTRYID_2);
boolean bindRegionCode = false;
if (regionCode == null) {
query.append(_FINDER_COLUMN_C_R_REGIONCODE_1);
}
else if (regionCode.equals(StringPool.BLANK)) {
query.append(_FINDER_COLUMN_C_R_REGIONCODE_3);
}
else {
bindRegionCode = true;
query.append(_FINDER_COLUMN_C_R_REGIONCODE_2);
}
String sql = query.toString();
Session session = null;
try {
session = openSession();
Query q = session.createQuery(sql);
QueryPos qPos = QueryPos.getInstance(q);
qPos.add(countryId);
if (bindRegionCode) {
qPos.add(regionCode);
}
List<Region> list = q.list();
if (list.isEmpty()) {
finderCache.putResult(FINDER_PATH_FETCH_BY_C_R, finderArgs,
list);
}
else {
Region region = list.get(0);
result = region;
cacheResult(region);
if ((region.getCountryId() != countryId) ||
(region.getRegionCode() == null) ||
!region.getRegionCode().equals(regionCode)) {
finderCache.putResult(FINDER_PATH_FETCH_BY_C_R,
finderArgs, region);
}
}
}
catch (Exception e) {
finderCache.removeResult(FINDER_PATH_FETCH_BY_C_R, finderArgs);
throw processException(e);
}
finally {
closeSession(session);
}
}
if (result instanceof List<?>) {
return null;
}
else {
return (Region)result;
}
}
/**
* Removes the region where countryId = ? and regionCode = ? from the database.
*
* @param countryId the country ID
* @param regionCode the region code
* @return the region that was removed
*/
@Override
public Region removeByC_R(long countryId, String regionCode)
throws NoSuchRegionException {
Region region = findByC_R(countryId, regionCode);
return remove(region);
}
/**
* Returns the number of regions where countryId = ? and regionCode = ?.
*
* @param countryId the country ID
* @param regionCode the region code
* @return the number of matching regions
*/
@Override
public int countByC_R(long countryId, String regionCode) {
FinderPath finderPath = FINDER_PATH_COUNT_BY_C_R;
Object[] finderArgs = new Object[] { countryId, regionCode };
Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
if (count == null) {
StringBundler query = new StringBundler(3);
query.append(_SQL_COUNT_REGION_WHERE);
query.append(_FINDER_COLUMN_C_R_COUNTRYID_2);
boolean bindRegionCode = false;
if (regionCode == null) {
query.append(_FINDER_COLUMN_C_R_REGIONCODE_1);
}
else if (regionCode.equals(StringPool.BLANK)) {
query.append(_FINDER_COLUMN_C_R_REGIONCODE_3);
}
else {
bindRegionCode = true;
query.append(_FINDER_COLUMN_C_R_REGIONCODE_2);
}
String sql = query.toString();
Session session = null;
try {
session = openSession();
Query q = session.createQuery(sql);
QueryPos qPos = QueryPos.getInstance(q);
qPos.add(countryId);
if (bindRegionCode) {
qPos.add(regionCode);
}
count = (Long)q.uniqueResult();
finderCache.putResult(finderPath, finderArgs, count);
}
catch (Exception e) {
finderCache.removeResult(finderPath, finderArgs);
throw processException(e);
}
finally {
closeSession(session);
}
}
return count.intValue();
}
private static final String _FINDER_COLUMN_C_R_COUNTRYID_2 = "region.countryId = ? AND ";
private static final String _FINDER_COLUMN_C_R_REGIONCODE_1 = "region.regionCode IS NULL";
private static final String _FINDER_COLUMN_C_R_REGIONCODE_2 = "region.regionCode = ?";
private static final String _FINDER_COLUMN_C_R_REGIONCODE_3 = "(region.regionCode IS NULL OR region.regionCode = '')";
public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_A = new FinderPath(RegionModelImpl.ENTITY_CACHE_ENABLED,
RegionModelImpl.FINDER_CACHE_ENABLED, RegionImpl.class,
FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_A",
new String[] {
Long.class.getName(), Boolean.class.getName(),
Integer.class.getName(), Integer.class.getName(),
OrderByComparator.class.getName()
});
public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_A = new FinderPath(RegionModelImpl.ENTITY_CACHE_ENABLED,
RegionModelImpl.FINDER_CACHE_ENABLED, RegionImpl.class,
FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_A",
new String[] { Long.class.getName(), Boolean.class.getName() },
RegionModelImpl.COUNTRYID_COLUMN_BITMASK |
RegionModelImpl.ACTIVE_COLUMN_BITMASK |
RegionModelImpl.NAME_COLUMN_BITMASK);
public static final FinderPath FINDER_PATH_COUNT_BY_C_A = new FinderPath(RegionModelImpl.ENTITY_CACHE_ENABLED,
RegionModelImpl.FINDER_CACHE_ENABLED, Long.class,
FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_A",
new String[] { Long.class.getName(), Boolean.class.getName() });
/**
* Returns all the regions where countryId = ? and active = ?.
*
* @param countryId the country ID
* @param active the active
* @return the matching regions
*/
@Override
public List<Region> findByC_A(long countryId, boolean active) {
return findByC_A(countryId, active, QueryUtil.ALL_POS,
QueryUtil.ALL_POS, null);
}
/**
* Returns a range of all the regions where countryId = ? and active = ?.
*
* <p>
* Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link RegionModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
* </p>
*
* @param countryId the country ID
* @param active the active
* @param start the lower bound of the range of regions
* @param end the upper bound of the range of regions (not inclusive)
* @return the range of matching regions
*/
@Override
public List<Region> findByC_A(long countryId, boolean active, int start,
int end) {
return findByC_A(countryId, active, start, end, null);
}
/**
* Returns an ordered range of all the regions where countryId = ? and active = ?.
*
* <p>
* Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link RegionModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
* </p>
*
* @param countryId the country ID
* @param active the active
* @param start the lower bound of the range of regions
* @param end the upper bound of the range of regions (not inclusive)
* @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
* @return the ordered range of matching regions
*/
@Override
public List<Region> findByC_A(long countryId, boolean active, int start,
int end, OrderByComparator<Region> orderByComparator) {
return findByC_A(countryId, active, start, end, orderByComparator, true);
}
/**
* Returns an ordered range of all the regions where countryId = ? and active = ?.
*
* <p>
* Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link RegionModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
* </p>
*
* @param countryId the country ID
* @param active the active
* @param start the lower bound of the range of regions
* @param end the upper bound of the range of regions (not inclusive)
* @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
* @param retrieveFromCache whether to retrieve from the finder cache
* @return the ordered range of matching regions
*/
@Override
public List<Region> findByC_A(long countryId, boolean active, int start,
int end, OrderByComparator<Region> orderByComparator,
boolean retrieveFromCache) {
boolean pagination = true;
FinderPath finderPath = null;
Object[] finderArgs = null;
if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
(orderByComparator == null)) {
pagination = false;
finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_A;
finderArgs = new Object[] { countryId, active };
}
else {
finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_A;
finderArgs = new Object[] {
countryId, active,
start, end, orderByComparator
};
}
List<Region> list = null;
if (retrieveFromCache) {
list = (List<Region>)finderCache.getResult(finderPath, finderArgs,
this);
if ((list != null) && !list.isEmpty()) {
for (Region region : list) {
if ((countryId != region.getCountryId()) ||
(active != region.getActive())) {
list = null;
break;
}
}
}
}
if (list == null) {
StringBundler query = null;
if (orderByComparator != null) {
query = new StringBundler(4 +
(orderByComparator.getOrderByFields().length * 2));
}
else {
query = new StringBundler(4);
}
query.append(_SQL_SELECT_REGION_WHERE);
query.append(_FINDER_COLUMN_C_A_COUNTRYID_2);
query.append(_FINDER_COLUMN_C_A_ACTIVE_2);
if (orderByComparator != null) {
appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
orderByComparator);
}
else
if (pagination) {
query.append(RegionModelImpl.ORDER_BY_JPQL);
}
String sql = query.toString();
Session session = null;
try {
session = openSession();
Query q = session.createQuery(sql);
QueryPos qPos = QueryPos.getInstance(q);
qPos.add(countryId);
qPos.add(active);
if (!pagination) {
list = (List<Region>)QueryUtil.list(q, getDialect(), start,
end, false);
Collections.sort(list);
list = Collections.unmodifiableList(list);
}
else {
list = (List<Region>)QueryUtil.list(q, getDialect(), start,
end);
}
cacheResult(list);
finderCache.putResult(finderPath, finderArgs, list);
}
catch (Exception e) {
finderCache.removeResult(finderPath, finderArgs);
throw processException(e);
}
finally {
closeSession(session);
}
}
return list;
}
/**
* Returns the first region in the ordered set where countryId = ? and active = ?.
*
* @param countryId the country ID
* @param active the active
* @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
* @return the first matching region
* @throws NoSuchRegionException if a matching region could not be found
*/
@Override
public Region findByC_A_First(long countryId, boolean active,
OrderByComparator<Region> orderByComparator)
throws NoSuchRegionException {
Region region = fetchByC_A_First(countryId, active, orderByComparator);
if (region != null) {
return region;
}
StringBundler msg = new StringBundler(6);
msg.append(_NO_SUCH_ENTITY_WITH_KEY);
msg.append("countryId=");
msg.append(countryId);
msg.append(", active=");
msg.append(active);
msg.append(StringPool.CLOSE_CURLY_BRACE);
throw new NoSuchRegionException(msg.toString());
}
/**
* Returns the first region in the ordered set where countryId = ? and active = ?.
*
* @param countryId the country ID
* @param active the active
* @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
* @return the first matching region, or <code>null</code> if a matching region could not be found
*/
@Override
public Region fetchByC_A_First(long countryId, boolean active,
OrderByComparator<Region> orderByComparator) {
List<Region> list = findByC_A(countryId, active, 0, 1, orderByComparator);
if (!list.isEmpty()) {
return list.get(0);
}
return null;
}
/**
* Returns the last region in the ordered set where countryId = ? and active = ?.
*
* @param countryId the country ID
* @param active the active
* @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
* @return the last matching region
* @throws NoSuchRegionException if a matching region could not be found
*/
@Override
public Region findByC_A_Last(long countryId, boolean active,
OrderByComparator<Region> orderByComparator)
throws NoSuchRegionException {
Region region = fetchByC_A_Last(countryId, active, orderByComparator);
if (region != null) {
return region;
}
StringBundler msg = new StringBundler(6);
msg.append(_NO_SUCH_ENTITY_WITH_KEY);
msg.append("countryId=");
msg.append(countryId);
msg.append(", active=");
msg.append(active);
msg.append(StringPool.CLOSE_CURLY_BRACE);
throw new NoSuchRegionException(msg.toString());
}
/**
* Returns the last region in the ordered set where countryId = ? and active = ?.
*
* @param countryId the country ID
* @param active the active
* @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
* @return the last matching region, or <code>null</code> if a matching region could not be found
*/
@Override
public Region fetchByC_A_Last(long countryId, boolean active,
OrderByComparator<Region> orderByComparator) {
int count = countByC_A(countryId, active);
if (count == 0) {
return null;
}
List<Region> list = findByC_A(countryId, active, count - 1, count,
orderByComparator);
if (!list.isEmpty()) {
return list.get(0);
}
return null;
}
/**
* Returns the regions before and after the current region in the ordered set where countryId = ? and active = ?.
*
* @param regionId the primary key of the current region
* @param countryId the country ID
* @param active the active
* @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
* @return the previous, current, and next region
* @throws NoSuchRegionException if a region with the primary key could not be found
*/
@Override
public Region[] findByC_A_PrevAndNext(long regionId, long countryId,
boolean active, OrderByComparator<Region> orderByComparator)
throws NoSuchRegionException {
Region region = findByPrimaryKey(regionId);
Session session = null;
try {
session = openSession();
Region[] array = new RegionImpl[3];
array[0] = getByC_A_PrevAndNext(session, region, countryId, active,
orderByComparator, true);
array[1] = region;
array[2] = getByC_A_PrevAndNext(session, region, countryId, active,
orderByComparator, false);
return array;
}
catch (Exception e) {
throw processException(e);
}
finally {
closeSession(session);
}
}
protected Region getByC_A_PrevAndNext(Session session, Region region,
long countryId, boolean active,
OrderByComparator<Region> orderByComparator, boolean previous) {
StringBundler query = null;
if (orderByComparator != null) {
query = new StringBundler(5 +
(orderByComparator.getOrderByConditionFields().length * 3) +
(orderByComparator.getOrderByFields().length * 3));
}
else {
query = new StringBundler(4);
}
query.append(_SQL_SELECT_REGION_WHERE);
query.append(_FINDER_COLUMN_C_A_COUNTRYID_2);
query.append(_FINDER_COLUMN_C_A_ACTIVE_2);
if (orderByComparator != null) {
String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
if (orderByConditionFields.length > 0) {
query.append(WHERE_AND);
}
for (int i = 0; i < orderByConditionFields.length; i++) {
query.append(_ORDER_BY_ENTITY_ALIAS);
query.append(orderByConditionFields[i]);
if ((i + 1) < orderByConditionFields.length) {
if (orderByComparator.isAscending() ^ previous) {
query.append(WHERE_GREATER_THAN_HAS_NEXT);
}
else {
query.append(WHERE_LESSER_THAN_HAS_NEXT);
}
}
else {
if (orderByComparator.isAscending() ^ previous) {
query.append(WHERE_GREATER_THAN);
}
else {
query.append(WHERE_LESSER_THAN);
}
}
}
query.append(ORDER_BY_CLAUSE);
String[] orderByFields = orderByComparator.getOrderByFields();
for (int i = 0; i < orderByFields.length; i++) {
query.append(_ORDER_BY_ENTITY_ALIAS);
query.append(orderByFields[i]);
if ((i + 1) < orderByFields.length) {
if (orderByComparator.isAscending() ^ previous) {
query.append(ORDER_BY_ASC_HAS_NEXT);
}
else {
query.append(ORDER_BY_DESC_HAS_NEXT);
}
}
else {
if (orderByComparator.isAscending() ^ previous) {
query.append(ORDER_BY_ASC);
}
else {
query.append(ORDER_BY_DESC);
}
}
}
}
else {
query.append(RegionModelImpl.ORDER_BY_JPQL);
}
String sql = query.toString();
Query q = session.createQuery(sql);
q.setFirstResult(0);
q.setMaxResults(2);
QueryPos qPos = QueryPos.getInstance(q);
qPos.add(countryId);
qPos.add(active);
if (orderByComparator != null) {
Object[] values = orderByComparator.getOrderByConditionValues(region);
for (Object value : values) {
qPos.add(value);
}
}
List<Region> list = q.list();
if (list.size() == 2) {
return list.get(1);
}
else {
return null;
}
}
/**
* Removes all the regions where countryId = ? and active = ? from the database.
*
* @param countryId the country ID
* @param active the active
*/
@Override
public void removeByC_A(long countryId, boolean active) {
for (Region region : findByC_A(countryId, active, QueryUtil.ALL_POS,
QueryUtil.ALL_POS, null)) {
remove(region);
}
}
/**
* Returns the number of regions where countryId = ? and active = ?.
*
* @param countryId the country ID
* @param active the active
* @return the number of matching regions
*/
@Override
public int countByC_A(long countryId, boolean active) {
FinderPath finderPath = FINDER_PATH_COUNT_BY_C_A;
Object[] finderArgs = new Object[] { countryId, active };
Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
if (count == null) {
StringBundler query = new StringBundler(3);
query.append(_SQL_COUNT_REGION_WHERE);
query.append(_FINDER_COLUMN_C_A_COUNTRYID_2);
query.append(_FINDER_COLUMN_C_A_ACTIVE_2);
String sql = query.toString();
Session session = null;
try {
session = openSession();
Query q = session.createQuery(sql);
QueryPos qPos = QueryPos.getInstance(q);
qPos.add(countryId);
qPos.add(active);
count = (Long)q.uniqueResult();
finderCache.putResult(finderPath, finderArgs, count);
}
catch (Exception e) {
finderCache.removeResult(finderPath, finderArgs);
throw processException(e);
}
finally {
closeSession(session);
}
}
return count.intValue();
}
private static final String _FINDER_COLUMN_C_A_COUNTRYID_2 = "region.countryId = ? AND ";
private static final String _FINDER_COLUMN_C_A_ACTIVE_2 = "region.active = ?";
public RegionPersistenceImpl() {
setModelClass(Region.class);
try {
Field field = ReflectionUtil.getDeclaredField(BasePersistenceImpl.class,
"_dbColumnNames");
Map<String, String> dbColumnNames = new HashMap<String, String>();
dbColumnNames.put("active", "active_");
field.set(this, dbColumnNames);
}
catch (Exception e) {
if (_log.isDebugEnabled()) {
_log.debug(e, e);
}
}
}
/**
* Caches the region in the entity cache if it is enabled.
*
* @param region the region
*/
@Override
public void cacheResult(Region region) {
entityCache.putResult(RegionModelImpl.ENTITY_CACHE_ENABLED,
RegionImpl.class, region.getPrimaryKey(), region);
finderCache.putResult(FINDER_PATH_FETCH_BY_C_R,
new Object[] { region.getCountryId(), region.getRegionCode() },
region);
region.resetOriginalValues();
}
/**
* Caches the regions in the entity cache if it is enabled.
*
* @param regions the regions
*/
@Override
public void cacheResult(List<Region> regions) {
for (Region region : regions) {
if (entityCache.getResult(RegionModelImpl.ENTITY_CACHE_ENABLED,
RegionImpl.class, region.getPrimaryKey()) == null) {
cacheResult(region);
}
else {
region.resetOriginalValues();
}
}
}
/**
* Clears the cache for all regions.
*
* <p>
* The {@link EntityCache} and {@link FinderCache} are both cleared by this method.
* </p>
*/
@Override
public void clearCache() {
entityCache.clearCache(RegionImpl.class);
finderCache.clearCache(FINDER_CLASS_NAME_ENTITY);
finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
}
/**
* Clears the cache for the region.
*
* <p>
* The {@link EntityCache} and {@link FinderCache} are both cleared by this method.
* </p>
*/
@Override
public void clearCache(Region region) {
entityCache.removeResult(RegionModelImpl.ENTITY_CACHE_ENABLED,
RegionImpl.class, region.getPrimaryKey());
finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
clearUniqueFindersCache((RegionModelImpl)region, true);
}
@Override
public void clearCache(List<Region> regions) {
finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
for (Region region : regions) {
entityCache.removeResult(RegionModelImpl.ENTITY_CACHE_ENABLED,
RegionImpl.class, region.getPrimaryKey());
clearUniqueFindersCache((RegionModelImpl)region, true);
}
}
protected void cacheUniqueFindersCache(RegionModelImpl regionModelImpl) {
Object[] args = new Object[] {
regionModelImpl.getCountryId(), regionModelImpl.getRegionCode()
};
finderCache.putResult(FINDER_PATH_COUNT_BY_C_R, args, Long.valueOf(1),
false);
finderCache.putResult(FINDER_PATH_FETCH_BY_C_R, args, regionModelImpl,
false);
}
protected void clearUniqueFindersCache(RegionModelImpl regionModelImpl,
boolean clearCurrent) {
if (clearCurrent) {
Object[] args = new Object[] {
regionModelImpl.getCountryId(),
regionModelImpl.getRegionCode()
};
finderCache.removeResult(FINDER_PATH_COUNT_BY_C_R, args);
finderCache.removeResult(FINDER_PATH_FETCH_BY_C_R, args);
}
if ((regionModelImpl.getColumnBitmask() &
FINDER_PATH_FETCH_BY_C_R.getColumnBitmask()) != 0) {
Object[] args = new Object[] {
regionModelImpl.getOriginalCountryId(),
regionModelImpl.getOriginalRegionCode()
};
finderCache.removeResult(FINDER_PATH_COUNT_BY_C_R, args);
finderCache.removeResult(FINDER_PATH_FETCH_BY_C_R, args);
}
}
/**
* Creates a new region with the primary key. Does not add the region to the database.
*
* @param regionId the primary key for the new region
* @return the new region
*/
@Override
public Region create(long regionId) {
Region region = new RegionImpl();
region.setNew(true);
region.setPrimaryKey(regionId);
return region;
}
/**
* Removes the region with the primary key from the database. Also notifies the appropriate model listeners.
*
* @param regionId the primary key of the region
* @return the region that was removed
* @throws NoSuchRegionException if a region with the primary key could not be found
*/
@Override
public Region remove(long regionId) throws NoSuchRegionException {
return remove((Serializable)regionId);
}
/**
* Removes the region with the primary key from the database. Also notifies the appropriate model listeners.
*
* @param primaryKey the primary key of the region
* @return the region that was removed
* @throws NoSuchRegionException if a region with the primary key could not be found
*/
@Override
public Region remove(Serializable primaryKey) throws NoSuchRegionException {
Session session = null;
try {
session = openSession();
Region region = (Region)session.get(RegionImpl.class, primaryKey);
if (region == null) {
if (_log.isDebugEnabled()) {
_log.debug(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
}
throw new NoSuchRegionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
primaryKey);
}
return remove(region);
}
catch (NoSuchRegionException nsee) {
throw nsee;
}
catch (Exception e) {
throw processException(e);
}
finally {
closeSession(session);
}
}
@Override
protected Region removeImpl(Region region) {
region = toUnwrappedModel(region);
Session session = null;
try {
session = openSession();
if (!session.contains(region)) {
region = (Region)session.get(RegionImpl.class,
region.getPrimaryKeyObj());
}
if (region != null) {
session.delete(region);
}
}
catch (Exception e) {
throw processException(e);
}
finally {
closeSession(session);
}
if (region != null) {
clearCache(region);
}
return region;
}
@Override
public Region updateImpl(Region region) {
region = toUnwrappedModel(region);
boolean isNew = region.isNew();
RegionModelImpl regionModelImpl = (RegionModelImpl)region;
Session session = null;
try {
session = openSession();
if (region.isNew()) {
session.save(region);
region.setNew(false);
}
else {
region = (Region)session.merge(region);
}
}
catch (Exception e) {
throw processException(e);
}
finally {
closeSession(session);
}
finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
if (!RegionModelImpl.COLUMN_BITMASK_ENABLED) {
finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
}
else
if (isNew) {
Object[] args = new Object[] { regionModelImpl.getCountryId() };
finderCache.removeResult(FINDER_PATH_COUNT_BY_COUNTRYID, args);
finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COUNTRYID,
args);
args = new Object[] { regionModelImpl.getActive() };
finderCache.removeResult(FINDER_PATH_COUNT_BY_ACTIVE, args);
finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ACTIVE,
args);
args = new Object[] {
regionModelImpl.getCountryId(), regionModelImpl.getActive()
};
finderCache.removeResult(FINDER_PATH_COUNT_BY_C_A, args);
finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_A,
args);
finderCache.removeResult(FINDER_PATH_COUNT_ALL, FINDER_ARGS_EMPTY);
finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL,
FINDER_ARGS_EMPTY);
}
else {
if ((regionModelImpl.getColumnBitmask() &
FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COUNTRYID.getColumnBitmask()) != 0) {
Object[] args = new Object[] {
regionModelImpl.getOriginalCountryId()
};
finderCache.removeResult(FINDER_PATH_COUNT_BY_COUNTRYID, args);
finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COUNTRYID,
args);
args = new Object[] { regionModelImpl.getCountryId() };
finderCache.removeResult(FINDER_PATH_COUNT_BY_COUNTRYID, args);
finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COUNTRYID,
args);
}
if ((regionModelImpl.getColumnBitmask() &
FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ACTIVE.getColumnBitmask()) != 0) {
Object[] args = new Object[] { regionModelImpl.getOriginalActive() };
finderCache.removeResult(FINDER_PATH_COUNT_BY_ACTIVE, args);
finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ACTIVE,
args);
args = new Object[] { regionModelImpl.getActive() };
finderCache.removeResult(FINDER_PATH_COUNT_BY_ACTIVE, args);
finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ACTIVE,
args);
}
if ((regionModelImpl.getColumnBitmask() &
FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_A.getColumnBitmask()) != 0) {
Object[] args = new Object[] {
regionModelImpl.getOriginalCountryId(),
regionModelImpl.getOriginalActive()
};
finderCache.removeResult(FINDER_PATH_COUNT_BY_C_A, args);
finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_A,
args);
args = new Object[] {
regionModelImpl.getCountryId(),
regionModelImpl.getActive()
};
finderCache.removeResult(FINDER_PATH_COUNT_BY_C_A, args);
finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_A,
args);
}
}
entityCache.putResult(RegionModelImpl.ENTITY_CACHE_ENABLED,
RegionImpl.class, region.getPrimaryKey(), region, false);
clearUniqueFindersCache(regionModelImpl, false);
cacheUniqueFindersCache(regionModelImpl);
region.resetOriginalValues();
return region;
}
protected Region toUnwrappedModel(Region region) {
if (region instanceof RegionImpl) {
return region;
}
RegionImpl regionImpl = new RegionImpl();
regionImpl.setNew(region.isNew());
regionImpl.setPrimaryKey(region.getPrimaryKey());
regionImpl.setMvccVersion(region.getMvccVersion());
regionImpl.setRegionId(region.getRegionId());
regionImpl.setCountryId(region.getCountryId());
regionImpl.setRegionCode(region.getRegionCode());
regionImpl.setName(region.getName());
regionImpl.setActive(region.isActive());
return regionImpl;
}
/**
* Returns the region with the primary key or throws a {@link com.liferay.portal.kernel.exception.NoSuchModelException} if it could not be found.
*
* @param primaryKey the primary key of the region
* @return the region
* @throws NoSuchRegionException if a region with the primary key could not be found
*/
@Override
public Region findByPrimaryKey(Serializable primaryKey)
throws NoSuchRegionException {
Region region = fetchByPrimaryKey(primaryKey);
if (region == null) {
if (_log.isDebugEnabled()) {
_log.debug(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
}
throw new NoSuchRegionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
primaryKey);
}
return region;
}
/**
* Returns the region with the primary key or throws a {@link NoSuchRegionException} if it could not be found.
*
* @param regionId the primary key of the region
* @return the region
* @throws NoSuchRegionException if a region with the primary key could not be found
*/
@Override
public Region findByPrimaryKey(long regionId) throws NoSuchRegionException {
return findByPrimaryKey((Serializable)regionId);
}
/**
* Returns the region with the primary key or returns <code>null</code> if it could not be found.
*
* @param primaryKey the primary key of the region
* @return the region, or <code>null</code> if a region with the primary key could not be found
*/
@Override
public Region fetchByPrimaryKey(Serializable primaryKey) {
Serializable serializable = entityCache.getResult(RegionModelImpl.ENTITY_CACHE_ENABLED,
RegionImpl.class, primaryKey);
if (serializable == nullModel) {
return null;
}
Region region = (Region)serializable;
if (region == null) {
Session session = null;
try {
session = openSession();
region = (Region)session.get(RegionImpl.class, primaryKey);
if (region != null) {
cacheResult(region);
}
else {
entityCache.putResult(RegionModelImpl.ENTITY_CACHE_ENABLED,
RegionImpl.class, primaryKey, nullModel);
}
}
catch (Exception e) {
entityCache.removeResult(RegionModelImpl.ENTITY_CACHE_ENABLED,
RegionImpl.class, primaryKey);
throw processException(e);
}
finally {
closeSession(session);
}
}
return region;
}
/**
* Returns the region with the primary key or returns <code>null</code> if it could not be found.
*
* @param regionId the primary key of the region
* @return the region, or <code>null</code> if a region with the primary key could not be found
*/
@Override
public Region fetchByPrimaryKey(long regionId) {
return fetchByPrimaryKey((Serializable)regionId);
}
@Override
public Map<Serializable, Region> fetchByPrimaryKeys(
Set<Serializable> primaryKeys) {
if (primaryKeys.isEmpty()) {
return Collections.emptyMap();
}
Map<Serializable, Region> map = new HashMap<Serializable, Region>();
if (primaryKeys.size() == 1) {
Iterator<Serializable> iterator = primaryKeys.iterator();
Serializable primaryKey = iterator.next();
Region region = fetchByPrimaryKey(primaryKey);
if (region != null) {
map.put(primaryKey, region);
}
return map;
}
Set<Serializable> uncachedPrimaryKeys = null;
for (Serializable primaryKey : primaryKeys) {
Serializable serializable = entityCache.getResult(RegionModelImpl.ENTITY_CACHE_ENABLED,
RegionImpl.class, primaryKey);
if (serializable != nullModel) {
if (serializable == null) {
if (uncachedPrimaryKeys == null) {
uncachedPrimaryKeys = new HashSet<Serializable>();
}
uncachedPrimaryKeys.add(primaryKey);
}
else {
map.put(primaryKey, (Region)serializable);
}
}
}
if (uncachedPrimaryKeys == null) {
return map;
}
StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
1);
query.append(_SQL_SELECT_REGION_WHERE_PKS_IN);
for (Serializable primaryKey : uncachedPrimaryKeys) {
query.append((long)primaryKey);
query.append(StringPool.COMMA);
}
query.setIndex(query.index() - 1);
query.append(StringPool.CLOSE_PARENTHESIS);
String sql = query.toString();
Session session = null;
try {
session = openSession();
Query q = session.createQuery(sql);
for (Region region : (List<Region>)q.list()) {
map.put(region.getPrimaryKeyObj(), region);
cacheResult(region);
uncachedPrimaryKeys.remove(region.getPrimaryKeyObj());
}
for (Serializable primaryKey : uncachedPrimaryKeys) {
entityCache.putResult(RegionModelImpl.ENTITY_CACHE_ENABLED,
RegionImpl.class, primaryKey, nullModel);
}
}
catch (Exception e) {
throw processException(e);
}
finally {
closeSession(session);
}
return map;
}
/**
* Returns all the regions.
*
* @return the regions
*/
@Override
public List<Region> findAll() {
return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
}
/**
* Returns a range of all the regions.
*
* <p>
* Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link RegionModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
* </p>
*
* @param start the lower bound of the range of regions
* @param end the upper bound of the range of regions (not inclusive)
* @return the range of regions
*/
@Override
public List<Region> findAll(int start, int end) {
return findAll(start, end, null);
}
/**
* Returns an ordered range of all the regions.
*
* <p>
* Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link RegionModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
* </p>
*
* @param start the lower bound of the range of regions
* @param end the upper bound of the range of regions (not inclusive)
* @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
* @return the ordered range of regions
*/
@Override
public List<Region> findAll(int start, int end,
OrderByComparator<Region> orderByComparator) {
return findAll(start, end, orderByComparator, true);
}
/**
* Returns an ordered range of all the regions.
*
* <p>
* Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link RegionModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
* </p>
*
* @param start the lower bound of the range of regions
* @param end the upper bound of the range of regions (not inclusive)
* @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
* @param retrieveFromCache whether to retrieve from the finder cache
* @return the ordered range of regions
*/
@Override
public List<Region> findAll(int start, int end,
OrderByComparator<Region> orderByComparator, boolean retrieveFromCache) {
boolean pagination = true;
FinderPath finderPath = null;
Object[] finderArgs = null;
if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
(orderByComparator == null)) {
pagination = false;
finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
finderArgs = FINDER_ARGS_EMPTY;
}
else {
finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
finderArgs = new Object[] { start, end, orderByComparator };
}
List<Region> list = null;
if (retrieveFromCache) {
list = (List<Region>)finderCache.getResult(finderPath, finderArgs,
this);
}
if (list == null) {
StringBundler query = null;
String sql = null;
if (orderByComparator != null) {
query = new StringBundler(2 +
(orderByComparator.getOrderByFields().length * 2));
query.append(_SQL_SELECT_REGION);
appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
orderByComparator);
sql = query.toString();
}
else {
sql = _SQL_SELECT_REGION;
if (pagination) {
sql = sql.concat(RegionModelImpl.ORDER_BY_JPQL);
}
}
Session session = null;
try {
session = openSession();
Query q = session.createQuery(sql);
if (!pagination) {
list = (List<Region>)QueryUtil.list(q, getDialect(), start,
end, false);
Collections.sort(list);
list = Collections.unmodifiableList(list);
}
else {
list = (List<Region>)QueryUtil.list(q, getDialect(), start,
end);
}
cacheResult(list);
finderCache.putResult(finderPath, finderArgs, list);
}
catch (Exception e) {
finderCache.removeResult(finderPath, finderArgs);
throw processException(e);
}
finally {
closeSession(session);
}
}
return list;
}
/**
* Removes all the regions from the database.
*
*/
@Override
public void removeAll() {
for (Region region : findAll()) {
remove(region);
}
}
/**
* Returns the number of regions.
*
* @return the number of regions
*/
@Override
public int countAll() {
Long count = (Long)finderCache.getResult(FINDER_PATH_COUNT_ALL,
FINDER_ARGS_EMPTY, this);
if (count == null) {
Session session = null;
try {
session = openSession();
Query q = session.createQuery(_SQL_COUNT_REGION);
count = (Long)q.uniqueResult();
finderCache.putResult(FINDER_PATH_COUNT_ALL, FINDER_ARGS_EMPTY,
count);
}
catch (Exception e) {
finderCache.removeResult(FINDER_PATH_COUNT_ALL,
FINDER_ARGS_EMPTY);
throw processException(e);
}
finally {
closeSession(session);
}
}
return count.intValue();
}
@Override
public Set<String> getBadColumnNames() {
return _badColumnNames;
}
@Override
protected Map<String, Integer> getTableColumnsMap() {
return RegionModelImpl.TABLE_COLUMNS_MAP;
}
/**
* Initializes the region persistence.
*/
public void afterPropertiesSet() {
}
public void destroy() {
entityCache.removeCache(RegionImpl.class.getName());
finderCache.removeCache(FINDER_CLASS_NAME_ENTITY);
finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
}
protected EntityCache entityCache = EntityCacheUtil.getEntityCache();
protected FinderCache finderCache = FinderCacheUtil.getFinderCache();
private static final String _SQL_SELECT_REGION = "SELECT region FROM Region region";
private static final String _SQL_SELECT_REGION_WHERE_PKS_IN = "SELECT region FROM Region region WHERE regionId IN (";
private static final String _SQL_SELECT_REGION_WHERE = "SELECT region FROM Region region WHERE ";
private static final String _SQL_COUNT_REGION = "SELECT COUNT(region) FROM Region region";
private static final String _SQL_COUNT_REGION_WHERE = "SELECT COUNT(region) FROM Region region WHERE ";
private static final String _ORDER_BY_ENTITY_ALIAS = "region.";
private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Region exists with the primary key ";
private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Region exists with the key {";
private static final Log _log = LogFactoryUtil.getLog(RegionPersistenceImpl.class);
private static final Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
"active"
});
}