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