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