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