001    /**
002     * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.asset.service.persistence;
016    
017    import com.liferay.portal.NoSuchModelException;
018    import com.liferay.portal.kernel.bean.BeanReference;
019    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020    import com.liferay.portal.kernel.dao.jdbc.MappingSqlQuery;
021    import com.liferay.portal.kernel.dao.jdbc.MappingSqlQueryFactoryUtil;
022    import com.liferay.portal.kernel.dao.jdbc.RowMapper;
023    import com.liferay.portal.kernel.dao.jdbc.SqlUpdate;
024    import com.liferay.portal.kernel.dao.jdbc.SqlUpdateFactoryUtil;
025    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
026    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
027    import com.liferay.portal.kernel.dao.orm.FinderPath;
028    import com.liferay.portal.kernel.dao.orm.Query;
029    import com.liferay.portal.kernel.dao.orm.QueryPos;
030    import com.liferay.portal.kernel.dao.orm.QueryUtil;
031    import com.liferay.portal.kernel.dao.orm.SQLQuery;
032    import com.liferay.portal.kernel.dao.orm.Session;
033    import com.liferay.portal.kernel.exception.SystemException;
034    import com.liferay.portal.kernel.log.Log;
035    import com.liferay.portal.kernel.log.LogFactoryUtil;
036    import com.liferay.portal.kernel.util.GetterUtil;
037    import com.liferay.portal.kernel.util.InstanceFactory;
038    import com.liferay.portal.kernel.util.OrderByComparator;
039    import com.liferay.portal.kernel.util.SetUtil;
040    import com.liferay.portal.kernel.util.StringBundler;
041    import com.liferay.portal.kernel.util.StringPool;
042    import com.liferay.portal.kernel.util.StringUtil;
043    import com.liferay.portal.kernel.util.UnmodifiableList;
044    import com.liferay.portal.kernel.util.Validator;
045    import com.liferay.portal.model.CacheModel;
046    import com.liferay.portal.model.ModelListener;
047    import com.liferay.portal.security.permission.InlineSQLHelperUtil;
048    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
049    
050    import com.liferay.portlet.asset.NoSuchTagException;
051    import com.liferay.portlet.asset.model.AssetTag;
052    import com.liferay.portlet.asset.model.impl.AssetTagImpl;
053    import com.liferay.portlet.asset.model.impl.AssetTagModelImpl;
054    
055    import java.io.Serializable;
056    
057    import java.util.ArrayList;
058    import java.util.Collections;
059    import java.util.List;
060    import java.util.Set;
061    
062    /**
063     * The persistence implementation for the asset tag service.
064     *
065     * <p>
066     * Caching information and settings can be found in <code>portal.properties</code>
067     * </p>
068     *
069     * @author Brian Wing Shun Chan
070     * @see AssetTagPersistence
071     * @see AssetTagUtil
072     * @generated
073     */
074    public class AssetTagPersistenceImpl extends BasePersistenceImpl<AssetTag>
075            implements AssetTagPersistence {
076            /*
077             * NOTE FOR DEVELOPERS:
078             *
079             * Never modify or reference this class directly. Always use {@link AssetTagUtil} to access the asset tag persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
080             */
081            public static final String FINDER_CLASS_NAME_ENTITY = AssetTagImpl.class.getName();
082            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
083                    ".List1";
084            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
085                    ".List2";
086            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(AssetTagModelImpl.ENTITY_CACHE_ENABLED,
087                            AssetTagModelImpl.FINDER_CACHE_ENABLED, AssetTagImpl.class,
088                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
089            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(AssetTagModelImpl.ENTITY_CACHE_ENABLED,
090                            AssetTagModelImpl.FINDER_CACHE_ENABLED, AssetTagImpl.class,
091                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
092            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(AssetTagModelImpl.ENTITY_CACHE_ENABLED,
093                            AssetTagModelImpl.FINDER_CACHE_ENABLED, Long.class,
094                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
095            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(AssetTagModelImpl.ENTITY_CACHE_ENABLED,
096                            AssetTagModelImpl.FINDER_CACHE_ENABLED, AssetTagImpl.class,
097                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByGroupId",
098                            new String[] {
099                                    Long.class.getName(),
100                                    
101                            Integer.class.getName(), Integer.class.getName(),
102                                    OrderByComparator.class.getName()
103                            });
104            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
105                    new FinderPath(AssetTagModelImpl.ENTITY_CACHE_ENABLED,
106                            AssetTagModelImpl.FINDER_CACHE_ENABLED, AssetTagImpl.class,
107                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
108                            new String[] { Long.class.getName() },
109                            AssetTagModelImpl.GROUPID_COLUMN_BITMASK |
110                            AssetTagModelImpl.NAME_COLUMN_BITMASK);
111            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(AssetTagModelImpl.ENTITY_CACHE_ENABLED,
112                            AssetTagModelImpl.FINDER_CACHE_ENABLED, Long.class,
113                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
114                            new String[] { Long.class.getName() });
115    
116            /**
117             * Returns all the asset tags where groupId = &#63;.
118             *
119             * @param groupId the group ID
120             * @return the matching asset tags
121             * @throws SystemException if a system exception occurred
122             */
123            public List<AssetTag> findByGroupId(long groupId) throws SystemException {
124                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
125            }
126    
127            /**
128             * Returns a range of all the asset tags where groupId = &#63;.
129             *
130             * <p>
131             * 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. 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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.asset.model.impl.AssetTagModelImpl}. 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.
132             * </p>
133             *
134             * @param groupId the group ID
135             * @param start the lower bound of the range of asset tags
136             * @param end the upper bound of the range of asset tags (not inclusive)
137             * @return the range of matching asset tags
138             * @throws SystemException if a system exception occurred
139             */
140            public List<AssetTag> findByGroupId(long groupId, int start, int end)
141                    throws SystemException {
142                    return findByGroupId(groupId, start, end, null);
143            }
144    
145            /**
146             * Returns an ordered range of all the asset tags where groupId = &#63;.
147             *
148             * <p>
149             * 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. 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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.asset.model.impl.AssetTagModelImpl}. 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.
150             * </p>
151             *
152             * @param groupId the group ID
153             * @param start the lower bound of the range of asset tags
154             * @param end the upper bound of the range of asset tags (not inclusive)
155             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
156             * @return the ordered range of matching asset tags
157             * @throws SystemException if a system exception occurred
158             */
159            public List<AssetTag> findByGroupId(long groupId, int start, int end,
160                    OrderByComparator orderByComparator) throws SystemException {
161                    boolean pagination = true;
162                    FinderPath finderPath = null;
163                    Object[] finderArgs = null;
164    
165                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
166                                    (orderByComparator == null)) {
167                            pagination = false;
168                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
169                            finderArgs = new Object[] { groupId };
170                    }
171                    else {
172                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
173                            finderArgs = new Object[] { groupId, start, end, orderByComparator };
174                    }
175    
176                    List<AssetTag> list = (List<AssetTag>)FinderCacheUtil.getResult(finderPath,
177                                    finderArgs, this);
178    
179                    if ((list != null) && !list.isEmpty()) {
180                            for (AssetTag assetTag : list) {
181                                    if ((groupId != assetTag.getGroupId())) {
182                                            list = null;
183    
184                                            break;
185                                    }
186                            }
187                    }
188    
189                    if (list == null) {
190                            StringBundler query = null;
191    
192                            if (orderByComparator != null) {
193                                    query = new StringBundler(3 +
194                                                    (orderByComparator.getOrderByFields().length * 3));
195                            }
196                            else {
197                                    query = new StringBundler(3);
198                            }
199    
200                            query.append(_SQL_SELECT_ASSETTAG_WHERE);
201    
202                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
203    
204                            if (orderByComparator != null) {
205                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
206                                            orderByComparator);
207                            }
208                            else
209                             if (pagination) {
210                                    query.append(AssetTagModelImpl.ORDER_BY_JPQL);
211                            }
212    
213                            String sql = query.toString();
214    
215                            Session session = null;
216    
217                            try {
218                                    session = openSession();
219    
220                                    Query q = session.createQuery(sql);
221    
222                                    QueryPos qPos = QueryPos.getInstance(q);
223    
224                                    qPos.add(groupId);
225    
226                                    if (!pagination) {
227                                            list = (List<AssetTag>)QueryUtil.list(q, getDialect(),
228                                                            start, end, false);
229    
230                                            Collections.sort(list);
231    
232                                            list = new UnmodifiableList<AssetTag>(list);
233                                    }
234                                    else {
235                                            list = (List<AssetTag>)QueryUtil.list(q, getDialect(),
236                                                            start, end);
237                                    }
238    
239                                    cacheResult(list);
240    
241                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
242                            }
243                            catch (Exception e) {
244                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
245    
246                                    throw processException(e);
247                            }
248                            finally {
249                                    closeSession(session);
250                            }
251                    }
252    
253                    return list;
254            }
255    
256            /**
257             * Returns the first asset tag in the ordered set where groupId = &#63;.
258             *
259             * @param groupId the group ID
260             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
261             * @return the first matching asset tag
262             * @throws com.liferay.portlet.asset.NoSuchTagException if a matching asset tag could not be found
263             * @throws SystemException if a system exception occurred
264             */
265            public AssetTag findByGroupId_First(long groupId,
266                    OrderByComparator orderByComparator)
267                    throws NoSuchTagException, SystemException {
268                    AssetTag assetTag = fetchByGroupId_First(groupId, orderByComparator);
269    
270                    if (assetTag != null) {
271                            return assetTag;
272                    }
273    
274                    StringBundler msg = new StringBundler(4);
275    
276                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
277    
278                    msg.append("groupId=");
279                    msg.append(groupId);
280    
281                    msg.append(StringPool.CLOSE_CURLY_BRACE);
282    
283                    throw new NoSuchTagException(msg.toString());
284            }
285    
286            /**
287             * Returns the first asset tag in the ordered set where groupId = &#63;.
288             *
289             * @param groupId the group ID
290             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
291             * @return the first matching asset tag, or <code>null</code> if a matching asset tag could not be found
292             * @throws SystemException if a system exception occurred
293             */
294            public AssetTag fetchByGroupId_First(long groupId,
295                    OrderByComparator orderByComparator) throws SystemException {
296                    List<AssetTag> list = findByGroupId(groupId, 0, 1, orderByComparator);
297    
298                    if (!list.isEmpty()) {
299                            return list.get(0);
300                    }
301    
302                    return null;
303            }
304    
305            /**
306             * Returns the last asset tag in the ordered set where groupId = &#63;.
307             *
308             * @param groupId the group ID
309             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
310             * @return the last matching asset tag
311             * @throws com.liferay.portlet.asset.NoSuchTagException if a matching asset tag could not be found
312             * @throws SystemException if a system exception occurred
313             */
314            public AssetTag findByGroupId_Last(long groupId,
315                    OrderByComparator orderByComparator)
316                    throws NoSuchTagException, SystemException {
317                    AssetTag assetTag = fetchByGroupId_Last(groupId, orderByComparator);
318    
319                    if (assetTag != null) {
320                            return assetTag;
321                    }
322    
323                    StringBundler msg = new StringBundler(4);
324    
325                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
326    
327                    msg.append("groupId=");
328                    msg.append(groupId);
329    
330                    msg.append(StringPool.CLOSE_CURLY_BRACE);
331    
332                    throw new NoSuchTagException(msg.toString());
333            }
334    
335            /**
336             * Returns the last asset tag in the ordered set where groupId = &#63;.
337             *
338             * @param groupId the group ID
339             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
340             * @return the last matching asset tag, or <code>null</code> if a matching asset tag could not be found
341             * @throws SystemException if a system exception occurred
342             */
343            public AssetTag fetchByGroupId_Last(long groupId,
344                    OrderByComparator orderByComparator) throws SystemException {
345                    int count = countByGroupId(groupId);
346    
347                    List<AssetTag> list = findByGroupId(groupId, count - 1, count,
348                                    orderByComparator);
349    
350                    if (!list.isEmpty()) {
351                            return list.get(0);
352                    }
353    
354                    return null;
355            }
356    
357            /**
358             * Returns the asset tags before and after the current asset tag in the ordered set where groupId = &#63;.
359             *
360             * @param tagId the primary key of the current asset tag
361             * @param groupId the group ID
362             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
363             * @return the previous, current, and next asset tag
364             * @throws com.liferay.portlet.asset.NoSuchTagException if a asset tag with the primary key could not be found
365             * @throws SystemException if a system exception occurred
366             */
367            public AssetTag[] findByGroupId_PrevAndNext(long tagId, long groupId,
368                    OrderByComparator orderByComparator)
369                    throws NoSuchTagException, SystemException {
370                    AssetTag assetTag = findByPrimaryKey(tagId);
371    
372                    Session session = null;
373    
374                    try {
375                            session = openSession();
376    
377                            AssetTag[] array = new AssetTagImpl[3];
378    
379                            array[0] = getByGroupId_PrevAndNext(session, assetTag, groupId,
380                                            orderByComparator, true);
381    
382                            array[1] = assetTag;
383    
384                            array[2] = getByGroupId_PrevAndNext(session, assetTag, groupId,
385                                            orderByComparator, false);
386    
387                            return array;
388                    }
389                    catch (Exception e) {
390                            throw processException(e);
391                    }
392                    finally {
393                            closeSession(session);
394                    }
395            }
396    
397            protected AssetTag getByGroupId_PrevAndNext(Session session,
398                    AssetTag assetTag, long groupId, OrderByComparator orderByComparator,
399                    boolean previous) {
400                    StringBundler query = null;
401    
402                    if (orderByComparator != null) {
403                            query = new StringBundler(6 +
404                                            (orderByComparator.getOrderByFields().length * 6));
405                    }
406                    else {
407                            query = new StringBundler(3);
408                    }
409    
410                    query.append(_SQL_SELECT_ASSETTAG_WHERE);
411    
412                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
413    
414                    if (orderByComparator != null) {
415                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
416    
417                            if (orderByConditionFields.length > 0) {
418                                    query.append(WHERE_AND);
419                            }
420    
421                            for (int i = 0; i < orderByConditionFields.length; i++) {
422                                    query.append(_ORDER_BY_ENTITY_ALIAS);
423                                    query.append(orderByConditionFields[i]);
424    
425                                    if ((i + 1) < orderByConditionFields.length) {
426                                            if (orderByComparator.isAscending() ^ previous) {
427                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
428                                            }
429                                            else {
430                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
431                                            }
432                                    }
433                                    else {
434                                            if (orderByComparator.isAscending() ^ previous) {
435                                                    query.append(WHERE_GREATER_THAN);
436                                            }
437                                            else {
438                                                    query.append(WHERE_LESSER_THAN);
439                                            }
440                                    }
441                            }
442    
443                            query.append(ORDER_BY_CLAUSE);
444    
445                            String[] orderByFields = orderByComparator.getOrderByFields();
446    
447                            for (int i = 0; i < orderByFields.length; i++) {
448                                    query.append(_ORDER_BY_ENTITY_ALIAS);
449                                    query.append(orderByFields[i]);
450    
451                                    if ((i + 1) < orderByFields.length) {
452                                            if (orderByComparator.isAscending() ^ previous) {
453                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
454                                            }
455                                            else {
456                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
457                                            }
458                                    }
459                                    else {
460                                            if (orderByComparator.isAscending() ^ previous) {
461                                                    query.append(ORDER_BY_ASC);
462                                            }
463                                            else {
464                                                    query.append(ORDER_BY_DESC);
465                                            }
466                                    }
467                            }
468                    }
469                    else {
470                            query.append(AssetTagModelImpl.ORDER_BY_JPQL);
471                    }
472    
473                    String sql = query.toString();
474    
475                    Query q = session.createQuery(sql);
476    
477                    q.setFirstResult(0);
478                    q.setMaxResults(2);
479    
480                    QueryPos qPos = QueryPos.getInstance(q);
481    
482                    qPos.add(groupId);
483    
484                    if (orderByComparator != null) {
485                            Object[] values = orderByComparator.getOrderByConditionValues(assetTag);
486    
487                            for (Object value : values) {
488                                    qPos.add(value);
489                            }
490                    }
491    
492                    List<AssetTag> list = q.list();
493    
494                    if (list.size() == 2) {
495                            return list.get(1);
496                    }
497                    else {
498                            return null;
499                    }
500            }
501    
502            /**
503             * Returns all the asset tags that the user has permission to view where groupId = &#63;.
504             *
505             * @param groupId the group ID
506             * @return the matching asset tags that the user has permission to view
507             * @throws SystemException if a system exception occurred
508             */
509            public List<AssetTag> filterFindByGroupId(long groupId)
510                    throws SystemException {
511                    return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
512                            QueryUtil.ALL_POS, null);
513            }
514    
515            /**
516             * Returns a range of all the asset tags that the user has permission to view where groupId = &#63;.
517             *
518             * <p>
519             * 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. 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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.asset.model.impl.AssetTagModelImpl}. 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.
520             * </p>
521             *
522             * @param groupId the group ID
523             * @param start the lower bound of the range of asset tags
524             * @param end the upper bound of the range of asset tags (not inclusive)
525             * @return the range of matching asset tags that the user has permission to view
526             * @throws SystemException if a system exception occurred
527             */
528            public List<AssetTag> filterFindByGroupId(long groupId, int start, int end)
529                    throws SystemException {
530                    return filterFindByGroupId(groupId, start, end, null);
531            }
532    
533            /**
534             * Returns an ordered range of all the asset tags that the user has permissions to view where groupId = &#63;.
535             *
536             * <p>
537             * 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. 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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.asset.model.impl.AssetTagModelImpl}. 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.
538             * </p>
539             *
540             * @param groupId the group ID
541             * @param start the lower bound of the range of asset tags
542             * @param end the upper bound of the range of asset tags (not inclusive)
543             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
544             * @return the ordered range of matching asset tags that the user has permission to view
545             * @throws SystemException if a system exception occurred
546             */
547            public List<AssetTag> filterFindByGroupId(long groupId, int start, int end,
548                    OrderByComparator orderByComparator) throws SystemException {
549                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
550                            return findByGroupId(groupId, start, end, orderByComparator);
551                    }
552    
553                    StringBundler query = null;
554    
555                    if (orderByComparator != null) {
556                            query = new StringBundler(3 +
557                                            (orderByComparator.getOrderByFields().length * 3));
558                    }
559                    else {
560                            query = new StringBundler(3);
561                    }
562    
563                    if (getDB().isSupportsInlineDistinct()) {
564                            query.append(_FILTER_SQL_SELECT_ASSETTAG_WHERE);
565                    }
566                    else {
567                            query.append(_FILTER_SQL_SELECT_ASSETTAG_NO_INLINE_DISTINCT_WHERE_1);
568                    }
569    
570                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
571    
572                    if (!getDB().isSupportsInlineDistinct()) {
573                            query.append(_FILTER_SQL_SELECT_ASSETTAG_NO_INLINE_DISTINCT_WHERE_2);
574                    }
575    
576                    if (orderByComparator != null) {
577                            if (getDB().isSupportsInlineDistinct()) {
578                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
579                                            orderByComparator);
580                            }
581                            else {
582                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
583                                            orderByComparator);
584                            }
585                    }
586                    else {
587                            if (getDB().isSupportsInlineDistinct()) {
588                                    query.append(AssetTagModelImpl.ORDER_BY_JPQL);
589                            }
590                            else {
591                                    query.append(AssetTagModelImpl.ORDER_BY_SQL);
592                            }
593                    }
594    
595                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
596                                    AssetTag.class.getName(),
597                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
598    
599                    Session session = null;
600    
601                    try {
602                            session = openSession();
603    
604                            SQLQuery q = session.createSQLQuery(sql);
605    
606                            if (getDB().isSupportsInlineDistinct()) {
607                                    q.addEntity(_FILTER_ENTITY_ALIAS, AssetTagImpl.class);
608                            }
609                            else {
610                                    q.addEntity(_FILTER_ENTITY_TABLE, AssetTagImpl.class);
611                            }
612    
613                            QueryPos qPos = QueryPos.getInstance(q);
614    
615                            qPos.add(groupId);
616    
617                            return (List<AssetTag>)QueryUtil.list(q, getDialect(), start, end);
618                    }
619                    catch (Exception e) {
620                            throw processException(e);
621                    }
622                    finally {
623                            closeSession(session);
624                    }
625            }
626    
627            /**
628             * Returns the asset tags before and after the current asset tag in the ordered set of asset tags that the user has permission to view where groupId = &#63;.
629             *
630             * @param tagId the primary key of the current asset tag
631             * @param groupId the group ID
632             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
633             * @return the previous, current, and next asset tag
634             * @throws com.liferay.portlet.asset.NoSuchTagException if a asset tag with the primary key could not be found
635             * @throws SystemException if a system exception occurred
636             */
637            public AssetTag[] filterFindByGroupId_PrevAndNext(long tagId, long groupId,
638                    OrderByComparator orderByComparator)
639                    throws NoSuchTagException, SystemException {
640                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
641                            return findByGroupId_PrevAndNext(tagId, groupId, orderByComparator);
642                    }
643    
644                    AssetTag assetTag = findByPrimaryKey(tagId);
645    
646                    Session session = null;
647    
648                    try {
649                            session = openSession();
650    
651                            AssetTag[] array = new AssetTagImpl[3];
652    
653                            array[0] = filterGetByGroupId_PrevAndNext(session, assetTag,
654                                            groupId, orderByComparator, true);
655    
656                            array[1] = assetTag;
657    
658                            array[2] = filterGetByGroupId_PrevAndNext(session, assetTag,
659                                            groupId, orderByComparator, false);
660    
661                            return array;
662                    }
663                    catch (Exception e) {
664                            throw processException(e);
665                    }
666                    finally {
667                            closeSession(session);
668                    }
669            }
670    
671            protected AssetTag filterGetByGroupId_PrevAndNext(Session session,
672                    AssetTag assetTag, long groupId, OrderByComparator orderByComparator,
673                    boolean previous) {
674                    StringBundler query = null;
675    
676                    if (orderByComparator != null) {
677                            query = new StringBundler(6 +
678                                            (orderByComparator.getOrderByFields().length * 6));
679                    }
680                    else {
681                            query = new StringBundler(3);
682                    }
683    
684                    if (getDB().isSupportsInlineDistinct()) {
685                            query.append(_FILTER_SQL_SELECT_ASSETTAG_WHERE);
686                    }
687                    else {
688                            query.append(_FILTER_SQL_SELECT_ASSETTAG_NO_INLINE_DISTINCT_WHERE_1);
689                    }
690    
691                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
692    
693                    if (!getDB().isSupportsInlineDistinct()) {
694                            query.append(_FILTER_SQL_SELECT_ASSETTAG_NO_INLINE_DISTINCT_WHERE_2);
695                    }
696    
697                    if (orderByComparator != null) {
698                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
699    
700                            if (orderByConditionFields.length > 0) {
701                                    query.append(WHERE_AND);
702                            }
703    
704                            for (int i = 0; i < orderByConditionFields.length; i++) {
705                                    if (getDB().isSupportsInlineDistinct()) {
706                                            query.append(_ORDER_BY_ENTITY_ALIAS);
707                                    }
708                                    else {
709                                            query.append(_ORDER_BY_ENTITY_TABLE);
710                                    }
711    
712                                    query.append(orderByConditionFields[i]);
713    
714                                    if ((i + 1) < orderByConditionFields.length) {
715                                            if (orderByComparator.isAscending() ^ previous) {
716                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
717                                            }
718                                            else {
719                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
720                                            }
721                                    }
722                                    else {
723                                            if (orderByComparator.isAscending() ^ previous) {
724                                                    query.append(WHERE_GREATER_THAN);
725                                            }
726                                            else {
727                                                    query.append(WHERE_LESSER_THAN);
728                                            }
729                                    }
730                            }
731    
732                            query.append(ORDER_BY_CLAUSE);
733    
734                            String[] orderByFields = orderByComparator.getOrderByFields();
735    
736                            for (int i = 0; i < orderByFields.length; i++) {
737                                    if (getDB().isSupportsInlineDistinct()) {
738                                            query.append(_ORDER_BY_ENTITY_ALIAS);
739                                    }
740                                    else {
741                                            query.append(_ORDER_BY_ENTITY_TABLE);
742                                    }
743    
744                                    query.append(orderByFields[i]);
745    
746                                    if ((i + 1) < orderByFields.length) {
747                                            if (orderByComparator.isAscending() ^ previous) {
748                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
749                                            }
750                                            else {
751                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
752                                            }
753                                    }
754                                    else {
755                                            if (orderByComparator.isAscending() ^ previous) {
756                                                    query.append(ORDER_BY_ASC);
757                                            }
758                                            else {
759                                                    query.append(ORDER_BY_DESC);
760                                            }
761                                    }
762                            }
763                    }
764                    else {
765                            if (getDB().isSupportsInlineDistinct()) {
766                                    query.append(AssetTagModelImpl.ORDER_BY_JPQL);
767                            }
768                            else {
769                                    query.append(AssetTagModelImpl.ORDER_BY_SQL);
770                            }
771                    }
772    
773                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
774                                    AssetTag.class.getName(),
775                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
776    
777                    SQLQuery q = session.createSQLQuery(sql);
778    
779                    q.setFirstResult(0);
780                    q.setMaxResults(2);
781    
782                    if (getDB().isSupportsInlineDistinct()) {
783                            q.addEntity(_FILTER_ENTITY_ALIAS, AssetTagImpl.class);
784                    }
785                    else {
786                            q.addEntity(_FILTER_ENTITY_TABLE, AssetTagImpl.class);
787                    }
788    
789                    QueryPos qPos = QueryPos.getInstance(q);
790    
791                    qPos.add(groupId);
792    
793                    if (orderByComparator != null) {
794                            Object[] values = orderByComparator.getOrderByConditionValues(assetTag);
795    
796                            for (Object value : values) {
797                                    qPos.add(value);
798                            }
799                    }
800    
801                    List<AssetTag> list = q.list();
802    
803                    if (list.size() == 2) {
804                            return list.get(1);
805                    }
806                    else {
807                            return null;
808                    }
809            }
810    
811            /**
812             * Removes all the asset tags where groupId = &#63; from the database.
813             *
814             * @param groupId the group ID
815             * @throws SystemException if a system exception occurred
816             */
817            public void removeByGroupId(long groupId) throws SystemException {
818                    for (AssetTag assetTag : findByGroupId(groupId, QueryUtil.ALL_POS,
819                                    QueryUtil.ALL_POS, null)) {
820                            remove(assetTag);
821                    }
822            }
823    
824            /**
825             * Returns the number of asset tags where groupId = &#63;.
826             *
827             * @param groupId the group ID
828             * @return the number of matching asset tags
829             * @throws SystemException if a system exception occurred
830             */
831            public int countByGroupId(long groupId) throws SystemException {
832                    FinderPath finderPath = FINDER_PATH_COUNT_BY_GROUPID;
833    
834                    Object[] finderArgs = new Object[] { groupId };
835    
836                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
837                                    this);
838    
839                    if (count == null) {
840                            StringBundler query = new StringBundler(2);
841    
842                            query.append(_SQL_COUNT_ASSETTAG_WHERE);
843    
844                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
845    
846                            String sql = query.toString();
847    
848                            Session session = null;
849    
850                            try {
851                                    session = openSession();
852    
853                                    Query q = session.createQuery(sql);
854    
855                                    QueryPos qPos = QueryPos.getInstance(q);
856    
857                                    qPos.add(groupId);
858    
859                                    count = (Long)q.uniqueResult();
860    
861                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
862                            }
863                            catch (Exception e) {
864                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
865    
866                                    throw processException(e);
867                            }
868                            finally {
869                                    closeSession(session);
870                            }
871                    }
872    
873                    return count.intValue();
874            }
875    
876            /**
877             * Returns the number of asset tags that the user has permission to view where groupId = &#63;.
878             *
879             * @param groupId the group ID
880             * @return the number of matching asset tags that the user has permission to view
881             * @throws SystemException if a system exception occurred
882             */
883            public int filterCountByGroupId(long groupId) throws SystemException {
884                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
885                            return countByGroupId(groupId);
886                    }
887    
888                    StringBundler query = new StringBundler(2);
889    
890                    query.append(_FILTER_SQL_COUNT_ASSETTAG_WHERE);
891    
892                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
893    
894                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
895                                    AssetTag.class.getName(),
896                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
897    
898                    Session session = null;
899    
900                    try {
901                            session = openSession();
902    
903                            SQLQuery q = session.createSQLQuery(sql);
904    
905                            q.addScalar(COUNT_COLUMN_NAME,
906                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
907    
908                            QueryPos qPos = QueryPos.getInstance(q);
909    
910                            qPos.add(groupId);
911    
912                            Long count = (Long)q.uniqueResult();
913    
914                            return count.intValue();
915                    }
916                    catch (Exception e) {
917                            throw processException(e);
918                    }
919                    finally {
920                            closeSession(session);
921                    }
922            }
923    
924            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "assetTag.groupId = ?";
925            public static final FinderPath FINDER_PATH_FETCH_BY_G_N = new FinderPath(AssetTagModelImpl.ENTITY_CACHE_ENABLED,
926                            AssetTagModelImpl.FINDER_CACHE_ENABLED, AssetTagImpl.class,
927                            FINDER_CLASS_NAME_ENTITY, "fetchByG_N",
928                            new String[] { Long.class.getName(), String.class.getName() },
929                            AssetTagModelImpl.GROUPID_COLUMN_BITMASK |
930                            AssetTagModelImpl.NAME_COLUMN_BITMASK);
931            public static final FinderPath FINDER_PATH_COUNT_BY_G_N = new FinderPath(AssetTagModelImpl.ENTITY_CACHE_ENABLED,
932                            AssetTagModelImpl.FINDER_CACHE_ENABLED, Long.class,
933                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_N",
934                            new String[] { Long.class.getName(), String.class.getName() });
935    
936            /**
937             * Returns the asset tag where groupId = &#63; and name = &#63; or throws a {@link com.liferay.portlet.asset.NoSuchTagException} if it could not be found.
938             *
939             * @param groupId the group ID
940             * @param name the name
941             * @return the matching asset tag
942             * @throws com.liferay.portlet.asset.NoSuchTagException if a matching asset tag could not be found
943             * @throws SystemException if a system exception occurred
944             */
945            public AssetTag findByG_N(long groupId, String name)
946                    throws NoSuchTagException, SystemException {
947                    AssetTag assetTag = fetchByG_N(groupId, name);
948    
949                    if (assetTag == null) {
950                            StringBundler msg = new StringBundler(6);
951    
952                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
953    
954                            msg.append("groupId=");
955                            msg.append(groupId);
956    
957                            msg.append(", name=");
958                            msg.append(name);
959    
960                            msg.append(StringPool.CLOSE_CURLY_BRACE);
961    
962                            if (_log.isWarnEnabled()) {
963                                    _log.warn(msg.toString());
964                            }
965    
966                            throw new NoSuchTagException(msg.toString());
967                    }
968    
969                    return assetTag;
970            }
971    
972            /**
973             * Returns the asset tag where groupId = &#63; and name = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
974             *
975             * @param groupId the group ID
976             * @param name the name
977             * @return the matching asset tag, or <code>null</code> if a matching asset tag could not be found
978             * @throws SystemException if a system exception occurred
979             */
980            public AssetTag fetchByG_N(long groupId, String name)
981                    throws SystemException {
982                    return fetchByG_N(groupId, name, true);
983            }
984    
985            /**
986             * Returns the asset tag where groupId = &#63; and name = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
987             *
988             * @param groupId the group ID
989             * @param name the name
990             * @param retrieveFromCache whether to use the finder cache
991             * @return the matching asset tag, or <code>null</code> if a matching asset tag could not be found
992             * @throws SystemException if a system exception occurred
993             */
994            public AssetTag fetchByG_N(long groupId, String name,
995                    boolean retrieveFromCache) throws SystemException {
996                    Object[] finderArgs = new Object[] { groupId, name };
997    
998                    Object result = null;
999    
1000                    if (retrieveFromCache) {
1001                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_N,
1002                                            finderArgs, this);
1003                    }
1004    
1005                    if (result instanceof AssetTag) {
1006                            AssetTag assetTag = (AssetTag)result;
1007    
1008                            if ((groupId != assetTag.getGroupId()) ||
1009                                            !Validator.equals(name, assetTag.getName())) {
1010                                    result = null;
1011                            }
1012                    }
1013    
1014                    if (result == null) {
1015                            StringBundler query = new StringBundler(4);
1016    
1017                            query.append(_SQL_SELECT_ASSETTAG_WHERE);
1018    
1019                            query.append(_FINDER_COLUMN_G_N_GROUPID_2);
1020    
1021                            if (name == null) {
1022                                    query.append(_FINDER_COLUMN_G_N_NAME_1);
1023                            }
1024                            else {
1025                                    if (name.equals(StringPool.BLANK)) {
1026                                            query.append(_FINDER_COLUMN_G_N_NAME_3);
1027                                    }
1028                                    else {
1029                                            query.append(_FINDER_COLUMN_G_N_NAME_2);
1030                                    }
1031                            }
1032    
1033                            String sql = query.toString();
1034    
1035                            Session session = null;
1036    
1037                            try {
1038                                    session = openSession();
1039    
1040                                    Query q = session.createQuery(sql);
1041    
1042                                    QueryPos qPos = QueryPos.getInstance(q);
1043    
1044                                    qPos.add(groupId);
1045    
1046                                    if (name != null) {
1047                                            qPos.add(name);
1048                                    }
1049    
1050                                    List<AssetTag> list = q.list();
1051    
1052                                    if (list.isEmpty()) {
1053                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N,
1054                                                    finderArgs, list);
1055                                    }
1056                                    else {
1057                                            if ((list.size() > 1) && _log.isWarnEnabled()) {
1058                                                    _log.warn(
1059                                                            "AssetTagPersistenceImpl.fetchByG_N(long, String, boolean) with parameters (" +
1060                                                            StringUtil.merge(finderArgs) +
1061                                                            ") yields a result set with more than 1 result. This violates the logical unique restriction. There is no order guarantee on which result is returned by this finder.");
1062                                            }
1063    
1064                                            AssetTag assetTag = list.get(0);
1065    
1066                                            result = assetTag;
1067    
1068                                            cacheResult(assetTag);
1069    
1070                                            if ((assetTag.getGroupId() != groupId) ||
1071                                                            (assetTag.getName() == null) ||
1072                                                            !assetTag.getName().equals(name)) {
1073                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N,
1074                                                            finderArgs, assetTag);
1075                                            }
1076                                    }
1077                            }
1078                            catch (Exception e) {
1079                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_N,
1080                                            finderArgs);
1081    
1082                                    throw processException(e);
1083                            }
1084                            finally {
1085                                    closeSession(session);
1086                            }
1087                    }
1088    
1089                    if (result instanceof List<?>) {
1090                            return null;
1091                    }
1092                    else {
1093                            return (AssetTag)result;
1094                    }
1095            }
1096    
1097            /**
1098             * Removes the asset tag where groupId = &#63; and name = &#63; from the database.
1099             *
1100             * @param groupId the group ID
1101             * @param name the name
1102             * @return the asset tag that was removed
1103             * @throws SystemException if a system exception occurred
1104             */
1105            public AssetTag removeByG_N(long groupId, String name)
1106                    throws NoSuchTagException, SystemException {
1107                    AssetTag assetTag = findByG_N(groupId, name);
1108    
1109                    return remove(assetTag);
1110            }
1111    
1112            /**
1113             * Returns the number of asset tags where groupId = &#63; and name = &#63;.
1114             *
1115             * @param groupId the group ID
1116             * @param name the name
1117             * @return the number of matching asset tags
1118             * @throws SystemException if a system exception occurred
1119             */
1120            public int countByG_N(long groupId, String name) throws SystemException {
1121                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_N;
1122    
1123                    Object[] finderArgs = new Object[] { groupId, name };
1124    
1125                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1126                                    this);
1127    
1128                    if (count == null) {
1129                            StringBundler query = new StringBundler(3);
1130    
1131                            query.append(_SQL_COUNT_ASSETTAG_WHERE);
1132    
1133                            query.append(_FINDER_COLUMN_G_N_GROUPID_2);
1134    
1135                            if (name == null) {
1136                                    query.append(_FINDER_COLUMN_G_N_NAME_1);
1137                            }
1138                            else {
1139                                    if (name.equals(StringPool.BLANK)) {
1140                                            query.append(_FINDER_COLUMN_G_N_NAME_3);
1141                                    }
1142                                    else {
1143                                            query.append(_FINDER_COLUMN_G_N_NAME_2);
1144                                    }
1145                            }
1146    
1147                            String sql = query.toString();
1148    
1149                            Session session = null;
1150    
1151                            try {
1152                                    session = openSession();
1153    
1154                                    Query q = session.createQuery(sql);
1155    
1156                                    QueryPos qPos = QueryPos.getInstance(q);
1157    
1158                                    qPos.add(groupId);
1159    
1160                                    if (name != null) {
1161                                            qPos.add(name);
1162                                    }
1163    
1164                                    count = (Long)q.uniqueResult();
1165    
1166                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1167                            }
1168                            catch (Exception e) {
1169                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1170    
1171                                    throw processException(e);
1172                            }
1173                            finally {
1174                                    closeSession(session);
1175                            }
1176                    }
1177    
1178                    return count.intValue();
1179            }
1180    
1181            private static final String _FINDER_COLUMN_G_N_GROUPID_2 = "assetTag.groupId = ? AND ";
1182            private static final String _FINDER_COLUMN_G_N_NAME_1 = "assetTag.name IS NULL";
1183            private static final String _FINDER_COLUMN_G_N_NAME_2 = "assetTag.name = ?";
1184            private static final String _FINDER_COLUMN_G_N_NAME_3 = "(assetTag.name IS NULL OR assetTag.name = ?)";
1185    
1186            /**
1187             * Caches the asset tag in the entity cache if it is enabled.
1188             *
1189             * @param assetTag the asset tag
1190             */
1191            public void cacheResult(AssetTag assetTag) {
1192                    EntityCacheUtil.putResult(AssetTagModelImpl.ENTITY_CACHE_ENABLED,
1193                            AssetTagImpl.class, assetTag.getPrimaryKey(), assetTag);
1194    
1195                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N,
1196                            new Object[] { Long.valueOf(assetTag.getGroupId()), assetTag.getName() },
1197                            assetTag);
1198    
1199                    assetTag.resetOriginalValues();
1200            }
1201    
1202            /**
1203             * Caches the asset tags in the entity cache if it is enabled.
1204             *
1205             * @param assetTags the asset tags
1206             */
1207            public void cacheResult(List<AssetTag> assetTags) {
1208                    for (AssetTag assetTag : assetTags) {
1209                            if (EntityCacheUtil.getResult(
1210                                                    AssetTagModelImpl.ENTITY_CACHE_ENABLED,
1211                                                    AssetTagImpl.class, assetTag.getPrimaryKey()) == null) {
1212                                    cacheResult(assetTag);
1213                            }
1214                            else {
1215                                    assetTag.resetOriginalValues();
1216                            }
1217                    }
1218            }
1219    
1220            /**
1221             * Clears the cache for all asset tags.
1222             *
1223             * <p>
1224             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
1225             * </p>
1226             */
1227            @Override
1228            public void clearCache() {
1229                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
1230                            CacheRegistryUtil.clear(AssetTagImpl.class.getName());
1231                    }
1232    
1233                    EntityCacheUtil.clearCache(AssetTagImpl.class.getName());
1234    
1235                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
1236                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1237                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1238            }
1239    
1240            /**
1241             * Clears the cache for the asset tag.
1242             *
1243             * <p>
1244             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
1245             * </p>
1246             */
1247            @Override
1248            public void clearCache(AssetTag assetTag) {
1249                    EntityCacheUtil.removeResult(AssetTagModelImpl.ENTITY_CACHE_ENABLED,
1250                            AssetTagImpl.class, assetTag.getPrimaryKey());
1251    
1252                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1253                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1254    
1255                    clearUniqueFindersCache(assetTag);
1256            }
1257    
1258            @Override
1259            public void clearCache(List<AssetTag> assetTags) {
1260                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1261                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1262    
1263                    for (AssetTag assetTag : assetTags) {
1264                            EntityCacheUtil.removeResult(AssetTagModelImpl.ENTITY_CACHE_ENABLED,
1265                                    AssetTagImpl.class, assetTag.getPrimaryKey());
1266    
1267                            clearUniqueFindersCache(assetTag);
1268                    }
1269            }
1270    
1271            protected void cacheUniqueFindersCache(AssetTag assetTag) {
1272                    if (assetTag.isNew()) {
1273                            Object[] args = new Object[] {
1274                                            Long.valueOf(assetTag.getGroupId()),
1275                                            
1276                                            assetTag.getName()
1277                                    };
1278    
1279                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_N, args,
1280                                    Long.valueOf(1));
1281                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N, args, assetTag);
1282                    }
1283                    else {
1284                            AssetTagModelImpl assetTagModelImpl = (AssetTagModelImpl)assetTag;
1285    
1286                            if ((assetTagModelImpl.getColumnBitmask() &
1287                                            FINDER_PATH_FETCH_BY_G_N.getColumnBitmask()) != 0) {
1288                                    Object[] args = new Object[] {
1289                                                    Long.valueOf(assetTag.getGroupId()),
1290                                                    
1291                                                    assetTag.getName()
1292                                            };
1293    
1294                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_N, args,
1295                                            Long.valueOf(1));
1296                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N, args,
1297                                            assetTag);
1298                            }
1299                    }
1300            }
1301    
1302            protected void clearUniqueFindersCache(AssetTag assetTag) {
1303                    AssetTagModelImpl assetTagModelImpl = (AssetTagModelImpl)assetTag;
1304    
1305                    Object[] args = new Object[] {
1306                                    Long.valueOf(assetTag.getGroupId()),
1307                                    
1308                                    assetTag.getName()
1309                            };
1310    
1311                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N, args);
1312                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_N, args);
1313    
1314                    if ((assetTagModelImpl.getColumnBitmask() &
1315                                    FINDER_PATH_FETCH_BY_G_N.getColumnBitmask()) != 0) {
1316                            args = new Object[] {
1317                                            Long.valueOf(assetTagModelImpl.getOriginalGroupId()),
1318                                            
1319                                            assetTagModelImpl.getOriginalName()
1320                                    };
1321    
1322                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N, args);
1323                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_N, args);
1324                    }
1325            }
1326    
1327            /**
1328             * Creates a new asset tag with the primary key. Does not add the asset tag to the database.
1329             *
1330             * @param tagId the primary key for the new asset tag
1331             * @return the new asset tag
1332             */
1333            public AssetTag create(long tagId) {
1334                    AssetTag assetTag = new AssetTagImpl();
1335    
1336                    assetTag.setNew(true);
1337                    assetTag.setPrimaryKey(tagId);
1338    
1339                    return assetTag;
1340            }
1341    
1342            /**
1343             * Removes the asset tag with the primary key from the database. Also notifies the appropriate model listeners.
1344             *
1345             * @param tagId the primary key of the asset tag
1346             * @return the asset tag that was removed
1347             * @throws com.liferay.portlet.asset.NoSuchTagException if a asset tag with the primary key could not be found
1348             * @throws SystemException if a system exception occurred
1349             */
1350            public AssetTag remove(long tagId)
1351                    throws NoSuchTagException, SystemException {
1352                    return remove(Long.valueOf(tagId));
1353            }
1354    
1355            /**
1356             * Removes the asset tag with the primary key from the database. Also notifies the appropriate model listeners.
1357             *
1358             * @param primaryKey the primary key of the asset tag
1359             * @return the asset tag that was removed
1360             * @throws com.liferay.portlet.asset.NoSuchTagException if a asset tag with the primary key could not be found
1361             * @throws SystemException if a system exception occurred
1362             */
1363            @Override
1364            public AssetTag remove(Serializable primaryKey)
1365                    throws NoSuchTagException, SystemException {
1366                    Session session = null;
1367    
1368                    try {
1369                            session = openSession();
1370    
1371                            AssetTag assetTag = (AssetTag)session.get(AssetTagImpl.class,
1372                                            primaryKey);
1373    
1374                            if (assetTag == null) {
1375                                    if (_log.isWarnEnabled()) {
1376                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1377                                    }
1378    
1379                                    throw new NoSuchTagException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1380                                            primaryKey);
1381                            }
1382    
1383                            return remove(assetTag);
1384                    }
1385                    catch (NoSuchTagException nsee) {
1386                            throw nsee;
1387                    }
1388                    catch (Exception e) {
1389                            throw processException(e);
1390                    }
1391                    finally {
1392                            closeSession(session);
1393                    }
1394            }
1395    
1396            @Override
1397            protected AssetTag removeImpl(AssetTag assetTag) throws SystemException {
1398                    assetTag = toUnwrappedModel(assetTag);
1399    
1400                    try {
1401                            clearAssetEntries.clear(assetTag.getPrimaryKey());
1402                    }
1403                    catch (Exception e) {
1404                            throw processException(e);
1405                    }
1406                    finally {
1407                            FinderCacheUtil.clearCache(AssetTagModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETTAGS_NAME);
1408                    }
1409    
1410                    Session session = null;
1411    
1412                    try {
1413                            session = openSession();
1414    
1415                            if (!session.contains(assetTag)) {
1416                                    assetTag = (AssetTag)session.get(AssetTagImpl.class,
1417                                                    assetTag.getPrimaryKeyObj());
1418                            }
1419    
1420                            if (assetTag != null) {
1421                                    session.delete(assetTag);
1422                            }
1423                    }
1424                    catch (Exception e) {
1425                            throw processException(e);
1426                    }
1427                    finally {
1428                            closeSession(session);
1429                    }
1430    
1431                    if (assetTag != null) {
1432                            clearCache(assetTag);
1433                    }
1434    
1435                    return assetTag;
1436            }
1437    
1438            @Override
1439            public AssetTag updateImpl(
1440                    com.liferay.portlet.asset.model.AssetTag assetTag)
1441                    throws SystemException {
1442                    assetTag = toUnwrappedModel(assetTag);
1443    
1444                    boolean isNew = assetTag.isNew();
1445    
1446                    AssetTagModelImpl assetTagModelImpl = (AssetTagModelImpl)assetTag;
1447    
1448                    Session session = null;
1449    
1450                    try {
1451                            session = openSession();
1452    
1453                            if (assetTag.isNew()) {
1454                                    session.save(assetTag);
1455    
1456                                    assetTag.setNew(false);
1457                            }
1458                            else {
1459                                    session.merge(assetTag);
1460                            }
1461                    }
1462                    catch (Exception e) {
1463                            throw processException(e);
1464                    }
1465                    finally {
1466                            closeSession(session);
1467                    }
1468    
1469                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1470    
1471                    if (isNew || !AssetTagModelImpl.COLUMN_BITMASK_ENABLED) {
1472                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1473                    }
1474    
1475                    else {
1476                            if ((assetTagModelImpl.getColumnBitmask() &
1477                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
1478                                    Object[] args = new Object[] {
1479                                                    Long.valueOf(assetTagModelImpl.getOriginalGroupId())
1480                                            };
1481    
1482                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
1483                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
1484                                            args);
1485    
1486                                    args = new Object[] { Long.valueOf(assetTagModelImpl.getGroupId()) };
1487    
1488                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
1489                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
1490                                            args);
1491                            }
1492                    }
1493    
1494                    EntityCacheUtil.putResult(AssetTagModelImpl.ENTITY_CACHE_ENABLED,
1495                            AssetTagImpl.class, assetTag.getPrimaryKey(), assetTag);
1496    
1497                    clearUniqueFindersCache(assetTag);
1498                    cacheUniqueFindersCache(assetTag);
1499    
1500                    return assetTag;
1501            }
1502    
1503            protected AssetTag toUnwrappedModel(AssetTag assetTag) {
1504                    if (assetTag instanceof AssetTagImpl) {
1505                            return assetTag;
1506                    }
1507    
1508                    AssetTagImpl assetTagImpl = new AssetTagImpl();
1509    
1510                    assetTagImpl.setNew(assetTag.isNew());
1511                    assetTagImpl.setPrimaryKey(assetTag.getPrimaryKey());
1512    
1513                    assetTagImpl.setTagId(assetTag.getTagId());
1514                    assetTagImpl.setGroupId(assetTag.getGroupId());
1515                    assetTagImpl.setCompanyId(assetTag.getCompanyId());
1516                    assetTagImpl.setUserId(assetTag.getUserId());
1517                    assetTagImpl.setUserName(assetTag.getUserName());
1518                    assetTagImpl.setCreateDate(assetTag.getCreateDate());
1519                    assetTagImpl.setModifiedDate(assetTag.getModifiedDate());
1520                    assetTagImpl.setName(assetTag.getName());
1521                    assetTagImpl.setAssetCount(assetTag.getAssetCount());
1522    
1523                    return assetTagImpl;
1524            }
1525    
1526            /**
1527             * Returns the asset tag with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
1528             *
1529             * @param primaryKey the primary key of the asset tag
1530             * @return the asset tag
1531             * @throws com.liferay.portal.NoSuchModelException if a asset tag with the primary key could not be found
1532             * @throws SystemException if a system exception occurred
1533             */
1534            @Override
1535            public AssetTag findByPrimaryKey(Serializable primaryKey)
1536                    throws NoSuchModelException, SystemException {
1537                    return findByPrimaryKey(((Long)primaryKey).longValue());
1538            }
1539    
1540            /**
1541             * Returns the asset tag with the primary key or throws a {@link com.liferay.portlet.asset.NoSuchTagException} if it could not be found.
1542             *
1543             * @param tagId the primary key of the asset tag
1544             * @return the asset tag
1545             * @throws com.liferay.portlet.asset.NoSuchTagException if a asset tag with the primary key could not be found
1546             * @throws SystemException if a system exception occurred
1547             */
1548            public AssetTag findByPrimaryKey(long tagId)
1549                    throws NoSuchTagException, SystemException {
1550                    AssetTag assetTag = fetchByPrimaryKey(tagId);
1551    
1552                    if (assetTag == null) {
1553                            if (_log.isWarnEnabled()) {
1554                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + tagId);
1555                            }
1556    
1557                            throw new NoSuchTagException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1558                                    tagId);
1559                    }
1560    
1561                    return assetTag;
1562            }
1563    
1564            /**
1565             * Returns the asset tag with the primary key or returns <code>null</code> if it could not be found.
1566             *
1567             * @param primaryKey the primary key of the asset tag
1568             * @return the asset tag, or <code>null</code> if a asset tag with the primary key could not be found
1569             * @throws SystemException if a system exception occurred
1570             */
1571            @Override
1572            public AssetTag fetchByPrimaryKey(Serializable primaryKey)
1573                    throws SystemException {
1574                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
1575            }
1576    
1577            /**
1578             * Returns the asset tag with the primary key or returns <code>null</code> if it could not be found.
1579             *
1580             * @param tagId the primary key of the asset tag
1581             * @return the asset tag, or <code>null</code> if a asset tag with the primary key could not be found
1582             * @throws SystemException if a system exception occurred
1583             */
1584            public AssetTag fetchByPrimaryKey(long tagId) throws SystemException {
1585                    AssetTag assetTag = (AssetTag)EntityCacheUtil.getResult(AssetTagModelImpl.ENTITY_CACHE_ENABLED,
1586                                    AssetTagImpl.class, tagId);
1587    
1588                    if (assetTag == _nullAssetTag) {
1589                            return null;
1590                    }
1591    
1592                    if (assetTag == null) {
1593                            Session session = null;
1594    
1595                            try {
1596                                    session = openSession();
1597    
1598                                    assetTag = (AssetTag)session.get(AssetTagImpl.class,
1599                                                    Long.valueOf(tagId));
1600    
1601                                    if (assetTag != null) {
1602                                            cacheResult(assetTag);
1603                                    }
1604                                    else {
1605                                            EntityCacheUtil.putResult(AssetTagModelImpl.ENTITY_CACHE_ENABLED,
1606                                                    AssetTagImpl.class, tagId, _nullAssetTag);
1607                                    }
1608                            }
1609                            catch (Exception e) {
1610                                    EntityCacheUtil.removeResult(AssetTagModelImpl.ENTITY_CACHE_ENABLED,
1611                                            AssetTagImpl.class, tagId);
1612    
1613                                    throw processException(e);
1614                            }
1615                            finally {
1616                                    closeSession(session);
1617                            }
1618                    }
1619    
1620                    return assetTag;
1621            }
1622    
1623            /**
1624             * Returns all the asset tags.
1625             *
1626             * @return the asset tags
1627             * @throws SystemException if a system exception occurred
1628             */
1629            public List<AssetTag> findAll() throws SystemException {
1630                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1631            }
1632    
1633            /**
1634             * Returns a range of all the asset tags.
1635             *
1636             * <p>
1637             * 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. 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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.asset.model.impl.AssetTagModelImpl}. 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.
1638             * </p>
1639             *
1640             * @param start the lower bound of the range of asset tags
1641             * @param end the upper bound of the range of asset tags (not inclusive)
1642             * @return the range of asset tags
1643             * @throws SystemException if a system exception occurred
1644             */
1645            public List<AssetTag> findAll(int start, int end) throws SystemException {
1646                    return findAll(start, end, null);
1647            }
1648    
1649            /**
1650             * Returns an ordered range of all the asset tags.
1651             *
1652             * <p>
1653             * 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. 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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.asset.model.impl.AssetTagModelImpl}. 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.
1654             * </p>
1655             *
1656             * @param start the lower bound of the range of asset tags
1657             * @param end the upper bound of the range of asset tags (not inclusive)
1658             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1659             * @return the ordered range of asset tags
1660             * @throws SystemException if a system exception occurred
1661             */
1662            public List<AssetTag> findAll(int start, int end,
1663                    OrderByComparator orderByComparator) throws SystemException {
1664                    boolean pagination = true;
1665                    FinderPath finderPath = null;
1666                    Object[] finderArgs = null;
1667    
1668                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1669                                    (orderByComparator == null)) {
1670                            pagination = false;
1671                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1672                            finderArgs = FINDER_ARGS_EMPTY;
1673                    }
1674                    else {
1675                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1676                            finderArgs = new Object[] { start, end, orderByComparator };
1677                    }
1678    
1679                    List<AssetTag> list = (List<AssetTag>)FinderCacheUtil.getResult(finderPath,
1680                                    finderArgs, this);
1681    
1682                    if (list == null) {
1683                            StringBundler query = null;
1684                            String sql = null;
1685    
1686                            if (orderByComparator != null) {
1687                                    query = new StringBundler(2 +
1688                                                    (orderByComparator.getOrderByFields().length * 3));
1689    
1690                                    query.append(_SQL_SELECT_ASSETTAG);
1691    
1692                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1693                                            orderByComparator);
1694    
1695                                    sql = query.toString();
1696                            }
1697                            else {
1698                                    sql = _SQL_SELECT_ASSETTAG;
1699    
1700                                    if (pagination) {
1701                                            sql = sql.concat(AssetTagModelImpl.ORDER_BY_JPQL);
1702                                    }
1703                            }
1704    
1705                            Session session = null;
1706    
1707                            try {
1708                                    session = openSession();
1709    
1710                                    Query q = session.createQuery(sql);
1711    
1712                                    if (!pagination) {
1713                                            list = (List<AssetTag>)QueryUtil.list(q, getDialect(),
1714                                                            start, end, false);
1715    
1716                                            Collections.sort(list);
1717    
1718                                            list = new UnmodifiableList<AssetTag>(list);
1719                                    }
1720                                    else {
1721                                            list = (List<AssetTag>)QueryUtil.list(q, getDialect(),
1722                                                            start, end);
1723                                    }
1724    
1725                                    cacheResult(list);
1726    
1727                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1728                            }
1729                            catch (Exception e) {
1730                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1731    
1732                                    throw processException(e);
1733                            }
1734                            finally {
1735                                    closeSession(session);
1736                            }
1737                    }
1738    
1739                    return list;
1740            }
1741    
1742            /**
1743             * Removes all the asset tags from the database.
1744             *
1745             * @throws SystemException if a system exception occurred
1746             */
1747            public void removeAll() throws SystemException {
1748                    for (AssetTag assetTag : findAll()) {
1749                            remove(assetTag);
1750                    }
1751            }
1752    
1753            /**
1754             * Returns the number of asset tags.
1755             *
1756             * @return the number of asset tags
1757             * @throws SystemException if a system exception occurred
1758             */
1759            public int countAll() throws SystemException {
1760                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1761                                    FINDER_ARGS_EMPTY, this);
1762    
1763                    if (count == null) {
1764                            Session session = null;
1765    
1766                            try {
1767                                    session = openSession();
1768    
1769                                    Query q = session.createQuery(_SQL_COUNT_ASSETTAG);
1770    
1771                                    count = (Long)q.uniqueResult();
1772    
1773                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1774                                            FINDER_ARGS_EMPTY, count);
1775                            }
1776                            catch (Exception e) {
1777                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
1778                                            FINDER_ARGS_EMPTY);
1779    
1780                                    throw processException(e);
1781                            }
1782                            finally {
1783                                    closeSession(session);
1784                            }
1785                    }
1786    
1787                    return count.intValue();
1788            }
1789    
1790            /**
1791             * Returns all the asset entries associated with the asset tag.
1792             *
1793             * @param pk the primary key of the asset tag
1794             * @return the asset entries associated with the asset tag
1795             * @throws SystemException if a system exception occurred
1796             */
1797            public List<com.liferay.portlet.asset.model.AssetEntry> getAssetEntries(
1798                    long pk) throws SystemException {
1799                    return getAssetEntries(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
1800            }
1801    
1802            /**
1803             * Returns a range of all the asset entries associated with the asset tag.
1804             *
1805             * <p>
1806             * 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. 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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.asset.model.impl.AssetTagModelImpl}. 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.
1807             * </p>
1808             *
1809             * @param pk the primary key of the asset tag
1810             * @param start the lower bound of the range of asset tags
1811             * @param end the upper bound of the range of asset tags (not inclusive)
1812             * @return the range of asset entries associated with the asset tag
1813             * @throws SystemException if a system exception occurred
1814             */
1815            public List<com.liferay.portlet.asset.model.AssetEntry> getAssetEntries(
1816                    long pk, int start, int end) throws SystemException {
1817                    return getAssetEntries(pk, start, end, null);
1818            }
1819    
1820            public static final FinderPath FINDER_PATH_GET_ASSETENTRIES = new FinderPath(com.liferay.portlet.asset.model.impl.AssetEntryModelImpl.ENTITY_CACHE_ENABLED,
1821                            AssetTagModelImpl.FINDER_CACHE_ENABLED_ASSETENTRIES_ASSETTAGS,
1822                            com.liferay.portlet.asset.model.impl.AssetEntryImpl.class,
1823                            AssetTagModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETTAGS_NAME,
1824                            "getAssetEntries",
1825                            new String[] {
1826                                    Long.class.getName(), Integer.class.getName(),
1827                                    Integer.class.getName(), OrderByComparator.class.getName()
1828                            });
1829    
1830            static {
1831                    FINDER_PATH_GET_ASSETENTRIES.setCacheKeyGeneratorCacheName(null);
1832            }
1833    
1834            /**
1835             * Returns an ordered range of all the asset entries associated with the asset tag.
1836             *
1837             * <p>
1838             * 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. 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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.asset.model.impl.AssetTagModelImpl}. 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.
1839             * </p>
1840             *
1841             * @param pk the primary key of the asset tag
1842             * @param start the lower bound of the range of asset tags
1843             * @param end the upper bound of the range of asset tags (not inclusive)
1844             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1845             * @return the ordered range of asset entries associated with the asset tag
1846             * @throws SystemException if a system exception occurred
1847             */
1848            public List<com.liferay.portlet.asset.model.AssetEntry> getAssetEntries(
1849                    long pk, int start, int end, OrderByComparator orderByComparator)
1850                    throws SystemException {
1851                    boolean pagination = true;
1852                    Object[] finderArgs = null;
1853    
1854                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1855                                    (orderByComparator == null)) {
1856                            pagination = false;
1857                            finderArgs = new Object[] { pk };
1858                    }
1859                    else {
1860                            finderArgs = new Object[] { pk, start, end, orderByComparator };
1861                    }
1862    
1863                    List<com.liferay.portlet.asset.model.AssetEntry> list = (List<com.liferay.portlet.asset.model.AssetEntry>)FinderCacheUtil.getResult(FINDER_PATH_GET_ASSETENTRIES,
1864                                    finderArgs, this);
1865    
1866                    if (list == null) {
1867                            Session session = null;
1868    
1869                            try {
1870                                    session = openSession();
1871    
1872                                    String sql = null;
1873    
1874                                    if (orderByComparator != null) {
1875                                            sql = _SQL_GETASSETENTRIES.concat(ORDER_BY_CLAUSE)
1876                                                                                              .concat(orderByComparator.getOrderBy());
1877                                    }
1878                                    else {
1879                                            sql = _SQL_GETASSETENTRIES;
1880    
1881                                            if (pagination) {
1882                                                    sql = sql.concat(com.liferay.portlet.asset.model.impl.AssetEntryModelImpl.ORDER_BY_SQL);
1883                                            }
1884                                    }
1885    
1886                                    SQLQuery q = session.createSQLQuery(sql);
1887    
1888                                    q.addEntity("AssetEntry",
1889                                            com.liferay.portlet.asset.model.impl.AssetEntryImpl.class);
1890    
1891                                    QueryPos qPos = QueryPos.getInstance(q);
1892    
1893                                    qPos.add(pk);
1894    
1895                                    if (!pagination) {
1896                                            list = (List<com.liferay.portlet.asset.model.AssetEntry>)QueryUtil.list(q,
1897                                                            getDialect(), start, end, false);
1898    
1899                                            Collections.sort(list);
1900    
1901                                            list = new UnmodifiableList<com.liferay.portlet.asset.model.AssetEntry>(list);
1902                                    }
1903                                    else {
1904                                            list = (List<com.liferay.portlet.asset.model.AssetEntry>)QueryUtil.list(q,
1905                                                            getDialect(), start, end);
1906                                    }
1907    
1908                                    assetEntryPersistence.cacheResult(list);
1909    
1910                                    FinderCacheUtil.putResult(FINDER_PATH_GET_ASSETENTRIES,
1911                                            finderArgs, list);
1912                            }
1913                            catch (Exception e) {
1914                                    FinderCacheUtil.removeResult(FINDER_PATH_GET_ASSETENTRIES,
1915                                            finderArgs);
1916    
1917                                    throw processException(e);
1918                            }
1919                            finally {
1920                                    closeSession(session);
1921                            }
1922                    }
1923    
1924                    return list;
1925            }
1926    
1927            public static final FinderPath FINDER_PATH_GET_ASSETENTRIES_SIZE = new FinderPath(com.liferay.portlet.asset.model.impl.AssetEntryModelImpl.ENTITY_CACHE_ENABLED,
1928                            AssetTagModelImpl.FINDER_CACHE_ENABLED_ASSETENTRIES_ASSETTAGS,
1929                            Long.class,
1930                            AssetTagModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETTAGS_NAME,
1931                            "getAssetEntriesSize", new String[] { Long.class.getName() });
1932    
1933            static {
1934                    FINDER_PATH_GET_ASSETENTRIES_SIZE.setCacheKeyGeneratorCacheName(null);
1935            }
1936    
1937            /**
1938             * Returns the number of asset entries associated with the asset tag.
1939             *
1940             * @param pk the primary key of the asset tag
1941             * @return the number of asset entries associated with the asset tag
1942             * @throws SystemException if a system exception occurred
1943             */
1944            public int getAssetEntriesSize(long pk) throws SystemException {
1945                    Object[] finderArgs = new Object[] { pk };
1946    
1947                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_ASSETENTRIES_SIZE,
1948                                    finderArgs, this);
1949    
1950                    if (count == null) {
1951                            Session session = null;
1952    
1953                            try {
1954                                    session = openSession();
1955    
1956                                    SQLQuery q = session.createSQLQuery(_SQL_GETASSETENTRIESSIZE);
1957    
1958                                    q.addScalar(COUNT_COLUMN_NAME,
1959                                            com.liferay.portal.kernel.dao.orm.Type.LONG);
1960    
1961                                    QueryPos qPos = QueryPos.getInstance(q);
1962    
1963                                    qPos.add(pk);
1964    
1965                                    count = (Long)q.uniqueResult();
1966    
1967                                    FinderCacheUtil.putResult(FINDER_PATH_GET_ASSETENTRIES_SIZE,
1968                                            finderArgs, count);
1969                            }
1970                            catch (Exception e) {
1971                                    FinderCacheUtil.removeResult(FINDER_PATH_GET_ASSETENTRIES_SIZE,
1972                                            finderArgs);
1973    
1974                                    throw processException(e);
1975                            }
1976                            finally {
1977                                    closeSession(session);
1978                            }
1979                    }
1980    
1981                    return count.intValue();
1982            }
1983    
1984            public static final FinderPath FINDER_PATH_CONTAINS_ASSETENTRY = new FinderPath(com.liferay.portlet.asset.model.impl.AssetEntryModelImpl.ENTITY_CACHE_ENABLED,
1985                            AssetTagModelImpl.FINDER_CACHE_ENABLED_ASSETENTRIES_ASSETTAGS,
1986                            Boolean.class,
1987                            AssetTagModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETTAGS_NAME,
1988                            "containsAssetEntry",
1989                            new String[] { Long.class.getName(), Long.class.getName() });
1990    
1991            /**
1992             * Returns <code>true</code> if the asset entry is associated with the asset tag.
1993             *
1994             * @param pk the primary key of the asset tag
1995             * @param assetEntryPK the primary key of the asset entry
1996             * @return <code>true</code> if the asset entry is associated with the asset tag; <code>false</code> otherwise
1997             * @throws SystemException if a system exception occurred
1998             */
1999            public boolean containsAssetEntry(long pk, long assetEntryPK)
2000                    throws SystemException {
2001                    Object[] finderArgs = new Object[] { pk, assetEntryPK };
2002    
2003                    Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_ASSETENTRY,
2004                                    finderArgs, this);
2005    
2006                    if (value == null) {
2007                            try {
2008                                    value = Boolean.valueOf(containsAssetEntry.contains(pk,
2009                                                            assetEntryPK));
2010    
2011                                    FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_ASSETENTRY,
2012                                            finderArgs, value);
2013                            }
2014                            catch (Exception e) {
2015                                    FinderCacheUtil.removeResult(FINDER_PATH_CONTAINS_ASSETENTRY,
2016                                            finderArgs);
2017    
2018                                    throw processException(e);
2019                            }
2020                    }
2021    
2022                    return value.booleanValue();
2023            }
2024    
2025            /**
2026             * Returns <code>true</code> if the asset tag has any asset entries associated with it.
2027             *
2028             * @param pk the primary key of the asset tag to check for associations with asset entries
2029             * @return <code>true</code> if the asset tag has any asset entries associated with it; <code>false</code> otherwise
2030             * @throws SystemException if a system exception occurred
2031             */
2032            public boolean containsAssetEntries(long pk) throws SystemException {
2033                    if (getAssetEntriesSize(pk) > 0) {
2034                            return true;
2035                    }
2036                    else {
2037                            return false;
2038                    }
2039            }
2040    
2041            /**
2042             * Adds an association between the asset tag and the asset entry. Also notifies the appropriate model listeners and clears the mapping table finder cache.
2043             *
2044             * @param pk the primary key of the asset tag
2045             * @param assetEntryPK the primary key of the asset entry
2046             * @throws SystemException if a system exception occurred
2047             */
2048            public void addAssetEntry(long pk, long assetEntryPK)
2049                    throws SystemException {
2050                    try {
2051                            addAssetEntry.add(pk, assetEntryPK);
2052                    }
2053                    catch (Exception e) {
2054                            throw processException(e);
2055                    }
2056                    finally {
2057                            FinderCacheUtil.clearCache(AssetTagModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETTAGS_NAME);
2058                    }
2059            }
2060    
2061            /**
2062             * Adds an association between the asset tag and the asset entry. Also notifies the appropriate model listeners and clears the mapping table finder cache.
2063             *
2064             * @param pk the primary key of the asset tag
2065             * @param assetEntry the asset entry
2066             * @throws SystemException if a system exception occurred
2067             */
2068            public void addAssetEntry(long pk,
2069                    com.liferay.portlet.asset.model.AssetEntry assetEntry)
2070                    throws SystemException {
2071                    try {
2072                            addAssetEntry.add(pk, assetEntry.getPrimaryKey());
2073                    }
2074                    catch (Exception e) {
2075                            throw processException(e);
2076                    }
2077                    finally {
2078                            FinderCacheUtil.clearCache(AssetTagModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETTAGS_NAME);
2079                    }
2080            }
2081    
2082            /**
2083             * Adds an association between the asset tag and the asset entries. Also notifies the appropriate model listeners and clears the mapping table finder cache.
2084             *
2085             * @param pk the primary key of the asset tag
2086             * @param assetEntryPKs the primary keys of the asset entries
2087             * @throws SystemException if a system exception occurred
2088             */
2089            public void addAssetEntries(long pk, long[] assetEntryPKs)
2090                    throws SystemException {
2091                    try {
2092                            for (long assetEntryPK : assetEntryPKs) {
2093                                    addAssetEntry.add(pk, assetEntryPK);
2094                            }
2095                    }
2096                    catch (Exception e) {
2097                            throw processException(e);
2098                    }
2099                    finally {
2100                            FinderCacheUtil.clearCache(AssetTagModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETTAGS_NAME);
2101                    }
2102            }
2103    
2104            /**
2105             * Adds an association between the asset tag and the asset entries. Also notifies the appropriate model listeners and clears the mapping table finder cache.
2106             *
2107             * @param pk the primary key of the asset tag
2108             * @param assetEntries the asset entries
2109             * @throws SystemException if a system exception occurred
2110             */
2111            public void addAssetEntries(long pk,
2112                    List<com.liferay.portlet.asset.model.AssetEntry> assetEntries)
2113                    throws SystemException {
2114                    try {
2115                            for (com.liferay.portlet.asset.model.AssetEntry assetEntry : assetEntries) {
2116                                    addAssetEntry.add(pk, assetEntry.getPrimaryKey());
2117                            }
2118                    }
2119                    catch (Exception e) {
2120                            throw processException(e);
2121                    }
2122                    finally {
2123                            FinderCacheUtil.clearCache(AssetTagModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETTAGS_NAME);
2124                    }
2125            }
2126    
2127            /**
2128             * Clears all associations between the asset tag and its asset entries. Also notifies the appropriate model listeners and clears the mapping table finder cache.
2129             *
2130             * @param pk the primary key of the asset tag to clear the associated asset entries from
2131             * @throws SystemException if a system exception occurred
2132             */
2133            public void clearAssetEntries(long pk) throws SystemException {
2134                    try {
2135                            clearAssetEntries.clear(pk);
2136                    }
2137                    catch (Exception e) {
2138                            throw processException(e);
2139                    }
2140                    finally {
2141                            FinderCacheUtil.clearCache(AssetTagModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETTAGS_NAME);
2142                    }
2143            }
2144    
2145            /**
2146             * Removes the association between the asset tag and the asset entry. Also notifies the appropriate model listeners and clears the mapping table finder cache.
2147             *
2148             * @param pk the primary key of the asset tag
2149             * @param assetEntryPK the primary key of the asset entry
2150             * @throws SystemException if a system exception occurred
2151             */
2152            public void removeAssetEntry(long pk, long assetEntryPK)
2153                    throws SystemException {
2154                    try {
2155                            removeAssetEntry.remove(pk, assetEntryPK);
2156                    }
2157                    catch (Exception e) {
2158                            throw processException(e);
2159                    }
2160                    finally {
2161                            FinderCacheUtil.clearCache(AssetTagModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETTAGS_NAME);
2162                    }
2163            }
2164    
2165            /**
2166             * Removes the association between the asset tag and the asset entry. Also notifies the appropriate model listeners and clears the mapping table finder cache.
2167             *
2168             * @param pk the primary key of the asset tag
2169             * @param assetEntry the asset entry
2170             * @throws SystemException if a system exception occurred
2171             */
2172            public void removeAssetEntry(long pk,
2173                    com.liferay.portlet.asset.model.AssetEntry assetEntry)
2174                    throws SystemException {
2175                    try {
2176                            removeAssetEntry.remove(pk, assetEntry.getPrimaryKey());
2177                    }
2178                    catch (Exception e) {
2179                            throw processException(e);
2180                    }
2181                    finally {
2182                            FinderCacheUtil.clearCache(AssetTagModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETTAGS_NAME);
2183                    }
2184            }
2185    
2186            /**
2187             * Removes the association between the asset tag and the asset entries. Also notifies the appropriate model listeners and clears the mapping table finder cache.
2188             *
2189             * @param pk the primary key of the asset tag
2190             * @param assetEntryPKs the primary keys of the asset entries
2191             * @throws SystemException if a system exception occurred
2192             */
2193            public void removeAssetEntries(long pk, long[] assetEntryPKs)
2194                    throws SystemException {
2195                    try {
2196                            for (long assetEntryPK : assetEntryPKs) {
2197                                    removeAssetEntry.remove(pk, assetEntryPK);
2198                            }
2199                    }
2200                    catch (Exception e) {
2201                            throw processException(e);
2202                    }
2203                    finally {
2204                            FinderCacheUtil.clearCache(AssetTagModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETTAGS_NAME);
2205                    }
2206            }
2207    
2208            /**
2209             * Removes the association between the asset tag and the asset entries. Also notifies the appropriate model listeners and clears the mapping table finder cache.
2210             *
2211             * @param pk the primary key of the asset tag
2212             * @param assetEntries the asset entries
2213             * @throws SystemException if a system exception occurred
2214             */
2215            public void removeAssetEntries(long pk,
2216                    List<com.liferay.portlet.asset.model.AssetEntry> assetEntries)
2217                    throws SystemException {
2218                    try {
2219                            for (com.liferay.portlet.asset.model.AssetEntry assetEntry : assetEntries) {
2220                                    removeAssetEntry.remove(pk, assetEntry.getPrimaryKey());
2221                            }
2222                    }
2223                    catch (Exception e) {
2224                            throw processException(e);
2225                    }
2226                    finally {
2227                            FinderCacheUtil.clearCache(AssetTagModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETTAGS_NAME);
2228                    }
2229            }
2230    
2231            /**
2232             * Sets the asset entries associated with the asset tag, removing and adding associations as necessary. Also notifies the appropriate model listeners and clears the mapping table finder cache.
2233             *
2234             * @param pk the primary key of the asset tag
2235             * @param assetEntryPKs the primary keys of the asset entries to be associated with the asset tag
2236             * @throws SystemException if a system exception occurred
2237             */
2238            public void setAssetEntries(long pk, long[] assetEntryPKs)
2239                    throws SystemException {
2240                    try {
2241                            Set<Long> assetEntryPKSet = SetUtil.fromArray(assetEntryPKs);
2242    
2243                            List<com.liferay.portlet.asset.model.AssetEntry> assetEntries = getAssetEntries(pk);
2244    
2245                            for (com.liferay.portlet.asset.model.AssetEntry assetEntry : assetEntries) {
2246                                    if (!assetEntryPKSet.remove(assetEntry.getPrimaryKey())) {
2247                                            removeAssetEntry.remove(pk, assetEntry.getPrimaryKey());
2248                                    }
2249                            }
2250    
2251                            for (Long assetEntryPK : assetEntryPKSet) {
2252                                    addAssetEntry.add(pk, assetEntryPK);
2253                            }
2254                    }
2255                    catch (Exception e) {
2256                            throw processException(e);
2257                    }
2258                    finally {
2259                            FinderCacheUtil.clearCache(AssetTagModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETTAGS_NAME);
2260                    }
2261            }
2262    
2263            /**
2264             * Sets the asset entries associated with the asset tag, removing and adding associations as necessary. Also notifies the appropriate model listeners and clears the mapping table finder cache.
2265             *
2266             * @param pk the primary key of the asset tag
2267             * @param assetEntries the asset entries to be associated with the asset tag
2268             * @throws SystemException if a system exception occurred
2269             */
2270            public void setAssetEntries(long pk,
2271                    List<com.liferay.portlet.asset.model.AssetEntry> assetEntries)
2272                    throws SystemException {
2273                    try {
2274                            long[] assetEntryPKs = new long[assetEntries.size()];
2275    
2276                            for (int i = 0; i < assetEntries.size(); i++) {
2277                                    com.liferay.portlet.asset.model.AssetEntry assetEntry = assetEntries.get(i);
2278    
2279                                    assetEntryPKs[i] = assetEntry.getPrimaryKey();
2280                            }
2281    
2282                            setAssetEntries(pk, assetEntryPKs);
2283                    }
2284                    catch (Exception e) {
2285                            throw processException(e);
2286                    }
2287                    finally {
2288                            FinderCacheUtil.clearCache(AssetTagModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETTAGS_NAME);
2289                    }
2290            }
2291    
2292            /**
2293             * Initializes the asset tag persistence.
2294             */
2295            public void afterPropertiesSet() {
2296                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2297                                            com.liferay.portal.util.PropsUtil.get(
2298                                                    "value.object.listener.com.liferay.portlet.asset.model.AssetTag")));
2299    
2300                    if (listenerClassNames.length > 0) {
2301                            try {
2302                                    List<ModelListener<AssetTag>> listenersList = new ArrayList<ModelListener<AssetTag>>();
2303    
2304                                    for (String listenerClassName : listenerClassNames) {
2305                                            listenersList.add((ModelListener<AssetTag>)InstanceFactory.newInstance(
2306                                                            listenerClassName));
2307                                    }
2308    
2309                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2310                            }
2311                            catch (Exception e) {
2312                                    _log.error(e);
2313                            }
2314                    }
2315    
2316                    containsAssetEntry = new ContainsAssetEntry();
2317    
2318                    addAssetEntry = new AddAssetEntry();
2319                    clearAssetEntries = new ClearAssetEntries();
2320                    removeAssetEntry = new RemoveAssetEntry();
2321            }
2322    
2323            public void destroy() {
2324                    EntityCacheUtil.removeCache(AssetTagImpl.class.getName());
2325                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2326                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2327                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2328            }
2329    
2330            @BeanReference(type = AssetEntryPersistence.class)
2331            protected AssetEntryPersistence assetEntryPersistence;
2332            protected ContainsAssetEntry containsAssetEntry;
2333            protected AddAssetEntry addAssetEntry;
2334            protected ClearAssetEntries clearAssetEntries;
2335            protected RemoveAssetEntry removeAssetEntry;
2336    
2337            protected class ContainsAssetEntry {
2338                    protected ContainsAssetEntry() {
2339                            _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
2340                                            _SQL_CONTAINSASSETENTRY,
2341                                            new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT },
2342                                            RowMapper.COUNT);
2343                    }
2344    
2345                    protected boolean contains(long tagId, long entryId) {
2346                            List<Integer> results = _mappingSqlQuery.execute(new Object[] {
2347                                                    new Long(tagId), new Long(entryId)
2348                                            });
2349    
2350                            if (results.size() > 0) {
2351                                    Integer count = results.get(0);
2352    
2353                                    if (count.intValue() > 0) {
2354                                            return true;
2355                                    }
2356                            }
2357    
2358                            return false;
2359                    }
2360    
2361                    private MappingSqlQuery<Integer> _mappingSqlQuery;
2362            }
2363    
2364            protected class AddAssetEntry {
2365                    protected AddAssetEntry() {
2366                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
2367                                            "INSERT INTO AssetEntries_AssetTags (tagId, entryId) VALUES (?, ?)",
2368                                            new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
2369                    }
2370    
2371                    protected void add(long tagId, long entryId) throws SystemException {
2372                            if (!containsAssetEntry.contains(tagId, entryId)) {
2373                                    ModelListener<com.liferay.portlet.asset.model.AssetEntry>[] assetEntryListeners =
2374                                            assetEntryPersistence.getListeners();
2375    
2376                                    for (ModelListener<AssetTag> listener : listeners) {
2377                                            listener.onBeforeAddAssociation(tagId,
2378                                                    com.liferay.portlet.asset.model.AssetEntry.class.getName(),
2379                                                    entryId);
2380                                    }
2381    
2382                                    for (ModelListener<com.liferay.portlet.asset.model.AssetEntry> listener : assetEntryListeners) {
2383                                            listener.onBeforeAddAssociation(entryId,
2384                                                    AssetTag.class.getName(), tagId);
2385                                    }
2386    
2387                                    _sqlUpdate.update(new Object[] {
2388                                                    new Long(tagId), new Long(entryId)
2389                                            });
2390    
2391                                    for (ModelListener<AssetTag> listener : listeners) {
2392                                            listener.onAfterAddAssociation(tagId,
2393                                                    com.liferay.portlet.asset.model.AssetEntry.class.getName(),
2394                                                    entryId);
2395                                    }
2396    
2397                                    for (ModelListener<com.liferay.portlet.asset.model.AssetEntry> listener : assetEntryListeners) {
2398                                            listener.onAfterAddAssociation(entryId,
2399                                                    AssetTag.class.getName(), tagId);
2400                                    }
2401                            }
2402                    }
2403    
2404                    private SqlUpdate _sqlUpdate;
2405            }
2406    
2407            protected class ClearAssetEntries {
2408                    protected ClearAssetEntries() {
2409                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
2410                                            "DELETE FROM AssetEntries_AssetTags WHERE tagId = ?",
2411                                            new int[] { java.sql.Types.BIGINT });
2412                    }
2413    
2414                    protected void clear(long tagId) throws SystemException {
2415                            ModelListener<com.liferay.portlet.asset.model.AssetEntry>[] assetEntryListeners =
2416                                    assetEntryPersistence.getListeners();
2417    
2418                            List<com.liferay.portlet.asset.model.AssetEntry> assetEntries = null;
2419    
2420                            if ((listeners.length > 0) || (assetEntryListeners.length > 0)) {
2421                                    assetEntries = getAssetEntries(tagId);
2422    
2423                                    for (com.liferay.portlet.asset.model.AssetEntry assetEntry : assetEntries) {
2424                                            for (ModelListener<AssetTag> listener : listeners) {
2425                                                    listener.onBeforeRemoveAssociation(tagId,
2426                                                            com.liferay.portlet.asset.model.AssetEntry.class.getName(),
2427                                                            assetEntry.getPrimaryKey());
2428                                            }
2429    
2430                                            for (ModelListener<com.liferay.portlet.asset.model.AssetEntry> listener : assetEntryListeners) {
2431                                                    listener.onBeforeRemoveAssociation(assetEntry.getPrimaryKey(),
2432                                                            AssetTag.class.getName(), tagId);
2433                                            }
2434                                    }
2435                            }
2436    
2437                            _sqlUpdate.update(new Object[] { new Long(tagId) });
2438    
2439                            if ((listeners.length > 0) || (assetEntryListeners.length > 0)) {
2440                                    for (com.liferay.portlet.asset.model.AssetEntry assetEntry : assetEntries) {
2441                                            for (ModelListener<AssetTag> listener : listeners) {
2442                                                    listener.onAfterRemoveAssociation(tagId,
2443                                                            com.liferay.portlet.asset.model.AssetEntry.class.getName(),
2444                                                            assetEntry.getPrimaryKey());
2445                                            }
2446    
2447                                            for (ModelListener<com.liferay.portlet.asset.model.AssetEntry> listener : assetEntryListeners) {
2448                                                    listener.onAfterRemoveAssociation(assetEntry.getPrimaryKey(),
2449                                                            AssetTag.class.getName(), tagId);
2450                                            }
2451                                    }
2452                            }
2453                    }
2454    
2455                    private SqlUpdate _sqlUpdate;
2456            }
2457    
2458            protected class RemoveAssetEntry {
2459                    protected RemoveAssetEntry() {
2460                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
2461                                            "DELETE FROM AssetEntries_AssetTags WHERE tagId = ? AND entryId = ?",
2462                                            new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
2463                    }
2464    
2465                    protected void remove(long tagId, long entryId)
2466                            throws SystemException {
2467                            if (containsAssetEntry.contains(tagId, entryId)) {
2468                                    ModelListener<com.liferay.portlet.asset.model.AssetEntry>[] assetEntryListeners =
2469                                            assetEntryPersistence.getListeners();
2470    
2471                                    for (ModelListener<AssetTag> listener : listeners) {
2472                                            listener.onBeforeRemoveAssociation(tagId,
2473                                                    com.liferay.portlet.asset.model.AssetEntry.class.getName(),
2474                                                    entryId);
2475                                    }
2476    
2477                                    for (ModelListener<com.liferay.portlet.asset.model.AssetEntry> listener : assetEntryListeners) {
2478                                            listener.onBeforeRemoveAssociation(entryId,
2479                                                    AssetTag.class.getName(), tagId);
2480                                    }
2481    
2482                                    _sqlUpdate.update(new Object[] {
2483                                                    new Long(tagId), new Long(entryId)
2484                                            });
2485    
2486                                    for (ModelListener<AssetTag> listener : listeners) {
2487                                            listener.onAfterRemoveAssociation(tagId,
2488                                                    com.liferay.portlet.asset.model.AssetEntry.class.getName(),
2489                                                    entryId);
2490                                    }
2491    
2492                                    for (ModelListener<com.liferay.portlet.asset.model.AssetEntry> listener : assetEntryListeners) {
2493                                            listener.onAfterRemoveAssociation(entryId,
2494                                                    AssetTag.class.getName(), tagId);
2495                                    }
2496                            }
2497                    }
2498    
2499                    private SqlUpdate _sqlUpdate;
2500            }
2501    
2502            private static final String _SQL_SELECT_ASSETTAG = "SELECT assetTag FROM AssetTag assetTag";
2503            private static final String _SQL_SELECT_ASSETTAG_WHERE = "SELECT assetTag FROM AssetTag assetTag WHERE ";
2504            private static final String _SQL_COUNT_ASSETTAG = "SELECT COUNT(assetTag) FROM AssetTag assetTag";
2505            private static final String _SQL_COUNT_ASSETTAG_WHERE = "SELECT COUNT(assetTag) FROM AssetTag assetTag WHERE ";
2506            private static final String _SQL_GETASSETENTRIES = "SELECT {AssetEntry.*} FROM AssetEntry INNER JOIN AssetEntries_AssetTags ON (AssetEntries_AssetTags.entryId = AssetEntry.entryId) WHERE (AssetEntries_AssetTags.tagId = ?)";
2507            private static final String _SQL_GETASSETENTRIESSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM AssetEntries_AssetTags WHERE tagId = ?";
2508            private static final String _SQL_CONTAINSASSETENTRY = "SELECT COUNT(*) AS COUNT_VALUE FROM AssetEntries_AssetTags WHERE tagId = ? AND entryId = ?";
2509            private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "assetTag.tagId";
2510            private static final String _FILTER_SQL_SELECT_ASSETTAG_WHERE = "SELECT DISTINCT {assetTag.*} FROM AssetTag assetTag WHERE ";
2511            private static final String _FILTER_SQL_SELECT_ASSETTAG_NO_INLINE_DISTINCT_WHERE_1 =
2512                    "SELECT {AssetTag.*} FROM (SELECT DISTINCT assetTag.tagId FROM AssetTag assetTag WHERE ";
2513            private static final String _FILTER_SQL_SELECT_ASSETTAG_NO_INLINE_DISTINCT_WHERE_2 =
2514                    ") TEMP_TABLE INNER JOIN AssetTag ON TEMP_TABLE.tagId = AssetTag.tagId";
2515            private static final String _FILTER_SQL_COUNT_ASSETTAG_WHERE = "SELECT COUNT(DISTINCT assetTag.tagId) AS COUNT_VALUE FROM AssetTag assetTag WHERE ";
2516            private static final String _FILTER_ENTITY_ALIAS = "assetTag";
2517            private static final String _FILTER_ENTITY_TABLE = "AssetTag";
2518            private static final String _ORDER_BY_ENTITY_ALIAS = "assetTag.";
2519            private static final String _ORDER_BY_ENTITY_TABLE = "AssetTag.";
2520            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No AssetTag exists with the primary key ";
2521            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No AssetTag exists with the key {";
2522            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
2523            private static Log _log = LogFactoryUtil.getLog(AssetTagPersistenceImpl.class);
2524            private static AssetTag _nullAssetTag = new AssetTagImpl() {
2525                            @Override
2526                            public Object clone() {
2527                                    return this;
2528                            }
2529    
2530                            @Override
2531                            public CacheModel<AssetTag> toCacheModel() {
2532                                    return _nullAssetTagCacheModel;
2533                            }
2534                    };
2535    
2536            private static CacheModel<AssetTag> _nullAssetTagCacheModel = new CacheModel<AssetTag>() {
2537                            public AssetTag toEntityModel() {
2538                                    return _nullAssetTag;
2539                            }
2540                    };
2541    }