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