Java tutorial
/** * 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 it.dontesta.labs.liferay.lrbo16.servicebuilder.service.persistence.impl; import aQute.bnd.annotation.ProviderType; import com.liferay.portal.kernel.dao.orm.EntityCache; import com.liferay.portal.kernel.dao.orm.FinderCache; 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.log.Log; import com.liferay.portal.kernel.log.LogFactoryUtil; import com.liferay.portal.kernel.service.ServiceContext; import com.liferay.portal.kernel.service.ServiceContextThreadLocal; import com.liferay.portal.kernel.service.persistence.CompanyProvider; import com.liferay.portal.kernel.service.persistence.CompanyProviderWrapper; import com.liferay.portal.kernel.service.persistence.impl.BasePersistenceImpl; import com.liferay.portal.kernel.util.OrderByComparator; 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.kernel.util.Validator; import com.liferay.portal.kernel.uuid.PortalUUIDUtil; import com.liferay.portal.spring.extender.service.ServiceReference; import it.dontesta.labs.liferay.lrbo16.servicebuilder.exception.NoSuchHorseException; import it.dontesta.labs.liferay.lrbo16.servicebuilder.model.Horse; import it.dontesta.labs.liferay.lrbo16.servicebuilder.model.impl.HorseImpl; import it.dontesta.labs.liferay.lrbo16.servicebuilder.model.impl.HorseModelImpl; import it.dontesta.labs.liferay.lrbo16.servicebuilder.service.persistence.HorsePersistence; import java.io.Serializable; import java.util.Collections; import java.util.Date; 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 horse service. * * <p> * Caching information and settings can be found in <code>portal.properties</code> * </p> * * @author Brian Wing Shun Chan * @see HorsePersistence * @see it.dontesta.labs.liferay.lrbo16.servicebuilder.service.persistence.HorseUtil * @generated */ @ProviderType public class HorsePersistenceImpl extends BasePersistenceImpl<Horse> implements HorsePersistence { /* * NOTE FOR DEVELOPERS: * * Never modify or reference this class directly. Always use {@link HorseUtil} to access the horse persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class. */ public static final String FINDER_CLASS_NAME_ENTITY = HorseImpl.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( HorseModelImpl.ENTITY_CACHE_ENABLED, HorseModelImpl.FINDER_CACHE_ENABLED, HorseImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]); public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath( HorseModelImpl.ENTITY_CACHE_ENABLED, HorseModelImpl.FINDER_CACHE_ENABLED, HorseImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]); public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(HorseModelImpl.ENTITY_CACHE_ENABLED, HorseModelImpl.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_UUID = new FinderPath( HorseModelImpl.ENTITY_CACHE_ENABLED, HorseModelImpl.FINDER_CACHE_ENABLED, HorseImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid", new String[] { String.class.getName(), Integer.class.getName(), Integer.class.getName(), OrderByComparator.class.getName() }); public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath( HorseModelImpl.ENTITY_CACHE_ENABLED, HorseModelImpl.FINDER_CACHE_ENABLED, HorseImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid", new String[] { String.class.getName() }, HorseModelImpl.UUID_COLUMN_BITMASK | HorseModelImpl.NAME_COLUMN_BITMASK); public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(HorseModelImpl.ENTITY_CACHE_ENABLED, HorseModelImpl.FINDER_CACHE_ENABLED, Long.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid", new String[] { String.class.getName() }); /** * Returns all the horses where uuid = ?. * * @param uuid the uuid * @return the matching horses */ @Override public List<Horse> findByUuid(String uuid) { return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null); } /** * Returns a range of all the horses where uuid = ?. * * <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 HorseModelImpl}. 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 uuid the uuid * @param start the lower bound of the range of horses * @param end the upper bound of the range of horses (not inclusive) * @return the range of matching horses */ @Override public List<Horse> findByUuid(String uuid, int start, int end) { return findByUuid(uuid, start, end, null); } /** * Returns an ordered range of all the horses where uuid = ?. * * <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 HorseModelImpl}. 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 uuid the uuid * @param start the lower bound of the range of horses * @param end the upper bound of the range of horses (not inclusive) * @param orderByComparator the comparator to order the results by (optionally <code>null</code>) * @return the ordered range of matching horses */ @Override public List<Horse> findByUuid(String uuid, int start, int end, OrderByComparator<Horse> orderByComparator) { return findByUuid(uuid, start, end, orderByComparator, true); } /** * Returns an ordered range of all the horses where uuid = ?. * * <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 HorseModelImpl}. 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 uuid the uuid * @param start the lower bound of the range of horses * @param end the upper bound of the range of horses (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 horses */ @Override public List<Horse> findByUuid(String uuid, int start, int end, OrderByComparator<Horse> 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_UUID; finderArgs = new Object[] { uuid }; } else { finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID; finderArgs = new Object[] { uuid, start, end, orderByComparator }; } List<Horse> list = null; if (retrieveFromCache) { list = (List<Horse>) finderCache.getResult(finderPath, finderArgs, this); if ((list != null) && !list.isEmpty()) { for (Horse horse : list) { if (!Objects.equals(uuid, horse.getUuid())) { 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_HORSE_WHERE); boolean bindUuid = false; if (uuid == null) { query.append(_FINDER_COLUMN_UUID_UUID_1); } else if (uuid.equals(StringPool.BLANK)) { query.append(_FINDER_COLUMN_UUID_UUID_3); } else { bindUuid = true; query.append(_FINDER_COLUMN_UUID_UUID_2); } if (orderByComparator != null) { appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator); } else if (pagination) { query.append(HorseModelImpl.ORDER_BY_JPQL); } String sql = query.toString(); Session session = null; try { session = openSession(); Query q = session.createQuery(sql); QueryPos qPos = QueryPos.getInstance(q); if (bindUuid) { qPos.add(uuid); } if (!pagination) { list = (List<Horse>) QueryUtil.list(q, getDialect(), start, end, false); Collections.sort(list); list = Collections.unmodifiableList(list); } else { list = (List<Horse>) 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 horse in the ordered set where uuid = ?. * * @param uuid the uuid * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the first matching horse * @throws NoSuchHorseException if a matching horse could not be found */ @Override public Horse findByUuid_First(String uuid, OrderByComparator<Horse> orderByComparator) throws NoSuchHorseException { Horse horse = fetchByUuid_First(uuid, orderByComparator); if (horse != null) { return horse; } StringBundler msg = new StringBundler(4); msg.append(_NO_SUCH_ENTITY_WITH_KEY); msg.append("uuid="); msg.append(uuid); msg.append(StringPool.CLOSE_CURLY_BRACE); throw new NoSuchHorseException(msg.toString()); } /** * Returns the first horse in the ordered set where uuid = ?. * * @param uuid the uuid * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the first matching horse, or <code>null</code> if a matching horse could not be found */ @Override public Horse fetchByUuid_First(String uuid, OrderByComparator<Horse> orderByComparator) { List<Horse> list = findByUuid(uuid, 0, 1, orderByComparator); if (!list.isEmpty()) { return list.get(0); } return null; } /** * Returns the last horse in the ordered set where uuid = ?. * * @param uuid the uuid * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the last matching horse * @throws NoSuchHorseException if a matching horse could not be found */ @Override public Horse findByUuid_Last(String uuid, OrderByComparator<Horse> orderByComparator) throws NoSuchHorseException { Horse horse = fetchByUuid_Last(uuid, orderByComparator); if (horse != null) { return horse; } StringBundler msg = new StringBundler(4); msg.append(_NO_SUCH_ENTITY_WITH_KEY); msg.append("uuid="); msg.append(uuid); msg.append(StringPool.CLOSE_CURLY_BRACE); throw new NoSuchHorseException(msg.toString()); } /** * Returns the last horse in the ordered set where uuid = ?. * * @param uuid the uuid * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the last matching horse, or <code>null</code> if a matching horse could not be found */ @Override public Horse fetchByUuid_Last(String uuid, OrderByComparator<Horse> orderByComparator) { int count = countByUuid(uuid); if (count == 0) { return null; } List<Horse> list = findByUuid(uuid, count - 1, count, orderByComparator); if (!list.isEmpty()) { return list.get(0); } return null; } /** * Returns the horses before and after the current horse in the ordered set where uuid = ?. * * @param horseId the primary key of the current horse * @param uuid the uuid * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the previous, current, and next horse * @throws NoSuchHorseException if a horse with the primary key could not be found */ @Override public Horse[] findByUuid_PrevAndNext(long horseId, String uuid, OrderByComparator<Horse> orderByComparator) throws NoSuchHorseException { Horse horse = findByPrimaryKey(horseId); Session session = null; try { session = openSession(); Horse[] array = new HorseImpl[3]; array[0] = getByUuid_PrevAndNext(session, horse, uuid, orderByComparator, true); array[1] = horse; array[2] = getByUuid_PrevAndNext(session, horse, uuid, orderByComparator, false); return array; } catch (Exception e) { throw processException(e); } finally { closeSession(session); } } protected Horse getByUuid_PrevAndNext(Session session, Horse horse, String uuid, OrderByComparator<Horse> 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_HORSE_WHERE); boolean bindUuid = false; if (uuid == null) { query.append(_FINDER_COLUMN_UUID_UUID_1); } else if (uuid.equals(StringPool.BLANK)) { query.append(_FINDER_COLUMN_UUID_UUID_3); } else { bindUuid = true; query.append(_FINDER_COLUMN_UUID_UUID_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(HorseModelImpl.ORDER_BY_JPQL); } String sql = query.toString(); Query q = session.createQuery(sql); q.setFirstResult(0); q.setMaxResults(2); QueryPos qPos = QueryPos.getInstance(q); if (bindUuid) { qPos.add(uuid); } if (orderByComparator != null) { Object[] values = orderByComparator.getOrderByConditionValues(horse); for (Object value : values) { qPos.add(value); } } List<Horse> list = q.list(); if (list.size() == 2) { return list.get(1); } else { return null; } } /** * Removes all the horses where uuid = ? from the database. * * @param uuid the uuid */ @Override public void removeByUuid(String uuid) { for (Horse horse : findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) { remove(horse); } } /** * Returns the number of horses where uuid = ?. * * @param uuid the uuid * @return the number of matching horses */ @Override public int countByUuid(String uuid) { FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID; Object[] finderArgs = new Object[] { uuid }; Long count = (Long) finderCache.getResult(finderPath, finderArgs, this); if (count == null) { StringBundler query = new StringBundler(2); query.append(_SQL_COUNT_HORSE_WHERE); boolean bindUuid = false; if (uuid == null) { query.append(_FINDER_COLUMN_UUID_UUID_1); } else if (uuid.equals(StringPool.BLANK)) { query.append(_FINDER_COLUMN_UUID_UUID_3); } else { bindUuid = true; query.append(_FINDER_COLUMN_UUID_UUID_2); } String sql = query.toString(); Session session = null; try { session = openSession(); Query q = session.createQuery(sql); QueryPos qPos = QueryPos.getInstance(q); if (bindUuid) { qPos.add(uuid); } 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_UUID_UUID_1 = "horse.uuid IS NULL"; private static final String _FINDER_COLUMN_UUID_UUID_2 = "horse.uuid = ?"; private static final String _FINDER_COLUMN_UUID_UUID_3 = "(horse.uuid IS NULL OR horse.uuid = '')"; public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(HorseModelImpl.ENTITY_CACHE_ENABLED, HorseModelImpl.FINDER_CACHE_ENABLED, HorseImpl.class, FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G", new String[] { String.class.getName(), Long.class.getName() }, HorseModelImpl.UUID_COLUMN_BITMASK | HorseModelImpl.GROUPID_COLUMN_BITMASK); public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(HorseModelImpl.ENTITY_CACHE_ENABLED, HorseModelImpl.FINDER_CACHE_ENABLED, Long.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUUID_G", new String[] { String.class.getName(), Long.class.getName() }); /** * Returns the horse where uuid = ? and groupId = ? or throws a {@link NoSuchHorseException} if it could not be found. * * @param uuid the uuid * @param groupId the group ID * @return the matching horse * @throws NoSuchHorseException if a matching horse could not be found */ @Override public Horse findByUUID_G(String uuid, long groupId) throws NoSuchHorseException { Horse horse = fetchByUUID_G(uuid, groupId); if (horse == null) { StringBundler msg = new StringBundler(6); msg.append(_NO_SUCH_ENTITY_WITH_KEY); msg.append("uuid="); msg.append(uuid); msg.append(", groupId="); msg.append(groupId); msg.append(StringPool.CLOSE_CURLY_BRACE); if (_log.isDebugEnabled()) { _log.debug(msg.toString()); } throw new NoSuchHorseException(msg.toString()); } return horse; } /** * Returns the horse where uuid = ? and groupId = ? or returns <code>null</code> if it could not be found. Uses the finder cache. * * @param uuid the uuid * @param groupId the group ID * @return the matching horse, or <code>null</code> if a matching horse could not be found */ @Override public Horse fetchByUUID_G(String uuid, long groupId) { return fetchByUUID_G(uuid, groupId, true); } /** * Returns the horse where uuid = ? and groupId = ? or returns <code>null</code> if it could not be found, optionally using the finder cache. * * @param uuid the uuid * @param groupId the group ID * @param retrieveFromCache whether to retrieve from the finder cache * @return the matching horse, or <code>null</code> if a matching horse could not be found */ @Override public Horse fetchByUUID_G(String uuid, long groupId, boolean retrieveFromCache) { Object[] finderArgs = new Object[] { uuid, groupId }; Object result = null; if (retrieveFromCache) { result = finderCache.getResult(FINDER_PATH_FETCH_BY_UUID_G, finderArgs, this); } if (result instanceof Horse) { Horse horse = (Horse) result; if (!Objects.equals(uuid, horse.getUuid()) || (groupId != horse.getGroupId())) { result = null; } } if (result == null) { StringBundler query = new StringBundler(4); query.append(_SQL_SELECT_HORSE_WHERE); boolean bindUuid = false; if (uuid == null) { query.append(_FINDER_COLUMN_UUID_G_UUID_1); } else if (uuid.equals(StringPool.BLANK)) { query.append(_FINDER_COLUMN_UUID_G_UUID_3); } else { bindUuid = true; query.append(_FINDER_COLUMN_UUID_G_UUID_2); } query.append(_FINDER_COLUMN_UUID_G_GROUPID_2); String sql = query.toString(); Session session = null; try { session = openSession(); Query q = session.createQuery(sql); QueryPos qPos = QueryPos.getInstance(q); if (bindUuid) { qPos.add(uuid); } qPos.add(groupId); List<Horse> list = q.list(); if (list.isEmpty()) { finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G, finderArgs, list); } else { Horse horse = list.get(0); result = horse; cacheResult(horse); if ((horse.getUuid() == null) || !horse.getUuid().equals(uuid) || (horse.getGroupId() != groupId)) { finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G, finderArgs, horse); } } } catch (Exception e) { finderCache.removeResult(FINDER_PATH_FETCH_BY_UUID_G, finderArgs); throw processException(e); } finally { closeSession(session); } } if (result instanceof List<?>) { return null; } else { return (Horse) result; } } /** * Removes the horse where uuid = ? and groupId = ? from the database. * * @param uuid the uuid * @param groupId the group ID * @return the horse that was removed */ @Override public Horse removeByUUID_G(String uuid, long groupId) throws NoSuchHorseException { Horse horse = findByUUID_G(uuid, groupId); return remove(horse); } /** * Returns the number of horses where uuid = ? and groupId = ?. * * @param uuid the uuid * @param groupId the group ID * @return the number of matching horses */ @Override public int countByUUID_G(String uuid, long groupId) { FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_G; Object[] finderArgs = new Object[] { uuid, groupId }; Long count = (Long) finderCache.getResult(finderPath, finderArgs, this); if (count == null) { StringBundler query = new StringBundler(3); query.append(_SQL_COUNT_HORSE_WHERE); boolean bindUuid = false; if (uuid == null) { query.append(_FINDER_COLUMN_UUID_G_UUID_1); } else if (uuid.equals(StringPool.BLANK)) { query.append(_FINDER_COLUMN_UUID_G_UUID_3); } else { bindUuid = true; query.append(_FINDER_COLUMN_UUID_G_UUID_2); } query.append(_FINDER_COLUMN_UUID_G_GROUPID_2); String sql = query.toString(); Session session = null; try { session = openSession(); Query q = session.createQuery(sql); QueryPos qPos = QueryPos.getInstance(q); if (bindUuid) { qPos.add(uuid); } qPos.add(groupId); 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_UUID_G_UUID_1 = "horse.uuid IS NULL AND "; private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "horse.uuid = ? AND "; private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(horse.uuid IS NULL OR horse.uuid = '') AND "; private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "horse.groupId = ?"; public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath( HorseModelImpl.ENTITY_CACHE_ENABLED, HorseModelImpl.FINDER_CACHE_ENABLED, HorseImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid_C", new String[] { String.class.getName(), Long.class.getName(), Integer.class.getName(), Integer.class.getName(), OrderByComparator.class.getName() }); public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C = new FinderPath( HorseModelImpl.ENTITY_CACHE_ENABLED, HorseModelImpl.FINDER_CACHE_ENABLED, HorseImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid_C", new String[] { String.class.getName(), Long.class.getName() }, HorseModelImpl.UUID_COLUMN_BITMASK | HorseModelImpl.COMPANYID_COLUMN_BITMASK | HorseModelImpl.NAME_COLUMN_BITMASK); public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(HorseModelImpl.ENTITY_CACHE_ENABLED, HorseModelImpl.FINDER_CACHE_ENABLED, Long.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C", new String[] { String.class.getName(), Long.class.getName() }); /** * Returns all the horses where uuid = ? and companyId = ?. * * @param uuid the uuid * @param companyId the company ID * @return the matching horses */ @Override public List<Horse> findByUuid_C(String uuid, long companyId) { return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null); } /** * Returns a range of all the horses where uuid = ? and companyId = ?. * * <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 HorseModelImpl}. 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 uuid the uuid * @param companyId the company ID * @param start the lower bound of the range of horses * @param end the upper bound of the range of horses (not inclusive) * @return the range of matching horses */ @Override public List<Horse> findByUuid_C(String uuid, long companyId, int start, int end) { return findByUuid_C(uuid, companyId, start, end, null); } /** * Returns an ordered range of all the horses where uuid = ? and companyId = ?. * * <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 HorseModelImpl}. 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 uuid the uuid * @param companyId the company ID * @param start the lower bound of the range of horses * @param end the upper bound of the range of horses (not inclusive) * @param orderByComparator the comparator to order the results by (optionally <code>null</code>) * @return the ordered range of matching horses */ @Override public List<Horse> findByUuid_C(String uuid, long companyId, int start, int end, OrderByComparator<Horse> orderByComparator) { return findByUuid_C(uuid, companyId, start, end, orderByComparator, true); } /** * Returns an ordered range of all the horses where uuid = ? and companyId = ?. * * <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 HorseModelImpl}. 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 uuid the uuid * @param companyId the company ID * @param start the lower bound of the range of horses * @param end the upper bound of the range of horses (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 horses */ @Override public List<Horse> findByUuid_C(String uuid, long companyId, int start, int end, OrderByComparator<Horse> 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_UUID_C; finderArgs = new Object[] { uuid, companyId }; } else { finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C; finderArgs = new Object[] { uuid, companyId, start, end, orderByComparator }; } List<Horse> list = null; if (retrieveFromCache) { list = (List<Horse>) finderCache.getResult(finderPath, finderArgs, this); if ((list != null) && !list.isEmpty()) { for (Horse horse : list) { if (!Objects.equals(uuid, horse.getUuid()) || (companyId != horse.getCompanyId())) { 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_HORSE_WHERE); boolean bindUuid = false; if (uuid == null) { query.append(_FINDER_COLUMN_UUID_C_UUID_1); } else if (uuid.equals(StringPool.BLANK)) { query.append(_FINDER_COLUMN_UUID_C_UUID_3); } else { bindUuid = true; query.append(_FINDER_COLUMN_UUID_C_UUID_2); } query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2); if (orderByComparator != null) { appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator); } else if (pagination) { query.append(HorseModelImpl.ORDER_BY_JPQL); } String sql = query.toString(); Session session = null; try { session = openSession(); Query q = session.createQuery(sql); QueryPos qPos = QueryPos.getInstance(q); if (bindUuid) { qPos.add(uuid); } qPos.add(companyId); if (!pagination) { list = (List<Horse>) QueryUtil.list(q, getDialect(), start, end, false); Collections.sort(list); list = Collections.unmodifiableList(list); } else { list = (List<Horse>) 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 horse in the ordered set where uuid = ? and companyId = ?. * * @param uuid the uuid * @param companyId the company ID * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the first matching horse * @throws NoSuchHorseException if a matching horse could not be found */ @Override public Horse findByUuid_C_First(String uuid, long companyId, OrderByComparator<Horse> orderByComparator) throws NoSuchHorseException { Horse horse = fetchByUuid_C_First(uuid, companyId, orderByComparator); if (horse != null) { return horse; } StringBundler msg = new StringBundler(6); msg.append(_NO_SUCH_ENTITY_WITH_KEY); msg.append("uuid="); msg.append(uuid); msg.append(", companyId="); msg.append(companyId); msg.append(StringPool.CLOSE_CURLY_BRACE); throw new NoSuchHorseException(msg.toString()); } /** * Returns the first horse in the ordered set where uuid = ? and companyId = ?. * * @param uuid the uuid * @param companyId the company ID * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the first matching horse, or <code>null</code> if a matching horse could not be found */ @Override public Horse fetchByUuid_C_First(String uuid, long companyId, OrderByComparator<Horse> orderByComparator) { List<Horse> list = findByUuid_C(uuid, companyId, 0, 1, orderByComparator); if (!list.isEmpty()) { return list.get(0); } return null; } /** * Returns the last horse in the ordered set where uuid = ? and companyId = ?. * * @param uuid the uuid * @param companyId the company ID * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the last matching horse * @throws NoSuchHorseException if a matching horse could not be found */ @Override public Horse findByUuid_C_Last(String uuid, long companyId, OrderByComparator<Horse> orderByComparator) throws NoSuchHorseException { Horse horse = fetchByUuid_C_Last(uuid, companyId, orderByComparator); if (horse != null) { return horse; } StringBundler msg = new StringBundler(6); msg.append(_NO_SUCH_ENTITY_WITH_KEY); msg.append("uuid="); msg.append(uuid); msg.append(", companyId="); msg.append(companyId); msg.append(StringPool.CLOSE_CURLY_BRACE); throw new NoSuchHorseException(msg.toString()); } /** * Returns the last horse in the ordered set where uuid = ? and companyId = ?. * * @param uuid the uuid * @param companyId the company ID * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the last matching horse, or <code>null</code> if a matching horse could not be found */ @Override public Horse fetchByUuid_C_Last(String uuid, long companyId, OrderByComparator<Horse> orderByComparator) { int count = countByUuid_C(uuid, companyId); if (count == 0) { return null; } List<Horse> list = findByUuid_C(uuid, companyId, count - 1, count, orderByComparator); if (!list.isEmpty()) { return list.get(0); } return null; } /** * Returns the horses before and after the current horse in the ordered set where uuid = ? and companyId = ?. * * @param horseId the primary key of the current horse * @param uuid the uuid * @param companyId the company ID * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the previous, current, and next horse * @throws NoSuchHorseException if a horse with the primary key could not be found */ @Override public Horse[] findByUuid_C_PrevAndNext(long horseId, String uuid, long companyId, OrderByComparator<Horse> orderByComparator) throws NoSuchHorseException { Horse horse = findByPrimaryKey(horseId); Session session = null; try { session = openSession(); Horse[] array = new HorseImpl[3]; array[0] = getByUuid_C_PrevAndNext(session, horse, uuid, companyId, orderByComparator, true); array[1] = horse; array[2] = getByUuid_C_PrevAndNext(session, horse, uuid, companyId, orderByComparator, false); return array; } catch (Exception e) { throw processException(e); } finally { closeSession(session); } } protected Horse getByUuid_C_PrevAndNext(Session session, Horse horse, String uuid, long companyId, OrderByComparator<Horse> 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_HORSE_WHERE); boolean bindUuid = false; if (uuid == null) { query.append(_FINDER_COLUMN_UUID_C_UUID_1); } else if (uuid.equals(StringPool.BLANK)) { query.append(_FINDER_COLUMN_UUID_C_UUID_3); } else { bindUuid = true; query.append(_FINDER_COLUMN_UUID_C_UUID_2); } query.append(_FINDER_COLUMN_UUID_C_COMPANYID_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(HorseModelImpl.ORDER_BY_JPQL); } String sql = query.toString(); Query q = session.createQuery(sql); q.setFirstResult(0); q.setMaxResults(2); QueryPos qPos = QueryPos.getInstance(q); if (bindUuid) { qPos.add(uuid); } qPos.add(companyId); if (orderByComparator != null) { Object[] values = orderByComparator.getOrderByConditionValues(horse); for (Object value : values) { qPos.add(value); } } List<Horse> list = q.list(); if (list.size() == 2) { return list.get(1); } else { return null; } } /** * Removes all the horses where uuid = ? and companyId = ? from the database. * * @param uuid the uuid * @param companyId the company ID */ @Override public void removeByUuid_C(String uuid, long companyId) { for (Horse horse : findByUuid_C(uuid, companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) { remove(horse); } } /** * Returns the number of horses where uuid = ? and companyId = ?. * * @param uuid the uuid * @param companyId the company ID * @return the number of matching horses */ @Override public int countByUuid_C(String uuid, long companyId) { FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C; Object[] finderArgs = new Object[] { uuid, companyId }; Long count = (Long) finderCache.getResult(finderPath, finderArgs, this); if (count == null) { StringBundler query = new StringBundler(3); query.append(_SQL_COUNT_HORSE_WHERE); boolean bindUuid = false; if (uuid == null) { query.append(_FINDER_COLUMN_UUID_C_UUID_1); } else if (uuid.equals(StringPool.BLANK)) { query.append(_FINDER_COLUMN_UUID_C_UUID_3); } else { bindUuid = true; query.append(_FINDER_COLUMN_UUID_C_UUID_2); } query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2); String sql = query.toString(); Session session = null; try { session = openSession(); Query q = session.createQuery(sql); QueryPos qPos = QueryPos.getInstance(q); if (bindUuid) { qPos.add(uuid); } qPos.add(companyId); 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_UUID_C_UUID_1 = "horse.uuid IS NULL AND "; private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "horse.uuid = ? AND "; private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(horse.uuid IS NULL OR horse.uuid = '') AND "; private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "horse.companyId = ?"; public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_NAME = new FinderPath( HorseModelImpl.ENTITY_CACHE_ENABLED, HorseModelImpl.FINDER_CACHE_ENABLED, HorseImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByName", new String[] { String.class.getName(), Integer.class.getName(), Integer.class.getName(), OrderByComparator.class.getName() }); public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NAME = new FinderPath( HorseModelImpl.ENTITY_CACHE_ENABLED, HorseModelImpl.FINDER_CACHE_ENABLED, HorseImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByName", new String[] { String.class.getName() }, HorseModelImpl.NAME_COLUMN_BITMASK); public static final FinderPath FINDER_PATH_COUNT_BY_NAME = new FinderPath(HorseModelImpl.ENTITY_CACHE_ENABLED, HorseModelImpl.FINDER_CACHE_ENABLED, Long.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByName", new String[] { String.class.getName() }); /** * Returns all the horses where name = ?. * * @param name the name * @return the matching horses */ @Override public List<Horse> findByName(String name) { return findByName(name, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null); } /** * Returns a range of all the horses where name = ?. * * <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 HorseModelImpl}. 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 name the name * @param start the lower bound of the range of horses * @param end the upper bound of the range of horses (not inclusive) * @return the range of matching horses */ @Override public List<Horse> findByName(String name, int start, int end) { return findByName(name, start, end, null); } /** * Returns an ordered range of all the horses where name = ?. * * <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 HorseModelImpl}. 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 name the name * @param start the lower bound of the range of horses * @param end the upper bound of the range of horses (not inclusive) * @param orderByComparator the comparator to order the results by (optionally <code>null</code>) * @return the ordered range of matching horses */ @Override public List<Horse> findByName(String name, int start, int end, OrderByComparator<Horse> orderByComparator) { return findByName(name, start, end, orderByComparator, true); } /** * Returns an ordered range of all the horses where name = ?. * * <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 HorseModelImpl}. 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 name the name * @param start the lower bound of the range of horses * @param end the upper bound of the range of horses (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 horses */ @Override public List<Horse> findByName(String name, int start, int end, OrderByComparator<Horse> 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_NAME; finderArgs = new Object[] { name }; } else { finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_NAME; finderArgs = new Object[] { name, start, end, orderByComparator }; } List<Horse> list = null; if (retrieveFromCache) { list = (List<Horse>) finderCache.getResult(finderPath, finderArgs, this); if ((list != null) && !list.isEmpty()) { for (Horse horse : list) { if (!Objects.equals(name, horse.getName())) { 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_HORSE_WHERE); boolean bindName = false; if (name == null) { query.append(_FINDER_COLUMN_NAME_NAME_1); } else if (name.equals(StringPool.BLANK)) { query.append(_FINDER_COLUMN_NAME_NAME_3); } else { bindName = true; query.append(_FINDER_COLUMN_NAME_NAME_2); } if (orderByComparator != null) { appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator); } else if (pagination) { query.append(HorseModelImpl.ORDER_BY_JPQL); } String sql = query.toString(); Session session = null; try { session = openSession(); Query q = session.createQuery(sql); QueryPos qPos = QueryPos.getInstance(q); if (bindName) { qPos.add(name); } if (!pagination) { list = (List<Horse>) QueryUtil.list(q, getDialect(), start, end, false); Collections.sort(list); list = Collections.unmodifiableList(list); } else { list = (List<Horse>) 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 horse in the ordered set where name = ?. * * @param name the name * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the first matching horse * @throws NoSuchHorseException if a matching horse could not be found */ @Override public Horse findByName_First(String name, OrderByComparator<Horse> orderByComparator) throws NoSuchHorseException { Horse horse = fetchByName_First(name, orderByComparator); if (horse != null) { return horse; } StringBundler msg = new StringBundler(4); msg.append(_NO_SUCH_ENTITY_WITH_KEY); msg.append("name="); msg.append(name); msg.append(StringPool.CLOSE_CURLY_BRACE); throw new NoSuchHorseException(msg.toString()); } /** * Returns the first horse in the ordered set where name = ?. * * @param name the name * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the first matching horse, or <code>null</code> if a matching horse could not be found */ @Override public Horse fetchByName_First(String name, OrderByComparator<Horse> orderByComparator) { List<Horse> list = findByName(name, 0, 1, orderByComparator); if (!list.isEmpty()) { return list.get(0); } return null; } /** * Returns the last horse in the ordered set where name = ?. * * @param name the name * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the last matching horse * @throws NoSuchHorseException if a matching horse could not be found */ @Override public Horse findByName_Last(String name, OrderByComparator<Horse> orderByComparator) throws NoSuchHorseException { Horse horse = fetchByName_Last(name, orderByComparator); if (horse != null) { return horse; } StringBundler msg = new StringBundler(4); msg.append(_NO_SUCH_ENTITY_WITH_KEY); msg.append("name="); msg.append(name); msg.append(StringPool.CLOSE_CURLY_BRACE); throw new NoSuchHorseException(msg.toString()); } /** * Returns the last horse in the ordered set where name = ?. * * @param name the name * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the last matching horse, or <code>null</code> if a matching horse could not be found */ @Override public Horse fetchByName_Last(String name, OrderByComparator<Horse> orderByComparator) { int count = countByName(name); if (count == 0) { return null; } List<Horse> list = findByName(name, count - 1, count, orderByComparator); if (!list.isEmpty()) { return list.get(0); } return null; } /** * Returns the horses before and after the current horse in the ordered set where name = ?. * * @param horseId the primary key of the current horse * @param name the name * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the previous, current, and next horse * @throws NoSuchHorseException if a horse with the primary key could not be found */ @Override public Horse[] findByName_PrevAndNext(long horseId, String name, OrderByComparator<Horse> orderByComparator) throws NoSuchHorseException { Horse horse = findByPrimaryKey(horseId); Session session = null; try { session = openSession(); Horse[] array = new HorseImpl[3]; array[0] = getByName_PrevAndNext(session, horse, name, orderByComparator, true); array[1] = horse; array[2] = getByName_PrevAndNext(session, horse, name, orderByComparator, false); return array; } catch (Exception e) { throw processException(e); } finally { closeSession(session); } } protected Horse getByName_PrevAndNext(Session session, Horse horse, String name, OrderByComparator<Horse> 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_HORSE_WHERE); boolean bindName = false; if (name == null) { query.append(_FINDER_COLUMN_NAME_NAME_1); } else if (name.equals(StringPool.BLANK)) { query.append(_FINDER_COLUMN_NAME_NAME_3); } else { bindName = true; query.append(_FINDER_COLUMN_NAME_NAME_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(HorseModelImpl.ORDER_BY_JPQL); } String sql = query.toString(); Query q = session.createQuery(sql); q.setFirstResult(0); q.setMaxResults(2); QueryPos qPos = QueryPos.getInstance(q); if (bindName) { qPos.add(name); } if (orderByComparator != null) { Object[] values = orderByComparator.getOrderByConditionValues(horse); for (Object value : values) { qPos.add(value); } } List<Horse> list = q.list(); if (list.size() == 2) { return list.get(1); } else { return null; } } /** * Removes all the horses where name = ? from the database. * * @param name the name */ @Override public void removeByName(String name) { for (Horse horse : findByName(name, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) { remove(horse); } } /** * Returns the number of horses where name = ?. * * @param name the name * @return the number of matching horses */ @Override public int countByName(String name) { FinderPath finderPath = FINDER_PATH_COUNT_BY_NAME; Object[] finderArgs = new Object[] { name }; Long count = (Long) finderCache.getResult(finderPath, finderArgs, this); if (count == null) { StringBundler query = new StringBundler(2); query.append(_SQL_COUNT_HORSE_WHERE); boolean bindName = false; if (name == null) { query.append(_FINDER_COLUMN_NAME_NAME_1); } else if (name.equals(StringPool.BLANK)) { query.append(_FINDER_COLUMN_NAME_NAME_3); } else { bindName = true; query.append(_FINDER_COLUMN_NAME_NAME_2); } String sql = query.toString(); Session session = null; try { session = openSession(); Query q = session.createQuery(sql); QueryPos qPos = QueryPos.getInstance(q); if (bindName) { qPos.add(name); } 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_NAME_NAME_1 = "horse.name IS NULL"; private static final String _FINDER_COLUMN_NAME_NAME_2 = "horse.name = ?"; private static final String _FINDER_COLUMN_NAME_NAME_3 = "(horse.name IS NULL OR horse.name = '')"; public HorsePersistenceImpl() { setModelClass(Horse.class); } /** * Caches the horse in the entity cache if it is enabled. * * @param horse the horse */ @Override public void cacheResult(Horse horse) { entityCache.putResult(HorseModelImpl.ENTITY_CACHE_ENABLED, HorseImpl.class, horse.getPrimaryKey(), horse); finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G, new Object[] { horse.getUuid(), horse.getGroupId() }, horse); horse.resetOriginalValues(); } /** * Caches the horses in the entity cache if it is enabled. * * @param horses the horses */ @Override public void cacheResult(List<Horse> horses) { for (Horse horse : horses) { if (entityCache.getResult(HorseModelImpl.ENTITY_CACHE_ENABLED, HorseImpl.class, horse.getPrimaryKey()) == null) { cacheResult(horse); } else { horse.resetOriginalValues(); } } } /** * Clears the cache for all horses. * * <p> * The {@link EntityCache} and {@link FinderCache} are both cleared by this method. * </p> */ @Override public void clearCache() { entityCache.clearCache(HorseImpl.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 horse. * * <p> * The {@link EntityCache} and {@link FinderCache} are both cleared by this method. * </p> */ @Override public void clearCache(Horse horse) { entityCache.removeResult(HorseModelImpl.ENTITY_CACHE_ENABLED, HorseImpl.class, horse.getPrimaryKey()); finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION); finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION); clearUniqueFindersCache((HorseModelImpl) horse); } @Override public void clearCache(List<Horse> horses) { finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION); finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION); for (Horse horse : horses) { entityCache.removeResult(HorseModelImpl.ENTITY_CACHE_ENABLED, HorseImpl.class, horse.getPrimaryKey()); clearUniqueFindersCache((HorseModelImpl) horse); } } protected void cacheUniqueFindersCache(HorseModelImpl horseModelImpl, boolean isNew) { if (isNew) { Object[] args = new Object[] { horseModelImpl.getUuid(), horseModelImpl.getGroupId() }; finderCache.putResult(FINDER_PATH_COUNT_BY_UUID_G, args, Long.valueOf(1)); finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G, args, horseModelImpl); } else { if ((horseModelImpl.getColumnBitmask() & FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) { Object[] args = new Object[] { horseModelImpl.getUuid(), horseModelImpl.getGroupId() }; finderCache.putResult(FINDER_PATH_COUNT_BY_UUID_G, args, Long.valueOf(1)); finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G, args, horseModelImpl); } } } protected void clearUniqueFindersCache(HorseModelImpl horseModelImpl) { Object[] args = new Object[] { horseModelImpl.getUuid(), horseModelImpl.getGroupId() }; finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args); finderCache.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args); if ((horseModelImpl.getColumnBitmask() & FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) { args = new Object[] { horseModelImpl.getOriginalUuid(), horseModelImpl.getOriginalGroupId() }; finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args); finderCache.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args); } } /** * Creates a new horse with the primary key. Does not add the horse to the database. * * @param horseId the primary key for the new horse * @return the new horse */ @Override public Horse create(long horseId) { Horse horse = new HorseImpl(); horse.setNew(true); horse.setPrimaryKey(horseId); String uuid = PortalUUIDUtil.generate(); horse.setUuid(uuid); horse.setCompanyId(companyProvider.getCompanyId()); return horse; } /** * Removes the horse with the primary key from the database. Also notifies the appropriate model listeners. * * @param horseId the primary key of the horse * @return the horse that was removed * @throws NoSuchHorseException if a horse with the primary key could not be found */ @Override public Horse remove(long horseId) throws NoSuchHorseException { return remove((Serializable) horseId); } /** * Removes the horse with the primary key from the database. Also notifies the appropriate model listeners. * * @param primaryKey the primary key of the horse * @return the horse that was removed * @throws NoSuchHorseException if a horse with the primary key could not be found */ @Override public Horse remove(Serializable primaryKey) throws NoSuchHorseException { Session session = null; try { session = openSession(); Horse horse = (Horse) session.get(HorseImpl.class, primaryKey); if (horse == null) { if (_log.isDebugEnabled()) { _log.debug(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey); } throw new NoSuchHorseException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey); } return remove(horse); } catch (NoSuchHorseException nsee) { throw nsee; } catch (Exception e) { throw processException(e); } finally { closeSession(session); } } @Override protected Horse removeImpl(Horse horse) { horse = toUnwrappedModel(horse); Session session = null; try { session = openSession(); if (!session.contains(horse)) { horse = (Horse) session.get(HorseImpl.class, horse.getPrimaryKeyObj()); } if (horse != null) { session.delete(horse); } } catch (Exception e) { throw processException(e); } finally { closeSession(session); } if (horse != null) { clearCache(horse); } return horse; } @Override public Horse updateImpl(Horse horse) { horse = toUnwrappedModel(horse); boolean isNew = horse.isNew(); HorseModelImpl horseModelImpl = (HorseModelImpl) horse; if (Validator.isNull(horse.getUuid())) { String uuid = PortalUUIDUtil.generate(); horse.setUuid(uuid); } ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext(); Date now = new Date(); if (isNew && (horse.getCreateDate() == null)) { if (serviceContext == null) { horse.setCreateDate(now); } else { horse.setCreateDate(serviceContext.getCreateDate(now)); } } if (!horseModelImpl.hasSetModifiedDate()) { if (serviceContext == null) { horse.setModifiedDate(now); } else { horse.setModifiedDate(serviceContext.getModifiedDate(now)); } } Session session = null; try { session = openSession(); if (horse.isNew()) { session.save(horse); horse.setNew(false); } else { horse = (Horse) session.merge(horse); } } catch (Exception e) { throw processException(e); } finally { closeSession(session); } finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION); if (isNew || !HorseModelImpl.COLUMN_BITMASK_ENABLED) { finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION); } else { if ((horseModelImpl.getColumnBitmask() & FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) { Object[] args = new Object[] { horseModelImpl.getOriginalUuid() }; finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID, args); finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID, args); args = new Object[] { horseModelImpl.getUuid() }; finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID, args); finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID, args); } if ((horseModelImpl.getColumnBitmask() & FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) { Object[] args = new Object[] { horseModelImpl.getOriginalUuid(), horseModelImpl.getOriginalCompanyId() }; finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args); finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C, args); args = new Object[] { horseModelImpl.getUuid(), horseModelImpl.getCompanyId() }; finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args); finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C, args); } if ((horseModelImpl.getColumnBitmask() & FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NAME.getColumnBitmask()) != 0) { Object[] args = new Object[] { horseModelImpl.getOriginalName() }; finderCache.removeResult(FINDER_PATH_COUNT_BY_NAME, args); finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NAME, args); args = new Object[] { horseModelImpl.getName() }; finderCache.removeResult(FINDER_PATH_COUNT_BY_NAME, args); finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NAME, args); } } entityCache.putResult(HorseModelImpl.ENTITY_CACHE_ENABLED, HorseImpl.class, horse.getPrimaryKey(), horse, false); clearUniqueFindersCache(horseModelImpl); cacheUniqueFindersCache(horseModelImpl, isNew); horse.resetOriginalValues(); return horse; } protected Horse toUnwrappedModel(Horse horse) { if (horse instanceof HorseImpl) { return horse; } HorseImpl horseImpl = new HorseImpl(); horseImpl.setNew(horse.isNew()); horseImpl.setPrimaryKey(horse.getPrimaryKey()); horseImpl.setUuid(horse.getUuid()); horseImpl.setHorseId(horse.getHorseId()); horseImpl.setGroupId(horse.getGroupId()); horseImpl.setCompanyId(horse.getCompanyId()); horseImpl.setUserId(horse.getUserId()); horseImpl.setUserName(horse.getUserName()); horseImpl.setCreateDate(horse.getCreateDate()); horseImpl.setModifiedDate(horse.getModifiedDate()); horseImpl.setName(horse.getName()); horseImpl.setAge(horse.getAge()); horseImpl.setGender(horse.getGender()); horseImpl.setKind(horse.getKind()); horseImpl.setMantle(horse.getMantle()); return horseImpl; } /** * Returns the horse 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 horse * @return the horse * @throws NoSuchHorseException if a horse with the primary key could not be found */ @Override public Horse findByPrimaryKey(Serializable primaryKey) throws NoSuchHorseException { Horse horse = fetchByPrimaryKey(primaryKey); if (horse == null) { if (_log.isDebugEnabled()) { _log.debug(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey); } throw new NoSuchHorseException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey); } return horse; } /** * Returns the horse with the primary key or throws a {@link NoSuchHorseException} if it could not be found. * * @param horseId the primary key of the horse * @return the horse * @throws NoSuchHorseException if a horse with the primary key could not be found */ @Override public Horse findByPrimaryKey(long horseId) throws NoSuchHorseException { return findByPrimaryKey((Serializable) horseId); } /** * Returns the horse with the primary key or returns <code>null</code> if it could not be found. * * @param primaryKey the primary key of the horse * @return the horse, or <code>null</code> if a horse with the primary key could not be found */ @Override public Horse fetchByPrimaryKey(Serializable primaryKey) { Serializable serializable = entityCache.getResult(HorseModelImpl.ENTITY_CACHE_ENABLED, HorseImpl.class, primaryKey); if (serializable == nullModel) { return null; } Horse horse = (Horse) serializable; if (horse == null) { Session session = null; try { session = openSession(); horse = (Horse) session.get(HorseImpl.class, primaryKey); if (horse != null) { cacheResult(horse); } else { entityCache.putResult(HorseModelImpl.ENTITY_CACHE_ENABLED, HorseImpl.class, primaryKey, nullModel); } } catch (Exception e) { entityCache.removeResult(HorseModelImpl.ENTITY_CACHE_ENABLED, HorseImpl.class, primaryKey); throw processException(e); } finally { closeSession(session); } } return horse; } /** * Returns the horse with the primary key or returns <code>null</code> if it could not be found. * * @param horseId the primary key of the horse * @return the horse, or <code>null</code> if a horse with the primary key could not be found */ @Override public Horse fetchByPrimaryKey(long horseId) { return fetchByPrimaryKey((Serializable) horseId); } @Override public Map<Serializable, Horse> fetchByPrimaryKeys(Set<Serializable> primaryKeys) { if (primaryKeys.isEmpty()) { return Collections.emptyMap(); } Map<Serializable, Horse> map = new HashMap<Serializable, Horse>(); if (primaryKeys.size() == 1) { Iterator<Serializable> iterator = primaryKeys.iterator(); Serializable primaryKey = iterator.next(); Horse horse = fetchByPrimaryKey(primaryKey); if (horse != null) { map.put(primaryKey, horse); } return map; } Set<Serializable> uncachedPrimaryKeys = null; for (Serializable primaryKey : primaryKeys) { Serializable serializable = entityCache.getResult(HorseModelImpl.ENTITY_CACHE_ENABLED, HorseImpl.class, primaryKey); if (serializable != nullModel) { if (serializable == null) { if (uncachedPrimaryKeys == null) { uncachedPrimaryKeys = new HashSet<Serializable>(); } uncachedPrimaryKeys.add(primaryKey); } else { map.put(primaryKey, (Horse) serializable); } } } if (uncachedPrimaryKeys == null) { return map; } StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) + 1); query.append(_SQL_SELECT_HORSE_WHERE_PKS_IN); for (Serializable primaryKey : uncachedPrimaryKeys) { query.append(String.valueOf(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 (Horse horse : (List<Horse>) q.list()) { map.put(horse.getPrimaryKeyObj(), horse); cacheResult(horse); uncachedPrimaryKeys.remove(horse.getPrimaryKeyObj()); } for (Serializable primaryKey : uncachedPrimaryKeys) { entityCache.putResult(HorseModelImpl.ENTITY_CACHE_ENABLED, HorseImpl.class, primaryKey, nullModel); } } catch (Exception e) { throw processException(e); } finally { closeSession(session); } return map; } /** * Returns all the horses. * * @return the horses */ @Override public List<Horse> findAll() { return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null); } /** * Returns a range of all the horses. * * <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 HorseModelImpl}. 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 horses * @param end the upper bound of the range of horses (not inclusive) * @return the range of horses */ @Override public List<Horse> findAll(int start, int end) { return findAll(start, end, null); } /** * Returns an ordered range of all the horses. * * <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 HorseModelImpl}. 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 horses * @param end the upper bound of the range of horses (not inclusive) * @param orderByComparator the comparator to order the results by (optionally <code>null</code>) * @return the ordered range of horses */ @Override public List<Horse> findAll(int start, int end, OrderByComparator<Horse> orderByComparator) { return findAll(start, end, orderByComparator, true); } /** * Returns an ordered range of all the horses. * * <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 HorseModelImpl}. 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 horses * @param end the upper bound of the range of horses (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 horses */ @Override public List<Horse> findAll(int start, int end, OrderByComparator<Horse> 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<Horse> list = null; if (retrieveFromCache) { list = (List<Horse>) 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_HORSE); appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator); sql = query.toString(); } else { sql = _SQL_SELECT_HORSE; if (pagination) { sql = sql.concat(HorseModelImpl.ORDER_BY_JPQL); } } Session session = null; try { session = openSession(); Query q = session.createQuery(sql); if (!pagination) { list = (List<Horse>) QueryUtil.list(q, getDialect(), start, end, false); Collections.sort(list); list = Collections.unmodifiableList(list); } else { list = (List<Horse>) 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 horses from the database. * */ @Override public void removeAll() { for (Horse horse : findAll()) { remove(horse); } } /** * Returns the number of horses. * * @return the number of horses */ @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_HORSE); 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 HorseModelImpl.TABLE_COLUMNS_MAP; } /** * Initializes the horse persistence. */ public void afterPropertiesSet() { } public void destroy() { entityCache.removeCache(HorseImpl.class.getName()); finderCache.removeCache(FINDER_CLASS_NAME_ENTITY); finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION); finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION); } @ServiceReference(type = CompanyProviderWrapper.class) protected CompanyProvider companyProvider; @ServiceReference(type = EntityCache.class) protected EntityCache entityCache; @ServiceReference(type = FinderCache.class) protected FinderCache finderCache; private static final String _SQL_SELECT_HORSE = "SELECT horse FROM Horse horse"; private static final String _SQL_SELECT_HORSE_WHERE_PKS_IN = "SELECT horse FROM Horse horse WHERE horseId IN ("; private static final String _SQL_SELECT_HORSE_WHERE = "SELECT horse FROM Horse horse WHERE "; private static final String _SQL_COUNT_HORSE = "SELECT COUNT(horse) FROM Horse horse"; private static final String _SQL_COUNT_HORSE_WHERE = "SELECT COUNT(horse) FROM Horse horse WHERE "; private static final String _ORDER_BY_ENTITY_ALIAS = "horse."; private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Horse exists with the primary key "; private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Horse exists with the key {"; private static final Log _log = LogFactoryUtil.getLog(HorsePersistenceImpl.class); private static final Set<String> _badColumnNames = SetUtil.fromArray(new String[] { "uuid" }); }