001    /**
002     * Copyright (c) 2000-present 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.impl;
016    
017    import aQute.bnd.annotation.ProviderType;
018    
019    import com.liferay.portal.kernel.bean.BeanReference;
020    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderPath;
023    import com.liferay.portal.kernel.dao.orm.Query;
024    import com.liferay.portal.kernel.dao.orm.QueryPos;
025    import com.liferay.portal.kernel.dao.orm.QueryUtil;
026    import com.liferay.portal.kernel.dao.orm.SQLQuery;
027    import com.liferay.portal.kernel.dao.orm.Session;
028    import com.liferay.portal.kernel.log.Log;
029    import com.liferay.portal.kernel.log.LogFactoryUtil;
030    import com.liferay.portal.kernel.util.ArrayUtil;
031    import com.liferay.portal.kernel.util.CharPool;
032    import com.liferay.portal.kernel.util.OrderByComparator;
033    import com.liferay.portal.kernel.util.SetUtil;
034    import com.liferay.portal.kernel.util.StringBundler;
035    import com.liferay.portal.kernel.util.StringPool;
036    import com.liferay.portal.kernel.util.StringUtil;
037    import com.liferay.portal.kernel.util.Validator;
038    import com.liferay.portal.model.CacheModel;
039    import com.liferay.portal.security.permission.InlineSQLHelperUtil;
040    import com.liferay.portal.service.ServiceContext;
041    import com.liferay.portal.service.ServiceContextThreadLocal;
042    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
043    import com.liferay.portal.service.persistence.impl.TableMapper;
044    import com.liferay.portal.service.persistence.impl.TableMapperFactory;
045    
046    import com.liferay.portlet.asset.NoSuchTagException;
047    import com.liferay.portlet.asset.model.AssetTag;
048    import com.liferay.portlet.asset.model.impl.AssetTagImpl;
049    import com.liferay.portlet.asset.model.impl.AssetTagModelImpl;
050    import com.liferay.portlet.asset.service.persistence.AssetEntryPersistence;
051    import com.liferay.portlet.asset.service.persistence.AssetTagPersistence;
052    
053    import java.io.Serializable;
054    
055    import java.util.Collections;
056    import java.util.Date;
057    import java.util.HashMap;
058    import java.util.HashSet;
059    import java.util.Iterator;
060    import java.util.List;
061    import java.util.Map;
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 com.liferay.portlet.asset.service.persistence.AssetTagUtil
074     * @generated
075     */
076    @ProviderType
077    public class AssetTagPersistenceImpl extends BasePersistenceImpl<AssetTag>
078            implements AssetTagPersistence {
079            /*
080             * NOTE FOR DEVELOPERS:
081             *
082             * 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.
083             */
084            public static final String FINDER_CLASS_NAME_ENTITY = AssetTagImpl.class.getName();
085            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
086                    ".List1";
087            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
088                    ".List2";
089            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(AssetTagModelImpl.ENTITY_CACHE_ENABLED,
090                            AssetTagModelImpl.FINDER_CACHE_ENABLED, AssetTagImpl.class,
091                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
092            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(AssetTagModelImpl.ENTITY_CACHE_ENABLED,
093                            AssetTagModelImpl.FINDER_CACHE_ENABLED, AssetTagImpl.class,
094                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
095            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(AssetTagModelImpl.ENTITY_CACHE_ENABLED,
096                            AssetTagModelImpl.FINDER_CACHE_ENABLED, Long.class,
097                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
098            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(AssetTagModelImpl.ENTITY_CACHE_ENABLED,
099                            AssetTagModelImpl.FINDER_CACHE_ENABLED, AssetTagImpl.class,
100                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByGroupId",
101                            new String[] {
102                                    Long.class.getName(),
103                                    
104                            Integer.class.getName(), Integer.class.getName(),
105                                    OrderByComparator.class.getName()
106                            });
107            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
108                    new FinderPath(AssetTagModelImpl.ENTITY_CACHE_ENABLED,
109                            AssetTagModelImpl.FINDER_CACHE_ENABLED, AssetTagImpl.class,
110                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
111                            new String[] { Long.class.getName() },
112                            AssetTagModelImpl.GROUPID_COLUMN_BITMASK |
113                            AssetTagModelImpl.NAME_COLUMN_BITMASK);
114            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(AssetTagModelImpl.ENTITY_CACHE_ENABLED,
115                            AssetTagModelImpl.FINDER_CACHE_ENABLED, Long.class,
116                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
117                            new String[] { Long.class.getName() });
118            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_GROUPID = new FinderPath(AssetTagModelImpl.ENTITY_CACHE_ENABLED,
119                            AssetTagModelImpl.FINDER_CACHE_ENABLED, Long.class,
120                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByGroupId",
121                            new String[] { Long.class.getName() });
122    
123            /**
124             * Returns all the asset tags where groupId = &#63;.
125             *
126             * @param groupId the group ID
127             * @return the matching asset tags
128             */
129            @Override
130            public List<AssetTag> findByGroupId(long groupId) {
131                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
132            }
133    
134            /**
135             * Returns a range of all the asset tags where groupId = &#63;.
136             *
137             * <p>
138             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetTagModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
139             * </p>
140             *
141             * @param groupId the group ID
142             * @param start the lower bound of the range of asset tags
143             * @param end the upper bound of the range of asset tags (not inclusive)
144             * @return the range of matching asset tags
145             */
146            @Override
147            public List<AssetTag> findByGroupId(long groupId, int start, int end) {
148                    return findByGroupId(groupId, start, end, null);
149            }
150    
151            /**
152             * Returns an ordered range of all the asset tags where groupId = &#63;.
153             *
154             * <p>
155             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetTagModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
156             * </p>
157             *
158             * @param groupId the group ID
159             * @param start the lower bound of the range of asset tags
160             * @param end the upper bound of the range of asset tags (not inclusive)
161             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
162             * @return the ordered range of matching asset tags
163             */
164            @Override
165            public List<AssetTag> findByGroupId(long groupId, int start, int end,
166                    OrderByComparator<AssetTag> orderByComparator) {
167                    boolean pagination = true;
168                    FinderPath finderPath = null;
169                    Object[] finderArgs = null;
170    
171                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
172                                    (orderByComparator == null)) {
173                            pagination = false;
174                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
175                            finderArgs = new Object[] { groupId };
176                    }
177                    else {
178                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
179                            finderArgs = new Object[] { groupId, start, end, orderByComparator };
180                    }
181    
182                    List<AssetTag> list = (List<AssetTag>)FinderCacheUtil.getResult(finderPath,
183                                    finderArgs, this);
184    
185                    if ((list != null) && !list.isEmpty()) {
186                            for (AssetTag assetTag : list) {
187                                    if ((groupId != assetTag.getGroupId())) {
188                                            list = null;
189    
190                                            break;
191                                    }
192                            }
193                    }
194    
195                    if (list == null) {
196                            StringBundler query = null;
197    
198                            if (orderByComparator != null) {
199                                    query = new StringBundler(3 +
200                                                    (orderByComparator.getOrderByFields().length * 3));
201                            }
202                            else {
203                                    query = new StringBundler(3);
204                            }
205    
206                            query.append(_SQL_SELECT_ASSETTAG_WHERE);
207    
208                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
209    
210                            if (orderByComparator != null) {
211                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
212                                            orderByComparator);
213                            }
214                            else
215                             if (pagination) {
216                                    query.append(AssetTagModelImpl.ORDER_BY_JPQL);
217                            }
218    
219                            String sql = query.toString();
220    
221                            Session session = null;
222    
223                            try {
224                                    session = openSession();
225    
226                                    Query q = session.createQuery(sql);
227    
228                                    QueryPos qPos = QueryPos.getInstance(q);
229    
230                                    qPos.add(groupId);
231    
232                                    if (!pagination) {
233                                            list = (List<AssetTag>)QueryUtil.list(q, getDialect(),
234                                                            start, end, false);
235    
236                                            Collections.sort(list);
237    
238                                            list = Collections.unmodifiableList(list);
239                                    }
240                                    else {
241                                            list = (List<AssetTag>)QueryUtil.list(q, getDialect(),
242                                                            start, end);
243                                    }
244    
245                                    cacheResult(list);
246    
247                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
248                            }
249                            catch (Exception e) {
250                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
251    
252                                    throw processException(e);
253                            }
254                            finally {
255                                    closeSession(session);
256                            }
257                    }
258    
259                    return list;
260            }
261    
262            /**
263             * Returns the first asset tag in the ordered set where groupId = &#63;.
264             *
265             * @param groupId the group ID
266             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
267             * @return the first matching asset tag
268             * @throws NoSuchTagException if a matching asset tag could not be found
269             */
270            @Override
271            public AssetTag findByGroupId_First(long groupId,
272                    OrderByComparator<AssetTag> orderByComparator)
273                    throws NoSuchTagException {
274                    AssetTag assetTag = fetchByGroupId_First(groupId, orderByComparator);
275    
276                    if (assetTag != null) {
277                            return assetTag;
278                    }
279    
280                    StringBundler msg = new StringBundler(4);
281    
282                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
283    
284                    msg.append("groupId=");
285                    msg.append(groupId);
286    
287                    msg.append(StringPool.CLOSE_CURLY_BRACE);
288    
289                    throw new NoSuchTagException(msg.toString());
290            }
291    
292            /**
293             * Returns the first asset tag in the ordered set where groupId = &#63;.
294             *
295             * @param groupId the group ID
296             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
297             * @return the first matching asset tag, or <code>null</code> if a matching asset tag could not be found
298             */
299            @Override
300            public AssetTag fetchByGroupId_First(long groupId,
301                    OrderByComparator<AssetTag> orderByComparator) {
302                    List<AssetTag> list = findByGroupId(groupId, 0, 1, orderByComparator);
303    
304                    if (!list.isEmpty()) {
305                            return list.get(0);
306                    }
307    
308                    return null;
309            }
310    
311            /**
312             * Returns the last asset tag in the ordered set where groupId = &#63;.
313             *
314             * @param groupId the group ID
315             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
316             * @return the last matching asset tag
317             * @throws NoSuchTagException if a matching asset tag could not be found
318             */
319            @Override
320            public AssetTag findByGroupId_Last(long groupId,
321                    OrderByComparator<AssetTag> orderByComparator)
322                    throws NoSuchTagException {
323                    AssetTag assetTag = fetchByGroupId_Last(groupId, orderByComparator);
324    
325                    if (assetTag != null) {
326                            return assetTag;
327                    }
328    
329                    StringBundler msg = new StringBundler(4);
330    
331                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
332    
333                    msg.append("groupId=");
334                    msg.append(groupId);
335    
336                    msg.append(StringPool.CLOSE_CURLY_BRACE);
337    
338                    throw new NoSuchTagException(msg.toString());
339            }
340    
341            /**
342             * Returns the last asset tag in the ordered set where groupId = &#63;.
343             *
344             * @param groupId the group ID
345             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
346             * @return the last matching asset tag, or <code>null</code> if a matching asset tag could not be found
347             */
348            @Override
349            public AssetTag fetchByGroupId_Last(long groupId,
350                    OrderByComparator<AssetTag> orderByComparator) {
351                    int count = countByGroupId(groupId);
352    
353                    if (count == 0) {
354                            return null;
355                    }
356    
357                    List<AssetTag> list = findByGroupId(groupId, count - 1, count,
358                                    orderByComparator);
359    
360                    if (!list.isEmpty()) {
361                            return list.get(0);
362                    }
363    
364                    return null;
365            }
366    
367            /**
368             * Returns the asset tags before and after the current asset tag in the ordered set where groupId = &#63;.
369             *
370             * @param tagId the primary key of the current asset tag
371             * @param groupId the group ID
372             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
373             * @return the previous, current, and next asset tag
374             * @throws NoSuchTagException if a asset tag with the primary key could not be found
375             */
376            @Override
377            public AssetTag[] findByGroupId_PrevAndNext(long tagId, long groupId,
378                    OrderByComparator<AssetTag> orderByComparator)
379                    throws NoSuchTagException {
380                    AssetTag assetTag = findByPrimaryKey(tagId);
381    
382                    Session session = null;
383    
384                    try {
385                            session = openSession();
386    
387                            AssetTag[] array = new AssetTagImpl[3];
388    
389                            array[0] = getByGroupId_PrevAndNext(session, assetTag, groupId,
390                                            orderByComparator, true);
391    
392                            array[1] = assetTag;
393    
394                            array[2] = getByGroupId_PrevAndNext(session, assetTag, groupId,
395                                            orderByComparator, false);
396    
397                            return array;
398                    }
399                    catch (Exception e) {
400                            throw processException(e);
401                    }
402                    finally {
403                            closeSession(session);
404                    }
405            }
406    
407            protected AssetTag getByGroupId_PrevAndNext(Session session,
408                    AssetTag assetTag, long groupId,
409                    OrderByComparator<AssetTag> orderByComparator, boolean previous) {
410                    StringBundler query = null;
411    
412                    if (orderByComparator != null) {
413                            query = new StringBundler(6 +
414                                            (orderByComparator.getOrderByFields().length * 6));
415                    }
416                    else {
417                            query = new StringBundler(3);
418                    }
419    
420                    query.append(_SQL_SELECT_ASSETTAG_WHERE);
421    
422                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
423    
424                    if (orderByComparator != null) {
425                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
426    
427                            if (orderByConditionFields.length > 0) {
428                                    query.append(WHERE_AND);
429                            }
430    
431                            for (int i = 0; i < orderByConditionFields.length; i++) {
432                                    query.append(_ORDER_BY_ENTITY_ALIAS);
433                                    query.append(orderByConditionFields[i]);
434    
435                                    if ((i + 1) < orderByConditionFields.length) {
436                                            if (orderByComparator.isAscending() ^ previous) {
437                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
438                                            }
439                                            else {
440                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
441                                            }
442                                    }
443                                    else {
444                                            if (orderByComparator.isAscending() ^ previous) {
445                                                    query.append(WHERE_GREATER_THAN);
446                                            }
447                                            else {
448                                                    query.append(WHERE_LESSER_THAN);
449                                            }
450                                    }
451                            }
452    
453                            query.append(ORDER_BY_CLAUSE);
454    
455                            String[] orderByFields = orderByComparator.getOrderByFields();
456    
457                            for (int i = 0; i < orderByFields.length; i++) {
458                                    query.append(_ORDER_BY_ENTITY_ALIAS);
459                                    query.append(orderByFields[i]);
460    
461                                    if ((i + 1) < orderByFields.length) {
462                                            if (orderByComparator.isAscending() ^ previous) {
463                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
464                                            }
465                                            else {
466                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
467                                            }
468                                    }
469                                    else {
470                                            if (orderByComparator.isAscending() ^ previous) {
471                                                    query.append(ORDER_BY_ASC);
472                                            }
473                                            else {
474                                                    query.append(ORDER_BY_DESC);
475                                            }
476                                    }
477                            }
478                    }
479                    else {
480                            query.append(AssetTagModelImpl.ORDER_BY_JPQL);
481                    }
482    
483                    String sql = query.toString();
484    
485                    Query q = session.createQuery(sql);
486    
487                    q.setFirstResult(0);
488                    q.setMaxResults(2);
489    
490                    QueryPos qPos = QueryPos.getInstance(q);
491    
492                    qPos.add(groupId);
493    
494                    if (orderByComparator != null) {
495                            Object[] values = orderByComparator.getOrderByConditionValues(assetTag);
496    
497                            for (Object value : values) {
498                                    qPos.add(value);
499                            }
500                    }
501    
502                    List<AssetTag> list = q.list();
503    
504                    if (list.size() == 2) {
505                            return list.get(1);
506                    }
507                    else {
508                            return null;
509                    }
510            }
511    
512            /**
513             * Returns all the asset tags that the user has permission to view where groupId = &#63;.
514             *
515             * @param groupId the group ID
516             * @return the matching asset tags that the user has permission to view
517             */
518            @Override
519            public List<AssetTag> filterFindByGroupId(long groupId) {
520                    return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
521                            QueryUtil.ALL_POS, null);
522            }
523    
524            /**
525             * Returns a range of all the asset tags that the user has permission to view where groupId = &#63;.
526             *
527             * <p>
528             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetTagModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
529             * </p>
530             *
531             * @param groupId the group ID
532             * @param start the lower bound of the range of asset tags
533             * @param end the upper bound of the range of asset tags (not inclusive)
534             * @return the range of matching asset tags that the user has permission to view
535             */
536            @Override
537            public List<AssetTag> filterFindByGroupId(long groupId, int start, int end) {
538                    return filterFindByGroupId(groupId, start, end, null);
539            }
540    
541            /**
542             * Returns an ordered range of all the asset tags that the user has permissions to view where groupId = &#63;.
543             *
544             * <p>
545             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetTagModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
546             * </p>
547             *
548             * @param groupId the group ID
549             * @param start the lower bound of the range of asset tags
550             * @param end the upper bound of the range of asset tags (not inclusive)
551             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
552             * @return the ordered range of matching asset tags that the user has permission to view
553             */
554            @Override
555            public List<AssetTag> filterFindByGroupId(long groupId, int start, int end,
556                    OrderByComparator<AssetTag> orderByComparator) {
557                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
558                            return findByGroupId(groupId, start, end, orderByComparator);
559                    }
560    
561                    StringBundler query = null;
562    
563                    if (orderByComparator != null) {
564                            query = new StringBundler(3 +
565                                            (orderByComparator.getOrderByFields().length * 3));
566                    }
567                    else {
568                            query = new StringBundler(3);
569                    }
570    
571                    if (getDB().isSupportsInlineDistinct()) {
572                            query.append(_FILTER_SQL_SELECT_ASSETTAG_WHERE);
573                    }
574                    else {
575                            query.append(_FILTER_SQL_SELECT_ASSETTAG_NO_INLINE_DISTINCT_WHERE_1);
576                    }
577    
578                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
579    
580                    if (!getDB().isSupportsInlineDistinct()) {
581                            query.append(_FILTER_SQL_SELECT_ASSETTAG_NO_INLINE_DISTINCT_WHERE_2);
582                    }
583    
584                    if (orderByComparator != null) {
585                            if (getDB().isSupportsInlineDistinct()) {
586                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
587                                            orderByComparator, true);
588                            }
589                            else {
590                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
591                                            orderByComparator, true);
592                            }
593                    }
594                    else {
595                            if (getDB().isSupportsInlineDistinct()) {
596                                    query.append(AssetTagModelImpl.ORDER_BY_JPQL);
597                            }
598                            else {
599                                    query.append(AssetTagModelImpl.ORDER_BY_SQL);
600                            }
601                    }
602    
603                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
604                                    AssetTag.class.getName(),
605                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
606    
607                    Session session = null;
608    
609                    try {
610                            session = openSession();
611    
612                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
613    
614                            if (getDB().isSupportsInlineDistinct()) {
615                                    q.addEntity(_FILTER_ENTITY_ALIAS, AssetTagImpl.class);
616                            }
617                            else {
618                                    q.addEntity(_FILTER_ENTITY_TABLE, AssetTagImpl.class);
619                            }
620    
621                            QueryPos qPos = QueryPos.getInstance(q);
622    
623                            qPos.add(groupId);
624    
625                            return (List<AssetTag>)QueryUtil.list(q, getDialect(), start, end);
626                    }
627                    catch (Exception e) {
628                            throw processException(e);
629                    }
630                    finally {
631                            closeSession(session);
632                    }
633            }
634    
635            /**
636             * 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;.
637             *
638             * @param tagId the primary key of the current asset tag
639             * @param groupId the group ID
640             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
641             * @return the previous, current, and next asset tag
642             * @throws NoSuchTagException if a asset tag with the primary key could not be found
643             */
644            @Override
645            public AssetTag[] filterFindByGroupId_PrevAndNext(long tagId, long groupId,
646                    OrderByComparator<AssetTag> orderByComparator)
647                    throws NoSuchTagException {
648                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
649                            return findByGroupId_PrevAndNext(tagId, groupId, orderByComparator);
650                    }
651    
652                    AssetTag assetTag = findByPrimaryKey(tagId);
653    
654                    Session session = null;
655    
656                    try {
657                            session = openSession();
658    
659                            AssetTag[] array = new AssetTagImpl[3];
660    
661                            array[0] = filterGetByGroupId_PrevAndNext(session, assetTag,
662                                            groupId, orderByComparator, true);
663    
664                            array[1] = assetTag;
665    
666                            array[2] = filterGetByGroupId_PrevAndNext(session, assetTag,
667                                            groupId, orderByComparator, false);
668    
669                            return array;
670                    }
671                    catch (Exception e) {
672                            throw processException(e);
673                    }
674                    finally {
675                            closeSession(session);
676                    }
677            }
678    
679            protected AssetTag filterGetByGroupId_PrevAndNext(Session session,
680                    AssetTag assetTag, long groupId,
681                    OrderByComparator<AssetTag> orderByComparator, boolean previous) {
682                    StringBundler query = null;
683    
684                    if (orderByComparator != null) {
685                            query = new StringBundler(6 +
686                                            (orderByComparator.getOrderByFields().length * 6));
687                    }
688                    else {
689                            query = new StringBundler(3);
690                    }
691    
692                    if (getDB().isSupportsInlineDistinct()) {
693                            query.append(_FILTER_SQL_SELECT_ASSETTAG_WHERE);
694                    }
695                    else {
696                            query.append(_FILTER_SQL_SELECT_ASSETTAG_NO_INLINE_DISTINCT_WHERE_1);
697                    }
698    
699                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
700    
701                    if (!getDB().isSupportsInlineDistinct()) {
702                            query.append(_FILTER_SQL_SELECT_ASSETTAG_NO_INLINE_DISTINCT_WHERE_2);
703                    }
704    
705                    if (orderByComparator != null) {
706                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
707    
708                            if (orderByConditionFields.length > 0) {
709                                    query.append(WHERE_AND);
710                            }
711    
712                            for (int i = 0; i < orderByConditionFields.length; i++) {
713                                    if (getDB().isSupportsInlineDistinct()) {
714                                            query.append(_ORDER_BY_ENTITY_ALIAS);
715                                    }
716                                    else {
717                                            query.append(_ORDER_BY_ENTITY_TABLE);
718                                    }
719    
720                                    query.append(orderByConditionFields[i]);
721    
722                                    if ((i + 1) < orderByConditionFields.length) {
723                                            if (orderByComparator.isAscending() ^ previous) {
724                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
725                                            }
726                                            else {
727                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
728                                            }
729                                    }
730                                    else {
731                                            if (orderByComparator.isAscending() ^ previous) {
732                                                    query.append(WHERE_GREATER_THAN);
733                                            }
734                                            else {
735                                                    query.append(WHERE_LESSER_THAN);
736                                            }
737                                    }
738                            }
739    
740                            query.append(ORDER_BY_CLAUSE);
741    
742                            String[] orderByFields = orderByComparator.getOrderByFields();
743    
744                            for (int i = 0; i < orderByFields.length; i++) {
745                                    if (getDB().isSupportsInlineDistinct()) {
746                                            query.append(_ORDER_BY_ENTITY_ALIAS);
747                                    }
748                                    else {
749                                            query.append(_ORDER_BY_ENTITY_TABLE);
750                                    }
751    
752                                    query.append(orderByFields[i]);
753    
754                                    if ((i + 1) < orderByFields.length) {
755                                            if (orderByComparator.isAscending() ^ previous) {
756                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
757                                            }
758                                            else {
759                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
760                                            }
761                                    }
762                                    else {
763                                            if (orderByComparator.isAscending() ^ previous) {
764                                                    query.append(ORDER_BY_ASC);
765                                            }
766                                            else {
767                                                    query.append(ORDER_BY_DESC);
768                                            }
769                                    }
770                            }
771                    }
772                    else {
773                            if (getDB().isSupportsInlineDistinct()) {
774                                    query.append(AssetTagModelImpl.ORDER_BY_JPQL);
775                            }
776                            else {
777                                    query.append(AssetTagModelImpl.ORDER_BY_SQL);
778                            }
779                    }
780    
781                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
782                                    AssetTag.class.getName(),
783                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
784    
785                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
786    
787                    q.setFirstResult(0);
788                    q.setMaxResults(2);
789    
790                    if (getDB().isSupportsInlineDistinct()) {
791                            q.addEntity(_FILTER_ENTITY_ALIAS, AssetTagImpl.class);
792                    }
793                    else {
794                            q.addEntity(_FILTER_ENTITY_TABLE, AssetTagImpl.class);
795                    }
796    
797                    QueryPos qPos = QueryPos.getInstance(q);
798    
799                    qPos.add(groupId);
800    
801                    if (orderByComparator != null) {
802                            Object[] values = orderByComparator.getOrderByConditionValues(assetTag);
803    
804                            for (Object value : values) {
805                                    qPos.add(value);
806                            }
807                    }
808    
809                    List<AssetTag> list = q.list();
810    
811                    if (list.size() == 2) {
812                            return list.get(1);
813                    }
814                    else {
815                            return null;
816                    }
817            }
818    
819            /**
820             * Returns all the asset tags that the user has permission to view where groupId = any &#63;.
821             *
822             * @param groupIds the group IDs
823             * @return the matching asset tags that the user has permission to view
824             */
825            @Override
826            public List<AssetTag> filterFindByGroupId(long[] groupIds) {
827                    return filterFindByGroupId(groupIds, QueryUtil.ALL_POS,
828                            QueryUtil.ALL_POS, null);
829            }
830    
831            /**
832             * Returns a range of all the asset tags that the user has permission to view where groupId = any &#63;.
833             *
834             * <p>
835             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetTagModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
836             * </p>
837             *
838             * @param groupIds the group IDs
839             * @param start the lower bound of the range of asset tags
840             * @param end the upper bound of the range of asset tags (not inclusive)
841             * @return the range of matching asset tags that the user has permission to view
842             */
843            @Override
844            public List<AssetTag> filterFindByGroupId(long[] groupIds, int start,
845                    int end) {
846                    return filterFindByGroupId(groupIds, start, end, null);
847            }
848    
849            /**
850             * Returns an ordered range of all the asset tags that the user has permission to view where groupId = any &#63;.
851             *
852             * <p>
853             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetTagModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
854             * </p>
855             *
856             * @param groupIds the group IDs
857             * @param start the lower bound of the range of asset tags
858             * @param end the upper bound of the range of asset tags (not inclusive)
859             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
860             * @return the ordered range of matching asset tags that the user has permission to view
861             */
862            @Override
863            public List<AssetTag> filterFindByGroupId(long[] groupIds, int start,
864                    int end, OrderByComparator<AssetTag> orderByComparator) {
865                    if (!InlineSQLHelperUtil.isEnabled(groupIds)) {
866                            return findByGroupId(groupIds, start, end, orderByComparator);
867                    }
868    
869                    if (groupIds == null) {
870                            groupIds = new long[0];
871                    }
872                    else {
873                            groupIds = ArrayUtil.unique(groupIds);
874                    }
875    
876                    StringBundler query = new StringBundler();
877    
878                    if (getDB().isSupportsInlineDistinct()) {
879                            query.append(_FILTER_SQL_SELECT_ASSETTAG_WHERE);
880                    }
881                    else {
882                            query.append(_FILTER_SQL_SELECT_ASSETTAG_NO_INLINE_DISTINCT_WHERE_1);
883                    }
884    
885                    if (groupIds.length > 0) {
886                            query.append(StringPool.OPEN_PARENTHESIS);
887    
888                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_7);
889    
890                            query.append(StringUtil.merge(groupIds));
891    
892                            query.append(StringPool.CLOSE_PARENTHESIS);
893    
894                            query.append(StringPool.CLOSE_PARENTHESIS);
895                    }
896    
897                    query.setStringAt(removeConjunction(query.stringAt(query.index() - 1)),
898                            query.index() - 1);
899    
900                    if (!getDB().isSupportsInlineDistinct()) {
901                            query.append(_FILTER_SQL_SELECT_ASSETTAG_NO_INLINE_DISTINCT_WHERE_2);
902                    }
903    
904                    if (orderByComparator != null) {
905                            if (getDB().isSupportsInlineDistinct()) {
906                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
907                                            orderByComparator, true);
908                            }
909                            else {
910                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
911                                            orderByComparator, true);
912                            }
913                    }
914                    else {
915                            if (getDB().isSupportsInlineDistinct()) {
916                                    query.append(AssetTagModelImpl.ORDER_BY_JPQL);
917                            }
918                            else {
919                                    query.append(AssetTagModelImpl.ORDER_BY_SQL);
920                            }
921                    }
922    
923                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
924                                    AssetTag.class.getName(),
925                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupIds);
926    
927                    Session session = null;
928    
929                    try {
930                            session = openSession();
931    
932                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
933    
934                            if (getDB().isSupportsInlineDistinct()) {
935                                    q.addEntity(_FILTER_ENTITY_ALIAS, AssetTagImpl.class);
936                            }
937                            else {
938                                    q.addEntity(_FILTER_ENTITY_TABLE, AssetTagImpl.class);
939                            }
940    
941                            return (List<AssetTag>)QueryUtil.list(q, getDialect(), start, end);
942                    }
943                    catch (Exception e) {
944                            throw processException(e);
945                    }
946                    finally {
947                            closeSession(session);
948                    }
949            }
950    
951            /**
952             * Returns all the asset tags where groupId = any &#63;.
953             *
954             * <p>
955             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetTagModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
956             * </p>
957             *
958             * @param groupIds the group IDs
959             * @return the matching asset tags
960             */
961            @Override
962            public List<AssetTag> findByGroupId(long[] groupIds) {
963                    return findByGroupId(groupIds, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
964                            null);
965            }
966    
967            /**
968             * Returns a range of all the asset tags where groupId = any &#63;.
969             *
970             * <p>
971             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetTagModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
972             * </p>
973             *
974             * @param groupIds the group IDs
975             * @param start the lower bound of the range of asset tags
976             * @param end the upper bound of the range of asset tags (not inclusive)
977             * @return the range of matching asset tags
978             */
979            @Override
980            public List<AssetTag> findByGroupId(long[] groupIds, int start, int end) {
981                    return findByGroupId(groupIds, start, end, null);
982            }
983    
984            /**
985             * Returns an ordered range of all the asset tags where groupId = any &#63;.
986             *
987             * <p>
988             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetTagModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
989             * </p>
990             *
991             * @param groupIds the group IDs
992             * @param start the lower bound of the range of asset tags
993             * @param end the upper bound of the range of asset tags (not inclusive)
994             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
995             * @return the ordered range of matching asset tags
996             */
997            @Override
998            public List<AssetTag> findByGroupId(long[] groupIds, int start, int end,
999                    OrderByComparator<AssetTag> orderByComparator) {
1000                    if (groupIds == null) {
1001                            groupIds = new long[0];
1002                    }
1003                    else {
1004                            groupIds = ArrayUtil.unique(groupIds);
1005                    }
1006    
1007                    if (groupIds.length == 1) {
1008                            return findByGroupId(groupIds[0], start, end, orderByComparator);
1009                    }
1010    
1011                    boolean pagination = true;
1012                    Object[] finderArgs = null;
1013    
1014                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1015                                    (orderByComparator == null)) {
1016                            pagination = false;
1017                            finderArgs = new Object[] { StringUtil.merge(groupIds) };
1018                    }
1019                    else {
1020                            finderArgs = new Object[] {
1021                                            StringUtil.merge(groupIds),
1022                                            
1023                                            start, end, orderByComparator
1024                                    };
1025                    }
1026    
1027                    List<AssetTag> list = (List<AssetTag>)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID,
1028                                    finderArgs, this);
1029    
1030                    if ((list != null) && !list.isEmpty()) {
1031                            for (AssetTag assetTag : list) {
1032                                    if (!ArrayUtil.contains(groupIds, assetTag.getGroupId())) {
1033                                            list = null;
1034    
1035                                            break;
1036                                    }
1037                            }
1038                    }
1039    
1040                    if (list == null) {
1041                            StringBundler query = new StringBundler();
1042    
1043                            query.append(_SQL_SELECT_ASSETTAG_WHERE);
1044    
1045                            if (groupIds.length > 0) {
1046                                    query.append(StringPool.OPEN_PARENTHESIS);
1047    
1048                                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_7);
1049    
1050                                    query.append(StringUtil.merge(groupIds));
1051    
1052                                    query.append(StringPool.CLOSE_PARENTHESIS);
1053    
1054                                    query.append(StringPool.CLOSE_PARENTHESIS);
1055                            }
1056    
1057                            query.setStringAt(removeConjunction(query.stringAt(query.index() -
1058                                                    1)), query.index() - 1);
1059    
1060                            if (orderByComparator != null) {
1061                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1062                                            orderByComparator);
1063                            }
1064                            else
1065                             if (pagination) {
1066                                    query.append(AssetTagModelImpl.ORDER_BY_JPQL);
1067                            }
1068    
1069                            String sql = query.toString();
1070    
1071                            Session session = null;
1072    
1073                            try {
1074                                    session = openSession();
1075    
1076                                    Query q = session.createQuery(sql);
1077    
1078                                    if (!pagination) {
1079                                            list = (List<AssetTag>)QueryUtil.list(q, getDialect(),
1080                                                            start, end, false);
1081    
1082                                            Collections.sort(list);
1083    
1084                                            list = Collections.unmodifiableList(list);
1085                                    }
1086                                    else {
1087                                            list = (List<AssetTag>)QueryUtil.list(q, getDialect(),
1088                                                            start, end);
1089                                    }
1090    
1091                                    cacheResult(list);
1092    
1093                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID,
1094                                            finderArgs, list);
1095                            }
1096                            catch (Exception e) {
1097                                    FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID,
1098                                            finderArgs);
1099    
1100                                    throw processException(e);
1101                            }
1102                            finally {
1103                                    closeSession(session);
1104                            }
1105                    }
1106    
1107                    return list;
1108            }
1109    
1110            /**
1111             * Removes all the asset tags where groupId = &#63; from the database.
1112             *
1113             * @param groupId the group ID
1114             */
1115            @Override
1116            public void removeByGroupId(long groupId) {
1117                    for (AssetTag assetTag : findByGroupId(groupId, QueryUtil.ALL_POS,
1118                                    QueryUtil.ALL_POS, null)) {
1119                            remove(assetTag);
1120                    }
1121            }
1122    
1123            /**
1124             * Returns the number of asset tags where groupId = &#63;.
1125             *
1126             * @param groupId the group ID
1127             * @return the number of matching asset tags
1128             */
1129            @Override
1130            public int countByGroupId(long groupId) {
1131                    FinderPath finderPath = FINDER_PATH_COUNT_BY_GROUPID;
1132    
1133                    Object[] finderArgs = new Object[] { groupId };
1134    
1135                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1136                                    this);
1137    
1138                    if (count == null) {
1139                            StringBundler query = new StringBundler(2);
1140    
1141                            query.append(_SQL_COUNT_ASSETTAG_WHERE);
1142    
1143                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1144    
1145                            String sql = query.toString();
1146    
1147                            Session session = null;
1148    
1149                            try {
1150                                    session = openSession();
1151    
1152                                    Query q = session.createQuery(sql);
1153    
1154                                    QueryPos qPos = QueryPos.getInstance(q);
1155    
1156                                    qPos.add(groupId);
1157    
1158                                    count = (Long)q.uniqueResult();
1159    
1160                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1161                            }
1162                            catch (Exception e) {
1163                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1164    
1165                                    throw processException(e);
1166                            }
1167                            finally {
1168                                    closeSession(session);
1169                            }
1170                    }
1171    
1172                    return count.intValue();
1173            }
1174    
1175            /**
1176             * Returns the number of asset tags where groupId = any &#63;.
1177             *
1178             * @param groupIds the group IDs
1179             * @return the number of matching asset tags
1180             */
1181            @Override
1182            public int countByGroupId(long[] groupIds) {
1183                    if (groupIds == null) {
1184                            groupIds = new long[0];
1185                    }
1186                    else {
1187                            groupIds = ArrayUtil.unique(groupIds);
1188                    }
1189    
1190                    Object[] finderArgs = new Object[] { StringUtil.merge(groupIds) };
1191    
1192                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_GROUPID,
1193                                    finderArgs, this);
1194    
1195                    if (count == null) {
1196                            StringBundler query = new StringBundler();
1197    
1198                            query.append(_SQL_COUNT_ASSETTAG_WHERE);
1199    
1200                            if (groupIds.length > 0) {
1201                                    query.append(StringPool.OPEN_PARENTHESIS);
1202    
1203                                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_7);
1204    
1205                                    query.append(StringUtil.merge(groupIds));
1206    
1207                                    query.append(StringPool.CLOSE_PARENTHESIS);
1208    
1209                                    query.append(StringPool.CLOSE_PARENTHESIS);
1210                            }
1211    
1212                            query.setStringAt(removeConjunction(query.stringAt(query.index() -
1213                                                    1)), query.index() - 1);
1214    
1215                            String sql = query.toString();
1216    
1217                            Session session = null;
1218    
1219                            try {
1220                                    session = openSession();
1221    
1222                                    Query q = session.createQuery(sql);
1223    
1224                                    count = (Long)q.uniqueResult();
1225    
1226                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_GROUPID,
1227                                            finderArgs, count);
1228                            }
1229                            catch (Exception e) {
1230                                    FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_GROUPID,
1231                                            finderArgs);
1232    
1233                                    throw processException(e);
1234                            }
1235                            finally {
1236                                    closeSession(session);
1237                            }
1238                    }
1239    
1240                    return count.intValue();
1241            }
1242    
1243            /**
1244             * Returns the number of asset tags that the user has permission to view where groupId = &#63;.
1245             *
1246             * @param groupId the group ID
1247             * @return the number of matching asset tags that the user has permission to view
1248             */
1249            @Override
1250            public int filterCountByGroupId(long groupId) {
1251                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1252                            return countByGroupId(groupId);
1253                    }
1254    
1255                    StringBundler query = new StringBundler(2);
1256    
1257                    query.append(_FILTER_SQL_COUNT_ASSETTAG_WHERE);
1258    
1259                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1260    
1261                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1262                                    AssetTag.class.getName(),
1263                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
1264    
1265                    Session session = null;
1266    
1267                    try {
1268                            session = openSession();
1269    
1270                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
1271    
1272                            q.addScalar(COUNT_COLUMN_NAME,
1273                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
1274    
1275                            QueryPos qPos = QueryPos.getInstance(q);
1276    
1277                            qPos.add(groupId);
1278    
1279                            Long count = (Long)q.uniqueResult();
1280    
1281                            return count.intValue();
1282                    }
1283                    catch (Exception e) {
1284                            throw processException(e);
1285                    }
1286                    finally {
1287                            closeSession(session);
1288                    }
1289            }
1290    
1291            /**
1292             * Returns the number of asset tags that the user has permission to view where groupId = any &#63;.
1293             *
1294             * @param groupIds the group IDs
1295             * @return the number of matching asset tags that the user has permission to view
1296             */
1297            @Override
1298            public int filterCountByGroupId(long[] groupIds) {
1299                    if (!InlineSQLHelperUtil.isEnabled(groupIds)) {
1300                            return countByGroupId(groupIds);
1301                    }
1302    
1303                    if (groupIds == null) {
1304                            groupIds = new long[0];
1305                    }
1306                    else {
1307                            groupIds = ArrayUtil.unique(groupIds);
1308                    }
1309    
1310                    StringBundler query = new StringBundler();
1311    
1312                    query.append(_FILTER_SQL_COUNT_ASSETTAG_WHERE);
1313    
1314                    if (groupIds.length > 0) {
1315                            query.append(StringPool.OPEN_PARENTHESIS);
1316    
1317                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_7);
1318    
1319                            query.append(StringUtil.merge(groupIds));
1320    
1321                            query.append(StringPool.CLOSE_PARENTHESIS);
1322    
1323                            query.append(StringPool.CLOSE_PARENTHESIS);
1324                    }
1325    
1326                    query.setStringAt(removeConjunction(query.stringAt(query.index() - 1)),
1327                            query.index() - 1);
1328    
1329                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1330                                    AssetTag.class.getName(),
1331                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupIds);
1332    
1333                    Session session = null;
1334    
1335                    try {
1336                            session = openSession();
1337    
1338                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
1339    
1340                            q.addScalar(COUNT_COLUMN_NAME,
1341                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
1342    
1343                            Long count = (Long)q.uniqueResult();
1344    
1345                            return count.intValue();
1346                    }
1347                    catch (Exception e) {
1348                            throw processException(e);
1349                    }
1350                    finally {
1351                            closeSession(session);
1352                    }
1353            }
1354    
1355            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "assetTag.groupId = ?";
1356            private static final String _FINDER_COLUMN_GROUPID_GROUPID_7 = "assetTag.groupId IN (";
1357            public static final FinderPath FINDER_PATH_FETCH_BY_G_N = new FinderPath(AssetTagModelImpl.ENTITY_CACHE_ENABLED,
1358                            AssetTagModelImpl.FINDER_CACHE_ENABLED, AssetTagImpl.class,
1359                            FINDER_CLASS_NAME_ENTITY, "fetchByG_N",
1360                            new String[] { Long.class.getName(), String.class.getName() },
1361                            AssetTagModelImpl.GROUPID_COLUMN_BITMASK |
1362                            AssetTagModelImpl.NAME_COLUMN_BITMASK);
1363            public static final FinderPath FINDER_PATH_COUNT_BY_G_N = new FinderPath(AssetTagModelImpl.ENTITY_CACHE_ENABLED,
1364                            AssetTagModelImpl.FINDER_CACHE_ENABLED, Long.class,
1365                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_N",
1366                            new String[] { Long.class.getName(), String.class.getName() });
1367    
1368            /**
1369             * Returns the asset tag where groupId = &#63; and name = &#63; or throws a {@link NoSuchTagException} if it could not be found.
1370             *
1371             * @param groupId the group ID
1372             * @param name the name
1373             * @return the matching asset tag
1374             * @throws NoSuchTagException if a matching asset tag could not be found
1375             */
1376            @Override
1377            public AssetTag findByG_N(long groupId, String name)
1378                    throws NoSuchTagException {
1379                    AssetTag assetTag = fetchByG_N(groupId, name);
1380    
1381                    if (assetTag == null) {
1382                            StringBundler msg = new StringBundler(6);
1383    
1384                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1385    
1386                            msg.append("groupId=");
1387                            msg.append(groupId);
1388    
1389                            msg.append(", name=");
1390                            msg.append(name);
1391    
1392                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1393    
1394                            if (_log.isWarnEnabled()) {
1395                                    _log.warn(msg.toString());
1396                            }
1397    
1398                            throw new NoSuchTagException(msg.toString());
1399                    }
1400    
1401                    return assetTag;
1402            }
1403    
1404            /**
1405             * 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.
1406             *
1407             * @param groupId the group ID
1408             * @param name the name
1409             * @return the matching asset tag, or <code>null</code> if a matching asset tag could not be found
1410             */
1411            @Override
1412            public AssetTag fetchByG_N(long groupId, String name) {
1413                    return fetchByG_N(groupId, name, true);
1414            }
1415    
1416            /**
1417             * 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.
1418             *
1419             * @param groupId the group ID
1420             * @param name the name
1421             * @param retrieveFromCache whether to use the finder cache
1422             * @return the matching asset tag, or <code>null</code> if a matching asset tag could not be found
1423             */
1424            @Override
1425            public AssetTag fetchByG_N(long groupId, String name,
1426                    boolean retrieveFromCache) {
1427                    Object[] finderArgs = new Object[] { groupId, name };
1428    
1429                    Object result = null;
1430    
1431                    if (retrieveFromCache) {
1432                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_N,
1433                                            finderArgs, this);
1434                    }
1435    
1436                    if (result instanceof AssetTag) {
1437                            AssetTag assetTag = (AssetTag)result;
1438    
1439                            if ((groupId != assetTag.getGroupId()) ||
1440                                            !Validator.equals(name, assetTag.getName())) {
1441                                    result = null;
1442                            }
1443                    }
1444    
1445                    if (result == null) {
1446                            StringBundler query = new StringBundler(4);
1447    
1448                            query.append(_SQL_SELECT_ASSETTAG_WHERE);
1449    
1450                            query.append(_FINDER_COLUMN_G_N_GROUPID_2);
1451    
1452                            boolean bindName = false;
1453    
1454                            if (name == null) {
1455                                    query.append(_FINDER_COLUMN_G_N_NAME_1);
1456                            }
1457                            else if (name.equals(StringPool.BLANK)) {
1458                                    query.append(_FINDER_COLUMN_G_N_NAME_3);
1459                            }
1460                            else {
1461                                    bindName = true;
1462    
1463                                    query.append(_FINDER_COLUMN_G_N_NAME_2);
1464                            }
1465    
1466                            String sql = query.toString();
1467    
1468                            Session session = null;
1469    
1470                            try {
1471                                    session = openSession();
1472    
1473                                    Query q = session.createQuery(sql);
1474    
1475                                    QueryPos qPos = QueryPos.getInstance(q);
1476    
1477                                    qPos.add(groupId);
1478    
1479                                    if (bindName) {
1480                                            qPos.add(name);
1481                                    }
1482    
1483                                    List<AssetTag> list = q.list();
1484    
1485                                    if (list.isEmpty()) {
1486                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N,
1487                                                    finderArgs, list);
1488                                    }
1489                                    else {
1490                                            AssetTag assetTag = list.get(0);
1491    
1492                                            result = assetTag;
1493    
1494                                            cacheResult(assetTag);
1495    
1496                                            if ((assetTag.getGroupId() != groupId) ||
1497                                                            (assetTag.getName() == null) ||
1498                                                            !assetTag.getName().equals(name)) {
1499                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N,
1500                                                            finderArgs, assetTag);
1501                                            }
1502                                    }
1503                            }
1504                            catch (Exception e) {
1505                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_N,
1506                                            finderArgs);
1507    
1508                                    throw processException(e);
1509                            }
1510                            finally {
1511                                    closeSession(session);
1512                            }
1513                    }
1514    
1515                    if (result instanceof List<?>) {
1516                            return null;
1517                    }
1518                    else {
1519                            return (AssetTag)result;
1520                    }
1521            }
1522    
1523            /**
1524             * Removes the asset tag where groupId = &#63; and name = &#63; from the database.
1525             *
1526             * @param groupId the group ID
1527             * @param name the name
1528             * @return the asset tag that was removed
1529             */
1530            @Override
1531            public AssetTag removeByG_N(long groupId, String name)
1532                    throws NoSuchTagException {
1533                    AssetTag assetTag = findByG_N(groupId, name);
1534    
1535                    return remove(assetTag);
1536            }
1537    
1538            /**
1539             * Returns the number of asset tags where groupId = &#63; and name = &#63;.
1540             *
1541             * @param groupId the group ID
1542             * @param name the name
1543             * @return the number of matching asset tags
1544             */
1545            @Override
1546            public int countByG_N(long groupId, String name) {
1547                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_N;
1548    
1549                    Object[] finderArgs = new Object[] { groupId, name };
1550    
1551                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1552                                    this);
1553    
1554                    if (count == null) {
1555                            StringBundler query = new StringBundler(3);
1556    
1557                            query.append(_SQL_COUNT_ASSETTAG_WHERE);
1558    
1559                            query.append(_FINDER_COLUMN_G_N_GROUPID_2);
1560    
1561                            boolean bindName = false;
1562    
1563                            if (name == null) {
1564                                    query.append(_FINDER_COLUMN_G_N_NAME_1);
1565                            }
1566                            else if (name.equals(StringPool.BLANK)) {
1567                                    query.append(_FINDER_COLUMN_G_N_NAME_3);
1568                            }
1569                            else {
1570                                    bindName = true;
1571    
1572                                    query.append(_FINDER_COLUMN_G_N_NAME_2);
1573                            }
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                                    if (bindName) {
1589                                            qPos.add(name);
1590                                    }
1591    
1592                                    count = (Long)q.uniqueResult();
1593    
1594                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1595                            }
1596                            catch (Exception e) {
1597                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1598    
1599                                    throw processException(e);
1600                            }
1601                            finally {
1602                                    closeSession(session);
1603                            }
1604                    }
1605    
1606                    return count.intValue();
1607            }
1608    
1609            private static final String _FINDER_COLUMN_G_N_GROUPID_2 = "assetTag.groupId = ? AND ";
1610            private static final String _FINDER_COLUMN_G_N_NAME_1 = "assetTag.name IS NULL";
1611            private static final String _FINDER_COLUMN_G_N_NAME_2 = "assetTag.name = ?";
1612            private static final String _FINDER_COLUMN_G_N_NAME_3 = "(assetTag.name IS NULL OR assetTag.name = '')";
1613            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_LIKEN = new FinderPath(AssetTagModelImpl.ENTITY_CACHE_ENABLED,
1614                            AssetTagModelImpl.FINDER_CACHE_ENABLED, AssetTagImpl.class,
1615                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_LikeN",
1616                            new String[] {
1617                                    Long.class.getName(), String.class.getName(),
1618                                    
1619                            Integer.class.getName(), Integer.class.getName(),
1620                                    OrderByComparator.class.getName()
1621                            });
1622            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_LIKEN = new FinderPath(AssetTagModelImpl.ENTITY_CACHE_ENABLED,
1623                            AssetTagModelImpl.FINDER_CACHE_ENABLED, Long.class,
1624                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByG_LikeN",
1625                            new String[] { Long.class.getName(), String.class.getName() });
1626    
1627            /**
1628             * Returns all the asset tags where groupId = &#63; and name LIKE &#63;.
1629             *
1630             * @param groupId the group ID
1631             * @param name the name
1632             * @return the matching asset tags
1633             */
1634            @Override
1635            public List<AssetTag> findByG_LikeN(long groupId, String name) {
1636                    return findByG_LikeN(groupId, name, QueryUtil.ALL_POS,
1637                            QueryUtil.ALL_POS, null);
1638            }
1639    
1640            /**
1641             * Returns a range of all the asset tags where groupId = &#63; and name LIKE &#63;.
1642             *
1643             * <p>
1644             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetTagModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1645             * </p>
1646             *
1647             * @param groupId the group ID
1648             * @param name the name
1649             * @param start the lower bound of the range of asset tags
1650             * @param end the upper bound of the range of asset tags (not inclusive)
1651             * @return the range of matching asset tags
1652             */
1653            @Override
1654            public List<AssetTag> findByG_LikeN(long groupId, String name, int start,
1655                    int end) {
1656                    return findByG_LikeN(groupId, name, start, end, null);
1657            }
1658    
1659            /**
1660             * Returns an ordered range of all the asset tags where groupId = &#63; and name LIKE &#63;.
1661             *
1662             * <p>
1663             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetTagModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1664             * </p>
1665             *
1666             * @param groupId the group ID
1667             * @param name the name
1668             * @param start the lower bound of the range of asset tags
1669             * @param end the upper bound of the range of asset tags (not inclusive)
1670             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1671             * @return the ordered range of matching asset tags
1672             */
1673            @Override
1674            public List<AssetTag> findByG_LikeN(long groupId, String name, int start,
1675                    int end, OrderByComparator<AssetTag> orderByComparator) {
1676                    boolean pagination = true;
1677                    FinderPath finderPath = null;
1678                    Object[] finderArgs = null;
1679    
1680                    finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_LIKEN;
1681                    finderArgs = new Object[] { groupId, name, start, end, orderByComparator };
1682    
1683                    List<AssetTag> list = (List<AssetTag>)FinderCacheUtil.getResult(finderPath,
1684                                    finderArgs, this);
1685    
1686                    if ((list != null) && !list.isEmpty()) {
1687                            for (AssetTag assetTag : list) {
1688                                    if ((groupId != assetTag.getGroupId()) ||
1689                                                    !StringUtil.wildcardMatches(assetTag.getName(), name,
1690                                                            CharPool.UNDERLINE, CharPool.PERCENT,
1691                                                            CharPool.BACK_SLASH, true)) {
1692                                            list = null;
1693    
1694                                            break;
1695                                    }
1696                            }
1697                    }
1698    
1699                    if (list == null) {
1700                            StringBundler query = null;
1701    
1702                            if (orderByComparator != null) {
1703                                    query = new StringBundler(4 +
1704                                                    (orderByComparator.getOrderByFields().length * 3));
1705                            }
1706                            else {
1707                                    query = new StringBundler(4);
1708                            }
1709    
1710                            query.append(_SQL_SELECT_ASSETTAG_WHERE);
1711    
1712                            query.append(_FINDER_COLUMN_G_LIKEN_GROUPID_2);
1713    
1714                            boolean bindName = false;
1715    
1716                            if (name == null) {
1717                                    query.append(_FINDER_COLUMN_G_LIKEN_NAME_1);
1718                            }
1719                            else if (name.equals(StringPool.BLANK)) {
1720                                    query.append(_FINDER_COLUMN_G_LIKEN_NAME_3);
1721                            }
1722                            else {
1723                                    bindName = true;
1724    
1725                                    query.append(_FINDER_COLUMN_G_LIKEN_NAME_2);
1726                            }
1727    
1728                            if (orderByComparator != null) {
1729                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1730                                            orderByComparator);
1731                            }
1732                            else
1733                             if (pagination) {
1734                                    query.append(AssetTagModelImpl.ORDER_BY_JPQL);
1735                            }
1736    
1737                            String sql = query.toString();
1738    
1739                            Session session = null;
1740    
1741                            try {
1742                                    session = openSession();
1743    
1744                                    Query q = session.createQuery(sql);
1745    
1746                                    QueryPos qPos = QueryPos.getInstance(q);
1747    
1748                                    qPos.add(groupId);
1749    
1750                                    if (bindName) {
1751                                            qPos.add(name);
1752                                    }
1753    
1754                                    if (!pagination) {
1755                                            list = (List<AssetTag>)QueryUtil.list(q, getDialect(),
1756                                                            start, end, false);
1757    
1758                                            Collections.sort(list);
1759    
1760                                            list = Collections.unmodifiableList(list);
1761                                    }
1762                                    else {
1763                                            list = (List<AssetTag>)QueryUtil.list(q, getDialect(),
1764                                                            start, end);
1765                                    }
1766    
1767                                    cacheResult(list);
1768    
1769                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1770                            }
1771                            catch (Exception e) {
1772                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1773    
1774                                    throw processException(e);
1775                            }
1776                            finally {
1777                                    closeSession(session);
1778                            }
1779                    }
1780    
1781                    return list;
1782            }
1783    
1784            /**
1785             * Returns the first asset tag in the ordered set where groupId = &#63; and name LIKE &#63;.
1786             *
1787             * @param groupId the group ID
1788             * @param name the name
1789             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1790             * @return the first matching asset tag
1791             * @throws NoSuchTagException if a matching asset tag could not be found
1792             */
1793            @Override
1794            public AssetTag findByG_LikeN_First(long groupId, String name,
1795                    OrderByComparator<AssetTag> orderByComparator)
1796                    throws NoSuchTagException {
1797                    AssetTag assetTag = fetchByG_LikeN_First(groupId, name,
1798                                    orderByComparator);
1799    
1800                    if (assetTag != null) {
1801                            return assetTag;
1802                    }
1803    
1804                    StringBundler msg = new StringBundler(6);
1805    
1806                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1807    
1808                    msg.append("groupId=");
1809                    msg.append(groupId);
1810    
1811                    msg.append(", name=");
1812                    msg.append(name);
1813    
1814                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1815    
1816                    throw new NoSuchTagException(msg.toString());
1817            }
1818    
1819            /**
1820             * Returns the first asset tag in the ordered set where groupId = &#63; and name LIKE &#63;.
1821             *
1822             * @param groupId the group ID
1823             * @param name the name
1824             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1825             * @return the first matching asset tag, or <code>null</code> if a matching asset tag could not be found
1826             */
1827            @Override
1828            public AssetTag fetchByG_LikeN_First(long groupId, String name,
1829                    OrderByComparator<AssetTag> orderByComparator) {
1830                    List<AssetTag> list = findByG_LikeN(groupId, name, 0, 1,
1831                                    orderByComparator);
1832    
1833                    if (!list.isEmpty()) {
1834                            return list.get(0);
1835                    }
1836    
1837                    return null;
1838            }
1839    
1840            /**
1841             * Returns the last asset tag in the ordered set where groupId = &#63; and name LIKE &#63;.
1842             *
1843             * @param groupId the group ID
1844             * @param name the name
1845             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1846             * @return the last matching asset tag
1847             * @throws NoSuchTagException if a matching asset tag could not be found
1848             */
1849            @Override
1850            public AssetTag findByG_LikeN_Last(long groupId, String name,
1851                    OrderByComparator<AssetTag> orderByComparator)
1852                    throws NoSuchTagException {
1853                    AssetTag assetTag = fetchByG_LikeN_Last(groupId, name, orderByComparator);
1854    
1855                    if (assetTag != null) {
1856                            return assetTag;
1857                    }
1858    
1859                    StringBundler msg = new StringBundler(6);
1860    
1861                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1862    
1863                    msg.append("groupId=");
1864                    msg.append(groupId);
1865    
1866                    msg.append(", name=");
1867                    msg.append(name);
1868    
1869                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1870    
1871                    throw new NoSuchTagException(msg.toString());
1872            }
1873    
1874            /**
1875             * Returns the last asset tag in the ordered set where groupId = &#63; and name LIKE &#63;.
1876             *
1877             * @param groupId the group ID
1878             * @param name the name
1879             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1880             * @return the last matching asset tag, or <code>null</code> if a matching asset tag could not be found
1881             */
1882            @Override
1883            public AssetTag fetchByG_LikeN_Last(long groupId, String name,
1884                    OrderByComparator<AssetTag> orderByComparator) {
1885                    int count = countByG_LikeN(groupId, name);
1886    
1887                    if (count == 0) {
1888                            return null;
1889                    }
1890    
1891                    List<AssetTag> list = findByG_LikeN(groupId, name, count - 1, count,
1892                                    orderByComparator);
1893    
1894                    if (!list.isEmpty()) {
1895                            return list.get(0);
1896                    }
1897    
1898                    return null;
1899            }
1900    
1901            /**
1902             * Returns the asset tags before and after the current asset tag in the ordered set where groupId = &#63; and name LIKE &#63;.
1903             *
1904             * @param tagId the primary key of the current asset tag
1905             * @param groupId the group ID
1906             * @param name the name
1907             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1908             * @return the previous, current, and next asset tag
1909             * @throws NoSuchTagException if a asset tag with the primary key could not be found
1910             */
1911            @Override
1912            public AssetTag[] findByG_LikeN_PrevAndNext(long tagId, long groupId,
1913                    String name, OrderByComparator<AssetTag> orderByComparator)
1914                    throws NoSuchTagException {
1915                    AssetTag assetTag = findByPrimaryKey(tagId);
1916    
1917                    Session session = null;
1918    
1919                    try {
1920                            session = openSession();
1921    
1922                            AssetTag[] array = new AssetTagImpl[3];
1923    
1924                            array[0] = getByG_LikeN_PrevAndNext(session, assetTag, groupId,
1925                                            name, orderByComparator, true);
1926    
1927                            array[1] = assetTag;
1928    
1929                            array[2] = getByG_LikeN_PrevAndNext(session, assetTag, groupId,
1930                                            name, orderByComparator, false);
1931    
1932                            return array;
1933                    }
1934                    catch (Exception e) {
1935                            throw processException(e);
1936                    }
1937                    finally {
1938                            closeSession(session);
1939                    }
1940            }
1941    
1942            protected AssetTag getByG_LikeN_PrevAndNext(Session session,
1943                    AssetTag assetTag, long groupId, String name,
1944                    OrderByComparator<AssetTag> orderByComparator, boolean previous) {
1945                    StringBundler query = null;
1946    
1947                    if (orderByComparator != null) {
1948                            query = new StringBundler(6 +
1949                                            (orderByComparator.getOrderByFields().length * 6));
1950                    }
1951                    else {
1952                            query = new StringBundler(3);
1953                    }
1954    
1955                    query.append(_SQL_SELECT_ASSETTAG_WHERE);
1956    
1957                    query.append(_FINDER_COLUMN_G_LIKEN_GROUPID_2);
1958    
1959                    boolean bindName = false;
1960    
1961                    if (name == null) {
1962                            query.append(_FINDER_COLUMN_G_LIKEN_NAME_1);
1963                    }
1964                    else if (name.equals(StringPool.BLANK)) {
1965                            query.append(_FINDER_COLUMN_G_LIKEN_NAME_3);
1966                    }
1967                    else {
1968                            bindName = true;
1969    
1970                            query.append(_FINDER_COLUMN_G_LIKEN_NAME_2);
1971                    }
1972    
1973                    if (orderByComparator != null) {
1974                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1975    
1976                            if (orderByConditionFields.length > 0) {
1977                                    query.append(WHERE_AND);
1978                            }
1979    
1980                            for (int i = 0; i < orderByConditionFields.length; i++) {
1981                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1982                                    query.append(orderByConditionFields[i]);
1983    
1984                                    if ((i + 1) < orderByConditionFields.length) {
1985                                            if (orderByComparator.isAscending() ^ previous) {
1986                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1987                                            }
1988                                            else {
1989                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1990                                            }
1991                                    }
1992                                    else {
1993                                            if (orderByComparator.isAscending() ^ previous) {
1994                                                    query.append(WHERE_GREATER_THAN);
1995                                            }
1996                                            else {
1997                                                    query.append(WHERE_LESSER_THAN);
1998                                            }
1999                                    }
2000                            }
2001    
2002                            query.append(ORDER_BY_CLAUSE);
2003    
2004                            String[] orderByFields = orderByComparator.getOrderByFields();
2005    
2006                            for (int i = 0; i < orderByFields.length; i++) {
2007                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2008                                    query.append(orderByFields[i]);
2009    
2010                                    if ((i + 1) < orderByFields.length) {
2011                                            if (orderByComparator.isAscending() ^ previous) {
2012                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2013                                            }
2014                                            else {
2015                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2016                                            }
2017                                    }
2018                                    else {
2019                                            if (orderByComparator.isAscending() ^ previous) {
2020                                                    query.append(ORDER_BY_ASC);
2021                                            }
2022                                            else {
2023                                                    query.append(ORDER_BY_DESC);
2024                                            }
2025                                    }
2026                            }
2027                    }
2028                    else {
2029                            query.append(AssetTagModelImpl.ORDER_BY_JPQL);
2030                    }
2031    
2032                    String sql = query.toString();
2033    
2034                    Query q = session.createQuery(sql);
2035    
2036                    q.setFirstResult(0);
2037                    q.setMaxResults(2);
2038    
2039                    QueryPos qPos = QueryPos.getInstance(q);
2040    
2041                    qPos.add(groupId);
2042    
2043                    if (bindName) {
2044                            qPos.add(name);
2045                    }
2046    
2047                    if (orderByComparator != null) {
2048                            Object[] values = orderByComparator.getOrderByConditionValues(assetTag);
2049    
2050                            for (Object value : values) {
2051                                    qPos.add(value);
2052                            }
2053                    }
2054    
2055                    List<AssetTag> list = q.list();
2056    
2057                    if (list.size() == 2) {
2058                            return list.get(1);
2059                    }
2060                    else {
2061                            return null;
2062                    }
2063            }
2064    
2065            /**
2066             * Returns all the asset tags that the user has permission to view where groupId = &#63; and name LIKE &#63;.
2067             *
2068             * @param groupId the group ID
2069             * @param name the name
2070             * @return the matching asset tags that the user has permission to view
2071             */
2072            @Override
2073            public List<AssetTag> filterFindByG_LikeN(long groupId, String name) {
2074                    return filterFindByG_LikeN(groupId, name, QueryUtil.ALL_POS,
2075                            QueryUtil.ALL_POS, null);
2076            }
2077    
2078            /**
2079             * Returns a range of all the asset tags that the user has permission to view where groupId = &#63; and name LIKE &#63;.
2080             *
2081             * <p>
2082             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetTagModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2083             * </p>
2084             *
2085             * @param groupId the group ID
2086             * @param name the name
2087             * @param start the lower bound of the range of asset tags
2088             * @param end the upper bound of the range of asset tags (not inclusive)
2089             * @return the range of matching asset tags that the user has permission to view
2090             */
2091            @Override
2092            public List<AssetTag> filterFindByG_LikeN(long groupId, String name,
2093                    int start, int end) {
2094                    return filterFindByG_LikeN(groupId, name, start, end, null);
2095            }
2096    
2097            /**
2098             * Returns an ordered range of all the asset tags that the user has permissions to view where groupId = &#63; and name LIKE &#63;.
2099             *
2100             * <p>
2101             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetTagModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2102             * </p>
2103             *
2104             * @param groupId the group ID
2105             * @param name the name
2106             * @param start the lower bound of the range of asset tags
2107             * @param end the upper bound of the range of asset tags (not inclusive)
2108             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2109             * @return the ordered range of matching asset tags that the user has permission to view
2110             */
2111            @Override
2112            public List<AssetTag> filterFindByG_LikeN(long groupId, String name,
2113                    int start, int end, OrderByComparator<AssetTag> orderByComparator) {
2114                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2115                            return findByG_LikeN(groupId, name, start, end, orderByComparator);
2116                    }
2117    
2118                    StringBundler query = null;
2119    
2120                    if (orderByComparator != null) {
2121                            query = new StringBundler(4 +
2122                                            (orderByComparator.getOrderByFields().length * 3));
2123                    }
2124                    else {
2125                            query = new StringBundler(4);
2126                    }
2127    
2128                    if (getDB().isSupportsInlineDistinct()) {
2129                            query.append(_FILTER_SQL_SELECT_ASSETTAG_WHERE);
2130                    }
2131                    else {
2132                            query.append(_FILTER_SQL_SELECT_ASSETTAG_NO_INLINE_DISTINCT_WHERE_1);
2133                    }
2134    
2135                    query.append(_FINDER_COLUMN_G_LIKEN_GROUPID_2);
2136    
2137                    boolean bindName = false;
2138    
2139                    if (name == null) {
2140                            query.append(_FINDER_COLUMN_G_LIKEN_NAME_1);
2141                    }
2142                    else if (name.equals(StringPool.BLANK)) {
2143                            query.append(_FINDER_COLUMN_G_LIKEN_NAME_3);
2144                    }
2145                    else {
2146                            bindName = true;
2147    
2148                            query.append(_FINDER_COLUMN_G_LIKEN_NAME_2);
2149                    }
2150    
2151                    if (!getDB().isSupportsInlineDistinct()) {
2152                            query.append(_FILTER_SQL_SELECT_ASSETTAG_NO_INLINE_DISTINCT_WHERE_2);
2153                    }
2154    
2155                    if (orderByComparator != null) {
2156                            if (getDB().isSupportsInlineDistinct()) {
2157                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2158                                            orderByComparator, true);
2159                            }
2160                            else {
2161                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
2162                                            orderByComparator, true);
2163                            }
2164                    }
2165                    else {
2166                            if (getDB().isSupportsInlineDistinct()) {
2167                                    query.append(AssetTagModelImpl.ORDER_BY_JPQL);
2168                            }
2169                            else {
2170                                    query.append(AssetTagModelImpl.ORDER_BY_SQL);
2171                            }
2172                    }
2173    
2174                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2175                                    AssetTag.class.getName(),
2176                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2177    
2178                    Session session = null;
2179    
2180                    try {
2181                            session = openSession();
2182    
2183                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
2184    
2185                            if (getDB().isSupportsInlineDistinct()) {
2186                                    q.addEntity(_FILTER_ENTITY_ALIAS, AssetTagImpl.class);
2187                            }
2188                            else {
2189                                    q.addEntity(_FILTER_ENTITY_TABLE, AssetTagImpl.class);
2190                            }
2191    
2192                            QueryPos qPos = QueryPos.getInstance(q);
2193    
2194                            qPos.add(groupId);
2195    
2196                            if (bindName) {
2197                                    qPos.add(name);
2198                            }
2199    
2200                            return (List<AssetTag>)QueryUtil.list(q, getDialect(), start, end);
2201                    }
2202                    catch (Exception e) {
2203                            throw processException(e);
2204                    }
2205                    finally {
2206                            closeSession(session);
2207                    }
2208            }
2209    
2210            /**
2211             * 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; and name LIKE &#63;.
2212             *
2213             * @param tagId the primary key of the current asset tag
2214             * @param groupId the group ID
2215             * @param name the name
2216             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2217             * @return the previous, current, and next asset tag
2218             * @throws NoSuchTagException if a asset tag with the primary key could not be found
2219             */
2220            @Override
2221            public AssetTag[] filterFindByG_LikeN_PrevAndNext(long tagId, long groupId,
2222                    String name, OrderByComparator<AssetTag> orderByComparator)
2223                    throws NoSuchTagException {
2224                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2225                            return findByG_LikeN_PrevAndNext(tagId, groupId, name,
2226                                    orderByComparator);
2227                    }
2228    
2229                    AssetTag assetTag = findByPrimaryKey(tagId);
2230    
2231                    Session session = null;
2232    
2233                    try {
2234                            session = openSession();
2235    
2236                            AssetTag[] array = new AssetTagImpl[3];
2237    
2238                            array[0] = filterGetByG_LikeN_PrevAndNext(session, assetTag,
2239                                            groupId, name, orderByComparator, true);
2240    
2241                            array[1] = assetTag;
2242    
2243                            array[2] = filterGetByG_LikeN_PrevAndNext(session, assetTag,
2244                                            groupId, name, orderByComparator, false);
2245    
2246                            return array;
2247                    }
2248                    catch (Exception e) {
2249                            throw processException(e);
2250                    }
2251                    finally {
2252                            closeSession(session);
2253                    }
2254            }
2255    
2256            protected AssetTag filterGetByG_LikeN_PrevAndNext(Session session,
2257                    AssetTag assetTag, long groupId, String name,
2258                    OrderByComparator<AssetTag> orderByComparator, boolean previous) {
2259                    StringBundler query = null;
2260    
2261                    if (orderByComparator != null) {
2262                            query = new StringBundler(6 +
2263                                            (orderByComparator.getOrderByFields().length * 6));
2264                    }
2265                    else {
2266                            query = new StringBundler(3);
2267                    }
2268    
2269                    if (getDB().isSupportsInlineDistinct()) {
2270                            query.append(_FILTER_SQL_SELECT_ASSETTAG_WHERE);
2271                    }
2272                    else {
2273                            query.append(_FILTER_SQL_SELECT_ASSETTAG_NO_INLINE_DISTINCT_WHERE_1);
2274                    }
2275    
2276                    query.append(_FINDER_COLUMN_G_LIKEN_GROUPID_2);
2277    
2278                    boolean bindName = false;
2279    
2280                    if (name == null) {
2281                            query.append(_FINDER_COLUMN_G_LIKEN_NAME_1);
2282                    }
2283                    else if (name.equals(StringPool.BLANK)) {
2284                            query.append(_FINDER_COLUMN_G_LIKEN_NAME_3);
2285                    }
2286                    else {
2287                            bindName = true;
2288    
2289                            query.append(_FINDER_COLUMN_G_LIKEN_NAME_2);
2290                    }
2291    
2292                    if (!getDB().isSupportsInlineDistinct()) {
2293                            query.append(_FILTER_SQL_SELECT_ASSETTAG_NO_INLINE_DISTINCT_WHERE_2);
2294                    }
2295    
2296                    if (orderByComparator != null) {
2297                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2298    
2299                            if (orderByConditionFields.length > 0) {
2300                                    query.append(WHERE_AND);
2301                            }
2302    
2303                            for (int i = 0; i < orderByConditionFields.length; i++) {
2304                                    if (getDB().isSupportsInlineDistinct()) {
2305                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2306                                    }
2307                                    else {
2308                                            query.append(_ORDER_BY_ENTITY_TABLE);
2309                                    }
2310    
2311                                    query.append(orderByConditionFields[i]);
2312    
2313                                    if ((i + 1) < orderByConditionFields.length) {
2314                                            if (orderByComparator.isAscending() ^ previous) {
2315                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2316                                            }
2317                                            else {
2318                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2319                                            }
2320                                    }
2321                                    else {
2322                                            if (orderByComparator.isAscending() ^ previous) {
2323                                                    query.append(WHERE_GREATER_THAN);
2324                                            }
2325                                            else {
2326                                                    query.append(WHERE_LESSER_THAN);
2327                                            }
2328                                    }
2329                            }
2330    
2331                            query.append(ORDER_BY_CLAUSE);
2332    
2333                            String[] orderByFields = orderByComparator.getOrderByFields();
2334    
2335                            for (int i = 0; i < orderByFields.length; i++) {
2336                                    if (getDB().isSupportsInlineDistinct()) {
2337                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2338                                    }
2339                                    else {
2340                                            query.append(_ORDER_BY_ENTITY_TABLE);
2341                                    }
2342    
2343                                    query.append(orderByFields[i]);
2344    
2345                                    if ((i + 1) < orderByFields.length) {
2346                                            if (orderByComparator.isAscending() ^ previous) {
2347                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2348                                            }
2349                                            else {
2350                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2351                                            }
2352                                    }
2353                                    else {
2354                                            if (orderByComparator.isAscending() ^ previous) {
2355                                                    query.append(ORDER_BY_ASC);
2356                                            }
2357                                            else {
2358                                                    query.append(ORDER_BY_DESC);
2359                                            }
2360                                    }
2361                            }
2362                    }
2363                    else {
2364                            if (getDB().isSupportsInlineDistinct()) {
2365                                    query.append(AssetTagModelImpl.ORDER_BY_JPQL);
2366                            }
2367                            else {
2368                                    query.append(AssetTagModelImpl.ORDER_BY_SQL);
2369                            }
2370                    }
2371    
2372                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2373                                    AssetTag.class.getName(),
2374                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2375    
2376                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
2377    
2378                    q.setFirstResult(0);
2379                    q.setMaxResults(2);
2380    
2381                    if (getDB().isSupportsInlineDistinct()) {
2382                            q.addEntity(_FILTER_ENTITY_ALIAS, AssetTagImpl.class);
2383                    }
2384                    else {
2385                            q.addEntity(_FILTER_ENTITY_TABLE, AssetTagImpl.class);
2386                    }
2387    
2388                    QueryPos qPos = QueryPos.getInstance(q);
2389    
2390                    qPos.add(groupId);
2391    
2392                    if (bindName) {
2393                            qPos.add(name);
2394                    }
2395    
2396                    if (orderByComparator != null) {
2397                            Object[] values = orderByComparator.getOrderByConditionValues(assetTag);
2398    
2399                            for (Object value : values) {
2400                                    qPos.add(value);
2401                            }
2402                    }
2403    
2404                    List<AssetTag> list = q.list();
2405    
2406                    if (list.size() == 2) {
2407                            return list.get(1);
2408                    }
2409                    else {
2410                            return null;
2411                    }
2412            }
2413    
2414            /**
2415             * Returns all the asset tags that the user has permission to view where groupId = any &#63; and name LIKE &#63;.
2416             *
2417             * @param groupIds the group IDs
2418             * @param name the name
2419             * @return the matching asset tags that the user has permission to view
2420             */
2421            @Override
2422            public List<AssetTag> filterFindByG_LikeN(long[] groupIds, String name) {
2423                    return filterFindByG_LikeN(groupIds, name, QueryUtil.ALL_POS,
2424                            QueryUtil.ALL_POS, null);
2425            }
2426    
2427            /**
2428             * Returns a range of all the asset tags that the user has permission to view where groupId = any &#63; and name LIKE &#63;.
2429             *
2430             * <p>
2431             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetTagModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2432             * </p>
2433             *
2434             * @param groupIds the group IDs
2435             * @param name the name
2436             * @param start the lower bound of the range of asset tags
2437             * @param end the upper bound of the range of asset tags (not inclusive)
2438             * @return the range of matching asset tags that the user has permission to view
2439             */
2440            @Override
2441            public List<AssetTag> filterFindByG_LikeN(long[] groupIds, String name,
2442                    int start, int end) {
2443                    return filterFindByG_LikeN(groupIds, name, start, end, null);
2444            }
2445    
2446            /**
2447             * Returns an ordered range of all the asset tags that the user has permission to view where groupId = any &#63; and name LIKE &#63;.
2448             *
2449             * <p>
2450             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetTagModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2451             * </p>
2452             *
2453             * @param groupIds the group IDs
2454             * @param name the name
2455             * @param start the lower bound of the range of asset tags
2456             * @param end the upper bound of the range of asset tags (not inclusive)
2457             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2458             * @return the ordered range of matching asset tags that the user has permission to view
2459             */
2460            @Override
2461            public List<AssetTag> filterFindByG_LikeN(long[] groupIds, String name,
2462                    int start, int end, OrderByComparator<AssetTag> orderByComparator) {
2463                    if (!InlineSQLHelperUtil.isEnabled(groupIds)) {
2464                            return findByG_LikeN(groupIds, name, start, end, orderByComparator);
2465                    }
2466    
2467                    if (groupIds == null) {
2468                            groupIds = new long[0];
2469                    }
2470                    else {
2471                            groupIds = ArrayUtil.unique(groupIds);
2472                    }
2473    
2474                    StringBundler query = new StringBundler();
2475    
2476                    if (getDB().isSupportsInlineDistinct()) {
2477                            query.append(_FILTER_SQL_SELECT_ASSETTAG_WHERE);
2478                    }
2479                    else {
2480                            query.append(_FILTER_SQL_SELECT_ASSETTAG_NO_INLINE_DISTINCT_WHERE_1);
2481                    }
2482    
2483                    if (groupIds.length > 0) {
2484                            query.append(StringPool.OPEN_PARENTHESIS);
2485    
2486                            query.append(_FINDER_COLUMN_G_LIKEN_GROUPID_7);
2487    
2488                            query.append(StringUtil.merge(groupIds));
2489    
2490                            query.append(StringPool.CLOSE_PARENTHESIS);
2491    
2492                            query.append(StringPool.CLOSE_PARENTHESIS);
2493    
2494                            query.append(WHERE_AND);
2495                    }
2496    
2497                    boolean bindName = false;
2498    
2499                    if (name == null) {
2500                            query.append(_FINDER_COLUMN_G_LIKEN_NAME_1);
2501                    }
2502                    else if (name.equals(StringPool.BLANK)) {
2503                            query.append(_FINDER_COLUMN_G_LIKEN_NAME_3);
2504                    }
2505                    else {
2506                            bindName = true;
2507    
2508                            query.append(_FINDER_COLUMN_G_LIKEN_NAME_2);
2509                    }
2510    
2511                    query.setStringAt(removeConjunction(query.stringAt(query.index() - 1)),
2512                            query.index() - 1);
2513    
2514                    if (!getDB().isSupportsInlineDistinct()) {
2515                            query.append(_FILTER_SQL_SELECT_ASSETTAG_NO_INLINE_DISTINCT_WHERE_2);
2516                    }
2517    
2518                    if (orderByComparator != null) {
2519                            if (getDB().isSupportsInlineDistinct()) {
2520                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2521                                            orderByComparator, true);
2522                            }
2523                            else {
2524                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
2525                                            orderByComparator, true);
2526                            }
2527                    }
2528                    else {
2529                            if (getDB().isSupportsInlineDistinct()) {
2530                                    query.append(AssetTagModelImpl.ORDER_BY_JPQL);
2531                            }
2532                            else {
2533                                    query.append(AssetTagModelImpl.ORDER_BY_SQL);
2534                            }
2535                    }
2536    
2537                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2538                                    AssetTag.class.getName(),
2539                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupIds);
2540    
2541                    Session session = null;
2542    
2543                    try {
2544                            session = openSession();
2545    
2546                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
2547    
2548                            if (getDB().isSupportsInlineDistinct()) {
2549                                    q.addEntity(_FILTER_ENTITY_ALIAS, AssetTagImpl.class);
2550                            }
2551                            else {
2552                                    q.addEntity(_FILTER_ENTITY_TABLE, AssetTagImpl.class);
2553                            }
2554    
2555                            QueryPos qPos = QueryPos.getInstance(q);
2556    
2557                            if (bindName) {
2558                                    qPos.add(name);
2559                            }
2560    
2561                            return (List<AssetTag>)QueryUtil.list(q, getDialect(), start, end);
2562                    }
2563                    catch (Exception e) {
2564                            throw processException(e);
2565                    }
2566                    finally {
2567                            closeSession(session);
2568                    }
2569            }
2570    
2571            /**
2572             * Returns all the asset tags where groupId = any &#63; and name LIKE &#63;.
2573             *
2574             * <p>
2575             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetTagModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2576             * </p>
2577             *
2578             * @param groupIds the group IDs
2579             * @param name the name
2580             * @return the matching asset tags
2581             */
2582            @Override
2583            public List<AssetTag> findByG_LikeN(long[] groupIds, String name) {
2584                    return findByG_LikeN(groupIds, name, QueryUtil.ALL_POS,
2585                            QueryUtil.ALL_POS, null);
2586            }
2587    
2588            /**
2589             * Returns a range of all the asset tags where groupId = any &#63; and name LIKE &#63;.
2590             *
2591             * <p>
2592             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetTagModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2593             * </p>
2594             *
2595             * @param groupIds the group IDs
2596             * @param name the name
2597             * @param start the lower bound of the range of asset tags
2598             * @param end the upper bound of the range of asset tags (not inclusive)
2599             * @return the range of matching asset tags
2600             */
2601            @Override
2602            public List<AssetTag> findByG_LikeN(long[] groupIds, String name,
2603                    int start, int end) {
2604                    return findByG_LikeN(groupIds, name, start, end, null);
2605            }
2606    
2607            /**
2608             * Returns an ordered range of all the asset tags where groupId = any &#63; and name LIKE &#63;.
2609             *
2610             * <p>
2611             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetTagModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2612             * </p>
2613             *
2614             * @param groupIds the group IDs
2615             * @param name the name
2616             * @param start the lower bound of the range of asset tags
2617             * @param end the upper bound of the range of asset tags (not inclusive)
2618             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2619             * @return the ordered range of matching asset tags
2620             */
2621            @Override
2622            public List<AssetTag> findByG_LikeN(long[] groupIds, String name,
2623                    int start, int end, OrderByComparator<AssetTag> orderByComparator) {
2624                    if (groupIds == null) {
2625                            groupIds = new long[0];
2626                    }
2627                    else {
2628                            groupIds = ArrayUtil.unique(groupIds);
2629                    }
2630    
2631                    if (groupIds.length == 1) {
2632                            return findByG_LikeN(groupIds[0], name, start, end,
2633                                    orderByComparator);
2634                    }
2635    
2636                    boolean pagination = true;
2637                    Object[] finderArgs = null;
2638    
2639                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2640                                    (orderByComparator == null)) {
2641                            pagination = false;
2642                            finderArgs = new Object[] { StringUtil.merge(groupIds), name };
2643                    }
2644                    else {
2645                            finderArgs = new Object[] {
2646                                            StringUtil.merge(groupIds), name,
2647                                            
2648                                            start, end, orderByComparator
2649                                    };
2650                    }
2651    
2652                    List<AssetTag> list = (List<AssetTag>)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_LIKEN,
2653                                    finderArgs, this);
2654    
2655                    if ((list != null) && !list.isEmpty()) {
2656                            for (AssetTag assetTag : list) {
2657                                    if (!ArrayUtil.contains(groupIds, assetTag.getGroupId()) ||
2658                                                    !Validator.equals(name, assetTag.getName())) {
2659                                            list = null;
2660    
2661                                            break;
2662                                    }
2663                            }
2664                    }
2665    
2666                    if (list == null) {
2667                            StringBundler query = new StringBundler();
2668    
2669                            query.append(_SQL_SELECT_ASSETTAG_WHERE);
2670    
2671                            if (groupIds.length > 0) {
2672                                    query.append(StringPool.OPEN_PARENTHESIS);
2673    
2674                                    query.append(_FINDER_COLUMN_G_LIKEN_GROUPID_7);
2675    
2676                                    query.append(StringUtil.merge(groupIds));
2677    
2678                                    query.append(StringPool.CLOSE_PARENTHESIS);
2679    
2680                                    query.append(StringPool.CLOSE_PARENTHESIS);
2681    
2682                                    query.append(WHERE_AND);
2683                            }
2684    
2685                            boolean bindName = false;
2686    
2687                            if (name == null) {
2688                                    query.append(_FINDER_COLUMN_G_LIKEN_NAME_1);
2689                            }
2690                            else if (name.equals(StringPool.BLANK)) {
2691                                    query.append(_FINDER_COLUMN_G_LIKEN_NAME_3);
2692                            }
2693                            else {
2694                                    bindName = true;
2695    
2696                                    query.append(_FINDER_COLUMN_G_LIKEN_NAME_2);
2697                            }
2698    
2699                            query.setStringAt(removeConjunction(query.stringAt(query.index() -
2700                                                    1)), query.index() - 1);
2701    
2702                            if (orderByComparator != null) {
2703                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2704                                            orderByComparator);
2705                            }
2706                            else
2707                             if (pagination) {
2708                                    query.append(AssetTagModelImpl.ORDER_BY_JPQL);
2709                            }
2710    
2711                            String sql = query.toString();
2712    
2713                            Session session = null;
2714    
2715                            try {
2716                                    session = openSession();
2717    
2718                                    Query q = session.createQuery(sql);
2719    
2720                                    QueryPos qPos = QueryPos.getInstance(q);
2721    
2722                                    if (bindName) {
2723                                            qPos.add(name);
2724                                    }
2725    
2726                                    if (!pagination) {
2727                                            list = (List<AssetTag>)QueryUtil.list(q, getDialect(),
2728                                                            start, end, false);
2729    
2730                                            Collections.sort(list);
2731    
2732                                            list = Collections.unmodifiableList(list);
2733                                    }
2734                                    else {
2735                                            list = (List<AssetTag>)QueryUtil.list(q, getDialect(),
2736                                                            start, end);
2737                                    }
2738    
2739                                    cacheResult(list);
2740    
2741                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_LIKEN,
2742                                            finderArgs, list);
2743                            }
2744                            catch (Exception e) {
2745                                    FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_LIKEN,
2746                                            finderArgs);
2747    
2748                                    throw processException(e);
2749                            }
2750                            finally {
2751                                    closeSession(session);
2752                            }
2753                    }
2754    
2755                    return list;
2756            }
2757    
2758            /**
2759             * Removes all the asset tags where groupId = &#63; and name LIKE &#63; from the database.
2760             *
2761             * @param groupId the group ID
2762             * @param name the name
2763             */
2764            @Override
2765            public void removeByG_LikeN(long groupId, String name) {
2766                    for (AssetTag assetTag : findByG_LikeN(groupId, name,
2767                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2768                            remove(assetTag);
2769                    }
2770            }
2771    
2772            /**
2773             * Returns the number of asset tags where groupId = &#63; and name LIKE &#63;.
2774             *
2775             * @param groupId the group ID
2776             * @param name the name
2777             * @return the number of matching asset tags
2778             */
2779            @Override
2780            public int countByG_LikeN(long groupId, String name) {
2781                    FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_LIKEN;
2782    
2783                    Object[] finderArgs = new Object[] { groupId, name };
2784    
2785                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2786                                    this);
2787    
2788                    if (count == null) {
2789                            StringBundler query = new StringBundler(3);
2790    
2791                            query.append(_SQL_COUNT_ASSETTAG_WHERE);
2792    
2793                            query.append(_FINDER_COLUMN_G_LIKEN_GROUPID_2);
2794    
2795                            boolean bindName = false;
2796    
2797                            if (name == null) {
2798                                    query.append(_FINDER_COLUMN_G_LIKEN_NAME_1);
2799                            }
2800                            else if (name.equals(StringPool.BLANK)) {
2801                                    query.append(_FINDER_COLUMN_G_LIKEN_NAME_3);
2802                            }
2803                            else {
2804                                    bindName = true;
2805    
2806                                    query.append(_FINDER_COLUMN_G_LIKEN_NAME_2);
2807                            }
2808    
2809                            String sql = query.toString();
2810    
2811                            Session session = null;
2812    
2813                            try {
2814                                    session = openSession();
2815    
2816                                    Query q = session.createQuery(sql);
2817    
2818                                    QueryPos qPos = QueryPos.getInstance(q);
2819    
2820                                    qPos.add(groupId);
2821    
2822                                    if (bindName) {
2823                                            qPos.add(name);
2824                                    }
2825    
2826                                    count = (Long)q.uniqueResult();
2827    
2828                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
2829                            }
2830                            catch (Exception e) {
2831                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2832    
2833                                    throw processException(e);
2834                            }
2835                            finally {
2836                                    closeSession(session);
2837                            }
2838                    }
2839    
2840                    return count.intValue();
2841            }
2842    
2843            /**
2844             * Returns the number of asset tags where groupId = any &#63; and name LIKE &#63;.
2845             *
2846             * @param groupIds the group IDs
2847             * @param name the name
2848             * @return the number of matching asset tags
2849             */
2850            @Override
2851            public int countByG_LikeN(long[] groupIds, String name) {
2852                    if (groupIds == null) {
2853                            groupIds = new long[0];
2854                    }
2855                    else {
2856                            groupIds = ArrayUtil.unique(groupIds);
2857                    }
2858    
2859                    Object[] finderArgs = new Object[] { StringUtil.merge(groupIds), name };
2860    
2861                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_LIKEN,
2862                                    finderArgs, this);
2863    
2864                    if (count == null) {
2865                            StringBundler query = new StringBundler();
2866    
2867                            query.append(_SQL_COUNT_ASSETTAG_WHERE);
2868    
2869                            if (groupIds.length > 0) {
2870                                    query.append(StringPool.OPEN_PARENTHESIS);
2871    
2872                                    query.append(_FINDER_COLUMN_G_LIKEN_GROUPID_7);
2873    
2874                                    query.append(StringUtil.merge(groupIds));
2875    
2876                                    query.append(StringPool.CLOSE_PARENTHESIS);
2877    
2878                                    query.append(StringPool.CLOSE_PARENTHESIS);
2879    
2880                                    query.append(WHERE_AND);
2881                            }
2882    
2883                            boolean bindName = false;
2884    
2885                            if (name == null) {
2886                                    query.append(_FINDER_COLUMN_G_LIKEN_NAME_1);
2887                            }
2888                            else if (name.equals(StringPool.BLANK)) {
2889                                    query.append(_FINDER_COLUMN_G_LIKEN_NAME_3);
2890                            }
2891                            else {
2892                                    bindName = true;
2893    
2894                                    query.append(_FINDER_COLUMN_G_LIKEN_NAME_2);
2895                            }
2896    
2897                            query.setStringAt(removeConjunction(query.stringAt(query.index() -
2898                                                    1)), query.index() - 1);
2899    
2900                            String sql = query.toString();
2901    
2902                            Session session = null;
2903    
2904                            try {
2905                                    session = openSession();
2906    
2907                                    Query q = session.createQuery(sql);
2908    
2909                                    QueryPos qPos = QueryPos.getInstance(q);
2910    
2911                                    if (bindName) {
2912                                            qPos.add(name);
2913                                    }
2914    
2915                                    count = (Long)q.uniqueResult();
2916    
2917                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_LIKEN,
2918                                            finderArgs, count);
2919                            }
2920                            catch (Exception e) {
2921                                    FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_LIKEN,
2922                                            finderArgs);
2923    
2924                                    throw processException(e);
2925                            }
2926                            finally {
2927                                    closeSession(session);
2928                            }
2929                    }
2930    
2931                    return count.intValue();
2932            }
2933    
2934            /**
2935             * Returns the number of asset tags that the user has permission to view where groupId = &#63; and name LIKE &#63;.
2936             *
2937             * @param groupId the group ID
2938             * @param name the name
2939             * @return the number of matching asset tags that the user has permission to view
2940             */
2941            @Override
2942            public int filterCountByG_LikeN(long groupId, String name) {
2943                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2944                            return countByG_LikeN(groupId, name);
2945                    }
2946    
2947                    StringBundler query = new StringBundler(3);
2948    
2949                    query.append(_FILTER_SQL_COUNT_ASSETTAG_WHERE);
2950    
2951                    query.append(_FINDER_COLUMN_G_LIKEN_GROUPID_2);
2952    
2953                    boolean bindName = false;
2954    
2955                    if (name == null) {
2956                            query.append(_FINDER_COLUMN_G_LIKEN_NAME_1);
2957                    }
2958                    else if (name.equals(StringPool.BLANK)) {
2959                            query.append(_FINDER_COLUMN_G_LIKEN_NAME_3);
2960                    }
2961                    else {
2962                            bindName = true;
2963    
2964                            query.append(_FINDER_COLUMN_G_LIKEN_NAME_2);
2965                    }
2966    
2967                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2968                                    AssetTag.class.getName(),
2969                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2970    
2971                    Session session = null;
2972    
2973                    try {
2974                            session = openSession();
2975    
2976                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
2977    
2978                            q.addScalar(COUNT_COLUMN_NAME,
2979                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
2980    
2981                            QueryPos qPos = QueryPos.getInstance(q);
2982    
2983                            qPos.add(groupId);
2984    
2985                            if (bindName) {
2986                                    qPos.add(name);
2987                            }
2988    
2989                            Long count = (Long)q.uniqueResult();
2990    
2991                            return count.intValue();
2992                    }
2993                    catch (Exception e) {
2994                            throw processException(e);
2995                    }
2996                    finally {
2997                            closeSession(session);
2998                    }
2999            }
3000    
3001            /**
3002             * Returns the number of asset tags that the user has permission to view where groupId = any &#63; and name LIKE &#63;.
3003             *
3004             * @param groupIds the group IDs
3005             * @param name the name
3006             * @return the number of matching asset tags that the user has permission to view
3007             */
3008            @Override
3009            public int filterCountByG_LikeN(long[] groupIds, String name) {
3010                    if (!InlineSQLHelperUtil.isEnabled(groupIds)) {
3011                            return countByG_LikeN(groupIds, name);
3012                    }
3013    
3014                    if (groupIds == null) {
3015                            groupIds = new long[0];
3016                    }
3017                    else {
3018                            groupIds = ArrayUtil.unique(groupIds);
3019                    }
3020    
3021                    StringBundler query = new StringBundler();
3022    
3023                    query.append(_FILTER_SQL_COUNT_ASSETTAG_WHERE);
3024    
3025                    if (groupIds.length > 0) {
3026                            query.append(StringPool.OPEN_PARENTHESIS);
3027    
3028                            query.append(_FINDER_COLUMN_G_LIKEN_GROUPID_7);
3029    
3030                            query.append(StringUtil.merge(groupIds));
3031    
3032                            query.append(StringPool.CLOSE_PARENTHESIS);
3033    
3034                            query.append(StringPool.CLOSE_PARENTHESIS);
3035    
3036                            query.append(WHERE_AND);
3037                    }
3038    
3039                    boolean bindName = false;
3040    
3041                    if (name == null) {
3042                            query.append(_FINDER_COLUMN_G_LIKEN_NAME_1);
3043                    }
3044                    else if (name.equals(StringPool.BLANK)) {
3045                            query.append(_FINDER_COLUMN_G_LIKEN_NAME_3);
3046                    }
3047                    else {
3048                            bindName = true;
3049    
3050                            query.append(_FINDER_COLUMN_G_LIKEN_NAME_2);
3051                    }
3052    
3053                    query.setStringAt(removeConjunction(query.stringAt(query.index() - 1)),
3054                            query.index() - 1);
3055    
3056                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3057                                    AssetTag.class.getName(),
3058                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupIds);
3059    
3060                    Session session = null;
3061    
3062                    try {
3063                            session = openSession();
3064    
3065                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
3066    
3067                            q.addScalar(COUNT_COLUMN_NAME,
3068                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
3069    
3070                            QueryPos qPos = QueryPos.getInstance(q);
3071    
3072                            if (bindName) {
3073                                    qPos.add(name);
3074                            }
3075    
3076                            Long count = (Long)q.uniqueResult();
3077    
3078                            return count.intValue();
3079                    }
3080                    catch (Exception e) {
3081                            throw processException(e);
3082                    }
3083                    finally {
3084                            closeSession(session);
3085                    }
3086            }
3087    
3088            private static final String _FINDER_COLUMN_G_LIKEN_GROUPID_2 = "assetTag.groupId = ? AND ";
3089            private static final String _FINDER_COLUMN_G_LIKEN_GROUPID_7 = "assetTag.groupId IN (";
3090            private static final String _FINDER_COLUMN_G_LIKEN_NAME_1 = "assetTag.name LIKE NULL";
3091            private static final String _FINDER_COLUMN_G_LIKEN_NAME_2 = "assetTag.name LIKE ?";
3092            private static final String _FINDER_COLUMN_G_LIKEN_NAME_3 = "(assetTag.name IS NULL OR assetTag.name LIKE '')";
3093    
3094            public AssetTagPersistenceImpl() {
3095                    setModelClass(AssetTag.class);
3096            }
3097    
3098            /**
3099             * Caches the asset tag in the entity cache if it is enabled.
3100             *
3101             * @param assetTag the asset tag
3102             */
3103            @Override
3104            public void cacheResult(AssetTag assetTag) {
3105                    EntityCacheUtil.putResult(AssetTagModelImpl.ENTITY_CACHE_ENABLED,
3106                            AssetTagImpl.class, assetTag.getPrimaryKey(), assetTag);
3107    
3108                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N,
3109                            new Object[] { assetTag.getGroupId(), assetTag.getName() }, assetTag);
3110    
3111                    assetTag.resetOriginalValues();
3112            }
3113    
3114            /**
3115             * Caches the asset tags in the entity cache if it is enabled.
3116             *
3117             * @param assetTags the asset tags
3118             */
3119            @Override
3120            public void cacheResult(List<AssetTag> assetTags) {
3121                    for (AssetTag assetTag : assetTags) {
3122                            if (EntityCacheUtil.getResult(
3123                                                    AssetTagModelImpl.ENTITY_CACHE_ENABLED,
3124                                                    AssetTagImpl.class, assetTag.getPrimaryKey()) == null) {
3125                                    cacheResult(assetTag);
3126                            }
3127                            else {
3128                                    assetTag.resetOriginalValues();
3129                            }
3130                    }
3131            }
3132    
3133            /**
3134             * Clears the cache for all asset tags.
3135             *
3136             * <p>
3137             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
3138             * </p>
3139             */
3140            @Override
3141            public void clearCache() {
3142                    EntityCacheUtil.clearCache(AssetTagImpl.class);
3143    
3144                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
3145                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
3146                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
3147            }
3148    
3149            /**
3150             * Clears the cache for the asset tag.
3151             *
3152             * <p>
3153             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
3154             * </p>
3155             */
3156            @Override
3157            public void clearCache(AssetTag assetTag) {
3158                    EntityCacheUtil.removeResult(AssetTagModelImpl.ENTITY_CACHE_ENABLED,
3159                            AssetTagImpl.class, assetTag.getPrimaryKey());
3160    
3161                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
3162                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
3163    
3164                    clearUniqueFindersCache(assetTag);
3165            }
3166    
3167            @Override
3168            public void clearCache(List<AssetTag> assetTags) {
3169                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
3170                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
3171    
3172                    for (AssetTag assetTag : assetTags) {
3173                            EntityCacheUtil.removeResult(AssetTagModelImpl.ENTITY_CACHE_ENABLED,
3174                                    AssetTagImpl.class, assetTag.getPrimaryKey());
3175    
3176                            clearUniqueFindersCache(assetTag);
3177                    }
3178            }
3179    
3180            protected void cacheUniqueFindersCache(AssetTag assetTag) {
3181                    if (assetTag.isNew()) {
3182                            Object[] args = new Object[] {
3183                                            assetTag.getGroupId(), assetTag.getName()
3184                                    };
3185    
3186                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_N, args,
3187                                    Long.valueOf(1));
3188                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N, args, assetTag);
3189                    }
3190                    else {
3191                            AssetTagModelImpl assetTagModelImpl = (AssetTagModelImpl)assetTag;
3192    
3193                            if ((assetTagModelImpl.getColumnBitmask() &
3194                                            FINDER_PATH_FETCH_BY_G_N.getColumnBitmask()) != 0) {
3195                                    Object[] args = new Object[] {
3196                                                    assetTag.getGroupId(), assetTag.getName()
3197                                            };
3198    
3199                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_N, args,
3200                                            Long.valueOf(1));
3201                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N, args,
3202                                            assetTag);
3203                            }
3204                    }
3205            }
3206    
3207            protected void clearUniqueFindersCache(AssetTag assetTag) {
3208                    AssetTagModelImpl assetTagModelImpl = (AssetTagModelImpl)assetTag;
3209    
3210                    Object[] args = new Object[] { assetTag.getGroupId(), assetTag.getName() };
3211    
3212                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N, args);
3213                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_N, args);
3214    
3215                    if ((assetTagModelImpl.getColumnBitmask() &
3216                                    FINDER_PATH_FETCH_BY_G_N.getColumnBitmask()) != 0) {
3217                            args = new Object[] {
3218                                            assetTagModelImpl.getOriginalGroupId(),
3219                                            assetTagModelImpl.getOriginalName()
3220                                    };
3221    
3222                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N, args);
3223                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_N, args);
3224                    }
3225            }
3226    
3227            /**
3228             * Creates a new asset tag with the primary key. Does not add the asset tag to the database.
3229             *
3230             * @param tagId the primary key for the new asset tag
3231             * @return the new asset tag
3232             */
3233            @Override
3234            public AssetTag create(long tagId) {
3235                    AssetTag assetTag = new AssetTagImpl();
3236    
3237                    assetTag.setNew(true);
3238                    assetTag.setPrimaryKey(tagId);
3239    
3240                    return assetTag;
3241            }
3242    
3243            /**
3244             * Removes the asset tag with the primary key from the database. Also notifies the appropriate model listeners.
3245             *
3246             * @param tagId the primary key of the asset tag
3247             * @return the asset tag that was removed
3248             * @throws NoSuchTagException if a asset tag with the primary key could not be found
3249             */
3250            @Override
3251            public AssetTag remove(long tagId) throws NoSuchTagException {
3252                    return remove((Serializable)tagId);
3253            }
3254    
3255            /**
3256             * Removes the asset tag with the primary key from the database. Also notifies the appropriate model listeners.
3257             *
3258             * @param primaryKey the primary key of the asset tag
3259             * @return the asset tag that was removed
3260             * @throws NoSuchTagException if a asset tag with the primary key could not be found
3261             */
3262            @Override
3263            public AssetTag remove(Serializable primaryKey) throws NoSuchTagException {
3264                    Session session = null;
3265    
3266                    try {
3267                            session = openSession();
3268    
3269                            AssetTag assetTag = (AssetTag)session.get(AssetTagImpl.class,
3270                                            primaryKey);
3271    
3272                            if (assetTag == null) {
3273                                    if (_log.isWarnEnabled()) {
3274                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
3275                                    }
3276    
3277                                    throw new NoSuchTagException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
3278                                            primaryKey);
3279                            }
3280    
3281                            return remove(assetTag);
3282                    }
3283                    catch (NoSuchTagException nsee) {
3284                            throw nsee;
3285                    }
3286                    catch (Exception e) {
3287                            throw processException(e);
3288                    }
3289                    finally {
3290                            closeSession(session);
3291                    }
3292            }
3293    
3294            @Override
3295            protected AssetTag removeImpl(AssetTag assetTag) {
3296                    assetTag = toUnwrappedModel(assetTag);
3297    
3298                    assetTagToAssetEntryTableMapper.deleteLeftPrimaryKeyTableMappings(assetTag.getPrimaryKey());
3299    
3300                    Session session = null;
3301    
3302                    try {
3303                            session = openSession();
3304    
3305                            if (!session.contains(assetTag)) {
3306                                    assetTag = (AssetTag)session.get(AssetTagImpl.class,
3307                                                    assetTag.getPrimaryKeyObj());
3308                            }
3309    
3310                            if (assetTag != null) {
3311                                    session.delete(assetTag);
3312                            }
3313                    }
3314                    catch (Exception e) {
3315                            throw processException(e);
3316                    }
3317                    finally {
3318                            closeSession(session);
3319                    }
3320    
3321                    if (assetTag != null) {
3322                            clearCache(assetTag);
3323                    }
3324    
3325                    return assetTag;
3326            }
3327    
3328            @Override
3329            public AssetTag updateImpl(AssetTag assetTag) {
3330                    assetTag = toUnwrappedModel(assetTag);
3331    
3332                    boolean isNew = assetTag.isNew();
3333    
3334                    AssetTagModelImpl assetTagModelImpl = (AssetTagModelImpl)assetTag;
3335    
3336                    ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext();
3337    
3338                    Date now = new Date();
3339    
3340                    if (isNew && (assetTag.getCreateDate() == null)) {
3341                            if (serviceContext == null) {
3342                                    assetTag.setCreateDate(now);
3343                            }
3344                            else {
3345                                    assetTag.setCreateDate(serviceContext.getCreateDate(now));
3346                            }
3347                    }
3348    
3349                    if (!assetTagModelImpl.hasSetModifiedDate()) {
3350                            if (serviceContext == null) {
3351                                    assetTag.setModifiedDate(now);
3352                            }
3353                            else {
3354                                    assetTag.setModifiedDate(serviceContext.getModifiedDate(now));
3355                            }
3356                    }
3357    
3358                    Session session = null;
3359    
3360                    try {
3361                            session = openSession();
3362    
3363                            if (assetTag.isNew()) {
3364                                    session.save(assetTag);
3365    
3366                                    assetTag.setNew(false);
3367                            }
3368                            else {
3369                                    session.merge(assetTag);
3370                            }
3371                    }
3372                    catch (Exception e) {
3373                            throw processException(e);
3374                    }
3375                    finally {
3376                            closeSession(session);
3377                    }
3378    
3379                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
3380    
3381                    if (isNew || !AssetTagModelImpl.COLUMN_BITMASK_ENABLED) {
3382                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
3383                    }
3384    
3385                    else {
3386                            if ((assetTagModelImpl.getColumnBitmask() &
3387                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
3388                                    Object[] args = new Object[] {
3389                                                    assetTagModelImpl.getOriginalGroupId()
3390                                            };
3391    
3392                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
3393                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
3394                                            args);
3395    
3396                                    args = new Object[] { assetTagModelImpl.getGroupId() };
3397    
3398                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
3399                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
3400                                            args);
3401                            }
3402                    }
3403    
3404                    EntityCacheUtil.putResult(AssetTagModelImpl.ENTITY_CACHE_ENABLED,
3405                            AssetTagImpl.class, assetTag.getPrimaryKey(), assetTag, false);
3406    
3407                    clearUniqueFindersCache(assetTag);
3408                    cacheUniqueFindersCache(assetTag);
3409    
3410                    assetTag.resetOriginalValues();
3411    
3412                    return assetTag;
3413            }
3414    
3415            protected AssetTag toUnwrappedModel(AssetTag assetTag) {
3416                    if (assetTag instanceof AssetTagImpl) {
3417                            return assetTag;
3418                    }
3419    
3420                    AssetTagImpl assetTagImpl = new AssetTagImpl();
3421    
3422                    assetTagImpl.setNew(assetTag.isNew());
3423                    assetTagImpl.setPrimaryKey(assetTag.getPrimaryKey());
3424    
3425                    assetTagImpl.setTagId(assetTag.getTagId());
3426                    assetTagImpl.setGroupId(assetTag.getGroupId());
3427                    assetTagImpl.setCompanyId(assetTag.getCompanyId());
3428                    assetTagImpl.setUserId(assetTag.getUserId());
3429                    assetTagImpl.setUserName(assetTag.getUserName());
3430                    assetTagImpl.setCreateDate(assetTag.getCreateDate());
3431                    assetTagImpl.setModifiedDate(assetTag.getModifiedDate());
3432                    assetTagImpl.setName(assetTag.getName());
3433                    assetTagImpl.setAssetCount(assetTag.getAssetCount());
3434    
3435                    return assetTagImpl;
3436            }
3437    
3438            /**
3439             * Returns the asset tag with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
3440             *
3441             * @param primaryKey the primary key of the asset tag
3442             * @return the asset tag
3443             * @throws NoSuchTagException if a asset tag with the primary key could not be found
3444             */
3445            @Override
3446            public AssetTag findByPrimaryKey(Serializable primaryKey)
3447                    throws NoSuchTagException {
3448                    AssetTag assetTag = fetchByPrimaryKey(primaryKey);
3449    
3450                    if (assetTag == null) {
3451                            if (_log.isWarnEnabled()) {
3452                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
3453                            }
3454    
3455                            throw new NoSuchTagException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
3456                                    primaryKey);
3457                    }
3458    
3459                    return assetTag;
3460            }
3461    
3462            /**
3463             * Returns the asset tag with the primary key or throws a {@link NoSuchTagException} if it could not be found.
3464             *
3465             * @param tagId the primary key of the asset tag
3466             * @return the asset tag
3467             * @throws NoSuchTagException if a asset tag with the primary key could not be found
3468             */
3469            @Override
3470            public AssetTag findByPrimaryKey(long tagId) throws NoSuchTagException {
3471                    return findByPrimaryKey((Serializable)tagId);
3472            }
3473    
3474            /**
3475             * Returns the asset tag with the primary key or returns <code>null</code> if it could not be found.
3476             *
3477             * @param primaryKey the primary key of the asset tag
3478             * @return the asset tag, or <code>null</code> if a asset tag with the primary key could not be found
3479             */
3480            @Override
3481            public AssetTag fetchByPrimaryKey(Serializable primaryKey) {
3482                    AssetTag assetTag = (AssetTag)EntityCacheUtil.getResult(AssetTagModelImpl.ENTITY_CACHE_ENABLED,
3483                                    AssetTagImpl.class, primaryKey);
3484    
3485                    if (assetTag == _nullAssetTag) {
3486                            return null;
3487                    }
3488    
3489                    if (assetTag == null) {
3490                            Session session = null;
3491    
3492                            try {
3493                                    session = openSession();
3494    
3495                                    assetTag = (AssetTag)session.get(AssetTagImpl.class, primaryKey);
3496    
3497                                    if (assetTag != null) {
3498                                            cacheResult(assetTag);
3499                                    }
3500                                    else {
3501                                            EntityCacheUtil.putResult(AssetTagModelImpl.ENTITY_CACHE_ENABLED,
3502                                                    AssetTagImpl.class, primaryKey, _nullAssetTag);
3503                                    }
3504                            }
3505                            catch (Exception e) {
3506                                    EntityCacheUtil.removeResult(AssetTagModelImpl.ENTITY_CACHE_ENABLED,
3507                                            AssetTagImpl.class, primaryKey);
3508    
3509                                    throw processException(e);
3510                            }
3511                            finally {
3512                                    closeSession(session);
3513                            }
3514                    }
3515    
3516                    return assetTag;
3517            }
3518    
3519            /**
3520             * Returns the asset tag with the primary key or returns <code>null</code> if it could not be found.
3521             *
3522             * @param tagId the primary key of the asset tag
3523             * @return the asset tag, or <code>null</code> if a asset tag with the primary key could not be found
3524             */
3525            @Override
3526            public AssetTag fetchByPrimaryKey(long tagId) {
3527                    return fetchByPrimaryKey((Serializable)tagId);
3528            }
3529    
3530            @Override
3531            public Map<Serializable, AssetTag> fetchByPrimaryKeys(
3532                    Set<Serializable> primaryKeys) {
3533                    if (primaryKeys.isEmpty()) {
3534                            return Collections.emptyMap();
3535                    }
3536    
3537                    Map<Serializable, AssetTag> map = new HashMap<Serializable, AssetTag>();
3538    
3539                    if (primaryKeys.size() == 1) {
3540                            Iterator<Serializable> iterator = primaryKeys.iterator();
3541    
3542                            Serializable primaryKey = iterator.next();
3543    
3544                            AssetTag assetTag = fetchByPrimaryKey(primaryKey);
3545    
3546                            if (assetTag != null) {
3547                                    map.put(primaryKey, assetTag);
3548                            }
3549    
3550                            return map;
3551                    }
3552    
3553                    Set<Serializable> uncachedPrimaryKeys = null;
3554    
3555                    for (Serializable primaryKey : primaryKeys) {
3556                            AssetTag assetTag = (AssetTag)EntityCacheUtil.getResult(AssetTagModelImpl.ENTITY_CACHE_ENABLED,
3557                                            AssetTagImpl.class, primaryKey);
3558    
3559                            if (assetTag == null) {
3560                                    if (uncachedPrimaryKeys == null) {
3561                                            uncachedPrimaryKeys = new HashSet<Serializable>();
3562                                    }
3563    
3564                                    uncachedPrimaryKeys.add(primaryKey);
3565                            }
3566                            else {
3567                                    map.put(primaryKey, assetTag);
3568                            }
3569                    }
3570    
3571                    if (uncachedPrimaryKeys == null) {
3572                            return map;
3573                    }
3574    
3575                    StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
3576                                    1);
3577    
3578                    query.append(_SQL_SELECT_ASSETTAG_WHERE_PKS_IN);
3579    
3580                    for (Serializable primaryKey : uncachedPrimaryKeys) {
3581                            query.append(String.valueOf(primaryKey));
3582    
3583                            query.append(StringPool.COMMA);
3584                    }
3585    
3586                    query.setIndex(query.index() - 1);
3587    
3588                    query.append(StringPool.CLOSE_PARENTHESIS);
3589    
3590                    String sql = query.toString();
3591    
3592                    Session session = null;
3593    
3594                    try {
3595                            session = openSession();
3596    
3597                            Query q = session.createQuery(sql);
3598    
3599                            for (AssetTag assetTag : (List<AssetTag>)q.list()) {
3600                                    map.put(assetTag.getPrimaryKeyObj(), assetTag);
3601    
3602                                    cacheResult(assetTag);
3603    
3604                                    uncachedPrimaryKeys.remove(assetTag.getPrimaryKeyObj());
3605                            }
3606    
3607                            for (Serializable primaryKey : uncachedPrimaryKeys) {
3608                                    EntityCacheUtil.putResult(AssetTagModelImpl.ENTITY_CACHE_ENABLED,
3609                                            AssetTagImpl.class, primaryKey, _nullAssetTag);
3610                            }
3611                    }
3612                    catch (Exception e) {
3613                            throw processException(e);
3614                    }
3615                    finally {
3616                            closeSession(session);
3617                    }
3618    
3619                    return map;
3620            }
3621    
3622            /**
3623             * Returns all the asset tags.
3624             *
3625             * @return the asset tags
3626             */
3627            @Override
3628            public List<AssetTag> findAll() {
3629                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
3630            }
3631    
3632            /**
3633             * Returns a range of all the asset tags.
3634             *
3635             * <p>
3636             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetTagModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3637             * </p>
3638             *
3639             * @param start the lower bound of the range of asset tags
3640             * @param end the upper bound of the range of asset tags (not inclusive)
3641             * @return the range of asset tags
3642             */
3643            @Override
3644            public List<AssetTag> findAll(int start, int end) {
3645                    return findAll(start, end, null);
3646            }
3647    
3648            /**
3649             * Returns an ordered range of all the asset tags.
3650             *
3651             * <p>
3652             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetTagModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3653             * </p>
3654             *
3655             * @param start the lower bound of the range of asset tags
3656             * @param end the upper bound of the range of asset tags (not inclusive)
3657             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3658             * @return the ordered range of asset tags
3659             */
3660            @Override
3661            public List<AssetTag> findAll(int start, int end,
3662                    OrderByComparator<AssetTag> orderByComparator) {
3663                    boolean pagination = true;
3664                    FinderPath finderPath = null;
3665                    Object[] finderArgs = null;
3666    
3667                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3668                                    (orderByComparator == null)) {
3669                            pagination = false;
3670                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
3671                            finderArgs = FINDER_ARGS_EMPTY;
3672                    }
3673                    else {
3674                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
3675                            finderArgs = new Object[] { start, end, orderByComparator };
3676                    }
3677    
3678                    List<AssetTag> list = (List<AssetTag>)FinderCacheUtil.getResult(finderPath,
3679                                    finderArgs, this);
3680    
3681                    if (list == null) {
3682                            StringBundler query = null;
3683                            String sql = null;
3684    
3685                            if (orderByComparator != null) {
3686                                    query = new StringBundler(2 +
3687                                                    (orderByComparator.getOrderByFields().length * 3));
3688    
3689                                    query.append(_SQL_SELECT_ASSETTAG);
3690    
3691                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3692                                            orderByComparator);
3693    
3694                                    sql = query.toString();
3695                            }
3696                            else {
3697                                    sql = _SQL_SELECT_ASSETTAG;
3698    
3699                                    if (pagination) {
3700                                            sql = sql.concat(AssetTagModelImpl.ORDER_BY_JPQL);
3701                                    }
3702                            }
3703    
3704                            Session session = null;
3705    
3706                            try {
3707                                    session = openSession();
3708    
3709                                    Query q = session.createQuery(sql);
3710    
3711                                    if (!pagination) {
3712                                            list = (List<AssetTag>)QueryUtil.list(q, getDialect(),
3713                                                            start, end, false);
3714    
3715                                            Collections.sort(list);
3716    
3717                                            list = Collections.unmodifiableList(list);
3718                                    }
3719                                    else {
3720                                            list = (List<AssetTag>)QueryUtil.list(q, getDialect(),
3721                                                            start, end);
3722                                    }
3723    
3724                                    cacheResult(list);
3725    
3726                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
3727                            }
3728                            catch (Exception e) {
3729                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3730    
3731                                    throw processException(e);
3732                            }
3733                            finally {
3734                                    closeSession(session);
3735                            }
3736                    }
3737    
3738                    return list;
3739            }
3740    
3741            /**
3742             * Removes all the asset tags from the database.
3743             *
3744             */
3745            @Override
3746            public void removeAll() {
3747                    for (AssetTag assetTag : findAll()) {
3748                            remove(assetTag);
3749                    }
3750            }
3751    
3752            /**
3753             * Returns the number of asset tags.
3754             *
3755             * @return the number of asset tags
3756             */
3757            @Override
3758            public int countAll() {
3759                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
3760                                    FINDER_ARGS_EMPTY, this);
3761    
3762                    if (count == null) {
3763                            Session session = null;
3764    
3765                            try {
3766                                    session = openSession();
3767    
3768                                    Query q = session.createQuery(_SQL_COUNT_ASSETTAG);
3769    
3770                                    count = (Long)q.uniqueResult();
3771    
3772                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
3773                                            FINDER_ARGS_EMPTY, count);
3774                            }
3775                            catch (Exception e) {
3776                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
3777                                            FINDER_ARGS_EMPTY);
3778    
3779                                    throw processException(e);
3780                            }
3781                            finally {
3782                                    closeSession(session);
3783                            }
3784                    }
3785    
3786                    return count.intValue();
3787            }
3788    
3789            /**
3790             * Returns the primaryKeys of asset entries associated with the asset tag.
3791             *
3792             * @param pk the primary key of the asset tag
3793             * @return long[] of the primaryKeys of asset entries associated with the asset tag
3794             */
3795            @Override
3796            public long[] getAssetEntryPrimaryKeys(long pk) {
3797                    long[] pks = assetTagToAssetEntryTableMapper.getRightPrimaryKeys(pk);
3798    
3799                    return pks.clone();
3800            }
3801    
3802            /**
3803             * Returns all the asset entries associated with the asset tag.
3804             *
3805             * @param pk the primary key of the asset tag
3806             * @return the asset entries associated with the asset tag
3807             */
3808            @Override
3809            public List<com.liferay.portlet.asset.model.AssetEntry> getAssetEntries(
3810                    long pk) {
3811                    return getAssetEntries(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
3812            }
3813    
3814            /**
3815             * Returns a range of all the asset entries associated with the asset tag.
3816             *
3817             * <p>
3818             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetTagModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3819             * </p>
3820             *
3821             * @param pk the primary key of the asset tag
3822             * @param start the lower bound of the range of asset tags
3823             * @param end the upper bound of the range of asset tags (not inclusive)
3824             * @return the range of asset entries associated with the asset tag
3825             */
3826            @Override
3827            public List<com.liferay.portlet.asset.model.AssetEntry> getAssetEntries(
3828                    long pk, int start, int end) {
3829                    return getAssetEntries(pk, start, end, null);
3830            }
3831    
3832            /**
3833             * Returns an ordered range of all the asset entries associated with the asset tag.
3834             *
3835             * <p>
3836             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetTagModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3837             * </p>
3838             *
3839             * @param pk the primary key of the asset tag
3840             * @param start the lower bound of the range of asset tags
3841             * @param end the upper bound of the range of asset tags (not inclusive)
3842             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3843             * @return the ordered range of asset entries associated with the asset tag
3844             */
3845            @Override
3846            public List<com.liferay.portlet.asset.model.AssetEntry> getAssetEntries(
3847                    long pk, int start, int end,
3848                    OrderByComparator<com.liferay.portlet.asset.model.AssetEntry> orderByComparator) {
3849                    return assetTagToAssetEntryTableMapper.getRightBaseModels(pk, start,
3850                            end, orderByComparator);
3851            }
3852    
3853            /**
3854             * Returns the number of asset entries associated with the asset tag.
3855             *
3856             * @param pk the primary key of the asset tag
3857             * @return the number of asset entries associated with the asset tag
3858             */
3859            @Override
3860            public int getAssetEntriesSize(long pk) {
3861                    long[] pks = assetTagToAssetEntryTableMapper.getRightPrimaryKeys(pk);
3862    
3863                    return pks.length;
3864            }
3865    
3866            /**
3867             * Returns <code>true</code> if the asset entry is associated with the asset tag.
3868             *
3869             * @param pk the primary key of the asset tag
3870             * @param assetEntryPK the primary key of the asset entry
3871             * @return <code>true</code> if the asset entry is associated with the asset tag; <code>false</code> otherwise
3872             */
3873            @Override
3874            public boolean containsAssetEntry(long pk, long assetEntryPK) {
3875                    return assetTagToAssetEntryTableMapper.containsTableMapping(pk,
3876                            assetEntryPK);
3877            }
3878    
3879            /**
3880             * Returns <code>true</code> if the asset tag has any asset entries associated with it.
3881             *
3882             * @param pk the primary key of the asset tag to check for associations with asset entries
3883             * @return <code>true</code> if the asset tag has any asset entries associated with it; <code>false</code> otherwise
3884             */
3885            @Override
3886            public boolean containsAssetEntries(long pk) {
3887                    if (getAssetEntriesSize(pk) > 0) {
3888                            return true;
3889                    }
3890                    else {
3891                            return false;
3892                    }
3893            }
3894    
3895            /**
3896             * Adds an association between the asset tag and the asset entry. Also notifies the appropriate model listeners and clears the mapping table finder cache.
3897             *
3898             * @param pk the primary key of the asset tag
3899             * @param assetEntryPK the primary key of the asset entry
3900             */
3901            @Override
3902            public void addAssetEntry(long pk, long assetEntryPK) {
3903                    assetTagToAssetEntryTableMapper.addTableMapping(pk, assetEntryPK);
3904            }
3905    
3906            /**
3907             * Adds an association between the asset tag and the asset entry. Also notifies the appropriate model listeners and clears the mapping table finder cache.
3908             *
3909             * @param pk the primary key of the asset tag
3910             * @param assetEntry the asset entry
3911             */
3912            @Override
3913            public void addAssetEntry(long pk,
3914                    com.liferay.portlet.asset.model.AssetEntry assetEntry) {
3915                    assetTagToAssetEntryTableMapper.addTableMapping(pk,
3916                            assetEntry.getPrimaryKey());
3917            }
3918    
3919            /**
3920             * Adds an association between the asset tag and the asset entries. Also notifies the appropriate model listeners and clears the mapping table finder cache.
3921             *
3922             * @param pk the primary key of the asset tag
3923             * @param assetEntryPKs the primary keys of the asset entries
3924             */
3925            @Override
3926            public void addAssetEntries(long pk, long[] assetEntryPKs) {
3927                    for (long assetEntryPK : assetEntryPKs) {
3928                            assetTagToAssetEntryTableMapper.addTableMapping(pk, assetEntryPK);
3929                    }
3930            }
3931    
3932            /**
3933             * Adds an association between the asset tag and the asset entries. Also notifies the appropriate model listeners and clears the mapping table finder cache.
3934             *
3935             * @param pk the primary key of the asset tag
3936             * @param assetEntries the asset entries
3937             */
3938            @Override
3939            public void addAssetEntries(long pk,
3940                    List<com.liferay.portlet.asset.model.AssetEntry> assetEntries) {
3941                    for (com.liferay.portlet.asset.model.AssetEntry assetEntry : assetEntries) {
3942                            assetTagToAssetEntryTableMapper.addTableMapping(pk,
3943                                    assetEntry.getPrimaryKey());
3944                    }
3945            }
3946    
3947            /**
3948             * Clears all associations between the asset tag and its asset entries. Also notifies the appropriate model listeners and clears the mapping table finder cache.
3949             *
3950             * @param pk the primary key of the asset tag to clear the associated asset entries from
3951             */
3952            @Override
3953            public void clearAssetEntries(long pk) {
3954                    assetTagToAssetEntryTableMapper.deleteLeftPrimaryKeyTableMappings(pk);
3955            }
3956    
3957            /**
3958             * Removes the association between the asset tag and the asset entry. Also notifies the appropriate model listeners and clears the mapping table finder cache.
3959             *
3960             * @param pk the primary key of the asset tag
3961             * @param assetEntryPK the primary key of the asset entry
3962             */
3963            @Override
3964            public void removeAssetEntry(long pk, long assetEntryPK) {
3965                    assetTagToAssetEntryTableMapper.deleteTableMapping(pk, assetEntryPK);
3966            }
3967    
3968            /**
3969             * Removes the association between the asset tag and the asset entry. Also notifies the appropriate model listeners and clears the mapping table finder cache.
3970             *
3971             * @param pk the primary key of the asset tag
3972             * @param assetEntry the asset entry
3973             */
3974            @Override
3975            public void removeAssetEntry(long pk,
3976                    com.liferay.portlet.asset.model.AssetEntry assetEntry) {
3977                    assetTagToAssetEntryTableMapper.deleteTableMapping(pk,
3978                            assetEntry.getPrimaryKey());
3979            }
3980    
3981            /**
3982             * Removes the association between the asset tag and the asset entries. Also notifies the appropriate model listeners and clears the mapping table finder cache.
3983             *
3984             * @param pk the primary key of the asset tag
3985             * @param assetEntryPKs the primary keys of the asset entries
3986             */
3987            @Override
3988            public void removeAssetEntries(long pk, long[] assetEntryPKs) {
3989                    for (long assetEntryPK : assetEntryPKs) {
3990                            assetTagToAssetEntryTableMapper.deleteTableMapping(pk, assetEntryPK);
3991                    }
3992            }
3993    
3994            /**
3995             * Removes the association between the asset tag and the asset entries. Also notifies the appropriate model listeners and clears the mapping table finder cache.
3996             *
3997             * @param pk the primary key of the asset tag
3998             * @param assetEntries the asset entries
3999             */
4000            @Override
4001            public void removeAssetEntries(long pk,
4002                    List<com.liferay.portlet.asset.model.AssetEntry> assetEntries) {
4003                    for (com.liferay.portlet.asset.model.AssetEntry assetEntry : assetEntries) {
4004                            assetTagToAssetEntryTableMapper.deleteTableMapping(pk,
4005                                    assetEntry.getPrimaryKey());
4006                    }
4007            }
4008    
4009            /**
4010             * 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.
4011             *
4012             * @param pk the primary key of the asset tag
4013             * @param assetEntryPKs the primary keys of the asset entries to be associated with the asset tag
4014             */
4015            @Override
4016            public void setAssetEntries(long pk, long[] assetEntryPKs) {
4017                    Set<Long> newAssetEntryPKsSet = SetUtil.fromArray(assetEntryPKs);
4018                    Set<Long> oldAssetEntryPKsSet = SetUtil.fromArray(assetTagToAssetEntryTableMapper.getRightPrimaryKeys(
4019                                            pk));
4020    
4021                    Set<Long> removeAssetEntryPKsSet = new HashSet<Long>(oldAssetEntryPKsSet);
4022    
4023                    removeAssetEntryPKsSet.removeAll(newAssetEntryPKsSet);
4024    
4025                    for (long removeAssetEntryPK : removeAssetEntryPKsSet) {
4026                            assetTagToAssetEntryTableMapper.deleteTableMapping(pk,
4027                                    removeAssetEntryPK);
4028                    }
4029    
4030                    newAssetEntryPKsSet.removeAll(oldAssetEntryPKsSet);
4031    
4032                    for (long newAssetEntryPK : newAssetEntryPKsSet) {
4033                            assetTagToAssetEntryTableMapper.addTableMapping(pk, newAssetEntryPK);
4034                    }
4035            }
4036    
4037            /**
4038             * 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.
4039             *
4040             * @param pk the primary key of the asset tag
4041             * @param assetEntries the asset entries to be associated with the asset tag
4042             */
4043            @Override
4044            public void setAssetEntries(long pk,
4045                    List<com.liferay.portlet.asset.model.AssetEntry> assetEntries) {
4046                    try {
4047                            long[] assetEntryPKs = new long[assetEntries.size()];
4048    
4049                            for (int i = 0; i < assetEntries.size(); i++) {
4050                                    com.liferay.portlet.asset.model.AssetEntry assetEntry = assetEntries.get(i);
4051    
4052                                    assetEntryPKs[i] = assetEntry.getPrimaryKey();
4053                            }
4054    
4055                            setAssetEntries(pk, assetEntryPKs);
4056                    }
4057                    catch (Exception e) {
4058                            throw processException(e);
4059                    }
4060            }
4061    
4062            /**
4063             * Initializes the asset tag persistence.
4064             */
4065            public void afterPropertiesSet() {
4066                    assetTagToAssetEntryTableMapper = TableMapperFactory.getTableMapper("AssetEntries_AssetTags",
4067                                    "tagId", "entryId", this, assetEntryPersistence);
4068            }
4069    
4070            public void destroy() {
4071                    EntityCacheUtil.removeCache(AssetTagImpl.class.getName());
4072                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
4073                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
4074                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
4075    
4076                    TableMapperFactory.removeTableMapper("AssetEntries_AssetTags");
4077            }
4078    
4079            @BeanReference(type = AssetEntryPersistence.class)
4080            protected AssetEntryPersistence assetEntryPersistence;
4081            protected TableMapper<AssetTag, com.liferay.portlet.asset.model.AssetEntry> assetTagToAssetEntryTableMapper;
4082            private static final String _SQL_SELECT_ASSETTAG = "SELECT assetTag FROM AssetTag assetTag";
4083            private static final String _SQL_SELECT_ASSETTAG_WHERE_PKS_IN = "SELECT assetTag FROM AssetTag assetTag WHERE tagId IN (";
4084            private static final String _SQL_SELECT_ASSETTAG_WHERE = "SELECT assetTag FROM AssetTag assetTag WHERE ";
4085            private static final String _SQL_COUNT_ASSETTAG = "SELECT COUNT(assetTag) FROM AssetTag assetTag";
4086            private static final String _SQL_COUNT_ASSETTAG_WHERE = "SELECT COUNT(assetTag) FROM AssetTag assetTag WHERE ";
4087            private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "assetTag.tagId";
4088            private static final String _FILTER_SQL_SELECT_ASSETTAG_WHERE = "SELECT DISTINCT {assetTag.*} FROM AssetTag assetTag WHERE ";
4089            private static final String _FILTER_SQL_SELECT_ASSETTAG_NO_INLINE_DISTINCT_WHERE_1 =
4090                    "SELECT {AssetTag.*} FROM (SELECT DISTINCT assetTag.tagId FROM AssetTag assetTag WHERE ";
4091            private static final String _FILTER_SQL_SELECT_ASSETTAG_NO_INLINE_DISTINCT_WHERE_2 =
4092                    ") TEMP_TABLE INNER JOIN AssetTag ON TEMP_TABLE.tagId = AssetTag.tagId";
4093            private static final String _FILTER_SQL_COUNT_ASSETTAG_WHERE = "SELECT COUNT(DISTINCT assetTag.tagId) AS COUNT_VALUE FROM AssetTag assetTag WHERE ";
4094            private static final String _FILTER_ENTITY_ALIAS = "assetTag";
4095            private static final String _FILTER_ENTITY_TABLE = "AssetTag";
4096            private static final String _ORDER_BY_ENTITY_ALIAS = "assetTag.";
4097            private static final String _ORDER_BY_ENTITY_TABLE = "AssetTag.";
4098            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No AssetTag exists with the primary key ";
4099            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No AssetTag exists with the key {";
4100            private static final Log _log = LogFactoryUtil.getLog(AssetTagPersistenceImpl.class);
4101            private static final AssetTag _nullAssetTag = new AssetTagImpl() {
4102                            @Override
4103                            public Object clone() {
4104                                    return this;
4105                            }
4106    
4107                            @Override
4108                            public CacheModel<AssetTag> toCacheModel() {
4109                                    return _nullAssetTagCacheModel;
4110                            }
4111                    };
4112    
4113            private static final CacheModel<AssetTag> _nullAssetTagCacheModel = new CacheModel<AssetTag>() {
4114                            @Override
4115                            public AssetTag toEntityModel() {
4116                                    return _nullAssetTag;
4117                            }
4118                    };
4119    }