All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.liferay.portal.service.persistence.impl.ResourceActionPersistenceImpl Maven / Gradle / Ivy

There is a newer version: 7.4.3.112-ga112
Show newest version
/**
 * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package com.liferay.portal.service.persistence.impl;

import aQute.bnd.annotation.ProviderType;

import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
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.NoSuchResourceActionException;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.model.ResourceAction;
import com.liferay.portal.kernel.service.persistence.ResourceActionPersistence;
import com.liferay.portal.kernel.service.persistence.impl.BasePersistenceImpl;
import com.liferay.portal.kernel.util.OrderByComparator;
import com.liferay.portal.kernel.util.ProxyUtil;
import com.liferay.portal.kernel.util.StringBundler;
import com.liferay.portal.model.impl.ResourceActionImpl;
import com.liferay.portal.model.impl.ResourceActionModelImpl;

import java.io.Serializable;

import java.lang.reflect.InvocationHandler;

import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;

/**
 * The persistence implementation for the resource action service.
 *
 * 

* Caching information and settings can be found in portal.properties *

* * @author Brian Wing Shun Chan * @generated */ @ProviderType public class ResourceActionPersistenceImpl extends BasePersistenceImpl implements ResourceActionPersistence { /* * NOTE FOR DEVELOPERS: * * Never modify or reference this class directly. Always use ResourceActionUtil to access the resource action persistence. Modify service.xml and rerun ServiceBuilder to regenerate this class. */ public static final String FINDER_CLASS_NAME_ENTITY = ResourceActionImpl.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"; private FinderPath _finderPathWithPaginationFindAll; private FinderPath _finderPathWithoutPaginationFindAll; private FinderPath _finderPathCountAll; private FinderPath _finderPathWithPaginationFindByName; private FinderPath _finderPathWithoutPaginationFindByName; private FinderPath _finderPathCountByName; /** * Returns all the resource actions where name = ?. * * @param name the name * @return the matching resource actions */ @Override public List findByName(String name) { return findByName(name, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null); } /** * Returns a range of all the resource actions where name = ?. * *

* Useful when paginating results. Returns a maximum of end - start instances. start and end are not primary keys, they are indexes in the result set. Thus, 0 refers to the first result in the set. Setting both start and end to QueryUtil#ALL_POS will return the full result set. If orderByComparator is specified, then the query will include the given ORDER BY logic. If orderByComparator is absent and pagination is required (start and end are not QueryUtil#ALL_POS), then the query will include the default ORDER BY logic from ResourceActionModelImpl. If both orderByComparator 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. *

* * @param name the name * @param start the lower bound of the range of resource actions * @param end the upper bound of the range of resource actions (not inclusive) * @return the range of matching resource actions */ @Override public List findByName(String name, int start, int end) { return findByName(name, start, end, null); } /** * Returns an ordered range of all the resource actions where name = ?. * *

* Useful when paginating results. Returns a maximum of end - start instances. start and end are not primary keys, they are indexes in the result set. Thus, 0 refers to the first result in the set. Setting both start and end to QueryUtil#ALL_POS will return the full result set. If orderByComparator is specified, then the query will include the given ORDER BY logic. If orderByComparator is absent and pagination is required (start and end are not QueryUtil#ALL_POS), then the query will include the default ORDER BY logic from ResourceActionModelImpl. If both orderByComparator 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. *

* * @param name the name * @param start the lower bound of the range of resource actions * @param end the upper bound of the range of resource actions (not inclusive) * @param orderByComparator the comparator to order the results by (optionally null) * @return the ordered range of matching resource actions */ @Override public List findByName( String name, int start, int end, OrderByComparator orderByComparator) { return findByName(name, start, end, orderByComparator, true); } /** * Returns an ordered range of all the resource actions where name = ?. * *

* Useful when paginating results. Returns a maximum of end - start instances. start and end are not primary keys, they are indexes in the result set. Thus, 0 refers to the first result in the set. Setting both start and end to QueryUtil#ALL_POS will return the full result set. If orderByComparator is specified, then the query will include the given ORDER BY logic. If orderByComparator is absent and pagination is required (start and end are not QueryUtil#ALL_POS), then the query will include the default ORDER BY logic from ResourceActionModelImpl. If both orderByComparator 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. *

* * @param name the name * @param start the lower bound of the range of resource actions * @param end the upper bound of the range of resource actions (not inclusive) * @param orderByComparator the comparator to order the results by (optionally null) * @param retrieveFromCache whether to retrieve from the finder cache * @return the ordered range of matching resource actions */ @Override public List findByName( String name, int start, int end, OrderByComparator orderByComparator, boolean retrieveFromCache) { name = Objects.toString(name, ""); boolean pagination = true; FinderPath finderPath = null; Object[] finderArgs = null; if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) && (orderByComparator == null)) { pagination = false; finderPath = _finderPathWithoutPaginationFindByName; finderArgs = new Object[] {name}; } else { finderPath = _finderPathWithPaginationFindByName; finderArgs = new Object[] {name, start, end, orderByComparator}; } List list = null; if (retrieveFromCache) { list = (List)FinderCacheUtil.getResult( finderPath, finderArgs, this); if ((list != null) && !list.isEmpty()) { for (ResourceAction resourceAction : list) { if (!name.equals(resourceAction.getName())) { list = null; break; } } } } if (list == null) { StringBundler query = null; if (orderByComparator != null) { query = new StringBundler( 3 + (orderByComparator.getOrderByFields().length * 2)); } else { query = new StringBundler(3); } query.append(_SQL_SELECT_RESOURCEACTION_WHERE); boolean bindName = false; if (name.isEmpty()) { query.append(_FINDER_COLUMN_NAME_NAME_3); } else { bindName = true; query.append(_FINDER_COLUMN_NAME_NAME_2); } if (orderByComparator != null) { appendOrderByComparator( query, _ORDER_BY_ENTITY_ALIAS, orderByComparator); } else if (pagination) { query.append(ResourceActionModelImpl.ORDER_BY_JPQL); } String sql = query.toString(); Session session = null; try { session = openSession(); Query q = session.createQuery(sql); QueryPos qPos = QueryPos.getInstance(q); if (bindName) { qPos.add(name); } if (!pagination) { list = (List)QueryUtil.list( q, getDialect(), start, end, false); Collections.sort(list); list = Collections.unmodifiableList(list); } else { list = (List)QueryUtil.list( q, getDialect(), start, end); } cacheResult(list); FinderCacheUtil.putResult(finderPath, finderArgs, list); } catch (Exception e) { FinderCacheUtil.removeResult(finderPath, finderArgs); throw processException(e); } finally { closeSession(session); } } return list; } /** * Returns the first resource action in the ordered set where name = ?. * * @param name the name * @param orderByComparator the comparator to order the set by (optionally null) * @return the first matching resource action * @throws NoSuchResourceActionException if a matching resource action could not be found */ @Override public ResourceAction findByName_First( String name, OrderByComparator orderByComparator) throws NoSuchResourceActionException { ResourceAction resourceAction = fetchByName_First( name, orderByComparator); if (resourceAction != null) { return resourceAction; } StringBundler msg = new StringBundler(4); msg.append(_NO_SUCH_ENTITY_WITH_KEY); msg.append("name="); msg.append(name); msg.append("}"); throw new NoSuchResourceActionException(msg.toString()); } /** * Returns the first resource action in the ordered set where name = ?. * * @param name the name * @param orderByComparator the comparator to order the set by (optionally null) * @return the first matching resource action, or null if a matching resource action could not be found */ @Override public ResourceAction fetchByName_First( String name, OrderByComparator orderByComparator) { List list = findByName(name, 0, 1, orderByComparator); if (!list.isEmpty()) { return list.get(0); } return null; } /** * Returns the last resource action in the ordered set where name = ?. * * @param name the name * @param orderByComparator the comparator to order the set by (optionally null) * @return the last matching resource action * @throws NoSuchResourceActionException if a matching resource action could not be found */ @Override public ResourceAction findByName_Last( String name, OrderByComparator orderByComparator) throws NoSuchResourceActionException { ResourceAction resourceAction = fetchByName_Last( name, orderByComparator); if (resourceAction != null) { return resourceAction; } StringBundler msg = new StringBundler(4); msg.append(_NO_SUCH_ENTITY_WITH_KEY); msg.append("name="); msg.append(name); msg.append("}"); throw new NoSuchResourceActionException(msg.toString()); } /** * Returns the last resource action in the ordered set where name = ?. * * @param name the name * @param orderByComparator the comparator to order the set by (optionally null) * @return the last matching resource action, or null if a matching resource action could not be found */ @Override public ResourceAction fetchByName_Last( String name, OrderByComparator orderByComparator) { int count = countByName(name); if (count == 0) { return null; } List list = findByName( name, count - 1, count, orderByComparator); if (!list.isEmpty()) { return list.get(0); } return null; } /** * Returns the resource actions before and after the current resource action in the ordered set where name = ?. * * @param resourceActionId the primary key of the current resource action * @param name the name * @param orderByComparator the comparator to order the set by (optionally null) * @return the previous, current, and next resource action * @throws NoSuchResourceActionException if a resource action with the primary key could not be found */ @Override public ResourceAction[] findByName_PrevAndNext( long resourceActionId, String name, OrderByComparator orderByComparator) throws NoSuchResourceActionException { name = Objects.toString(name, ""); ResourceAction resourceAction = findByPrimaryKey(resourceActionId); Session session = null; try { session = openSession(); ResourceAction[] array = new ResourceActionImpl[3]; array[0] = getByName_PrevAndNext( session, resourceAction, name, orderByComparator, true); array[1] = resourceAction; array[2] = getByName_PrevAndNext( session, resourceAction, name, orderByComparator, false); return array; } catch (Exception e) { throw processException(e); } finally { closeSession(session); } } protected ResourceAction getByName_PrevAndNext( Session session, ResourceAction resourceAction, String name, OrderByComparator 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_RESOURCEACTION_WHERE); boolean bindName = false; if (name.isEmpty()) { query.append(_FINDER_COLUMN_NAME_NAME_3); } else { bindName = true; query.append(_FINDER_COLUMN_NAME_NAME_2); } if (orderByComparator != null) { String[] orderByConditionFields = orderByComparator.getOrderByConditionFields(); if (orderByConditionFields.length > 0) { query.append(WHERE_AND); } for (int i = 0; i < orderByConditionFields.length; i++) { query.append(_ORDER_BY_ENTITY_ALIAS); query.append(orderByConditionFields[i]); if ((i + 1) < orderByConditionFields.length) { if (orderByComparator.isAscending() ^ previous) { query.append(WHERE_GREATER_THAN_HAS_NEXT); } else { query.append(WHERE_LESSER_THAN_HAS_NEXT); } } else { if (orderByComparator.isAscending() ^ previous) { query.append(WHERE_GREATER_THAN); } else { query.append(WHERE_LESSER_THAN); } } } query.append(ORDER_BY_CLAUSE); String[] orderByFields = orderByComparator.getOrderByFields(); for (int i = 0; i < orderByFields.length; i++) { query.append(_ORDER_BY_ENTITY_ALIAS); query.append(orderByFields[i]); if ((i + 1) < orderByFields.length) { if (orderByComparator.isAscending() ^ previous) { query.append(ORDER_BY_ASC_HAS_NEXT); } else { query.append(ORDER_BY_DESC_HAS_NEXT); } } else { if (orderByComparator.isAscending() ^ previous) { query.append(ORDER_BY_ASC); } else { query.append(ORDER_BY_DESC); } } } } else { query.append(ResourceActionModelImpl.ORDER_BY_JPQL); } String sql = query.toString(); Query q = session.createQuery(sql); q.setFirstResult(0); q.setMaxResults(2); QueryPos qPos = QueryPos.getInstance(q); if (bindName) { qPos.add(name); } if (orderByComparator != null) { for (Object orderByConditionValue : orderByComparator.getOrderByConditionValues( resourceAction)) { qPos.add(orderByConditionValue); } } List list = q.list(); if (list.size() == 2) { return list.get(1); } else { return null; } } /** * Removes all the resource actions where name = ? from the database. * * @param name the name */ @Override public void removeByName(String name) { for (ResourceAction resourceAction : findByName(name, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) { remove(resourceAction); } } /** * Returns the number of resource actions where name = ?. * * @param name the name * @return the number of matching resource actions */ @Override public int countByName(String name) { name = Objects.toString(name, ""); FinderPath finderPath = _finderPathCountByName; Object[] finderArgs = new Object[] {name}; Long count = (Long)FinderCacheUtil.getResult( finderPath, finderArgs, this); if (count == null) { StringBundler query = new StringBundler(2); query.append(_SQL_COUNT_RESOURCEACTION_WHERE); boolean bindName = false; if (name.isEmpty()) { query.append(_FINDER_COLUMN_NAME_NAME_3); } else { bindName = true; query.append(_FINDER_COLUMN_NAME_NAME_2); } String sql = query.toString(); Session session = null; try { session = openSession(); Query q = session.createQuery(sql); QueryPos qPos = QueryPos.getInstance(q); if (bindName) { qPos.add(name); } count = (Long)q.uniqueResult(); FinderCacheUtil.putResult(finderPath, finderArgs, count); } catch (Exception e) { FinderCacheUtil.removeResult(finderPath, finderArgs); throw processException(e); } finally { closeSession(session); } } return count.intValue(); } private static final String _FINDER_COLUMN_NAME_NAME_2 = "resourceAction.name = ?"; private static final String _FINDER_COLUMN_NAME_NAME_3 = "(resourceAction.name IS NULL OR resourceAction.name = '')"; private FinderPath _finderPathFetchByN_A; private FinderPath _finderPathCountByN_A; /** * Returns the resource action where name = ? and actionId = ? or throws a NoSuchResourceActionException if it could not be found. * * @param name the name * @param actionId the action ID * @return the matching resource action * @throws NoSuchResourceActionException if a matching resource action could not be found */ @Override public ResourceAction findByN_A(String name, String actionId) throws NoSuchResourceActionException { ResourceAction resourceAction = fetchByN_A(name, actionId); if (resourceAction == null) { StringBundler msg = new StringBundler(6); msg.append(_NO_SUCH_ENTITY_WITH_KEY); msg.append("name="); msg.append(name); msg.append(", actionId="); msg.append(actionId); msg.append("}"); if (_log.isDebugEnabled()) { _log.debug(msg.toString()); } throw new NoSuchResourceActionException(msg.toString()); } return resourceAction; } /** * Returns the resource action where name = ? and actionId = ? or returns null if it could not be found. Uses the finder cache. * * @param name the name * @param actionId the action ID * @return the matching resource action, or null if a matching resource action could not be found */ @Override public ResourceAction fetchByN_A(String name, String actionId) { return fetchByN_A(name, actionId, true); } /** * Returns the resource action where name = ? and actionId = ? or returns null if it could not be found, optionally using the finder cache. * * @param name the name * @param actionId the action ID * @param retrieveFromCache whether to retrieve from the finder cache * @return the matching resource action, or null if a matching resource action could not be found */ @Override public ResourceAction fetchByN_A( String name, String actionId, boolean retrieveFromCache) { name = Objects.toString(name, ""); actionId = Objects.toString(actionId, ""); Object[] finderArgs = new Object[] {name, actionId}; Object result = null; if (retrieveFromCache) { result = FinderCacheUtil.getResult( _finderPathFetchByN_A, finderArgs, this); } if (result instanceof ResourceAction) { ResourceAction resourceAction = (ResourceAction)result; if (!Objects.equals(name, resourceAction.getName()) || !Objects.equals(actionId, resourceAction.getActionId())) { result = null; } } if (result == null) { StringBundler query = new StringBundler(4); query.append(_SQL_SELECT_RESOURCEACTION_WHERE); boolean bindName = false; if (name.isEmpty()) { query.append(_FINDER_COLUMN_N_A_NAME_3); } else { bindName = true; query.append(_FINDER_COLUMN_N_A_NAME_2); } boolean bindActionId = false; if (actionId.isEmpty()) { query.append(_FINDER_COLUMN_N_A_ACTIONID_3); } else { bindActionId = true; query.append(_FINDER_COLUMN_N_A_ACTIONID_2); } String sql = query.toString(); Session session = null; try { session = openSession(); Query q = session.createQuery(sql); QueryPos qPos = QueryPos.getInstance(q); if (bindName) { qPos.add(name); } if (bindActionId) { qPos.add(actionId); } List list = q.list(); if (list.isEmpty()) { FinderCacheUtil.putResult( _finderPathFetchByN_A, finderArgs, list); } else { ResourceAction resourceAction = list.get(0); result = resourceAction; cacheResult(resourceAction); } } catch (Exception e) { FinderCacheUtil.removeResult(_finderPathFetchByN_A, finderArgs); throw processException(e); } finally { closeSession(session); } } if (result instanceof List) { return null; } else { return (ResourceAction)result; } } /** * Removes the resource action where name = ? and actionId = ? from the database. * * @param name the name * @param actionId the action ID * @return the resource action that was removed */ @Override public ResourceAction removeByN_A(String name, String actionId) throws NoSuchResourceActionException { ResourceAction resourceAction = findByN_A(name, actionId); return remove(resourceAction); } /** * Returns the number of resource actions where name = ? and actionId = ?. * * @param name the name * @param actionId the action ID * @return the number of matching resource actions */ @Override public int countByN_A(String name, String actionId) { name = Objects.toString(name, ""); actionId = Objects.toString(actionId, ""); FinderPath finderPath = _finderPathCountByN_A; Object[] finderArgs = new Object[] {name, actionId}; Long count = (Long)FinderCacheUtil.getResult( finderPath, finderArgs, this); if (count == null) { StringBundler query = new StringBundler(3); query.append(_SQL_COUNT_RESOURCEACTION_WHERE); boolean bindName = false; if (name.isEmpty()) { query.append(_FINDER_COLUMN_N_A_NAME_3); } else { bindName = true; query.append(_FINDER_COLUMN_N_A_NAME_2); } boolean bindActionId = false; if (actionId.isEmpty()) { query.append(_FINDER_COLUMN_N_A_ACTIONID_3); } else { bindActionId = true; query.append(_FINDER_COLUMN_N_A_ACTIONID_2); } String sql = query.toString(); Session session = null; try { session = openSession(); Query q = session.createQuery(sql); QueryPos qPos = QueryPos.getInstance(q); if (bindName) { qPos.add(name); } if (bindActionId) { qPos.add(actionId); } count = (Long)q.uniqueResult(); FinderCacheUtil.putResult(finderPath, finderArgs, count); } catch (Exception e) { FinderCacheUtil.removeResult(finderPath, finderArgs); throw processException(e); } finally { closeSession(session); } } return count.intValue(); } private static final String _FINDER_COLUMN_N_A_NAME_2 = "resourceAction.name = ? AND "; private static final String _FINDER_COLUMN_N_A_NAME_3 = "(resourceAction.name IS NULL OR resourceAction.name = '') AND "; private static final String _FINDER_COLUMN_N_A_ACTIONID_2 = "resourceAction.actionId = ?"; private static final String _FINDER_COLUMN_N_A_ACTIONID_3 = "(resourceAction.actionId IS NULL OR resourceAction.actionId = '')"; public ResourceActionPersistenceImpl() { setModelClass(ResourceAction.class); } /** * Caches the resource action in the entity cache if it is enabled. * * @param resourceAction the resource action */ @Override public void cacheResult(ResourceAction resourceAction) { EntityCacheUtil.putResult( ResourceActionModelImpl.ENTITY_CACHE_ENABLED, ResourceActionImpl.class, resourceAction.getPrimaryKey(), resourceAction); FinderCacheUtil.putResult( _finderPathFetchByN_A, new Object[] { resourceAction.getName(), resourceAction.getActionId() }, resourceAction); resourceAction.resetOriginalValues(); } /** * Caches the resource actions in the entity cache if it is enabled. * * @param resourceActions the resource actions */ @Override public void cacheResult(List resourceActions) { for (ResourceAction resourceAction : resourceActions) { if (EntityCacheUtil.getResult( ResourceActionModelImpl.ENTITY_CACHE_ENABLED, ResourceActionImpl.class, resourceAction.getPrimaryKey()) == null) { cacheResult(resourceAction); } else { resourceAction.resetOriginalValues(); } } } /** * Clears the cache for all resource actions. * *

* The com.liferay.portal.kernel.dao.orm.EntityCache and com.liferay.portal.kernel.dao.orm.FinderCache are both cleared by this method. *

*/ @Override public void clearCache() { EntityCacheUtil.clearCache(ResourceActionImpl.class); FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY); FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION); FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION); } /** * Clears the cache for the resource action. * *

* The com.liferay.portal.kernel.dao.orm.EntityCache and com.liferay.portal.kernel.dao.orm.FinderCache are both cleared by this method. *

*/ @Override public void clearCache(ResourceAction resourceAction) { EntityCacheUtil.removeResult( ResourceActionModelImpl.ENTITY_CACHE_ENABLED, ResourceActionImpl.class, resourceAction.getPrimaryKey()); FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION); FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION); clearUniqueFindersCache((ResourceActionModelImpl)resourceAction, true); } @Override public void clearCache(List resourceActions) { FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION); FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION); for (ResourceAction resourceAction : resourceActions) { EntityCacheUtil.removeResult( ResourceActionModelImpl.ENTITY_CACHE_ENABLED, ResourceActionImpl.class, resourceAction.getPrimaryKey()); clearUniqueFindersCache( (ResourceActionModelImpl)resourceAction, true); } } protected void cacheUniqueFindersCache( ResourceActionModelImpl resourceActionModelImpl) { Object[] args = new Object[] { resourceActionModelImpl.getName(), resourceActionModelImpl.getActionId() }; FinderCacheUtil.putResult( _finderPathCountByN_A, args, Long.valueOf(1), false); FinderCacheUtil.putResult( _finderPathFetchByN_A, args, resourceActionModelImpl, false); } protected void clearUniqueFindersCache( ResourceActionModelImpl resourceActionModelImpl, boolean clearCurrent) { if (clearCurrent) { Object[] args = new Object[] { resourceActionModelImpl.getName(), resourceActionModelImpl.getActionId() }; FinderCacheUtil.removeResult(_finderPathCountByN_A, args); FinderCacheUtil.removeResult(_finderPathFetchByN_A, args); } if ((resourceActionModelImpl.getColumnBitmask() & _finderPathFetchByN_A.getColumnBitmask()) != 0) { Object[] args = new Object[] { resourceActionModelImpl.getOriginalName(), resourceActionModelImpl.getOriginalActionId() }; FinderCacheUtil.removeResult(_finderPathCountByN_A, args); FinderCacheUtil.removeResult(_finderPathFetchByN_A, args); } } /** * Creates a new resource action with the primary key. Does not add the resource action to the database. * * @param resourceActionId the primary key for the new resource action * @return the new resource action */ @Override public ResourceAction create(long resourceActionId) { ResourceAction resourceAction = new ResourceActionImpl(); resourceAction.setNew(true); resourceAction.setPrimaryKey(resourceActionId); return resourceAction; } /** * Removes the resource action with the primary key from the database. Also notifies the appropriate model listeners. * * @param resourceActionId the primary key of the resource action * @return the resource action that was removed * @throws NoSuchResourceActionException if a resource action with the primary key could not be found */ @Override public ResourceAction remove(long resourceActionId) throws NoSuchResourceActionException { return remove((Serializable)resourceActionId); } /** * Removes the resource action with the primary key from the database. Also notifies the appropriate model listeners. * * @param primaryKey the primary key of the resource action * @return the resource action that was removed * @throws NoSuchResourceActionException if a resource action with the primary key could not be found */ @Override public ResourceAction remove(Serializable primaryKey) throws NoSuchResourceActionException { Session session = null; try { session = openSession(); ResourceAction resourceAction = (ResourceAction)session.get( ResourceActionImpl.class, primaryKey); if (resourceAction == null) { if (_log.isDebugEnabled()) { _log.debug(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey); } throw new NoSuchResourceActionException( _NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey); } return remove(resourceAction); } catch (NoSuchResourceActionException nsee) { throw nsee; } catch (Exception e) { throw processException(e); } finally { closeSession(session); } } @Override protected ResourceAction removeImpl(ResourceAction resourceAction) { Session session = null; try { session = openSession(); if (!session.contains(resourceAction)) { resourceAction = (ResourceAction)session.get( ResourceActionImpl.class, resourceAction.getPrimaryKeyObj()); } if (resourceAction != null) { session.delete(resourceAction); } } catch (Exception e) { throw processException(e); } finally { closeSession(session); } if (resourceAction != null) { clearCache(resourceAction); } return resourceAction; } @Override public ResourceAction updateImpl(ResourceAction resourceAction) { boolean isNew = resourceAction.isNew(); if (!(resourceAction instanceof ResourceActionModelImpl)) { InvocationHandler invocationHandler = null; if (ProxyUtil.isProxyClass(resourceAction.getClass())) { invocationHandler = ProxyUtil.getInvocationHandler( resourceAction); throw new IllegalArgumentException( "Implement ModelWrapper in resourceAction proxy " + invocationHandler.getClass()); } throw new IllegalArgumentException( "Implement ModelWrapper in custom ResourceAction implementation " + resourceAction.getClass()); } ResourceActionModelImpl resourceActionModelImpl = (ResourceActionModelImpl)resourceAction; Session session = null; try { session = openSession(); if (resourceAction.isNew()) { session.save(resourceAction); resourceAction.setNew(false); } else { resourceAction = (ResourceAction)session.merge(resourceAction); } } catch (Exception e) { throw processException(e); } finally { closeSession(session); } FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION); if (!ResourceActionModelImpl.COLUMN_BITMASK_ENABLED) { FinderCacheUtil.clearCache( FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION); } else if (isNew) { Object[] args = new Object[] {resourceActionModelImpl.getName()}; FinderCacheUtil.removeResult(_finderPathCountByName, args); FinderCacheUtil.removeResult( _finderPathWithoutPaginationFindByName, args); FinderCacheUtil.removeResult( _finderPathCountAll, FINDER_ARGS_EMPTY); FinderCacheUtil.removeResult( _finderPathWithoutPaginationFindAll, FINDER_ARGS_EMPTY); } else { if ((resourceActionModelImpl.getColumnBitmask() & _finderPathWithoutPaginationFindByName.getColumnBitmask()) != 0) { Object[] args = new Object[] { resourceActionModelImpl.getOriginalName() }; FinderCacheUtil.removeResult(_finderPathCountByName, args); FinderCacheUtil.removeResult( _finderPathWithoutPaginationFindByName, args); args = new Object[] {resourceActionModelImpl.getName()}; FinderCacheUtil.removeResult(_finderPathCountByName, args); FinderCacheUtil.removeResult( _finderPathWithoutPaginationFindByName, args); } } EntityCacheUtil.putResult( ResourceActionModelImpl.ENTITY_CACHE_ENABLED, ResourceActionImpl.class, resourceAction.getPrimaryKey(), resourceAction, false); clearUniqueFindersCache(resourceActionModelImpl, false); cacheUniqueFindersCache(resourceActionModelImpl); resourceAction.resetOriginalValues(); return resourceAction; } /** * Returns the resource action with the primary key or throws a com.liferay.portal.kernel.exception.NoSuchModelException if it could not be found. * * @param primaryKey the primary key of the resource action * @return the resource action * @throws NoSuchResourceActionException if a resource action with the primary key could not be found */ @Override public ResourceAction findByPrimaryKey(Serializable primaryKey) throws NoSuchResourceActionException { ResourceAction resourceAction = fetchByPrimaryKey(primaryKey); if (resourceAction == null) { if (_log.isDebugEnabled()) { _log.debug(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey); } throw new NoSuchResourceActionException( _NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey); } return resourceAction; } /** * Returns the resource action with the primary key or throws a NoSuchResourceActionException if it could not be found. * * @param resourceActionId the primary key of the resource action * @return the resource action * @throws NoSuchResourceActionException if a resource action with the primary key could not be found */ @Override public ResourceAction findByPrimaryKey(long resourceActionId) throws NoSuchResourceActionException { return findByPrimaryKey((Serializable)resourceActionId); } /** * Returns the resource action with the primary key or returns null if it could not be found. * * @param primaryKey the primary key of the resource action * @return the resource action, or null if a resource action with the primary key could not be found */ @Override public ResourceAction fetchByPrimaryKey(Serializable primaryKey) { Serializable serializable = EntityCacheUtil.getResult( ResourceActionModelImpl.ENTITY_CACHE_ENABLED, ResourceActionImpl.class, primaryKey); if (serializable == nullModel) { return null; } ResourceAction resourceAction = (ResourceAction)serializable; if (resourceAction == null) { Session session = null; try { session = openSession(); resourceAction = (ResourceAction)session.get( ResourceActionImpl.class, primaryKey); if (resourceAction != null) { cacheResult(resourceAction); } else { EntityCacheUtil.putResult( ResourceActionModelImpl.ENTITY_CACHE_ENABLED, ResourceActionImpl.class, primaryKey, nullModel); } } catch (Exception e) { EntityCacheUtil.removeResult( ResourceActionModelImpl.ENTITY_CACHE_ENABLED, ResourceActionImpl.class, primaryKey); throw processException(e); } finally { closeSession(session); } } return resourceAction; } /** * Returns the resource action with the primary key or returns null if it could not be found. * * @param resourceActionId the primary key of the resource action * @return the resource action, or null if a resource action with the primary key could not be found */ @Override public ResourceAction fetchByPrimaryKey(long resourceActionId) { return fetchByPrimaryKey((Serializable)resourceActionId); } @Override public Map fetchByPrimaryKeys( Set primaryKeys) { if (primaryKeys.isEmpty()) { return Collections.emptyMap(); } Map map = new HashMap(); if (primaryKeys.size() == 1) { Iterator iterator = primaryKeys.iterator(); Serializable primaryKey = iterator.next(); ResourceAction resourceAction = fetchByPrimaryKey(primaryKey); if (resourceAction != null) { map.put(primaryKey, resourceAction); } return map; } Set uncachedPrimaryKeys = null; for (Serializable primaryKey : primaryKeys) { Serializable serializable = EntityCacheUtil.getResult( ResourceActionModelImpl.ENTITY_CACHE_ENABLED, ResourceActionImpl.class, primaryKey); if (serializable != nullModel) { if (serializable == null) { if (uncachedPrimaryKeys == null) { uncachedPrimaryKeys = new HashSet(); } uncachedPrimaryKeys.add(primaryKey); } else { map.put(primaryKey, (ResourceAction)serializable); } } } if (uncachedPrimaryKeys == null) { return map; } StringBundler query = new StringBundler( uncachedPrimaryKeys.size() * 2 + 1); query.append(_SQL_SELECT_RESOURCEACTION_WHERE_PKS_IN); for (Serializable primaryKey : uncachedPrimaryKeys) { query.append((long)primaryKey); query.append(","); } query.setIndex(query.index() - 1); query.append(")"); String sql = query.toString(); Session session = null; try { session = openSession(); Query q = session.createQuery(sql); for (ResourceAction resourceAction : (List)q.list()) { map.put(resourceAction.getPrimaryKeyObj(), resourceAction); cacheResult(resourceAction); uncachedPrimaryKeys.remove(resourceAction.getPrimaryKeyObj()); } for (Serializable primaryKey : uncachedPrimaryKeys) { EntityCacheUtil.putResult( ResourceActionModelImpl.ENTITY_CACHE_ENABLED, ResourceActionImpl.class, primaryKey, nullModel); } } catch (Exception e) { throw processException(e); } finally { closeSession(session); } return map; } /** * Returns all the resource actions. * * @return the resource actions */ @Override public List findAll() { return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null); } /** * Returns a range of all the resource actions. * *

* Useful when paginating results. Returns a maximum of end - start instances. start and end are not primary keys, they are indexes in the result set. Thus, 0 refers to the first result in the set. Setting both start and end to QueryUtil#ALL_POS will return the full result set. If orderByComparator is specified, then the query will include the given ORDER BY logic. If orderByComparator is absent and pagination is required (start and end are not QueryUtil#ALL_POS), then the query will include the default ORDER BY logic from ResourceActionModelImpl. If both orderByComparator 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. *

* * @param start the lower bound of the range of resource actions * @param end the upper bound of the range of resource actions (not inclusive) * @return the range of resource actions */ @Override public List findAll(int start, int end) { return findAll(start, end, null); } /** * Returns an ordered range of all the resource actions. * *

* Useful when paginating results. Returns a maximum of end - start instances. start and end are not primary keys, they are indexes in the result set. Thus, 0 refers to the first result in the set. Setting both start and end to QueryUtil#ALL_POS will return the full result set. If orderByComparator is specified, then the query will include the given ORDER BY logic. If orderByComparator is absent and pagination is required (start and end are not QueryUtil#ALL_POS), then the query will include the default ORDER BY logic from ResourceActionModelImpl. If both orderByComparator 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. *

* * @param start the lower bound of the range of resource actions * @param end the upper bound of the range of resource actions (not inclusive) * @param orderByComparator the comparator to order the results by (optionally null) * @return the ordered range of resource actions */ @Override public List findAll( int start, int end, OrderByComparator orderByComparator) { return findAll(start, end, orderByComparator, true); } /** * Returns an ordered range of all the resource actions. * *

* Useful when paginating results. Returns a maximum of end - start instances. start and end are not primary keys, they are indexes in the result set. Thus, 0 refers to the first result in the set. Setting both start and end to QueryUtil#ALL_POS will return the full result set. If orderByComparator is specified, then the query will include the given ORDER BY logic. If orderByComparator is absent and pagination is required (start and end are not QueryUtil#ALL_POS), then the query will include the default ORDER BY logic from ResourceActionModelImpl. If both orderByComparator 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. *

* * @param start the lower bound of the range of resource actions * @param end the upper bound of the range of resource actions (not inclusive) * @param orderByComparator the comparator to order the results by (optionally null) * @param retrieveFromCache whether to retrieve from the finder cache * @return the ordered range of resource actions */ @Override public List findAll( int start, int end, OrderByComparator 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 = _finderPathWithoutPaginationFindAll; finderArgs = FINDER_ARGS_EMPTY; } else { finderPath = _finderPathWithPaginationFindAll; finderArgs = new Object[] {start, end, orderByComparator}; } List list = null; if (retrieveFromCache) { list = (List)FinderCacheUtil.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_RESOURCEACTION); appendOrderByComparator( query, _ORDER_BY_ENTITY_ALIAS, orderByComparator); sql = query.toString(); } else { sql = _SQL_SELECT_RESOURCEACTION; if (pagination) { sql = sql.concat(ResourceActionModelImpl.ORDER_BY_JPQL); } } Session session = null; try { session = openSession(); Query q = session.createQuery(sql); if (!pagination) { list = (List)QueryUtil.list( q, getDialect(), start, end, false); Collections.sort(list); list = Collections.unmodifiableList(list); } else { list = (List)QueryUtil.list( q, getDialect(), start, end); } cacheResult(list); FinderCacheUtil.putResult(finderPath, finderArgs, list); } catch (Exception e) { FinderCacheUtil.removeResult(finderPath, finderArgs); throw processException(e); } finally { closeSession(session); } } return list; } /** * Removes all the resource actions from the database. * */ @Override public void removeAll() { for (ResourceAction resourceAction : findAll()) { remove(resourceAction); } } /** * Returns the number of resource actions. * * @return the number of resource actions */ @Override public int countAll() { Long count = (Long)FinderCacheUtil.getResult( _finderPathCountAll, FINDER_ARGS_EMPTY, this); if (count == null) { Session session = null; try { session = openSession(); Query q = session.createQuery(_SQL_COUNT_RESOURCEACTION); count = (Long)q.uniqueResult(); FinderCacheUtil.putResult( _finderPathCountAll, FINDER_ARGS_EMPTY, count); } catch (Exception e) { FinderCacheUtil.removeResult( _finderPathCountAll, FINDER_ARGS_EMPTY); throw processException(e); } finally { closeSession(session); } } return count.intValue(); } @Override protected Map getTableColumnsMap() { return ResourceActionModelImpl.TABLE_COLUMNS_MAP; } /** * Initializes the resource action persistence. */ public void afterPropertiesSet() { _finderPathWithPaginationFindAll = new FinderPath( ResourceActionModelImpl.ENTITY_CACHE_ENABLED, ResourceActionModelImpl.FINDER_CACHE_ENABLED, ResourceActionImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]); _finderPathWithoutPaginationFindAll = new FinderPath( ResourceActionModelImpl.ENTITY_CACHE_ENABLED, ResourceActionModelImpl.FINDER_CACHE_ENABLED, ResourceActionImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]); _finderPathCountAll = new FinderPath( ResourceActionModelImpl.ENTITY_CACHE_ENABLED, ResourceActionModelImpl.FINDER_CACHE_ENABLED, Long.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]); _finderPathWithPaginationFindByName = new FinderPath( ResourceActionModelImpl.ENTITY_CACHE_ENABLED, ResourceActionModelImpl.FINDER_CACHE_ENABLED, ResourceActionImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByName", new String[] { String.class.getName(), Integer.class.getName(), Integer.class.getName(), OrderByComparator.class.getName() }); _finderPathWithoutPaginationFindByName = new FinderPath( ResourceActionModelImpl.ENTITY_CACHE_ENABLED, ResourceActionModelImpl.FINDER_CACHE_ENABLED, ResourceActionImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByName", new String[] {String.class.getName()}, ResourceActionModelImpl.NAME_COLUMN_BITMASK | ResourceActionModelImpl.BITWISEVALUE_COLUMN_BITMASK); _finderPathCountByName = new FinderPath( ResourceActionModelImpl.ENTITY_CACHE_ENABLED, ResourceActionModelImpl.FINDER_CACHE_ENABLED, Long.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByName", new String[] {String.class.getName()}); _finderPathFetchByN_A = new FinderPath( ResourceActionModelImpl.ENTITY_CACHE_ENABLED, ResourceActionModelImpl.FINDER_CACHE_ENABLED, ResourceActionImpl.class, FINDER_CLASS_NAME_ENTITY, "fetchByN_A", new String[] {String.class.getName(), String.class.getName()}, ResourceActionModelImpl.NAME_COLUMN_BITMASK | ResourceActionModelImpl.ACTIONID_COLUMN_BITMASK); _finderPathCountByN_A = new FinderPath( ResourceActionModelImpl.ENTITY_CACHE_ENABLED, ResourceActionModelImpl.FINDER_CACHE_ENABLED, Long.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByN_A", new String[] {String.class.getName(), String.class.getName()}); } public void destroy() { EntityCacheUtil.removeCache(ResourceActionImpl.class.getName()); FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY); FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION); FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION); } private static final String _SQL_SELECT_RESOURCEACTION = "SELECT resourceAction FROM ResourceAction resourceAction"; private static final String _SQL_SELECT_RESOURCEACTION_WHERE_PKS_IN = "SELECT resourceAction FROM ResourceAction resourceAction WHERE resourceActionId IN ("; private static final String _SQL_SELECT_RESOURCEACTION_WHERE = "SELECT resourceAction FROM ResourceAction resourceAction WHERE "; private static final String _SQL_COUNT_RESOURCEACTION = "SELECT COUNT(resourceAction) FROM ResourceAction resourceAction"; private static final String _SQL_COUNT_RESOURCEACTION_WHERE = "SELECT COUNT(resourceAction) FROM ResourceAction resourceAction WHERE "; private static final String _ORDER_BY_ENTITY_ALIAS = "resourceAction."; private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ResourceAction exists with the primary key "; private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ResourceAction exists with the key {"; private static final Log _log = LogFactoryUtil.getLog( ResourceActionPersistenceImpl.class); }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy