--- /dev/null
+/**
+ * Copyright (c) 2000-2012 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.pentila.entSavoie.blog.service.persistence;
+
+import com.liferay.portal.NoSuchModelException;
+import com.liferay.portal.kernel.bean.BeanReference;
+import com.liferay.portal.kernel.cache.CacheRegistryUtil;
+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.SystemException;
+import com.liferay.portal.kernel.log.Log;
+import com.liferay.portal.kernel.log.LogFactoryUtil;
+import com.liferay.portal.kernel.portlet.PortletClassLoaderUtil;
+import com.liferay.portal.kernel.util.GetterUtil;
+import com.liferay.portal.kernel.util.InstanceFactory;
+import com.liferay.portal.kernel.util.OrderByComparator;
+import com.liferay.portal.kernel.util.PropsKeys;
+import com.liferay.portal.kernel.util.PropsUtil;
+import com.liferay.portal.kernel.util.StringBundler;
+import com.liferay.portal.kernel.util.StringPool;
+import com.liferay.portal.kernel.util.StringUtil;
+import com.liferay.portal.model.CacheModel;
+import com.liferay.portal.model.ModelListener;
+import com.liferay.portal.service.persistence.BatchSessionUtil;
+import com.liferay.portal.service.persistence.ResourcePersistence;
+import com.liferay.portal.service.persistence.UserPersistence;
+import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
+
+import com.pentila.entSavoie.blog.NoSuchBlogChannelException;
+import com.pentila.entSavoie.blog.model.BlogChannel;
+import com.pentila.entSavoie.blog.model.impl.BlogChannelImpl;
+import com.pentila.entSavoie.blog.model.impl.BlogChannelModelImpl;
+
+import java.io.Serializable;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * The persistence implementation for the blog channel service.
+ *
+ * <p>
+ * Caching information and settings can be found in <code>portal.properties</code>
+ * </p>
+ *
+ * @author Mathieu Amblard et Benjamin Apprederisse
+ * @see BlogChannelPersistence
+ * @see BlogChannelUtil
+ * @generated
+ */
+public class BlogChannelPersistenceImpl extends BasePersistenceImpl<BlogChannel>
+ implements BlogChannelPersistence {
+ /*
+ * NOTE FOR DEVELOPERS:
+ *
+ * Never modify or reference this class directly. Always use {@link BlogChannelUtil} to access the blog channel persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
+ */
+ public static final String FINDER_CLASS_NAME_ENTITY = BlogChannelImpl.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_FETCH_BY_USERID = new FinderPath(BlogChannelModelImpl.ENTITY_CACHE_ENABLED,
+ BlogChannelModelImpl.FINDER_CACHE_ENABLED, BlogChannelImpl.class,
+ FINDER_CLASS_NAME_ENTITY, "fetchByuserId",
+ new String[] { Long.class.getName() },
+ BlogChannelModelImpl.USERID_COLUMN_BITMASK);
+ public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(BlogChannelModelImpl.ENTITY_CACHE_ENABLED,
+ BlogChannelModelImpl.FINDER_CACHE_ENABLED, Long.class,
+ FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByuserId",
+ new String[] { Long.class.getName() });
+ public static final FinderPath FINDER_PATH_FETCH_BY_GROUPID = new FinderPath(BlogChannelModelImpl.ENTITY_CACHE_ENABLED,
+ BlogChannelModelImpl.FINDER_CACHE_ENABLED, BlogChannelImpl.class,
+ FINDER_CLASS_NAME_ENTITY, "fetchBygroupId",
+ new String[] { Long.class.getName() },
+ BlogChannelModelImpl.GROUPID_COLUMN_BITMASK);
+ public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(BlogChannelModelImpl.ENTITY_CACHE_ENABLED,
+ BlogChannelModelImpl.FINDER_CACHE_ENABLED, Long.class,
+ FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countBygroupId",
+ new String[] { Long.class.getName() });
+ public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(BlogChannelModelImpl.ENTITY_CACHE_ENABLED,
+ BlogChannelModelImpl.FINDER_CACHE_ENABLED, BlogChannelImpl.class,
+ FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
+ public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(BlogChannelModelImpl.ENTITY_CACHE_ENABLED,
+ BlogChannelModelImpl.FINDER_CACHE_ENABLED, BlogChannelImpl.class,
+ FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
+ public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(BlogChannelModelImpl.ENTITY_CACHE_ENABLED,
+ BlogChannelModelImpl.FINDER_CACHE_ENABLED, Long.class,
+ FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
+
+ /**
+ * Caches the blog channel in the entity cache if it is enabled.
+ *
+ * @param blogChannel the blog channel
+ */
+ public void cacheResult(BlogChannel blogChannel) {
+ EntityCacheUtil.putResult(BlogChannelModelImpl.ENTITY_CACHE_ENABLED,
+ BlogChannelImpl.class, blogChannel.getPrimaryKey(), blogChannel);
+
+ FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_USERID,
+ new Object[] { Long.valueOf(blogChannel.getUserId()) }, blogChannel);
+
+ FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_GROUPID,
+ new Object[] { Long.valueOf(blogChannel.getGroupId()) }, blogChannel);
+
+ blogChannel.resetOriginalValues();
+ }
+
+ /**
+ * Caches the blog channels in the entity cache if it is enabled.
+ *
+ * @param blogChannels the blog channels
+ */
+ public void cacheResult(List<BlogChannel> blogChannels) {
+ for (BlogChannel blogChannel : blogChannels) {
+ if (EntityCacheUtil.getResult(
+ BlogChannelModelImpl.ENTITY_CACHE_ENABLED,
+ BlogChannelImpl.class, blogChannel.getPrimaryKey()) == null) {
+ cacheResult(blogChannel);
+ }
+ else {
+ blogChannel.resetOriginalValues();
+ }
+ }
+ }
+
+ /**
+ * Clears the cache for all blog channels.
+ *
+ * <p>
+ * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
+ * </p>
+ */
+ @Override
+ public void clearCache() {
+ if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
+ CacheRegistryUtil.clear(BlogChannelImpl.class.getName());
+ }
+
+ EntityCacheUtil.clearCache(BlogChannelImpl.class.getName());
+
+ 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 blog channel.
+ *
+ * <p>
+ * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
+ * </p>
+ */
+ @Override
+ public void clearCache(BlogChannel blogChannel) {
+ EntityCacheUtil.removeResult(BlogChannelModelImpl.ENTITY_CACHE_ENABLED,
+ BlogChannelImpl.class, blogChannel.getPrimaryKey());
+
+ FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
+ FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
+
+ clearUniqueFindersCache(blogChannel);
+ }
+
+ @Override
+ public void clearCache(List<BlogChannel> blogChannels) {
+ FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
+ FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
+
+ for (BlogChannel blogChannel : blogChannels) {
+ EntityCacheUtil.removeResult(BlogChannelModelImpl.ENTITY_CACHE_ENABLED,
+ BlogChannelImpl.class, blogChannel.getPrimaryKey());
+
+ clearUniqueFindersCache(blogChannel);
+ }
+ }
+
+ protected void clearUniqueFindersCache(BlogChannel blogChannel) {
+ FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_USERID,
+ new Object[] { Long.valueOf(blogChannel.getUserId()) });
+
+ FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_GROUPID,
+ new Object[] { Long.valueOf(blogChannel.getGroupId()) });
+ }
+
+ /**
+ * Creates a new blog channel with the primary key. Does not add the blog channel to the database.
+ *
+ * @param channelId the primary key for the new blog channel
+ * @return the new blog channel
+ */
+ public BlogChannel create(long channelId) {
+ BlogChannel blogChannel = new BlogChannelImpl();
+
+ blogChannel.setNew(true);
+ blogChannel.setPrimaryKey(channelId);
+
+ return blogChannel;
+ }
+
+ /**
+ * Removes the blog channel with the primary key from the database. Also notifies the appropriate model listeners.
+ *
+ * @param channelId the primary key of the blog channel
+ * @return the blog channel that was removed
+ * @throws com.pentila.entSavoie.blog.NoSuchBlogChannelException if a blog channel with the primary key could not be found
+ * @throws SystemException if a system exception occurred
+ */
+ public BlogChannel remove(long channelId)
+ throws NoSuchBlogChannelException, SystemException {
+ return remove(Long.valueOf(channelId));
+ }
+
+ /**
+ * Removes the blog channel with the primary key from the database. Also notifies the appropriate model listeners.
+ *
+ * @param primaryKey the primary key of the blog channel
+ * @return the blog channel that was removed
+ * @throws com.pentila.entSavoie.blog.NoSuchBlogChannelException if a blog channel with the primary key could not be found
+ * @throws SystemException if a system exception occurred
+ */
+ @Override
+ public BlogChannel remove(Serializable primaryKey)
+ throws NoSuchBlogChannelException, SystemException {
+ Session session = null;
+
+ try {
+ session = openSession();
+
+ BlogChannel blogChannel = (BlogChannel)session.get(BlogChannelImpl.class,
+ primaryKey);
+
+ if (blogChannel == null) {
+ if (_log.isWarnEnabled()) {
+ _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
+ }
+
+ throw new NoSuchBlogChannelException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
+ primaryKey);
+ }
+
+ return remove(blogChannel);
+ }
+ catch (NoSuchBlogChannelException nsee) {
+ throw nsee;
+ }
+ catch (Exception e) {
+ throw processException(e);
+ }
+ finally {
+ closeSession(session);
+ }
+ }
+
+ @Override
+ protected BlogChannel removeImpl(BlogChannel blogChannel)
+ throws SystemException {
+ blogChannel = toUnwrappedModel(blogChannel);
+
+ Session session = null;
+
+ try {
+ session = openSession();
+
+ BatchSessionUtil.delete(session, blogChannel);
+ }
+ catch (Exception e) {
+ throw processException(e);
+ }
+ finally {
+ closeSession(session);
+ }
+
+ clearCache(blogChannel);
+
+ return blogChannel;
+ }
+
+ @Override
+ public BlogChannel updateImpl(
+ com.pentila.entSavoie.blog.model.BlogChannel blogChannel, boolean merge)
+ throws SystemException {
+ blogChannel = toUnwrappedModel(blogChannel);
+
+ boolean isNew = blogChannel.isNew();
+
+ BlogChannelModelImpl blogChannelModelImpl = (BlogChannelModelImpl)blogChannel;
+
+ Session session = null;
+
+ try {
+ session = openSession();
+
+ BatchSessionUtil.update(session, blogChannel, merge);
+
+ blogChannel.setNew(false);
+ }
+ catch (Exception e) {
+ throw processException(e);
+ }
+ finally {
+ closeSession(session);
+ }
+
+ FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
+
+ if (isNew || !BlogChannelModelImpl.COLUMN_BITMASK_ENABLED) {
+ FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
+ }
+
+ EntityCacheUtil.putResult(BlogChannelModelImpl.ENTITY_CACHE_ENABLED,
+ BlogChannelImpl.class, blogChannel.getPrimaryKey(), blogChannel);
+
+ if (isNew) {
+ FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_USERID,
+ new Object[] { Long.valueOf(blogChannel.getUserId()) },
+ blogChannel);
+
+ FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_GROUPID,
+ new Object[] { Long.valueOf(blogChannel.getGroupId()) },
+ blogChannel);
+ }
+ else {
+ if ((blogChannelModelImpl.getColumnBitmask() &
+ FINDER_PATH_FETCH_BY_USERID.getColumnBitmask()) != 0) {
+ Object[] args = new Object[] {
+ Long.valueOf(blogChannelModelImpl.getOriginalUserId())
+ };
+
+ FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
+
+ FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_USERID, args);
+
+ FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_USERID,
+ new Object[] { Long.valueOf(blogChannel.getUserId()) },
+ blogChannel);
+ }
+
+ if ((blogChannelModelImpl.getColumnBitmask() &
+ FINDER_PATH_FETCH_BY_GROUPID.getColumnBitmask()) != 0) {
+ Object[] args = new Object[] {
+ Long.valueOf(blogChannelModelImpl.getOriginalGroupId())
+ };
+
+ FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
+
+ FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_GROUPID, args);
+
+ FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_GROUPID,
+ new Object[] { Long.valueOf(blogChannel.getGroupId()) },
+ blogChannel);
+ }
+ }
+
+ return blogChannel;
+ }
+
+ protected BlogChannel toUnwrappedModel(BlogChannel blogChannel) {
+ if (blogChannel instanceof BlogChannelImpl) {
+ return blogChannel;
+ }
+
+ BlogChannelImpl blogChannelImpl = new BlogChannelImpl();
+
+ blogChannelImpl.setNew(blogChannel.isNew());
+ blogChannelImpl.setPrimaryKey(blogChannel.getPrimaryKey());
+
+ blogChannelImpl.setChannelId(blogChannel.getChannelId());
+ blogChannelImpl.setGroupId(blogChannel.getGroupId());
+ blogChannelImpl.setUserId(blogChannel.getUserId());
+ blogChannelImpl.setTitle(blogChannel.getTitle());
+ blogChannelImpl.setDescription(blogChannel.getDescription());
+ blogChannelImpl.setPubDate(blogChannel.getPubDate());
+ blogChannelImpl.setLastBuildDate(blogChannel.getLastBuildDate());
+ blogChannelImpl.setConfiguration(blogChannel.getConfiguration());
+ blogChannelImpl.setTopBand(blogChannel.getTopBand());
+ blogChannelImpl.setActive_(blogChannel.isActive_());
+
+ return blogChannelImpl;
+ }
+
+ /**
+ * Returns the blog channel with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
+ *
+ * @param primaryKey the primary key of the blog channel
+ * @return the blog channel
+ * @throws com.liferay.portal.NoSuchModelException if a blog channel with the primary key could not be found
+ * @throws SystemException if a system exception occurred
+ */
+ @Override
+ public BlogChannel findByPrimaryKey(Serializable primaryKey)
+ throws NoSuchModelException, SystemException {
+ return findByPrimaryKey(((Long)primaryKey).longValue());
+ }
+
+ /**
+ * Returns the blog channel with the primary key or throws a {@link com.pentila.entSavoie.blog.NoSuchBlogChannelException} if it could not be found.
+ *
+ * @param channelId the primary key of the blog channel
+ * @return the blog channel
+ * @throws com.pentila.entSavoie.blog.NoSuchBlogChannelException if a blog channel with the primary key could not be found
+ * @throws SystemException if a system exception occurred
+ */
+ public BlogChannel findByPrimaryKey(long channelId)
+ throws NoSuchBlogChannelException, SystemException {
+ BlogChannel blogChannel = fetchByPrimaryKey(channelId);
+
+ if (blogChannel == null) {
+ if (_log.isWarnEnabled()) {
+ _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + channelId);
+ }
+
+ throw new NoSuchBlogChannelException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
+ channelId);
+ }
+
+ return blogChannel;
+ }
+
+ /**
+ * Returns the blog channel with the primary key or returns <code>null</code> if it could not be found.
+ *
+ * @param primaryKey the primary key of the blog channel
+ * @return the blog channel, or <code>null</code> if a blog channel with the primary key could not be found
+ * @throws SystemException if a system exception occurred
+ */
+ @Override
+ public BlogChannel fetchByPrimaryKey(Serializable primaryKey)
+ throws SystemException {
+ return fetchByPrimaryKey(((Long)primaryKey).longValue());
+ }
+
+ /**
+ * Returns the blog channel with the primary key or returns <code>null</code> if it could not be found.
+ *
+ * @param channelId the primary key of the blog channel
+ * @return the blog channel, or <code>null</code> if a blog channel with the primary key could not be found
+ * @throws SystemException if a system exception occurred
+ */
+ public BlogChannel fetchByPrimaryKey(long channelId)
+ throws SystemException {
+ BlogChannel blogChannel = (BlogChannel)EntityCacheUtil.getResult(BlogChannelModelImpl.ENTITY_CACHE_ENABLED,
+ BlogChannelImpl.class, channelId);
+
+ if (blogChannel == _nullBlogChannel) {
+ return null;
+ }
+
+ if (blogChannel == null) {
+ Session session = null;
+
+ boolean hasException = false;
+
+ try {
+ session = openSession();
+
+ blogChannel = (BlogChannel)session.get(BlogChannelImpl.class,
+ Long.valueOf(channelId));
+ }
+ catch (Exception e) {
+ hasException = true;
+
+ throw processException(e);
+ }
+ finally {
+ if (blogChannel != null) {
+ cacheResult(blogChannel);
+ }
+ else if (!hasException) {
+ EntityCacheUtil.putResult(BlogChannelModelImpl.ENTITY_CACHE_ENABLED,
+ BlogChannelImpl.class, channelId, _nullBlogChannel);
+ }
+
+ closeSession(session);
+ }
+ }
+
+ return blogChannel;
+ }
+
+ /**
+ * Returns the blog channel where userId = ? or throws a {@link com.pentila.entSavoie.blog.NoSuchBlogChannelException} if it could not be found.
+ *
+ * @param userId the user ID
+ * @return the matching blog channel
+ * @throws com.pentila.entSavoie.blog.NoSuchBlogChannelException if a matching blog channel could not be found
+ * @throws SystemException if a system exception occurred
+ */
+ public BlogChannel findByuserId(long userId)
+ throws NoSuchBlogChannelException, SystemException {
+ BlogChannel blogChannel = fetchByuserId(userId);
+
+ if (blogChannel == null) {
+ StringBundler msg = new StringBundler(4);
+
+ msg.append(_NO_SUCH_ENTITY_WITH_KEY);
+
+ msg.append("userId=");
+ msg.append(userId);
+
+ msg.append(StringPool.CLOSE_CURLY_BRACE);
+
+ if (_log.isWarnEnabled()) {
+ _log.warn(msg.toString());
+ }
+
+ throw new NoSuchBlogChannelException(msg.toString());
+ }
+
+ return blogChannel;
+ }
+
+ /**
+ * Returns the blog channel where userId = ? or returns <code>null</code> if it could not be found. Uses the finder cache.
+ *
+ * @param userId the user ID
+ * @return the matching blog channel, or <code>null</code> if a matching blog channel could not be found
+ * @throws SystemException if a system exception occurred
+ */
+ public BlogChannel fetchByuserId(long userId) throws SystemException {
+ return fetchByuserId(userId, true);
+ }
+
+ /**
+ * Returns the blog channel where userId = ? or returns <code>null</code> if it could not be found, optionally using the finder cache.
+ *
+ * @param userId the user ID
+ * @param retrieveFromCache whether to use the finder cache
+ * @return the matching blog channel, or <code>null</code> if a matching blog channel could not be found
+ * @throws SystemException if a system exception occurred
+ */
+ public BlogChannel fetchByuserId(long userId, boolean retrieveFromCache)
+ throws SystemException {
+ Object[] finderArgs = new Object[] { userId };
+
+ Object result = null;
+
+ if (retrieveFromCache) {
+ result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_USERID,
+ finderArgs, this);
+ }
+
+ if (result instanceof BlogChannel) {
+ BlogChannel blogChannel = (BlogChannel)result;
+
+ if ((userId != blogChannel.getUserId())) {
+ result = null;
+ }
+ }
+
+ if (result == null) {
+ StringBundler query = new StringBundler(2);
+
+ query.append(_SQL_SELECT_BLOGCHANNEL_WHERE);
+
+ query.append(_FINDER_COLUMN_USERID_USERID_2);
+
+ String sql = query.toString();
+
+ Session session = null;
+
+ try {
+ session = openSession();
+
+ Query q = session.createQuery(sql);
+
+ QueryPos qPos = QueryPos.getInstance(q);
+
+ qPos.add(userId);
+
+ List<BlogChannel> list = q.list();
+
+ result = list;
+
+ BlogChannel blogChannel = null;
+
+ if (list.isEmpty()) {
+ FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_USERID,
+ finderArgs, list);
+ }
+ else {
+ blogChannel = list.get(0);
+
+ cacheResult(blogChannel);
+
+ if ((blogChannel.getUserId() != userId)) {
+ FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_USERID,
+ finderArgs, blogChannel);
+ }
+ }
+
+ return blogChannel;
+ }
+ catch (Exception e) {
+ throw processException(e);
+ }
+ finally {
+ if (result == null) {
+ FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_USERID,
+ finderArgs);
+ }
+
+ closeSession(session);
+ }
+ }
+ else {
+ if (result instanceof List<?>) {
+ return null;
+ }
+ else {
+ return (BlogChannel)result;
+ }
+ }
+ }
+
+ /**
+ * Returns the blog channel where groupId = ? or throws a {@link com.pentila.entSavoie.blog.NoSuchBlogChannelException} if it could not be found.
+ *
+ * @param groupId the group ID
+ * @return the matching blog channel
+ * @throws com.pentila.entSavoie.blog.NoSuchBlogChannelException if a matching blog channel could not be found
+ * @throws SystemException if a system exception occurred
+ */
+ public BlogChannel findBygroupId(long groupId)
+ throws NoSuchBlogChannelException, SystemException {
+ BlogChannel blogChannel = fetchBygroupId(groupId);
+
+ if (blogChannel == null) {
+ StringBundler msg = new StringBundler(4);
+
+ msg.append(_NO_SUCH_ENTITY_WITH_KEY);
+
+ msg.append("groupId=");
+ msg.append(groupId);
+
+ msg.append(StringPool.CLOSE_CURLY_BRACE);
+
+ if (_log.isWarnEnabled()) {
+ _log.warn(msg.toString());
+ }
+
+ throw new NoSuchBlogChannelException(msg.toString());
+ }
+
+ return blogChannel;
+ }
+
+ /**
+ * Returns the blog channel where groupId = ? or returns <code>null</code> if it could not be found. Uses the finder cache.
+ *
+ * @param groupId the group ID
+ * @return the matching blog channel, or <code>null</code> if a matching blog channel could not be found
+ * @throws SystemException if a system exception occurred
+ */
+ public BlogChannel fetchBygroupId(long groupId) throws SystemException {
+ return fetchBygroupId(groupId, true);
+ }
+
+ /**
+ * Returns the blog channel where groupId = ? or returns <code>null</code> if it could not be found, optionally using the finder cache.
+ *
+ * @param groupId the group ID
+ * @param retrieveFromCache whether to use the finder cache
+ * @return the matching blog channel, or <code>null</code> if a matching blog channel could not be found
+ * @throws SystemException if a system exception occurred
+ */
+ public BlogChannel fetchBygroupId(long groupId, boolean retrieveFromCache)
+ throws SystemException {
+ Object[] finderArgs = new Object[] { groupId };
+
+ Object result = null;
+
+ if (retrieveFromCache) {
+ result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_GROUPID,
+ finderArgs, this);
+ }
+
+ if (result instanceof BlogChannel) {
+ BlogChannel blogChannel = (BlogChannel)result;
+
+ if ((groupId != blogChannel.getGroupId())) {
+ result = null;
+ }
+ }
+
+ if (result == null) {
+ StringBundler query = new StringBundler(2);
+
+ query.append(_SQL_SELECT_BLOGCHANNEL_WHERE);
+
+ query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
+
+ String sql = query.toString();
+
+ Session session = null;
+
+ try {
+ session = openSession();
+
+ Query q = session.createQuery(sql);
+
+ QueryPos qPos = QueryPos.getInstance(q);
+
+ qPos.add(groupId);
+
+ List<BlogChannel> list = q.list();
+
+ result = list;
+
+ BlogChannel blogChannel = null;
+
+ if (list.isEmpty()) {
+ FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_GROUPID,
+ finderArgs, list);
+ }
+ else {
+ blogChannel = list.get(0);
+
+ cacheResult(blogChannel);
+
+ if ((blogChannel.getGroupId() != groupId)) {
+ FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_GROUPID,
+ finderArgs, blogChannel);
+ }
+ }
+
+ return blogChannel;
+ }
+ catch (Exception e) {
+ throw processException(e);
+ }
+ finally {
+ if (result == null) {
+ FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_GROUPID,
+ finderArgs);
+ }
+
+ closeSession(session);
+ }
+ }
+ else {
+ if (result instanceof List<?>) {
+ return null;
+ }
+ else {
+ return (BlogChannel)result;
+ }
+ }
+ }
+
+ /**
+ * Returns all the blog channels.
+ *
+ * @return the blog channels
+ * @throws SystemException if a system exception occurred
+ */
+ public List<BlogChannel> findAll() throws SystemException {
+ return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
+ }
+
+ /**
+ * Returns a range of all the blog channels.
+ *
+ * <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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
+ * </p>
+ *
+ * @param start the lower bound of the range of blog channels
+ * @param end the upper bound of the range of blog channels (not inclusive)
+ * @return the range of blog channels
+ * @throws SystemException if a system exception occurred
+ */
+ public List<BlogChannel> findAll(int start, int end)
+ throws SystemException {
+ return findAll(start, end, null);
+ }
+
+ /**
+ * Returns an ordered range of all the blog channels.
+ *
+ * <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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
+ * </p>
+ *
+ * @param start the lower bound of the range of blog channels
+ * @param end the upper bound of the range of blog channels (not inclusive)
+ * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
+ * @return the ordered range of blog channels
+ * @throws SystemException if a system exception occurred
+ */
+ public List<BlogChannel> findAll(int start, int end,
+ OrderByComparator orderByComparator) throws SystemException {
+ FinderPath finderPath = null;
+ Object[] finderArgs = new Object[] { start, end, orderByComparator };
+
+ if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
+ (orderByComparator == null)) {
+ 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<BlogChannel> list = (List<BlogChannel>)FinderCacheUtil.getResult(finderPath,
+ finderArgs, this);
+
+ if (list == null) {
+ StringBundler query = null;
+ String sql = null;
+
+ if (orderByComparator != null) {
+ query = new StringBundler(2 +
+ (orderByComparator.getOrderByFields().length * 3));
+
+ query.append(_SQL_SELECT_BLOGCHANNEL);
+
+ appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
+ orderByComparator);
+
+ sql = query.toString();
+ }
+ else {
+ sql = _SQL_SELECT_BLOGCHANNEL;
+ }
+
+ Session session = null;
+
+ try {
+ session = openSession();
+
+ Query q = session.createQuery(sql);
+
+ if (orderByComparator == null) {
+ list = (List<BlogChannel>)QueryUtil.list(q, getDialect(),
+ start, end, false);
+
+ Collections.sort(list);
+ }
+ else {
+ list = (List<BlogChannel>)QueryUtil.list(q, getDialect(),
+ start, end);
+ }
+ }
+ catch (Exception e) {
+ throw processException(e);
+ }
+ finally {
+ if (list == null) {
+ FinderCacheUtil.removeResult(finderPath, finderArgs);
+ }
+ else {
+ cacheResult(list);
+
+ FinderCacheUtil.putResult(finderPath, finderArgs, list);
+ }
+
+ closeSession(session);
+ }
+ }
+
+ return list;
+ }
+
+ /**
+ * Removes the blog channel where userId = ? from the database.
+ *
+ * @param userId the user ID
+ * @return the blog channel that was removed
+ * @throws SystemException if a system exception occurred
+ */
+ public BlogChannel removeByuserId(long userId)
+ throws NoSuchBlogChannelException, SystemException {
+ BlogChannel blogChannel = findByuserId(userId);
+
+ return remove(blogChannel);
+ }
+
+ /**
+ * Removes the blog channel where groupId = ? from the database.
+ *
+ * @param groupId the group ID
+ * @return the blog channel that was removed
+ * @throws SystemException if a system exception occurred
+ */
+ public BlogChannel removeBygroupId(long groupId)
+ throws NoSuchBlogChannelException, SystemException {
+ BlogChannel blogChannel = findBygroupId(groupId);
+
+ return remove(blogChannel);
+ }
+
+ /**
+ * Removes all the blog channels from the database.
+ *
+ * @throws SystemException if a system exception occurred
+ */
+ public void removeAll() throws SystemException {
+ for (BlogChannel blogChannel : findAll()) {
+ remove(blogChannel);
+ }
+ }
+
+ /**
+ * Returns the number of blog channels where userId = ?.
+ *
+ * @param userId the user ID
+ * @return the number of matching blog channels
+ * @throws SystemException if a system exception occurred
+ */
+ public int countByuserId(long userId) throws SystemException {
+ Object[] finderArgs = new Object[] { userId };
+
+ Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_USERID,
+ finderArgs, this);
+
+ if (count == null) {
+ StringBundler query = new StringBundler(2);
+
+ query.append(_SQL_COUNT_BLOGCHANNEL_WHERE);
+
+ query.append(_FINDER_COLUMN_USERID_USERID_2);
+
+ String sql = query.toString();
+
+ Session session = null;
+
+ try {
+ session = openSession();
+
+ Query q = session.createQuery(sql);
+
+ QueryPos qPos = QueryPos.getInstance(q);
+
+ qPos.add(userId);
+
+ count = (Long)q.uniqueResult();
+ }
+ catch (Exception e) {
+ throw processException(e);
+ }
+ finally {
+ if (count == null) {
+ count = Long.valueOf(0);
+ }
+
+ FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_USERID,
+ finderArgs, count);
+
+ closeSession(session);
+ }
+ }
+
+ return count.intValue();
+ }
+
+ /**
+ * Returns the number of blog channels where groupId = ?.
+ *
+ * @param groupId the group ID
+ * @return the number of matching blog channels
+ * @throws SystemException if a system exception occurred
+ */
+ public int countBygroupId(long groupId) throws SystemException {
+ Object[] finderArgs = new Object[] { groupId };
+
+ Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
+ finderArgs, this);
+
+ if (count == null) {
+ StringBundler query = new StringBundler(2);
+
+ query.append(_SQL_COUNT_BLOGCHANNEL_WHERE);
+
+ query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
+
+ String sql = query.toString();
+
+ Session session = null;
+
+ try {
+ session = openSession();
+
+ Query q = session.createQuery(sql);
+
+ QueryPos qPos = QueryPos.getInstance(q);
+
+ qPos.add(groupId);
+
+ count = (Long)q.uniqueResult();
+ }
+ catch (Exception e) {
+ throw processException(e);
+ }
+ finally {
+ if (count == null) {
+ count = Long.valueOf(0);
+ }
+
+ FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
+ finderArgs, count);
+
+ closeSession(session);
+ }
+ }
+
+ return count.intValue();
+ }
+
+ /**
+ * Returns the number of blog channels.
+ *
+ * @return the number of blog channels
+ * @throws SystemException if a system exception occurred
+ */
+ public int countAll() throws SystemException {
+ Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
+ FINDER_ARGS_EMPTY, this);
+
+ if (count == null) {
+ Session session = null;
+
+ try {
+ session = openSession();
+
+ Query q = session.createQuery(_SQL_COUNT_BLOGCHANNEL);
+
+ count = (Long)q.uniqueResult();
+ }
+ catch (Exception e) {
+ throw processException(e);
+ }
+ finally {
+ if (count == null) {
+ count = Long.valueOf(0);
+ }
+
+ FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
+ FINDER_ARGS_EMPTY, count);
+
+ closeSession(session);
+ }
+ }
+
+ return count.intValue();
+ }
+
+ /**
+ * Initializes the blog channel persistence.
+ */
+ public void afterPropertiesSet() {
+ String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
+ com.liferay.util.service.ServiceProps.get(
+ "value.object.listener.com.pentila.entSavoie.blog.model.BlogChannel")));
+
+ if (listenerClassNames.length > 0) {
+ try {
+ List<ModelListener<BlogChannel>> listenersList = new ArrayList<ModelListener<BlogChannel>>();
+
+ for (String listenerClassName : listenerClassNames) {
+ listenersList.add((ModelListener<BlogChannel>)InstanceFactory.newInstance(
+ PortletClassLoaderUtil.getClassLoader(),
+ listenerClassName, (Class<?>[])null, (Object[])null));
+ }
+
+ listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
+ }
+ catch (Exception e) {
+ _log.error(e);
+ }
+ }
+ }
+
+ public void destroy() {
+ EntityCacheUtil.removeCache(BlogChannelImpl.class.getName());
+ FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
+ FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
+ }
+
+ @BeanReference(type = BlogCategoryPersistence.class)
+ protected BlogCategoryPersistence blogCategoryPersistence;
+ @BeanReference(type = BlogChannelPersistence.class)
+ protected BlogChannelPersistence blogChannelPersistence;
+ @BeanReference(type = BlogItemPersistence.class)
+ protected BlogItemPersistence blogItemPersistence;
+ @BeanReference(type = ResourcePersistence.class)
+ protected ResourcePersistence resourcePersistence;
+ @BeanReference(type = UserPersistence.class)
+ protected UserPersistence userPersistence;
+ private static final String _SQL_SELECT_BLOGCHANNEL = "SELECT blogChannel FROM BlogChannel blogChannel";
+ private static final String _SQL_SELECT_BLOGCHANNEL_WHERE = "SELECT blogChannel FROM BlogChannel blogChannel WHERE ";
+ private static final String _SQL_COUNT_BLOGCHANNEL = "SELECT COUNT(blogChannel) FROM BlogChannel blogChannel";
+ private static final String _SQL_COUNT_BLOGCHANNEL_WHERE = "SELECT COUNT(blogChannel) FROM BlogChannel blogChannel WHERE ";
+ private static final String _FINDER_COLUMN_USERID_USERID_2 = "blogChannel.userId = ?";
+ private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "blogChannel.groupId = ?";
+ private static final String _ORDER_BY_ENTITY_ALIAS = "blogChannel.";
+ private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No BlogChannel exists with the primary key ";
+ private static final String _NO_SUCH_ENTITY_WITH_KEY = "No BlogChannel exists with the key {";
+ private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = GetterUtil.getBoolean(PropsUtil.get(
+ PropsKeys.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE));
+ private static Log _log = LogFactoryUtil.getLog(BlogChannelPersistenceImpl.class);
+ private static BlogChannel _nullBlogChannel = new BlogChannelImpl() {
+ @Override
+ public Object clone() {
+ return this;
+ }
+
+ @Override
+ public CacheModel<BlogChannel> toCacheModel() {
+ return _nullBlogChannelCacheModel;
+ }
+ };
+
+ private static CacheModel<BlogChannel> _nullBlogChannelCacheModel = new CacheModel<BlogChannel>() {
+ public BlogChannel toEntityModel() {
+ return _nullBlogChannel;
+ }
+ };
+}
\ No newline at end of file