/** * 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.workflow.kaleo.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.StringBundler; import com.liferay.portal.kernel.util.StringPool; import com.liferay.portal.kernel.util.StringUtil; import com.liferay.portal.spring.extender.service.ServiceReference; import com.liferay.portal.workflow.kaleo.exception.NoSuchTaskException; import com.liferay.portal.workflow.kaleo.model.KaleoTask; import com.liferay.portal.workflow.kaleo.model.impl.KaleoTaskImpl; import com.liferay.portal.workflow.kaleo.model.impl.KaleoTaskModelImpl; import com.liferay.portal.workflow.kaleo.service.persistence.KaleoTaskPersistence; 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.Set; /** * The persistence implementation for the kaleo task service. * * <p> * Caching information and settings can be found in <code>portal.properties</code> * </p> * * @author Brian Wing Shun Chan * @see KaleoTaskPersistence * @see com.liferay.portal.workflow.kaleo.service.persistence.KaleoTaskUtil * @generated */ @ProviderType public class KaleoTaskPersistenceImpl extends BasePersistenceImpl<KaleoTask> implements KaleoTaskPersistence { /* * NOTE FOR DEVELOPERS: * * Never modify or reference this class directly. Always use {@link KaleoTaskUtil} to access the kaleo task persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class. */ public static final String FINDER_CLASS_NAME_ENTITY = KaleoTaskImpl.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(KaleoTaskModelImpl.ENTITY_CACHE_ENABLED, KaleoTaskModelImpl.FINDER_CACHE_ENABLED, KaleoTaskImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]); public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(KaleoTaskModelImpl.ENTITY_CACHE_ENABLED, KaleoTaskModelImpl.FINDER_CACHE_ENABLED, KaleoTaskImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]); public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(KaleoTaskModelImpl.ENTITY_CACHE_ENABLED, KaleoTaskModelImpl.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_COMPANYID = new FinderPath(KaleoTaskModelImpl.ENTITY_CACHE_ENABLED, KaleoTaskModelImpl.FINDER_CACHE_ENABLED, KaleoTaskImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByCompanyId", new String[] { Long.class.getName(), Integer.class.getName(), Integer.class.getName(), OrderByComparator.class.getName() }); public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID = new FinderPath(KaleoTaskModelImpl.ENTITY_CACHE_ENABLED, KaleoTaskModelImpl.FINDER_CACHE_ENABLED, KaleoTaskImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCompanyId", new String[] { Long.class.getName() }, KaleoTaskModelImpl.COMPANYID_COLUMN_BITMASK); public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(KaleoTaskModelImpl.ENTITY_CACHE_ENABLED, KaleoTaskModelImpl.FINDER_CACHE_ENABLED, Long.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId", new String[] { Long.class.getName() }); /** * Returns all the kaleo tasks where companyId = ?. * * @param companyId the company ID * @return the matching kaleo tasks */ @Override public List<KaleoTask> findByCompanyId(long companyId) { return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null); } /** * Returns a range of all the kaleo tasks where 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 KaleoTaskModelImpl}. 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 companyId the company ID * @param start the lower bound of the range of kaleo tasks * @param end the upper bound of the range of kaleo tasks (not inclusive) * @return the range of matching kaleo tasks */ @Override public List<KaleoTask> findByCompanyId(long companyId, int start, int end) { return findByCompanyId(companyId, start, end, null); } /** * Returns an ordered range of all the kaleo tasks where 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 KaleoTaskModelImpl}. 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 companyId the company ID * @param start the lower bound of the range of kaleo tasks * @param end the upper bound of the range of kaleo tasks (not inclusive) * @param orderByComparator the comparator to order the results by (optionally <code>null</code>) * @return the ordered range of matching kaleo tasks */ @Override public List<KaleoTask> findByCompanyId(long companyId, int start, int end, OrderByComparator<KaleoTask> orderByComparator) { return findByCompanyId(companyId, start, end, orderByComparator, true); } /** * Returns an ordered range of all the kaleo tasks where 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 KaleoTaskModelImpl}. 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 companyId the company ID * @param start the lower bound of the range of kaleo tasks * @param end the upper bound of the range of kaleo tasks (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 kaleo tasks */ @Override public List<KaleoTask> findByCompanyId(long companyId, int start, int end, OrderByComparator<KaleoTask> 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_COMPANYID; finderArgs = new Object[] { companyId }; } else { finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID; finderArgs = new Object[] { companyId, start, end, orderByComparator }; } List<KaleoTask> list = null; if (retrieveFromCache) { list = (List<KaleoTask>)finderCache.getResult(finderPath, finderArgs, this); if ((list != null) && !list.isEmpty()) { for (KaleoTask kaleoTask : list) { if ((companyId != kaleoTask.getCompanyId())) { 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_KALEOTASK_WHERE); query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2); if (orderByComparator != null) { appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator); } else if (pagination) { query.append(KaleoTaskModelImpl.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(companyId); if (!pagination) { list = (List<KaleoTask>)QueryUtil.list(q, getDialect(), start, end, false); Collections.sort(list); list = Collections.unmodifiableList(list); } else { list = (List<KaleoTask>)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 kaleo task in the ordered set where companyId = ?. * * @param companyId the company ID * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the first matching kaleo task * @throws NoSuchTaskException if a matching kaleo task could not be found */ @Override public KaleoTask findByCompanyId_First(long companyId, OrderByComparator<KaleoTask> orderByComparator) throws NoSuchTaskException { KaleoTask kaleoTask = fetchByCompanyId_First(companyId, orderByComparator); if (kaleoTask != null) { return kaleoTask; } StringBundler msg = new StringBundler(4); msg.append(_NO_SUCH_ENTITY_WITH_KEY); msg.append("companyId="); msg.append(companyId); msg.append(StringPool.CLOSE_CURLY_BRACE); throw new NoSuchTaskException(msg.toString()); } /** * Returns the first kaleo task in the ordered set where companyId = ?. * * @param companyId the company ID * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the first matching kaleo task, or <code>null</code> if a matching kaleo task could not be found */ @Override public KaleoTask fetchByCompanyId_First(long companyId, OrderByComparator<KaleoTask> orderByComparator) { List<KaleoTask> list = findByCompanyId(companyId, 0, 1, orderByComparator); if (!list.isEmpty()) { return list.get(0); } return null; } /** * Returns the last kaleo task in the ordered set where companyId = ?. * * @param companyId the company ID * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the last matching kaleo task * @throws NoSuchTaskException if a matching kaleo task could not be found */ @Override public KaleoTask findByCompanyId_Last(long companyId, OrderByComparator<KaleoTask> orderByComparator) throws NoSuchTaskException { KaleoTask kaleoTask = fetchByCompanyId_Last(companyId, orderByComparator); if (kaleoTask != null) { return kaleoTask; } StringBundler msg = new StringBundler(4); msg.append(_NO_SUCH_ENTITY_WITH_KEY); msg.append("companyId="); msg.append(companyId); msg.append(StringPool.CLOSE_CURLY_BRACE); throw new NoSuchTaskException(msg.toString()); } /** * Returns the last kaleo task in the ordered set where companyId = ?. * * @param companyId the company ID * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the last matching kaleo task, or <code>null</code> if a matching kaleo task could not be found */ @Override public KaleoTask fetchByCompanyId_Last(long companyId, OrderByComparator<KaleoTask> orderByComparator) { int count = countByCompanyId(companyId); if (count == 0) { return null; } List<KaleoTask> list = findByCompanyId(companyId, count - 1, count, orderByComparator); if (!list.isEmpty()) { return list.get(0); } return null; } /** * Returns the kaleo tasks before and after the current kaleo task in the ordered set where companyId = ?. * * @param kaleoTaskId the primary key of the current kaleo task * @param companyId the company ID * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the previous, current, and next kaleo task * @throws NoSuchTaskException if a kaleo task with the primary key could not be found */ @Override public KaleoTask[] findByCompanyId_PrevAndNext(long kaleoTaskId, long companyId, OrderByComparator<KaleoTask> orderByComparator) throws NoSuchTaskException { KaleoTask kaleoTask = findByPrimaryKey(kaleoTaskId); Session session = null; try { session = openSession(); KaleoTask[] array = new KaleoTaskImpl[3]; array[0] = getByCompanyId_PrevAndNext(session, kaleoTask, companyId, orderByComparator, true); array[1] = kaleoTask; array[2] = getByCompanyId_PrevAndNext(session, kaleoTask, companyId, orderByComparator, false); return array; } catch (Exception e) { throw processException(e); } finally { closeSession(session); } } protected KaleoTask getByCompanyId_PrevAndNext(Session session, KaleoTask kaleoTask, long companyId, OrderByComparator<KaleoTask> 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_KALEOTASK_WHERE); query.append(_FINDER_COLUMN_COMPANYID_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(KaleoTaskModelImpl.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(companyId); if (orderByComparator != null) { Object[] values = orderByComparator.getOrderByConditionValues(kaleoTask); for (Object value : values) { qPos.add(value); } } List<KaleoTask> list = q.list(); if (list.size() == 2) { return list.get(1); } else { return null; } } /** * Removes all the kaleo tasks where companyId = ? from the database. * * @param companyId the company ID */ @Override public void removeByCompanyId(long companyId) { for (KaleoTask kaleoTask : findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) { remove(kaleoTask); } } /** * Returns the number of kaleo tasks where companyId = ?. * * @param companyId the company ID * @return the number of matching kaleo tasks */ @Override public int countByCompanyId(long companyId) { FinderPath finderPath = FINDER_PATH_COUNT_BY_COMPANYID; Object[] finderArgs = new Object[] { companyId }; Long count = (Long)finderCache.getResult(finderPath, finderArgs, this); if (count == null) { StringBundler query = new StringBundler(2); query.append(_SQL_COUNT_KALEOTASK_WHERE); query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2); String sql = query.toString(); Session session = null; try { session = openSession(); Query q = session.createQuery(sql); QueryPos qPos = QueryPos.getInstance(q); 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_COMPANYID_COMPANYID_2 = "kaleoTask.companyId = ?"; public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_KALEODEFINITIONID = new FinderPath(KaleoTaskModelImpl.ENTITY_CACHE_ENABLED, KaleoTaskModelImpl.FINDER_CACHE_ENABLED, KaleoTaskImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByKaleoDefinitionId", new String[] { Long.class.getName(), Integer.class.getName(), Integer.class.getName(), OrderByComparator.class.getName() }); public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_KALEODEFINITIONID = new FinderPath(KaleoTaskModelImpl.ENTITY_CACHE_ENABLED, KaleoTaskModelImpl.FINDER_CACHE_ENABLED, KaleoTaskImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByKaleoDefinitionId", new String[] { Long.class.getName() }, KaleoTaskModelImpl.KALEODEFINITIONID_COLUMN_BITMASK); public static final FinderPath FINDER_PATH_COUNT_BY_KALEODEFINITIONID = new FinderPath(KaleoTaskModelImpl.ENTITY_CACHE_ENABLED, KaleoTaskModelImpl.FINDER_CACHE_ENABLED, Long.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByKaleoDefinitionId", new String[] { Long.class.getName() }); /** * Returns all the kaleo tasks where kaleoDefinitionId = ?. * * @param kaleoDefinitionId the kaleo definition ID * @return the matching kaleo tasks */ @Override public List<KaleoTask> findByKaleoDefinitionId(long kaleoDefinitionId) { return findByKaleoDefinitionId(kaleoDefinitionId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null); } /** * Returns a range of all the kaleo tasks where kaleoDefinitionId = ?. * * <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 KaleoTaskModelImpl}. 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 kaleoDefinitionId the kaleo definition ID * @param start the lower bound of the range of kaleo tasks * @param end the upper bound of the range of kaleo tasks (not inclusive) * @return the range of matching kaleo tasks */ @Override public List<KaleoTask> findByKaleoDefinitionId(long kaleoDefinitionId, int start, int end) { return findByKaleoDefinitionId(kaleoDefinitionId, start, end, null); } /** * Returns an ordered range of all the kaleo tasks where kaleoDefinitionId = ?. * * <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 KaleoTaskModelImpl}. 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 kaleoDefinitionId the kaleo definition ID * @param start the lower bound of the range of kaleo tasks * @param end the upper bound of the range of kaleo tasks (not inclusive) * @param orderByComparator the comparator to order the results by (optionally <code>null</code>) * @return the ordered range of matching kaleo tasks */ @Override public List<KaleoTask> findByKaleoDefinitionId(long kaleoDefinitionId, int start, int end, OrderByComparator<KaleoTask> orderByComparator) { return findByKaleoDefinitionId(kaleoDefinitionId, start, end, orderByComparator, true); } /** * Returns an ordered range of all the kaleo tasks where kaleoDefinitionId = ?. * * <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 KaleoTaskModelImpl}. 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 kaleoDefinitionId the kaleo definition ID * @param start the lower bound of the range of kaleo tasks * @param end the upper bound of the range of kaleo tasks (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 kaleo tasks */ @Override public List<KaleoTask> findByKaleoDefinitionId(long kaleoDefinitionId, int start, int end, OrderByComparator<KaleoTask> 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_KALEODEFINITIONID; finderArgs = new Object[] { kaleoDefinitionId }; } else { finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_KALEODEFINITIONID; finderArgs = new Object[] { kaleoDefinitionId, start, end, orderByComparator }; } List<KaleoTask> list = null; if (retrieveFromCache) { list = (List<KaleoTask>)finderCache.getResult(finderPath, finderArgs, this); if ((list != null) && !list.isEmpty()) { for (KaleoTask kaleoTask : list) { if ((kaleoDefinitionId != kaleoTask.getKaleoDefinitionId())) { 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_KALEOTASK_WHERE); query.append(_FINDER_COLUMN_KALEODEFINITIONID_KALEODEFINITIONID_2); if (orderByComparator != null) { appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator); } else if (pagination) { query.append(KaleoTaskModelImpl.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(kaleoDefinitionId); if (!pagination) { list = (List<KaleoTask>)QueryUtil.list(q, getDialect(), start, end, false); Collections.sort(list); list = Collections.unmodifiableList(list); } else { list = (List<KaleoTask>)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 kaleo task in the ordered set where kaleoDefinitionId = ?. * * @param kaleoDefinitionId the kaleo definition ID * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the first matching kaleo task * @throws NoSuchTaskException if a matching kaleo task could not be found */ @Override public KaleoTask findByKaleoDefinitionId_First(long kaleoDefinitionId, OrderByComparator<KaleoTask> orderByComparator) throws NoSuchTaskException { KaleoTask kaleoTask = fetchByKaleoDefinitionId_First(kaleoDefinitionId, orderByComparator); if (kaleoTask != null) { return kaleoTask; } StringBundler msg = new StringBundler(4); msg.append(_NO_SUCH_ENTITY_WITH_KEY); msg.append("kaleoDefinitionId="); msg.append(kaleoDefinitionId); msg.append(StringPool.CLOSE_CURLY_BRACE); throw new NoSuchTaskException(msg.toString()); } /** * Returns the first kaleo task in the ordered set where kaleoDefinitionId = ?. * * @param kaleoDefinitionId the kaleo definition ID * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the first matching kaleo task, or <code>null</code> if a matching kaleo task could not be found */ @Override public KaleoTask fetchByKaleoDefinitionId_First(long kaleoDefinitionId, OrderByComparator<KaleoTask> orderByComparator) { List<KaleoTask> list = findByKaleoDefinitionId(kaleoDefinitionId, 0, 1, orderByComparator); if (!list.isEmpty()) { return list.get(0); } return null; } /** * Returns the last kaleo task in the ordered set where kaleoDefinitionId = ?. * * @param kaleoDefinitionId the kaleo definition ID * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the last matching kaleo task * @throws NoSuchTaskException if a matching kaleo task could not be found */ @Override public KaleoTask findByKaleoDefinitionId_Last(long kaleoDefinitionId, OrderByComparator<KaleoTask> orderByComparator) throws NoSuchTaskException { KaleoTask kaleoTask = fetchByKaleoDefinitionId_Last(kaleoDefinitionId, orderByComparator); if (kaleoTask != null) { return kaleoTask; } StringBundler msg = new StringBundler(4); msg.append(_NO_SUCH_ENTITY_WITH_KEY); msg.append("kaleoDefinitionId="); msg.append(kaleoDefinitionId); msg.append(StringPool.CLOSE_CURLY_BRACE); throw new NoSuchTaskException(msg.toString()); } /** * Returns the last kaleo task in the ordered set where kaleoDefinitionId = ?. * * @param kaleoDefinitionId the kaleo definition ID * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the last matching kaleo task, or <code>null</code> if a matching kaleo task could not be found */ @Override public KaleoTask fetchByKaleoDefinitionId_Last(long kaleoDefinitionId, OrderByComparator<KaleoTask> orderByComparator) { int count = countByKaleoDefinitionId(kaleoDefinitionId); if (count == 0) { return null; } List<KaleoTask> list = findByKaleoDefinitionId(kaleoDefinitionId, count - 1, count, orderByComparator); if (!list.isEmpty()) { return list.get(0); } return null; } /** * Returns the kaleo tasks before and after the current kaleo task in the ordered set where kaleoDefinitionId = ?. * * @param kaleoTaskId the primary key of the current kaleo task * @param kaleoDefinitionId the kaleo definition ID * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the previous, current, and next kaleo task * @throws NoSuchTaskException if a kaleo task with the primary key could not be found */ @Override public KaleoTask[] findByKaleoDefinitionId_PrevAndNext(long kaleoTaskId, long kaleoDefinitionId, OrderByComparator<KaleoTask> orderByComparator) throws NoSuchTaskException { KaleoTask kaleoTask = findByPrimaryKey(kaleoTaskId); Session session = null; try { session = openSession(); KaleoTask[] array = new KaleoTaskImpl[3]; array[0] = getByKaleoDefinitionId_PrevAndNext(session, kaleoTask, kaleoDefinitionId, orderByComparator, true); array[1] = kaleoTask; array[2] = getByKaleoDefinitionId_PrevAndNext(session, kaleoTask, kaleoDefinitionId, orderByComparator, false); return array; } catch (Exception e) { throw processException(e); } finally { closeSession(session); } } protected KaleoTask getByKaleoDefinitionId_PrevAndNext(Session session, KaleoTask kaleoTask, long kaleoDefinitionId, OrderByComparator<KaleoTask> 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_KALEOTASK_WHERE); query.append(_FINDER_COLUMN_KALEODEFINITIONID_KALEODEFINITIONID_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(KaleoTaskModelImpl.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(kaleoDefinitionId); if (orderByComparator != null) { Object[] values = orderByComparator.getOrderByConditionValues(kaleoTask); for (Object value : values) { qPos.add(value); } } List<KaleoTask> list = q.list(); if (list.size() == 2) { return list.get(1); } else { return null; } } /** * Removes all the kaleo tasks where kaleoDefinitionId = ? from the database. * * @param kaleoDefinitionId the kaleo definition ID */ @Override public void removeByKaleoDefinitionId(long kaleoDefinitionId) { for (KaleoTask kaleoTask : findByKaleoDefinitionId(kaleoDefinitionId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) { remove(kaleoTask); } } /** * Returns the number of kaleo tasks where kaleoDefinitionId = ?. * * @param kaleoDefinitionId the kaleo definition ID * @return the number of matching kaleo tasks */ @Override public int countByKaleoDefinitionId(long kaleoDefinitionId) { FinderPath finderPath = FINDER_PATH_COUNT_BY_KALEODEFINITIONID; Object[] finderArgs = new Object[] { kaleoDefinitionId }; Long count = (Long)finderCache.getResult(finderPath, finderArgs, this); if (count == null) { StringBundler query = new StringBundler(2); query.append(_SQL_COUNT_KALEOTASK_WHERE); query.append(_FINDER_COLUMN_KALEODEFINITIONID_KALEODEFINITIONID_2); String sql = query.toString(); Session session = null; try { session = openSession(); Query q = session.createQuery(sql); QueryPos qPos = QueryPos.getInstance(q); qPos.add(kaleoDefinitionId); 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_KALEODEFINITIONID_KALEODEFINITIONID_2 = "kaleoTask.kaleoDefinitionId = ?"; public static final FinderPath FINDER_PATH_FETCH_BY_KALEONODEID = new FinderPath(KaleoTaskModelImpl.ENTITY_CACHE_ENABLED, KaleoTaskModelImpl.FINDER_CACHE_ENABLED, KaleoTaskImpl.class, FINDER_CLASS_NAME_ENTITY, "fetchByKaleoNodeId", new String[] { Long.class.getName() }, KaleoTaskModelImpl.KALEONODEID_COLUMN_BITMASK); public static final FinderPath FINDER_PATH_COUNT_BY_KALEONODEID = new FinderPath(KaleoTaskModelImpl.ENTITY_CACHE_ENABLED, KaleoTaskModelImpl.FINDER_CACHE_ENABLED, Long.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByKaleoNodeId", new String[] { Long.class.getName() }); /** * Returns the kaleo task where kaleoNodeId = ? or throws a {@link NoSuchTaskException} if it could not be found. * * @param kaleoNodeId the kaleo node ID * @return the matching kaleo task * @throws NoSuchTaskException if a matching kaleo task could not be found */ @Override public KaleoTask findByKaleoNodeId(long kaleoNodeId) throws NoSuchTaskException { KaleoTask kaleoTask = fetchByKaleoNodeId(kaleoNodeId); if (kaleoTask == null) { StringBundler msg = new StringBundler(4); msg.append(_NO_SUCH_ENTITY_WITH_KEY); msg.append("kaleoNodeId="); msg.append(kaleoNodeId); msg.append(StringPool.CLOSE_CURLY_BRACE); if (_log.isDebugEnabled()) { _log.debug(msg.toString()); } throw new NoSuchTaskException(msg.toString()); } return kaleoTask; } /** * Returns the kaleo task where kaleoNodeId = ? or returns <code>null</code> if it could not be found. Uses the finder cache. * * @param kaleoNodeId the kaleo node ID * @return the matching kaleo task, or <code>null</code> if a matching kaleo task could not be found */ @Override public KaleoTask fetchByKaleoNodeId(long kaleoNodeId) { return fetchByKaleoNodeId(kaleoNodeId, true); } /** * Returns the kaleo task where kaleoNodeId = ? or returns <code>null</code> if it could not be found, optionally using the finder cache. * * @param kaleoNodeId the kaleo node ID * @param retrieveFromCache whether to retrieve from the finder cache * @return the matching kaleo task, or <code>null</code> if a matching kaleo task could not be found */ @Override public KaleoTask fetchByKaleoNodeId(long kaleoNodeId, boolean retrieveFromCache) { Object[] finderArgs = new Object[] { kaleoNodeId }; Object result = null; if (retrieveFromCache) { result = finderCache.getResult(FINDER_PATH_FETCH_BY_KALEONODEID, finderArgs, this); } if (result instanceof KaleoTask) { KaleoTask kaleoTask = (KaleoTask)result; if ((kaleoNodeId != kaleoTask.getKaleoNodeId())) { result = null; } } if (result == null) { StringBundler query = new StringBundler(3); query.append(_SQL_SELECT_KALEOTASK_WHERE); query.append(_FINDER_COLUMN_KALEONODEID_KALEONODEID_2); String sql = query.toString(); Session session = null; try { session = openSession(); Query q = session.createQuery(sql); QueryPos qPos = QueryPos.getInstance(q); qPos.add(kaleoNodeId); List<KaleoTask> list = q.list(); if (list.isEmpty()) { finderCache.putResult(FINDER_PATH_FETCH_BY_KALEONODEID, finderArgs, list); } else { if (list.size() > 1) { Collections.sort(list, Collections.reverseOrder()); if (_log.isWarnEnabled()) { _log.warn( "KaleoTaskPersistenceImpl.fetchByKaleoNodeId(long, boolean) with parameters (" + StringUtil.merge(finderArgs) + ") yields a result set with more than 1 result. This violates the logical unique restriction. There is no order guarantee on which result is returned by this finder."); } } KaleoTask kaleoTask = list.get(0); result = kaleoTask; cacheResult(kaleoTask); if ((kaleoTask.getKaleoNodeId() != kaleoNodeId)) { finderCache.putResult(FINDER_PATH_FETCH_BY_KALEONODEID, finderArgs, kaleoTask); } } } catch (Exception e) { finderCache.removeResult(FINDER_PATH_FETCH_BY_KALEONODEID, finderArgs); throw processException(e); } finally { closeSession(session); } } if (result instanceof List<?>) { return null; } else { return (KaleoTask)result; } } /** * Removes the kaleo task where kaleoNodeId = ? from the database. * * @param kaleoNodeId the kaleo node ID * @return the kaleo task that was removed */ @Override public KaleoTask removeByKaleoNodeId(long kaleoNodeId) throws NoSuchTaskException { KaleoTask kaleoTask = findByKaleoNodeId(kaleoNodeId); return remove(kaleoTask); } /** * Returns the number of kaleo tasks where kaleoNodeId = ?. * * @param kaleoNodeId the kaleo node ID * @return the number of matching kaleo tasks */ @Override public int countByKaleoNodeId(long kaleoNodeId) { FinderPath finderPath = FINDER_PATH_COUNT_BY_KALEONODEID; Object[] finderArgs = new Object[] { kaleoNodeId }; Long count = (Long)finderCache.getResult(finderPath, finderArgs, this); if (count == null) { StringBundler query = new StringBundler(2); query.append(_SQL_COUNT_KALEOTASK_WHERE); query.append(_FINDER_COLUMN_KALEONODEID_KALEONODEID_2); String sql = query.toString(); Session session = null; try { session = openSession(); Query q = session.createQuery(sql); QueryPos qPos = QueryPos.getInstance(q); qPos.add(kaleoNodeId); 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_KALEONODEID_KALEONODEID_2 = "kaleoTask.kaleoNodeId = ?"; public KaleoTaskPersistenceImpl() { setModelClass(KaleoTask.class); } /** * Caches the kaleo task in the entity cache if it is enabled. * * @param kaleoTask the kaleo task */ @Override public void cacheResult(KaleoTask kaleoTask) { entityCache.putResult(KaleoTaskModelImpl.ENTITY_CACHE_ENABLED, KaleoTaskImpl.class, kaleoTask.getPrimaryKey(), kaleoTask); finderCache.putResult(FINDER_PATH_FETCH_BY_KALEONODEID, new Object[] { kaleoTask.getKaleoNodeId() }, kaleoTask); kaleoTask.resetOriginalValues(); } /** * Caches the kaleo tasks in the entity cache if it is enabled. * * @param kaleoTasks the kaleo tasks */ @Override public void cacheResult(List<KaleoTask> kaleoTasks) { for (KaleoTask kaleoTask : kaleoTasks) { if (entityCache.getResult(KaleoTaskModelImpl.ENTITY_CACHE_ENABLED, KaleoTaskImpl.class, kaleoTask.getPrimaryKey()) == null) { cacheResult(kaleoTask); } else { kaleoTask.resetOriginalValues(); } } } /** * Clears the cache for all kaleo tasks. * * <p> * The {@link EntityCache} and {@link FinderCache} are both cleared by this method. * </p> */ @Override public void clearCache() { entityCache.clearCache(KaleoTaskImpl.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 kaleo task. * * <p> * The {@link EntityCache} and {@link FinderCache} are both cleared by this method. * </p> */ @Override public void clearCache(KaleoTask kaleoTask) { entityCache.removeResult(KaleoTaskModelImpl.ENTITY_CACHE_ENABLED, KaleoTaskImpl.class, kaleoTask.getPrimaryKey()); finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION); finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION); clearUniqueFindersCache((KaleoTaskModelImpl)kaleoTask, true); } @Override public void clearCache(List<KaleoTask> kaleoTasks) { finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION); finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION); for (KaleoTask kaleoTask : kaleoTasks) { entityCache.removeResult(KaleoTaskModelImpl.ENTITY_CACHE_ENABLED, KaleoTaskImpl.class, kaleoTask.getPrimaryKey()); clearUniqueFindersCache((KaleoTaskModelImpl)kaleoTask, true); } } protected void cacheUniqueFindersCache( KaleoTaskModelImpl kaleoTaskModelImpl) { Object[] args = new Object[] { kaleoTaskModelImpl.getKaleoNodeId() }; finderCache.putResult(FINDER_PATH_COUNT_BY_KALEONODEID, args, Long.valueOf(1), false); finderCache.putResult(FINDER_PATH_FETCH_BY_KALEONODEID, args, kaleoTaskModelImpl, false); } protected void clearUniqueFindersCache( KaleoTaskModelImpl kaleoTaskModelImpl, boolean clearCurrent) { if (clearCurrent) { Object[] args = new Object[] { kaleoTaskModelImpl.getKaleoNodeId() }; finderCache.removeResult(FINDER_PATH_COUNT_BY_KALEONODEID, args); finderCache.removeResult(FINDER_PATH_FETCH_BY_KALEONODEID, args); } if ((kaleoTaskModelImpl.getColumnBitmask() & FINDER_PATH_FETCH_BY_KALEONODEID.getColumnBitmask()) != 0) { Object[] args = new Object[] { kaleoTaskModelImpl.getOriginalKaleoNodeId() }; finderCache.removeResult(FINDER_PATH_COUNT_BY_KALEONODEID, args); finderCache.removeResult(FINDER_PATH_FETCH_BY_KALEONODEID, args); } } /** * Creates a new kaleo task with the primary key. Does not add the kaleo task to the database. * * @param kaleoTaskId the primary key for the new kaleo task * @return the new kaleo task */ @Override public KaleoTask create(long kaleoTaskId) { KaleoTask kaleoTask = new KaleoTaskImpl(); kaleoTask.setNew(true); kaleoTask.setPrimaryKey(kaleoTaskId); kaleoTask.setCompanyId(companyProvider.getCompanyId()); return kaleoTask; } /** * Removes the kaleo task with the primary key from the database. Also notifies the appropriate model listeners. * * @param kaleoTaskId the primary key of the kaleo task * @return the kaleo task that was removed * @throws NoSuchTaskException if a kaleo task with the primary key could not be found */ @Override public KaleoTask remove(long kaleoTaskId) throws NoSuchTaskException { return remove((Serializable)kaleoTaskId); } /** * Removes the kaleo task with the primary key from the database. Also notifies the appropriate model listeners. * * @param primaryKey the primary key of the kaleo task * @return the kaleo task that was removed * @throws NoSuchTaskException if a kaleo task with the primary key could not be found */ @Override public KaleoTask remove(Serializable primaryKey) throws NoSuchTaskException { Session session = null; try { session = openSession(); KaleoTask kaleoTask = (KaleoTask)session.get(KaleoTaskImpl.class, primaryKey); if (kaleoTask == null) { if (_log.isDebugEnabled()) { _log.debug(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey); } throw new NoSuchTaskException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey); } return remove(kaleoTask); } catch (NoSuchTaskException nsee) { throw nsee; } catch (Exception e) { throw processException(e); } finally { closeSession(session); } } @Override protected KaleoTask removeImpl(KaleoTask kaleoTask) { kaleoTask = toUnwrappedModel(kaleoTask); Session session = null; try { session = openSession(); if (!session.contains(kaleoTask)) { kaleoTask = (KaleoTask)session.get(KaleoTaskImpl.class, kaleoTask.getPrimaryKeyObj()); } if (kaleoTask != null) { session.delete(kaleoTask); } } catch (Exception e) { throw processException(e); } finally { closeSession(session); } if (kaleoTask != null) { clearCache(kaleoTask); } return kaleoTask; } @Override public KaleoTask updateImpl(KaleoTask kaleoTask) { kaleoTask = toUnwrappedModel(kaleoTask); boolean isNew = kaleoTask.isNew(); KaleoTaskModelImpl kaleoTaskModelImpl = (KaleoTaskModelImpl)kaleoTask; ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext(); Date now = new Date(); if (isNew && (kaleoTask.getCreateDate() == null)) { if (serviceContext == null) { kaleoTask.setCreateDate(now); } else { kaleoTask.setCreateDate(serviceContext.getCreateDate(now)); } } if (!kaleoTaskModelImpl.hasSetModifiedDate()) { if (serviceContext == null) { kaleoTask.setModifiedDate(now); } else { kaleoTask.setModifiedDate(serviceContext.getModifiedDate(now)); } } Session session = null; try { session = openSession(); if (kaleoTask.isNew()) { session.save(kaleoTask); kaleoTask.setNew(false); } else { kaleoTask = (KaleoTask)session.merge(kaleoTask); } } catch (Exception e) { throw processException(e); } finally { closeSession(session); } finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION); if (!KaleoTaskModelImpl.COLUMN_BITMASK_ENABLED) { finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION); } else if (isNew) { Object[] args = new Object[] { kaleoTaskModelImpl.getCompanyId() }; finderCache.removeResult(FINDER_PATH_COUNT_BY_COMPANYID, args); finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID, args); args = new Object[] { kaleoTaskModelImpl.getKaleoDefinitionId() }; finderCache.removeResult(FINDER_PATH_COUNT_BY_KALEODEFINITIONID, args); finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_KALEODEFINITIONID, args); finderCache.removeResult(FINDER_PATH_COUNT_ALL, FINDER_ARGS_EMPTY); finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL, FINDER_ARGS_EMPTY); } else { if ((kaleoTaskModelImpl.getColumnBitmask() & FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) { Object[] args = new Object[] { kaleoTaskModelImpl.getOriginalCompanyId() }; finderCache.removeResult(FINDER_PATH_COUNT_BY_COMPANYID, args); finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID, args); args = new Object[] { kaleoTaskModelImpl.getCompanyId() }; finderCache.removeResult(FINDER_PATH_COUNT_BY_COMPANYID, args); finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID, args); } if ((kaleoTaskModelImpl.getColumnBitmask() & FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_KALEODEFINITIONID.getColumnBitmask()) != 0) { Object[] args = new Object[] { kaleoTaskModelImpl.getOriginalKaleoDefinitionId() }; finderCache.removeResult(FINDER_PATH_COUNT_BY_KALEODEFINITIONID, args); finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_KALEODEFINITIONID, args); args = new Object[] { kaleoTaskModelImpl.getKaleoDefinitionId() }; finderCache.removeResult(FINDER_PATH_COUNT_BY_KALEODEFINITIONID, args); finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_KALEODEFINITIONID, args); } } entityCache.putResult(KaleoTaskModelImpl.ENTITY_CACHE_ENABLED, KaleoTaskImpl.class, kaleoTask.getPrimaryKey(), kaleoTask, false); clearUniqueFindersCache(kaleoTaskModelImpl, false); cacheUniqueFindersCache(kaleoTaskModelImpl); kaleoTask.resetOriginalValues(); return kaleoTask; } protected KaleoTask toUnwrappedModel(KaleoTask kaleoTask) { if (kaleoTask instanceof KaleoTaskImpl) { return kaleoTask; } KaleoTaskImpl kaleoTaskImpl = new KaleoTaskImpl(); kaleoTaskImpl.setNew(kaleoTask.isNew()); kaleoTaskImpl.setPrimaryKey(kaleoTask.getPrimaryKey()); kaleoTaskImpl.setKaleoTaskId(kaleoTask.getKaleoTaskId()); kaleoTaskImpl.setGroupId(kaleoTask.getGroupId()); kaleoTaskImpl.setCompanyId(kaleoTask.getCompanyId()); kaleoTaskImpl.setUserId(kaleoTask.getUserId()); kaleoTaskImpl.setUserName(kaleoTask.getUserName()); kaleoTaskImpl.setCreateDate(kaleoTask.getCreateDate()); kaleoTaskImpl.setModifiedDate(kaleoTask.getModifiedDate()); kaleoTaskImpl.setKaleoDefinitionId(kaleoTask.getKaleoDefinitionId()); kaleoTaskImpl.setKaleoNodeId(kaleoTask.getKaleoNodeId()); kaleoTaskImpl.setName(kaleoTask.getName()); kaleoTaskImpl.setDescription(kaleoTask.getDescription()); return kaleoTaskImpl; } /** * Returns the kaleo task 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 kaleo task * @return the kaleo task * @throws NoSuchTaskException if a kaleo task with the primary key could not be found */ @Override public KaleoTask findByPrimaryKey(Serializable primaryKey) throws NoSuchTaskException { KaleoTask kaleoTask = fetchByPrimaryKey(primaryKey); if (kaleoTask == null) { if (_log.isDebugEnabled()) { _log.debug(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey); } throw new NoSuchTaskException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey); } return kaleoTask; } /** * Returns the kaleo task with the primary key or throws a {@link NoSuchTaskException} if it could not be found. * * @param kaleoTaskId the primary key of the kaleo task * @return the kaleo task * @throws NoSuchTaskException if a kaleo task with the primary key could not be found */ @Override public KaleoTask findByPrimaryKey(long kaleoTaskId) throws NoSuchTaskException { return findByPrimaryKey((Serializable)kaleoTaskId); } /** * Returns the kaleo task with the primary key or returns <code>null</code> if it could not be found. * * @param primaryKey the primary key of the kaleo task * @return the kaleo task, or <code>null</code> if a kaleo task with the primary key could not be found */ @Override public KaleoTask fetchByPrimaryKey(Serializable primaryKey) { Serializable serializable = entityCache.getResult(KaleoTaskModelImpl.ENTITY_CACHE_ENABLED, KaleoTaskImpl.class, primaryKey); if (serializable == nullModel) { return null; } KaleoTask kaleoTask = (KaleoTask)serializable; if (kaleoTask == null) { Session session = null; try { session = openSession(); kaleoTask = (KaleoTask)session.get(KaleoTaskImpl.class, primaryKey); if (kaleoTask != null) { cacheResult(kaleoTask); } else { entityCache.putResult(KaleoTaskModelImpl.ENTITY_CACHE_ENABLED, KaleoTaskImpl.class, primaryKey, nullModel); } } catch (Exception e) { entityCache.removeResult(KaleoTaskModelImpl.ENTITY_CACHE_ENABLED, KaleoTaskImpl.class, primaryKey); throw processException(e); } finally { closeSession(session); } } return kaleoTask; } /** * Returns the kaleo task with the primary key or returns <code>null</code> if it could not be found. * * @param kaleoTaskId the primary key of the kaleo task * @return the kaleo task, or <code>null</code> if a kaleo task with the primary key could not be found */ @Override public KaleoTask fetchByPrimaryKey(long kaleoTaskId) { return fetchByPrimaryKey((Serializable)kaleoTaskId); } @Override public Map<Serializable, KaleoTask> fetchByPrimaryKeys( Set<Serializable> primaryKeys) { if (primaryKeys.isEmpty()) { return Collections.emptyMap(); } Map<Serializable, KaleoTask> map = new HashMap<Serializable, KaleoTask>(); if (primaryKeys.size() == 1) { Iterator<Serializable> iterator = primaryKeys.iterator(); Serializable primaryKey = iterator.next(); KaleoTask kaleoTask = fetchByPrimaryKey(primaryKey); if (kaleoTask != null) { map.put(primaryKey, kaleoTask); } return map; } Set<Serializable> uncachedPrimaryKeys = null; for (Serializable primaryKey : primaryKeys) { Serializable serializable = entityCache.getResult(KaleoTaskModelImpl.ENTITY_CACHE_ENABLED, KaleoTaskImpl.class, primaryKey); if (serializable != nullModel) { if (serializable == null) { if (uncachedPrimaryKeys == null) { uncachedPrimaryKeys = new HashSet<Serializable>(); } uncachedPrimaryKeys.add(primaryKey); } else { map.put(primaryKey, (KaleoTask)serializable); } } } if (uncachedPrimaryKeys == null) { return map; } StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) + 1); query.append(_SQL_SELECT_KALEOTASK_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 (KaleoTask kaleoTask : (List<KaleoTask>)q.list()) { map.put(kaleoTask.getPrimaryKeyObj(), kaleoTask); cacheResult(kaleoTask); uncachedPrimaryKeys.remove(kaleoTask.getPrimaryKeyObj()); } for (Serializable primaryKey : uncachedPrimaryKeys) { entityCache.putResult(KaleoTaskModelImpl.ENTITY_CACHE_ENABLED, KaleoTaskImpl.class, primaryKey, nullModel); } } catch (Exception e) { throw processException(e); } finally { closeSession(session); } return map; } /** * Returns all the kaleo tasks. * * @return the kaleo tasks */ @Override public List<KaleoTask> findAll() { return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null); } /** * Returns a range of all the kaleo tasks. * * <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 KaleoTaskModelImpl}. 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 kaleo tasks * @param end the upper bound of the range of kaleo tasks (not inclusive) * @return the range of kaleo tasks */ @Override public List<KaleoTask> findAll(int start, int end) { return findAll(start, end, null); } /** * Returns an ordered range of all the kaleo tasks. * * <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 KaleoTaskModelImpl}. 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 kaleo tasks * @param end the upper bound of the range of kaleo tasks (not inclusive) * @param orderByComparator the comparator to order the results by (optionally <code>null</code>) * @return the ordered range of kaleo tasks */ @Override public List<KaleoTask> findAll(int start, int end, OrderByComparator<KaleoTask> orderByComparator) { return findAll(start, end, orderByComparator, true); } /** * Returns an ordered range of all the kaleo tasks. * * <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 KaleoTaskModelImpl}. 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 kaleo tasks * @param end the upper bound of the range of kaleo tasks (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 kaleo tasks */ @Override public List<KaleoTask> findAll(int start, int end, OrderByComparator<KaleoTask> 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<KaleoTask> list = null; if (retrieveFromCache) { list = (List<KaleoTask>)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_KALEOTASK); appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator); sql = query.toString(); } else { sql = _SQL_SELECT_KALEOTASK; if (pagination) { sql = sql.concat(KaleoTaskModelImpl.ORDER_BY_JPQL); } } Session session = null; try { session = openSession(); Query q = session.createQuery(sql); if (!pagination) { list = (List<KaleoTask>)QueryUtil.list(q, getDialect(), start, end, false); Collections.sort(list); list = Collections.unmodifiableList(list); } else { list = (List<KaleoTask>)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 kaleo tasks from the database. * */ @Override public void removeAll() { for (KaleoTask kaleoTask : findAll()) { remove(kaleoTask); } } /** * Returns the number of kaleo tasks. * * @return the number of kaleo tasks */ @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_KALEOTASK); 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 protected Map<String, Integer> getTableColumnsMap() { return KaleoTaskModelImpl.TABLE_COLUMNS_MAP; } /** * Initializes the kaleo task persistence. */ public void afterPropertiesSet() { } public void destroy() { entityCache.removeCache(KaleoTaskImpl.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_KALEOTASK = "SELECT kaleoTask FROM KaleoTask kaleoTask"; private static final String _SQL_SELECT_KALEOTASK_WHERE_PKS_IN = "SELECT kaleoTask FROM KaleoTask kaleoTask WHERE kaleoTaskId IN ("; private static final String _SQL_SELECT_KALEOTASK_WHERE = "SELECT kaleoTask FROM KaleoTask kaleoTask WHERE "; private static final String _SQL_COUNT_KALEOTASK = "SELECT COUNT(kaleoTask) FROM KaleoTask kaleoTask"; private static final String _SQL_COUNT_KALEOTASK_WHERE = "SELECT COUNT(kaleoTask) FROM KaleoTask kaleoTask WHERE "; private static final String _ORDER_BY_ENTITY_ALIAS = "kaleoTask."; private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No KaleoTask exists with the primary key "; private static final String _NO_SUCH_ENTITY_WITH_KEY = "No KaleoTask exists with the key {"; private static final Log _log = LogFactoryUtil.getLog(KaleoTaskPersistenceImpl.class); }