/** * Copyright (c) 2000-present Liferay, Inc. All rights reserved. * * This library is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by the Free * Software Foundation; either version 2.1 of the License, or (at your option) * any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more * details. */ package com.liferay.portal.service.persistence.impl; import aQute.bnd.annotation.ProviderType; import com.liferay.portal.kernel.bean.BeanReference; import com.liferay.portal.kernel.dao.orm.EntityCache; import com.liferay.portal.kernel.dao.orm.EntityCacheUtil; import com.liferay.portal.kernel.dao.orm.FinderCache; import com.liferay.portal.kernel.dao.orm.FinderCacheUtil; import com.liferay.portal.kernel.dao.orm.FinderPath; import com.liferay.portal.kernel.dao.orm.Query; import com.liferay.portal.kernel.dao.orm.QueryPos; import com.liferay.portal.kernel.dao.orm.QueryUtil; import com.liferay.portal.kernel.dao.orm.Session; import com.liferay.portal.kernel.exception.NoSuchContactException; import com.liferay.portal.kernel.log.Log; import com.liferay.portal.kernel.log.LogFactoryUtil; import com.liferay.portal.kernel.model.Contact; 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.ContactPersistence; 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.model.impl.ContactImpl; import com.liferay.portal.model.impl.ContactModelImpl; 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 contact service. * * <p> * Caching information and settings can be found in <code>portal.properties</code> * </p> * * @author Brian Wing Shun Chan * @see ContactPersistence * @see com.liferay.portal.kernel.service.persistence.ContactUtil * @generated */ @ProviderType public class ContactPersistenceImpl extends BasePersistenceImpl<Contact> implements ContactPersistence { /* * NOTE FOR DEVELOPERS: * * Never modify or reference this class directly. Always use {@link ContactUtil} to access the contact persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class. */ public static final String FINDER_CLASS_NAME_ENTITY = ContactImpl.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(ContactModelImpl.ENTITY_CACHE_ENABLED, ContactModelImpl.FINDER_CACHE_ENABLED, ContactImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]); public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(ContactModelImpl.ENTITY_CACHE_ENABLED, ContactModelImpl.FINDER_CACHE_ENABLED, ContactImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]); public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ContactModelImpl.ENTITY_CACHE_ENABLED, ContactModelImpl.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(ContactModelImpl.ENTITY_CACHE_ENABLED, ContactModelImpl.FINDER_CACHE_ENABLED, ContactImpl.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(ContactModelImpl.ENTITY_CACHE_ENABLED, ContactModelImpl.FINDER_CACHE_ENABLED, ContactImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCompanyId", new String[] { Long.class.getName() }, ContactModelImpl.COMPANYID_COLUMN_BITMASK); public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(ContactModelImpl.ENTITY_CACHE_ENABLED, ContactModelImpl.FINDER_CACHE_ENABLED, Long.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId", new String[] { Long.class.getName() }); /** * Returns all the contacts where companyId = ?. * * @param companyId the company ID * @return the matching contacts */ @Override public List<Contact> findByCompanyId(long companyId) { return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null); } /** * Returns a range of all the contacts 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 ContactModelImpl}. 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 contacts * @param end the upper bound of the range of contacts (not inclusive) * @return the range of matching contacts */ @Override public List<Contact> findByCompanyId(long companyId, int start, int end) { return findByCompanyId(companyId, start, end, null); } /** * Returns an ordered range of all the contacts 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 ContactModelImpl}. 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 contacts * @param end the upper bound of the range of contacts (not inclusive) * @param orderByComparator the comparator to order the results by (optionally <code>null</code>) * @return the ordered range of matching contacts */ @Override public List<Contact> findByCompanyId(long companyId, int start, int end, OrderByComparator<Contact> orderByComparator) { return findByCompanyId(companyId, start, end, orderByComparator, true); } /** * Returns an ordered range of all the contacts 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 ContactModelImpl}. 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 contacts * @param end the upper bound of the range of contacts (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 contacts */ @Override public List<Contact> findByCompanyId(long companyId, int start, int end, OrderByComparator<Contact> 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<Contact> list = null; if (retrieveFromCache) { list = (List<Contact>)finderCache.getResult(finderPath, finderArgs, this); if ((list != null) && !list.isEmpty()) { for (Contact contact : list) { if ((companyId != contact.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_CONTACT_WHERE); query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2); if (orderByComparator != null) { appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator); } else if (pagination) { query.append(ContactModelImpl.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<Contact>)QueryUtil.list(q, getDialect(), start, end, false); Collections.sort(list); list = Collections.unmodifiableList(list); } else { list = (List<Contact>)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 contact 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 contact * @throws NoSuchContactException if a matching contact could not be found */ @Override public Contact findByCompanyId_First(long companyId, OrderByComparator<Contact> orderByComparator) throws NoSuchContactException { Contact contact = fetchByCompanyId_First(companyId, orderByComparator); if (contact != null) { return contact; } 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 NoSuchContactException(msg.toString()); } /** * Returns the first contact 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 contact, or <code>null</code> if a matching contact could not be found */ @Override public Contact fetchByCompanyId_First(long companyId, OrderByComparator<Contact> orderByComparator) { List<Contact> list = findByCompanyId(companyId, 0, 1, orderByComparator); if (!list.isEmpty()) { return list.get(0); } return null; } /** * Returns the last contact 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 contact * @throws NoSuchContactException if a matching contact could not be found */ @Override public Contact findByCompanyId_Last(long companyId, OrderByComparator<Contact> orderByComparator) throws NoSuchContactException { Contact contact = fetchByCompanyId_Last(companyId, orderByComparator); if (contact != null) { return contact; } 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 NoSuchContactException(msg.toString()); } /** * Returns the last contact 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 contact, or <code>null</code> if a matching contact could not be found */ @Override public Contact fetchByCompanyId_Last(long companyId, OrderByComparator<Contact> orderByComparator) { int count = countByCompanyId(companyId); if (count == 0) { return null; } List<Contact> list = findByCompanyId(companyId, count - 1, count, orderByComparator); if (!list.isEmpty()) { return list.get(0); } return null; } /** * Returns the contacts before and after the current contact in the ordered set where companyId = ?. * * @param contactId the primary key of the current contact * @param companyId the company ID * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the previous, current, and next contact * @throws NoSuchContactException if a contact with the primary key could not be found */ @Override public Contact[] findByCompanyId_PrevAndNext(long contactId, long companyId, OrderByComparator<Contact> orderByComparator) throws NoSuchContactException { Contact contact = findByPrimaryKey(contactId); Session session = null; try { session = openSession(); Contact[] array = new ContactImpl[3]; array[0] = getByCompanyId_PrevAndNext(session, contact, companyId, orderByComparator, true); array[1] = contact; array[2] = getByCompanyId_PrevAndNext(session, contact, companyId, orderByComparator, false); return array; } catch (Exception e) { throw processException(e); } finally { closeSession(session); } } protected Contact getByCompanyId_PrevAndNext(Session session, Contact contact, long companyId, OrderByComparator<Contact> 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_CONTACT_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(ContactModelImpl.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(contact); for (Object value : values) { qPos.add(value); } } List<Contact> list = q.list(); if (list.size() == 2) { return list.get(1); } else { return null; } } /** * Removes all the contacts where companyId = ? from the database. * * @param companyId the company ID */ @Override public void removeByCompanyId(long companyId) { for (Contact contact : findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) { remove(contact); } } /** * Returns the number of contacts where companyId = ?. * * @param companyId the company ID * @return the number of matching contacts */ @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_CONTACT_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 = "contact.companyId = ?"; public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_ACCOUNTID = new FinderPath(ContactModelImpl.ENTITY_CACHE_ENABLED, ContactModelImpl.FINDER_CACHE_ENABLED, ContactImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByAccountId", new String[] { Long.class.getName(), Integer.class.getName(), Integer.class.getName(), OrderByComparator.class.getName() }); public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ACCOUNTID = new FinderPath(ContactModelImpl.ENTITY_CACHE_ENABLED, ContactModelImpl.FINDER_CACHE_ENABLED, ContactImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByAccountId", new String[] { Long.class.getName() }, ContactModelImpl.ACCOUNTID_COLUMN_BITMASK); public static final FinderPath FINDER_PATH_COUNT_BY_ACCOUNTID = new FinderPath(ContactModelImpl.ENTITY_CACHE_ENABLED, ContactModelImpl.FINDER_CACHE_ENABLED, Long.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByAccountId", new String[] { Long.class.getName() }); /** * Returns all the contacts where accountId = ?. * * @param accountId the account ID * @return the matching contacts */ @Override public List<Contact> findByAccountId(long accountId) { return findByAccountId(accountId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null); } /** * Returns a range of all the contacts where accountId = ?. * * <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 ContactModelImpl}. 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 accountId the account ID * @param start the lower bound of the range of contacts * @param end the upper bound of the range of contacts (not inclusive) * @return the range of matching contacts */ @Override public List<Contact> findByAccountId(long accountId, int start, int end) { return findByAccountId(accountId, start, end, null); } /** * Returns an ordered range of all the contacts where accountId = ?. * * <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 ContactModelImpl}. 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 accountId the account ID * @param start the lower bound of the range of contacts * @param end the upper bound of the range of contacts (not inclusive) * @param orderByComparator the comparator to order the results by (optionally <code>null</code>) * @return the ordered range of matching contacts */ @Override public List<Contact> findByAccountId(long accountId, int start, int end, OrderByComparator<Contact> orderByComparator) { return findByAccountId(accountId, start, end, orderByComparator, true); } /** * Returns an ordered range of all the contacts where accountId = ?. * * <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 ContactModelImpl}. 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 accountId the account ID * @param start the lower bound of the range of contacts * @param end the upper bound of the range of contacts (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 contacts */ @Override public List<Contact> findByAccountId(long accountId, int start, int end, OrderByComparator<Contact> 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_ACCOUNTID; finderArgs = new Object[] { accountId }; } else { finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_ACCOUNTID; finderArgs = new Object[] { accountId, start, end, orderByComparator }; } List<Contact> list = null; if (retrieveFromCache) { list = (List<Contact>)finderCache.getResult(finderPath, finderArgs, this); if ((list != null) && !list.isEmpty()) { for (Contact contact : list) { if ((accountId != contact.getAccountId())) { 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_CONTACT_WHERE); query.append(_FINDER_COLUMN_ACCOUNTID_ACCOUNTID_2); if (orderByComparator != null) { appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator); } else if (pagination) { query.append(ContactModelImpl.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(accountId); if (!pagination) { list = (List<Contact>)QueryUtil.list(q, getDialect(), start, end, false); Collections.sort(list); list = Collections.unmodifiableList(list); } else { list = (List<Contact>)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 contact in the ordered set where accountId = ?. * * @param accountId the account ID * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the first matching contact * @throws NoSuchContactException if a matching contact could not be found */ @Override public Contact findByAccountId_First(long accountId, OrderByComparator<Contact> orderByComparator) throws NoSuchContactException { Contact contact = fetchByAccountId_First(accountId, orderByComparator); if (contact != null) { return contact; } StringBundler msg = new StringBundler(4); msg.append(_NO_SUCH_ENTITY_WITH_KEY); msg.append("accountId="); msg.append(accountId); msg.append(StringPool.CLOSE_CURLY_BRACE); throw new NoSuchContactException(msg.toString()); } /** * Returns the first contact in the ordered set where accountId = ?. * * @param accountId the account ID * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the first matching contact, or <code>null</code> if a matching contact could not be found */ @Override public Contact fetchByAccountId_First(long accountId, OrderByComparator<Contact> orderByComparator) { List<Contact> list = findByAccountId(accountId, 0, 1, orderByComparator); if (!list.isEmpty()) { return list.get(0); } return null; } /** * Returns the last contact in the ordered set where accountId = ?. * * @param accountId the account ID * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the last matching contact * @throws NoSuchContactException if a matching contact could not be found */ @Override public Contact findByAccountId_Last(long accountId, OrderByComparator<Contact> orderByComparator) throws NoSuchContactException { Contact contact = fetchByAccountId_Last(accountId, orderByComparator); if (contact != null) { return contact; } StringBundler msg = new StringBundler(4); msg.append(_NO_SUCH_ENTITY_WITH_KEY); msg.append("accountId="); msg.append(accountId); msg.append(StringPool.CLOSE_CURLY_BRACE); throw new NoSuchContactException(msg.toString()); } /** * Returns the last contact in the ordered set where accountId = ?. * * @param accountId the account ID * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the last matching contact, or <code>null</code> if a matching contact could not be found */ @Override public Contact fetchByAccountId_Last(long accountId, OrderByComparator<Contact> orderByComparator) { int count = countByAccountId(accountId); if (count == 0) { return null; } List<Contact> list = findByAccountId(accountId, count - 1, count, orderByComparator); if (!list.isEmpty()) { return list.get(0); } return null; } /** * Returns the contacts before and after the current contact in the ordered set where accountId = ?. * * @param contactId the primary key of the current contact * @param accountId the account ID * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the previous, current, and next contact * @throws NoSuchContactException if a contact with the primary key could not be found */ @Override public Contact[] findByAccountId_PrevAndNext(long contactId, long accountId, OrderByComparator<Contact> orderByComparator) throws NoSuchContactException { Contact contact = findByPrimaryKey(contactId); Session session = null; try { session = openSession(); Contact[] array = new ContactImpl[3]; array[0] = getByAccountId_PrevAndNext(session, contact, accountId, orderByComparator, true); array[1] = contact; array[2] = getByAccountId_PrevAndNext(session, contact, accountId, orderByComparator, false); return array; } catch (Exception e) { throw processException(e); } finally { closeSession(session); } } protected Contact getByAccountId_PrevAndNext(Session session, Contact contact, long accountId, OrderByComparator<Contact> 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_CONTACT_WHERE); query.append(_FINDER_COLUMN_ACCOUNTID_ACCOUNTID_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(ContactModelImpl.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(accountId); if (orderByComparator != null) { Object[] values = orderByComparator.getOrderByConditionValues(contact); for (Object value : values) { qPos.add(value); } } List<Contact> list = q.list(); if (list.size() == 2) { return list.get(1); } else { return null; } } /** * Removes all the contacts where accountId = ? from the database. * * @param accountId the account ID */ @Override public void removeByAccountId(long accountId) { for (Contact contact : findByAccountId(accountId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) { remove(contact); } } /** * Returns the number of contacts where accountId = ?. * * @param accountId the account ID * @return the number of matching contacts */ @Override public int countByAccountId(long accountId) { FinderPath finderPath = FINDER_PATH_COUNT_BY_ACCOUNTID; Object[] finderArgs = new Object[] { accountId }; Long count = (Long)finderCache.getResult(finderPath, finderArgs, this); if (count == null) { StringBundler query = new StringBundler(2); query.append(_SQL_COUNT_CONTACT_WHERE); query.append(_FINDER_COLUMN_ACCOUNTID_ACCOUNTID_2); String sql = query.toString(); Session session = null; try { session = openSession(); Query q = session.createQuery(sql); QueryPos qPos = QueryPos.getInstance(q); qPos.add(accountId); 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_ACCOUNTID_ACCOUNTID_2 = "contact.accountId = ?"; public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C = new FinderPath(ContactModelImpl.ENTITY_CACHE_ENABLED, ContactModelImpl.FINDER_CACHE_ENABLED, ContactImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_C", new String[] { Long.class.getName(), Long.class.getName(), Integer.class.getName(), Integer.class.getName(), OrderByComparator.class.getName() }); public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C = new FinderPath(ContactModelImpl.ENTITY_CACHE_ENABLED, ContactModelImpl.FINDER_CACHE_ENABLED, ContactImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_C", new String[] { Long.class.getName(), Long.class.getName() }, ContactModelImpl.CLASSNAMEID_COLUMN_BITMASK | ContactModelImpl.CLASSPK_COLUMN_BITMASK); public static final FinderPath FINDER_PATH_COUNT_BY_C_C = new FinderPath(ContactModelImpl.ENTITY_CACHE_ENABLED, ContactModelImpl.FINDER_CACHE_ENABLED, Long.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C", new String[] { Long.class.getName(), Long.class.getName() }); /** * Returns all the contacts where classNameId = ? and classPK = ?. * * @param classNameId the class name ID * @param classPK the class pk * @return the matching contacts */ @Override public List<Contact> findByC_C(long classNameId, long classPK) { return findByC_C(classNameId, classPK, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null); } /** * Returns a range of all the contacts where classNameId = ? and classPK = ?. * * <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 ContactModelImpl}. 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 classNameId the class name ID * @param classPK the class pk * @param start the lower bound of the range of contacts * @param end the upper bound of the range of contacts (not inclusive) * @return the range of matching contacts */ @Override public List<Contact> findByC_C(long classNameId, long classPK, int start, int end) { return findByC_C(classNameId, classPK, start, end, null); } /** * Returns an ordered range of all the contacts where classNameId = ? and classPK = ?. * * <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 ContactModelImpl}. 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 classNameId the class name ID * @param classPK the class pk * @param start the lower bound of the range of contacts * @param end the upper bound of the range of contacts (not inclusive) * @param orderByComparator the comparator to order the results by (optionally <code>null</code>) * @return the ordered range of matching contacts */ @Override public List<Contact> findByC_C(long classNameId, long classPK, int start, int end, OrderByComparator<Contact> orderByComparator) { return findByC_C(classNameId, classPK, start, end, orderByComparator, true); } /** * Returns an ordered range of all the contacts where classNameId = ? and classPK = ?. * * <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 ContactModelImpl}. 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 classNameId the class name ID * @param classPK the class pk * @param start the lower bound of the range of contacts * @param end the upper bound of the range of contacts (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 contacts */ @Override public List<Contact> findByC_C(long classNameId, long classPK, int start, int end, OrderByComparator<Contact> orderByComparator, boolean retrieveFromCache) { boolean pagination = true; FinderPath finderPath = null; Object[] finderArgs = null; if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) && (orderByComparator == null)) { pagination = false; finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C; finderArgs = new Object[] { classNameId, classPK }; } else { finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C; finderArgs = new Object[] { classNameId, classPK, start, end, orderByComparator }; } List<Contact> list = null; if (retrieveFromCache) { list = (List<Contact>)finderCache.getResult(finderPath, finderArgs, this); if ((list != null) && !list.isEmpty()) { for (Contact contact : list) { if ((classNameId != contact.getClassNameId()) || (classPK != contact.getClassPK())) { 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_CONTACT_WHERE); query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2); query.append(_FINDER_COLUMN_C_C_CLASSPK_2); if (orderByComparator != null) { appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator); } else if (pagination) { query.append(ContactModelImpl.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(classNameId); qPos.add(classPK); if (!pagination) { list = (List<Contact>)QueryUtil.list(q, getDialect(), start, end, false); Collections.sort(list); list = Collections.unmodifiableList(list); } else { list = (List<Contact>)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 contact in the ordered set where classNameId = ? and classPK = ?. * * @param classNameId the class name ID * @param classPK the class pk * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the first matching contact * @throws NoSuchContactException if a matching contact could not be found */ @Override public Contact findByC_C_First(long classNameId, long classPK, OrderByComparator<Contact> orderByComparator) throws NoSuchContactException { Contact contact = fetchByC_C_First(classNameId, classPK, orderByComparator); if (contact != null) { return contact; } StringBundler msg = new StringBundler(6); msg.append(_NO_SUCH_ENTITY_WITH_KEY); msg.append("classNameId="); msg.append(classNameId); msg.append(", classPK="); msg.append(classPK); msg.append(StringPool.CLOSE_CURLY_BRACE); throw new NoSuchContactException(msg.toString()); } /** * Returns the first contact in the ordered set where classNameId = ? and classPK = ?. * * @param classNameId the class name ID * @param classPK the class pk * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the first matching contact, or <code>null</code> if a matching contact could not be found */ @Override public Contact fetchByC_C_First(long classNameId, long classPK, OrderByComparator<Contact> orderByComparator) { List<Contact> list = findByC_C(classNameId, classPK, 0, 1, orderByComparator); if (!list.isEmpty()) { return list.get(0); } return null; } /** * Returns the last contact in the ordered set where classNameId = ? and classPK = ?. * * @param classNameId the class name ID * @param classPK the class pk * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the last matching contact * @throws NoSuchContactException if a matching contact could not be found */ @Override public Contact findByC_C_Last(long classNameId, long classPK, OrderByComparator<Contact> orderByComparator) throws NoSuchContactException { Contact contact = fetchByC_C_Last(classNameId, classPK, orderByComparator); if (contact != null) { return contact; } StringBundler msg = new StringBundler(6); msg.append(_NO_SUCH_ENTITY_WITH_KEY); msg.append("classNameId="); msg.append(classNameId); msg.append(", classPK="); msg.append(classPK); msg.append(StringPool.CLOSE_CURLY_BRACE); throw new NoSuchContactException(msg.toString()); } /** * Returns the last contact in the ordered set where classNameId = ? and classPK = ?. * * @param classNameId the class name ID * @param classPK the class pk * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the last matching contact, or <code>null</code> if a matching contact could not be found */ @Override public Contact fetchByC_C_Last(long classNameId, long classPK, OrderByComparator<Contact> orderByComparator) { int count = countByC_C(classNameId, classPK); if (count == 0) { return null; } List<Contact> list = findByC_C(classNameId, classPK, count - 1, count, orderByComparator); if (!list.isEmpty()) { return list.get(0); } return null; } /** * Returns the contacts before and after the current contact in the ordered set where classNameId = ? and classPK = ?. * * @param contactId the primary key of the current contact * @param classNameId the class name ID * @param classPK the class pk * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the previous, current, and next contact * @throws NoSuchContactException if a contact with the primary key could not be found */ @Override public Contact[] findByC_C_PrevAndNext(long contactId, long classNameId, long classPK, OrderByComparator<Contact> orderByComparator) throws NoSuchContactException { Contact contact = findByPrimaryKey(contactId); Session session = null; try { session = openSession(); Contact[] array = new ContactImpl[3]; array[0] = getByC_C_PrevAndNext(session, contact, classNameId, classPK, orderByComparator, true); array[1] = contact; array[2] = getByC_C_PrevAndNext(session, contact, classNameId, classPK, orderByComparator, false); return array; } catch (Exception e) { throw processException(e); } finally { closeSession(session); } } protected Contact getByC_C_PrevAndNext(Session session, Contact contact, long classNameId, long classPK, OrderByComparator<Contact> 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_CONTACT_WHERE); query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2); query.append(_FINDER_COLUMN_C_C_CLASSPK_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(ContactModelImpl.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(classNameId); qPos.add(classPK); if (orderByComparator != null) { Object[] values = orderByComparator.getOrderByConditionValues(contact); for (Object value : values) { qPos.add(value); } } List<Contact> list = q.list(); if (list.size() == 2) { return list.get(1); } else { return null; } } /** * Removes all the contacts where classNameId = ? and classPK = ? from the database. * * @param classNameId the class name ID * @param classPK the class pk */ @Override public void removeByC_C(long classNameId, long classPK) { for (Contact contact : findByC_C(classNameId, classPK, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) { remove(contact); } } /** * Returns the number of contacts where classNameId = ? and classPK = ?. * * @param classNameId the class name ID * @param classPK the class pk * @return the number of matching contacts */ @Override public int countByC_C(long classNameId, long classPK) { FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C; Object[] finderArgs = new Object[] { classNameId, classPK }; Long count = (Long)finderCache.getResult(finderPath, finderArgs, this); if (count == null) { StringBundler query = new StringBundler(3); query.append(_SQL_COUNT_CONTACT_WHERE); query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2); query.append(_FINDER_COLUMN_C_C_CLASSPK_2); String sql = query.toString(); Session session = null; try { session = openSession(); Query q = session.createQuery(sql); QueryPos qPos = QueryPos.getInstance(q); qPos.add(classNameId); qPos.add(classPK); count = (Long)q.uniqueResult(); finderCache.putResult(finderPath, finderArgs, count); } catch (Exception e) { finderCache.removeResult(finderPath, finderArgs); throw processException(e); } finally { closeSession(session); } } return count.intValue(); } private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "contact.classNameId = ? AND "; private static final String _FINDER_COLUMN_C_C_CLASSPK_2 = "contact.classPK = ?"; public ContactPersistenceImpl() { setModelClass(Contact.class); } /** * Caches the contact in the entity cache if it is enabled. * * @param contact the contact */ @Override public void cacheResult(Contact contact) { entityCache.putResult(ContactModelImpl.ENTITY_CACHE_ENABLED, ContactImpl.class, contact.getPrimaryKey(), contact); contact.resetOriginalValues(); } /** * Caches the contacts in the entity cache if it is enabled. * * @param contacts the contacts */ @Override public void cacheResult(List<Contact> contacts) { for (Contact contact : contacts) { if (entityCache.getResult(ContactModelImpl.ENTITY_CACHE_ENABLED, ContactImpl.class, contact.getPrimaryKey()) == null) { cacheResult(contact); } else { contact.resetOriginalValues(); } } } /** * Clears the cache for all contacts. * * <p> * The {@link EntityCache} and {@link FinderCache} are both cleared by this method. * </p> */ @Override public void clearCache() { entityCache.clearCache(ContactImpl.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 contact. * * <p> * The {@link EntityCache} and {@link FinderCache} are both cleared by this method. * </p> */ @Override public void clearCache(Contact contact) { entityCache.removeResult(ContactModelImpl.ENTITY_CACHE_ENABLED, ContactImpl.class, contact.getPrimaryKey()); finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION); finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION); } @Override public void clearCache(List<Contact> contacts) { finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION); finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION); for (Contact contact : contacts) { entityCache.removeResult(ContactModelImpl.ENTITY_CACHE_ENABLED, ContactImpl.class, contact.getPrimaryKey()); } } /** * Creates a new contact with the primary key. Does not add the contact to the database. * * @param contactId the primary key for the new contact * @return the new contact */ @Override public Contact create(long contactId) { Contact contact = new ContactImpl(); contact.setNew(true); contact.setPrimaryKey(contactId); contact.setCompanyId(companyProvider.getCompanyId()); return contact; } /** * Removes the contact with the primary key from the database. Also notifies the appropriate model listeners. * * @param contactId the primary key of the contact * @return the contact that was removed * @throws NoSuchContactException if a contact with the primary key could not be found */ @Override public Contact remove(long contactId) throws NoSuchContactException { return remove((Serializable)contactId); } /** * Removes the contact with the primary key from the database. Also notifies the appropriate model listeners. * * @param primaryKey the primary key of the contact * @return the contact that was removed * @throws NoSuchContactException if a contact with the primary key could not be found */ @Override public Contact remove(Serializable primaryKey) throws NoSuchContactException { Session session = null; try { session = openSession(); Contact contact = (Contact)session.get(ContactImpl.class, primaryKey); if (contact == null) { if (_log.isDebugEnabled()) { _log.debug(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey); } throw new NoSuchContactException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey); } return remove(contact); } catch (NoSuchContactException nsee) { throw nsee; } catch (Exception e) { throw processException(e); } finally { closeSession(session); } } @Override protected Contact removeImpl(Contact contact) { contact = toUnwrappedModel(contact); Session session = null; try { session = openSession(); if (!session.contains(contact)) { contact = (Contact)session.get(ContactImpl.class, contact.getPrimaryKeyObj()); } if (contact != null) { session.delete(contact); } } catch (Exception e) { throw processException(e); } finally { closeSession(session); } if (contact != null) { clearCache(contact); } return contact; } @Override public Contact updateImpl(Contact contact) { contact = toUnwrappedModel(contact); boolean isNew = contact.isNew(); ContactModelImpl contactModelImpl = (ContactModelImpl)contact; ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext(); Date now = new Date(); if (isNew && (contact.getCreateDate() == null)) { if (serviceContext == null) { contact.setCreateDate(now); } else { contact.setCreateDate(serviceContext.getCreateDate(now)); } } if (!contactModelImpl.hasSetModifiedDate()) { if (serviceContext == null) { contact.setModifiedDate(now); } else { contact.setModifiedDate(serviceContext.getModifiedDate(now)); } } Session session = null; try { session = openSession(); if (contact.isNew()) { session.save(contact); contact.setNew(false); } else { contact = (Contact)session.merge(contact); } } catch (Exception e) { throw processException(e); } finally { closeSession(session); } finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION); if (!ContactModelImpl.COLUMN_BITMASK_ENABLED) { finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION); } else if (isNew) { Object[] args = new Object[] { contactModelImpl.getCompanyId() }; finderCache.removeResult(FINDER_PATH_COUNT_BY_COMPANYID, args); finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID, args); args = new Object[] { contactModelImpl.getAccountId() }; finderCache.removeResult(FINDER_PATH_COUNT_BY_ACCOUNTID, args); finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ACCOUNTID, args); args = new Object[] { contactModelImpl.getClassNameId(), contactModelImpl.getClassPK() }; finderCache.removeResult(FINDER_PATH_COUNT_BY_C_C, args); finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C, args); finderCache.removeResult(FINDER_PATH_COUNT_ALL, FINDER_ARGS_EMPTY); finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL, FINDER_ARGS_EMPTY); } else { if ((contactModelImpl.getColumnBitmask() & FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) { Object[] args = new Object[] { contactModelImpl.getOriginalCompanyId() }; finderCache.removeResult(FINDER_PATH_COUNT_BY_COMPANYID, args); finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID, args); args = new Object[] { contactModelImpl.getCompanyId() }; finderCache.removeResult(FINDER_PATH_COUNT_BY_COMPANYID, args); finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID, args); } if ((contactModelImpl.getColumnBitmask() & FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ACCOUNTID.getColumnBitmask()) != 0) { Object[] args = new Object[] { contactModelImpl.getOriginalAccountId() }; finderCache.removeResult(FINDER_PATH_COUNT_BY_ACCOUNTID, args); finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ACCOUNTID, args); args = new Object[] { contactModelImpl.getAccountId() }; finderCache.removeResult(FINDER_PATH_COUNT_BY_ACCOUNTID, args); finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ACCOUNTID, args); } if ((contactModelImpl.getColumnBitmask() & FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C.getColumnBitmask()) != 0) { Object[] args = new Object[] { contactModelImpl.getOriginalClassNameId(), contactModelImpl.getOriginalClassPK() }; finderCache.removeResult(FINDER_PATH_COUNT_BY_C_C, args); finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C, args); args = new Object[] { contactModelImpl.getClassNameId(), contactModelImpl.getClassPK() }; finderCache.removeResult(FINDER_PATH_COUNT_BY_C_C, args); finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C, args); } } entityCache.putResult(ContactModelImpl.ENTITY_CACHE_ENABLED, ContactImpl.class, contact.getPrimaryKey(), contact, false); contact.resetOriginalValues(); return contact; } protected Contact toUnwrappedModel(Contact contact) { if (contact instanceof ContactImpl) { return contact; } ContactImpl contactImpl = new ContactImpl(); contactImpl.setNew(contact.isNew()); contactImpl.setPrimaryKey(contact.getPrimaryKey()); contactImpl.setMvccVersion(contact.getMvccVersion()); contactImpl.setContactId(contact.getContactId()); contactImpl.setCompanyId(contact.getCompanyId()); contactImpl.setUserId(contact.getUserId()); contactImpl.setUserName(contact.getUserName()); contactImpl.setCreateDate(contact.getCreateDate()); contactImpl.setModifiedDate(contact.getModifiedDate()); contactImpl.setClassNameId(contact.getClassNameId()); contactImpl.setClassPK(contact.getClassPK()); contactImpl.setAccountId(contact.getAccountId()); contactImpl.setParentContactId(contact.getParentContactId()); contactImpl.setEmailAddress(contact.getEmailAddress()); contactImpl.setFirstName(contact.getFirstName()); contactImpl.setMiddleName(contact.getMiddleName()); contactImpl.setLastName(contact.getLastName()); contactImpl.setPrefixId(contact.getPrefixId()); contactImpl.setSuffixId(contact.getSuffixId()); contactImpl.setMale(contact.isMale()); contactImpl.setBirthday(contact.getBirthday()); contactImpl.setSmsSn(contact.getSmsSn()); contactImpl.setFacebookSn(contact.getFacebookSn()); contactImpl.setJabberSn(contact.getJabberSn()); contactImpl.setSkypeSn(contact.getSkypeSn()); contactImpl.setTwitterSn(contact.getTwitterSn()); contactImpl.setEmployeeStatusId(contact.getEmployeeStatusId()); contactImpl.setEmployeeNumber(contact.getEmployeeNumber()); contactImpl.setJobTitle(contact.getJobTitle()); contactImpl.setJobClass(contact.getJobClass()); contactImpl.setHoursOfOperation(contact.getHoursOfOperation()); return contactImpl; } /** * Returns the contact 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 contact * @return the contact * @throws NoSuchContactException if a contact with the primary key could not be found */ @Override public Contact findByPrimaryKey(Serializable primaryKey) throws NoSuchContactException { Contact contact = fetchByPrimaryKey(primaryKey); if (contact == null) { if (_log.isDebugEnabled()) { _log.debug(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey); } throw new NoSuchContactException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey); } return contact; } /** * Returns the contact with the primary key or throws a {@link NoSuchContactException} if it could not be found. * * @param contactId the primary key of the contact * @return the contact * @throws NoSuchContactException if a contact with the primary key could not be found */ @Override public Contact findByPrimaryKey(long contactId) throws NoSuchContactException { return findByPrimaryKey((Serializable)contactId); } /** * Returns the contact with the primary key or returns <code>null</code> if it could not be found. * * @param primaryKey the primary key of the contact * @return the contact, or <code>null</code> if a contact with the primary key could not be found */ @Override public Contact fetchByPrimaryKey(Serializable primaryKey) { Serializable serializable = entityCache.getResult(ContactModelImpl.ENTITY_CACHE_ENABLED, ContactImpl.class, primaryKey); if (serializable == nullModel) { return null; } Contact contact = (Contact)serializable; if (contact == null) { Session session = null; try { session = openSession(); contact = (Contact)session.get(ContactImpl.class, primaryKey); if (contact != null) { cacheResult(contact); } else { entityCache.putResult(ContactModelImpl.ENTITY_CACHE_ENABLED, ContactImpl.class, primaryKey, nullModel); } } catch (Exception e) { entityCache.removeResult(ContactModelImpl.ENTITY_CACHE_ENABLED, ContactImpl.class, primaryKey); throw processException(e); } finally { closeSession(session); } } return contact; } /** * Returns the contact with the primary key or returns <code>null</code> if it could not be found. * * @param contactId the primary key of the contact * @return the contact, or <code>null</code> if a contact with the primary key could not be found */ @Override public Contact fetchByPrimaryKey(long contactId) { return fetchByPrimaryKey((Serializable)contactId); } @Override public Map<Serializable, Contact> fetchByPrimaryKeys( Set<Serializable> primaryKeys) { if (primaryKeys.isEmpty()) { return Collections.emptyMap(); } Map<Serializable, Contact> map = new HashMap<Serializable, Contact>(); if (primaryKeys.size() == 1) { Iterator<Serializable> iterator = primaryKeys.iterator(); Serializable primaryKey = iterator.next(); Contact contact = fetchByPrimaryKey(primaryKey); if (contact != null) { map.put(primaryKey, contact); } return map; } Set<Serializable> uncachedPrimaryKeys = null; for (Serializable primaryKey : primaryKeys) { Serializable serializable = entityCache.getResult(ContactModelImpl.ENTITY_CACHE_ENABLED, ContactImpl.class, primaryKey); if (serializable != nullModel) { if (serializable == null) { if (uncachedPrimaryKeys == null) { uncachedPrimaryKeys = new HashSet<Serializable>(); } uncachedPrimaryKeys.add(primaryKey); } else { map.put(primaryKey, (Contact)serializable); } } } if (uncachedPrimaryKeys == null) { return map; } StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) + 1); query.append(_SQL_SELECT_CONTACT_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 (Contact contact : (List<Contact>)q.list()) { map.put(contact.getPrimaryKeyObj(), contact); cacheResult(contact); uncachedPrimaryKeys.remove(contact.getPrimaryKeyObj()); } for (Serializable primaryKey : uncachedPrimaryKeys) { entityCache.putResult(ContactModelImpl.ENTITY_CACHE_ENABLED, ContactImpl.class, primaryKey, nullModel); } } catch (Exception e) { throw processException(e); } finally { closeSession(session); } return map; } /** * Returns all the contacts. * * @return the contacts */ @Override public List<Contact> findAll() { return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null); } /** * Returns a range of all the contacts. * * <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 ContactModelImpl}. 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 contacts * @param end the upper bound of the range of contacts (not inclusive) * @return the range of contacts */ @Override public List<Contact> findAll(int start, int end) { return findAll(start, end, null); } /** * Returns an ordered range of all the contacts. * * <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 ContactModelImpl}. 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 contacts * @param end the upper bound of the range of contacts (not inclusive) * @param orderByComparator the comparator to order the results by (optionally <code>null</code>) * @return the ordered range of contacts */ @Override public List<Contact> findAll(int start, int end, OrderByComparator<Contact> orderByComparator) { return findAll(start, end, orderByComparator, true); } /** * Returns an ordered range of all the contacts. * * <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 ContactModelImpl}. 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 contacts * @param end the upper bound of the range of contacts (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 contacts */ @Override public List<Contact> findAll(int start, int end, OrderByComparator<Contact> 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<Contact> list = null; if (retrieveFromCache) { list = (List<Contact>)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_CONTACT); appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator); sql = query.toString(); } else { sql = _SQL_SELECT_CONTACT; if (pagination) { sql = sql.concat(ContactModelImpl.ORDER_BY_JPQL); } } Session session = null; try { session = openSession(); Query q = session.createQuery(sql); if (!pagination) { list = (List<Contact>)QueryUtil.list(q, getDialect(), start, end, false); Collections.sort(list); list = Collections.unmodifiableList(list); } else { list = (List<Contact>)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 contacts from the database. * */ @Override public void removeAll() { for (Contact contact : findAll()) { remove(contact); } } /** * Returns the number of contacts. * * @return the number of contacts */ @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_CONTACT); 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 ContactModelImpl.TABLE_COLUMNS_MAP; } /** * Initializes the contact persistence. */ public void afterPropertiesSet() { } public void destroy() { entityCache.removeCache(ContactImpl.class.getName()); finderCache.removeCache(FINDER_CLASS_NAME_ENTITY); finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION); finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION); } @BeanReference(type = CompanyProviderWrapper.class) protected CompanyProvider companyProvider; protected EntityCache entityCache = EntityCacheUtil.getEntityCache(); protected FinderCache finderCache = FinderCacheUtil.getFinderCache(); private static final String _SQL_SELECT_CONTACT = "SELECT contact FROM Contact contact"; private static final String _SQL_SELECT_CONTACT_WHERE_PKS_IN = "SELECT contact FROM Contact contact WHERE contactId IN ("; private static final String _SQL_SELECT_CONTACT_WHERE = "SELECT contact FROM Contact contact WHERE "; private static final String _SQL_COUNT_CONTACT = "SELECT COUNT(contact) FROM Contact contact"; private static final String _SQL_COUNT_CONTACT_WHERE = "SELECT COUNT(contact) FROM Contact contact WHERE "; private static final String _ORDER_BY_ENTITY_ALIAS = "contact."; private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Contact exists with the primary key "; private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Contact exists with the key {"; private static final Log _log = LogFactoryUtil.getLog(ContactPersistenceImpl.class); }